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