1 /*
2 * Electronic Arts CMV Video Decoder
3 * Copyright (c) 2007-2008 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 CMV Video Decoder
25 * by Peter Ross (pross@xvid.org)
26 *
27 * Technical details here:
28 * http://wiki.multimedia.cx/index.php?title=Electronic_Arts_CMV
29 */
30
36
44
47
50
57 }
58
59 return 0;
60 }
61
64 {
65 unsigned char *dst = frame->
data[0];
66 int i;
67
72 }
73 }
74
76 const unsigned char *
src,
int src_stride,
78 int xoffset, int yoffset,
80 int i,j;
81
82 for(j=y;j<y+4;j++)
83 for(i=x;i<x+4;i++)
84 {
85 if (i+xoffset>=0 && i+xoffset<width &&
86 j+yoffset>=0 && j+yoffset<height) {
87 dst[j*dst_stride + i] = src[(j+yoffset)*src_stride + i+xoffset];
88 }else{
89 dst[j*dst_stride + i] = 0;
90 }
91 }
92 }
93
96 {
99
100 i = 0;
102 for(x=0; x<s->
avctx->
width/4 && buf_end - buf > i; x++) {
103 if (buf[i]==0xFF) {
104 unsigned char *dst = frame->
data[0] + (y*4)*frame->
linesize[0] + x*4;
105 if (raw+16<buf_end && *raw==0xFF) {
/* intra */
106 raw++;
107 memcpy(dst, raw, 4);
108 memcpy(dst + frame->
linesize[0], raw+4, 4);
109 memcpy(dst + 2 * frame->
linesize[0], raw+8, 4);
110 memcpy(dst + 3 * frame->
linesize[0], raw+12, 4);
111 raw+=16;
112 }else if(raw<buf_end) { /* inter using second-last frame as reference */
113 int xoffset = (*raw & 0xF) - 7;
114 int yoffset = ((*raw >> 4)) - 7;
119 raw++;
120 }
121 }else{ /* inter using last frame as reference */
122 int xoffset = (buf[i] & 0xF) - 7;
123 int yoffset = ((buf[i] >> 4)) - 7;
128 }
129 i++;
130 }
131 }
132
134 {
135 int pal_start, pal_count, i,
ret, fps;
136
137 if(buf_end - buf < 16) {
140 }
141
144
149 }
150
152 if (ret < 0)
154
156 if (fps > 0)
158
161
162 buf += 16;
163 for (i=pal_start; i<pal_start+pal_count && i<
AVPALETTE_COUNT && buf_end - buf >= 3; i++) {
165 buf += 3;
166 }
167
168 return 0;
169 }
170
171 #define EA_PREAMBLE_SIZE 8
172 #define MVIh_TAG MKTAG('M', 'V', 'I', 'h')
173
175 void *
data,
int *got_frame,
177 {
179 int buf_size = avpkt->
size;
181 const uint8_t *buf_end = buf + buf_size;
184
187
191 if (ret < 0)
194 return -1;
196 }
197
199 return -1;
200
203
205
207 if ((buf[0]&1)) { // subtype
211 }else{
215 }
216
221
222 *got_frame = 1;
223
224 return buf_size;
225 }
226
229
232
233 return 0;
234 }
235
246 };