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