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