1
#ifndef LJPEG_DECOMPRESSOR_H
2
#define LJPEG_DECOMPRESSOR_H
4
#include "RawDecoder.h"
5
#include "BitPumpMSB.h"
7
RawSpeed - RAW file decoder.
9
Copyright (C) 2009 Klaus Post
11
This library is free software; you can redistribute it and/or
12
modify it under the terms of the GNU Lesser General Public
13
License as published by the Free Software Foundation; either
14
version 2 of the License, or (at your option) any later version.
16
This library is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
Lesser General Public License for more details.
21
You should have received a copy of the GNU Lesser General Public
22
License along with this library; if not, write to the Free Software
23
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25
http://www.klauspost.com
29
* The following enum and two structs are stolen from the IJG JPEG library
30
* Comments added by tm. See Copyright in LJpegDecompressor.cpp
35
typedef enum { /* JPEG marker codes */
37
M_SOF0 = 0xc0, /* baseline DCT */
38
M_SOF1 = 0xc1, /* extended sequential DCT */
39
M_SOF2 = 0xc2, /* progressive DCT */
40
M_SOF3 = 0xc3, /* lossless (sequential) */
42
M_SOF5 = 0xc5, /* differential sequential DCT */
43
M_SOF6 = 0xc6, /* differential progressive DCT */
44
M_SOF7 = 0xc7, /* differential lossless */
46
M_JPG = 0xc8, /* JPEG extensions */
47
M_SOF9 = 0xc9, /* extended sequential DCT */
48
M_SOF10 = 0xca, /* progressive DCT */
49
M_SOF11 = 0xcb, /* lossless (sequential) */
51
M_SOF13 = 0xcd, /* differential sequential DCT */
52
M_SOF14 = 0xce, /* differential progressive DCT */
53
M_SOF15 = 0xcf, /* differential lossless */
55
M_DHT = 0xc4, /* define Huffman tables */
57
M_DAC = 0xcc, /* define arithmetic conditioning table */
59
M_RST0 = 0xd0, /* restart */
60
M_RST1 = 0xd1, /* restart */
61
M_RST2 = 0xd2, /* restart */
62
M_RST3 = 0xd3, /* restart */
63
M_RST4 = 0xd4, /* restart */
64
M_RST5 = 0xd5, /* restart */
65
M_RST6 = 0xd6, /* restart */
66
M_RST7 = 0xd7, /* restart */
68
M_SOI = 0xd8, /* start of image */
69
M_EOI = 0xd9, /* end of image */
70
M_SOS = 0xda, /* start of scan */
71
M_DQT = 0xdb, /* define quantization tables */
72
M_DNL = 0xdc, /* define number of lines */
73
M_DRI = 0xdd, /* define restart interval */
74
M_DHP = 0xde, /* define hierarchical progression */
75
M_EXP = 0xdf, /* expand reference image(s) */
77
M_APP0 = 0xe0, /* application marker, used for JFIF */
78
M_APP1 = 0xe1, /* application marker */
79
M_APP2 = 0xe2, /* application marker */
80
M_APP3 = 0xe3, /* application marker */
81
M_APP4 = 0xe4, /* application marker */
82
M_APP5 = 0xe5, /* application marker */
83
M_APP6 = 0xe6, /* application marker */
84
M_APP7 = 0xe7, /* application marker */
85
M_APP8 = 0xe8, /* application marker */
86
M_APP9 = 0xe9, /* application marker */
87
M_APP10 = 0xea, /* application marker */
88
M_APP11 = 0xeb, /* application marker */
89
M_APP12 = 0xec, /* application marker */
90
M_APP13 = 0xed, /* application marker */
91
M_APP14 = 0xee, /* application marker, used by Adobe */
92
M_APP15 = 0xef, /* application marker */
94
M_JPG0 = 0xf0, /* reserved for JPEG extensions */
95
M_JPG13 = 0xfd, /* reserved for JPEG extensions */
96
M_COM = 0xfe, /* comment */
98
M_TEM = 0x01, /* temporary use */
105
* The following structure stores basic information about one component.
107
typedef struct JpegComponentInfo {
109
* These values are fixed over the whole image.
110
* They are read from the SOF marker.
112
uint32 componentId; /* identifier for this component (0..255) */
113
uint32 componentIndex; /* its index in SOF or cPtr->compInfo[] */
116
* Huffman table selector (0..3). The value may vary
117
* between scans. It is read from the SOS marker.
120
uint32 superH; // Horizontal Supersampling
121
uint32 superV; // Vertical Supersampling
125
* One of the following structures is created for each huffman coding
126
* table. We use the same structure for encoding and decoding, so there
127
* may be some extra fields for encoding that aren't used in the decoding
131
struct HuffmanTable {
133
* These two fields directly represent the contents of a JPEG DHT
140
* The remaining fields are computed from the above to allow more
141
* efficient coding and decoding. These fields should be considered
142
* private to the Huffman compression & decompression modules.
145
ushort16 mincode[17];
155
SOFInfo() { w = h = cps = prec = 0; initialized = false;};
156
~SOFInfo() {initialized = false;};
159
uint32 cps; // Components
160
uint32 prec; // Precision
161
JpegComponentInfo compInfo[4];
165
class LJpegDecompressor
168
LJpegDecompressor(FileMap* file, RawImage img);
169
virtual ~LJpegDecompressor(void);
170
virtual void startDecoder(uint32 offset, uint32 size, uint32 offsetX, uint32 offsetY);
171
virtual void getSOF(SOFInfo* i, uint32 offset, uint32 size);
172
bool mDNGCompatible; // DNG v1.0.x compatibility
173
bool mUseBigtable; // Use only for large images
174
virtual void addSlices(vector<int> slices) {slicesW=slices;}; // CR2 slices.
176
virtual void parseSOF(SOFInfo* i);
177
virtual void parseSOS();
178
virtual void createHuffmanTable(HuffmanTable *htbl);
179
virtual void createBigTable(HuffmanTable *htbl);
180
virtual void decodeScan() {ThrowRDE("LJpegDecompressor: No Scan decoder found");};
181
JpegMarker getNextMarker(bool allowskip);
183
int HuffDecode(HuffmanTable *htbl);
193
uint32 offX, offY; // Offset into image where decoding should start
194
uint32 skipX, skipY; // Tile is larger than output, skip these border pixels
195
HuffmanTable huff[4];
198
} // namespace RawSpeed