annotate dxa.c @ 7468:38e9f32f8d43 libavcodec

mb_field_decoding_flag was not initialized Fixes at least: MR7_BT_B.h264 Sharp_MP_PAFF_1r2.jvt Sharp_MP_PAFF_2.jvt
author michael
date Sun, 03 Aug 2008 13:00:39 +0000
parents e943e1409077
children 2acf0ae7b041
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4671
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
1 /*
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
2 * Feeble Files/ScummVM DXA decoder
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
3 * Copyright (c) 2007 Konstantin Shishkov
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
4 *
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
5 * This file is part of FFmpeg.
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
6 *
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
11 *
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
15 * Lesser General Public License for more details.
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
16 *
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
20 */
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
21
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
22 /**
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
23 * @file dxa.c
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
24 * DXA Video decoder
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
25 */
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
26
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
27 #include <stdio.h>
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
28 #include <stdlib.h>
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
29
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
30 #include "avcodec.h"
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
31
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
32 #include <zlib.h>
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
33
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
34 /*
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
35 * Decoder context
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
36 */
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
37 typedef struct DxaDecContext {
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
38 AVCodecContext *avctx;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
39 AVFrame pic, prev;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
40
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
41 int dsize;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
42 uint8_t *decomp_buf;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
43 uint32_t pal[256];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
44 } DxaDecContext;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
45
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
46 static const int shift1[6] = { 0, 8, 8, 8, 4, 4 };
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
47 static const int shift2[6] = { 0, 0, 8, 4, 0, 4 };
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
48
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
49 static int decode_13(AVCodecContext *avctx, DxaDecContext *c, uint8_t* dst, uint8_t *src, uint8_t *ref)
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
50 {
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
51 uint8_t *code, *data, *mv, *msk, *tmp, *tmp2;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
52 int i, j, k;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
53 int type, x, y, d, d2;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
54 int stride = c->pic.linesize[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
55 uint32_t mask;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
56
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
57 code = src + 12;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
58 data = code + ((avctx->width * avctx->height) >> 4);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
59 mv = data + AV_RB32(src + 0);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
60 msk = mv + AV_RB32(src + 4);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
61
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
62 for(j = 0; j < avctx->height; j += 4){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
63 for(i = 0; i < avctx->width; i += 4){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
64 tmp = dst + i;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
65 tmp2 = ref + i;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
66 type = *code++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
67 switch(type){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
68 case 4: // motion compensation
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
69 x = (*mv) >> 4; if(x & 8) x = 8 - x;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
70 y = (*mv++) & 0xF; if(y & 8) y = 8 - y;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
71 tmp2 += x + y*stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
72 case 0: // skip
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
73 case 5: // skip in method 12
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
74 for(y = 0; y < 4; y++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
75 memcpy(tmp, tmp2, 4);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
76 tmp += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
77 tmp2 += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
78 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
79 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
80 case 1: // masked change
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
81 case 10: // masked change with only half of pixels changed
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
82 case 11: // cases 10-15 are for method 12 only
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
83 case 12:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
84 case 13:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
85 case 14:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
86 case 15:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
87 if(type == 1){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
88 mask = AV_RB16(msk);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
89 msk += 2;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
90 }else{
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
91 type -= 10;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
92 mask = ((msk[0] & 0xF0) << shift1[type]) | ((msk[0] & 0xF) << shift2[type]);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
93 msk++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
94 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
95 for(y = 0; y < 4; y++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
96 for(x = 0; x < 4; x++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
97 tmp[x] = (mask & 0x8000) ? *data++ : tmp2[x];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
98 mask <<= 1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
99 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
100 tmp += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
101 tmp2 += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
102 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
103 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
104 case 2: // fill block
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
105 for(y = 0; y < 4; y++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
106 memset(tmp, data[0], 4);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
107 tmp += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
108 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
109 data++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
110 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
111 case 3: // raw block
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
112 for(y = 0; y < 4; y++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
113 memcpy(tmp, data, 4);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
114 data += 4;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
115 tmp += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
116 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
117 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
118 case 8: // subblocks - method 13 only
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
119 mask = *msk++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
120 for(k = 0; k < 4; k++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
121 d = ((k & 1) << 1) + ((k & 2) * stride);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
122 d2 = ((k & 1) << 1) + ((k & 2) * stride);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
123 tmp2 = ref + i + d2;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
124 switch(mask & 0xC0){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
125 case 0x80: // motion compensation
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
126 x = (*mv) >> 4; if(x & 8) x = 8 - x;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
127 y = (*mv++) & 0xF; if(y & 8) y = 8 - y;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
128 tmp2 += x + y*stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
129 case 0x00: // skip
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
130 tmp[d + 0 ] = tmp2[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
131 tmp[d + 1 ] = tmp2[1];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
132 tmp[d + 0 + stride] = tmp2[0 + stride];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
133 tmp[d + 1 + stride] = tmp2[1 + stride];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
134 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
135 case 0x40: // fill
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
136 tmp[d + 0 ] = data[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
137 tmp[d + 1 ] = data[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
138 tmp[d + 0 + stride] = data[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
139 tmp[d + 1 + stride] = data[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
140 data++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
141 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
142 case 0xC0: // raw
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
143 tmp[d + 0 ] = *data++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
144 tmp[d + 1 ] = *data++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
145 tmp[d + 0 + stride] = *data++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
146 tmp[d + 1 + stride] = *data++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
147 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
148 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
149 mask <<= 2;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
150 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
151 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
152 case 32: // vector quantization - 2 colors
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
153 mask = AV_RB16(msk);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
154 msk += 2;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
155 for(y = 0; y < 4; y++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
156 for(x = 0; x < 4; x++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
157 tmp[x] = data[mask & 1];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
158 mask >>= 1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
159 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
160 tmp += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
161 tmp2 += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
162 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
163 data += 2;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
164 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
165 case 33: // vector quantization - 3 or 4 colors
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
166 case 34:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
167 mask = AV_RB32(msk);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
168 msk += 4;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
169 for(y = 0; y < 4; y++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
170 for(x = 0; x < 4; x++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
171 tmp[x] = data[mask & 3];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
172 mask >>= 2;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
173 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
174 tmp += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
175 tmp2 += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
176 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
177 data += type - 30;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
178 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
179 default:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
180 av_log(avctx, AV_LOG_ERROR, "Unknown opcode %d\n", type);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
181 return -1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
182 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
183 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
184 dst += stride * 4;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
185 ref += stride * 4;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
186 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
187 return 0;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
188 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
189
6267
michael
parents: 5215
diff changeset
190 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size)
4671
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
191 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4671
diff changeset
192 DxaDecContext * const c = avctx->priv_data;
4671
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
193 uint8_t *outptr, *srcptr, *tmpptr;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
194 unsigned long dsize;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
195 int i, j, compr;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
196 int stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
197 int orig_buf_size = buf_size;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
198 int pc = 0;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
199
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
200 /* make the palette available on the way out */
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
201 if(buf[0]=='C' && buf[1]=='M' && buf[2]=='A' && buf[3]=='P'){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
202 int r, g, b;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
203
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
204 buf += 4;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
205 for(i = 0; i < 256; i++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
206 r = *buf++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
207 g = *buf++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
208 b = *buf++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
209 c->pal[i] = (r << 16) | (g << 8) | b;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
210 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
211 pc = 1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
212 buf_size -= 768+4;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
213 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
214
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
215 if(avctx->get_buffer(avctx, &c->pic) < 0){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
216 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
217 return -1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
218 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
219 memcpy(c->pic.data[1], c->pal, AVPALETTE_SIZE);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
220 c->pic.palette_has_changed = pc;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
221
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
222 outptr = c->pic.data[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
223 srcptr = c->decomp_buf;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
224 tmpptr = c->prev.data[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
225 stride = c->pic.linesize[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
226
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
227 if(buf[0]=='N' && buf[1]=='U' && buf[2]=='L' && buf[3]=='L')
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
228 compr = -1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
229 else
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
230 compr = buf[4];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
231
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
232 dsize = c->dsize;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
233 if((compr != 4 && compr != -1) && uncompress(c->decomp_buf, &dsize, buf + 9, buf_size - 9) != Z_OK){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
234 av_log(avctx, AV_LOG_ERROR, "Uncompress failed!\n");
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
235 return -1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
236 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
237 switch(compr){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
238 case -1:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
239 c->pic.key_frame = 0;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
240 c->pic.pict_type = FF_P_TYPE;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
241 if(c->prev.data[0])
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
242 memcpy(c->pic.data[0], c->prev.data[0], c->pic.linesize[0] * avctx->height);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
243 else{ // Should happen only when first frame is 'NULL'
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
244 memset(c->pic.data[0], 0, c->pic.linesize[0] * avctx->height);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
245 c->pic.key_frame = 1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
246 c->pic.pict_type = FF_I_TYPE;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
247 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
248 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
249 case 2:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
250 case 3:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
251 case 4:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
252 case 5:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
253 c->pic.key_frame = !(compr & 1);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
254 c->pic.pict_type = (compr & 1) ? FF_P_TYPE : FF_I_TYPE;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
255 for(j = 0; j < avctx->height; j++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
256 if(compr & 1){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
257 for(i = 0; i < avctx->width; i++)
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
258 outptr[i] = srcptr[i] ^ tmpptr[i];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
259 tmpptr += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
260 }else
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
261 memcpy(outptr, srcptr, avctx->width);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
262 outptr += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
263 srcptr += avctx->width;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
264 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
265 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
266 case 12: // ScummVM coding
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
267 case 13:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
268 c->pic.key_frame = 0;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
269 c->pic.pict_type = FF_P_TYPE;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
270 decode_13(avctx, c, c->pic.data[0], srcptr, c->prev.data[0]);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
271 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
272 default:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
273 av_log(avctx, AV_LOG_ERROR, "Unknown/unsupported compression type %d\n", buf[4]);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
274 return -1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
275 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
276
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
277 FFSWAP(AVFrame, c->pic, c->prev);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
278 if(c->pic.data[0])
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
279 avctx->release_buffer(avctx, &c->pic);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
280
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
281 *data_size = sizeof(AVFrame);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
282 *(AVFrame*)data = c->prev;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
283
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
284 /* always report that the buffer was completely consumed */
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
285 return orig_buf_size;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
286 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
287
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6267
diff changeset
288 static av_cold int decode_init(AVCodecContext *avctx)
4671
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
289 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4671
diff changeset
290 DxaDecContext * const c = avctx->priv_data;
4671
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
291
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
292 c->avctx = avctx;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
293 avctx->pix_fmt = PIX_FMT_PAL8;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
294
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
295 if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) {
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
296 return -1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
297 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
298
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
299 c->dsize = avctx->width * avctx->height * 2;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
300 if((c->decomp_buf = av_malloc(c->dsize)) == NULL) {
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
301 av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
302 return -1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
303 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
304
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
305 return 0;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
306 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
307
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6267
diff changeset
308 static av_cold int decode_end(AVCodecContext *avctx)
4671
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
309 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4671
diff changeset
310 DxaDecContext * const c = avctx->priv_data;
4671
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
311
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
312 av_freep(&c->decomp_buf);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
313 if(c->prev.data[0])
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
314 avctx->release_buffer(avctx, &c->prev);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
315 if(c->pic.data[0])
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
316 avctx->release_buffer(avctx, &c->pic);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
317
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
318 return 0;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
319 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
320
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
321 AVCodec dxa_decoder = {
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
322 "dxa",
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
323 CODEC_TYPE_VIDEO,
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
324 CODEC_ID_DXA,
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
325 sizeof(DxaDecContext),
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
326 decode_init,
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
327 NULL,
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
328 decode_end,
6712
5b3acf9fd50a Add long names to AVCodec declarations.
diego
parents: 6517
diff changeset
329 decode_frame,
7040
e943e1409077 Make AVCodec long_names definition conditional depending on CONFIG_SMALL.
stefano
parents: 6712
diff changeset
330 .long_name = NULL_IF_CONFIG_SMALL("Feeble Files/ScummVM DXA"),
4671
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
331 };
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
332