iipsrv 1.1
iipsrv is an advanced high-performance feature-rich image server for web-based streamed viewing and zooming of ultra high-resolution images
KakaduImage.h
1// Kakadu JPEG2000 Image class Interface
2
3/* IIP Kakadu JPEG2000 Class
4
5
6 Development supported by Moravian Library in Brno (Moravska zemska
7 knihovna v Brne, http://www.mzk.cz/) R&D grant MK00009494301 & Old
8 Maps Online (http://www.oldmapsonline.org/) from the Ministry of
9 Culture of the Czech Republic.
10
11
12 Copyright (C) 2009-2017 IIPImage.
13 Author: Ruven Pillay
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software Foundation,
27 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
28*/
29
30
31#ifndef _KAKADUIMAGE_H
32#define _KAKADUIMAGE_H
33
34
35#include "IIPImage.h"
36#include "Logger.h"
37
38#include <jpx.h>
39#include <jp2.h>
40#include <kdu_stripe_decompressor.h>
41#include <fstream>
42
43#define TILESIZE 256
44
45// Kakadu 7.5 uses namespaces
46#if KDU_MAJOR_VERSION > 7 || (KDU_MAJOR_VERSION == 7 && KDU_MINOR_VERSION >= 5)
47using namespace kdu_supp; // Also includes the `kdu_core' namespace
48#endif
49
50extern Logger logfile;
51
52
54class kdu_stream_message : public kdu_message {
55 private: // Data
56 std::ostream *stream;
57 std::string message;
58
59 public: // Member classes
60 kdu_stream_message(std::ostream *stream)
61 { this->stream = stream; }
62 void put_text(const char *string)
63 { logfile << string; }
64 void flush(bool end_of_message=false){
65 logfile << message;
66 if( end_of_message ) throw 1;
67 }
68};
69
70
71//static kdu_stream_message cout_message(&std::cout);
72//static kdu_stream_message cerr_message(&std::cerr);
73
74static kdu_stream_message cout_message(&logfile);
75static kdu_stream_message cerr_message(&logfile);
76
77static kdu_message_formatter pretty_cout(&cout_message);
78static kdu_message_formatter pretty_cerr(&cerr_message);
79
80
81
82
83
85class KakaduImage : public IIPImage {
86
87 private:
88
90 kdu_codestream codestream;
91
93 kdu_compressed_source *input;
94
96 jpx_source jpx_input;
97
99 jp2_family_src src;
100
102 jpx_codestream_source jpx_stream;
103
105 kdu_stripe_decompressor decompressor;
106
108 kdu_dims comp_dims;
109
111
119 void process( unsigned int r, int l, int x, int y, unsigned int w, unsigned int h, void* d );
120
122
124 void delete_buffer( void* b );
125
126
127 public:
128
131 tile_width = TILESIZE; tile_height = TILESIZE; input = NULL;
132 };
133
135
137 KakaduImage( const std::string& path ): IIPImage( path ){
138 tile_width = TILESIZE; tile_height = TILESIZE; input = NULL;
139 };
140
142
144 KakaduImage( const KakaduImage& image ): IIPImage( image ) {};
145
147
149 KakaduImage( const IIPImage& image ): IIPImage( image ){
150 tile_width = TILESIZE; tile_height = TILESIZE; input = NULL;
151 };
152
154
157 if( this != &image ){
158 closeImage();
159 IIPImage::operator=(image);
160 }
161 return *this;
162 }
163
164
167
168
170 void openImage();
171
173
176 void loadImageInfo( int x, int y );
177
180
182 bool regionDecoding(){ return true; };
183
185
191 RawTile getTile( int x, int y, unsigned int r, int l, unsigned int t );
192
194
205 RawTile getRegion( int ha, int va, unsigned int r, int l, int x, int y, unsigned int w, unsigned int h );
206
211 };
212
215
216
217};
218
219
220#endif
Main class to handle the pyramidal image source.
Definition IIPImage.h:62
IIPImage & operator=(IIPImage image)
Assignment operator.
Definition IIPImage.h:375
unsigned int tile_width
The base tile pixel dimensions.
Definition IIPImage.h:115
Image class for Kakadu JPEG2000 Images: Inherits from IIPImage. Uses the Kakadu library.
Definition KakaduImage.h:85
KDU_READMODE kdu_readmode
Read-mode.
Definition KakaduImage.h:214
KakaduImage()
Constructor.
Definition KakaduImage.h:130
bool regionDecoding()
Return whether this image type directly handles region decoding.
Definition KakaduImage.h:182
KakaduImage(const std::string &path)
Constructor.
Definition KakaduImage.h:137
void openImage()
Overloaded function for opening a TIFF image.
void loadImageInfo(int x, int y)
Overloaded function for loading TIFF image information.
~KakaduImage()
Destructor.
Definition KakaduImage.h:166
RawTile getTile(int x, int y, unsigned int r, int l, unsigned int t)
Overloaded function for getting a particular tile.
void closeImage()
Overloaded function for closing a JPEG2000 image.
KDU_READMODE
Read-mode types.
Definition KakaduImage.h:208
@ KDU_FUSSY
Fussy mode.
Definition KakaduImage.h:209
@ KDU_RESILIENT
Reslient mode for damaged JP2 streams.
Definition KakaduImage.h:210
@ KDU_FAST
Default fast mode.
Definition KakaduImage.h:208
KakaduImage(const KakaduImage &image)
Copy Constructor.
Definition KakaduImage.h:144
KakaduImage(const IIPImage &image)
Constructor from IIPImage object.
Definition KakaduImage.h:149
KakaduImage & operator=(KakaduImage image)
Assignment Operator.
Definition KakaduImage.h:156
RawTile getRegion(int ha, int va, unsigned int r, int l, int x, int y, unsigned int w, unsigned int h)
Overloaded function for returning a region for a given angle and resolution.
Logger class - handles ofstreams and syslog.
Definition Logger.h:79
Class to represent a single image tile.
Definition RawTile.h:45
Wrapper class to handle error messages from Kakadu.
Definition KakaduImage.h:54