1 /*
2 * MSMPEG4 backend for encoder and decoder
3 * Copyright (c) 2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * msmpeg4v1 & v2 stuff by Michael Niedermayer <michaelni@gmx.at>
7 *
8 * This file is part of FFmpeg.
9 *
10 * FFmpeg is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * FFmpeg is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with FFmpeg; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 /**
26 * @file
27 * MSMPEG4 backend for encoder and decoder
28 */
29
40
41 /*
42 * You can also call this codec : MPEG4 with a twist !
43 *
44 * TODO:
45 * - (encoding) select best mv table (two choices)
46 * - (encoding) select best vlc/dc table
47 */
48
49 /* This table is practically identical to the one from h263
50 * except that it is inverted. */
52 {
53 int level, uni_code, uni_len;
54
56 return;
57
58 for(level=-256; level<256; level++){
60 /* find number of bits */
61 size = 0;
62 v = abs(level);
63 while (v) {
64 v >>= 1;
65 size++;
66 }
67
68 if (level < 0)
69 l= (-
level) ^ ((1 << size) - 1);
70 else
72
73 /* luminance h263 */
76 uni_code ^= (1<<uni_len)-1; //M$ does not like compatibility
77
78 if (size > 0) {
79 uni_code<<=
size; uni_code|=l;
81 if (size > 8){
82 uni_code<<=1; uni_code|=1;
83 uni_len++;
84 }
85 }
88
89 /* chrominance h263 */
92 uni_code ^= (1<<uni_len)-1; //M$ does not like compatibility
93
94 if (size > 0) {
95 uni_code<<=
size; uni_code|=l;
97 if (size > 8){
98 uni_code<<=1; uni_code|=1;
99 uni_len++;
100 }
101 }
104
105 }
106 }
107
109 {
111 case 1:
112 case 2:
115 break;
116 case 3:
120 } else{
123 }
124 break;
125 case 4:
126 case 5:
129 break;
130 #if CONFIG_VC1_DECODER
131 case 6:
134 break;
135 #endif
136
137 }
138
139
145 }
146 //Note the default tables are set in common_init in mpegvideo.c
147
149 }
150
151 /* predict coded block */
153 {
155
158
159 /* B C
160 * A X
161 */
165
166 if (b == c) {
168 } else {
170 }
171
172 /* store value */
174
176 }
177
179 {
181 int sum=0;
182 for(y=0; y<block_size; y++){
183 int x;
184 for(x=0; x<block_size; x++){
186 }
187 }
188 return FASTDIV((sum + (scale>>1)), scale);
189 }
190
191 /* dir = 0: left, dir = 1: top prediction */
193 int16_t **dc_val_ptr, int *dir_ptr)
194 {
196 int16_t *dc_val;
197
198 /* find prediction */
199 if (n < 4) {
201 } else {
203 }
204
207
208 /* B C
209 * A X
210 */
211 a = dc_val[ - 1];
212 b = dc_val[ - 1 -
wrap];
214
216 b=c=1024;
217 }
218
219 /* XXX: the following solution consumes divisions, but it does not
220 necessitate to modify mpegvideo.c. The problem comes from the
221 fact they decided to store the quantized DC (which would lead
222 to problems if Q could vary !) */
223 #if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE
224 __asm__ volatile(
225 "movl %3, %%eax \n\t"
226 "shrl 1,ドル %%eax \n\t"
227 "addl %%eax, %2 \n\t"
228 "addl %%eax, %1 \n\t"
229 "addl %0, %%eax \n\t"
230 "imull %4 \n\t"
231 "movl %%edx, %0 \n\t"
232 "movl %1, %%eax \n\t"
233 "imull %4 \n\t"
234 "movl %%edx, %1 \n\t"
235 "movl %2, %%eax \n\t"
236 "imull %4 \n\t"
237 "movl %%edx, %2 \n\t"
238 :
"+b" (
a),
"+c" (b),
"+D" (
c)
240 : "%eax", "%edx"
241 );
242 #else
243 /* #elif ARCH_ALPHA */
244 /* Divisions are extremely costly on Alpha; optimize the most
245 common case. But they are costly everywhere...
246 */
247 if (scale == 8) {
248 a = (a + (8 >> 1)) / 8;
249 b = (b + (8 >> 1)) / 8;
250 c = (c + (8 >> 1)) / 8;
251 } else {
252 a =
FASTDIV((a + (scale >> 1)), scale);
253 b =
FASTDIV((b + (scale >> 1)), scale);
254 c =
FASTDIV((c + (scale >> 1)), scale);
255 }
256 #endif
257 /* XXX: WARNING: they did not choose the same test as MPEG4. This
258 is very important ! */
263
264 if(n==1){
266 *dir_ptr = 0;
267 }else if(n==2){
269 *dir_ptr = 1;
270 }else if(n==3){
271 if (abs(a - b) < abs(b - c)) {
273 *dir_ptr = 1;
274 } else {
276 *dir_ptr = 0;
277 }
278 }else{
280 if(n<4){
283 }else{
286 }
287 if(s->
mb_x==0) a= (1024 + (scale>>1))/
scale;
289 if(s->
mb_y==0) c= (1024 + (scale>>1))/
scale;
291
294 *dir_ptr = 0;
296 if(n==0){
298 *dir_ptr = 1;
299 }else{
301 *dir_ptr = 0;
302 }
304 if(n==0){
306 *dir_ptr = 0;
307 }else{
309 *dir_ptr = 1;
310 }
311 } else {
313 *dir_ptr = 1;
314 }
315 }
316 }else{
317 if (abs(a - b) < abs(b - c)) {
319 *dir_ptr = 1;
320 } else {
322 *dir_ptr = 0;
323 }
324 }
325 }else{
326 if (abs(a - b) <= abs(b - c)) {
328 *dir_ptr = 1;
329 } else {
331 *dir_ptr = 0;
332 }
333 }
334
335 /* update predictor */
336 *dc_val_ptr = &dc_val[0];
338 }
339