1 /*
2 * Deluxe Paint Animation decoder
3 * Copyright (c) 2009 Peter Ross
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * Deluxe Paint Animation decoder
25 */
26
30
35 int x;
///< x coordinate position
37
39 {
41 int i;
42
44
48
52
54 for (i = 0; i < 256; i++)
55 s->
palette[i] = bytestream2_get_le32u(&s->
gb);
56
57 return 0;
58 }
59
60 /**
61 * Perform decode operation
62 * @param dst pointer to destination image buffer
63 * @param dst_end pointer to end of destination image buffer
64 * @param gb GetByteContext (optional, see below)
65 * @param pixel Fill color (optional, see below)
66 * @param count Pixel count
67 * @param x Pointer to x-axis counter
68 * @param width Image width
69 * @param linesize Destination image buffer linesize
70 * @return non-zero if destination buffer is exhausted
71 *
72 * a copy operation is achieved when 'gb' is set
73 * a fill operation is achieved when 'gb' is null and pixel is >= 0
74 * a skip operation is achieved when 'gb' is null and pixel is < 0
75 */
79 int *x,
int width,
int linesize)
80 {
81 int remaining = width - *x;
82 while(count > 0) {
83 int striplen =
FFMIN(count, remaining);
84 if (gb) {
86 goto exhausted;
88 } else if (pixel >= 0)
89 memset(*dst, pixel, striplen);
90 *dst += striplen;
91 remaining -= striplen;
92 count -= striplen;
93 if (remaining <= 0) {
94 *dst += linesize -
width;
96 }
97 if (linesize > 0) {
98 if (*dst >= dst_end) goto exhausted;
99 } else {
100 if (*dst <= dst_end) goto exhausted;
101 }
102 }
103 *x = width - remaining;
104 return 0;
105
106 exhausted:
107 *x = width - remaining;
108 return 1;
109 }
110
112 void *
data,
int *got_frame,
114 {
116 const int buf_size = avpkt->
size;
119
124
126
127 if (bytestream2_get_byte(&s->
gb) != 0x42) {
130 }
131 if (bytestream2_get_byte(&s->
gb)) {
134 }
136
138 do {
139 /* if statements are ordered by probability */
140 #define OP(gb, pixel, count) \
141 op(&dst, dst_end, (gb), (pixel), (count), &s->x, avctx->width, s->frame->linesize[0])
142
143 int type = bytestream2_get_byte(&s->
gb);
144 count = type & 0x7F;
145 type >>= 7;
146 if (count) {
147 if (
OP(type ? NULL : &s->
gb, -1, count))
break;
148 } else if (!type) {
150 count = bytestream2_get_byte(&s->
gb);
/* count==0 gives nop */
151 pixel = bytestream2_get_byte(&s->
gb);
152 if (
OP(NULL, pixel, count))
break;
153 } else {
155 type = bytestream2_get_le16(&s->
gb);
156 count = type & 0x3FFF;
157 type >>= 14;
158 if (!count) {
159 if (type == 0)
160 break; // stop
161 if (type == 2) {
164 }
165 continue;
166 }
167 pixel = type == 3 ? bytestream2_get_byte(&s->
gb) : -1;
168 if (type == 1) count += 0x4000;
169 if (
OP(type == 2 ? &s->
gb : NULL, pixel, count))
break;
170 }
172
174
175 *got_frame = 1;
178
179 return buf_size;
180 }
181
183 {
185
187 return 0;
188 }
189
200 };