iipsrv  0.9.9
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-2011 IIPImage.
13  Authors: Ruven Pillay & Petr Pridal
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 2 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
27  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 */
29 
30 
31 #ifndef _KAKADUIMAGE_H
32 #define _KAKADUIMAGE_H
33 
34 
35 #include "IIPImage.h"
36 #include <cstdio>
37 
38 #include <jpx.h>
39 #include <jp2.h>
40 #include <kdu_stripe_decompressor.h>
41 #include <iostream>
42 #include <fstream>
43 
44 #define TILESIZE 256
45 
46 
47 extern std::ofstream logfile;
48 
49 
51 class kdu_stream_message : public kdu_message {
52  private: // Data
53  std::ostream *stream;
54  std::string message;
55 
56  public: // Member classes
57  kdu_stream_message(std::ostream *stream)
58  { this->stream = stream; }
59  void put_text(const char *string)
60  { logfile << string; }
61  void flush(bool end_of_message=false){
62  logfile << message;
63  if( end_of_message ) throw 1;
64  }
65 };
66 
67 
68 //static kdu_stream_message cout_message(&std::cout);
69 //static kdu_stream_message cerr_message(&std::cerr);
70 
71 static kdu_stream_message cout_message(&logfile);
72 static kdu_stream_message cerr_message(&logfile);
73 
74 static kdu_message_formatter pretty_cout(&cout_message);
75 static kdu_message_formatter pretty_cerr(&cerr_message);
76 
77 
78 
79 
80 
82 class KakaduImage : public IIPImage {
83 
84  private:
85 
87  kdu_codestream codestream;
88 
90  kdu_compressed_source *input;
91 
93  jpx_source jpx_input;
94 
96  jp2_family_src src;
97 
99  jpx_codestream_source jpx_stream;
100 
102  kdu_stripe_decompressor decompressor;
103 
104  // Tile or Strip region
105  kdu_dims comp_dims;
106 
107  // Quality layers
108  unsigned int max_layers;
109 
111  unsigned int virtual_levels;
112 
113 
115 
123  void process( unsigned int r, int l, int x, int y, unsigned int w, unsigned int h, void* d ) throw (std::string);
124 
125 
126 
127  public:
128 
131  tile_width = TILESIZE; tile_height = TILESIZE;
132  numResolutions = 0; virtual_levels = 0;
133  };
134 
136 
138  KakaduImage( const std::string& path ): IIPImage( path ) {
139  tile_width = TILESIZE; tile_height = TILESIZE;
140  numResolutions = 0; virtual_levels = 0;
141  };
142 
144 
146  KakaduImage( const IIPImage& image ): IIPImage( image ) {
147  tile_width = TILESIZE; tile_height = TILESIZE;
148  numResolutions = 0; virtual_levels = 0;
149  };
150 
153 
155  void openImage() throw (std::string);
156 
157 
159 
162  void loadImageInfo( int x, int y ) throw (std::string);
163 
165  void closeImage();
166 
168 
174  RawTile getTile( int x, int y, unsigned int r, int l, unsigned int t ) throw (std::string);
175 
177 
188  void getRegion( int ha, int va, unsigned int r, int l, int x, int y, unsigned int w, unsigned int h, unsigned char* b ) throw (std::string);
189 
190 
191 };
192 
193 
194 #endif