comparison gif.c @ 8773:80a01d448b45 libavcodec

remove dead netscape loop header code in gif encoder, patch by Daniel Verkamp, daniel at drv dot nu
author bcoudurier
date Mon, 09 Feb 2009 08:11:08 +0000
parents 21a41fd79033
children 0a8166d20fd3
comparison
equal deleted inserted replaced
8772:5a9485bd4421 8773:80a01d448b45
50 50
51 #include "bitstream.h" 51 #include "bitstream.h"
52 52
53 /* bitstream minipacket size */ 53 /* bitstream minipacket size */
54 #define GIF_CHUNKS 100 54 #define GIF_CHUNKS 100
55
56 /* slows down the decoding (and some browsers don't like it) */
57 /* update on the 'some browsers don't like it issue from above: this was probably due to missing 'Data Sub-block Terminator' (byte 19) in the app_header */
58 #define GIF_ADD_APP_HEADER // required to enable looping of animated gif
59 55
60 typedef struct { 56 typedef struct {
61 unsigned char r; 57 unsigned char r;
62 unsigned char g; 58 unsigned char g;
63 unsigned char b; 59 unsigned char b;
109 { 0xff, 0xff, 0x00 }, { 0xff, 0xff, 0x33 }, { 0xff, 0xff, 0x66 }, { 0xff, 0xff, 0x99 }, { 0xff, 0xff, 0xcc }, { 0xff, 0xff, 0xff }, 105 { 0xff, 0xff, 0x00 }, { 0xff, 0xff, 0x33 }, { 0xff, 0xff, 0x66 }, { 0xff, 0xff, 0x99 }, { 0xff, 0xff, 0xcc }, { 0xff, 0xff, 0xff },
110 }; 106 };
111 107
112 /* GIF header */ 108 /* GIF header */
113 static int gif_image_write_header(uint8_t **bytestream, 109 static int gif_image_write_header(uint8_t **bytestream,
114 int width, int height, int loop_count, 110 int width, int height,
115 uint32_t *palette) 111 uint32_t *palette)
116 { 112 {
117 int i; 113 int i;
118 unsigned int v; 114 unsigned int v;
119 115
136 v = palette[i]; 132 v = palette[i];
137 bytestream_put_be24(bytestream, v); 133 bytestream_put_be24(bytestream, v);
138 } 134 }
139 } 135 }
140 136
141 /* update: this is the 'NETSCAPE EXTENSION' that allows for looped animated gif
142 see http://members.aol.com/royalef/gifabout.htm#net-extension
143
144 byte 1 : 33 (hex 0x21) GIF Extension code
145 byte 2 : 255 (hex 0xFF) Application Extension Label
146 byte 3 : 11 (hex (0x0B) Length of Application Block
147 (eleven bytes of data to follow)
148 bytes 4 to 11 : "NETSCAPE"
149 bytes 12 to 14 : "2.0"
150 byte 15 : 3 (hex 0x03) Length of Data Sub-Block
151 (three bytes of data to follow)
152 byte 16 : 1 (hex 0x01)
153 bytes 17 to 18 : 0 to 65535, an unsigned integer in
154 lo-hi byte format. This indicate the
155 number of iterations the loop should
156 be executed.
157 bytes 19 : 0 (hex 0x00) a Data Sub-block Terminator
158 */
159
160 /* application extension header */
161 #ifdef GIF_ADD_APP_HEADER
162 if (loop_count >= 0 && loop_count <= 65535) {
163 bytestream_put_byte(bytestream, 0x21);
164 bytestream_put_byte(bytestream, 0xff);
165 bytestream_put_byte(bytestream, 0x0b);
166 bytestream_put_buffer(bytestream, "NETSCAPE2.0", 11); // bytes 4 to 14
167 bytestream_put_byte(bytestream, 0x03); // byte 15
168 bytestream_put_byte(bytestream, 0x01); // byte 16
169 bytestream_put_le16(bytestream, (uint16_t)loop_count);
170 bytestream_put_byte(bytestream, 0x00); // byte 19
171 }
172 #endif
173 return 0; 137 return 0;
174 } 138 }
175 139
176 /* this is maybe slow, but allows for extensions */ 140 /* this is maybe slow, but allows for extensions */
177 static inline unsigned char gif_clut_index(uint8_t r, uint8_t g, uint8_t b) 141 static inline unsigned char gif_clut_index(uint8_t r, uint8_t g, uint8_t b)
268 uint8_t *outbuf_ptr = outbuf; 232 uint8_t *outbuf_ptr = outbuf;
269 233
270 *p = *pict; 234 *p = *pict;
271 p->pict_type = FF_I_TYPE; 235 p->pict_type = FF_I_TYPE;
272 p->key_frame = 1; 236 p->key_frame = 1;
273 gif_image_write_header(&outbuf_ptr, avctx->width, avctx->height, -1, (uint32_t *)pict->data[1]); 237 gif_image_write_header(&outbuf_ptr, avctx->width, avctx->height, (uint32_t *)pict->data[1]);
274 gif_image_write_image(&outbuf_ptr, 0, 0, avctx->width, avctx->height, pict->data[0], pict->linesize[0], PIX_FMT_PAL8); 238 gif_image_write_image(&outbuf_ptr, 0, 0, avctx->width, avctx->height, pict->data[0], pict->linesize[0], PIX_FMT_PAL8);
275 return outbuf_ptr - outbuf; 239 return outbuf_ptr - outbuf;
276 } 240 }
277 241
278 AVCodec gif_encoder = { 242 AVCodec gif_encoder = {