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 
59  virtual RawDataPtr decompress() override;
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) noexcept(false);
144  void HuffDecoderInit (DecompressInfo *dcPtr) noexcept(false);
145  void ProcessRestart (DecompressInfo *dcPtr) noexcept(false);
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) noexcept(false);
154  void GetDri (DecompressInfo *dcPtr) noexcept(false);
155  void GetSof (DecompressInfo *dcPtr) noexcept(false);
156  void GetSos (DecompressInfo *dcPtr) noexcept(false);
157  JpegMarker ProcessTables (DecompressInfo *dcPtr);
158  void ReadFileHeader (DecompressInfo *dcPtr) noexcept(false);
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  RawDataPtr m_output;
172 
174  LJpegDecompressor(const LJpegDecompressor& f) = delete;
175  LJpegDecompressor & operator=(const LJpegDecompressor&) = delete;
176 };
177 
178 }
179 }
180 
181 
182 
183 #endif
184 /*
185  Local Variables:
186  mode:c++
187  c-file-style:"stroustrup"
188  c-file-offsets:((innamespace . 0))
189  indent-tabs-mode:nil
190  fill-column:80
191  End:
192 */
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 RawDataPtr decompress() override
void setSlices(const std::vector< uint16_t > &slices)
base virtual class for IO
Definition: stream.hpp:41