comparison gif.c @ 10629:f164bb900d0b libavcodec

pass avctx as argument instead of width and height
author bcoudurier
date Wed, 02 Dec 2009 21:25:28 +0000
parents 3d43d9bcf903
children e15eb76d9e47
comparison
equal deleted inserted replaced
10628:3d43d9bcf903 10629:f164bb900d0b
56 typedef struct { 56 typedef struct {
57 AVFrame picture; 57 AVFrame picture;
58 } GIFContext; 58 } GIFContext;
59 59
60 /* GIF header */ 60 /* GIF header */
61 static int gif_image_write_header(uint8_t **bytestream, 61 static int gif_image_write_header(AVCodecContext *avctx,
62 int width, int height, 62 uint8_t **bytestream, uint32_t *palette)
63 uint32_t *palette)
64 { 63 {
65 int i; 64 int i;
66 unsigned int v; 65 unsigned int v;
67 66
68 bytestream_put_buffer(bytestream, "GIF", 3); 67 bytestream_put_buffer(bytestream, "GIF", 3);
69 bytestream_put_buffer(bytestream, "89a", 3); 68 bytestream_put_buffer(bytestream, "89a", 3);
70 bytestream_put_le16(bytestream, width); 69 bytestream_put_le16(bytestream, avctx->width);
71 bytestream_put_le16(bytestream, height); 70 bytestream_put_le16(bytestream, avctx->height);
72 71
73 bytestream_put_byte(bytestream, 0xf7); /* flags: global clut, 256 entries */ 72 bytestream_put_byte(bytestream, 0xf7); /* flags: global clut, 256 entries */
74 bytestream_put_byte(bytestream, 0x1f); /* background color index */ 73 bytestream_put_byte(bytestream, 0x1f); /* background color index */
75 bytestream_put_byte(bytestream, 0); /* aspect ratio */ 74 bytestream_put_byte(bytestream, 0); /* aspect ratio */
76 75
81 } 80 }
82 81
83 return 0; 82 return 0;
84 } 83 }
85 84
86 static int gif_image_write_image(uint8_t **bytestream, 85 static int gif_image_write_image(AVCodecContext *avctx, uint8_t **bytestream,
87 int width, int height,
88 const uint8_t *buf, int linesize) 86 const uint8_t *buf, int linesize)
89 { 87 {
90 PutBitContext p; 88 PutBitContext p;
91 uint8_t buffer[200]; /* 100 * 9 / 8 = 113 */ 89 uint8_t buffer[200]; /* 100 * 9 / 8 = 113 */
92 int i, left, w; 90 int i, left, w;
94 /* image block */ 92 /* image block */
95 93
96 bytestream_put_byte(bytestream, 0x2c); 94 bytestream_put_byte(bytestream, 0x2c);
97 bytestream_put_le16(bytestream, 0); 95 bytestream_put_le16(bytestream, 0);
98 bytestream_put_le16(bytestream, 0); 96 bytestream_put_le16(bytestream, 0);
99 bytestream_put_le16(bytestream, width); 97 bytestream_put_le16(bytestream, avctx->width);
100 bytestream_put_le16(bytestream, height); 98 bytestream_put_le16(bytestream, avctx->height);
101 bytestream_put_byte(bytestream, 0x00); /* flags */ 99 bytestream_put_byte(bytestream, 0x00); /* flags */
102 /* no local clut */ 100 /* no local clut */
103 101
104 bytestream_put_byte(bytestream, 0x08); 102 bytestream_put_byte(bytestream, 0x08);
105 103
106 left= width * height; 104 left= avctx->width * avctx->height;
107 105
108 init_put_bits(&p, buffer, 130); 106 init_put_bits(&p, buffer, 130);
109 107
110 /* 108 /*
111 * the thing here is the bitstream is written as little packets, with a size byte before 109 * the thing here is the bitstream is written as little packets, with a size byte before
112 * but it's still the same bitstream between packets (no flush !) 110 * but it's still the same bitstream between packets (no flush !)
113 */ 111 */
114 ptr = buf; 112 ptr = buf;
115 w = width; 113 w = avctx->width;
116 while(left>0) { 114 while(left>0) {
117 115
118 put_bits(&p, 9, 0x0100); /* clear code */ 116 put_bits(&p, 9, 0x0100); /* clear code */
119 117
120 for(i=(left<GIF_CHUNKS)?left:GIF_CHUNKS;i;i--) { 118 for(i=(left<GIF_CHUNKS)?left:GIF_CHUNKS;i;i--) {
121 put_bits(&p, 9, *ptr++); 119 put_bits(&p, 9, *ptr++);
122 if (--w == 0) { 120 if (--w == 0) {
123 w = width; 121 w = avctx->width;
124 buf += linesize; 122 buf += linesize;
125 ptr = buf; 123 ptr = buf;
126 } 124 }
127 } 125 }
128 126
159 uint8_t *outbuf_ptr = outbuf; 157 uint8_t *outbuf_ptr = outbuf;
160 158
161 *p = *pict; 159 *p = *pict;
162 p->pict_type = FF_I_TYPE; 160 p->pict_type = FF_I_TYPE;
163 p->key_frame = 1; 161 p->key_frame = 1;
164 gif_image_write_header(&outbuf_ptr, avctx->width, avctx->height, (uint32_t *)pict->data[1]); 162 gif_image_write_header(avctx, &outbuf_ptr, (uint32_t *)pict->data[1]);
165 gif_image_write_image(&outbuf_ptr, avctx->width, avctx->height, pict->data[0], pict->linesize[0]); 163 gif_image_write_image(avctx, &outbuf_ptr, pict->data[0], pict->linesize[0]);
166 return outbuf_ptr - outbuf; 164 return outbuf_ptr - outbuf;
167 } 165 }
168 166
169 AVCodec gif_encoder = { 167 AVCodec gif_encoder = {
170 "gif", 168 "gif",