iipsrv 0.9.9
|
00001 /* JPEG class wrapper to ijg jpeg library 00002 00003 Copyright (C) 2000-2003 Ruven Pillay. 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 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 /* Undefine this to prevent compiler warning 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