1 |
2 |
quickwayne |
/* File : jpeg.h, header for all jpeg code */
|
2 |
|
|
/* Author: Pierre Guerrier, march 1998 */
|
3 |
|
|
/* */
|
4 |
|
|
/* 19/01/99 Edited by Koen van Eijk */
|
5 |
|
|
|
6 |
|
|
/*#define SPY*/
|
7 |
|
|
/* Leave structures in memory,output something and dump core in the event
|
8 |
|
|
of a failure: */
|
9 |
|
|
#define DEBUG 0
|
10 |
|
|
|
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/*----------------------------------*/
|
14 |
|
|
/* JPEG format parsing markers here */
|
15 |
|
|
/*----------------------------------*/
|
16 |
|
|
|
17 |
|
|
#define SOI_MK 0xFFD8 /* start of image */
|
18 |
|
|
#define APP_MK 0xFFE0 /* custom, up to FFEF */
|
19 |
|
|
#define COM_MK 0xFFFE /* commment segment */
|
20 |
|
|
#define SOF_MK 0xFFC0 /* start of frame */
|
21 |
|
|
#define SOS_MK 0xFFDA /* start of scan */
|
22 |
|
|
#define DHT_MK 0xFFC4 /* Huffman table */
|
23 |
|
|
#define DQT_MK 0xFFDB /* Quant. table */
|
24 |
|
|
#define DRI_MK 0xFFDD /* restart interval */
|
25 |
|
|
#define EOI_MK 0xFFD9 /* end of image */
|
26 |
|
|
#define MK_MSK 0xFFF0
|
27 |
|
|
|
28 |
|
|
#define RST_MK(x) ( (0xFFF8&(x)) == 0xFFD0 )
|
29 |
|
|
/* is x a restart interval ? */
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
|
|
/*-------------------------------------------------------- */
|
34 |
|
|
/* all kinds of macros here */
|
35 |
|
|
/*-------------------------------------------------------- */
|
36 |
|
|
|
37 |
|
|
#define first_quad(c) ((c) >> 4) /* first 4 bits in file order */
|
38 |
|
|
#define second_quad(c) ((c) & 15)
|
39 |
|
|
|
40 |
|
|
#define HUFF_ID(hclass, id) (2 * (hclass) + (id))
|
41 |
|
|
|
42 |
|
|
#define DC_CLASS 0
|
43 |
|
|
#define AC_CLASS 1
|
44 |
|
|
|
45 |
|
|
|
46 |
|
|
/*-------------------------------------------------------*/
|
47 |
|
|
/* JPEG data types here */
|
48 |
|
|
/*-------------------------------------------------------*/
|
49 |
|
|
|
50 |
|
|
typedef union { /* block of pixel-space values */
|
51 |
|
|
unsigned char block[8][8];
|
52 |
|
|
unsigned char linear[64];
|
53 |
|
|
} PBlock;
|
54 |
|
|
|
55 |
|
|
typedef union { /* block of frequency-space values */
|
56 |
|
|
int block[8][8];
|
57 |
|
|
int linear[64];
|
58 |
|
|
} FBlock;
|
59 |
|
|
|
60 |
|
|
|
61 |
|
|
/* component descriptor structure */
|
62 |
|
|
|
63 |
|
|
typedef struct {
|
64 |
|
|
unsigned char CID; /* component ID */
|
65 |
|
|
unsigned char IDX; /* index of first block in MCU */
|
66 |
|
|
|
67 |
|
|
unsigned char HS; /* sampling factors */
|
68 |
|
|
unsigned char VS;
|
69 |
|
|
unsigned char HDIV; /* sample width ratios */
|
70 |
|
|
unsigned char VDIV;
|
71 |
|
|
|
72 |
|
|
char QT; /* QTable index, 2bits */
|
73 |
|
|
char DC_HT; /* DC table index, 1bit */
|
74 |
|
|
char AC_HT; /* AC table index, 1bit */
|
75 |
|
|
int PRED; /* DC predictor value */
|
76 |
|
|
} cd_t;
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
/*--------------------------------------------*/
|
80 |
|
|
/* global variables here */
|
81 |
|
|
/*--------------------------------------------*/
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
extern cd_t comp[3]; /* for every component, useful stuff */
|
85 |
|
|
|
86 |
|
|
extern PBlock *MCU_buff[10]; /* decoded component buffer */
|
87 |
|
|
/* between IDCT and color convert */
|
88 |
|
|
extern int MCU_valid[10]; /* for every DCT block, component id then -1 */
|
89 |
|
|
|
90 |
|
|
extern PBlock *QTable[4]; /* three quantization tables */
|
91 |
|
|
extern int QTvalid[4]; /* at most, but seen as four ... */
|
92 |
|
|
|
93 |
|
|
extern FILE *fi;
|
94 |
|
|
extern FILE *fo;
|
95 |
|
|
|
96 |
|
|
/* picture attributes */
|
97 |
|
|
extern int x_size, y_size; /* Video frame size */
|
98 |
|
|
extern int rx_size, ry_size; /* down-rounded Video frame size */
|
99 |
|
|
/* in pixel units, multiple of MCU */
|
100 |
|
|
extern int MCU_sx, MCU_sy; /* MCU size in pixels */
|
101 |
|
|
extern int mx_size, my_size; /* picture size in units of MCUs */
|
102 |
|
|
extern int n_comp; /* number of components 1,3 */
|
103 |
|
|
|
104 |
|
|
/* processing cursor variables */
|
105 |
|
|
extern int in_frame, curcomp, MCU_row, MCU_column;
|
106 |
|
|
/* current position in MCU unit */
|
107 |
|
|
|
108 |
|
|
/* RGB buffer storage */
|
109 |
|
|
extern unsigned char *ColorBuffer; /* MCU after color conversion */
|
110 |
|
|
extern unsigned char *FrameBuffer; /* complete final RGB image */
|
111 |
|
|
extern PBlock *PBuff;
|
112 |
|
|
extern FBlock *FBuff;
|
113 |
|
|
|
114 |
|
|
/* process statistics */
|
115 |
|
|
extern int stuffers; /* number of stuff bytes in file */
|
116 |
|
|
extern int passed; /* number of bytes skipped looking for markers */
|
117 |
|
|
|
118 |
|
|
extern int verbose;
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
/*-----------------------------------------*/
|
122 |
|
|
/* prototypes from utils.c */
|
123 |
|
|
/*-----------------------------------------*/
|
124 |
|
|
|
125 |
|
|
extern void show_FBlock(FBlock *S);
|
126 |
|
|
extern void show_PBlock(PBlock *S);
|
127 |
|
|
extern void bin_dump(FILE *fi);
|
128 |
|
|
|
129 |
|
|
extern int ceil_div(int N, int D);
|
130 |
|
|
extern int floor_div(int N, int D);
|
131 |
|
|
extern void reset_prediction();
|
132 |
|
|
extern int reformat(unsigned long S, int good);
|
133 |
|
|
extern void free_structures();
|
134 |
|
|
extern void suicide();
|
135 |
|
|
extern void aborted_stream(FILE *fi);
|
136 |
|
|
extern void RGB_save(FILE *fo);
|
137 |
|
|
|
138 |
|
|
/*-----------------------------------------*/
|
139 |
|
|
/* prototypes from parse.c */
|
140 |
|
|
/*-----------------------------------------*/
|
141 |
|
|
|
142 |
|
|
extern void clear_bits();
|
143 |
|
|
extern unsigned long get_bits(FILE *fi, int number);
|
144 |
|
|
extern unsigned char get_one_bit(FILE *fi);
|
145 |
|
|
extern unsigned int get_size(FILE *fi);
|
146 |
|
|
extern unsigned int get_next_MK(FILE *fi);
|
147 |
|
|
extern int load_quant_tables(FILE *fi);
|
148 |
|
|
extern int init_MCU();
|
149 |
|
|
extern void skip_segment(FILE *fi);
|
150 |
|
|
extern int process_MCU(FILE *fi);
|
151 |
|
|
|
152 |
|
|
/*-------------------------------------------*/
|
153 |
|
|
/* prototypes from fast_idct.c */
|
154 |
|
|
/*-------------------------------------------*/
|
155 |
|
|
|
156 |
|
|
extern void IDCT(const FBlock *S, PBlock *T);
|
157 |
|
|
|
158 |
|
|
/*-----------------------------------------*/
|
159 |
|
|
/* prototypes from color.c */
|
160 |
|
|
/*-----------------------------------------*/
|
161 |
|
|
|
162 |
|
|
extern void color_conversion();
|
163 |
|
|
|
164 |
|
|
/*-------------------------------------------*/
|
165 |
|
|
/* prototypes from table_vld.c or tree_vld.c */
|
166 |
|
|
/*-------------------------------------------*/
|
167 |
|
|
|
168 |
|
|
extern int load_huff_tables(FILE *fi);
|
169 |
|
|
extern unsigned char get_symbol(FILE *fi, int select);
|
170 |
|
|
|
171 |
|
|
/*-----------------------------------------*/
|
172 |
|
|
/* prototypes from huffman.c */
|
173 |
|
|
/*-----------------------------------------*/
|
174 |
|
|
|
175 |
|
|
extern void unpack_block(FILE *fi, FBlock *T, int comp);
|
176 |
|
|
/* unpack, predict, dequantize, reorder on store */
|
177 |
|
|
|
178 |
|
|
/*-----------------------------------------*/
|
179 |
|
|
/* prototypes from spy.c */
|
180 |
|
|
/*-----------------------------------------*/
|
181 |
|
|
|
182 |
|
|
extern void trace_bits(int number, int type);
|
183 |
|
|
extern void output_stats(char *dumpfile);
|
184 |
|
|
|