1 //  ----------------------------------------------------------------------------
2 //  MODULE    : FlashPixJPEG.h
3 //  LANGUAGE  : C
4 //  CREATOR   : Yue Zhang
5 //  CREAT. DATE : Thursday, March 28, 1996
6 //  DESCRIPTION : This file contains declarations of JPEG functions called by
7 //          FlashPix based on HP JPEG code.
8 //  COMMENTS  : The functions calls include two parts, encoder and decoder.
9 //  ----------------------------------------------------------------------------
10 //  Copyright (c) 1999 Digital Imaging Group, Inc.
11 //  For conditions of distribution and use, see copyright notice
12 //  in Flashpix.h
13 //  ----------------------------------------------------------------------------
14   #ifndef FlashPixJPEG_h
15   #define FlashPixJPEG_h
16 //  ----------------------------------------------------------------------------
17 
18 //  Includes
19 //  --------
20   #include "decoder.h"
21   #include "enctile.h"
22   #include "encoder.h"
23   #include "public.h"
24 
25 //  Constants
26 //  ---------
27   /*#ifndef BYTE
28   #define BYTE  unsigned char
29   #define LPBYTE  BYTE *
30   #endif
31 
32   // Define decoder method
33   #define ENTROPY_ONLY    0
34   #define ENTROPY_AND_HEADER  1
35 
36   #define CHEN_DCT    0
37   #define WINOGRAD    1
38   #define PRUNED_WINOGRAD   2
39 
40 
41 //  Types Declarations from HP code enctile.h
42 //  ------------------------------------------
43   typedef struct {
44       unsigned short ehufcode[256];   // ehufcode[i]=Huffman code for value i
45       int ehufsize[256];              // number of bits in ehufcode[i]
46   } HUFFMAN_TABLE;
47 
48   typedef struct {
49     HUFFMAN_TABLE luminanceDCHuffman;
50     HUFFMAN_TABLE luminanceACHuffman;
51     HUFFMAN_TABLE chrominanceDCHuffman;
52     HUFFMAN_TABLE chrominanceACHuffman;
53     int luminanceQuantization[64];
54     int chrominanceQuantization[64];
55     int threshLuminanceQuantization[64];
56     int threshChrominanceQuantization[64];
57     int en_last_dc[4];
58   }  JPEG_STRUCT;
59 
60   typedef struct {
61     int width;     // tile width
62     int height;    // tile height
63     int components; // # of components: 1-4
64     int *Hsamp, *Vsamp;  // one pair of <Hsamp,Vsamp> subsampling factors per component
65     int iflag;     // Interleave-flag: 1/0= Interleaved/Non-interleaved
66     unsigned char *data; // points to image/compressed data
67   } TILE_DATA;
68 
69   typedef struct {
70     BYTE      subsampling;  // stored in FPX tile header format
71     int       iHsamp[4];    // same thing, but in the format the
72     int       iVsamp[4];    // encoder prefers
73     JPEG_STRUCT   jpegStruct;   // used by the encoder to store tables
74     BYTE      ssDisabled;   // if non-zero, internal subsampling is
75                     // disabled
76     BYTE      YCrCbDisabled;  // if non-zero, internal YCrCb is disabled
77     int       xPixels;    // x dimension of a tile in pixels
78     int       yPixels;    // y dimension of a tile in pixels
79     int       bytes;      // number of bytes per pixel
80     int       qFactor;    // the quality level of the encoding
81     TILE_DATA   tile_data;
82     int       nu_huff;    // # of Huffman Tables (4, two DC-AC sets)
83     int       nu_qtables;   // # of Q-tables (a max of 4 tables)
84     unsigned char *scratch;   // place to hold rotated/subsampled data
85     unsigned char *header;    // place to hold the JPEG header
86     long      headerBytes;  // how big is the header anyway?
87   } ENCODER_STRUCT;
88 
89   #define ENCODER ENCODER_STRUCT*
90 
91 
92   //  Types Declarations from HP code decoder.h
93   //  ------------------------------------------
94   typedef struct _HUFFMAN_TREE
95   {                       // Huffman tree as suggested by JPEG
96       int mincode[8];             // mincode[i]=min code with 8+i+1 bit length
97       int maxcode[8];             // maxcode[i]=max code with 8+i+1 bit length
98                                      -1 if no code with this length
99                                   // min/maxcode are inclusive and only the
100                                      last 8-bit are stored in min/maxcode
101       int valptr[8];              // (first index (of mincode) to the array
102                                      'huffval' in HUFFMAN_TABLE,i.e Huffman
103                                      value for codeword 'mincode') - mincode
104   } HUFFMAN_TREE;
105 
106   typedef struct _HUFFMAN_ELEM
107   {
108       unsigned char codelen;      // number of bits (1-8) in the code word,
109                                      0 means >8 bits, use hufftree instead
110       unsigned char value;        // Huffman value if codelen <= 8
111       HUFFMAN_TREE *hufftree;     // Huffman tree if codelen > 8
112   } HUFFMAN_ELEM;
113 
114   typedef struct _HUFFMAN_TABLE
115   {
116       int huff_class;              // 0=DC table or lossless table, 1=AC table
117       int ident;                  // Huffman table identifier (0 - 3)
118       HUFFMAN_ELEM huffelem[256]; // Huffman Table
119       int huffval[256];           // Huffman values for codes >8 bit long
120   } DHUFF_TABLE;
121 
122   typedef struct _QUANT_TABLE
123   {
124       int precision;              // 0 <-> 8-bit elements, 1 <-> 16-bit
125       int ident;                  // table identifier (0 - 3)
126       int elements[80];           // 64 table elements + extra 16 elements
127                                      to catch error in Decode_AC
128   } QUANT_TABLE;
129 
130   typedef struct _FRAME_COMPONENT
131   {                // Component-Spec structure
132       int ident;                  // component identifier
133       int width;                  // width of this component
134       int height;                 // height of this component
135       int hsampling;              // horizontal sampling factor
136       int vsampling;              // vertical sampling factor
137       int quant_sel;              // quantization table selector
138   } FRAME_COMPONENT;
139 
140   typedef struct _FRAME
141   {                // Frame structure
142       int precision;              // sample precision in bits
143       int width;                  // width of the source image
144       int height;                 // height of the source image
145       int ncomps;                 // number of image components in frame
146       int horMCU;                 // number of MCU in hor. direction
147       long totalMCU;              // total number of MCU
148       FRAME_COMPONENT *comps;     // array of 'ncomps' items
149   } FRAME;
150 
151   typedef struct _DECODERSTRUCT
152   {
153           int hSize, vSize; // width/height of tile in pixels
154           int num_channels; // bytes per pixel
155 
156     int InternalUpsample; // if TRUE, then upsampling is done in jpeg decoder
157     int InternalColor; // if TRUE, then color conversion is done in jpeg decoder
158 
159     // next 6 bytes are a copy of jpegsubtype above
160     unsigned char interleave_type;
161     unsigned char chroma_subsample;
162     unsigned char internal_colorconvert;  // color conversion is needed
163     unsigned char jpeg_tblselector;
164 
165     unsigned char horiz_subsample; // left nibble of chroma_subsample unsigned char above
166     unsigned char vert_subsample;  // right nibble of chroma_subsample unsigned char above
167 
168     int numb_huffman_pair_tables;
169     DHUFF_TABLE *huffman_table_dc[4]; // A maximum of 4 pairs of Huffman tables
170     DHUFF_TABLE *huffman_table_ac[4]; // A maximum of 4 pairs of Huffman tables
171     int numb_quant_tables;
172     QUANT_TABLE *quant_table[4];     // A maximum of 4 quantization tables per tile
173 
174     FRAME *frame;     // A JPEG frame-structure
175 
176   } DECODER_STRUCT;
177 
178   #define DECODER DECODER_STRUCT*
179 
180 
181 //  Types Definitions
182 //  -----------------
183 
184 //  'extern' Functions
185 //  ------------------
186 
187 //  Functions declarations
188 //  ----------------------
189 
190 #ifdef __cplusplus
191 extern  "C" {
192 #endif
193 
194     short     eJPEG_Init(ENCODER *pencoder);
195 
196     int     eJPEG_DisableInternalSubsampling(ENCODER encoder);
197 
198     int     eJPEG_DisableInternalYCbCr(ENCODER encoder);
199 
200     int     eJPEG_SetSubsampling(ENCODER encoder, BYTE subSampling);
201 
202     int     eJPEG_SetQFactor(ENCODER encoder, int quality);
203 
204     int     eJPEG_SetJPEGTables(
205           int cls[4],
206           int ident[4],     // for arbitrary channel/table pairings...
207           int *qTables[4],
208           int *huffACBits[4],
209           int *huffACValues[4],
210           int *huffDCBits[4],
211           int *huffDCValues[4]
212           );
213 
214     int     eJPEG_SetTileSize(
215           ENCODER encoder,
216           int hSize,      // in pixels, the width of a tile
217           int vSize,      // in pixels, the height of a tile
218           int bytesPerPixel // how many bytes per pixel
219           );
220 
221     int     eJPEG_CreateHeader(
222           ENCODER encoder,      // same value returned by eJPEG_Init
223           long hdrBufferSize,     // the size of the <hdrBuffer> in bytes
224           unsigned char *hdrBuffer, // the buffer itself
225           long *hdrBufferUsed     // upon return shows the amount of
226                         // <hdrBuffer> that was used
227           );
228 
229     int     eJPEG_ConcatenateHeader(ENCODER encoder);
230 
231     long    eJPEG_EncodeTile(
232           ENCODER encoder,      // same value returned by eJPEG_Init
233           unsigned char *inbuf, // assumed to be the size of a tile or sub-
234                       // sampled tile!
235           unsigned char *outbuf,  // the buffer to put the compressed tile into
236           size_t outbuf_size    // size of the output buffer
237           );
238 
239     int     eJPEG_Shutdown(ENCODER encoder);
240 
241     int     dJPEG_DecoderInit(DECODER* pDecoder);
242 
243     void    dJPEG_DisableColorConvert(DECODER decoder);
244 
245     void    dJPEG_EnableColorConvert(DECODER decoder);
246 
247     void    dJPEG_DisableUpsample(DECODER decoder);
248 
249     void    dJPEG_EnableUpsample(DECODER decoder);
250 
251     void    dJPEG_DecoderFree(DECODER decoder);
252 
253     int     dJPEG_CopyJpegSubtype(DECODER decoder, unsigned long JpegSubtype);
254 
255     int     dJPEG_DecodeTile(unsigned char *outbuf,
256                size_t outbuf_size,
257                unsigned char *inbuf,
258                size_t inbuf_size,
259                DECODER decoder,
260                      int parse_option,
261                int dct_method);
262 
263     int     dJPEG_DecodeTileHeader(unsigned char *inbuf,
264                size_t inbuf_size,
265                DECODER decoder,
266               int dct_method);
267 
268     int     dJPEG_SetTileSize( void *decoder,
269                  int hSize,
270                  int vSize,
271                  int num_channels);
272 
273 #ifdef __cplusplus
274 } // end extern
275 #endif
276 
277 //  'extern' Variables
278 //  ------------------
279 */
280 //  ----------------------------------------------------------------------------
281   #endif // FlashPixJPEG_h
282 //  ----------------------------------------------------------------------------
283