Mercurial > libavformat.hg
annotate gifdec.c @ 3039:1135ef610233 libavformat
Include poll.h instead of sys/poll.h
author | lucabe |
---|---|
date | Wed, 13 Feb 2008 12:51:14 +0000 |
parents | d52c718e83f9 |
children | ed30b032fa7b |
rev | line source |
---|---|
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
1 /* |
1415
3b00fb8ef8e4
replace coder/decoder file description in libavformat by muxer/demuxer
aurel
parents:
1358
diff
changeset
|
2 * GIF demuxer |
46
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 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
23 //#define DEBUG |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
24 |
887 | 25 #define MAXBITS 12 |
26 #define SIZTABLE (1<<MAXBITS) | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
27 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
28 #define GCE_DISPOSAL_NONE 0 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
29 #define GCE_DISPOSAL_INPLACE 1 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
30 #define GCE_DISPOSAL_BACKGROUND 2 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
31 #define GCE_DISPOSAL_RESTORE 3 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
32 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
33 typedef struct GifState { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
34 int screen_width; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
35 int screen_height; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
36 int bits_per_pixel; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
37 int background_color_index; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
38 int transparent_color_index; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
39 int color_resolution; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
40 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
|
41 int image_linesize; |
60 | 42 uint32_t *image_palette; |
43 int pix_fmt; | |
44 | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
45 /* 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
|
46 int gce_disposal; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
47 /* delay during which the frame is shown */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
48 int gce_delay; |
885 | 49 |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
50 /* LZW compatible decoder */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
51 ByteIOContext *f; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
52 int eob_reached; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
53 uint8_t *pbuf, *ebuf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
54 int bbits; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
55 unsigned int bbuf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
56 |
887 | 57 int cursize; /* The current code size */ |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
58 int curmask; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
59 int codesize; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
60 int clear_code; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
61 int end_code; |
887 | 62 int newcodes; /* First available code */ |
63 int top_slot; /* Highest code for current size */ | |
64 int slot; /* Last read code */ | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
65 int fc, oc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
66 uint8_t *sp; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
67 uint8_t stack[SIZTABLE]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
68 uint8_t suffix[SIZTABLE]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
69 uint16_t prefix[SIZTABLE]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
70 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
71 /* aux buffers */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
72 uint8_t global_palette[256 * 3]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
73 uint8_t local_palette[256 * 3]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
74 uint8_t buf[256]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
75 } GifState; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
76 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
77 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
78 static const uint8_t gif87a_sig[6] = "GIF87a"; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
79 static const uint8_t gif89a_sig[6] = "GIF89a"; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
80 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
81 static const uint16_t mask[17] = |
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 0x0000, 0x0001, 0x0003, 0x0007, |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
84 0x000F, 0x001F, 0x003F, 0x007F, |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
85 0x00FF, 0x01FF, 0x03FF, 0x07FF, |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
86 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
87 }; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
88 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
89 /* 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
95 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
|
96 int bits_per_pixel, has_global_palette, ext_code, ext_len; |
116 | 97 int gce_flags, gce_disposal; |
98 | |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
99 if (pd->buf_size < 24 || |
887 | 100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 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
|
109 for(;;) { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
110 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
|
111 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
|
112 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
|
113 break; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
114 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 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
|
116 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
|
117 ext_code = *p++; |
116 | 118 if (p >= p_end) |
119 return 0; | |
120 ext_len = *p++; | |
121 if (ext_code == 0xf9) { | |
122 if (p >= p_end) | |
123 return 0; | |
124 /* if GCE extension found with gce_disposal != 0: it is | |
125 likely to be an animation */ | |
126 gce_flags = *p++; | |
127 gce_disposal = (gce_flags >> 2) & 0x7; | |
128 if (gce_disposal != 0) | |
129 return AVPROBE_SCORE_MAX; | |
130 else | |
131 return 0; | |
132 } | |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
133 for(;;) { |
116 | 134 if (ext_len == 0) |
135 break; | |
136 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
|
137 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
|
138 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
|
139 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
|
140 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
141 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
142 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
|
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 |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
145 static void GLZWDecodeInit(GifState * s, int csize) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
146 { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
147 /* read buffer */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
148 s->eob_reached = 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
149 s->pbuf = s->buf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
150 s->ebuf = s->buf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
151 s->bbuf = 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
152 s->bbits = 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
153 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
154 /* decoder */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
155 s->codesize = csize; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
156 s->cursize = s->codesize + 1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
157 s->curmask = mask[s->cursize]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
158 s->top_slot = 1 << s->cursize; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
159 s->clear_code = 1 << s->codesize; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
160 s->end_code = s->clear_code + 1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
161 s->slot = s->newcodes = s->clear_code + 2; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
162 s->oc = s->fc = 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
163 s->sp = s->stack; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
164 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
165 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
166 /* XXX: optimize */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
167 static inline int GetCode(GifState * s) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
168 { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
169 int c, sizbuf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
170 uint8_t *ptr; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
171 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
172 while (s->bbits < s->cursize) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
173 ptr = s->pbuf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
174 if (ptr >= s->ebuf) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
175 if (!s->eob_reached) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
176 sizbuf = get_byte(s->f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
177 s->ebuf = s->buf + sizbuf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
178 s->pbuf = s->buf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
179 if (sizbuf > 0) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
180 get_buffer(s->f, s->buf, sizbuf); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
181 } else { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
182 s->eob_reached = 1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
183 } |
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 ptr = s->pbuf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
186 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
187 s->bbuf |= ptr[0] << s->bbits; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
188 ptr++; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
189 s->pbuf = ptr; |
887 | 190 s->bbits += 8; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
191 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
192 c = s->bbuf & s->curmask; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
193 s->bbuf >>= s->cursize; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
194 s->bbits -= s->cursize; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
195 return c; |
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 /* 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
|
199 written by Steven A. Bennett in 1987. */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
200 /* return the number of byte decoded */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
201 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
|
202 { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
203 int l, c, code, oc, fc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
204 uint8_t *sp; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
205 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
206 if (s->end_code < 0) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
207 return 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
208 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
209 l = len; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
210 sp = s->sp; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
211 oc = s->oc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
212 fc = s->fc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
213 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
214 while (sp > s->stack) { |
887 | 215 *buf++ = *(--sp); |
216 if ((--l) == 0) | |
217 goto the_end; | |
46
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 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
220 for (;;) { |
887 | 221 c = GetCode(s); |
222 if (c == s->end_code) { | |
223 s->end_code = -1; | |
224 break; | |
225 } else if (c == s->clear_code) { | |
226 s->cursize = s->codesize + 1; | |
227 s->curmask = mask[s->cursize]; | |
228 s->slot = s->newcodes; | |
229 s->top_slot = 1 << s->cursize; | |
230 while ((c = GetCode(s)) == s->clear_code); | |
231 if (c == s->end_code) { | |
232 s->end_code = -1; | |
233 break; | |
234 } | |
235 /* test error */ | |
236 if (c >= s->slot) | |
237 c = 0; | |
238 fc = oc = c; | |
239 *buf++ = c; | |
240 if ((--l) == 0) | |
241 break; | |
242 } else { | |
243 code = c; | |
244 if (code >= s->slot) { | |
245 *sp++ = fc; | |
246 code = oc; | |
247 } | |
248 while (code >= s->newcodes) { | |
249 *sp++ = s->suffix[code]; | |
250 code = s->prefix[code]; | |
251 } | |
252 *sp++ = code; | |
253 if (s->slot < s->top_slot) { | |
254 s->suffix[s->slot] = fc = code; | |
255 s->prefix[s->slot++] = oc; | |
256 oc = c; | |
257 } | |
258 if (s->slot >= s->top_slot) { | |
259 if (s->cursize < MAXBITS) { | |
260 s->top_slot <<= 1; | |
261 s->curmask = mask[++s->cursize]; | |
262 } | |
263 } | |
264 while (sp > s->stack) { | |
265 *buf++ = *(--sp); | |
266 if ((--l) == 0) | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
267 goto the_end; |
887 | 268 } |
269 } | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
270 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
271 the_end: |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
272 s->sp = sp; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
273 s->oc = oc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
274 s->fc = fc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
275 return len - l; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
276 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
277 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
278 static int gif_read_image(GifState *s) |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
279 { |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
280 ByteIOContext *f = s->f; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
281 int left, top, width, height, bits_per_pixel, code_size, flags; |
60 | 282 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
|
283 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
|
284 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
285 left = get_le16(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
286 top = get_le16(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
287 width = get_le16(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
288 height = get_le16(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
289 flags = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
290 is_interleaved = flags & 0x40; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
291 has_local_palette = flags & 0x80; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
292 bits_per_pixel = (flags & 0x07) + 1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
293 #ifdef DEBUG |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
294 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
|
295 #endif |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
296 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
297 if (has_local_palette) { |
887 | 298 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
|
299 palette = s->local_palette; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
300 } else { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
301 palette = s->global_palette; |
60 | 302 bits_per_pixel = s->bits_per_pixel; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
303 } |
885 | 304 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
305 /* 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
|
306 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
|
307 top + height > s->screen_height) |
1787
eb16c64144ee
This fixes error handling for BeOS, removing the need for some ifdefs.
mmu_man
parents:
1444
diff
changeset
|
308 return AVERROR(EINVAL); |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
309 |
60 | 310 /* build the palette */ |
311 if (s->pix_fmt == PIX_FMT_RGB24) { | |
312 line = av_malloc(width); | |
313 if (!line) | |
1787
eb16c64144ee
This fixes error handling for BeOS, removing the need for some ifdefs.
mmu_man
parents:
1444
diff
changeset
|
314 return AVERROR(ENOMEM); |
60 | 315 } else { |
316 n = (1 << bits_per_pixel); | |
317 spal = palette; | |
318 for(i = 0; i < n; i++) { | |
885 | 319 s->image_palette[i] = (0xff << 24) | |
60 | 320 (spal[0] << 16) | (spal[1] << 8) | (spal[2]); |
321 spal += 3; | |
322 } | |
323 for(; i < 256; i++) | |
324 s->image_palette[i] = (0xff << 24); | |
116 | 325 /* handle transparency */ |
326 if (s->transparent_color_index >= 0) | |
327 s->image_palette[s->transparent_color_index] = 0; | |
60 | 328 line = NULL; |
329 } | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
330 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
331 /* now get the image data */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
332 s->f = f; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
333 code_size = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
334 GLZWDecodeInit(s, code_size); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
335 |
60 | 336 /* 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
|
337 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
|
338 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
|
339 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
|
340 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
|
341 y1 = 0; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
342 for (y = 0; y < height; y++) { |
60 | 343 if (s->pix_fmt == PIX_FMT_RGB24) { |
344 /* transcode to RGB24 */ | |
345 GLZWDecode(s, line, width); | |
346 d = ptr; | |
347 sptr = line; | |
348 for(x = 0; x < width; x++) { | |
349 spal = palette + sptr[0] * 3; | |
350 d[0] = spal[0]; | |
351 d[1] = spal[1]; | |
352 d[2] = spal[2]; | |
353 d += 3; | |
354 sptr++; | |
355 } | |
356 } else { | |
357 GLZWDecode(s, ptr, width); | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
358 } |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
359 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
|
360 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
|
361 default: |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
362 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
|
363 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
|
364 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
|
365 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
|
366 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
|
367 y1 = 4; |
885 | 368 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
|
369 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
|
370 else |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
371 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
|
372 pass++; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
373 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
374 break; |
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 2: |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
376 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
|
377 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
|
378 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
|
379 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
|
380 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
|
381 pass++; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
382 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
383 break; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
384 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
|
385 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
|
386 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
|
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 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
389 } else { |
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; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
391 } |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
392 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
393 av_free(line); |
885 | 394 |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
395 /* 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
|
396 while (!s->eob_reached) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
397 GetCode(s); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
398 return 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
399 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
400 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
401 static int gif_read_extension(GifState *s) |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
402 { |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
403 ByteIOContext *f = s->f; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
404 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
|
405 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
406 /* extension */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
407 ext_code = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
408 ext_len = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
409 #ifdef DEBUG |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
410 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
|
411 #endif |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
412 switch(ext_code) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
413 case 0xf9: |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
414 if (ext_len != 4) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
415 goto discard_ext; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
416 s->transparent_color_index = -1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
417 gce_flags = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
418 s->gce_delay = get_le16(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
419 gce_transparent_index = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
420 if (gce_flags & 0x01) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
421 s->transparent_color_index = gce_transparent_index; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
422 else |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
423 s->transparent_color_index = -1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
424 s->gce_disposal = (gce_flags >> 2) & 0x7; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
425 #ifdef DEBUG |
885 | 426 printf("gif: gce_flags=%x delay=%d tcolor=%d disposal=%d\n", |
427 gce_flags, s->gce_delay, | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
428 s->transparent_color_index, s->gce_disposal); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
429 #endif |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
430 ext_len = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
431 break; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
432 } |
885 | 433 |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
434 /* NOTE: many extension blocks can come after */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
435 discard_ext: |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
436 while (ext_len != 0) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
437 for (i = 0; i < ext_len; i++) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
438 get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
439 ext_len = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
440 #ifdef DEBUG |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
441 printf("gif: ext_len1=%d\n", ext_len); |
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 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
444 return 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
445 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
446 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
447 static int gif_read_header1(GifState *s) |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
448 { |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
449 ByteIOContext *f = s->f; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
450 uint8_t sig[6]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
451 int ret, v, n; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
452 int has_global_palette; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
453 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
454 /* read gif signature */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
455 ret = get_buffer(f, sig, 6); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
456 if (ret != 6) |
887 | 457 return -1; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
458 if (memcmp(sig, gif87a_sig, 6) != 0 && |
887 | 459 memcmp(sig, gif89a_sig, 6) != 0) |
460 return -1; | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
461 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
462 /* read screen header */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
463 s->transparent_color_index = -1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
464 s->screen_width = get_le16(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
465 s->screen_height = get_le16(f); |
885 | 466 if( (unsigned)s->screen_width > 32767 |
639 | 467 || (unsigned)s->screen_height > 32767){ |
468 av_log(NULL, AV_LOG_ERROR, "picture size too large\n"); | |
469 return -1; | |
885 | 470 } |
639 | 471 |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
472 v = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
473 s->color_resolution = ((v & 0x70) >> 4) + 1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
474 has_global_palette = (v & 0x80); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
475 s->bits_per_pixel = (v & 0x07) + 1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
476 s->background_color_index = get_byte(f); |
887 | 477 get_byte(f); /* ignored */ |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
478 #ifdef DEBUG |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
479 printf("gif: screen_w=%d screen_h=%d bpp=%d global_palette=%d\n", |
887 | 480 s->screen_width, s->screen_height, s->bits_per_pixel, |
481 has_global_palette); | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
482 #endif |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
483 if (has_global_palette) { |
887 | 484 n = 1 << s->bits_per_pixel; |
485 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
|
486 } |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
487 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
|
488 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
489 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
490 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
|
491 { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
492 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
|
493 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
|
494 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
495 for (;;) { |
887 | 496 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
|
497 #ifdef DEBUG |
887 | 498 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
|
499 #endif |
887 | 500 switch (code) { |
501 case ',': | |
502 if (gif_read_image(s) < 0) | |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
1787
diff
changeset
|
503 return AVERROR(EIO); |
887 | 504 ret = 0; |
505 goto the_end; | |
506 case ';': | |
507 /* end of image */ | |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
1787
diff
changeset
|
508 ret = AVERROR(EIO); |
887 | 509 goto the_end; |
510 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
|
511 if (gif_read_extension(s) < 0) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
1787
diff
changeset
|
512 return AVERROR(EIO); |
887 | 513 break; |
514 case EOF: | |
515 default: | |
516 /* error or errneous EOF */ | |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
1787
diff
changeset
|
517 ret = AVERROR(EIO); |
887 | 518 goto the_end; |
519 } | |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
520 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
521 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
|
522 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
|
523 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
524 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
525 static int gif_read_header(AVFormatContext * s1, |
887 | 526 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
|
527 { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
528 GifState *s = s1->priv_data; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2274
diff
changeset
|
529 ByteIOContext *f = s1->pb; |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
530 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
|
531 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
532 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
|
533 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
|
534 return -1; |
885 | 535 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
536 /* 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
|
537 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
|
538 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
|
539 if (!s->image_buf) |
1787
eb16c64144ee
This fixes error handling for BeOS, removing the need for some ifdefs.
mmu_man
parents:
1444
diff
changeset
|
540 return AVERROR(ENOMEM); |
60 | 541 s->pix_fmt = PIX_FMT_RGB24; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
542 /* now we are ready: build format streams */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
543 st = av_new_stream(s1, 0); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
544 if (!st) |
887 | 545 return -1; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
546 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
743
diff
changeset
|
547 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
|
548 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
|
549 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
|
550 st->codec->time_base.num = 1; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
551 /* 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
|
552 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
|
553 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
|
554 st->codec->pix_fmt = PIX_FMT_RGB24; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
555 return 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
556 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
557 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
558 static int gif_read_packet(AVFormatContext * s1, |
887 | 559 AVPacket * pkt) |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
560 { |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
561 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
|
562 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
|
563 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
564 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
|
565 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
|
566 return ret; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
567 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
568 /* 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
|
569 if (av_new_packet(pkt, s->screen_width * s->screen_height * 3)) { |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
1787
diff
changeset
|
570 return AVERROR(EIO); |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
571 } |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
572 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
|
573 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
|
574 return 0; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
575 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
576 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
577 static int gif_read_close(AVFormatContext *s1) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
578 { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
579 GifState *s = s1->priv_data; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
580 av_free(s->image_buf); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
581 return 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
582 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
583 |
1167 | 584 AVInputFormat gif_demuxer = |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
585 { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
586 "gif", |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
587 "gif format", |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
588 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
|
589 gif_video_probe, |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
590 gif_read_header, |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
591 gif_read_packet, |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
592 gif_read_close, |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
593 }; |