comparison vc1.c @ 3367:8c7b8ffc2485 libavcodec

Some optimization and fixes - mostly reworked MC and bitplanes.
author kostya
date Thu, 29 Jun 2006 11:05:33 +0000
parents c59aa4cdf042
children ad7215e207f8
comparison
equal deleted inserted replaced
3366:c59aa4cdf042 3367:8c7b8ffc2485
200 CS_MID_RATE_INTRA, 200 CS_MID_RATE_INTRA,
201 CS_MID_RATE_INTER, 201 CS_MID_RATE_INTER,
202 CS_HIGH_RATE_INTRA, 202 CS_HIGH_RATE_INTRA,
203 CS_HIGH_RATE_INTER 203 CS_HIGH_RATE_INTER
204 }; 204 };
205
206 /** Bitplane struct
207 * We mainly need data and is_raw, so this struct could be avoided
208 * to save a level of indirection; feel free to modify
209 * @fixme For now, stride=width
210 * @warning Data are bits, either 1 or 0
211 */
212 typedef struct BitPlane {
213 uint8_t *data; ///< Data buffer
214 int width; ///< Width of the buffer
215 int stride; ///< Stride of the buffer
216 int height; ///< Plane height
217 uint8_t is_raw; ///< Bit values must be read at MB level
218 } BitPlane;
219
220
221 /** Block data for DC/AC prediction
222 */
223 typedef struct Block {
224 uint16_t dc;
225 int16_t hor_ac[7];
226 int16_t vert_ac[7];
227 int16_t dcstep, step;
228 } Block;
229 205
230 /** The VC1 Context 206 /** The VC1 Context
231 * @fixme Change size wherever another size is more efficient 207 * @fixme Change size wherever another size is more efficient
232 * Many members are only used for Advanced Profile 208 * Many members are only used for Advanced Profile
233 */ 209 */
332 uint8_t mvrange; 308 uint8_t mvrange;
333 uint8_t pquantizer; ///< Uniform (over sequence) quantizer in use 309 uint8_t pquantizer; ///< Uniform (over sequence) quantizer in use
334 uint8_t *previous_line_cbpcy; ///< To use for predicted CBPCY 310 uint8_t *previous_line_cbpcy; ///< To use for predicted CBPCY
335 VLC *cbpcy_vlc; ///< CBPCY VLC table 311 VLC *cbpcy_vlc; ///< CBPCY VLC table
336 int tt_index; ///< Index for Transform Type tables 312 int tt_index; ///< Index for Transform Type tables
337 BitPlane mv_type_mb_plane; ///< bitplane for mv_type == (4MV) 313 uint8_t* mv_type_mb_plane; ///< bitplane for mv_type == (4MV)
338 BitPlane skip_mb_plane; ///< bitplane for skipped MBs 314 uint8_t* skip_mb_plane; ///< bitplane for skipped MBs
339 BitPlane direct_mb_plane; ///< bitplane for "direct" MBs 315 // BitPlane direct_mb_plane; ///< bitplane for "direct" MBs
316 int mv_type_is_raw; ///< mv type mb plane is not coded
317 int skip_is_raw; ///< skip mb plane is not coded
340 318
341 /** Frame decoding info for S/M profiles only */ 319 /** Frame decoding info for S/M profiles only */
342 //@{ 320 //@{
343 uint8_t rangeredfrm; ///< out_sample = CLIP((in_sample-128)*2+128) 321 uint8_t rangeredfrm; ///< out_sample = CLIP((in_sample-128)*2+128)
344 uint8_t interpfrm; 322 uint8_t interpfrm;
357 uint8_t uvsamp; 335 uint8_t uvsamp;
358 uint8_t postproc; 336 uint8_t postproc;
359 int hrd_num_leaky_buckets; 337 int hrd_num_leaky_buckets;
360 uint8_t bit_rate_exponent; 338 uint8_t bit_rate_exponent;
361 uint8_t buffer_size_exponent; 339 uint8_t buffer_size_exponent;
362 BitPlane ac_pred_plane; ///< AC prediction flags bitplane 340 // BitPlane ac_pred_plane; ///< AC prediction flags bitplane
363 BitPlane over_flags_plane; ///< Overflags bitplane 341 // BitPlane over_flags_plane; ///< Overflags bitplane
364 uint8_t condover; 342 uint8_t condover;
365 uint16_t *hrd_rate, *hrd_buffer; 343 uint16_t *hrd_rate, *hrd_buffer;
366 uint8_t *hrd_fullness; 344 uint8_t *hrd_fullness;
367 uint8_t range_mapy_flag; 345 uint8_t range_mapy_flag;
368 uint8_t range_mapuv_flag; 346 uint8_t range_mapuv_flag;
434 static int vc1_init_common(VC1Context *v) 412 static int vc1_init_common(VC1Context *v)
435 { 413 {
436 static int done = 0; 414 static int done = 0;
437 int i = 0; 415 int i = 0;
438 416
439 /* Set the bit planes */
440 v->mv_type_mb_plane = (struct BitPlane) { NULL, 0, 0, 0 };
441 v->direct_mb_plane = (struct BitPlane) { NULL, 0, 0, 0 };
442 v->skip_mb_plane = (struct BitPlane) { NULL, 0, 0, 0 };
443 v->ac_pred_plane = v->over_flags_plane = (struct BitPlane) { NULL, 0, 0, 0 };
444 v->hrd_rate = v->hrd_buffer = NULL; 417 v->hrd_rate = v->hrd_buffer = NULL;
445 418
446 /* VLC tables */ 419 /* VLC tables */
447 if(!done) 420 if(!done)
448 { 421 {
519 IMODE_ROWSKIP, 492 IMODE_ROWSKIP,
520 IMODE_COLSKIP 493 IMODE_COLSKIP
521 }; 494 };
522 /** @} */ //imode defines 495 /** @} */ //imode defines
523 496
524 /** Allocate the buffer from a bitplane, given its dimensions
525 * @param bp Bitplane which buffer is to allocate
526 * @param[in] width Width of the buffer
527 * @param[in] height Height of the buffer
528 * @return Status
529 * @todo TODO: Take into account stride
530 * @todo TODO: Allow use of external buffers ?
531 */
532 static int alloc_bitplane(BitPlane *bp, int width, int height)
533 {
534 if (!bp || bp->width<0 || bp->height<0) return -1;
535 bp->data = (uint8_t*)av_malloc(width*height);
536 if (!bp->data) return -1;
537 bp->width = bp->stride = width;
538 bp->height = height;
539 return 0;
540 }
541
542 /** Free the bitplane's buffer
543 * @param bp Bitplane which buffer is to free
544 */
545 static void free_bitplane(BitPlane *bp)
546 {
547 bp->width = bp->stride = bp->height = 0;
548 if (bp->data) av_freep(&bp->data);
549 }
550
551 /** Decode rows by checking if they are skipped 497 /** Decode rows by checking if they are skipped
552 * @param plane Buffer to store decoded bits 498 * @param plane Buffer to store decoded bits
553 * @param[in] width Width of this buffer 499 * @param[in] width Width of this buffer
554 * @param[in] height Height of this buffer 500 * @param[in] height Height of this buffer
555 * @param[in] stride of this buffer 501 * @param[in] stride of this buffer
593 * @param v VC-1 context for bit reading and logging 539 * @param v VC-1 context for bit reading and logging
594 * @return Status 540 * @return Status
595 * @fixme FIXME: Optimize 541 * @fixme FIXME: Optimize
596 * @todo TODO: Decide if a struct is needed 542 * @todo TODO: Decide if a struct is needed
597 */ 543 */
598 static int bitplane_decoding(BitPlane *bp, VC1Context *v) 544 static int bitplane_decoding(uint8_t* data, int *raw_flag, VC1Context *v)
599 { 545 {
600 GetBitContext *gb = &v->s.gb; 546 GetBitContext *gb = &v->s.gb;
601 547
602 int imode, x, y, code, offset; 548 int imode, x, y, code, offset;
603 uint8_t invert, *planep = bp->data; 549 uint8_t invert, *planep = data;
604 550 int width, height, stride;
551
552 width = v->s.mb_width;
553 height = v->s.mb_height;
554 stride = v->s.mb_stride;
605 invert = get_bits(gb, 1); 555 invert = get_bits(gb, 1);
606 imode = get_vlc2(gb, vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 1); 556 imode = get_vlc2(gb, vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 1);
607 557
608 bp->is_raw = 0; 558 *raw_flag = 0;
609 switch (imode) 559 switch (imode)
610 { 560 {
611 case IMODE_RAW: 561 case IMODE_RAW:
612 //Data is actually read in the MB layer (same for all tests == "raw") 562 //Data is actually read in the MB layer (same for all tests == "raw")
613 bp->is_raw = 1; //invert ignored 563 *raw_flag = 1; //invert ignored
614 return invert; 564 return invert;
615 case IMODE_DIFF2: 565 case IMODE_DIFF2:
616 case IMODE_NORM2: 566 case IMODE_NORM2:
617 if ((bp->height * bp->width) & 1) 567 if ((height * width) & 1)
618 { 568 {
619 *planep++ = get_bits(gb, 1); 569 *planep++ = get_bits(gb, 1);
620 offset = 1; 570 offset = 1;
621 } 571 }
622 else offset = 0; 572 else offset = 0;
623 // decode bitplane as one long line 573 // decode bitplane as one long line
624 for (y = offset; y < bp->height * bp->width; y += 2) { 574 for (y = offset; y < height * width; y += 2) {
625 code = get_vlc2(gb, vc1_norm2_vlc.table, VC1_NORM2_VLC_BITS, 1); 575 code = get_vlc2(gb, vc1_norm2_vlc.table, VC1_NORM2_VLC_BITS, 1);
626 *planep++ = code & 1; 576 *planep++ = code & 1;
627 offset++; 577 offset++;
628 if(offset == bp->width) { 578 if(offset == width) {
629 offset = 0; 579 offset = 0;
630 planep += bp->stride - bp->width; 580 planep += stride - width;
631 } 581 }
632 *planep++ = code >> 1; 582 *planep++ = code >> 1;
633 offset++; 583 offset++;
634 if(offset == bp->width) { 584 if(offset == width) {
635 offset = 0; 585 offset = 0;
636 planep += bp->stride - bp->width; 586 planep += stride - width;
637 } 587 }
638 } 588 }
639 break; 589 break;
640 case IMODE_DIFF6: 590 case IMODE_DIFF6:
641 case IMODE_NORM6: 591 case IMODE_NORM6:
642 if(!(bp->height % 3) && (bp->width % 3)) { // use 2x3 decoding 592 if(!(height % 3) && (width % 3)) { // use 2x3 decoding
643 for(y = 0; y < bp->height; y+= 3) { 593 for(y = 0; y < height; y+= 3) {
644 for(x = bp->width & 1; x < bp->width; x += 2) { 594 for(x = width & 1; x < width; x += 2) {
645 code = get_vlc2(gb, vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2); 595 code = get_vlc2(gb, vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
646 if(code < 0){ 596 if(code < 0){
647 av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n"); 597 av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
648 return -1; 598 return -1;
649 } 599 }
650 planep[x + 0] = (code >> 0) & 1; 600 planep[x + 0] = (code >> 0) & 1;
651 planep[x + 1] = (code >> 1) & 1; 601 planep[x + 1] = (code >> 1) & 1;
652 planep[x + 0 + bp->stride] = (code >> 2) & 1; 602 planep[x + 0 + stride] = (code >> 2) & 1;
653 planep[x + 1 + bp->stride] = (code >> 3) & 1; 603 planep[x + 1 + stride] = (code >> 3) & 1;
654 planep[x + 0 + bp->stride * 2] = (code >> 4) & 1; 604 planep[x + 0 + stride * 2] = (code >> 4) & 1;
655 planep[x + 1 + bp->stride * 2] = (code >> 5) & 1; 605 planep[x + 1 + stride * 2] = (code >> 5) & 1;
656 } 606 }
657 planep += bp->stride * 3; 607 planep += stride * 3;
658 } 608 }
659 if(bp->width & 1) decode_colskip(bp->data, 1, bp->height, bp->stride, &v->s.gb); 609 if(width & 1) decode_colskip(data, 1, height, stride, &v->s.gb);
660 } else { // 3x2 610 } else { // 3x2
661 for(y = bp->height & 1; y < bp->height; y += 2) { 611 for(y = height & 1; y < height; y += 2) {
662 for(x = bp->width % 3; x < bp->width; x += 3) { 612 for(x = width % 3; x < width; x += 3) {
663 code = get_vlc2(gb, vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2); 613 code = get_vlc2(gb, vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2);
664 if(code < 0){ 614 if(code < 0){
665 av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n"); 615 av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n");
666 return -1; 616 return -1;
667 } 617 }
668 planep[x + 0] = (code >> 0) & 1; 618 planep[x + 0] = (code >> 0) & 1;
669 planep[x + 1] = (code >> 1) & 1; 619 planep[x + 1] = (code >> 1) & 1;
670 planep[x + 2] = (code >> 2) & 1; 620 planep[x + 2] = (code >> 2) & 1;
671 planep[x + 0 + bp->stride] = (code >> 3) & 1; 621 planep[x + 0 + stride] = (code >> 3) & 1;
672 planep[x + 1 + bp->stride] = (code >> 4) & 1; 622 planep[x + 1 + stride] = (code >> 4) & 1;
673 planep[x + 2 + bp->stride] = (code >> 5) & 1; 623 planep[x + 2 + stride] = (code >> 5) & 1;
674 } 624 }
675 planep += bp->stride * 2; 625 planep += stride * 2;
676 } 626 }
677 x = bp->width % 3; 627 x = width % 3;
678 if(x) decode_colskip(bp->data , x, bp->height , bp->stride, &v->s.gb); 628 if(x) decode_colskip(data , x, height , stride, &v->s.gb);
679 if(bp->height & 1) decode_rowskip(bp->data+x, bp->width - x, bp->height & 1, bp->stride, &v->s.gb); 629 if(height & 1) decode_rowskip(data+x, width - x, 1, stride, &v->s.gb);
680 } 630 }
681 break; 631 break;
682 case IMODE_ROWSKIP: 632 case IMODE_ROWSKIP:
683 decode_rowskip(bp->data, bp->width, bp->height, bp->stride, &v->s.gb); 633 decode_rowskip(data, width, height, stride, &v->s.gb);
684 break; 634 break;
685 case IMODE_COLSKIP: 635 case IMODE_COLSKIP:
686 decode_colskip(bp->data, bp->width, bp->height, bp->stride, &v->s.gb); 636 decode_colskip(data, width, height, stride, &v->s.gb);
687 break; 637 break;
688 default: break; 638 default: break;
689 } 639 }
690 640
691 /* Applying diff operator */ 641 /* Applying diff operator */
692 if (imode == IMODE_DIFF2 || imode == IMODE_DIFF6) 642 if (imode == IMODE_DIFF2 || imode == IMODE_DIFF6)
693 { 643 {
694 planep = bp->data; 644 planep = data;
695 planep[0] ^= invert; 645 planep[0] ^= invert;
696 for (x=1; x<bp->width; x++) 646 for (x=1; x<width; x++)
697 planep[x] ^= planep[x-1]; 647 planep[x] ^= planep[x-1];
698 for (y=1; y<bp->height; y++) 648 for (y=1; y<height; y++)
699 { 649 {
700 planep += bp->stride; 650 planep += stride;
701 planep[0] ^= planep[-bp->stride]; 651 planep[0] ^= planep[-stride];
702 for (x=1; x<bp->width; x++) 652 for (x=1; x<width; x++)
703 { 653 {
704 if (planep[x-1] != planep[x-bp->stride]) planep[x] ^= invert; 654 if (planep[x-1] != planep[x-stride]) planep[x] ^= invert;
705 else planep[x] ^= planep[x-1]; 655 else planep[x] ^= planep[x-1];
706 } 656 }
707 } 657 }
708 } 658 }
709 else if (invert) 659 else if (invert)
710 { 660 {
711 planep = bp->data; 661 planep = data;
712 for (x=0; x<bp->width*bp->height; x++) planep[x] = !planep[x]; //FIXME stride 662 for (x=0; x<stride*height; x++) planep[x] = !planep[x]; //FIXME stride
713 } 663 }
714 return (imode<<1) + invert; 664 return (imode<<1) + invert;
715 } 665 }
666
716 /** @} */ //Bitplane group 667 /** @} */ //Bitplane group
717 668
718 /***********************************************************************/ 669 /***********************************************************************/
719 /** VOP Dquant decoding 670 /** VOP Dquant decoding
720 * @param v VC-1 Context 671 * @param v VC-1 Context
884 for(i = 0; i < 64; i++) 835 for(i = 0; i < 64; i++)
885 block[i] += 128; 836 block[i] += 128;
886 } 837 }
887 838
888 839
840 static void vc1_v_overlap(uint8_t* src, int stride)
841 {
842 int i;
843 int a, b, c, d;
844 for(i = 0; i < 8; i++) {
845 a = src[-2*stride];
846 b = src[-stride];
847 c = src[0];
848 d = src[stride];
849
850 src[-2*stride] = (7*a + d) >> 3;
851 src[-stride] = (-a + 7*b + c + d) >> 3;
852 src[0] = (a + b + 7*c - d) >> 3;
853 src[stride] = (a + 7*d) >> 3;
854 src++;
855 }
856 }
857
858 static void vc1_h_overlap(uint8_t* src, int stride)
859 {
860 int i;
861 int a, b, c, d;
862 for(i = 0; i < 8; i++) {
863 a = src[-2];
864 b = src[-1];
865 c = src[0];
866 d = src[1];
867
868 src[-2] = (7*a + d) >> 3;
869 src[-1] = (-a + 7*b + c + d) >> 3;
870 src[0] = (a + b + 7*c - d) >> 3;
871 src[1] = (a + 7*d) >> 3;
872 src += stride;
873 }
874 }
875
889 /** Put block onto picture 876 /** Put block onto picture
890 * @todo move to DSPContext 877 * @todo move to DSPContext
891 */ 878 */
892 static void vc1_put_block(VC1Context *v, DCTELEM block[6][64]) 879 static void vc1_put_block(VC1Context *v, DCTELEM block[6][64])
893 { 880 {
908 895
909 dsp->put_pixels_clamped(block[4], v->s.dest[1], us); 896 dsp->put_pixels_clamped(block[4], v->s.dest[1], us);
910 dsp->put_pixels_clamped(block[5], v->s.dest[2], vs); 897 dsp->put_pixels_clamped(block[5], v->s.dest[2], vs);
911 } 898 }
912 899
900 /* clip motion vector as specified in 8.3.6.5 */
901 #define CLIP_RANGE(mv, src, lim, bs) \
902 if(mv < -bs) mv = -bs - src * bs; \
903 if(mv > lim) mv = lim - src * bs;
904
913 /** Do motion compensation over 1 macroblock 905 /** Do motion compensation over 1 macroblock
914 * Mostly adapted hpel_motion and qpel_motion from mpegvideo.c 906 * Mostly adapted hpel_motion and qpel_motion from mpegvideo.c
915 */ 907 */
916 static void vc1_mc_1mv(VC1Context *v) 908 static void vc1_mc_1mv(VC1Context *v)
917 { 909 {
918 MpegEncContext *s = &v->s; 910 MpegEncContext *s = &v->s;
919 DSPContext *dsp = &v->s.dsp; 911 DSPContext *dsp = &v->s.dsp;
920 uint8_t *srcY, *srcU, *srcV; 912 uint8_t *srcY, *srcU, *srcV;
921 int dxy, mx, my, src_x, src_y; 913 int dxy, uvdxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
922 int width = s->mb_width * 16, height = s->mb_height * 16;
923 914
924 if(!v->s.last_picture.data[0])return; 915 if(!v->s.last_picture.data[0])return;
925 916
926 mx = s->mv[0][0][0] >> s->mspel; 917 mx = s->mv[0][0][0];
927 my = s->mv[0][0][1] >> s->mspel; 918 my = s->mv[0][0][1];
919 uvmx = (mx + ((mx & 3) == 3)) >> 1;
920 uvmy = (my + ((my & 3) == 3)) >> 1;
928 srcY = s->last_picture.data[0]; 921 srcY = s->last_picture.data[0];
929 srcU = s->last_picture.data[1]; 922 srcU = s->last_picture.data[1];
930 srcV = s->last_picture.data[2]; 923 srcV = s->last_picture.data[2];
931 924
932 if(s->mspel) { // hpel mc 925 if(v->fastuvmc) { // XXX: 8.3.5.4.5 specifies something different
926 uvmx = (uvmx + 1) >> 1;
927 uvmy = (uvmy + 1) >> 1;
928 }
929
930 src_x = s->mb_x * 16 + (mx >> 2);
931 src_y = s->mb_y * 16 + (my >> 2);
932 uvsrc_x = s->mb_x * 8 + (uvmx >> 2);
933 uvsrc_y = s->mb_y * 8 + (uvmy >> 2);
934
935 CLIP_RANGE( src_x, s->mb_x, s->mb_width * 16, 16);
936 CLIP_RANGE( src_y, s->mb_y, s->mb_height * 16, 16);
937 CLIP_RANGE(uvsrc_x, s->mb_x, s->mb_width * 8, 8);
938 CLIP_RANGE(uvsrc_y, s->mb_y, s->mb_height * 8, 8);
939
940 srcY += src_y * s->linesize + src_x;
941 srcU += uvsrc_y * s->uvlinesize + uvsrc_x;
942 srcV += uvsrc_y * s->uvlinesize + uvsrc_x;
943
944 if((unsigned)src_x > s->h_edge_pos - (mx&3) - 16
945 || (unsigned)src_y > s->v_edge_pos - (my&3) - 16){
946 uint8_t *uvbuf= s->edge_emu_buffer + 18 * s->linesize;
947
948 ff_emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 16+1, 16+1,
949 src_x, src_y, s->h_edge_pos, s->v_edge_pos);
950 srcY = s->edge_emu_buffer;
951 ff_emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8+1, 8+1,
952 uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
953 ff_emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8+1, 8+1,
954 uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
955 srcU = uvbuf;
956 srcV = uvbuf + 16;
957 }
958
959 if(!s->quarter_sample) { // hpel mc
960 mx >>= 1;
961 my >>= 1;
962 uvmx >>= 1;
963 uvmy >>= 1;
933 dxy = ((my & 1) << 1) | (mx & 1); 964 dxy = ((my & 1) << 1) | (mx & 1);
934 src_x = s->mb_x * 16 + (mx >> 1); 965 uvdxy = 0;
935 src_y = s->mb_y * 16 + (my >> 1); 966
936 /* src_x = clip(src_x, -16, width); //FIXME unneeded for emu?
937 if (src_x == width)
938 dxy &= ~1;
939 src_y = clip(src_y, -16, height);
940 if (src_y == height)
941 dxy &= ~2;*/
942 srcY += src_y * s->linesize + src_x;
943 srcU += (src_y >> 1) * s->uvlinesize + (src_x >> 1);
944 srcV += (src_y >> 1) * s->uvlinesize + (src_x >> 1);
945
946 if((unsigned)src_x > s->h_edge_pos - (mx&1) - 16
947 || (unsigned)src_y > s->v_edge_pos - (my&1) - 16){
948 uint8_t *uvbuf= s->edge_emu_buffer + 18 * s->linesize;
949
950 ff_emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 16+1, 16+1,
951 src_x, src_y, s->h_edge_pos, s->v_edge_pos);
952 srcY = s->edge_emu_buffer;
953 ff_emulated_edge_mc(uvbuf, srcU, s->uvlinesize, 8+1, 8+1,
954 src_x >> 1, src_y >> 1, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
955 ff_emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8+1, 8+1,
956 src_x >> 1, src_y >> 1, s->h_edge_pos >> 1, s->v_edge_pos >> 1);
957 srcU = uvbuf;
958 srcV = uvbuf + 16;
959 }
960 dsp->put_no_rnd_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16); 967 dsp->put_no_rnd_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16);
961 dsp->put_no_rnd_pixels_tab[1][0](s->dest[1], srcU, s->uvlinesize, 8);
962 dsp->put_no_rnd_pixels_tab[1][0](s->dest[2], srcV, s->uvlinesize, 8);
963 } else { 968 } else {
964 int motion_x = mx, motion_y = my, uvdxy, uvsrc_x, uvsrc_y; 969 dxy = ((my & 3) << 2) | (mx & 3);
965 dxy = ((motion_y & 3) << 2) | (motion_x & 3); 970 uvdxy = ((uvmy & 1) << 1) | (uvmx & 1);
966 src_x = s->mb_x * 16 + (mx >> 2);
967 src_y = s->mb_y * 16 + (my >> 2);
968
969 mx= motion_x/2;
970 my= motion_y/2;
971
972 mx= (mx>>1)|(mx&1);
973 my= (my>>1)|(my&1);
974
975 uvdxy= (mx&1) | ((my&1)<<1);
976 mx>>=1;
977 my>>=1;
978
979 uvsrc_x = s->mb_x * 8 + mx;
980 uvsrc_y = s->mb_y * 8 + my;
981
982 srcY = s->last_picture.data[0] + src_y * s->linesize + src_x;
983 srcU = s->last_picture.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x;
984 srcV = s->last_picture.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x;
985
986 if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 16
987 || (unsigned)src_y > s->v_edge_pos - (motion_y&3) - 16 ){
988 uint8_t *uvbuf= s->edge_emu_buffer + 18*s->linesize;
989 ff_emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 17, 17,
990 src_x, src_y, s->h_edge_pos, s->v_edge_pos);
991 srcY = s->edge_emu_buffer;
992 ff_emulated_edge_mc(uvbuf, srcU, s->uvlinesize, 9, 9,
993 uvsrc_x, uvsrc_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
994 ff_emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 9, 9,
995 uvsrc_x, uvsrc_y, s->h_edge_pos>>1, s->v_edge_pos>>1);
996 srcU = uvbuf;
997 srcV = uvbuf + 16;
998 }
999 971
1000 dsp->put_no_rnd_qpel_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize); 972 dsp->put_no_rnd_qpel_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize);
1001 dsp->put_no_rnd_pixels_tab[1][uvdxy](s->dest[1], srcU, s->uvlinesize, 8); 973 }
1002 dsp->put_no_rnd_pixels_tab[1][uvdxy](s->dest[2], srcV, s->uvlinesize, 8); 974 dsp->put_mspel_pixels_tab[uvdxy](s->dest[1], srcU, s->uvlinesize);
1003 } 975 dsp->put_mspel_pixels_tab[uvdxy](s->dest[2], srcV, s->uvlinesize);
1004 } 976 }
1005 977
1006 /** 978 /**
1007 * Decode Simple/Main Profiles sequence header 979 * Decode Simple/Main Profiles sequence header
1008 * @see Figure 7-8, p16-17 980 * @see Figure 7-8, p16-17
1213 v->mv_mode2 = mv_pmode_table[lowquant][get_prefix(gb, 1, 3)]; 1185 v->mv_mode2 = mv_pmode_table[lowquant][get_prefix(gb, 1, 3)];
1214 v->lumscale = get_bits(gb, 6); 1186 v->lumscale = get_bits(gb, 6);
1215 v->lumshift = get_bits(gb, 6); 1187 v->lumshift = get_bits(gb, 6);
1216 } 1188 }
1217 if(v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN) 1189 if(v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN)
1218 v->s.mspel = 1; 1190 v->s.quarter_sample = 0;
1219 else 1191 else
1220 v->s.mspel = 0; 1192 v->s.quarter_sample = 1;
1221 1193
1222 if(v->mv_mode != MV_PMODE_1MV && v->mv_mode != MV_PMODE_1MV_HPEL && v->mv_mode != MV_PMODE_1MV_HPEL_BILIN) { 1194 if(v->mv_mode != MV_PMODE_1MV && v->mv_mode != MV_PMODE_1MV_HPEL && v->mv_mode != MV_PMODE_1MV_HPEL_BILIN) {
1223 av_log(v->s.avctx, AV_LOG_ERROR, "Only 1MV P-frames are supported by now\n"); 1195 av_log(v->s.avctx, AV_LOG_ERROR, "Only 1MV P-frames are supported by now\n");
1224 return -1; 1196 return -1;
1225 } 1197 }
1226 if ((v->mv_mode == MV_PMODE_INTENSITY_COMP && 1198 if ((v->mv_mode == MV_PMODE_INTENSITY_COMP &&
1227 v->mv_mode2 == MV_PMODE_MIXED_MV) 1199 v->mv_mode2 == MV_PMODE_MIXED_MV)
1228 || v->mv_mode == MV_PMODE_MIXED_MV) 1200 || v->mv_mode == MV_PMODE_MIXED_MV)
1229 { 1201 {
1230 status = bitplane_decoding(&v->mv_type_mb_plane, v); 1202 status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v);
1231 if (status < 0) return -1; 1203 if (status < 0) return -1;
1232 av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: " 1204 av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: "
1233 "Imode: %i, Invert: %i\n", status>>1, status&1); 1205 "Imode: %i, Invert: %i\n", status>>1, status&1);
1234 } 1206 } else {
1235 status = bitplane_decoding(&v->skip_mb_plane, v); 1207 v->mv_type_is_raw = 0;
1208 memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height);
1209 }
1210 status = bitplane_decoding(v->skip_mb_plane, &v->skip_is_raw, v);
1236 if (status < 0) return -1; 1211 if (status < 0) return -1;
1237 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: " 1212 av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: "
1238 "Imode: %i, Invert: %i\n", status>>1, status&1); 1213 "Imode: %i, Invert: %i\n", status>>1, status&1);
1239 1214
1240 /* Hopefully this is correct for P frames */ 1215 /* Hopefully this is correct for P frames */
1325 else mb_has_coeffs = 0; \ 1300 else mb_has_coeffs = 0; \
1326 s->mb_intra = 0; \ 1301 s->mb_intra = 0; \
1327 if (!index) { _dmv_x = _dmv_y = 0; } \ 1302 if (!index) { _dmv_x = _dmv_y = 0; } \
1328 else if (index == 35) \ 1303 else if (index == 35) \
1329 { \ 1304 { \
1330 _dmv_x = get_bits(gb, v->k_x - s->mspel); \ 1305 _dmv_x = get_bits(gb, v->k_x - 1 + s->quarter_sample); \
1331 _dmv_y = get_bits(gb, v->k_y - s->mspel); \ 1306 _dmv_y = get_bits(gb, v->k_y - 1 + s->quarter_sample); \
1332 } \ 1307 } \
1333 else if (index == 36) \ 1308 else if (index == 36) \
1334 { \ 1309 { \
1335 _dmv_x = 0; \ 1310 _dmv_x = 0; \
1336 _dmv_y = 0; \ 1311 _dmv_y = 0; \
1337 s->mb_intra = 1; \ 1312 s->mb_intra = 1; \
1338 } \ 1313 } \
1339 else \ 1314 else \
1340 { \ 1315 { \
1341 index1 = index%6; \ 1316 index1 = index%6; \
1342 if (s->mspel && index1 == 5) val = 1; \ 1317 if (!s->quarter_sample && index1 == 5) val = 1; \
1343 else val = 0; \ 1318 else val = 0; \
1344 if(size_table[index1] - val > 0) \ 1319 if(size_table[index1] - val > 0) \
1345 val = get_bits(gb, size_table[index1] - val); \ 1320 val = get_bits(gb, size_table[index1] - val); \
1346 else val = 0; \ 1321 else val = 0; \
1347 sign = 0 - (val&1); \ 1322 sign = 0 - (val&1); \
1348 _dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \ 1323 _dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
1349 \ 1324 \
1350 index1 = index/6; \ 1325 index1 = index/6; \
1351 if (s->mspel && index1 == 5) val = 1; \ 1326 if (!s->quarter_sample && index1 == 5) val = 1; \
1352 else val = 0; \ 1327 else val = 0; \
1353 if(size_table[index1] - val > 0) \ 1328 if(size_table[index1] - val > 0) \
1354 val = get_bits(gb, size_table[index1] - val); \ 1329 val = get_bits(gb, size_table[index1] - val); \
1355 else val = 0; \ 1330 else val = 0; \
1356 sign = 0 - (val&1); \ 1331 sign = 0 - (val&1); \
1357 _dmv_y = (sign ^ ((val>>1) + offset_table[index1])) - sign; \ 1332 _dmv_y = (sign ^ ((val>>1) + offset_table[index1])) - sign; \
1366 int px, py; 1341 int px, py;
1367 int sum; 1342 int sum;
1368 int mb_pos = s->mb_x + s->mb_y * s->mb_stride; 1343 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
1369 1344
1370 /* scale MV difference to be quad-pel */ 1345 /* scale MV difference to be quad-pel */
1371 dmv_x <<= s->mspel; 1346 dmv_x <<= 1 - s->quarter_sample;
1372 dmv_y <<= s->mspel; 1347 dmv_y <<= 1 - s->quarter_sample;
1373 1348
1374 wrap = s->b8_stride; 1349 wrap = s->b8_stride;
1375 xy = s->block_index[0]; 1350 xy = s->block_index[0];
1376 1351
1377 C = s->current_picture.motion_val[0][xy - (1 << mv1)]; 1352 C = s->current_picture.motion_val[0][xy - (1 << mv1)];
1625 lst = index >= vc1_last_decode_table[codingset]; 1600 lst = index >= vc1_last_decode_table[codingset];
1626 if(get_bits(gb, 1)) 1601 if(get_bits(gb, 1))
1627 level = -level; 1602 level = -level;
1628 } else { 1603 } else {
1629 escape = decode210(gb); 1604 escape = decode210(gb);
1630 if (escape == 0) { 1605 if (escape != 2) {
1631 index = get_vlc2(gb, vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3); 1606 index = get_vlc2(gb, vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3);
1632 run = vc1_index_decode_table[codingset][index][0]; 1607 run = vc1_index_decode_table[codingset][index][0];
1633 level = vc1_index_decode_table[codingset][index][1]; 1608 level = vc1_index_decode_table[codingset][index][1];
1634 lst = index >= vc1_last_decode_table[codingset]; 1609 lst = index >= vc1_last_decode_table[codingset];
1635 if(lst) 1610 if(escape == 0) {
1636 level += vc1_last_delta_level_table[codingset][run]; 1611 if(lst)
1637 else 1612 level += vc1_last_delta_level_table[codingset][run];
1638 level += vc1_delta_level_table[codingset][run]; 1613 else
1639 if(get_bits(gb, 1)) 1614 level += vc1_delta_level_table[codingset][run];
1640 level = -level; 1615 } else {
1641 } else if (escape == 1) { 1616 if(lst)
1642 index = get_vlc2(gb, vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3); 1617 run += vc1_last_delta_run_table[codingset][level] + 1;
1643 run = vc1_index_decode_table[codingset][index][0]; 1618 else
1644 level = vc1_index_decode_table[codingset][index][1]; 1619 run += vc1_delta_run_table[codingset][level] + 1;
1645 lst = index >= vc1_last_decode_table[codingset]; 1620 }
1646 if(lst)
1647 run += vc1_last_delta_run_table[codingset][level] + 1;
1648 else
1649 run += vc1_delta_run_table[codingset][level] + 1;
1650 if(get_bits(gb, 1)) 1621 if(get_bits(gb, 1))
1651 level = -level; 1622 level = -level;
1652 } else { 1623 } else {
1653 int sign; 1624 int sign;
1654 lst = get_bits(gb, 1); 1625 lst = get_bits(gb, 1);
1942 break; 1913 break;
1943 block[zz_table[i++]] = value; 1914 block[zz_table[i++]] = value;
1944 } 1915 }
1945 1916
1946 /* apply AC prediction if needed */ 1917 /* apply AC prediction if needed */
1947 if(s->ac_pred) { 1918 if(s->ac_pred && (v->a_avail || v->c_avail)) {
1948 /* scale predictors if needed*/ 1919 /* scale predictors if needed*/
1949 int mb_pos2, q1, q2; 1920 int mb_pos2, q1, q2;
1950 1921
1951 mb_pos2 = mb_pos - dc_pred_dir - (1 - dc_pred_dir) * s->mb_stride; 1922 mb_pos2 = mb_pos - dc_pred_dir - (1 - dc_pred_dir) * s->mb_stride;
1952 q1 = s->current_picture.qscale_table[mb_pos]; 1923 q1 = s->current_picture.qscale_table[mb_pos];
1958 } 1929 }
1959 if(!a_avail) { 1930 if(!a_avail) {
1960 memset(ac_val + 8, 0, 8 * sizeof(ac_val[0])); 1931 memset(ac_val + 8, 0, 8 * sizeof(ac_val[0]));
1961 dc_pred_dir = 1; 1932 dc_pred_dir = 1;
1962 } 1933 }
1963 if(!q1 && q1 && q2 && q1 != q2) { 1934 if(q2 && q1 != q2) {
1964 q1 = q1 * 2 - 1; 1935 q1 = q1 * 2 - 1;
1965 q2 = q2 * 2 - 1; 1936 q2 = q2 * 2 - 1;
1966 1937
1967 if(dc_pred_dir) { //left 1938 if(dc_pred_dir) { //left
1968 for(k = 1; k < 8; k++) 1939 for(k = 1; k < 8; k++)
2015 1986
2016 scale = mquant * 2; 1987 scale = mquant * 2;
2017 memset(ac_val2, 0, 16 * 2); 1988 memset(ac_val2, 0, 16 * 2);
2018 if(dc_pred_dir) {//left 1989 if(dc_pred_dir) {//left
2019 ac_val -= 16; 1990 ac_val -= 16;
2020 if(s->ac_pred) 1991 if(s->ac_pred && (v->a_avail || v->c_avail))
2021 memcpy(ac_val2, ac_val, 8 * 2); 1992 memcpy(ac_val2, ac_val, 8 * 2);
2022 } else {//top 1993 } else {//top
2023 ac_val -= 16 * s->block_wrap[n]; 1994 ac_val -= 16 * s->block_wrap[n];
2024 if(s->ac_pred) 1995 if(s->ac_pred && (v->a_avail || v->c_avail))
2025 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2); 1996 memcpy(ac_val2 + 8, ac_val + 8, 8 * 2);
2026 } 1997 }
2027 1998
2028 /* apply AC prediction if needed */ 1999 /* apply AC prediction if needed */
2029 if(s->ac_pred) { 2000 if(s->ac_pred && (v->a_avail || v->c_avail)) {
2030 if(dc_pred_dir) { //left 2001 if(dc_pred_dir) { //left
2031 for(k = 1; k < 8; k++) { 2002 for(k = 1; k < 8; k++) {
2032 block[k << 3] = ac_val[k] * scale; 2003 block[k << 3] = ac_val[k] * scale;
2033 if(!v->pquantizer) 2004 if(!v->pquantizer)
2034 block[k << 3] += (block[k << 3] < 0) ? -mquant : mquant; 2005 block[k << 3] += (block[k << 3] < 0) ? -mquant : mquant;
2080 } 2051 }
2081 if(ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) { 2052 if(ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) {
2082 ttblk = TT_4X8; 2053 ttblk = TT_4X8;
2083 subblkpat = 2 - (ttblk == TT_4X8_LEFT); 2054 subblkpat = 2 - (ttblk == TT_4X8_LEFT);
2084 } 2055 }
2085
2086 switch(ttblk) { 2056 switch(ttblk) {
2087 case TT_8X8: 2057 case TT_8X8:
2088 i = 0; 2058 i = 0;
2089 last = 0; 2059 last = 0;
2090 while (!last) { 2060 while (!last) {
2099 break; 2069 break;
2100 case TT_4X4: 2070 case TT_4X4:
2101 for(j = 0; j < 4; j++) { 2071 for(j = 0; j < 4; j++) {
2102 last = subblkpat & (1 << (3 - j)); 2072 last = subblkpat & (1 << (3 - j));
2103 i = 0; 2073 i = 0;
2104 off = (j & 1) * 4 + (j & 2) * 32; 2074 off = (j & 1) * 4 + (j & 2) * 16;
2105 while (!last) { 2075 while (!last) {
2106 vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2); 2076 vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2);
2107 i += skip; 2077 i += skip;
2108 if(i > 15) 2078 if(i > 15)
2109 break; 2079 break;
2110 idx = vc1_simple_progressive_4x4_zz[i++]; 2080 idx = vc1_simple_progressive_4x4_zz[i++];
2111 block[idx + off] = value * scale; 2081 block[idx + off] = value * scale;
2112 } 2082 }
2113 vc1_inv_trans(block + off, 4, 4); 2083 if(!(subblkpat & (1 << (3 - j))))
2084 vc1_inv_trans(block + off, 4, 4);
2114 } 2085 }
2115 break; 2086 break;
2116 case TT_8X4: 2087 case TT_8X4:
2117 for(j = 0; j < 2; j++) { 2088 for(j = 0; j < 2; j++) {
2118 last = subblkpat & (1 << (1 - j)); 2089 last = subblkpat & (1 << (1 - j));
2124 if(i > 31) 2095 if(i > 31)
2125 break; 2096 break;
2126 idx = vc1_simple_progressive_8x4_zz[i++]; 2097 idx = vc1_simple_progressive_8x4_zz[i++];
2127 block[idx + off] = value * scale; 2098 block[idx + off] = value * scale;
2128 } 2099 }
2129 if(!(subblkpat & (1 << (1 - j)))) vc1_inv_trans(block + off, 8, 4); 2100 if(!(subblkpat & (1 << (1 - j))))
2101 vc1_inv_trans(block + off, 8, 4);
2130 } 2102 }
2131 break; 2103 break;
2132 case TT_4X8: 2104 case TT_4X8:
2133 for(j = 0; j < 2; j++) { 2105 for(j = 0; j < 2; j++) {
2134 last = subblkpat & (1 << (1 - j)); 2106 last = subblkpat & (1 << (1 - j));
2140 if(i > 31) 2112 if(i > 31)
2141 break; 2113 break;
2142 idx = vc1_simple_progressive_8x4_zz[i++]; 2114 idx = vc1_simple_progressive_8x4_zz[i++];
2143 block[idx + off] = value * scale; 2115 block[idx + off] = value * scale;
2144 } 2116 }
2145 vc1_inv_trans(block + off, 4, 8); 2117 if(!(subblkpat & (1 << (1 - j))))
2118 vc1_inv_trans(block + off, 4, 8);
2146 } 2119 }
2147 break; 2120 break;
2148 } 2121 }
2149 return 0; 2122 return 0;
2150 } 2123 }
2156 */ 2129 */
2157 static int vc1_decode_p_mb(VC1Context *v, DCTELEM block[6][64]) 2130 static int vc1_decode_p_mb(VC1Context *v, DCTELEM block[6][64])
2158 { 2131 {
2159 MpegEncContext *s = &v->s; 2132 MpegEncContext *s = &v->s;
2160 GetBitContext *gb = &s->gb; 2133 GetBitContext *gb = &s->gb;
2161 int i, j, mb_offset = s->mb_x + s->mb_y*s->mb_width; /* XXX: mb_stride */ 2134 int i, j;
2162 int mb_pos = s->mb_x + s->mb_y * s->mb_stride; 2135 int mb_pos = s->mb_x + s->mb_y * s->mb_stride;
2163 int cbp; /* cbp decoding stuff */ 2136 int cbp; /* cbp decoding stuff */
2164 int hybrid_pred; /* Prediction types */ 2137 int hybrid_pred; /* Prediction types */
2165 int mqdiff, mquant; /* MB quantization */ 2138 int mqdiff, mquant; /* MB quantization */
2166 int ttmb = v->ttmb; /* MB Transform type */ 2139 int ttmb = v->ttmb; /* MB Transform type */
2172 int dmv_x, dmv_y; /* Differential MV components */ 2145 int dmv_x, dmv_y; /* Differential MV components */
2173 int index, index1; /* LUT indices */ 2146 int index, index1; /* LUT indices */
2174 int val, sign; /* temp values */ 2147 int val, sign; /* temp values */
2175 int first_block = 1; 2148 int first_block = 1;
2176 int dst_idx, off; 2149 int dst_idx, off;
2150 int skipped, fourmv;
2177 2151
2178 mquant = v->pq; /* Loosy initialization */ 2152 mquant = v->pq; /* Loosy initialization */
2179 2153
2180 if (v->mv_type_mb_plane.is_raw) 2154 if (v->mv_type_is_raw)
2181 v->mv_type_mb_plane.data[mb_offset] = get_bits(gb, 1); 2155 fourmv = get_bits1(gb);
2182 if (v->skip_mb_plane.is_raw) 2156 else
2183 v->skip_mb_plane.data[mb_offset] = get_bits(gb, 1); 2157 fourmv = v->mv_type_mb_plane[mb_pos];
2184 s->current_picture.mbskip_table[mb_pos] = v->skip_mb_plane.data[mb_offset]; 2158 if (v->skip_is_raw)
2185 if (!v->mv_type_mb_plane.data[mb_offset]) /* 1MV mode */ 2159 skipped = get_bits1(gb);
2160 else
2161 skipped = v->skip_mb_plane[mb_pos];
2162
2163 if (!fourmv) /* 1MV mode */
2186 { 2164 {
2187 if (!v->skip_mb_plane.data[mb_offset]) 2165 if (!skipped)
2188 { 2166 {
2189 GET_MVDATA(dmv_x, dmv_y); 2167 GET_MVDATA(dmv_x, dmv_y);
2190 2168
2191 s->current_picture.mb_type[mb_pos] = s->mb_intra ? MB_TYPE_INTRA : MB_TYPE_16x16; 2169 s->current_picture.mb_type[mb_pos] = s->mb_intra ? MB_TYPE_INTRA : MB_TYPE_16x16;
2192 vc1_pred_mv(s, dmv_x, dmv_y, 1, v->range_x, v->range_y); 2170 vc1_pred_mv(s, dmv_x, dmv_y, 1, v->range_x, v->range_y);
2230 v->a_avail = 1; 2208 v->a_avail = 1;
2231 if((i == 1 || i == 3) || (s->mb_x && IS_INTRA(s->current_picture.mb_type[mb_pos - 1]))) 2209 if((i == 1 || i == 3) || (s->mb_x && IS_INTRA(s->current_picture.mb_type[mb_pos - 1])))
2232 v->c_avail = 1; 2210 v->c_avail = 1;
2233 2211
2234 vc1_decode_intra_block(v, block[i], i, val, mquant, (i&4)?v->codingset2:v->codingset); 2212 vc1_decode_intra_block(v, block[i], i, val, mquant, (i&4)?v->codingset2:v->codingset);
2235 vc1_inv_trans(s->block[i], 8, 8); 2213 vc1_inv_trans(block[i], 8, 8);
2236 for(j = 0; j < 64; j++) s->block[i][j] += 128; 2214 for(j = 0; j < 64; j++) block[i][j] += 128;
2237 s->dsp.put_pixels_clamped(s->block[i], s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2)); 2215 s->dsp.put_pixels_clamped(block[i], s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2));
2238 /* TODO: proper loop filtering */ 2216 /* TODO: proper loop filtering */
2239 if(v->a_avail) 2217 if(v->pq >= 9 && v->overlap) {
2240 s->dsp.h263_v_loop_filter(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2), s->y_dc_scale); 2218 if(v->a_avail)
2241 if(v->c_avail) 2219 s->dsp.h263_v_loop_filter(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2), s->y_dc_scale);
2242 s->dsp.h263_h_loop_filter(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2), s->y_dc_scale); 2220 if(v->c_avail)
2221 s->dsp.h263_h_loop_filter(s->dest[dst_idx] + off, s->linesize >> ((i & 4) >> 2), s->y_dc_scale);
2222 }
2243 } else if(val) { 2223 } else if(val) {
2244 vc1_decode_p_block(v, block[i], i, mquant, ttmb, first_block); 2224 vc1_decode_p_block(v, block[i], i, mquant, ttmb, first_block);
2245 if(!v->ttmbf && ttmb < 8) ttmb = -1; 2225 if(!v->ttmbf && ttmb < 8) ttmb = -1;
2246 first_block = 0; 2226 first_block = 0;
2247 s->dsp.add_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize); 2227 s->dsp.add_pixels_clamped(block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize);
2248 } 2228 }
2249 } 2229 }
2250 } 2230 }
2251 else //Skipped 2231 else //Skipped
2252 { 2232 {
2257 return 0; 2237 return 0;
2258 } 2238 }
2259 } //1MV mode 2239 } //1MV mode
2260 else //4MV mode 2240 else //4MV mode
2261 {//FIXME: looks not conforming to standard and is not even theoretically complete 2241 {//FIXME: looks not conforming to standard and is not even theoretically complete
2262 if (!v->skip_mb_plane.data[mb_offset] /* unskipped MB */) 2242 if (!skipped /* unskipped MB */)
2263 { 2243 {
2264 int blk_intra[4], blk_coded[4]; 2244 int blk_intra[4], blk_coded[4];
2265 /* Get CBPCY */ 2245 /* Get CBPCY */
2266 cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2); 2246 cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2);
2267 for (i=0; i<4; i++) 2247 for (i=0; i<4; i++)
2493 GetBitContext gb; 2473 GetBitContext gb;
2494 2474
2495 if (!avctx->extradata_size || !avctx->extradata) return -1; 2475 if (!avctx->extradata_size || !avctx->extradata) return -1;
2496 avctx->pix_fmt = PIX_FMT_YUV420P; 2476 avctx->pix_fmt = PIX_FMT_YUV420P;
2497 v->s.avctx = avctx; 2477 v->s.avctx = avctx;
2478 avctx->flags |= CODEC_FLAG_EMU_EDGE;
2479 v->s.flags |= CODEC_FLAG_EMU_EDGE;
2498 2480
2499 if(ff_h263_decode_init(avctx) < 0) 2481 if(ff_h263_decode_init(avctx) < 0)
2500 return -1; 2482 return -1;
2501 if (vc1_init_common(v) < 0) return -1; 2483 if (vc1_init_common(v) < 0) return -1;
2502 2484
2503 av_log(avctx, AV_LOG_INFO, "This decoder is not supposed to produce picture. Dont report this as a bug!\n"); 2485 av_log(avctx, AV_LOG_INFO, "This decoder is not supposed to produce picture. Dont report this as a bug!\n");
2504 av_log(avctx, AV_LOG_INFO, "If you see a picture, don't believe your eyes.\n"); 2486 av_log(avctx, AV_LOG_INFO, "If you see a picture, don't believe your eyes.\n");
2505 2487
2506 avctx->flags |= CODEC_FLAG_EMU_EDGE;
2507 avctx->coded_width = avctx->width; 2488 avctx->coded_width = avctx->width;
2508 avctx->coded_height = avctx->height; 2489 avctx->coded_height = avctx->height;
2509 if (avctx->codec_id == CODEC_ID_WMV3) 2490 if (avctx->codec_id == CODEC_ID_WMV3)
2510 { 2491 {
2511 int count = 0; 2492 int count = 0;
2535 2516
2536 s->mb_width = (avctx->coded_width+15)>>4; 2517 s->mb_width = (avctx->coded_width+15)>>4;
2537 s->mb_height = (avctx->coded_height+15)>>4; 2518 s->mb_height = (avctx->coded_height+15)>>4;
2538 2519
2539 /* Allocate mb bitplanes */ 2520 /* Allocate mb bitplanes */
2540 if (alloc_bitplane(&v->mv_type_mb_plane, s->mb_width, s->mb_height) < 0) 2521 v->mv_type_mb_plane = av_malloc(s->mb_stride * s->mb_height);
2541 return -1; 2522 v->skip_mb_plane = av_malloc(s->mb_stride * s->mb_height);
2542 if (alloc_bitplane(&v->mv_type_mb_plane, s->mb_width, s->mb_height) < 0)
2543 return -1;
2544 if (alloc_bitplane(&v->skip_mb_plane, s->mb_width, s->mb_height) < 0)
2545 return -1;
2546 if (alloc_bitplane(&v->direct_mb_plane, s->mb_width, s->mb_height) < 0)
2547 return -1;
2548 2523
2549 /* For predictors */ 2524 /* For predictors */
2550 v->previous_line_cbpcy = (uint8_t *)av_malloc(s->mb_stride*4); 2525 v->previous_line_cbpcy = (uint8_t *)av_malloc(s->mb_stride*4);
2551 if (!v->previous_line_cbpcy) return -1; 2526 if (!v->previous_line_cbpcy) return -1;
2552 2527
2553 /* Init coded blocks info */ 2528 /* Init coded blocks info */
2554 if (v->profile == PROFILE_ADVANCED) 2529 if (v->profile == PROFILE_ADVANCED)
2555 { 2530 {
2556 if (alloc_bitplane(&v->over_flags_plane, s->mb_width, s->mb_height) < 0) 2531 // if (alloc_bitplane(&v->over_flags_plane, s->mb_width, s->mb_height) < 0)
2557 return -1; 2532 // return -1;
2558 if (alloc_bitplane(&v->ac_pred_plane, s->mb_width, s->mb_height) < 0) 2533 // if (alloc_bitplane(&v->ac_pred_plane, s->mb_width, s->mb_height) < 0)
2559 return -1; 2534 // return -1;
2560 } 2535 }
2561 2536
2562 return 0; 2537 return 0;
2563 } 2538 }
2564 2539
2668 VC1Context *v = avctx->priv_data; 2643 VC1Context *v = avctx->priv_data;
2669 2644
2670 av_freep(&v->hrd_rate); 2645 av_freep(&v->hrd_rate);
2671 av_freep(&v->hrd_buffer); 2646 av_freep(&v->hrd_buffer);
2672 MPV_common_end(&v->s); 2647 MPV_common_end(&v->s);
2673 free_bitplane(&v->mv_type_mb_plane); 2648 av_freep(&v->mv_type_mb_plane);
2674 free_bitplane(&v->skip_mb_plane); 2649 av_freep(&v->skip_mb_plane);
2675 free_bitplane(&v->direct_mb_plane);
2676 return 0; 2650 return 0;
2677 } 2651 }
2678 2652
2679 2653
2680 AVCodec vc1_decoder = { 2654 AVCodec vc1_decoder = {