72 #define MAXCODE(n_bits) ((1 << (n_bits)) - 1) 84 if (dinfo->bytesinpkt > 0) {
85 dinfo->packetbuf[0] = (char) dinfo->bytesinpkt++;
86 if (
JFWRITE(dinfo->pub.output_file, dinfo->packetbuf, dinfo->bytesinpkt)
87 != (size_t) dinfo->bytesinpkt)
88 ERREXIT(dinfo->cinfo, JERR_FILE_WRITE);
89 dinfo->bytesinpkt = 0;
95 #define CHAR_OUT(dinfo,c) \ 96 { (dinfo)->packetbuf[++(dinfo)->bytesinpkt] = (char) (c); \ 97 if ((dinfo)->bytesinpkt >= 255) \ 98 flush_packet(dinfo); \ 109 dinfo->cur_accum |= ((
INT32) code) << dinfo->cur_bits;
110 dinfo->cur_bits += dinfo->n_bits;
112 while (dinfo->cur_bits >= 8) {
113 CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF);
114 dinfo->cur_accum >>= 8;
115 dinfo->cur_bits -= 8;
147 dinfo->n_bits = i_bits;
148 dinfo->maxcode =
MAXCODE(dinfo->n_bits);
149 dinfo->ClearCode = (1 << (i_bits - 1));
150 dinfo->EOFCode = dinfo->ClearCode + 1;
151 dinfo->code_counter = dinfo->ClearCode + 2;
153 dinfo->bytesinpkt = 0;
154 dinfo->cur_accum = 0;
157 output(dinfo, dinfo->ClearCode);
172 if (dinfo->code_counter < dinfo->maxcode) {
173 dinfo->code_counter++;
175 output(dinfo, dinfo->ClearCode);
176 dinfo->code_counter = dinfo->ClearCode + 2;
186 output(dinfo, dinfo->EOFCode);
188 if (dinfo->cur_bits > 0) {
189 CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF);
203 putc(
w & 0xFF, dinfo->pub.output_file);
204 putc((
w >> 8) & 0xFF, dinfo->pub.output_file);
212 putc(
val, dinfo->pub.output_file);
213 putc(
val, dinfo->pub.output_file);
214 putc(
val, dinfo->pub.output_file);
223 int BitsPerPixel, ColorMapSize, InitCodeSize, FlagByte;
224 int cshift = dinfo->cinfo->data_precision - 8;
227 if (num_colors > 256)
228 ERREXIT1(dinfo->cinfo, JERR_TOO_MANY_COLORS, num_colors);
231 while (num_colors > (1 << BitsPerPixel))
233 ColorMapSize = 1 << BitsPerPixel;
234 if (BitsPerPixel <= 1)
237 InitCodeSize = BitsPerPixel;
242 putc(
'G', dinfo->pub.output_file);
243 putc(
'I', dinfo->pub.output_file);
244 putc(
'F', dinfo->pub.output_file);
245 putc(
'8', dinfo->pub.output_file);
246 putc(
'7', dinfo->pub.output_file);
247 putc(
'a', dinfo->pub.output_file);
249 put_word(dinfo, (
unsigned int) dinfo->cinfo->output_width);
250 put_word(dinfo, (
unsigned int) dinfo->cinfo->output_height);
252 FlagByte |= (BitsPerPixel-1) << 4;
253 FlagByte |= (BitsPerPixel-1);
254 putc(FlagByte, dinfo->pub.output_file);
255 putc(0, dinfo->pub.output_file);
256 putc(0, dinfo->pub.output_file);
260 for (
i=0;
i < ColorMapSize;
i++) {
261 if (
i < num_colors) {
262 if (colormap !=
NULL) {
263 if (dinfo->cinfo->out_color_space ==
JCS_RGB) {
265 putc(
GETJSAMPLE(colormap[0][
i]) >> cshift, dinfo->pub.output_file);
266 putc(
GETJSAMPLE(colormap[1][i]) >> cshift, dinfo->pub.output_file);
267 putc(
GETJSAMPLE(colormap[2][i]) >> cshift, dinfo->pub.output_file);
274 put_3bytes(dinfo, (
i * 255 + (num_colors-1)/2) / (num_colors-1));
282 putc(
',', dinfo->pub.output_file);
285 put_word(dinfo, (
unsigned int) dinfo->cinfo->output_width);
286 put_word(dinfo, (
unsigned int) dinfo->cinfo->output_height);
288 putc(0x00, dinfo->pub.output_file);
290 putc(InitCodeSize, dinfo->pub.output_file);
306 if (cinfo->quantize_colors)
307 emit_header(dest, cinfo->actual_number_of_colors, cinfo->colormap);
326 ptr = dest->pub.buffer[0];
327 for (col = cinfo->output_width; col > 0; col--) {
345 putc(0, dest->pub.output_file);
347 putc(
';', dest->pub.output_file);
349 fflush(dest->pub.output_file);
350 if (ferror(dest->pub.output_file))
351 ERREXIT(cinfo, JERR_FILE_WRITE);
374 cinfo->out_color_space !=
JCS_RGB)
375 ERREXIT(cinfo, JERR_GIF_COLORSPACE);
378 if (cinfo->out_color_space !=
JCS_GRAYSCALE || cinfo->data_precision > 8) {
380 cinfo->quantize_colors =
TRUE;
381 if (cinfo->desired_number_of_colors > 256)
382 cinfo->desired_number_of_colors = 256;
388 if (cinfo->output_components != 1)
392 dest->pub.buffer = (*cinfo->mem->alloc_sarray)
394 dest->pub.buffer_height = 1;
emit_header(gif_dest_ptr dinfo, int num_colors, JSAMPARRAY colormap)
struct jpeg_common_struct * j_common_ptr
#define GETJSAMPLE(value)
finish_output_gif(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
put_3bytes(gif_dest_ptr dinfo, int val)
#define ERREXIT(cinfo, code)
#define CHAR_OUT(dinfo, c)
put_word(gif_dest_ptr dinfo, unsigned int w)
start_output_gif(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)
#define JFWRITE(file, buf, sizeofbuf)
jpeg_calc_output_dimensions(j_decompress_ptr cinfo)
jinit_write_gif(j_decompress_ptr cinfo)
compress_init(gif_dest_ptr dinfo, int i_bits)
compress_pixel(gif_dest_ptr dinfo, int c)
#define ERREXIT1(cinfo, code, p1)
compress_term(gif_dest_ptr dinfo)
if(!abbox) return FT_THROW(Invalid_Argument)
GLubyte GLubyte GLubyte GLubyte w
put_pixel_rows(j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, JDIMENSION rows_supplied)
gif_dest_struct * gif_dest_ptr
output(gif_dest_ptr dinfo, int code)
flush_packet(gif_dest_ptr dinfo)