libopenraw
ljpegdecompressor.h
1 /*
2  * libopenraw - ljpegdecompressor.h
3  *
4  * Copyright (C) 2007 Hubert Figuiere
5  *
6  * This library is free software: you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3 of
9  * the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef __OPENRAW_LJPEGDECOMPRESSOR_H__
22 #define __OPENRAW_LJPEGDECOMPRESSOR_H__
23 
24 #include <stdint.h>
25 
26 #include <vector>
27 
28 #include <libopenraw/libopenraw.h>
29 
30 #include "exception.h"
31 #include "decompressor.h"
32 
33 namespace OpenRaw {
34 
35 class RawData;
36 
37 namespace Internals {
38 struct HuffmanTable;
39 struct DecompressInfo;
40 typedef int16_t ComponentType;
41 typedef ComponentType *MCU;
42 
43 
45  : public Decompressor
46 {
47 public:
49  RawContainer *);
50  virtual ~LJpegDecompressor();
51 
59  virtual RawData *decompress(RawData *in = NULL);
69  void setSlices(const std::vector<uint16_t> & slices);
70  bool isSliced() const
71  {
72  return m_slices.size() > 1;
73  }
74 private:
75 
81  int32_t readBits(IO::Stream * s, uint16_t bitCount);
82  int32_t show_bits8(IO::Stream * s);
83  void flush_bits(uint16_t nbits);
84  int32_t get_bits(uint16_t nbits);
85  int32_t get_bit();
86 
90  typedef enum {
91  M_SOF0 = 0xc0,
92  M_SOF1 = 0xc1,
93  M_SOF2 = 0xc2,
94  M_SOF3 = 0xc3,
95 
96  M_SOF5 = 0xc5,
97  M_SOF6 = 0xc6,
98  M_SOF7 = 0xc7,
99 
100  M_JPG = 0xc8,
101  M_SOF9 = 0xc9,
102  M_SOF10 = 0xca,
103  M_SOF11 = 0xcb,
104 
105  M_SOF13 = 0xcd,
106  M_SOF14 = 0xce,
107  M_SOF15 = 0xcf,
108 
109  M_DHT = 0xc4,
110 
111  M_DAC = 0xcc,
112 
113  M_RST0 = 0xd0,
114  M_RST1 = 0xd1,
115  M_RST2 = 0xd2,
116  M_RST3 = 0xd3,
117  M_RST4 = 0xd4,
118  M_RST5 = 0xd5,
119  M_RST6 = 0xd6,
120  M_RST7 = 0xd7,
121 
122  M_SOI = 0xd8,
123  M_EOI = 0xd9,
124  M_SOS = 0xda,
125  M_DQT = 0xdb,
126  M_DNL = 0xdc,
127  M_DRI = 0xdd,
128  M_DHP = 0xde,
129  M_EXP = 0xdf,
130 
131  M_APP0 = 0xe0,
132  M_APP15 = 0xef,
133 
134  M_JPG0 = 0xf0,
135  M_JPG13 = 0xfd,
136  M_COM = 0xfe,
137 
138  M_TEM = 0x01,
139 
140  M_ERROR = 0x100
141  } JpegMarker;
142 
143  void DecoderStructInit (DecompressInfo *dcPtr) throw(DecodingException);
144  void HuffDecoderInit (DecompressInfo *dcPtr) throw(DecodingException);
145  void ProcessRestart (DecompressInfo *dcPtr) throw(DecodingException);
146  void DecodeFirstRow(DecompressInfo *dcPtr,
147  MCU *curRowBuf);
148  void DecodeImage(DecompressInfo *dcPtr);
149  int32_t QuickPredict(int32_t col, int16_t curComp,
150  MCU *curRowBuf, MCU *prevRowBuf,
151  int32_t psv);
152  void PmPutRow(MCU* RowBuf, int32_t numComp, int32_t numCol, int32_t Pt);
153  void GetDht (DecompressInfo *dcPtr) throw(DecodingException);
154  void GetDri (DecompressInfo *dcPtr) throw(DecodingException);
155  void GetSof (DecompressInfo *dcPtr) throw(DecodingException);
156  void GetSos (DecompressInfo *dcPtr) throw(DecodingException);
157  JpegMarker ProcessTables (DecompressInfo *dcPtr);
158  void ReadFileHeader (DecompressInfo *dcPtr) throw(DecodingException);
159  int32_t ReadScanHeader (DecompressInfo *dcPtr);
160  int32_t HuffDecode(HuffmanTable *htbl);
161 
162  std::vector<uint16_t> m_slices;
163 
164  MCU *m_mcuROW1, *m_mcuROW2;
165  char *m_buf1,*m_buf2;
166 
168  void fillBitBuffer (IO::Stream * s, uint16_t nbits);
169  uint16_t m_bitsLeft;
170  uint32_t m_getBuffer;
171  RawData *m_output;
172 
176  LJpegDecompressor & operator=(const LJpegDecompressor&);
177 };
178 
179 }
180 }
181 
182 
183 
184 #endif
185 /*
186  Local Variables:
187  mode:c++
188  c-file-style:"stroustrup"
189  c-file-offsets:((innamespace . 0))
190  indent-tabs-mode:nil
191  fill-column:80
192  End:
193 */