Originally committed as revision 381 to svn://svn.ffmpeg.org/ffmpeg/trunk
Michael Niedermayer authored on 2002/04/07 11:03:32... | ... |
@@ -47,6 +47,8 @@ UINT32 squareTbl[512]; |
47 | 47 |
|
48 | 48 |
extern UINT16 default_intra_matrix[64]; |
49 | 49 |
extern UINT16 default_non_intra_matrix[64]; |
50 |
+extern UINT16 ff_mpeg4_default_intra_matrix[64]; |
|
51 |
+extern UINT16 ff_mpeg4_default_non_intra_matrix[64]; |
|
50 | 52 |
|
51 | 53 |
UINT8 zigzag_direct[64] = { |
52 | 54 |
0, 1, 8, 16, 9, 2, 3, 10, |
... | ... |
@@ -953,6 +955,8 @@ void dsputil_init(void) |
953 | 953 |
} |
954 | 954 |
block_permute(default_intra_matrix); |
955 | 955 |
block_permute(default_non_intra_matrix); |
956 |
+ block_permute(ff_mpeg4_default_intra_matrix); |
|
957 |
+ block_permute(ff_mpeg4_default_non_intra_matrix); |
|
956 | 958 |
} |
957 | 959 |
|
958 | 960 |
build_zigzag_end(); |
... | ... |
@@ -624,17 +624,14 @@ static void h263_encode_motion(MpegEncContext * s, int val) |
624 | 624 |
} |
625 | 625 |
|
626 | 626 |
if (val >= 0) { |
627 |
- val--; |
|
628 |
- code = (val >> bit_size) + 1; |
|
629 |
- bits = val & (range - 1); |
|
630 | 627 |
sign = 0; |
631 | 628 |
} else { |
632 | 629 |
val = -val; |
633 |
- val--; |
|
634 |
- code = (val >> bit_size) + 1; |
|
635 |
- bits = val & (range - 1); |
|
636 | 630 |
sign = 1; |
637 | 631 |
} |
632 |
+ val--; |
|
633 |
+ code = (val >> bit_size) + 1; |
|
634 |
+ bits = val & (range - 1); |
|
638 | 635 |
|
639 | 636 |
put_bits(&s->pb, mvtab[code][1] + 1, (mvtab[code][0] << 1) | sign); |
640 | 637 |
if (bit_size > 0) { |
... | ... |
@@ -728,7 +725,7 @@ static void init_uni_dc_tab() |
728 | 728 |
{ |
729 | 729 |
int level, uni_code, uni_len; |
730 | 730 |
|
731 |
- for(level=-255; level<256; level++){ |
|
731 |
+ for(level=-256; level<256; level++){ |
|
732 | 732 |
int size, v, l; |
733 | 733 |
/* find number of bits */ |
734 | 734 |
size = 0; |
... | ... |
@@ -2509,7 +2506,57 @@ int mpeg4_decode_picture_header(MpegEncContext * s) |
2509 | 2509 |
} |
2510 | 2510 |
|
2511 | 2511 |
// FIXME a bunch of grayscale shape things |
2512 |
- if(get_bits1(&s->gb)) printf("Quant-Type not supported\n"); /* vol_quant_type */ //FIXME |
|
2512 |
+ |
|
2513 |
+ if(get_bits1(&s->gb)){ /* vol_quant_type */ |
|
2514 |
+ int i, j, v; |
|
2515 |
+ /* load default matrixes */ |
|
2516 |
+ for(i=0; i<64; i++){ |
|
2517 |
+ v= ff_mpeg4_default_intra_matrix[i]; |
|
2518 |
+ s->intra_matrix[i]= v; |
|
2519 |
+ s->chroma_intra_matrix[i]= v; |
|
2520 |
+ |
|
2521 |
+ v= ff_mpeg4_default_non_intra_matrix[i]; |
|
2522 |
+ s->non_intra_matrix[i]= v; |
|
2523 |
+ s->chroma_non_intra_matrix[i]= v; |
|
2524 |
+ } |
|
2525 |
+ |
|
2526 |
+ /* load custom intra matrix */ |
|
2527 |
+ if(get_bits1(&s->gb)){ |
|
2528 |
+ for(i=0; i<64; i++){ |
|
2529 |
+ v= get_bits(&s->gb, 8); |
|
2530 |
+ if(v==0) break; |
|
2531 |
+ |
|
2532 |
+ j= zigzag_direct[i]; |
|
2533 |
+ s->intra_matrix[j]= v; |
|
2534 |
+ s->chroma_intra_matrix[j]= v; |
|
2535 |
+ } |
|
2536 |
+ } |
|
2537 |
+ |
|
2538 |
+ /* load custom non intra matrix */ |
|
2539 |
+ if(get_bits1(&s->gb)){ |
|
2540 |
+ for(i=0; i<64; i++){ |
|
2541 |
+ v= get_bits(&s->gb, 8); |
|
2542 |
+ if(v==0) break; |
|
2543 |
+ |
|
2544 |
+ j= zigzag_direct[i]; |
|
2545 |
+ s->non_intra_matrix[j]= v; |
|
2546 |
+ s->chroma_non_intra_matrix[j]= v; |
|
2547 |
+ } |
|
2548 |
+ |
|
2549 |
+ /* replicate last value */ |
|
2550 |
+ for(; i<64; i++){ |
|
2551 |
+ j= zigzag_direct[i]; |
|
2552 |
+ s->non_intra_matrix[j]= v; |
|
2553 |
+ s->chroma_non_intra_matrix[j]= v; |
|
2554 |
+ } |
|
2555 |
+ } |
|
2556 |
+ |
|
2557 |
+ s->dct_unquantize= s->dct_unquantize_mpeg; |
|
2558 |
+ |
|
2559 |
+ // FIXME a bunch of grayscale shape things |
|
2560 |
+ }else |
|
2561 |
+ s->dct_unquantize= s->dct_unquantize_h263; |
|
2562 |
+ |
|
2513 | 2563 |
if(vo_ver_id != 1) |
2514 | 2564 |
s->quarter_sample= get_bits1(&s->gb); |
2515 | 2565 |
else s->quarter_sample=0; |
... | ... |
@@ -440,11 +440,9 @@ void unused_var_warning_killer(){ |
440 | 440 |
void MPV_common_init_mmx(MpegEncContext *s) |
441 | 441 |
{ |
442 | 442 |
if (mm_flags & MM_MMX) { |
443 |
- if (s->out_format == FMT_H263) |
|
444 |
- s->dct_unquantize = dct_unquantize_h263_mmx; |
|
445 |
- else |
|
446 |
- s->dct_unquantize = dct_unquantize_mpeg1_mmx; |
|
447 |
- |
|
443 |
+ s->dct_unquantize_h263 = dct_unquantize_h263_mmx; |
|
444 |
+ s->dct_unquantize_mpeg = dct_unquantize_mpeg1_mmx; |
|
445 |
+ |
|
448 | 446 |
draw_edges = draw_edges_mmx; |
449 | 447 |
|
450 | 448 |
if(mm_flags & MM_MMXEXT){ |
... | ... |
@@ -122,3 +122,27 @@ static const UINT16 pixel_aspect[16][2]={ |
122 | 122 |
{0, 0}, |
123 | 123 |
{0, 0}, |
124 | 124 |
}; |
125 |
+ |
|
126 |
+/* these matrixes will be permuted for the idct */ |
|
127 |
+INT16 ff_mpeg4_default_intra_matrix[64] = { |
|
128 |
+ 8, 17, 18, 19, 21, 23, 25, 27, |
|
129 |
+ 17, 18, 19, 21, 23, 25, 27, 28, |
|
130 |
+ 20, 21, 22, 23, 24, 26, 28, 30, |
|
131 |
+ 21, 22, 23, 24, 26, 28, 30, 32, |
|
132 |
+ 22, 23, 24, 26, 28, 30, 32, 35, |
|
133 |
+ 23, 24, 26, 28, 30, 32, 35, 38, |
|
134 |
+ 25, 26, 28, 30, 32, 35, 38, 41, |
|
135 |
+ 27, 28, 30, 32, 35, 38, 41, 45, |
|
136 |
+}; |
|
137 |
+ |
|
138 |
+INT16 ff_mpeg4_default_non_intra_matrix[64] = { |
|
139 |
+ 16, 17, 18, 19, 20, 21, 22, 23, |
|
140 |
+ 17, 18, 19, 20, 21, 22, 23, 24, |
|
141 |
+ 18, 19, 20, 21, 22, 23, 24, 25, |
|
142 |
+ 19, 20, 21, 22, 23, 24, 26, 27, |
|
143 |
+ 20, 21, 22, 23, 25, 26, 27, 28, |
|
144 |
+ 21, 22, 23, 24, 26, 27, 28, 30, |
|
145 |
+ 22, 23, 24, 26, 27, 28, 30, 31, |
|
146 |
+ 23, 24, 25, 27, 28, 30, 31, 33, |
|
147 |
+}; |
|
148 |
+ |
... | ... |
@@ -110,14 +110,18 @@ int MPV_common_init(MpegEncContext *s) |
110 | 110 |
int c_size, i; |
111 | 111 |
UINT8 *pict; |
112 | 112 |
|
113 |
- if (s->out_format == FMT_H263) |
|
114 |
- s->dct_unquantize = dct_unquantize_h263_c; |
|
115 |
- else |
|
116 |
- s->dct_unquantize = dct_unquantize_mpeg1_c; |
|
113 |
+ s->dct_unquantize_h263 = dct_unquantize_h263_c; |
|
114 |
+ s->dct_unquantize_mpeg = dct_unquantize_mpeg1_c; |
|
117 | 115 |
|
118 | 116 |
#ifdef HAVE_MMX |
119 | 117 |
MPV_common_init_mmx(s); |
120 | 118 |
#endif |
119 |
+ //setup default unquantizers (mpeg4 might change it later) |
|
120 |
+ if(s->out_format == FMT_H263) |
|
121 |
+ s->dct_unquantize = s->dct_unquantize_h263; |
|
122 |
+ else |
|
123 |
+ s->dct_unquantize = s->dct_unquantize_mpeg; |
|
124 |
+ |
|
121 | 125 |
s->mb_width = (s->width + 15) / 16; |
122 | 126 |
s->mb_height = (s->height + 15) / 16; |
123 | 127 |
s->mb_num = s->mb_width * s->mb_height; |
... | ... |
@@ -309,7 +309,11 @@ typedef struct MpegEncContext { |
309 | 309 |
DCTELEM intra_block[6][64] __align8; |
310 | 310 |
DCTELEM inter_block[6][64] __align8; |
311 | 311 |
DCTELEM inter4v_block[6][64] __align8; |
312 |
- void (*dct_unquantize)(struct MpegEncContext *s, |
|
312 |
+ void (*dct_unquantize_mpeg)(struct MpegEncContext *s, |
|
313 |
+ DCTELEM *block, int n, int qscale); |
|
314 |
+ void (*dct_unquantize_h263)(struct MpegEncContext *s, |
|
315 |
+ DCTELEM *block, int n, int qscale); |
|
316 |
+ void (*dct_unquantize)(struct MpegEncContext *s, // unquantizer to use (mpeg4 can use both) |
|
313 | 317 |
DCTELEM *block, int n, int qscale); |
314 | 318 |
} MpegEncContext; |
315 | 319 |
|