ljpegdecompressor_priv.h

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

Generated on Sun Mar 23 09:28:21 2008 for libopenraw by  doxygen 1.5.5