libopenraw
ljpegdecompressor_priv.hpp
1/*
2 * libopenraw - ljpegdecompressor_priv.h
3 *
4 * Copyright (C) 2007-2013 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 OR_INTERNALS_LJPEGDECOMPRESSOR_PRIV_H
22#define OR_INTERNALS_LJPEGDECOMPRESSOR_PRIV_H
23
24#include <string.h>
25
26
27
28namespace OpenRaw {
29namespace Internals {
30
31/*
32* The following structure stores basic information about one component.
33*/
34typedef struct JpegComponentInfo {
35 /*
36 * These values are fixed over the whole image.
37 * They are read from the SOF marker.
38 */
39 int16_t componentId; /* identifier for this component (0..255) */
40 int16_t componentIndex; /* its index in SOF or cPtr->compInfo[] */
41
42 /*
43 * Downsampling is not normally used in lossless JPEG, although
44 * it is permitted by the JPEG standard (DIS). We set all sampling
45 * factors to 1 in this program.
46 */
47 int16_t hSampFactor; /* horizontal sampling factor */
48 int16_t vSampFactor; /* vertical sampling factor */
49
50 /*
51 * Huffman table selector (0..3). The value may vary
52 * between scans. It is read from the SOS marker.
53 */
54 int16_t dcTblNo;
56
57
58/*
59* One of the following structures is created for each huffman coding
60* table. We use the same structure for encoding and decoding, so there
61* may be some extra fields for encoding that aren't used in the decoding
62* and vice-versa.
63*/
65 /*
66 * These two fields directly represent the contents of a JPEG DHT
67 * marker
68 */
69 uint8_t bits[17];
70 uint8_t huffval[256];
71
72 /*
73 * This field is used only during compression. It's initialized
74 * FALSE when the table is created, and set TRUE when it's been
75 * output to the file.
76 */
77 bool sentTable;
78
79 /*
80 * The remaining fields are computed from the above to allow more
81 * efficient coding and decoding. These fields should be considered
82 * private to the Huffman compression & decompression modules.
83 */
84 uint16_t ehufco[256];
85 char ehufsi[256];
86
87 uint16_t mincode[17];
88 int32_t maxcode[18];
89 int16_t valptr[17];
90 int32_t numbits[256];
91 int32_t value[256];
92};
93
94/*
95 * One of the following structures is used to pass around the
96 * decompression information.
97 */
98struct DecompressInfo
99{
100 // non copyable
101 DecompressInfo(const DecompressInfo&) = delete;
102 DecompressInfo& operator=(const DecompressInfo&) = delete;
103
104 DecompressInfo()
105 : imageWidth(0), imageHeight(0),
106 dataPrecision(0), compInfo(NULL),
107 numComponents(0),
108 compsInScan(0),
109 Ss(0), Pt(0),
110 restartInterval(0), restartInRows(0),
111 restartRowsToGo(0), nextRestartNum(0)
112
113 {
114 memset(&curCompInfo, 0, sizeof(curCompInfo));
115 memset(&MCUmembership, 0, sizeof(MCUmembership));
116 memset(&dcHuffTblPtrs, 0, sizeof(dcHuffTblPtrs));
117 }
118 ~DecompressInfo()
119 {
120 int i;
121 for(i = 0; i < 4; i++) {
122 if(dcHuffTblPtrs[i]) {
123 free(dcHuffTblPtrs[i]);
124 }
125 }
126 if(compInfo) {
127 free(compInfo);
128 }
129 }
130 /*
131 * Image width, height, and image data precision (bits/sample)
132 * These fields are set by ReadFileHeader or ReadScanHeader
133 */
134 int32_t imageWidth;
135 int32_t imageHeight;
136 int32_t dataPrecision;
137
138 /*
139 * compInfo[i] describes component that appears i'th in SOF
140 * numComponents is the # of color components in JPEG image.
141 */
142 JpegComponentInfo *compInfo;
143 int16_t numComponents;
144
145 /*
146 * *curCompInfo[i] describes component that appears i'th in SOS.
147 * compsInScan is the # of color components in current scan.
148 */
149 JpegComponentInfo *curCompInfo[4];
150 int16_t compsInScan;
151
152 /*
153 * MCUmembership[i] indexes the i'th component of MCU into the
154 * curCompInfo array.
155 */
156 int16_t MCUmembership[10];
157
158 /*
159 * ptrs to Huffman coding tables, or NULL if not defined
160 */
161 HuffmanTable *dcHuffTblPtrs[4];
162
163 /*
164 * prediction seletion value (PSV) and point transform parameter (Pt)
165 */
166 int32_t Ss;
167 int32_t Pt;
168
169 /*
170 * In lossless JPEG, restart interval shall be an integer
171 * multiple of the number of MCU in a MCU row.
172 */
173 int32_t restartInterval;/* MCUs per restart interval, 0 = no restart */
174 int32_t restartInRows; /*if > 0, MCU rows per restart interval; 0 = no restart*/
175
176 /*
177 * these fields are private data for the entropy decoder
178 */
179 int32_t restartRowsToGo; /* MCUs rows left in this restart interval */
180 int16_t nextRestartNum; /* # of next RSTn marker (0..7) */
181};
182
183}
184}
185
186
187#endif
188
CIFF is the container for CRW files. It is an attempt from Canon to make this a standard....
Definition arwfile.cpp:30