iipsrv  1.0
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-2016 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 
37 #include <jpx.h>
38 #include <jp2.h>
39 #include <kdu_stripe_decompressor.h>
40 #include <fstream>
41 
42 #define TILESIZE 256
43 
44 // Kakadu 7.5 uses namespaces
45 #if KDU_MAJOR_VERSION > 7 || (KDU_MAJOR_VERSION == 7 && KDU_MINOR_VERSION >= 5)
46 using namespace kdu_supp; // Also includes the `kdu_core' namespace
47 #endif
48 
49 extern std::ofstream logfile;
50 
51 
53 class kdu_stream_message : public kdu_message {
54  private: // Data
55  std::ostream *stream;
56  std::string message;
57 
58  public: // Member classes
59  kdu_stream_message(std::ostream *stream)
60  { this->stream = stream; }
61  void put_text(const char *string)
62  { logfile << string; }
63  void flush(bool end_of_message=false){
64  logfile << message;
65  if( end_of_message ) throw 1;
66  }
67 };
68 
69 
70 //static kdu_stream_message cout_message(&std::cout);
71 //static kdu_stream_message cerr_message(&std::cerr);
72 
73 static kdu_stream_message cout_message(&logfile);
74 static kdu_stream_message cerr_message(&logfile);
75 
76 static kdu_message_formatter pretty_cout(&cout_message);
77 static kdu_message_formatter pretty_cerr(&cerr_message);
78 
79 
80 
81 
82 
84 class KakaduImage : public IIPImage {
85 
86  private:
87 
89  kdu_codestream codestream;
90 
92  kdu_compressed_source *input;
93 
95  jpx_source jpx_input;
96 
98  jp2_family_src src;
99 
101  jpx_codestream_source jpx_stream;
102 
104  kdu_stripe_decompressor decompressor;
105 
107  kdu_dims comp_dims;
108 
110 
118  void process( unsigned int r, int l, int x, int y, unsigned int w, unsigned int h, void* d ) throw (file_error);
119 
121 
123  void delete_buffer( void* b );
124 
125 
126  public:
127 
130  tile_width = TILESIZE; tile_height = TILESIZE; input = NULL;
131  };
132 
134 
136  KakaduImage( const std::string& path ): IIPImage( path ){
137  tile_width = TILESIZE; tile_height = TILESIZE; input = NULL;
138  };
139 
141 
143  KakaduImage( const KakaduImage& image ): IIPImage( image ) {};
144 
146 
148  KakaduImage( const IIPImage& image ): IIPImage( image ){
149  tile_width = TILESIZE; tile_height = TILESIZE; input = NULL;
150  };
151 
153 
155  KakaduImage& operator = ( KakaduImage image ) {
156  if( this != &image ){
157  closeImage();
158  IIPImage::operator=(image);
159  }
160  return *this;
161  }
162 
163 
165  ~KakaduImage() { closeImage(); };
166 
168  void openImage() throw (file_error);
169 
170 
172 
175  void loadImageInfo( int x, int y ) throw (file_error);
176 
178  void closeImage();
179 
181  bool regionDecoding(){ return true; };
182 
184 
190  RawTile getTile( int x, int y, unsigned int r, int l, unsigned int t ) throw (file_error);
191 
193 
204  RawTile getRegion( int ha, int va, unsigned int r, int l, int x, int y, unsigned int w, unsigned int h ) throw (file_error);
205 
206 
207 };
208 
209 
210 #endif
KakaduImage(const std::string &path)
Constructor.
Definition: KakaduImage.h:136
KakaduImage()
Constructor.
Definition: KakaduImage.h:129
Image class for Kakadu JPEG2000 Images: Inherits from IIPImage. Uses the Kakadu library.
Definition: KakaduImage.h:84
KakaduImage(const KakaduImage &image)
Copy Constructor.
Definition: KakaduImage.h:143
Define our own derived exception class for file errors.
Definition: IIPImage.h:43
~KakaduImage()
Destructor.
Definition: KakaduImage.h:165
Main class to handle the pyramidal image source.
Definition: IIPImage.h:61
Wrapper class to handle error messages from Kakadu.
Definition: KakaduImage.h:53
IIPImage & operator=(IIPImage image)
Assignment operator.
Definition: IIPImage.h:370
Class to represent a single image tile.
Definition: RawTile.h:45
KakaduImage(const IIPImage &image)
Constructor from IIPImage object.
Definition: KakaduImage.h:148