00001 /* 00002 * libopenraw - ljpegdecompressor_priv.h 00003 * 00004 * Copyright (C) 2007 Hubert Figuiere 00005 * 00006 * This library is free software: you can redistribute it and/or 00007 * modify it under the terms of the GNU Lesser General Public License 00008 * as published by the Free Software Foundation, either version 3 of 00009 * the License, or (at your option) any later version. 00010 * 00011 * This library is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this library. If not, see 00018 * <http://www.gnu.org/licenses/>. 00019 */ 00020 00021 #ifndef __OPENRAW_LJPEGDECOMPRESSOR_PRIV_H__ 00022 #define __OPENRAW_LJPEGDECOMPRESSOR_PRIV_H__ 00023 00024 #include <string.h> 00025 00026 00027 00028 namespace OpenRaw { 00029 00030 namespace Internals { 00031 00032 /* 00033 * The following structure stores basic information about one component. 00034 */ 00035 typedef struct JpegComponentInfo { 00036 /* 00037 * These values are fixed over the whole image. 00038 * They are read from the SOF marker. 00039 */ 00040 int16_t componentId; /* identifier for this component (0..255) */ 00041 int16_t componentIndex; /* its index in SOF or cPtr->compInfo[] */ 00042 00043 /* 00044 * Downsampling is not normally used in lossless JPEG, although 00045 * it is permitted by the JPEG standard (DIS). We set all sampling 00046 * factors to 1 in this program. 00047 */ 00048 int16_t hSampFactor; /* horizontal sampling factor */ 00049 int16_t vSampFactor; /* vertical sampling factor */ 00050 00051 /* 00052 * Huffman table selector (0..3). The value may vary 00053 * between scans. It is read from the SOS marker. 00054 */ 00055 int16_t dcTblNo; 00056 } JpegComponentInfo; 00057 00058 00059 /* 00060 * One of the following structures is created for each huffman coding 00061 * table. We use the same structure for encoding and decoding, so there 00062 * may be some extra fields for encoding that aren't used in the decoding 00063 * and vice-versa. 00064 */ 00065 struct HuffmanTable { 00066 /* 00067 * These two fields directly represent the contents of a JPEG DHT 00068 * marker 00069 */ 00070 uint8_t bits[17]; 00071 uint8_t huffval[256]; 00072 00073 /* 00074 * This field is used only during compression. It's initialized 00075 * FALSE when the table is created, and set TRUE when it's been 00076 * output to the file. 00077 */ 00078 bool sentTable; 00079 00080 /* 00081 * The remaining fields are computed from the above to allow more 00082 * efficient coding and decoding. These fields should be considered 00083 * private to the Huffman compression & decompression modules. 00084 */ 00085 uint16_t ehufco[256]; 00086 char ehufsi[256]; 00087 00088 uint16_t mincode[17]; 00089 int32_t maxcode[18]; 00090 int16_t valptr[17]; 00091 int32_t numbits[256]; 00092 int32_t value[256]; 00093 }; 00094 00095 /* 00096 * One of the following structures is used to pass around the 00097 * decompression information. 00098 */ 00099 struct DecompressInfo 00100 : public boost::noncopyable 00101 { 00102 DecompressInfo() 00103 : imageWidth(0), imageHeight(0), 00104 dataPrecision(0), compInfo(NULL), 00105 numComponents(0), 00106 compsInScan(0), 00107 Ss(0), Pt(0), 00108 restartInterval(0), restartInRows(0), 00109 restartRowsToGo(0), nextRestartNum(0) 00110 00111 { 00112 memset(&curCompInfo, 0, sizeof(curCompInfo)); 00113 memset(&MCUmembership, 0, sizeof(MCUmembership)); 00114 memset(&dcHuffTblPtrs, 0, sizeof(dcHuffTblPtrs)); 00115 } 00116 ~DecompressInfo() 00117 { 00118 int i; 00119 for(i = 0; i < 4; i++) { 00120 if(dcHuffTblPtrs[i]) { 00121 free(dcHuffTblPtrs[i]); 00122 } 00123 } 00124 if(compInfo) { 00125 free(compInfo); 00126 } 00127 } 00128 /* 00129 * Image width, height, and image data precision (bits/sample) 00130 * These fields are set by ReadFileHeader or ReadScanHeader 00131 */ 00132 int32_t imageWidth; 00133 int32_t imageHeight; 00134 int32_t dataPrecision; 00135 00136 /* 00137 * compInfo[i] describes component that appears i'th in SOF 00138 * numComponents is the # of color components in JPEG image. 00139 */ 00140 JpegComponentInfo *compInfo; 00141 int16_t numComponents; 00142 00143 /* 00144 * *curCompInfo[i] describes component that appears i'th in SOS. 00145 * compsInScan is the # of color components in current scan. 00146 */ 00147 JpegComponentInfo *curCompInfo[4]; 00148 int16_t compsInScan; 00149 00150 /* 00151 * MCUmembership[i] indexes the i'th component of MCU into the 00152 * curCompInfo array. 00153 */ 00154 int16_t MCUmembership[10]; 00155 00156 /* 00157 * ptrs to Huffman coding tables, or NULL if not defined 00158 */ 00159 HuffmanTable *dcHuffTblPtrs[4]; 00160 00161 /* 00162 * prediction seletion value (PSV) and point transform parameter (Pt) 00163 */ 00164 int32_t Ss; 00165 int32_t Pt; 00166 00167 /* 00168 * In lossless JPEG, restart interval shall be an integer 00169 * multiple of the number of MCU in a MCU row. 00170 */ 00171 int32_t restartInterval;/* MCUs per restart interval, 0 = no restart */ 00172 int32_t restartInRows; /*if > 0, MCU rows per restart interval; 0 = no restart*/ 00173 00174 /* 00175 * these fields are private data for the entropy decoder 00176 */ 00177 int32_t restartRowsToGo; /* MCUs rows left in this restart interval */ 00178 int16_t nextRestartNum; /* # of next RSTn marker (0..7) */ 00179 00180 private: 00182 DecompressInfo(const DecompressInfo& f); 00184 DecompressInfo & operator=(const DecompressInfo&); 00185 }; 00186 00187 } 00188 } 00189 00190 00191 #endif 00192