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