JPEGCompressor.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _JPEGCOMPRESSOR_H
00023 #define _JPEGCOMPRESSOR_H
00024
00025
00026
00027 #include <cstdio>
00028 #include <string>
00029 #include "RawTile.h"
00030
00031
00032 extern "C"{
00033
00034
00035 #undef HAVE_STDLIB_H
00036 #include <jpeglib.h>
00037 }
00038
00039
00040
00042
00043
00044 typedef struct {
00045 struct jpeg_destination_mgr pub;
00047 size_t size;
00048 JOCTET *buffer;
00049 unsigned char* source;
00050 unsigned int strip_height;
00052 } iip_destination_mgr;
00053
00054 typedef iip_destination_mgr * iip_dest_ptr;
00055
00056
00057
00059
00060 class JPEGCompressor{
00061
00062
00063 private:
00064
00066 unsigned int width, height, channels;
00067
00069 int Q;
00070
00072 unsigned char header[1024];
00073
00075 unsigned char *data;
00076
00078 unsigned int header_size;
00079
00081 struct jpeg_compress_struct cinfo;
00082 struct jpeg_error_mgr jerr;
00083 iip_destination_mgr dest_mgr;
00084 iip_dest_ptr dest;
00085
00086
00087 public:
00088
00090
00091 JPEGCompressor( int quality ) { Q = quality; };
00092
00093
00095
00096 void setQuality( int factor ) {
00097 if( factor < 0 ) Q = 0;
00098 else if( factor > 100 ) Q = 100;
00099 else Q = factor;
00100 };
00101
00102
00104 int getQuality() { return Q; }
00105
00106
00108
00114 void InitCompression( RawTile& rawtile, unsigned int strip_height ) throw (std::string);
00115
00117
00120 unsigned int CompressStrip( unsigned char* s, unsigned int tile_height ) throw (std::string);
00121
00123 unsigned int Finish() throw (std::string);
00124
00125
00127
00128 int Compress( RawTile& t ) throw (std::string);
00129
00130
00132 unsigned int getHeaderSize() { return header_size; }
00133
00135 inline unsigned char* getHeader() { return header; }
00136
00137
00138 };
00139
00140
00141 #endif