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)
47 using namespace kdu_supp; // Also includes the `kdu_core' namespace
48 #endif
49 
50 extern Logger logfile;
51 
52 
54 class 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 
74 static kdu_stream_message cout_message(&logfile);
75 static kdu_stream_message cerr_message(&logfile);
76 
77 static kdu_message_formatter pretty_cout(&cout_message);
78 static kdu_message_formatter pretty_cerr(&cerr_message);
79 
80 
81 
82 
83 
85 class 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 
156  KakaduImage& operator = ( KakaduImage image ) {
157  if( this != &image ){
158  closeImage();
159  IIPImage::operator=(image);
160  }
161  return *this;
162  }
163 
164 
166  ~KakaduImage() { closeImage(); };
167 
168 
170  void openImage();
171 
173 
176  void loadImageInfo( int x, int y );
177 
179  void closeImage();
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 
208  enum KDU_READMODE { KDU_FAST,
210  KDU_RESILIENT
211  };
212 
215 
216 
217 };
218 
219 
220 #endif
Logger class - handles ofstreams and syslog.
Definition: Logger.h:79
KakaduImage(const std::string &path)
Constructor.
Definition: KakaduImage.h:137
KDU_READMODE kdu_readmode
Read-mode.
Definition: KakaduImage.h:214
bool regionDecoding()
Return whether this image type directly handles region decoding.
Definition: KakaduImage.h:182
KakaduImage()
Constructor.
Definition: KakaduImage.h:130
Image class for Kakadu JPEG2000 Images: Inherits from IIPImage. Uses the Kakadu library.
Definition: KakaduImage.h:85
KakaduImage(const KakaduImage &image)
Copy Constructor.
Definition: KakaduImage.h:144
Fussy mode.
Definition: KakaduImage.h:209
~KakaduImage()
Destructor.
Definition: KakaduImage.h:166
Main class to handle the pyramidal image source.
Definition: IIPImage.h:62
Wrapper class to handle error messages from Kakadu.
Definition: KakaduImage.h:54
IIPImage & operator=(IIPImage image)
Assignment operator.
Definition: IIPImage.h:375
Class to represent a single image tile.
Definition: RawTile.h:45
KakaduImage(const IIPImage &image)
Constructor from IIPImage object.
Definition: KakaduImage.h:149
KDU_READMODE
Read-mode types.
Definition: KakaduImage.h:208