annotate dxa.c @ 10817:d1fe22d92a65 libavcodec

Rename mpeg4 intra vlc tables so they contain "mpeg4", this improves readability of msmpeg4 code (one now knows where that table comes from).
author michael
date Fri, 08 Jan 2010 17:41:14 +0000
parents d7ed9dcc78e3
children 8a4984c5cacc
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 /**
8718
e9d9d946f213 Use full internal pathname in doxygen @file directives.
diego
parents: 8573
diff changeset
23 * @file libavcodec/dxa.c
4671
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
8573
2acf0ae7b041 Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents: 7040
diff changeset
30 #include "libavutil/intreadwrite.h"
4671
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
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
191 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
4671
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
192 {
9355
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
193 const uint8_t *buf = avpkt->data;
54bc8a2727b0 Implement avcodec_decode_video2(), _audio3() and _subtitle2() which takes an
rbultje
parents: 8718
diff changeset
194 int buf_size = avpkt->size;
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4671
diff changeset
195 DxaDecContext * const c = avctx->priv_data;
4671
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
196 uint8_t *outptr, *srcptr, *tmpptr;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
197 unsigned long dsize;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
198 int i, j, compr;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
199 int stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
200 int orig_buf_size = buf_size;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
201 int pc = 0;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
202
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
203 /* make the palette available on the way out */
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
204 if(buf[0]=='C' && buf[1]=='M' && buf[2]=='A' && buf[3]=='P'){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
205 int r, g, b;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
206
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
207 buf += 4;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
208 for(i = 0; i < 256; i++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
209 r = *buf++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
210 g = *buf++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
211 b = *buf++;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
212 c->pal[i] = (r << 16) | (g << 8) | b;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
213 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
214 pc = 1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
215 buf_size -= 768+4;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
216 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
217
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
218 if(avctx->get_buffer(avctx, &c->pic) < 0){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
219 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
220 return -1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
221 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
222 memcpy(c->pic.data[1], c->pal, AVPALETTE_SIZE);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
223 c->pic.palette_has_changed = pc;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
224
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
225 outptr = c->pic.data[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
226 srcptr = c->decomp_buf;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
227 tmpptr = c->prev.data[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
228 stride = c->pic.linesize[0];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
229
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
230 if(buf[0]=='N' && buf[1]=='U' && buf[2]=='L' && buf[3]=='L')
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
231 compr = -1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
232 else
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
233 compr = buf[4];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
234
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
235 dsize = c->dsize;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
236 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
237 av_log(avctx, AV_LOG_ERROR, "Uncompress failed!\n");
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
238 return -1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
239 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
240 switch(compr){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
241 case -1:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
242 c->pic.key_frame = 0;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
243 c->pic.pict_type = FF_P_TYPE;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
244 if(c->prev.data[0])
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
245 memcpy(c->pic.data[0], c->prev.data[0], c->pic.linesize[0] * avctx->height);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
246 else{ // Should happen only when first frame is 'NULL'
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
247 memset(c->pic.data[0], 0, c->pic.linesize[0] * avctx->height);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
248 c->pic.key_frame = 1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
249 c->pic.pict_type = FF_I_TYPE;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
250 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
251 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
252 case 2:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
253 case 3:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
254 case 4:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
255 case 5:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
256 c->pic.key_frame = !(compr & 1);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
257 c->pic.pict_type = (compr & 1) ? FF_P_TYPE : FF_I_TYPE;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
258 for(j = 0; j < avctx->height; j++){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
259 if(compr & 1){
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
260 for(i = 0; i < avctx->width; i++)
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
261 outptr[i] = srcptr[i] ^ tmpptr[i];
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
262 tmpptr += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
263 }else
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
264 memcpy(outptr, srcptr, avctx->width);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
265 outptr += stride;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
266 srcptr += avctx->width;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
267 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
268 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
269 case 12: // ScummVM coding
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
270 case 13:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
271 c->pic.key_frame = 0;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
272 c->pic.pict_type = FF_P_TYPE;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
273 decode_13(avctx, c, c->pic.data[0], srcptr, c->prev.data[0]);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
274 break;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
275 default:
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
276 av_log(avctx, AV_LOG_ERROR, "Unknown/unsupported compression type %d\n", buf[4]);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
277 return -1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
278 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
279
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
280 FFSWAP(AVFrame, c->pic, c->prev);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
281 if(c->pic.data[0])
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
282 avctx->release_buffer(avctx, &c->pic);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
283
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
284 *data_size = sizeof(AVFrame);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
285 *(AVFrame*)data = c->prev;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
286
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
287 /* always report that the buffer was completely consumed */
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
288 return orig_buf_size;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
289 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
290
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6267
diff changeset
291 static av_cold int decode_init(AVCodecContext *avctx)
4671
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
292 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4671
diff changeset
293 DxaDecContext * const c = avctx->priv_data;
4671
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
294
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
295 c->avctx = avctx;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
296 avctx->pix_fmt = PIX_FMT_PAL8;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
297
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
298 c->dsize = avctx->width * avctx->height * 2;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
299 if((c->decomp_buf = av_malloc(c->dsize)) == NULL) {
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
300 av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n");
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
301 return -1;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
302 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
303
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
304 return 0;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
305 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
306
6517
48759bfbd073 Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents: 6267
diff changeset
307 static av_cold int decode_end(AVCodecContext *avctx)
4671
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
308 {
4827
b3ee9a1526b0 Get rid of unnecessary pointer casts.
diego
parents: 4671
diff changeset
309 DxaDecContext * const c = avctx->priv_data;
4671
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
310
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
311 av_freep(&c->decomp_buf);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
312 if(c->prev.data[0])
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
313 avctx->release_buffer(avctx, &c->prev);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
314 if(c->pic.data[0])
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
315 avctx->release_buffer(avctx, &c->pic);
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
316
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
317 return 0;
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
318 }
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
319
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
320 AVCodec dxa_decoder = {
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
321 "dxa",
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
322 CODEC_TYPE_VIDEO,
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
323 CODEC_ID_DXA,
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
324 sizeof(DxaDecContext),
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
325 decode_init,
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
326 NULL,
97e3364d267a DXA demuxer and decoder
kostya
parents:
diff changeset
327 decode_end,
6712
5b3acf9fd50a Add long names to AVCodec declarations.
diego
parents: 6517
diff changeset
328 decode_frame,
9800
a9011e7defee dxa decoder uses get_buffer, set CODEC_CAP_DR1
bcoudurier
parents: 9355
diff changeset
329 CODEC_CAP_DR1,
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