1 /* -*-C-*-
2 ******************************************************************************
3 *
4 * File:         enctile.h
5 * RCS:          $Header: /ImageMagick/delegates/fpx/jpeg/enctile.h,v 1.2 2000/12/23 22:37:48 bfriesen Exp $
6 * Description:  header file for JPEG encoder library.
7 * Author:       Kirt Winter
8 * Created:      Fri Aug  4 11:04:22 1995
9 * Initial Source Release:     Wed Jan 17 1996
10 * Language:     C
11 * Package:      Hewlett-Packard JPEG Encoder/Decoder
12 *
13 * Copyright (c) 1999 Digital Imaging Group, Inc.
14 * For conditions of distribution and use, see copyright notice
15 * in Flashpix.h
16 *
17 ******************************************************************************
18 */
19 
20 typedef struct {
21   unsigned char *bits;
22   unsigned char *vals;
23   unsigned char hclass; /* 0: DC, 1: AC */
24   unsigned char ident;  /* 0,1,2,or 3 for extended JPEG systems */
25                               /* 0, or 1 for baseline JPEG */
26 } JPEGHuffTable;
27 
28 typedef struct {
29   unsigned char *quantizer; /* Table elements specified in zigzag order */
30   unsigned char ident;  /* 0,1,2,3 */
31 } JPEGQuantTable;
32 
33 typedef struct {
34     unsigned short ehufcode[256]; /* ehufcode[i]=Huffman code for value i */
35     int ehufsize[256]; /* number of bits in ehufcode[i] */
36 } HUFFMAN_TABLE;       /* Internal Huffman-Table representation */
37 
38 
39 #ifndef TILE_DATA_DEFINED
40 typedef struct {
41   int width;     /* tile width */
42   int height;/* tile height */
43   int components; /* # of components: 1-4 */
44   int *Hsamp,*Vsamp; /* a pair of <Hsamp,Vsamp> subsampling factors per component */
45   int iflag;     /* Interleave-flag: 1/0= Interleaved/Non-interleaved */
46   unsigned char *data; /* points to image/compressed data */
47 } TILE_DATA;
48 #define TILE_DATA_DEFINED
49 #endif
50 
51 typedef struct {
52   HUFFMAN_TABLE huff[8];
53   int luminanceQuantization[64];
54   int chrominanceQuantization[64];
55   int tbl3_Quantization[64];
56   int tbl4_Quantization[64];
57   int threshLuminanceQuantization[64];
58   int threshChrominanceQuantization[64];
59   int tbl3_threshQuantization[64];
60   int tbl4_threshQuantization[64];
61   int en_last_dc[4];
62 }  JPEG_STRUCT;
63 
64 /*
65 * It creates the JPEG header bitstream.
66 */
67 JPEGEXPORT
68 int JPEGEncodeTileInit(unsigned char *data,   /* points to the input tile */
69 int width, int height,
70 int bytes,                /* number of bytes per pixel */
71 int quality_factor,
72 int *Hsamp,int *Vsamp,  /* Hor. & Vert. subsampling factors */
73 int iflag,          /* 1/0 = Interleaved/Non-interleaved data */
74 TILE_DATA *tile_data,
75 int nu_huff,        /* # of Huffman Tables (a max of 8 tables, ie four DC-AC sets) */
76 JPEGHuffTable *huffman_table,  /* Huffman Tables in the Bits-Value format */
77 unsigned char *CompDCHuffIdent,
78 unsigned char *CompACHuffIdent,
79 int nu_qtables,       /* # of Q-tables (a max of 4 tables) */
80 JPEGQuantTable *q_table,
81 unsigned char *CompQuantIdent,
82 JPEG_STRUCT *jpeg_struct,
83 unsigned char *header_buffer,
84 long header_buffer_size,
85 long *header_bytes);
86 
87 JPEGEXPORT
88 int JPEGEncodeTile(TILE_DATA *tile_data,
89 JPEG_STRUCT *jpeg_struct,
90 unsigned char *CompDCHuffIdent,
91 unsigned char *CompACHuffIdent,
92 unsigned char *CompQuantIdent,
93 unsigned char *out_buf,
94 long int out_buf_size,
95 long int *compr_size);
96 
97 JPEGEXPORT
98 void Scale_Matrix(int numerator,
99 int denominator,
100 int *in,
101 int *out);
102 
103 JPEGEXPORT
104 void Clear_Last_DC(JPEG_STRUCT *jpeg_struct);
105 
106 JPEGEXPORT
107 void EN_Encode_DC(int dc_val,
108 int comp,
109 HUFFMAN_TABLE *huffman,
110 JPEG_STRUCT *jpeg_struct);
111 
112 void EN_Encode_Block(int *block,
113 int comp, /* image component number */
114 HUFFMAN_TABLE *dcHuffman,
115 HUFFMAN_TABLE *acHuffman,
116 int *quant,
117 JPEG_STRUCT *jpeg_struct);
118 
119 JPEGEXPORT
120 int EN_Encode_Scan_Gray(unsigned char *buf,
121 int width,
122 int height,
123 JPEG_STRUCT *jpeg_struct);
124 
125 JPEGEXPORT
126 int EN_Encode_Scan_Color11(unsigned char *buf,
127 int width,
128 int height,
129 int interleaved,
130 JPEG_STRUCT *jpeg_struct);
131 
132 JPEGEXPORT
133 int EN_Encode_Scan_Color111(unsigned char *buf,
134 int width,
135 int height,
136 int interleaved,
137 JPEG_STRUCT *jpeg_struct);
138 
139 JPEGEXPORT
140 int EN_Encode_Scan_Color1111(unsigned char *buf,
141 int width, int height,
142 int interleaved,
143 JPEG_STRUCT *jpeg_struct);
144 
145 JPEGEXPORT
146 int EN_Encode_Scan_Color4114(unsigned char *buf,
147 int width, int height,
148 int interleaved,
149 JPEG_STRUCT *jpeg_struct);
150 
151 JPEGEXPORT
152 int EN_Encode_Scan_Color411(unsigned char *buf,
153 int width, int height,
154 int interleaved,
155 JPEG_STRUCT *jpeg_struct);
156 
157 JPEGEXPORT
158 int EN_Encode_Scan_Color422(unsigned char *buf,
159 int width, int height,
160 int interleaved,
161 JPEG_STRUCT *jpeg_struct);
162 
163 JPEGEXPORT
164 int EN_Encode_Scan_Color4224(unsigned char *buf,
165 int width, int height,
166 int interleaved,
167 JPEG_STRUCT *jpeg_struct);
168 
169 JPEGEXPORT
170 int EN_Encode_Scan_Color(unsigned char *buf,
171 int width, int height,
172 JPEG_STRUCT *jpeg_struct);
173 
174 JPEGEXPORT
175 int EN_Encode_Scan(TILE_DATA *tile_data,
176 JPEG_STRUCT *jpeg_struct);
177