ljpegdecompressor.h

00001 /*
00002  * libopenraw - ljpegdecompressor.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_H__
00022 #define __OPENRAW_LJPEGDECOMPRESSOR_H__
00023 
00024 #include <stdint.h>
00025 
00026 #include <vector>
00027 
00028 #include <libopenraw/libopenraw.h>
00029 
00030 #include "exception.h"
00031 #include "decompressor.h"
00032 
00033 namespace OpenRaw {
00034 
00035 class RawData;
00036         
00037 namespace Internals {
00038 struct HuffmanTable;
00039 struct DecompressInfo;
00040 typedef int16_t ComponentType;
00041 typedef ComponentType *MCU;
00042 
00043 
00044 class LJpegDecompressor
00045     : public Decompressor
00046 {
00047 public:
00048     LJpegDecompressor(IO::Stream *,
00049                       RawContainer *);
00050     virtual ~LJpegDecompressor();
00051             
00059     virtual RawData *decompress(RawData *in = NULL);
00069     void setSlices(const std::vector<uint16_t> & slices);
00070     bool isSliced() const
00071         { 
00072             return m_slices.size() > 1; 
00073         }
00074 private:
00075             
00081     int32_t readBits(IO::Stream * s, uint16_t bitCount);
00082     int32_t show_bits8(IO::Stream * s);
00083     void flush_bits(uint16_t nbits);
00084     int32_t get_bits(uint16_t nbits);
00085     int32_t get_bit();
00086             
00090     typedef enum {
00091         M_SOF0 = 0xc0,
00092         M_SOF1 = 0xc1,
00093         M_SOF2 = 0xc2,
00094         M_SOF3 = 0xc3,
00095                 
00096         M_SOF5 = 0xc5,
00097         M_SOF6 = 0xc6,
00098         M_SOF7 = 0xc7,
00099 
00100         M_JPG = 0xc8,
00101         M_SOF9 = 0xc9,
00102         M_SOF10 = 0xca,
00103         M_SOF11 = 0xcb,
00104 
00105         M_SOF13 = 0xcd,
00106         M_SOF14 = 0xce,
00107         M_SOF15 = 0xcf,
00108 
00109         M_DHT = 0xc4,
00110 
00111         M_DAC = 0xcc,
00112 
00113         M_RST0 = 0xd0,
00114         M_RST1 = 0xd1,
00115         M_RST2 = 0xd2,
00116         M_RST3 = 0xd3,
00117         M_RST4 = 0xd4,
00118         M_RST5 = 0xd5,
00119         M_RST6 = 0xd6,
00120         M_RST7 = 0xd7,
00121 
00122         M_SOI = 0xd8,
00123         M_EOI = 0xd9,
00124         M_SOS = 0xda,
00125         M_DQT = 0xdb,
00126         M_DNL = 0xdc,
00127         M_DRI = 0xdd,
00128         M_DHP = 0xde,
00129         M_EXP = 0xdf,
00130 
00131         M_APP0 = 0xe0,
00132         M_APP15 = 0xef,
00133 
00134         M_JPG0 = 0xf0,
00135         M_JPG13 = 0xfd,
00136         M_COM = 0xfe,
00137 
00138         M_TEM = 0x01,
00139 
00140         M_ERROR = 0x100
00141     } JpegMarker;
00142 
00143     void DecoderStructInit (DecompressInfo *dcPtr) throw(DecodingException);
00144     void HuffDecoderInit (DecompressInfo *dcPtr) throw(DecodingException);
00145     void ProcessRestart (DecompressInfo *dcPtr) throw(DecodingException);
00146     void DecodeFirstRow(DecompressInfo *dcPtr,
00147                         MCU *curRowBuf);
00148     void DecodeImage(DecompressInfo *dcPtr);
00149     int32_t QuickPredict(int32_t col, int16_t curComp,
00150                          MCU *curRowBuf, MCU *prevRowBuf,
00151                          int32_t psv);
00152     void PmPutRow(MCU* RowBuf, int32_t numComp, int32_t numCol, int32_t Pt);
00153     void GetDht (DecompressInfo *dcPtr) throw(DecodingException);
00154     void GetDri (DecompressInfo *dcPtr) throw(DecodingException);
00155     void GetSof (DecompressInfo *dcPtr) throw(DecodingException);
00156     void GetSos (DecompressInfo *dcPtr) throw(DecodingException);
00157     JpegMarker ProcessTables (DecompressInfo *dcPtr);
00158     void ReadFileHeader (DecompressInfo *dcPtr) throw(DecodingException);
00159     int32_t ReadScanHeader (DecompressInfo *dcPtr);
00160     int32_t HuffDecode(HuffmanTable *htbl);
00161 
00162     std::vector<uint16_t> m_slices;
00163 
00164     MCU *m_mcuROW1, *m_mcuROW2;
00165     char *m_buf1,*m_buf2;
00166 
00168     void fillBitBuffer (IO::Stream * s, uint16_t nbits);
00169     uint16_t m_bitsLeft;
00170     uint32_t m_getBuffer;
00171     RawData *m_output;
00172 
00174     LJpegDecompressor(const LJpegDecompressor& f);
00176     LJpegDecompressor & operator=(const LJpegDecompressor&);
00177 };
00178 
00179 }
00180 }
00181 
00182 
00183 
00184 #endif
00185 /*
00186   Local Variables:
00187   mode:c++
00188   c-file-style:"stroustrup"
00189   c-file-offsets:((innamespace . 0))
00190   indent-tabs-mode:nil
00191   fill-column:80
00192   End:
00193 */

Generated on Sat Aug 15 16:52:19 2009 for libopenraw by  doxygen 1.5.9