]> Creatis software - gdcm.git/blob - src/jpeg/ljpg/jpeg.h
*FIX: gdcmjpeg -> gdcmljpeg
[gdcm.git] / src / jpeg / ljpg / jpeg.h
1 /*
2  * jpeg.h
3  *
4  * Basic jpeg data structure definitions.
5  */
6 /*
7  * $Id: jpeg.h,v 1.2 2003/10/29 18:24:40 malaterre Exp $
8  */
9 #ifndef _JPEG
10 #define _JPEG
11
12 /* a function referenced thru EXTERNs: */
13 #ifdef WIN32
14   #define GLOBAL(type)          __declspec( dllexport ) type
15 #else
16   #define GLOBAL(type)          type
17 #endif
18
19 typedef unsigned char   Uchar;
20 typedef unsigned short  Ushort;
21 typedef unsigned int    Uint;
22 typedef FILE *          StreamIN ;
23
24
25 /*
26  * The following structure stores basic information about one component.
27  */
28 typedef struct JpegComponentInfo 
29 {
30     /*
31      * These values are fixed over the whole image.
32      * They are read from the SOF marker.
33      */
34     short componentId;          /* identifier for this component (0..255) */
35     short componentIndex;       /* its index in SOF or cPtr->compInfo[]   */
36
37     /*
38      * Downsampling is not normally used in lossless JPEG, although
39      * it is permitted by the JPEG standard (DIS). We set all sampling 
40      * factors to 1 in this program.
41      */
42     short hSampFactor;          /* horizontal sampling factor */
43     short vSampFactor;          /* vertical sampling factor   */
44
45     /*
46      * Huffman table selector (0..3). The value may vary
47      * between scans. It is read from the SOS marker.
48      */
49     short dcTblNo;
50 } JpegComponentInfo;
51
52
53 /*
54  * One of the following structures is created for each huffman coding
55  * table.  We use the same structure for encoding and decoding, so there
56  * may be some extra fields for encoding that aren't used in the decoding
57  * and vice-versa.
58  */
59 typedef struct HuffmanTable 
60 {
61     /*
62      * These two fields directly represent the contents of a JPEG DHT
63      * marker
64      */
65     Uchar bits[17];
66     Uchar huffval[256];
67
68     /*
69      * This field is used only during compression.  It's initialized
70      * FALSE when the table is created, and set TRUE when it's been
71      * output to the file.
72      */
73     int sentTable;
74
75     /*
76      * The remaining fields are computed from the above to allow more
77      * efficient coding and decoding.  These fields should be considered
78      * private to the Huffman compression & decompression modules.
79      */
80     Ushort ehufco[256];
81     char ehufsi[256];
82
83     Ushort mincode[17];
84     int maxcode[18];
85     short valptr[17];
86     int numbits[256];
87     int value[256];
88 } HuffmanTable;
89
90 /*
91  * One of the following structures is used to pass around the
92  * compression information.
93  */
94
95
96
97 /*
98  * One of the following structures is used to pass around the
99  * decompression information.
100  */
101 typedef struct DecompressInfo 
102 {
103     /*
104      * Image width, height, and image data precision (bits/sample)
105      * These fields are set by ReadFileHeader or ReadScanHeader
106      */ 
107     int imageWidth;
108     int imageHeight;
109     int dataPrecision;
110
111     /*
112      * compInfo[i] describes component that appears i'th in SOF
113      * numComponents is the # of color components in JPEG image.
114      */
115     JpegComponentInfo compInfo[4];
116     short numComponents;
117
118     /*
119      * *curCompInfo[i] describes component that appears i'th in SOS.
120      * compsInScan is the # of color components in current scan.
121      */
122     JpegComponentInfo *curCompInfo[4];
123     short compsInScan;
124
125     /*
126      * MCUmembership[i] indexes the i'th component of MCU into the
127      * curCompInfo array.
128      */
129     short MCUmembership[10];
130
131     /*
132      * ptrs to Huffman coding tables, or NULL if not defined
133      */
134     HuffmanTable *dcHuffTblPtrs[4];
135
136     /* 
137      * prediction seletion value (PSV) and point transform parameter (Pt)
138      */
139     int Ss;
140     int Pt;
141
142     /*
143      * In lossless JPEG, restart interval shall be an integer
144      * multiple of the number of MCU in a MCU row.
145      */
146     int restartInterval;/* MCUs per restart interval, 0 = no restart */
147     int restartInRows; /*if > 0, MCU rows per restart interval; 0 = no restart*/
148
149     /*
150      * these fields are private data for the entropy decoder
151      */
152     int restartRowsToGo;        /* MCUs rows left in this restart interval */
153     short nextRestartNum;       /* # of next RSTn marker (0..7) */
154
155     int  error;                 /* an ERROR flag */
156
157 } DecompressInfo;
158
159
160 /*
161  *--------------------------------------------------------------
162  *
163  * swap --
164  *
165  *      Swap the contents stored in a and b.
166  *      "type" is the variable type of a and b.
167  *
168  * Results:
169  *      The values in a and b are swapped.
170  *
171  * Side effects:
172  *      None.
173  *
174  *--------------------------------------------------------------
175  */
176 #define swap(type,a,b) {type c; c=(a); (a)=(b); (b)=c;}
177
178 #define MEMSET(s,c,n) memset((void *)(s),(int)(c),(int)(n))
179 #define MEMCPY(s1,s2,n) memcpy((void *)(s1),(void *)(s2),(int)(n))
180
181 /*
182  * Lossless JPEG specifies data precision to be from 2 to 16 bits/sample.
183  */ 
184 #define MinPrecisionBits 2
185 #define MaxPrecisionBits 16
186 #define MinPrecisionValue 2
187 #define MaxPrecisionValue 65535
188
189 #endif /* _JPEG */
190