35#define MAX_LZW_BITS 12
37typedef INT16 code_int;
39#define LZW_TABLE_SIZE ((code_int) 1 << MAX_LZW_BITS)
45#define MAXCODE(n_bits) (((code_int) 1 << (n_bits)) - 1)
66#define HASH_ENTRY(prefix, suffix) ((((hash_entry) (prefix)) << 8) | (suffix))
84 code_int waiting_code;
91 code_int code_counter;
103typedef gif_dest_struct * gif_dest_ptr;
112flush_packet (gif_dest_ptr dinfo)
115 if (dinfo->bytesinpkt > 0) {
116 dinfo->packetbuf[0] = (
char) dinfo->bytesinpkt++;
117 if (
JFWRITE(dinfo->pub.output_file, dinfo->packetbuf, dinfo->bytesinpkt)
118 != (
size_t) dinfo->bytesinpkt)
119 ERREXIT(dinfo->cinfo, JERR_FILE_WRITE);
120 dinfo->bytesinpkt = 0;
126#define CHAR_OUT(dinfo, c) \
127 { (dinfo)->packetbuf[++(dinfo)->bytesinpkt] = (char) (c); \
128 if ((dinfo)->bytesinpkt >= 255) \
129 flush_packet(dinfo); \
136output (gif_dest_ptr dinfo, code_int
code)
140 dinfo->cur_accum |= ((
INT32)
code) << dinfo->cur_bits;
141 dinfo->cur_bits += dinfo->n_bits;
143 while (dinfo->cur_bits >= 8) {
144 CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF);
145 dinfo->cur_accum >>= 8;
146 dinfo->cur_bits -= 8;
154 if (dinfo->free_code > dinfo->maxcode) {
156 if (dinfo->n_bits == MAX_LZW_BITS)
157 dinfo->maxcode = LZW_TABLE_SIZE;
159 dinfo->maxcode = MAXCODE(dinfo->n_bits);
168clear_hash (gif_dest_ptr dinfo)
177clear_block (gif_dest_ptr dinfo)
181 dinfo->free_code = dinfo->ClearCode + 2;
182 output(dinfo, dinfo->ClearCode);
183 dinfo->n_bits = dinfo->init_bits;
184 dinfo->maxcode = MAXCODE(dinfo->n_bits);
189compress_init (gif_dest_ptr dinfo,
int i_bits)
193 dinfo->n_bits = dinfo->init_bits = i_bits;
194 dinfo->maxcode = MAXCODE(dinfo->n_bits);
195 dinfo->ClearCode = ((code_int) 1 << (i_bits - 1));
196 dinfo->EOFCode = dinfo->ClearCode + 1;
197 dinfo->code_counter = dinfo->free_code = dinfo->ClearCode + 2;
198 dinfo->first_byte =
TRUE;
200 dinfo->bytesinpkt = 0;
201 dinfo->cur_accum = 0;
204 if (dinfo->hash_code !=
NULL)
207 output(dinfo, dinfo->ClearCode);
212compress_term (gif_dest_ptr dinfo)
216 if (! dinfo->first_byte)
217 output(dinfo, dinfo->waiting_code);
219 output(dinfo, dinfo->EOFCode);
221 if (dinfo->cur_bits > 0) {
222 CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF);
233put_word (gif_dest_ptr dinfo,
unsigned int w)
236 putc(
w & 0xFF, dinfo->pub.output_file);
237 putc((
w >> 8) & 0xFF, dinfo->pub.output_file);
242put_3bytes (gif_dest_ptr dinfo,
int val)
245 putc(
val, dinfo->pub.output_file);
246 putc(
val, dinfo->pub.output_file);
247 putc(
val, dinfo->pub.output_file);
252emit_header (gif_dest_ptr dinfo,
int num_colors,
JSAMPARRAY colormap)
256 int BitsPerPixel, ColorMapSize, InitCodeSize, FlagByte;
257 int cshift = dinfo->cinfo->data_precision - 8;
260 if (num_colors > 256)
261 ERREXIT1(dinfo->cinfo, JERR_TOO_MANY_COLORS, num_colors);
264 while (num_colors > (1 << BitsPerPixel))
266 ColorMapSize = 1 << BitsPerPixel;
267 if (BitsPerPixel <= 1)
270 InitCodeSize = BitsPerPixel;
275 putc(
'G', dinfo->pub.output_file);
276 putc(
'I', dinfo->pub.output_file);
277 putc(
'F', dinfo->pub.output_file);
278 putc(
'8', dinfo->pub.output_file);
279 putc(
'7', dinfo->pub.output_file);
280 putc(
'a', dinfo->pub.output_file);
282 put_word(dinfo, (
unsigned int) dinfo->cinfo->output_width);
283 put_word(dinfo, (
unsigned int) dinfo->cinfo->output_height);
285 FlagByte |= (BitsPerPixel - 1) << 4;
286 FlagByte |= (BitsPerPixel - 1);
287 putc(FlagByte, dinfo->pub.output_file);
288 putc(0, dinfo->pub.output_file);
289 putc(0, dinfo->pub.output_file);
293 for (
i = 0;
i < ColorMapSize;
i++) {
294 if (
i < num_colors) {
295 if (colormap !=
NULL) {
296 if (dinfo->cinfo->out_color_space ==
JCS_RGB) {
303 put_3bytes(dinfo,
GETJSAMPLE(colormap[0][
i]) >> cshift);
307 put_3bytes(dinfo, (
i * 255 + (num_colors - 1) / 2) / (num_colors - 1));
315 putc(
',', dinfo->pub.output_file);
318 put_word(dinfo, (
unsigned int) dinfo->cinfo->output_width);
319 put_word(dinfo, (
unsigned int) dinfo->cinfo->output_height);
321 putc(0x00, dinfo->pub.output_file);
323 putc(InitCodeSize, dinfo->pub.output_file);
326 compress_init(dinfo, InitCodeSize + 1);
337 gif_dest_ptr
dest = (gif_dest_ptr) dinfo;
360 gif_dest_ptr
dest = (gif_dest_ptr) dinfo;
365 register hash_int disp;
373 if (
dest->first_byte) {
374 dest->waiting_code =
c;
383 i = ((hash_int)
c << (MAX_LZW_BITS-8)) +
dest->waiting_code;
390 if (
dest->hash_code[
i] == 0) {
393 if (
dest->free_code < LZW_TABLE_SIZE) {
395 dest->hash_value[
i] = probe_value;
398 dest->waiting_code =
c;
401 if (
dest->hash_value[
i] == probe_value) {
414 if (
dest->hash_code[
i] == 0) {
417 if (
dest->free_code < LZW_TABLE_SIZE) {
419 dest->hash_value[
i] = probe_value;
422 dest->waiting_code =
c;
425 if (
dest->hash_value[
i] == probe_value) {
461 gif_dest_ptr
dest = (gif_dest_ptr) dinfo;
478 if (
dest->code_counter <
dest->maxcode) {
479 dest->code_counter++;
482 dest->code_counter =
dest->ClearCode + 2;
495 gif_dest_ptr
dest = (gif_dest_ptr) dinfo;
506 ERREXIT(cinfo, JERR_FILE_WRITE);
520 dest = (gif_dest_ptr) (*cinfo->mem->alloc_small)
523 dest->pub.start_output = start_output_gif;
524 dest->pub.finish_output = finish_output_gif;
528 ERREXIT(cinfo, JERR_GIF_COLORSPACE);
545 dest->pub.buffer = (*cinfo->mem->alloc_sarray)
547 dest->pub.buffer_height = 1;
550 dest->pub.put_pixel_rows = put_LZW_pixel_rows;
552 dest->hash_code = (code_int *) (*cinfo->mem->alloc_small)
557 dest->pub.put_pixel_rows = put_raw_pixel_rows;
GLubyte GLubyte GLubyte GLubyte w
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
_Check_return_opt_ _CRTIMP int __cdecl putc(_In_ int _Ch, _Inout_ FILE *_File)
jpeg_calc_output_dimensions(j_decompress_ptr cinfo)
#define ERREXIT1(cinfo, code, p1)
#define JFWRITE(file, buf, sizeofbuf)
#define GETJSAMPLE(value)
struct jpeg_common_struct * j_common_ptr
J_COLOR_SPACE out_color_space
int actual_number_of_colors
int desired_number_of_colors
#define MEMZERO(addr, type, size)
struct _HASH_ENTRY HASH_ENTRY