annotate dxa.c @ 4970:28b67304e5d0 libavcodec

Fix r8963
author ramiro
date Thu, 10 May 2007 15:00:09 +0000
parents f99e40a7155b
children 2b72f9bc4f06
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 /**
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
24 * @file dxa.c
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
25 * DXA Video decoder
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
26 */
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
27
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
28 #include <stdio.h>
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
29 #include <stdlib.h>
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
30
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
31 #include "avcodec.h"
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
32
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
33 #include <zlib.h>
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
34
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
35 /*
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
36 * Decoder context
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
37 */
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
38 typedef struct DxaDecContext {
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
39 AVCodecContext *avctx;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
40 AVFrame pic, prev;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
41
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
42 int dsize;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
43 uint8_t *decomp_buf;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
44 uint32_t pal[256];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
45 } DxaDecContext;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
46
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
47 static const int shift1[6] = { 0, 8, 8, 8, 4, 4 };
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
48 static const int shift2[6] = { 0, 0, 8, 4, 0, 4 };
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
49
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
50 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
51 {
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
52 uint8_t *code, *data, *mv, *msk, *tmp, *tmp2;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
53 int i, j, k;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
54 int type, x, y, d, d2;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
55 int stride = c->pic.linesize[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
56 uint32_t mask;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
57
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
58 code = src + 12;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
59 data = code + ((avctx->width * avctx->height) >> 4);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
60 mv = data + AV_RB32(src + 0);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
61 msk = mv + AV_RB32(src + 4);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
62
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
63 for(j = 0; j < avctx->height; j += 4){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
64 for(i = 0; i < avctx->width; i += 4){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
65 tmp = dst + i;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
66 tmp2 = ref + i;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
67 type = *code++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
68 switch(type){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
69 case 4: // motion compensation
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
70 x = (*mv) >> 4; if(x & 8) x = 8 - x;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
71 y = (*mv++) & 0xF; if(y & 8) y = 8 - y;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
72 tmp2 += x + y*stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
73 case 0: // skip
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
74 case 5: // skip in method 12
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
75 for(y = 0; y < 4; y++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
76 memcpy(tmp, tmp2, 4);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
77 tmp += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
78 tmp2 += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
79 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
80 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
81 case 1: // masked change
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
82 case 10: // masked change with only half of pixels changed
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
83 case 11: // cases 10-15 are for method 12 only
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
84 case 12:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
85 case 13:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
86 case 14:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
87 case 15:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
88 if(type == 1){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
89 mask = AV_RB16(msk);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
90 msk += 2;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
91 }else{
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
92 type -= 10;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
93 mask = ((msk[0] & 0xF0) << shift1[type]) | ((msk[0] & 0xF) << shift2[type]);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
94 msk++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
95 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
96 for(y = 0; y < 4; y++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
97 for(x = 0; x < 4; x++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
98 tmp[x] = (mask & 0x8000) ? *data++ : tmp2[x];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
99 mask <<= 1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
100 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
101 tmp += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
102 tmp2 += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
103 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
104 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
105 case 2: // fill block
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
106 for(y = 0; y < 4; y++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
107 memset(tmp, data[0], 4);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
108 tmp += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
109 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
110 data++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
111 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
112 case 3: // raw block
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
113 for(y = 0; y < 4; y++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
114 memcpy(tmp, data, 4);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
115 data += 4;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
116 tmp += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
117 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
118 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
119 case 8: // subblocks - method 13 only
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
120 mask = *msk++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
121 for(k = 0; k < 4; k++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
122 d = ((k & 1) << 1) + ((k & 2) * stride);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
123 d2 = ((k & 1) << 1) + ((k & 2) * stride);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
124 tmp2 = ref + i + d2;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
125 switch(mask & 0xC0){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
126 case 0x80: // motion compensation
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
127 x = (*mv) >> 4; if(x & 8) x = 8 - x;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
128 y = (*mv++) & 0xF; if(y & 8) y = 8 - y;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
129 tmp2 += x + y*stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
130 case 0x00: // skip
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
131 tmp[d + 0 ] = tmp2[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
132 tmp[d + 1 ] = tmp2[1];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
133 tmp[d + 0 + stride] = tmp2[0 + stride];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
134 tmp[d + 1 + stride] = tmp2[1 + stride];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
135 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
136 case 0x40: // fill
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
137 tmp[d + 0 ] = data[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
138 tmp[d + 1 ] = data[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
139 tmp[d + 0 + stride] = data[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
140 tmp[d + 1 + stride] = data[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
141 data++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
142 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
143 case 0xC0: // raw
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
144 tmp[d + 0 ] = *data++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
145 tmp[d + 1 ] = *data++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
146 tmp[d + 0 + stride] = *data++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
147 tmp[d + 1 + stride] = *data++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
148 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
149 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
150 mask <<= 2;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
151 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
152 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
153 case 32: // vector quantization - 2 colors
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
154 mask = AV_RB16(msk);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
155 msk += 2;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
156 for(y = 0; y < 4; y++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
157 for(x = 0; x < 4; x++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
158 tmp[x] = data[mask & 1];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
159 mask >>= 1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
160 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
161 tmp += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
162 tmp2 += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
163 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
164 data += 2;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
165 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
166 case 33: // vector quantization - 3 or 4 colors
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
167 case 34:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
168 mask = AV_RB32(msk);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
169 msk += 4;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
170 for(y = 0; y < 4; y++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
171 for(x = 0; x < 4; x++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
172 tmp[x] = data[mask & 3];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
173 mask >>= 2;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
174 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
175 tmp += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
176 tmp2 += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
177 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
178 data += type - 30;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
179 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
180 default:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
181 av_log(avctx, AV_LOG_ERROR, "Unknown opcode %d\n", type);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
182 return -1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
183 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
184 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
185 dst += stride * 4;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
186 ref += stride * 4;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
187 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
188 return 0;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
189 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
190
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
191 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
192 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4671
diff changeset
193 DxaDecContext * const c = avctx->priv_data;
4671
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
194 uint8_t *outptr, *srcptr, *tmpptr;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
195 unsigned long dsize;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
196 int i, j, compr;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
197 int stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
198 int orig_buf_size = buf_size;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
199 int pc = 0;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
200
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
201 /* make the palette available on the way out */
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
202 if(buf[0]=='C' && buf[1]=='M' && buf[2]=='A' && buf[3]=='P'){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
203 int r, g, b;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
204
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
205 buf += 4;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
206 for(i = 0; i < 256; i++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
207 r = *buf++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
208 g = *buf++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
209 b = *buf++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
210 c->pal[i] = (r << 16) | (g << 8) | b;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
211 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
212 pc = 1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
213 buf_size -= 768+4;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
214 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
215
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
216 if(avctx->get_buffer(avctx, &c->pic) < 0){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
217 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
218 return -1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
219 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
220 memcpy(c->pic.data[1], c->pal, AVPALETTE_SIZE);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
221 c->pic.palette_has_changed = pc;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
222
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
223 outptr = c->pic.data[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
224 srcptr = c->decomp_buf;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
225 tmpptr = c->prev.data[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
226 stride = c->pic.linesize[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
227
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
228 if(buf[0]=='N' && buf[1]=='U' && buf[2]=='L' && buf[3]=='L')
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
229 compr = -1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
230 else
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
231 compr = buf[4];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
232
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
233 dsize = c->dsize;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
234 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
235 av_log(avctx, AV_LOG_ERROR, "Uncompress failed!\n");
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
236 return -1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
237 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
238 switch(compr){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
239 case -1:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
240 c->pic.key_frame = 0;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
241 c->pic.pict_type = FF_P_TYPE;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
242 if(c->prev.data[0])
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
243 memcpy(c->pic.data[0], c->prev.data[0], c->pic.linesize[0] * avctx->height);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
244 else{ // Should happen only when first frame is 'NULL'
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
245 memset(c->pic.data[0], 0, c->pic.linesize[0] * avctx->height);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
246 c->pic.key_frame = 1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
247 c->pic.pict_type = FF_I_TYPE;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
248 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
249 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
250 case 2:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
251 case 3:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
252 case 4:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
253 case 5:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
254 c->pic.key_frame = !(compr & 1);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
255 c->pic.pict_type = (compr & 1) ? FF_P_TYPE : FF_I_TYPE;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
256 for(j = 0; j < avctx->height; j++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
257 if(compr & 1){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
258 for(i = 0; i < avctx->width; i++)
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
259 outptr[i] = srcptr[i] ^ tmpptr[i];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
260 tmpptr += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
261 }else
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
262 memcpy(outptr, srcptr, avctx->width);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
263 outptr += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
264 srcptr += avctx->width;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
265 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
266 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
267 case 12: // ScummVM coding
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
268 case 13:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
269 c->pic.key_frame = 0;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
270 c->pic.pict_type = FF_P_TYPE;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
271 decode_13(avctx, c, c->pic.data[0], srcptr, c->prev.data[0]);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
272 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
273 default:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
274 av_log(avctx, AV_LOG_ERROR, "Unknown/unsupported compression type %d\n", buf[4]);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
275 return -1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
276 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
277
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
278 FFSWAP(AVFrame, c->pic, c->prev);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
279 if(c->pic.data[0])
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
280 avctx->release_buffer(avctx, &c->pic);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
281
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
282 *data_size = sizeof(AVFrame);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
283 *(AVFrame*)data = c->prev;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
284
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
285 /* always report that the buffer was completely consumed */
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
286 return orig_buf_size;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
287 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
288
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
289 static int decode_init(AVCodecContext *avctx)
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
290 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4671
diff changeset
291 DxaDecContext * const c = avctx->priv_data;
4671
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
292
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
293 c->avctx = avctx;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
294 avctx->pix_fmt = PIX_FMT_PAL8;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
295
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
296 if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) {
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
297 return -1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
298 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
299
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
300 c->dsize = avctx->width * avctx->height * 2;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
301 if((c->decomp_buf = av_malloc(c->dsize)) == NULL) {
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
302 av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
303 return -1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
304 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
305
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
306 return 0;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
307 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
308
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
309 static int decode_end(AVCodecContext *avctx)
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
310 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4671
diff changeset
311 DxaDecContext * const c = avctx->priv_data;
4671
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
312
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
313 av_freep(&c->decomp_buf);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
314 if(c->prev.data[0])
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
315 avctx->release_buffer(avctx, &c->prev);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
316 if(c->pic.data[0])
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
317 avctx->release_buffer(avctx, &c->pic);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
318
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
319 return 0;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
320 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
321
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
322 AVCodec dxa_decoder = {
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
323 "dxa",
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
324 CODEC_TYPE_VIDEO,
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
325 CODEC_ID_DXA,
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
326 sizeof(DxaDecContext),
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
327 decode_init,
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
328 NULL,
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
329 decode_end,
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
330 decode_frame
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
331 };
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
332