KakaduImage.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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:
00053 std::ostream *stream;
00054 std::string message;
00055
00056 public:
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
00069
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
00105 kdu_dims comp_dims;
00106
00107
00108 unsigned int max_layers;
00109
00111 unsigned int virtual_levels;
00112
00113
00115
00123 void process( int r, int l, int x, int y, int w, 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, int w, int h, unsigned char* b ) throw (std::string);
00189
00190
00191 };
00192
00193
00194 #endif