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 #ifndef SO_LDM_JPEG_COMPRESSOR_H
00026 #define SO_LDM_JPEG_COMPRESSOR_H
00027
00028 #include <LDM/compressors/SoDataCompressor.h>
00029
00030 struct jpeg_destination_mgr;
00031 struct jpeg_source_mgr;
00032 struct jpeg_compress_struct;
00033 struct jpeg_decompress_struct;
00034 struct jpeg_error_mgr;
00035 struct jpeg_ldm_comp_destination_mgr;
00036 struct jpeg_ldm_decomp_destination_mgr;
00037
00038 class SoLibJpeg;
00039
00040 typedef struct jpeg_compress_struct *j_compress_ptr;
00041 typedef struct jpeg_decompress_struct * j_decompress_ptr;
00042
00066 class SoJpegDataCompressor : public SoDataCompressor
00067 {
00068 SO_TYPED_CLASS_HEADER();
00069
00070 public:
00074 SoJpegDataCompressor();
00078 virtual ~SoJpegDataCompressor();
00079
00087 virtual size_t compress(void *src, size_t srcLen, const TileInfo &tileInfo);
00088
00096 virtual size_t uncompress(void *dest, size_t destLen, const TileInfo &tileInfo);
00097
00104 virtual SbString getCompressionFormatName() const { return SbString("jpeg"); }
00105
00110 virtual bool isLossless() { return false; }
00111
00112 private:
00113 SoLibJpeg *m_jpeg;
00114
00115 struct jpeg_compress_struct *m_cinfo;
00116 struct jpeg_decompress_struct *m_dcinfo;
00117
00118 size_t allocateNeededSpace(size_t srcLen);
00119
00120
00121 static void initDestination(j_compress_ptr cinfo);
00122 static unsigned char emptyOutputBuffer(j_compress_ptr cinfo);
00123 static void termDestination(j_compress_ptr cinfo);
00124
00125 static void initSource(j_decompress_ptr cinfo);
00126 static unsigned char fillInputBuffer(j_decompress_ptr cinfo);
00127 static void skipInputData(j_decompress_ptr cinfo, long num_bytes);
00128 static void resyncToRestart(j_decompress_ptr cinfo, int desired);
00129 static void termSource(j_decompress_ptr cinfo);
00130
00131 void createCompressInfo(jpeg_compress_struct *cinfo, jpeg_error_mgr *jerr,
00132 jpeg_ldm_comp_destination_mgr *destMgr);
00133 static void createDecompressInfo(jpeg_decompress_struct *cinfo,
00134 jpeg_error_mgr *jerr,
00135 jpeg_ldm_decomp_destination_mgr *srcMgr);
00136
00137 size_t compressBatch( void* src, size_t srcLen, const TileInfo& tileInfo );
00138 static size_t uncompressBatch( void* dest, const TileInfo& tileInfo, const unsigned char* srcBuffer, size_t srcLen );
00139
00140 void allocBatchSizeBytes();
00141 static void writeBatchSize( unsigned char* buffer, uint64_t batchSize );
00142 static uint64_t readBatchSize( const unsigned char* buffer );
00143 };
00144
00145 #endif
00146
00147
00148