1 /*
2 * QPEG codec
3 * Copyright (c) 2004 Konstantin Shishkov
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 * QPEG codec.
25 */
26
32
39
42 {
47 int filled = 0;
48 int rows_to_go;
49
53
57 if(
code == 0xFC)
/* end-of-picture code */
58 break;
59 if(
code >= 0xF8) {
/* very long run */
60 c0 = bytestream2_get_byte(&qctx->
buffer);
61 c1 = bytestream2_get_byte(&qctx->
buffer);
62 run = ((
code & 0x7) << 16) + (c0 << 8) +
c1 + 2;
63 }
else if (
code >= 0xF0) {
/* long run */
64 c0 = bytestream2_get_byte(&qctx->
buffer);
65 run = ((
code & 0xF) << 8) + c0 + 2;
66 }
else if (
code >= 0xE0) {
/* short run */
68 }
else if (
code >= 0xC0) {
/* very long copy */
69 c0 = bytestream2_get_byte(&qctx->
buffer);
70 c1 = bytestream2_get_byte(&qctx->
buffer);
71 copy = ((
code & 0x3F) << 16) + (c0 << 8) +
c1 + 1;
72 }
else if (
code >= 0x80) {
/* long copy */
73 c0 = bytestream2_get_byte(&qctx->
buffer);
74 copy = ((
code & 0x7F) << 8) + c0 + 1;
75 } else { /* short copy */
77 }
78
79 /* perform actual run or copy */
81 int p;
82
83 p = bytestream2_get_byte(&qctx->
buffer);
86 memset(dst+filled, p,
step);
89 if (filled >=
width) {
90 filled = 0;
92 rows_to_go--;
93 while (
run -
i >
width && rows_to_go > 0) {
94 memset(dst, p,
width);
96 rows_to_go--;
98 }
99 if(rows_to_go <= 0)
100 break;
101 }
102 }
103 } else {
111 if (filled >=
width) {
112 filled = 0;
114 rows_to_go--;
115 if(rows_to_go <= 0)
116 break;
117 }
118 }
119 }
120 }
121 }
122
124 { 0x00, 0x20, 0x20, 0x20, 0x18, 0x10, 0x10, 0x20, 0x10, 0x08, 0x18, 0x08, 0x08, 0x18, 0x10, 0x04};
126 { 0x00, 0x20, 0x18, 0x08, 0x18, 0x10, 0x20, 0x10, 0x08, 0x10, 0x20, 0x20, 0x08, 0x10, 0x18, 0x04};
127
128 /* Decodes delta frames */
131 int delta,
const uint8_t *ctable,
132 uint8_t *refdata)
133 {
136 int filled = 0;
137 int orig_height;
138
139 if (refdata) {
140 /* copy prev frame */
143 } else {
144 refdata = dst;
145 }
146
150
153
155 /* motion compensation */
158 int me_idx;
159 int me_w, me_h, me_x, me_y;
160 uint8_t *me_plane;
162
163 /* get block size by index */
167
168 /* extract motion vector */
169 corr = bytestream2_get_byte(&qctx->
buffer);
170
175
180
181 /* check motion vector */
182 if ((me_x + filled < 0) || (me_x + me_w + filled >
width) ||
183 (
height - me_y - me_h < 0) || (
height - me_y >= orig_height) ||
186 me_x, me_y, me_w, me_h, filled,
height);
187 else {
188 /* do motion compensation */
189 me_plane = refdata + (filled + me_x) + (
height - me_y) *
stride;
190 for(j = 0; j < me_h; j++) {
191 for(
i = 0;
i < me_w;
i++)
193 }
194 }
195 }
197 }
198 }
199
200 if(
code == 0xE0)
/* end-of-picture code */
201 break;
202 if(
code > 0xE0) {
/* run code: 0xE1..0xFF */
203 int p;
204
206 p = bytestream2_get_byte(&qctx->
buffer);
208 dst[filled++] = p;
209 if(filled >=
width) {
210 filled = 0;
214 break;
215 }
216 }
217 }
else if(
code >= 0xC0) {
/* copy code: 0xC0..0xDF */
219
221 break;
222
224 dst[filled++] = bytestream2_get_byte(&qctx->
buffer);
225 if(filled >=
width) {
226 filled = 0;
230 break;
231 }
232 }
233 }
else if(
code >= 0x80) {
/* skip code: 0x80..0xBF */
234 int skip;
235
237 /* codes 0x80 and 0x81 are actually escape codes,
238 skip value minus constant is in the next byte */
240 skip = bytestream2_get_byte(&qctx->
buffer) + 64;
242 skip = bytestream2_get_byte(&qctx->
buffer) + 320;
243 else
245 filled += skip;
246 while( filled >=
width) {
251 break;
252 }
253 } else {
254 /* zero code treated as one-pixel skip */
256 dst[filled++] = ctable[
code & 0x7F];
257 }
258 else
259 filled++;
260 if(filled >=
width) {
261 filled = 0;
264 }
265 }
266 }
267 }
268
271 {
272 uint8_t ctable[128];
275 uint8_t* outdata;
277
278 if (avpkt->
size < 0x86) {
281 }
282
284
287 outdata = p->
data[0];
291
292 delta = bytestream2_get_byte(&
a->buffer);
293 intra =
delta == 0x10;
294 if (intra) {
296 } else {
298 }
299
300 /* make the palette available on the way out */
303
307
310
311 *got_frame = 1;
312
314 }
315
319 const uint8_t *pal_src;
320
322
325
326 for (
i=0;
i<pal_size/4;
i++)
328 }
329
331 {
333
335
336 return 0;
337 }
338
341
344
348
350
351 return 0;
352 }
353
367 };