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