1 /*
2 * Feeble Files/ScummVM DXA decoder
3 * Copyright (c) 2007 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 * DXA Video decoder
25 */
26
27 #include <stdio.h>
28 #include <stdlib.h>
29
35
36 #include <zlib.h>
37
38 /*
39 * Decoder context
40 */
43
48
49 static const int shift1[6] = { 0, 8, 8, 8, 4, 4 };
50 static const int shift2[6] = { 0, 0, 8, 4, 0, 4 };
51
54 {
56 int i, j, k;
57 int type, x,
y, d, d2;
59
60 code = src + 12;
61 data = code + ((avctx->
width * avctx->
height) >> 4);
64
65 for(j = 0; j < avctx->
height; j += 4){
66 for(i = 0; i < avctx->
width; i += 4){
67 tmp = dst + i;
68 tmp2 = ref + i;
69 type = *code++;
70 switch(type){
71 case 4: // motion compensation
72 x = (*mv) >> 4; if(x & 8) x = 8 - x;
73 y = (*mv++) & 0xF;
if(y & 8) y = 8 -
y;
74 if (i < -x || avctx->
width - i - 4 < x ||
75 j < -y || avctx->
height - j - 4 < y) {
78 }
80 case 0: // skip
81 case 5: // skip in method 12
82 for(y = 0; y < 4; y++){
83 memcpy(tmp, tmp2, 4);
86 }
87 break;
88 case 1: // masked change
89 case 10: // masked change with only half of pixels changed
90 case 11: // cases 10-15 are for method 12 only
91 case 12:
92 case 13:
93 case 14:
94 case 15:
95 if(type == 1){
97 msk += 2;
98 }else{
99 type -= 10;
100 mask = ((msk[0] & 0xF0) <<
shift1[type]) | ((msk[0] & 0xF) <<
shift2[type]);
101 msk++;
102 }
103 for(y = 0; y < 4; y++){
104 for(x = 0; x < 4; x++){
105 tmp[x] = (mask & 0x8000) ? *data++ : tmp2[x];
106 mask <<= 1;
107 }
110 }
111 break;
112 case 2: // fill block
113 for(y = 0; y < 4; y++){
114 memset(tmp, data[0], 4);
116 }
117 data++;
118 break;
119 case 3: // raw block
120 for(y = 0; y < 4; y++){
121 memcpy(tmp, data, 4);
122 data += 4;
124 }
125 break;
126 case 8: // subblocks - method 13 only
127 mask = *msk++;
128 for(k = 0; k < 4; k++){
129 d = ((k & 1) << 1) + ((k & 2) * stride);
130 d2 = ((k & 1) << 1) + ((k & 2) * stride);
131 tmp2 = ref + i + d2;
132 switch(mask & 0xC0){
133 case 0x80: // motion compensation
134 x = (*mv) >> 4; if(x & 8) x = 8 - x;
135 y = (*mv++) & 0xF;
if(y & 8) y = 8 -
y;
136 if (i + 2*(k & 1) < -x || avctx->
width - i - 2*(k & 1) - 2 < x ||
137 j + (k & 2) < -y || avctx->
height - j - (k & 2) - 2 < y) {
140 }
142 case 0x00: // skip
143 tmp[d + 0 ] = tmp2[0];
144 tmp[d + 1 ] = tmp2[1];
147 break;
148 case 0x40: // fill
149 tmp[d + 0 ] = data[0];
150 tmp[d + 1 ] = data[0];
151 tmp[d + 0 +
stride] = data[0];
152 tmp[d + 1 +
stride] = data[0];
153 data++;
154 break;
155 case 0xC0: // raw
156 tmp[d + 0 ] = *data++;
157 tmp[d + 1 ] = *data++;
158 tmp[d + 0 +
stride] = *data++;
159 tmp[d + 1 +
stride] = *data++;
160 break;
161 }
162 mask <<= 2;
163 }
164 break;
165 case 32: // vector quantization - 2 colors
167 msk += 2;
168 for(y = 0; y < 4; y++){
169 for(x = 0; x < 4; x++){
170 tmp[x] = data[mask & 1];
171 mask >>= 1;
172 }
175 }
176 data += 2;
177 break;
178 case 33: // vector quantization - 3 or 4 colors
179 case 34:
181 msk += 4;
182 for(y = 0; y < 4; y++){
183 for(x = 0; x < 4; x++){
184 tmp[x] = data[mask & 3];
185 mask >>= 2;
186 }
189 }
190 data += type - 30;
191 break;
192 default:
195 }
196 }
197 dst += stride * 4;
198 ref += stride * 4;
199 }
200 return 0;
201 }
202
204 {
207 uint8_t *outptr, *srcptr, *tmpptr;
208 unsigned long dsize;
209 int i, j, compr,
ret;
211 int pc = 0;
213
215
216 /* make the palette available on the way out */
217 if (bytestream2_peek_le32(&gb) ==
MKTAG(
'C',
'M',
'A',
'P')) {
219 for(i = 0; i < 256; i++){
220 c->
pal[i] = 0xFF
U << 24 | bytestream2_get_be24(&gb);
221 }
222 pc = 1;
223 }
224
229
230 outptr = frame->
data[0];
234
235 if (bytestream2_get_le32(&gb) ==
MKTAG(
'N',
'U',
'L',
'L'))
236 compr = -1;
237 else
238 compr = bytestream2_get_byte(&gb);
239
241 if (compr != 4 && compr != -1) {
247 }
248 }
249 switch(compr){
250 case -1:
255 else{ // Should happen only when first frame is 'NULL'
259 }
260 break;
261 case 2:
262 case 3:
263 case 4:
264 case 5:
267 for(j = 0; j < avctx->
height; j++){
268 if((compr & 1) && tmpptr){
269 for(i = 0; i < avctx->
width; i++)
270 outptr[i] = srcptr[i] ^ tmpptr[i];
272 }else
273 memcpy(outptr, srcptr, avctx->
width);
275 srcptr += avctx->
width;
276 }
277 break;
278 case 12: // ScummVM coding
279 case 13:
285 }
287 break;
288 default:
291 }
292
296
297 *got_frame = 1;
298
299 /* always report that the buffer was completely consumed */
301 }
302
304 {
306
308
312
319 }
320
321 return 0;
322 }
323
325 {
327
330
331 return 0;
332 }
333
344 };