libopenraw  0.3.7
ljpegdecompressor.hpp
1 /* -*- Mode: C++ -*- */
2 /*
3  * libopenraw - ljpegdecompressor.h
4  *
5  * Copyright (C) 2007-2022 Hubert Figuière
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 #pragma once
23 
24 #include <stddef.h>
25 #include <sys/types.h>
26 #include <stdint.h>
27 
28 #include <vector>
29 
30 #include "decompressor.hpp"
31 
32 namespace OpenRaw {
33 
34 class RawData;
35 
36 namespace Internals {
37 
38 class Stream;
39 class RawContainer;
40 struct HuffmanTable;
41 struct DecompressInfo;
42 
43 typedef int16_t ComponentType;
44 typedef ComponentType *MCU;
45 
46 
48  : public Decompressor
49 {
50 public:
52  RawContainer *);
53  virtual ~LJpegDecompressor();
54 
58  virtual RawDataPtr decompress() override;
68  void setSlices(const std::vector<uint16_t> & slices);
69  bool isSliced() const
70  {
71  return m_slices.size() > 1;
72  }
73 private:
74 
80  int32_t readBits(IO::Stream * s, uint16_t bitCount);
81  int32_t show_bits8(IO::Stream * s);
82  void flush_bits(uint16_t nbits);
83  int32_t get_bits(uint16_t nbits);
84  int32_t get_bit();
85 
89  typedef enum {
90  M_SOF0 = 0xc0,
91  M_SOF1 = 0xc1,
92  M_SOF2 = 0xc2,
93  M_SOF3 = 0xc3,
94 
95  M_SOF5 = 0xc5,
96  M_SOF6 = 0xc6,
97  M_SOF7 = 0xc7,
98 
99  M_JPG = 0xc8,
100  M_SOF9 = 0xc9,
101  M_SOF10 = 0xca,
102  M_SOF11 = 0xcb,
103 
104  M_SOF13 = 0xcd,
105  M_SOF14 = 0xce,
106  M_SOF15 = 0xcf,
107 
108  M_DHT = 0xc4,
109 
110  M_DAC = 0xcc,
111 
112  M_RST0 = 0xd0,
113  M_RST1 = 0xd1,
114  M_RST2 = 0xd2,
115  M_RST3 = 0xd3,
116  M_RST4 = 0xd4,
117  M_RST5 = 0xd5,
118  M_RST6 = 0xd6,
119  M_RST7 = 0xd7,
120 
121  M_SOI = 0xd8,
122  M_EOI = 0xd9,
123  M_SOS = 0xda,
124  M_DQT = 0xdb,
125  M_DNL = 0xdc,
126  M_DRI = 0xdd,
127  M_DHP = 0xde,
128  M_EXP = 0xdf,
129 
130  M_APP0 = 0xe0,
131  M_APP15 = 0xef,
132 
133  M_JPG0 = 0xf0,
134  M_JPG13 = 0xfd,
135  M_COM = 0xfe,
136 
137  M_TEM = 0x01,
138 
139  M_ERROR = 0x100
140  } JpegMarker;
141 
142  void DecoderStructInit (DecompressInfo *dcPtr) noexcept(false);
143  void HuffDecoderInit (DecompressInfo *dcPtr) noexcept(false);
144  void ProcessRestart (DecompressInfo *dcPtr) noexcept(false);
145  void DecodeFirstRow(DecompressInfo *dcPtr,
146  MCU *curRowBuf);
147  void DecodeImage(DecompressInfo *dcPtr);
148  int32_t QuickPredict(int32_t col, int16_t curComp,
149  MCU *curRowBuf, MCU *prevRowBuf,
150  int32_t psv);
151  void PmPutRow(MCU* RowBuf, int32_t numComp, int32_t numCol, int32_t Pt);
152  void GetDht (DecompressInfo *dcPtr) noexcept(false);
153  void GetDri (DecompressInfo *dcPtr) noexcept(false);
154  void GetSof (DecompressInfo *dcPtr) noexcept(false);
155  void GetSos (DecompressInfo *dcPtr) noexcept(false);
156  JpegMarker ProcessTables (DecompressInfo *dcPtr);
157  void ReadFileHeader (DecompressInfo *dcPtr) noexcept(false);
158  int32_t ReadScanHeader (DecompressInfo *dcPtr);
159  int32_t HuffDecode(HuffmanTable *htbl);
160 
161  std::vector<uint16_t> m_slices;
162 
163  MCU *m_mcuROW1, *m_mcuROW2;
164  MCU m_buf1, m_buf2;
165 
167  void fillBitBuffer (IO::Stream * s, uint16_t nbits);
168  uint16_t m_bitsLeft;
169  uint32_t m_getBuffer;
170  RawDataPtr m_output;
171 
173  LJpegDecompressor(const LJpegDecompressor& f) = delete;
174  LJpegDecompressor & operator=(const LJpegDecompressor&) = delete;
175 };
176 
177 }
178 }
179 
180 /*
181  Local Variables:
182  mode:c++
183  c-file-style:"stroustrup"
184  c-file-offsets:((innamespace . 0))
185  indent-tabs-mode:nil
186  fill-column:80
187  End:
188 */
base virtual class for IO
Definition: stream.hpp:44
void setSlices(const std::vector< uint16_t > &slices)
virtual RawDataPtr decompress() override
Generic interface for the RAW file container.
Global namespace for libopenraw.
Definition: arwfile.cpp:29