00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
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);
00060 void setSlices(const std::vector<uint16_t> & slices,
00061 std::vector<uint16_t>::size_type idx = 0);
00062 bool isSliced() const
00063 {
00064 return m_slices.size() > 1;
00065 }
00066 private:
00067
00073 int32_t readBits(IO::Stream * s, uint16_t bitCount);
00074 int32_t show_bits8(IO::Stream * s);
00075 void flush_bits(uint16_t nbits);
00076 int32_t get_bits(uint16_t nbits);
00077 int32_t get_bit();
00078
00082 typedef enum {
00083 M_SOF0 = 0xc0,
00084 M_SOF1 = 0xc1,
00085 M_SOF2 = 0xc2,
00086 M_SOF3 = 0xc3,
00087
00088 M_SOF5 = 0xc5,
00089 M_SOF6 = 0xc6,
00090 M_SOF7 = 0xc7,
00091
00092 M_JPG = 0xc8,
00093 M_SOF9 = 0xc9,
00094 M_SOF10 = 0xca,
00095 M_SOF11 = 0xcb,
00096
00097 M_SOF13 = 0xcd,
00098 M_SOF14 = 0xce,
00099 M_SOF15 = 0xcf,
00100
00101 M_DHT = 0xc4,
00102
00103 M_DAC = 0xcc,
00104
00105 M_RST0 = 0xd0,
00106 M_RST1 = 0xd1,
00107 M_RST2 = 0xd2,
00108 M_RST3 = 0xd3,
00109 M_RST4 = 0xd4,
00110 M_RST5 = 0xd5,
00111 M_RST6 = 0xd6,
00112 M_RST7 = 0xd7,
00113
00114 M_SOI = 0xd8,
00115 M_EOI = 0xd9,
00116 M_SOS = 0xda,
00117 M_DQT = 0xdb,
00118 M_DNL = 0xdc,
00119 M_DRI = 0xdd,
00120 M_DHP = 0xde,
00121 M_EXP = 0xdf,
00122
00123 M_APP0 = 0xe0,
00124 M_APP15 = 0xef,
00125
00126 M_JPG0 = 0xf0,
00127 M_JPG13 = 0xfd,
00128 M_COM = 0xfe,
00129
00130 M_TEM = 0x01,
00131
00132 M_ERROR = 0x100
00133 } JpegMarker;
00134
00135 void DecoderStructInit (DecompressInfo *dcPtr) throw(DecodingException);
00136 void HuffDecoderInit (DecompressInfo *dcPtr) throw(DecodingException);
00137 void ProcessRestart (DecompressInfo *dcPtr) throw(DecodingException);
00138 void DecodeFirstRow(DecompressInfo *dcPtr,
00139 MCU *curRowBuf);
00140 void DecodeImage(DecompressInfo *dcPtr);
00141 int32_t QuickPredict(int32_t col, int16_t curComp,
00142 MCU *curRowBuf, MCU *prevRowBuf,
00143 int32_t psv);
00144 void PmPutRow(MCU* RowBuf, int32_t numComp, int32_t numCol, int32_t Pt);
00145 void GetDht (DecompressInfo *dcPtr) throw(DecodingException);
00146 void GetDri (DecompressInfo *dcPtr) throw(DecodingException);
00147 void GetSof (DecompressInfo *dcPtr) throw(DecodingException);
00148 void GetSos (DecompressInfo *dcPtr) throw(DecodingException);
00149 JpegMarker ProcessTables (DecompressInfo *dcPtr);
00150 void ReadFileHeader (DecompressInfo *dcPtr) throw(DecodingException);
00151 int32_t ReadScanHeader (DecompressInfo *dcPtr);
00152 int32_t HuffDecode(HuffmanTable *htbl);
00153
00154 std::vector<uint16_t> m_slices;
00155
00156 MCU *m_mcuROW1, *m_mcuROW2;
00157 char *m_buf1,*m_buf2;
00158
00160 void fillBitBuffer (IO::Stream * s, uint16_t nbits);
00161 uint16_t m_bitsLeft;
00162 uint32_t m_getBuffer;
00163 RawData *m_output;
00164
00166 LJpegDecompressor(const LJpegDecompressor& f);
00168 LJpegDecompressor & operator=(const LJpegDecompressor&);
00169 };
00170
00171 }
00172 }
00173
00174
00175
00176 #endif