iipsrv 0.9.9
|
00001 // Kakadu JPEG2000 Image class Interface 00002 00003 /* IIP Kakadu JPEG2000 Class 00004 00005 00006 Development supported by Moravian Library in Brno (Moravska zemska 00007 knihovna v Brne, http://www.mzk.cz/) R&D grant MK00009494301 & Old 00008 Maps Online (http://www.oldmapsonline.org/) from the Ministry of 00009 Culture of the Czech Republic. 00010 00011 00012 Copyright (C) 2009-2011 IIPImage. 00013 Authors: Ruven Pillay & Petr Pridal 00014 00015 This program is free software; you can redistribute it and/or modify 00016 it under the terms of the GNU General Public License as published by 00017 the Free Software Foundation; either version 2 of the License, or 00018 (at your option) any later version. 00019 00020 This program is distributed in the hope that it will be useful, 00021 but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 GNU General Public License for more details. 00024 00025 You should have received a copy of the GNU General Public License 00026 along with this program; if not, write to the Free Software 00027 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00028 */ 00029 00030 00031 #ifndef _KAKADUIMAGE_H 00032 #define _KAKADUIMAGE_H 00033 00034 00035 #include "IIPImage.h" 00036 #include <cstdio> 00037 00038 #include <jpx.h> 00039 #include <jp2.h> 00040 #include <kdu_stripe_decompressor.h> 00041 #include <iostream> 00042 #include <fstream> 00043 00044 #define TILESIZE 256 00045 00046 00047 extern std::ofstream logfile; 00048 00049 00051 class kdu_stream_message : public kdu_message { 00052 private: // Data 00053 std::ostream *stream; 00054 std::string message; 00055 00056 public: // Member classes 00057 kdu_stream_message(std::ostream *stream) 00058 { this->stream = stream; } 00059 void put_text(const char *string) 00060 { logfile << string; } 00061 void flush(bool end_of_message=false){ 00062 logfile << message; 00063 if( end_of_message ) throw 1; 00064 } 00065 }; 00066 00067 00068 //static kdu_stream_message cout_message(&std::cout); 00069 //static kdu_stream_message cerr_message(&std::cerr); 00070 00071 static kdu_stream_message cout_message(&logfile); 00072 static kdu_stream_message cerr_message(&logfile); 00073 00074 static kdu_message_formatter pretty_cout(&cout_message); 00075 static kdu_message_formatter pretty_cerr(&cerr_message); 00076 00077 00078 00079 00080 00082 class KakaduImage : public IIPImage { 00083 00084 private: 00085 00087 kdu_codestream codestream; 00088 00090 kdu_compressed_source *input; 00091 00093 jpx_source jpx_input; 00094 00096 jp2_family_src src; 00097 00099 jpx_codestream_source jpx_stream; 00100 00102 kdu_stripe_decompressor decompressor; 00103 00104 // Tile or Strip region 00105 kdu_dims comp_dims; 00106 00107 // Quality layers 00108 unsigned int max_layers; 00109 00111 unsigned int virtual_levels; 00112 00113 00115 00123 void process( unsigned int r, int l, int x, int y, unsigned int w, unsigned int h, void* d ) throw (std::string); 00124 00125 00126 00127 public: 00128 00130 KakaduImage():IIPImage() { 00131 tile_width = TILESIZE; tile_height = TILESIZE; 00132 numResolutions = 0; virtual_levels = 0; 00133 }; 00134 00136 00138 KakaduImage( const std::string& path ): IIPImage( path ) { 00139 tile_width = TILESIZE; tile_height = TILESIZE; 00140 numResolutions = 0; virtual_levels = 0; 00141 }; 00142 00144 00146 KakaduImage( const IIPImage& image ): IIPImage( image ) { 00147 tile_width = TILESIZE; tile_height = TILESIZE; 00148 numResolutions = 0; virtual_levels = 0; 00149 }; 00150 00152 ~KakaduImage() { closeImage(); }; 00153 00155 void openImage() throw (std::string); 00156 00157 00159 00162 void loadImageInfo( int x, int y ) throw (std::string); 00163 00165 void closeImage(); 00166 00168 00174 RawTile getTile( int x, int y, unsigned int r, int l, unsigned int t ) throw (std::string); 00175 00177 00188 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); 00189 00190 00191 }; 00192 00193 00194 #endif