Mercurial > libavformat.hg
annotate gifdec.c @ 80:63807035cdb5 libavformat
10l
author | michaelni |
---|---|
date | Sat, 08 Mar 2003 23:39:53 +0000 |
parents | c89672a5f24e |
children | 25062c9b1f86 |
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 * |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
5 * This library is free software; you can redistribute it and/or |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
6 * 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
|
7 * License as published by the Free Software Foundation; either |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
8 * version 2 of the License, or (at your option) any later version. |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
9 * |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
10 * This library is distributed in the hope that it will be useful, |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
11 * 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
|
12 * 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
|
13 * Lesser General Public License for more details. |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
14 * |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
15 * You should have received a copy of the GNU Lesser General Public |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
16 * License along with this library; if not, write to the Free Software |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
18 */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
19 #include "avformat.h" |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
20 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
21 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
|
22 |
46
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 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
25 #define MAXBITS 12 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
26 #define SIZTABLE (1<<MAXBITS) |
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; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
49 |
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 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
57 int cursize; /* The current code size */ |
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; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
62 int newcodes; /* First available code */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
63 int top_slot; /* Highest code for current size */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
64 int slot; /* Last read code */ |
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; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
97 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
98 if (pd->buf_size < 24 || |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
99 memcmp(pd->buf, gif89a_sig, 6) != 0) |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 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
|
106 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
|
107 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
|
108 for(;;) { |
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 (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
|
110 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
|
111 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
|
112 break; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
113 p++; |
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 >= 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
|
115 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
|
116 ext_code = *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 GCE extension found: it is likely to be an animation */ |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
118 if (ext_code == 0xf9) |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
119 return AVPROBE_SCORE_MAX; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
120 for(;;) { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
121 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
|
122 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
|
123 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
|
124 if (ext_len == 0) |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
125 break; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
126 p += ext_len; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
127 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
128 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
129 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
|
130 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
131 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
132 static int gif_image_probe(AVProbeData * pd) |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
133 { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
134 if (pd->buf_size >= 24 && |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
135 (memcmp(pd->buf, gif87a_sig, 6) == 0 || |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
136 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
|
137 return AVPROBE_SCORE_MAX - 1; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
138 else |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
139 return 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
140 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
141 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
142 |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
143 static void GLZWDecodeInit(GifState * s, int csize) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
144 { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
145 /* read buffer */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
146 s->eob_reached = 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
147 s->pbuf = s->buf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
148 s->ebuf = s->buf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
149 s->bbuf = 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
150 s->bbits = 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
151 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
152 /* decoder */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
153 s->codesize = csize; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
154 s->cursize = s->codesize + 1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
155 s->curmask = mask[s->cursize]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
156 s->top_slot = 1 << s->cursize; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
157 s->clear_code = 1 << s->codesize; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
158 s->end_code = s->clear_code + 1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
159 s->slot = s->newcodes = s->clear_code + 2; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
160 s->oc = s->fc = 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
161 s->sp = s->stack; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
162 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
163 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
164 /* XXX: optimize */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
165 static inline int GetCode(GifState * s) |
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 int c, sizbuf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
168 uint8_t *ptr; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
169 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
170 while (s->bbits < s->cursize) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
171 ptr = s->pbuf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
172 if (ptr >= s->ebuf) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
173 if (!s->eob_reached) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
174 sizbuf = get_byte(s->f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
175 s->ebuf = s->buf + sizbuf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
176 s->pbuf = s->buf; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
177 if (sizbuf > 0) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
178 get_buffer(s->f, s->buf, sizbuf); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
179 } else { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
180 s->eob_reached = 1; |
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 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
183 ptr = s->pbuf; |
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 s->bbuf |= ptr[0] << s->bbits; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
186 ptr++; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
187 s->pbuf = ptr; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
188 s->bbits += 8; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
189 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
190 c = s->bbuf & s->curmask; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
191 s->bbuf >>= s->cursize; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
192 s->bbits -= s->cursize; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
193 return c; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
194 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
195 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
196 /* 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
|
197 written by Steven A. Bennett in 1987. */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
198 /* return the number of byte decoded */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
199 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
|
200 { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
201 int l, c, code, oc, fc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
202 uint8_t *sp; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
203 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
204 if (s->end_code < 0) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
205 return 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
206 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
207 l = len; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
208 sp = s->sp; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
209 oc = s->oc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
210 fc = s->fc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
211 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
212 while (sp > s->stack) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
213 *buf++ = *(--sp); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
214 if ((--l) == 0) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
215 goto the_end; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
216 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
217 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
218 for (;;) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
219 c = GetCode(s); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
220 if (c == s->end_code) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
221 s->end_code = -1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
222 break; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
223 } else if (c == s->clear_code) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
224 s->cursize = s->codesize + 1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
225 s->curmask = mask[s->cursize]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
226 s->slot = s->newcodes; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
227 s->top_slot = 1 << s->cursize; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
228 while ((c = GetCode(s)) == s->clear_code); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
229 if (c == s->end_code) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
230 s->end_code = -1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
231 break; |
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 /* test error */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
234 if (c >= s->slot) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
235 c = 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
236 fc = oc = c; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
237 *buf++ = c; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
238 if ((--l) == 0) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
239 break; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
240 } else { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
241 code = c; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
242 if (code >= s->slot) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
243 *sp++ = fc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
244 code = oc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
245 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
246 while (code >= s->newcodes) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
247 *sp++ = s->suffix[code]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
248 code = s->prefix[code]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
249 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
250 *sp++ = code; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
251 if (s->slot < s->top_slot) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
252 s->suffix[s->slot] = fc = code; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
253 s->prefix[s->slot++] = oc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
254 oc = c; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
255 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
256 if (s->slot >= s->top_slot) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
257 if (s->cursize < MAXBITS) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
258 s->top_slot <<= 1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
259 s->curmask = mask[++s->cursize]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
260 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
261 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
262 while (sp > s->stack) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
263 *buf++ = *(--sp); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
264 if ((--l) == 0) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
265 goto the_end; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
266 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
267 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
268 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
269 the_end: |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
270 s->sp = sp; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
271 s->oc = oc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
272 s->fc = fc; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
273 return len - l; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
274 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
275 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
276 static int gif_read_image(GifState *s) |
46
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 ByteIOContext *f = s->f; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
279 int left, top, width, height, bits_per_pixel, code_size, flags; |
60 | 280 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
|
281 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
|
282 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
283 left = get_le16(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
284 top = get_le16(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
285 width = get_le16(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
286 height = get_le16(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
287 flags = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
288 is_interleaved = flags & 0x40; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
289 has_local_palette = flags & 0x80; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
290 bits_per_pixel = (flags & 0x07) + 1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
291 #ifdef DEBUG |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
292 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
|
293 #endif |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
294 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
295 if (has_local_palette) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
296 get_buffer(f, s->local_palette, 3 * (1 << bits_per_pixel)); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
297 palette = s->local_palette; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
298 } else { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
299 palette = s->global_palette; |
60 | 300 bits_per_pixel = s->bits_per_pixel; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
301 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
302 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
303 /* 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
|
304 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
|
305 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
|
306 return -EINVAL; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
307 |
60 | 308 /* build the palette */ |
309 if (s->pix_fmt == PIX_FMT_RGB24) { | |
310 line = av_malloc(width); | |
311 if (!line) | |
312 return -ENOMEM; | |
313 } else { | |
314 n = (1 << bits_per_pixel); | |
315 spal = palette; | |
316 for(i = 0; i < n; i++) { | |
317 s->image_palette[i] = (0xff << 24) | | |
318 (spal[0] << 16) | (spal[1] << 8) | (spal[2]); | |
319 spal += 3; | |
320 } | |
321 for(; i < 256; i++) | |
322 s->image_palette[i] = (0xff << 24); | |
323 line = NULL; | |
324 } | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
325 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
326 /* now get the image data */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
327 s->f = f; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
328 code_size = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
329 GLZWDecodeInit(s, code_size); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
330 |
60 | 331 /* 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
|
332 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
|
333 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
|
334 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
|
335 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
|
336 y1 = 0; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
337 for (y = 0; y < height; y++) { |
60 | 338 if (s->pix_fmt == PIX_FMT_RGB24) { |
339 /* transcode to RGB24 */ | |
340 GLZWDecode(s, line, width); | |
341 d = ptr; | |
342 sptr = line; | |
343 for(x = 0; x < width; x++) { | |
344 spal = palette + sptr[0] * 3; | |
345 d[0] = spal[0]; | |
346 d[1] = spal[1]; | |
347 d[2] = spal[2]; | |
348 d += 3; | |
349 sptr++; | |
350 } | |
351 } else { | |
352 GLZWDecode(s, ptr, width); | |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
353 } |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
354 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
|
355 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
|
356 default: |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
357 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
|
358 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
|
359 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
|
360 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
|
361 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
|
362 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
|
363 if (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
|
364 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
|
365 else |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
366 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
|
367 pass++; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
368 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
369 break; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
370 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
|
371 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
|
372 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
|
373 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
|
374 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
|
375 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
|
376 pass++; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
377 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
378 break; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
379 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
|
380 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
|
381 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
|
382 break; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
383 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
384 } else { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
385 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
|
386 } |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
387 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
388 av_free(line); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
389 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
390 /* 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
|
391 while (!s->eob_reached) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
392 GetCode(s); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
393 return 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
394 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
395 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
396 static int gif_read_extension(GifState *s) |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
397 { |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
398 ByteIOContext *f = s->f; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
399 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
|
400 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
401 /* extension */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
402 ext_code = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
403 ext_len = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
404 #ifdef DEBUG |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
405 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
|
406 #endif |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
407 switch(ext_code) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
408 case 0xf9: |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
409 if (ext_len != 4) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
410 goto discard_ext; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
411 s->transparent_color_index = -1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
412 gce_flags = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
413 s->gce_delay = get_le16(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
414 gce_transparent_index = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
415 if (gce_flags & 0x01) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
416 s->transparent_color_index = gce_transparent_index; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
417 else |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
418 s->transparent_color_index = -1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
419 s->gce_disposal = (gce_flags >> 2) & 0x7; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
420 #ifdef DEBUG |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
421 printf("gif: gce_flags=%x delay=%d tcolor=%d disposal=%d\n", |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
422 gce_flags, s->gce_delay, |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
423 s->transparent_color_index, s->gce_disposal); |
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 ext_len = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
426 break; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
427 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
428 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
429 /* NOTE: many extension blocks can come after */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
430 discard_ext: |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
431 while (ext_len != 0) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
432 for (i = 0; i < ext_len; i++) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
433 get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
434 ext_len = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
435 #ifdef DEBUG |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
436 printf("gif: ext_len1=%d\n", ext_len); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
437 #endif |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
438 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
439 return 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
440 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
441 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
442 static int gif_read_header1(GifState *s) |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
443 { |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
444 ByteIOContext *f = s->f; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
445 uint8_t sig[6]; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
446 int ret, v, n; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
447 int has_global_palette; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
448 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
449 /* read gif signature */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
450 ret = get_buffer(f, sig, 6); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
451 if (ret != 6) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
452 return -1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
453 if (memcmp(sig, gif87a_sig, 6) != 0 && |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
454 memcmp(sig, gif89a_sig, 6) != 0) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
455 return -1; |
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 /* read screen header */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
458 s->transparent_color_index = -1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
459 s->screen_width = get_le16(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
460 s->screen_height = get_le16(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
461 v = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
462 s->color_resolution = ((v & 0x70) >> 4) + 1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
463 has_global_palette = (v & 0x80); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
464 s->bits_per_pixel = (v & 0x07) + 1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
465 s->background_color_index = get_byte(f); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
466 get_byte(f); /* ignored */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
467 #ifdef DEBUG |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
468 printf("gif: screen_w=%d screen_h=%d bpp=%d global_palette=%d\n", |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
469 s->screen_width, s->screen_height, s->bits_per_pixel, |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
470 has_global_palette); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
471 #endif |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
472 if (has_global_palette) { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
473 n = 1 << s->bits_per_pixel; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
474 get_buffer(f, s->global_palette, n * 3); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
475 } |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
476 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
|
477 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
478 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
479 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
|
480 { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
481 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
|
482 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
|
483 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
484 for (;;) { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
485 code = url_fgetc(f); |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
486 #ifdef DEBUG |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
487 printf("gif: code=%02x '%c'\n", code, code); |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
488 #endif |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
489 switch (code) { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
490 case ',': |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
491 if (gif_read_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
|
492 return -EIO; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
493 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
|
494 goto 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
|
495 case ';': |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
496 /* end of image */ |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
497 ret = -EIO; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
498 goto 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
|
499 case '!': |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
500 if (gif_read_extension(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
|
501 return -EIO; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
502 break; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
503 case EOF: |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
504 default: |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
505 /* error or errneous EOF */ |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
506 ret = -EIO; |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
507 goto 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
|
508 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
509 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
510 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
|
511 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
|
512 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
513 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
514 static int gif_read_header(AVFormatContext * s1, |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
515 AVFormatParameters * ap) |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
516 { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
517 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
|
518 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
|
519 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
|
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 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
|
522 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
|
523 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
|
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 /* 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
|
526 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
|
527 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
|
528 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
|
529 return -ENOMEM; |
60 | 530 s->pix_fmt = PIX_FMT_RGB24; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
531 /* now we are ready: build format streams */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
532 st = av_new_stream(s1, 0); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
533 if (!st) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
534 return -1; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
535 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
536 st->codec.codec_type = CODEC_TYPE_VIDEO; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
537 st->codec.codec_id = CODEC_ID_RAWVIDEO; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
538 st->codec.frame_rate = 5 * FRAME_RATE_BASE; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
539 /* XXX: check if screen size is always valid */ |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
540 st->codec.width = s->screen_width; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
541 st->codec.height = s->screen_height; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
542 st->codec.pix_fmt = PIX_FMT_RGB24; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
543 return 0; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
544 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
545 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
546 static int gif_read_packet(AVFormatContext * s1, |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
547 AVPacket * pkt) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
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 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
|
550 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
|
551 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
552 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
|
553 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
|
554 return ret; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
555 |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
556 /* 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
|
557 if (av_new_packet(pkt, 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
|
558 return -EIO; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
559 } |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
560 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
|
561 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
|
562 return 0; |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
563 } |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
564 |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
565 static int gif_read_close(AVFormatContext *s1) |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
566 { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
567 GifState *s = s1->priv_data; |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
568 av_free(s->image_buf); |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
569 return 0; |
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 |
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 /* read gif as image */ |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
573 static int gif_read(ByteIOContext *f, |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
574 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
|
575 { |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
576 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
|
577 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
|
578 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
|
579 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
580 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
|
581 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
|
582 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
|
583 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
|
584 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
|
585 info->height = s->screen_height; |
60 | 586 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
|
587 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
|
588 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
|
589 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
|
590 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
|
591 s->image_linesize = info->pict.linesize[0]; |
60 | 592 s->image_palette = (uint32_t *)info->pict.data[1]; |
593 | |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
594 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
|
595 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
|
596 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
|
597 } |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
598 |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
599 AVInputFormat gif_iformat = |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
600 { |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
601 "gif", |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
602 "gif format", |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
603 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
|
604 gif_video_probe, |
46
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
605 gif_read_header, |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
606 gif_read_packet, |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
607 gif_read_close, |
890e9121a54d
added animated GIF decoder (pts and various disposal handling are missing)
bellard
parents:
diff
changeset
|
608 }; |
50
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
609 |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
610 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
|
611 "gif", |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
612 "gif", |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
613 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
|
614 gif_read, |
60 | 615 (1 << 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
|
616 gif_write, |
658be43f6a0d
added automatic GIF/animated GIF probing - added GIF as an image format too - added interlaced gif support
bellard
parents:
46
diff
changeset
|
617 }; |