Mercurial > libavformat.hg
annotate gifdec.c @ 1402:23541e51b7ca libavformat
dont mess with ByteIOContext internal variables (fixes showdown2.mov)
author | michael |
---|---|
date | Thu, 19 Oct 2006 10:05:36 +0000 |
parents | 0899bfe4105c |
children | 3b00fb8ef8e4 |
rev | line source |
---|---|
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
1 /* |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
2 * GIF decoder |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
3 * Copyright (c) 2003 Fabrice Bellard. |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
4 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
5 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
6 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
11 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
16 * |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
887
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
20 */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
21 #include "avformat.h" |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
22 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
23 int gif_write(ByteIOContext *pb, AVImageInfo *info); |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
24 |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
25 //#define DEBUG |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
26 |
887 | 27 #define MAXBITS 12 |
28 #define SIZTABLE (1<<MAXBITS) | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
29 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
30 #define GCE_DISPOSAL_NONE 0 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
31 #define GCE_DISPOSAL_INPLACE 1 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
32 #define GCE_DISPOSAL_BACKGROUND 2 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
33 #define GCE_DISPOSAL_RESTORE 3 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
34 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
35 typedef struct GifState { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
36 int screen_width; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
37 int screen_height; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
38 int bits_per_pixel; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
39 int background_color_index; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
40 int transparent_color_index; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
41 int color_resolution; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
42 uint8_t *image_buf; |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
43 int image_linesize; |
60 | 44 uint32_t *image_palette; |
45 int pix_fmt; | |
46 | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
47 /* after the frame is displayed, the disposal method is used */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
48 int gce_disposal; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
49 /* delay during which the frame is shown */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
50 int gce_delay; |
885 | 51 |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
52 /* LZW compatible decoder */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
53 ByteIOContext *f; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
54 int eob_reached; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
55 uint8_t *pbuf, *ebuf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
56 int bbits; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
57 unsigned int bbuf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
58 |
887 | 59 int cursize; /* The current code size */ |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
60 int curmask; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
61 int codesize; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
62 int clear_code; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
63 int end_code; |
887 | 64 int newcodes; /* First available code */ |
65 int top_slot; /* Highest code for current size */ | |
66 int slot; /* Last read code */ | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
67 int fc, oc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
68 uint8_t *sp; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
69 uint8_t stack[SIZTABLE]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
70 uint8_t suffix[SIZTABLE]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
71 uint16_t prefix[SIZTABLE]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
72 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
73 /* aux buffers */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
74 uint8_t global_palette[256 * 3]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
75 uint8_t local_palette[256 * 3]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
76 uint8_t buf[256]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
77 } GifState; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
78 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
79 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
80 static const uint8_t gif87a_sig[6] = "GIF87a"; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
81 static const uint8_t gif89a_sig[6] = "GIF89a"; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
82 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
83 static const uint16_t mask[17] = |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
84 { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
85 0x0000, 0x0001, 0x0003, 0x0007, |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
86 0x000F, 0x001F, 0x003F, 0x007F, |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
87 0x00FF, 0x01FF, 0x03FF, 0x07FF, |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
88 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
89 }; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
90 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
91 /* Probe gif video format or gif image format. The current heuristic |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
92 supposes the gif87a is always a single image. For gif89a, we |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
93 consider it as a video only if a GCE extension is present in the |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
94 first kilobyte. */ |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
95 static int gif_video_probe(AVProbeData * pd) |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
96 { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
97 const uint8_t *p, *p_end; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
98 int bits_per_pixel, has_global_palette, ext_code, ext_len; |
116 | 99 int gce_flags, gce_disposal; |
100 | |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
101 if (pd->buf_size < 24 || |
887 | 102 memcmp(pd->buf, gif89a_sig, 6) != 0) |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
103 return 0; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
104 p_end = pd->buf + pd->buf_size; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
105 p = pd->buf + 6; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
106 bits_per_pixel = (p[4] & 0x07) + 1; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
107 has_global_palette = (p[4] & 0x80); |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
108 p += 7; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
109 if (has_global_palette) |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
110 p += (1 << bits_per_pixel) * 3; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
111 for(;;) { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
112 if (p >= p_end) |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
113 return 0; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
114 if (*p != '!') |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
115 break; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
116 p++; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
117 if (p >= p_end) |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
118 return 0; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
119 ext_code = *p++; |
116 | 120 if (p >= p_end) |
121 return 0; | |
122 ext_len = *p++; | |
123 if (ext_code == 0xf9) { | |
124 if (p >= p_end) | |
125 return 0; | |
126 /* if GCE extension found with gce_disposal != 0: it is | |
127 likely to be an animation */ | |
128 gce_flags = *p++; | |
129 gce_disposal = (gce_flags >> 2) & 0x7; | |
130 if (gce_disposal != 0) | |
131 return AVPROBE_SCORE_MAX; | |
132 else | |
133 return 0; | |
134 } | |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
135 for(;;) { |
116 | 136 if (ext_len == 0) |
137 break; | |
138 p += ext_len; | |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
139 if (p >= p_end) |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
140 return 0; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
141 ext_len = *p++; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
142 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
143 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
144 return 0; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
145 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
146 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
147 static int gif_image_probe(AVProbeData * pd) |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
148 { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
149 if (pd->buf_size >= 24 && |
887 | 150 (memcmp(pd->buf, gif87a_sig, 6) == 0 || |
151 memcmp(pd->buf, gif89a_sig, 6) == 0)) | |
152 return AVPROBE_SCORE_MAX - 1; | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
153 else |
887 | 154 return 0; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
155 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
156 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
157 |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
158 static void GLZWDecodeInit(GifState * s, int csize) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
159 { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
160 /* read buffer */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
161 s->eob_reached = 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
162 s->pbuf = s->buf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
163 s->ebuf = s->buf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
164 s->bbuf = 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
165 s->bbits = 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
166 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
167 /* decoder */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
168 s->codesize = csize; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
169 s->cursize = s->codesize + 1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
170 s->curmask = mask[s->cursize]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
171 s->top_slot = 1 << s->cursize; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
172 s->clear_code = 1 << s->codesize; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
173 s->end_code = s->clear_code + 1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
174 s->slot = s->newcodes = s->clear_code + 2; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
175 s->oc = s->fc = 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
176 s->sp = s->stack; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
177 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
178 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
179 /* XXX: optimize */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
180 static inline int GetCode(GifState * s) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
181 { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
182 int c, sizbuf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
183 uint8_t *ptr; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
184 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
185 while (s->bbits < s->cursize) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
186 ptr = s->pbuf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
187 if (ptr >= s->ebuf) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
188 if (!s->eob_reached) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
189 sizbuf = get_byte(s->f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
190 s->ebuf = s->buf + sizbuf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
191 s->pbuf = s->buf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
192 if (sizbuf > 0) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
193 get_buffer(s->f, s->buf, sizbuf); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
194 } else { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
195 s->eob_reached = 1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
196 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
197 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
198 ptr = s->pbuf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
199 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
200 s->bbuf |= ptr[0] << s->bbits; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
201 ptr++; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
202 s->pbuf = ptr; |
887 | 203 s->bbits += 8; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
204 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
205 c = s->bbuf & s->curmask; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
206 s->bbuf >>= s->cursize; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
207 s->bbits -= s->cursize; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
208 return c; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
209 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
210 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
211 /* NOTE: the algorithm here is inspired from the LZW GIF decoder |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
212 written by Steven A. Bennett in 1987. */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
213 /* return the number of byte decoded */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
214 static int GLZWDecode(GifState * s, uint8_t * buf, int len) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
215 { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
216 int l, c, code, oc, fc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
217 uint8_t *sp; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
218 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
219 if (s->end_code < 0) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
220 return 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
221 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
222 l = len; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
223 sp = s->sp; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
224 oc = s->oc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
225 fc = s->fc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
226 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
227 while (sp > s->stack) { |
887 | 228 *buf++ = *(--sp); |
229 if ((--l) == 0) | |
230 goto the_end; | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
231 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
232 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
233 for (;;) { |
887 | 234 c = GetCode(s); |
235 if (c == s->end_code) { | |
236 s->end_code = -1; | |
237 break; | |
238 } else if (c == s->clear_code) { | |
239 s->cursize = s->codesize + 1; | |
240 s->curmask = mask[s->cursize]; | |
241 s->slot = s->newcodes; | |
242 s->top_slot = 1 << s->cursize; | |
243 while ((c = GetCode(s)) == s->clear_code); | |
244 if (c == s->end_code) { | |
245 s->end_code = -1; | |
246 break; | |
247 } | |
248 /* test error */ | |
249 if (c >= s->slot) | |
250 c = 0; | |
251 fc = oc = c; | |
252 *buf++ = c; | |
253 if ((--l) == 0) | |
254 break; | |
255 } else { | |
256 code = c; | |
257 if (code >= s->slot) { | |
258 *sp++ = fc; | |
259 code = oc; | |
260 } | |
261 while (code >= s->newcodes) { | |
262 *sp++ = s->suffix[code]; | |
263 code = s->prefix[code]; | |
264 } | |
265 *sp++ = code; | |
266 if (s->slot < s->top_slot) { | |
267 s->suffix[s->slot] = fc = code; | |
268 s->prefix[s->slot++] = oc; | |
269 oc = c; | |
270 } | |
271 if (s->slot >= s->top_slot) { | |
272 if (s->cursize < MAXBITS) { | |
273 s->top_slot <<= 1; | |
274 s->curmask = mask[++s->cursize]; | |
275 } | |
276 } | |
277 while (sp > s->stack) { | |
278 *buf++ = *(--sp); | |
279 if ((--l) == 0) | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
280 goto the_end; |
887 | 281 } |
282 } | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
283 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
284 the_end: |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
285 s->sp = sp; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
286 s->oc = oc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
287 s->fc = fc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
288 return len - l; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
289 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
290 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
291 static int gif_read_image(GifState *s) |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
292 { |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
293 ByteIOContext *f = s->f; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
294 int left, top, width, height, bits_per_pixel, code_size, flags; |
60 | 295 int is_interleaved, has_local_palette, y, x, pass, y1, linesize, n, i; |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
296 uint8_t *ptr, *line, *d, *spal, *palette, *sptr, *ptr1; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
297 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
298 left = get_le16(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
299 top = get_le16(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
300 width = get_le16(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
301 height = get_le16(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
302 flags = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
303 is_interleaved = flags & 0x40; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
304 has_local_palette = flags & 0x80; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
305 bits_per_pixel = (flags & 0x07) + 1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
306 #ifdef DEBUG |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
307 printf("gif: image x=%d y=%d w=%d h=%d\n", left, top, width, height); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
308 #endif |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
309 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
310 if (has_local_palette) { |
887 | 311 get_buffer(f, s->local_palette, 3 * (1 << bits_per_pixel)); |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
312 palette = s->local_palette; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
313 } else { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
314 palette = s->global_palette; |
60 | 315 bits_per_pixel = s->bits_per_pixel; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
316 } |
885 | 317 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
318 /* verify that all the image is inside the screen dimensions */ |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
319 if (left + width > s->screen_width || |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
320 top + height > s->screen_height) |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
321 return -EINVAL; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
322 |
60 | 323 /* build the palette */ |
324 if (s->pix_fmt == PIX_FMT_RGB24) { | |
325 line = av_malloc(width); | |
326 if (!line) | |
327 return -ENOMEM; | |
328 } else { | |
329 n = (1 << bits_per_pixel); | |
330 spal = palette; | |
331 for(i = 0; i < n; i++) { | |
885 | 332 s->image_palette[i] = (0xff << 24) | |
60 | 333 (spal[0] << 16) | (spal[1] << 8) | (spal[2]); |
334 spal += 3; | |
335 } | |
336 for(; i < 256; i++) | |
337 s->image_palette[i] = (0xff << 24); | |
116 | 338 /* handle transparency */ |
339 if (s->transparent_color_index >= 0) | |
340 s->image_palette[s->transparent_color_index] = 0; | |
60 | 341 line = NULL; |
342 } | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
343 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
344 /* now get the image data */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
345 s->f = f; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
346 code_size = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
347 GLZWDecodeInit(s, code_size); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
348 |
60 | 349 /* read all the image */ |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
350 linesize = s->image_linesize; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
351 ptr1 = s->image_buf + top * linesize + (left * 3); |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
352 ptr = ptr1; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
353 pass = 0; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
354 y1 = 0; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
355 for (y = 0; y < height; y++) { |
60 | 356 if (s->pix_fmt == PIX_FMT_RGB24) { |
357 /* transcode to RGB24 */ | |
358 GLZWDecode(s, line, width); | |
359 d = ptr; | |
360 sptr = line; | |
361 for(x = 0; x < width; x++) { | |
362 spal = palette + sptr[0] * 3; | |
363 d[0] = spal[0]; | |
364 d[1] = spal[1]; | |
365 d[2] = spal[2]; | |
366 d += 3; | |
367 sptr++; | |
368 } | |
369 } else { | |
370 GLZWDecode(s, ptr, width); | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
371 } |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
372 if (is_interleaved) { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
373 switch(pass) { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
374 default: |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
375 case 0: |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
376 case 1: |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
377 y1 += 8; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
378 ptr += linesize * 8; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
379 if (y1 >= height) { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
380 y1 = 4; |
885 | 381 if (pass == 0) |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
382 ptr = ptr1 + linesize * 4; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
383 else |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
384 ptr = ptr1 + linesize * 2; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
385 pass++; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
386 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
387 break; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
388 case 2: |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
389 y1 += 4; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
390 ptr += linesize * 4; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
391 if (y1 >= height) { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
392 y1 = 1; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
393 ptr = ptr1 + linesize; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
394 pass++; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
395 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
396 break; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
397 case 3: |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
398 y1 += 2; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
399 ptr += linesize * 2; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
400 break; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
401 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
402 } else { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
403 ptr += linesize; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
404 } |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
405 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
406 av_free(line); |
885 | 407 |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
408 /* read the garbage data until end marker is found */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
409 while (!s->eob_reached) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
410 GetCode(s); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
411 return 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
412 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
413 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
414 static int gif_read_extension(GifState *s) |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
415 { |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
416 ByteIOContext *f = s->f; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
417 int ext_code, ext_len, i, gce_flags, gce_transparent_index; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
418 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
419 /* extension */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
420 ext_code = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
421 ext_len = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
422 #ifdef DEBUG |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
423 printf("gif: ext_code=0x%x len=%d\n", ext_code, ext_len); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
424 #endif |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
425 switch(ext_code) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
426 case 0xf9: |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
427 if (ext_len != 4) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
428 goto discard_ext; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
429 s->transparent_color_index = -1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
430 gce_flags = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
431 s->gce_delay = get_le16(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
432 gce_transparent_index = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
433 if (gce_flags & 0x01) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
434 s->transparent_color_index = gce_transparent_index; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
435 else |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
436 s->transparent_color_index = -1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
437 s->gce_disposal = (gce_flags >> 2) & 0x7; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
438 #ifdef DEBUG |
885 | 439 printf("gif: gce_flags=%x delay=%d tcolor=%d disposal=%d\n", |
440 gce_flags, s->gce_delay, | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
441 s->transparent_color_index, s->gce_disposal); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
442 #endif |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
443 ext_len = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
444 break; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
445 } |
885 | 446 |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
447 /* NOTE: many extension blocks can come after */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
448 discard_ext: |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
449 while (ext_len != 0) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
450 for (i = 0; i < ext_len; i++) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
451 get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
452 ext_len = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
453 #ifdef DEBUG |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
454 printf("gif: ext_len1=%d\n", ext_len); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
455 #endif |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
456 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
457 return 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
458 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
459 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
460 static int gif_read_header1(GifState *s) |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
461 { |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
462 ByteIOContext *f = s->f; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
463 uint8_t sig[6]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
464 int ret, v, n; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
465 int has_global_palette; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
466 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
467 /* read gif signature */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
468 ret = get_buffer(f, sig, 6); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
469 if (ret != 6) |
887 | 470 return -1; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
471 if (memcmp(sig, gif87a_sig, 6) != 0 && |
887 | 472 memcmp(sig, gif89a_sig, 6) != 0) |
473 return -1; | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
474 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
475 /* read screen header */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
476 s->transparent_color_index = -1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
477 s->screen_width = get_le16(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
478 s->screen_height = get_le16(f); |
885 | 479 if( (unsigned)s->screen_width > 32767 |
639 | 480 || (unsigned)s->screen_height > 32767){ |
481 av_log(NULL, AV_LOG_ERROR, "picture size too large\n"); | |
482 return -1; | |
885 | 483 } |
639 | 484 |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
485 v = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
486 s->color_resolution = ((v & 0x70) >> 4) + 1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
487 has_global_palette = (v & 0x80); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
488 s->bits_per_pixel = (v & 0x07) + 1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
489 s->background_color_index = get_byte(f); |
887 | 490 get_byte(f); /* ignored */ |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
491 #ifdef DEBUG |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
492 printf("gif: screen_w=%d screen_h=%d bpp=%d global_palette=%d\n", |
887 | 493 s->screen_width, s->screen_height, s->bits_per_pixel, |
494 has_global_palette); | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
495 #endif |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
496 if (has_global_palette) { |
887 | 497 n = 1 << s->bits_per_pixel; |
498 get_buffer(f, s->global_palette, n * 3); | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
499 } |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
500 return 0; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
501 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
502 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
503 static int gif_parse_next_image(GifState *s) |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
504 { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
505 ByteIOContext *f = s->f; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
506 int ret, code; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
507 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
508 for (;;) { |
887 | 509 code = url_fgetc(f); |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
510 #ifdef DEBUG |
887 | 511 printf("gif: code=%02x '%c'\n", code, code); |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
512 #endif |
887 | 513 switch (code) { |
514 case ',': | |
515 if (gif_read_image(s) < 0) | |
516 return AVERROR_IO; | |
517 ret = 0; | |
518 goto the_end; | |
519 case ';': | |
520 /* end of image */ | |
521 ret = AVERROR_IO; | |
522 goto the_end; | |
523 case '!': | |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
524 if (gif_read_extension(s) < 0) |
482 | 525 return AVERROR_IO; |
887 | 526 break; |
527 case EOF: | |
528 default: | |
529 /* error or errneous EOF */ | |
530 ret = AVERROR_IO; | |
531 goto the_end; | |
532 } | |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
533 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
534 the_end: |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
535 return ret; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
536 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
537 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
538 static int gif_read_header(AVFormatContext * s1, |
887 | 539 AVFormatParameters * ap) |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
540 { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
541 GifState *s = s1->priv_data; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
542 ByteIOContext *f = &s1->pb; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
543 AVStream *st; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
544 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
545 s->f = f; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
546 if (gif_read_header1(s) < 0) |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
547 return -1; |
885 | 548 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
549 /* allocate image buffer */ |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
550 s->image_linesize = s->screen_width * 3; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
551 s->image_buf = av_malloc(s->screen_height * s->image_linesize); |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
552 if (!s->image_buf) |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
553 return -ENOMEM; |
60 | 554 s->pix_fmt = PIX_FMT_RGB24; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
555 /* now we are ready: build format streams */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
556 st = av_new_stream(s1, 0); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
557 if (!st) |
887 | 558 return -1; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
559 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
743
diff
changeset
|
560 st->codec->codec_type = CODEC_TYPE_VIDEO; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
743
diff
changeset
|
561 st->codec->codec_id = CODEC_ID_RAWVIDEO; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
743
diff
changeset
|
562 st->codec->time_base.den = 5; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
743
diff
changeset
|
563 st->codec->time_base.num = 1; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
564 /* XXX: check if screen size is always valid */ |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
743
diff
changeset
|
565 st->codec->width = s->screen_width; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
743
diff
changeset
|
566 st->codec->height = s->screen_height; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
743
diff
changeset
|
567 st->codec->pix_fmt = PIX_FMT_RGB24; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
568 return 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
569 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
570 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
571 static int gif_read_packet(AVFormatContext * s1, |
887 | 572 AVPacket * pkt) |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
573 { |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
574 GifState *s = s1->priv_data; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
575 int ret; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
576 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
577 ret = gif_parse_next_image(s); |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
578 if (ret < 0) |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
579 return ret; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
580 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
581 /* XXX: avoid copying */ |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
582 if (av_new_packet(pkt, s->screen_width * s->screen_height * 3)) { |
887 | 583 return AVERROR_IO; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
584 } |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
585 pkt->stream_index = 0; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
586 memcpy(pkt->data, s->image_buf, s->screen_width * s->screen_height * 3); |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
587 return 0; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
588 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
589 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
590 static int gif_read_close(AVFormatContext *s1) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
591 { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
592 GifState *s = s1->priv_data; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
593 av_free(s->image_buf); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
594 return 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
595 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
596 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
597 /* read gif as image */ |
885 | 598 static int gif_read(ByteIOContext *f, |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
599 int (*alloc_cb)(void *opaque, AVImageInfo *info), void *opaque) |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
600 { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
601 GifState s1, *s = &s1; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
602 AVImageInfo info1, *info = &info1; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
603 int ret; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
604 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
605 memset(s, 0, sizeof(GifState)); |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
606 s->f = f; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
607 if (gif_read_header1(s) < 0) |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
608 return -1; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
609 info->width = s->screen_width; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
610 info->height = s->screen_height; |
60 | 611 info->pix_fmt = PIX_FMT_PAL8; |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
612 ret = alloc_cb(opaque, info); |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
613 if (ret) |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
614 return ret; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
615 s->image_buf = info->pict.data[0]; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
616 s->image_linesize = info->pict.linesize[0]; |
60 | 617 s->image_palette = (uint32_t *)info->pict.data[1]; |
618 | |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
619 if (gif_parse_next_image(s) < 0) |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
620 return -1; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
621 return 0; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
622 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
623 |
1167 | 624 AVInputFormat gif_demuxer = |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
625 { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
626 "gif", |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
627 "gif format", |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
628 sizeof(GifState), |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
629 gif_video_probe, |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
630 gif_read_header, |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
631 gif_read_packet, |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
632 gif_read_close, |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
633 }; |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
634 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
635 AVImageFormat gif_image_format = { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
636 "gif", |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
637 "gif", |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
638 gif_image_probe, |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
639 gif_read, |
60 | 640 (1 << PIX_FMT_PAL8), |
1169 | 641 #ifdef CONFIG_GIF_MUXER |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
642 gif_write, |
1169 | 643 #endif |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
644 }; |