1 /*
2 * Electronic Arts Madcow Video Decoder
3 * Copyright (c) 2007-2009 Peter Ross
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * Electronic Arts Madcow Video Decoder
25 * @author Peter Ross <pross@xvid.org>
26 *
27 * @see technical details at
28 * http://wiki.multimedia.cx/index.php?title=Electronic_Arts_MAD
29 */
30
39
40 #define EA_PREAMBLE_SIZE 8
41 #define MADk_TAG MKTAG('M', 'A', 'D', 'k') /* MAD i-frame */
42 #define MADm_TAG MKTAG('M', 'A', 'D', 'm') /* MAD p-frame */
43 #define MADe_TAG MKTAG('M', 'A', 'D', 'e') /* MAD lqp-frame */
44
58
60 {
68 return 0;
69 }
70
71 static inline void comp(
unsigned char *dst,
int dst_stride,
72 unsigned char *
src,
int src_stride,
int add)
73 {
74 int j, i;
75 for (j=0; j<8; j++)
76 for (i=0; i<8; i++)
77 dst[j*dst_stride + i] = av_clip_uint8(src[j*src_stride + i] + add);
78 }
79
81 int mb_x, int mb_y,
82 int j, int mv_x, int mv_y, int add)
83 {
84 if (j < 4) {
87 return;
88 comp(frame->
data[0] + (mb_y*16 + ((j&2)<<2))*frame->
linesize[0] + mb_x*16 + ((j&1)<<3),
96 return;
101 }
102 }
103
105 int mb_x, int mb_y, int j)
106 {
107 if (j < 4) {
109 frame->
data[0] + (mb_y*16 + ((j&2)<<2))*frame->
linesize[0] + mb_x*16 + ((j&1)<<3),
114 frame->
data[index] + (mb_y*8)*frame->
linesize[index] + mb_x*8,
116 }
117 }
118
120 {
125
126 block[0] = (128 +
get_sbits(&s->
gb, 8)) * quant_matrix[0];
127
128 /* The RL decoder is derived from mpeg1_decode_block_intra;
129 Escaped level and run values a decoded differently */
130 i = 0;
131 {
133 /* now quantify & encode AC coefficients */
134 for (;;) {
137
138 if (level == 127) {
139 break;
140 } else if (level != 0) {
142 j = scantable[i];
143 level = (level*quant_matrix[j]) >> 4;
144 level = (level-1)|1;
147 } else {
148 /* escape */
151
154
156 j = scantable[i];
157 if (level < 0) {
159 level = (level*quant_matrix[j]) >> 4;
160 level = (level-1)|1;
162 } else {
163 level = (level*quant_matrix[j]) >> 4;
164 level = (level-1)|1;
165 }
166 }
167 if (i > 63) {
169 return -1;
170 }
171
173 }
175 }
176 return 0;
177 }
178
180 {
184 value = -17;
186 }
188 }
189
191 {
192 int mv_map = 0;
193 int mv_x, mv_y;
194 int j;
195
196 if (inter) {
198 if (v < 2) {
202 }
203 }
204
205 for (j=0; j<6; j++) {
206 if (mv_map & (1<<j)) { // mv_x and mv_y are guarded by mv_map
210 } else {
213 return -1;
215 }
216 }
217 return 0;
218 }
219
221 {
222 int i;
223
225 for (i=1; i<64; i++)
227 }
228
230 void *
data,
int *got_frame,
232 {
234 int buf_size = avpkt->
size;
235 const uint8_t *buf_end = buf+buf_size;
239 int chunk_type;
241
242 if (buf_size < 26) {
244 *got_frame = 0;
246 }
247
250 buf += 8;
251
253 AV_RL16(&buf[6]), 1000, 1<<30);
254
258 buf += 16;
259
260 if (width < 16 || height < 16) {
263 }
264
265 if (avctx->
width != width || avctx->
height != height) {
266 if((width * height)/2048*7 > buf_end-buf)
272 }
273
276
280 if (ret < 0)
288 }
289
291 buf_end - buf);
297
302
303 *got_frame = 1;
304
309 }
310
311 return buf_size;
312 }
313
315 {
319 return 0;
320 }
321
332 };