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
31
38
41 {
46 int filled = 0;
47 int rows_to_go;
48
52
56 if(
code == 0xFC)
/* end-of-picture code */
57 break;
58 if(
code >= 0xF8) {
/* very long run */
59 c0 = bytestream2_get_byte(&qctx->
buffer);
60 c1 = bytestream2_get_byte(&qctx->
buffer);
61 run = ((
code & 0x7) << 16) + (c0 << 8) +
c1 + 2;
62 }
else if (
code >= 0xF0) {
/* long run */
63 c0 = bytestream2_get_byte(&qctx->
buffer);
64 run = ((
code & 0xF) << 8) + c0 + 2;
65 }
else if (
code >= 0xE0) {
/* short run */
67 }
else if (
code >= 0xC0) {
/* very long copy */
68 c0 = bytestream2_get_byte(&qctx->
buffer);
69 c1 = bytestream2_get_byte(&qctx->
buffer);
70 copy = ((
code & 0x3F) << 16) + (c0 << 8) +
c1 + 1;
71 }
else if (
code >= 0x80) {
/* long copy */
72 c0 = bytestream2_get_byte(&qctx->
buffer);
73 copy = ((
code & 0x7F) << 8) + c0 + 1;
74 } else { /* short copy */
76 }
77
78 /* perform actual run or copy */
80 int p;
81
82 p = bytestream2_get_byte(&qctx->
buffer);
88 if (filled >=
width) {
89 filled = 0;
91 rows_to_go--;
92 while (
run -
i >
width && rows_to_go > 0) {
95 rows_to_go--;
97 }
98 if(rows_to_go <= 0)
99 break;
100 }
101 }
102 } else {
110 if (filled >=
width) {
111 filled = 0;
113 rows_to_go--;
114 if(rows_to_go <= 0)
115 break;
116 }
117 }
118 }
119 }
120 }
121
123 { 0x00, 0x20, 0x20, 0x20, 0x18, 0x10, 0x10, 0x20, 0x10, 0x08, 0x18, 0x08, 0x08, 0x18, 0x10, 0x04};
125 { 0x00, 0x20, 0x18, 0x08, 0x18, 0x10, 0x20, 0x10, 0x08, 0x10, 0x20, 0x20, 0x08, 0x10, 0x18, 0x04};
126
127 /* Decodes delta frames */
130 int delta,
const uint8_t *ctable,
131 uint8_t *refdata)
132 {
135 int filled = 0;
136 int orig_height;
137
138 if (refdata) {
139 /* copy prev frame */
142 } else {
144 }
145
149
152
154 /* motion compensation */
157 int me_idx;
158 int me_w, me_h, me_x, me_y;
159 uint8_t *me_plane;
161
162 /* get block size by index */
166
167 /* extract motion vector */
168 corr = bytestream2_get_byte(&qctx->
buffer);
169
174
179
180 /* check motion vector */
181 if ((me_x + filled < 0) || (me_x + me_w + filled >
width) ||
182 (
height - me_y - me_h < 0) || (
height - me_y >= orig_height) ||
185 me_x, me_y, me_w, me_h, filled,
height);
186 else {
187 /* do motion compensation */
188 me_plane = refdata + (filled + me_x) + (
height - me_y) *
stride;
189 for(j = 0; j < me_h; j++) {
190 for(
i = 0;
i < me_w;
i++)
192 }
193 }
194 }
196 }
197 }
198
199 if(
code == 0xE0)
/* end-of-picture code */
200 break;
201 if(
code > 0xE0) {
/* run code: 0xE1..0xFF */
202 int p;
203
205 p = bytestream2_get_byte(&qctx->
buffer);
208 if(filled >=
width) {
209 filled = 0;
213 break;
214 }
215 }
216 }
else if(
code >= 0xC0) {
/* copy code: 0xC0..0xDF */
218
220 break;
221
223 dst[filled++] = bytestream2_get_byte(&qctx->
buffer);
224 if(filled >=
width) {
225 filled = 0;
229 break;
230 }
231 }
232 }
else if(
code >= 0x80) {
/* skip code: 0x80..0xBF */
234
236 /* codes 0x80 and 0x81 are actually escape codes,
237 skip value minus constant is in the next byte */
239 skip = bytestream2_get_byte(&qctx->
buffer) + 64;
241 skip = bytestream2_get_byte(&qctx->
buffer) + 320;
242 else
245 while( filled >=
width) {
250 break;
251 }
252 } else {
253 /* zero code treated as one-pixel skip */
255 dst[filled++] = ctable[
code & 0x7F];
256 }
257 else
258 filled++;
259 if(filled >=
width) {
260 filled = 0;
263 }
264 }
265 }
266 }
267
270 {
271 uint8_t ctable[128];
274 uint8_t* outdata;
276
277 if (avpkt->
size < 0x86) {
280 }
281
283
286 outdata = p->
data[0];
290
291 delta = bytestream2_get_byte(&
a->buffer);
292 intra =
delta == 0x10;
293 if (intra) {
295 } else {
297 }
298
299 /* make the palette available on the way out */
300 #if FF_API_PALETTE_HAS_CHANGED
303 #endif
305 #if FF_API_PALETTE_HAS_CHANGED
307 #endif
309
312
313 if (intra)
315 else
318
319 *got_frame = 1;
320
322 }
323
327 const uint8_t *pal_src;
328
330
333
334 for (
i=0;
i<pal_size/4;
i++)
336 }
337
339 {
341
343
344 return 0;
345 }
346
349
352
356
358
359 return 0;
360 }
361
374 };