~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavcodec/motion_est.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-01-12 22:23:28 UTC
  • mfrom: (0.4.7 sid)
  • mto: This revision was merged to the branch mainline in revision 76.
  • Revision ID: package-import@ubuntu.com-20120112222328-8jqdyodym3p84ygu
Tags: 2:1.0~rc4.dfsg1+svn34540-1
* New upstream snapshot
* upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
52
52
                                  int src_index, int ref_index,
53
53
                                  int size, int h);
54
54
 
55
 
static inline int update_map_generation(MotionEstContext *c)
 
55
static inline unsigned update_map_generation(MotionEstContext *c)
56
56
{
57
57
    c->map_generation+= 1<<(ME_MAP_MV_BITS*2);
58
58
    if(c->map_generation==0){
248
248
    }
249
249
}
250
250
 
251
 
/*! \brief compares a block (either a full macroblock or a partition thereof)
 
251
/** @brief compares a block (either a full macroblock or a partition thereof)
252
252
    against a proposed motion-compensated prediction of that block
253
253
 */
254
254
static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby,
374
374
    return 0;
375
375
}
376
376
 
377
 
#if 0
378
 
static int pix_dev(uint8_t * pix, int line_size, int mean)
379
 
{
380
 
    int s, i, j;
381
 
 
382
 
    s = 0;
383
 
    for (i = 0; i < 16; i++) {
384
 
        for (j = 0; j < 16; j += 8) {
385
 
            s += FFABS(pix[0]-mean);
386
 
            s += FFABS(pix[1]-mean);
387
 
            s += FFABS(pix[2]-mean);
388
 
            s += FFABS(pix[3]-mean);
389
 
            s += FFABS(pix[4]-mean);
390
 
            s += FFABS(pix[5]-mean);
391
 
            s += FFABS(pix[6]-mean);
392
 
            s += FFABS(pix[7]-mean);
393
 
            pix += 8;
394
 
        }
395
 
        pix += line_size - 16;
396
 
    }
397
 
    return s;
398
 
}
399
 
#endif
400
 
 
401
377
static inline void no_motion_search(MpegEncContext * s,
402
378
                                    int *mx_ptr, int *my_ptr)
403
379
{
533
509
    if(mv4){
534
510
        int mot_xy= s->block_index[0];
535
511
 
536
 
        s->current_picture.motion_val[0][mot_xy  ][0]= mx;
537
 
        s->current_picture.motion_val[0][mot_xy  ][1]= my;
538
 
        s->current_picture.motion_val[0][mot_xy+1][0]= mx;
539
 
        s->current_picture.motion_val[0][mot_xy+1][1]= my;
 
512
        s->current_picture.f.motion_val[0][mot_xy    ][0] = mx;
 
513
        s->current_picture.f.motion_val[0][mot_xy    ][1] = my;
 
514
        s->current_picture.f.motion_val[0][mot_xy + 1][0] = mx;
 
515
        s->current_picture.f.motion_val[0][mot_xy + 1][1] = my;
540
516
 
541
517
        mot_xy += s->b8_stride;
542
 
        s->current_picture.motion_val[0][mot_xy  ][0]= mx;
543
 
        s->current_picture.motion_val[0][mot_xy  ][1]= my;
544
 
        s->current_picture.motion_val[0][mot_xy+1][0]= mx;
545
 
        s->current_picture.motion_val[0][mot_xy+1][1]= my;
 
518
        s->current_picture.f.motion_val[0][mot_xy    ][0] = mx;
 
519
        s->current_picture.f.motion_val[0][mot_xy    ][1] = my;
 
520
        s->current_picture.f.motion_val[0][mot_xy + 1][0] = mx;
 
521
        s->current_picture.f.motion_val[0][mot_xy + 1][1] = my;
546
522
    }
547
523
}
548
524
 
615
591
        const int mot_stride = s->b8_stride;
616
592
        const int mot_xy = s->block_index[block];
617
593
 
618
 
        P_LEFT[0] = s->current_picture.motion_val[0][mot_xy - 1][0];
619
 
        P_LEFT[1] = s->current_picture.motion_val[0][mot_xy - 1][1];
 
594
        P_LEFT[0] = s->current_picture.f.motion_val[0][mot_xy - 1][0];
 
595
        P_LEFT[1] = s->current_picture.f.motion_val[0][mot_xy - 1][1];
620
596
 
621
597
        if(P_LEFT[0]       > (c->xmax<<shift)) P_LEFT[0]       = (c->xmax<<shift);
622
598
 
625
601
            c->pred_x= pred_x4= P_LEFT[0];
626
602
            c->pred_y= pred_y4= P_LEFT[1];
627
603
        } else {
628
 
            P_TOP[0]      = s->current_picture.motion_val[0][mot_xy - mot_stride             ][0];
629
 
            P_TOP[1]      = s->current_picture.motion_val[0][mot_xy - mot_stride             ][1];
630
 
            P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][0];
631
 
            P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][1];
 
604
            P_TOP[0]      = s->current_picture.f.motion_val[0][mot_xy - mot_stride             ][0];
 
605
            P_TOP[1]      = s->current_picture.f.motion_val[0][mot_xy - mot_stride             ][1];
 
606
            P_TOPRIGHT[0] = s->current_picture.f.motion_val[0][mot_xy - mot_stride + off[block]][0];
 
607
            P_TOPRIGHT[1] = s->current_picture.f.motion_val[0][mot_xy - mot_stride + off[block]][1];
632
608
            if(P_TOP[1]      > (c->ymax<<shift)) P_TOP[1]     = (c->ymax<<shift);
633
609
            if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift);
634
610
            if(P_TOPRIGHT[0] > (c->xmax<<shift)) P_TOPRIGHT[0]= (c->xmax<<shift);
680
656
            my4_sum+= my4;
681
657
        }
682
658
 
683
 
        s->current_picture.motion_val[0][ s->block_index[block] ][0]= mx4;
684
 
        s->current_picture.motion_val[0][ s->block_index[block] ][1]= my4;
 
659
        s->current_picture.f.motion_val[0][s->block_index[block]][0] = mx4;
 
660
        s->current_picture.f.motion_val[0][s->block_index[block]][1] = my4;
685
661
 
686
662
        if(mx4 != mx || my4 != my) same=0;
687
663
    }
690
666
        return INT_MAX;
691
667
 
692
668
    if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){
693
 
        dmin_sum += s->dsp.mb_cmp[0](s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*16*stride, c->scratchpad, stride, 16);
 
669
        dmin_sum += s->dsp.mb_cmp[0](s, s->new_picture.f.data[0] + s->mb_x*16 + s->mb_y*16*stride, c->scratchpad, stride, 16);
694
670
    }
695
671
 
696
672
    if(c->avctx->mb_cmp&FF_CMP_CHROMA){
705
681
        offset= (s->mb_x*8 + (mx>>1)) + (s->mb_y*8 + (my>>1))*s->uvlinesize;
706
682
 
707
683
        if(s->no_rounding){
708
 
            s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad    , s->last_picture.data[1] + offset, s->uvlinesize, 8);
709
 
            s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad+8  , s->last_picture.data[2] + offset, s->uvlinesize, 8);
 
684
            s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad    , s->last_picture.f.data[1] + offset, s->uvlinesize, 8);
 
685
            s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad + 8, s->last_picture.f.data[2] + offset, s->uvlinesize, 8);
710
686
        }else{
711
 
            s->dsp.put_pixels_tab       [1][dxy](c->scratchpad    , s->last_picture.data[1] + offset, s->uvlinesize, 8);
712
 
            s->dsp.put_pixels_tab       [1][dxy](c->scratchpad+8  , s->last_picture.data[2] + offset, s->uvlinesize, 8);
 
687
            s->dsp.put_pixels_tab       [1][dxy](c->scratchpad    , s->last_picture.f.data[1] + offset, s->uvlinesize, 8);
 
688
            s->dsp.put_pixels_tab       [1][dxy](c->scratchpad + 8, s->last_picture.f.data[2] + offset, s->uvlinesize, 8);
713
689
        }
714
690
 
715
 
        dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad  , s->uvlinesize, 8);
716
 
        dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad+8, s->uvlinesize, 8);
 
691
        dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.f.data[1] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad  , s->uvlinesize, 8);
 
692
        dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.f.data[2] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad+8, s->uvlinesize, 8);
717
693
    }
718
694
 
719
695
    c->pred_x= mx;
879
855
    Picture *p= s->current_picture_ptr;
880
856
    int mb_xy= mb_x + mb_y*s->mb_stride;
881
857
    int xy= 2*mb_x + 2*mb_y*s->b8_stride;
882
 
    int mb_type= s->current_picture.mb_type[mb_xy];
 
858
    int mb_type= s->current_picture.f.mb_type[mb_xy];
883
859
    int flags= c->flags;
884
860
    int shift= (flags&FLAG_QPEL) + 1;
885
861
    int mask= (1<<shift)-1;
896
872
 
897
873
    for(i=0; i<4; i++){
898
874
        int xy= s->block_index[i];
899
 
        clip_input_mv(s, p->motion_val[0][xy], !!IS_INTERLACED(mb_type));
900
 
        clip_input_mv(s, p->motion_val[1][xy], !!IS_INTERLACED(mb_type));
 
875
        clip_input_mv(s, p->f.motion_val[0][xy], !!IS_INTERLACED(mb_type));
 
876
        clip_input_mv(s, p->f.motion_val[1][xy], !!IS_INTERLACED(mb_type));
901
877
    }
902
878
 
903
879
    if(IS_INTERLACED(mb_type)){
912
888
        }
913
889
 
914
890
        if(USES_LIST(mb_type, 0)){
915
 
            int field_select0= p->ref_index[0][4*mb_xy  ];
916
 
            int field_select1= p->ref_index[0][4*mb_xy+2];
 
891
            int field_select0= p->f.ref_index[0][4*mb_xy  ];
 
892
            int field_select1= p->f.ref_index[0][4*mb_xy+2];
917
893
            assert(field_select0==0 ||field_select0==1);
918
894
            assert(field_select1==0 ||field_select1==1);
919
895
            init_interlaced_ref(s, 0);
921
897
            if(p_type){
922
898
                s->p_field_select_table[0][mb_xy]= field_select0;
923
899
                s->p_field_select_table[1][mb_xy]= field_select1;
924
 
                *(uint32_t*)s->p_field_mv_table[0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[0][xy ];
925
 
                *(uint32_t*)s->p_field_mv_table[1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[0][xy2];
 
900
                *(uint32_t*)s->p_field_mv_table[0][field_select0][mb_xy] = *(uint32_t*)p->f.motion_val[0][xy ];
 
901
                *(uint32_t*)s->p_field_mv_table[1][field_select1][mb_xy] = *(uint32_t*)p->f.motion_val[0][xy2];
926
902
                s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER_I;
927
903
            }else{
928
904
                s->b_field_select_table[0][0][mb_xy]= field_select0;
929
905
                s->b_field_select_table[0][1][mb_xy]= field_select1;
930
 
                *(uint32_t*)s->b_field_mv_table[0][0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[0][xy ];
931
 
                *(uint32_t*)s->b_field_mv_table[0][1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[0][xy2];
 
906
                *(uint32_t*)s->b_field_mv_table[0][0][field_select0][mb_xy] = *(uint32_t*)p->f.motion_val[0][xy ];
 
907
                *(uint32_t*)s->b_field_mv_table[0][1][field_select1][mb_xy] = *(uint32_t*)p->f.motion_val[0][xy2];
932
908
                s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_FORWARD_I;
933
909
            }
934
910
 
935
 
            x= p->motion_val[0][xy ][0];
936
 
            y= p->motion_val[0][xy ][1];
 
911
            x = p->f.motion_val[0][xy ][0];
 
912
            y = p->f.motion_val[0][xy ][1];
937
913
            d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select0, 0, cmpf, chroma_cmpf, flags);
938
 
            x= p->motion_val[0][xy2][0];
939
 
            y= p->motion_val[0][xy2][1];
 
914
            x = p->f.motion_val[0][xy2][0];
 
915
            y = p->f.motion_val[0][xy2][1];
940
916
            d+= cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select1, 1, cmpf, chroma_cmpf, flags);
941
917
        }
942
918
        if(USES_LIST(mb_type, 1)){
943
 
            int field_select0= p->ref_index[1][4*mb_xy  ];
944
 
            int field_select1= p->ref_index[1][4*mb_xy+2];
 
919
            int field_select0 = p->f.ref_index[1][4 * mb_xy    ];
 
920
            int field_select1 = p->f.ref_index[1][4 * mb_xy + 2];
945
921
            assert(field_select0==0 ||field_select0==1);
946
922
            assert(field_select1==0 ||field_select1==1);
947
923
            init_interlaced_ref(s, 2);
948
924
 
949
925
            s->b_field_select_table[1][0][mb_xy]= field_select0;
950
926
            s->b_field_select_table[1][1][mb_xy]= field_select1;
951
 
            *(uint32_t*)s->b_field_mv_table[1][0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[1][xy ];
952
 
            *(uint32_t*)s->b_field_mv_table[1][1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[1][xy2];
 
927
            *(uint32_t*)s->b_field_mv_table[1][0][field_select0][mb_xy] = *(uint32_t*)p->f.motion_val[1][xy ];
 
928
            *(uint32_t*)s->b_field_mv_table[1][1][field_select1][mb_xy] = *(uint32_t*)p->f.motion_val[1][xy2];
953
929
            if(USES_LIST(mb_type, 0)){
954
930
                s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_BIDIR_I;
955
931
            }else{
956
932
                s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_BACKWARD_I;
957
933
            }
958
934
 
959
 
            x= p->motion_val[1][xy ][0];
960
 
            y= p->motion_val[1][xy ][1];
 
935
            x = p->f.motion_val[1][xy ][0];
 
936
            y = p->f.motion_val[1][xy ][1];
961
937
            d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select0+2, 0, cmpf, chroma_cmpf, flags);
962
 
            x= p->motion_val[1][xy2][0];
963
 
            y= p->motion_val[1][xy2][1];
 
938
            x = p->f.motion_val[1][xy2][0];
 
939
            y = p->f.motion_val[1][xy2][1];
964
940
            d+= cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select1+2, 1, cmpf, chroma_cmpf, flags);
965
941
            //FIXME bidir scores
966
942
        }
976
952
        init_mv4_ref(c);
977
953
        for(i=0; i<4; i++){
978
954
            xy= s->block_index[i];
979
 
            x= p->motion_val[0][xy][0];
980
 
            y= p->motion_val[0][xy][1];
 
955
            x= p->f.motion_val[0][xy][0];
 
956
            y= p->f.motion_val[0][xy][1];
981
957
            d+= cmp(s, x>>shift, y>>shift, x&mask, y&mask, 1, 8, i, i, cmpf, chroma_cmpf, flags);
982
958
        }
983
959
        s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER4V;
984
960
    }else{
985
961
        if(USES_LIST(mb_type, 0)){
986
962
            if(p_type){
987
 
                *(uint32_t*)s->p_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy];
 
963
                *(uint32_t*)s->p_mv_table[mb_xy] = *(uint32_t*)p->f.motion_val[0][xy];
988
964
                s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER;
989
965
            }else if(USES_LIST(mb_type, 1)){
990
 
                *(uint32_t*)s->b_bidir_forw_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy];
991
 
                *(uint32_t*)s->b_bidir_back_mv_table[mb_xy]= *(uint32_t*)p->motion_val[1][xy];
 
966
                *(uint32_t*)s->b_bidir_forw_mv_table[mb_xy] = *(uint32_t*)p->f.motion_val[0][xy];
 
967
                *(uint32_t*)s->b_bidir_back_mv_table[mb_xy] = *(uint32_t*)p->f.motion_val[1][xy];
992
968
                s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_BIDIR;
993
969
            }else{
994
 
                *(uint32_t*)s->b_forw_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy];
 
970
                *(uint32_t*)s->b_forw_mv_table[mb_xy] = *(uint32_t*)p->f.motion_val[0][xy];
995
971
                s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_FORWARD;
996
972
            }
997
 
            x= p->motion_val[0][xy][0];
998
 
            y= p->motion_val[0][xy][1];
 
973
            x = p->f.motion_val[0][xy][0];
 
974
            y = p->f.motion_val[0][xy][1];
999
975
            d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 16, 0, 0, cmpf, chroma_cmpf, flags);
1000
976
        }else if(USES_LIST(mb_type, 1)){
1001
 
            *(uint32_t*)s->b_back_mv_table[mb_xy]= *(uint32_t*)p->motion_val[1][xy];
 
977
            *(uint32_t*)s->b_back_mv_table[mb_xy] = *(uint32_t*)p->f.motion_val[1][xy];
1002
978
            s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_BACKWARD;
1003
979
 
1004
 
            x= p->motion_val[1][xy][0];
1005
 
            y= p->motion_val[1][xy][1];
 
980
            x = p->f.motion_val[1][xy][0];
 
981
            y = p->f.motion_val[1][xy][1];
1006
982
            d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 16, 2, 0, cmpf, chroma_cmpf, flags);
1007
983
        }else
1008
984
            s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTRA;
1023
999
    int mb_type=0;
1024
1000
    Picture * const pic= &s->current_picture;
1025
1001
 
1026
 
    init_ref(c, s->new_picture.data, s->last_picture.data, NULL, 16*mb_x, 16*mb_y, 0);
 
1002
    init_ref(c, s->new_picture.f.data, s->last_picture.f.data, NULL, 16*mb_x, 16*mb_y, 0);
1027
1003
 
1028
1004
    assert(s->quarter_sample==0 || s->quarter_sample==1);
1029
1005
    assert(s->linesize == c->stride);
1040
1016
    /* intra / predictive decision */
1041
1017
    pix = c->src[0][0];
1042
1018
    sum = s->dsp.pix_sum(pix, s->linesize);
1043
 
    varc = s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500;
 
1019
    varc = s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)sum*sum)>>8) + 500;
1044
1020
 
1045
1021
    pic->mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8;
1046
1022
    pic->mb_var [s->mb_stride * mb_y + mb_x] = (varc+128)>>8;
1075
1051
            const int mot_stride = s->b8_stride;
1076
1052
            const int mot_xy = s->block_index[0];
1077
1053
 
1078
 
            P_LEFT[0]       = s->current_picture.motion_val[0][mot_xy - 1][0];
1079
 
            P_LEFT[1]       = s->current_picture.motion_val[0][mot_xy - 1][1];
 
1054
            P_LEFT[0] = s->current_picture.f.motion_val[0][mot_xy - 1][0];
 
1055
            P_LEFT[1] = s->current_picture.f.motion_val[0][mot_xy - 1][1];
1080
1056
 
1081
1057
            if(P_LEFT[0]       > (c->xmax<<shift)) P_LEFT[0]       = (c->xmax<<shift);
1082
1058
 
1083
1059
            if(!s->first_slice_line) {
1084
 
                P_TOP[0]      = s->current_picture.motion_val[0][mot_xy - mot_stride    ][0];
1085
 
                P_TOP[1]      = s->current_picture.motion_val[0][mot_xy - mot_stride    ][1];
1086
 
                P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][0];
1087
 
                P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][1];
 
1060
                P_TOP[0]      = s->current_picture.f.motion_val[0][mot_xy - mot_stride    ][0];
 
1061
                P_TOP[1]      = s->current_picture.f.motion_val[0][mot_xy - mot_stride    ][1];
 
1062
                P_TOPRIGHT[0] = s->current_picture.f.motion_val[0][mot_xy - mot_stride + 2][0];
 
1063
                P_TOPRIGHT[1] = s->current_picture.f.motion_val[0][mot_xy - mot_stride + 2][1];
1088
1064
                if(P_TOP[1]      > (c->ymax<<shift)) P_TOP[1]     = (c->ymax<<shift);
1089
1065
                if(P_TOPRIGHT[0] < (c->xmin<<shift)) P_TOPRIGHT[0]= (c->xmin<<shift);
1090
1066
                if(P_TOPRIGHT[1] > (c->ymax<<shift)) P_TOPRIGHT[1]= (c->ymax<<shift);
1202
1178
        if((c->avctx->mb_cmp&0xFF)==FF_CMP_SSE){
1203
1179
            intra_score= varc - 500;
1204
1180
        }else{
1205
 
            int mean= (sum+128)>>8;
 
1181
            unsigned mean = (sum+128)>>8;
1206
1182
            mean*= 0x01010101;
1207
1183
 
1208
1184
            for(i=0; i<16; i++){
1214
1190
 
1215
1191
            intra_score= s->dsp.mb_cmp[0](s, c->scratchpad, pix, s->linesize, 16);
1216
1192
        }
1217
 
#if 0 //FIXME
1218
 
        /* get chroma score */
1219
 
        if(c->avctx->mb_cmp&FF_CMP_CHROMA){
1220
 
            for(i=1; i<3; i++){
1221
 
                uint8_t *dest_c;
1222
 
                int mean;
1223
 
 
1224
 
                if(s->out_format == FMT_H263){
1225
 
                    mean= (s->dc_val[i][mb_x + mb_y*s->b8_stride] + 4)>>3; //FIXME not exact but simple ;)
1226
 
                }else{
1227
 
                    mean= (s->last_dc[i] + 4)>>3;
1228
 
                }
1229
 
                dest_c = s->new_picture.data[i] + (mb_y * 8  * (s->uvlinesize)) + mb_x * 8;
1230
 
 
1231
 
                mean*= 0x01010101;
1232
 
                for(i=0; i<8; i++){
1233
 
                    *(uint32_t*)(&c->scratchpad[i*s->uvlinesize+ 0]) = mean;
1234
 
                    *(uint32_t*)(&c->scratchpad[i*s->uvlinesize+ 4]) = mean;
1235
 
                }
1236
 
 
1237
 
                intra_score+= s->dsp.mb_cmp[1](s, c->scratchpad, dest_c, s->uvlinesize);
1238
 
            }
1239
 
        }
1240
 
#endif
1241
1193
        intra_score += c->mb_penalty_factor*16;
1242
1194
 
1243
1195
        if(intra_score < dmin){
1244
1196
            mb_type= CANDIDATE_MB_TYPE_INTRA;
1245
 
            s->current_picture.mb_type[mb_y*s->mb_stride + mb_x]= CANDIDATE_MB_TYPE_INTRA; //FIXME cleanup
 
1197
            s->current_picture.f.mb_type[mb_y*s->mb_stride + mb_x] = CANDIDATE_MB_TYPE_INTRA; //FIXME cleanup
1246
1198
        }else
1247
 
            s->current_picture.mb_type[mb_y*s->mb_stride + mb_x]= 0;
 
1199
            s->current_picture.f.mb_type[mb_y*s->mb_stride + mb_x] = 0;
1248
1200
 
1249
1201
        {
1250
1202
            int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);
1264
1216
    int P[10][2];
1265
1217
    const int shift= 1+s->quarter_sample;
1266
1218
    const int xy= mb_x + mb_y*s->mb_stride;
1267
 
    init_ref(c, s->new_picture.data, s->last_picture.data, NULL, 16*mb_x, 16*mb_y, 0);
 
1219
    init_ref(c, s->new_picture.f.data, s->last_picture.f.data, NULL, 16*mb_x, 16*mb_y, 0);
1268
1220
 
1269
1221
    assert(s->quarter_sample==0 || s->quarter_sample==1);
1270
1222
 
1615
1567
    ymin= xmin=(-32)>>shift;
1616
1568
    ymax= xmax=   31>>shift;
1617
1569
 
1618
 
    if(IS_8X8(s->next_picture.mb_type[mot_xy])){
 
1570
    if (IS_8X8(s->next_picture.f.mb_type[mot_xy])) {
1619
1571
        s->mv_type= MV_TYPE_8X8;
1620
1572
    }else{
1621
1573
        s->mv_type= MV_TYPE_16X16;
1625
1577
        int index= s->block_index[i];
1626
1578
        int min, max;
1627
1579
 
1628
 
        c->co_located_mv[i][0]= s->next_picture.motion_val[0][index][0];
1629
 
        c->co_located_mv[i][1]= s->next_picture.motion_val[0][index][1];
 
1580
        c->co_located_mv[i][0] = s->next_picture.f.motion_val[0][index][0];
 
1581
        c->co_located_mv[i][1] = s->next_picture.f.motion_val[0][index][1];
1630
1582
        c->direct_basis_mv[i][0]= c->co_located_mv[i][0]*time_pb/time_pp + ((i& 1)<<(shift+3));
1631
1583
        c->direct_basis_mv[i][1]= c->co_located_mv[i][1]*time_pb/time_pp + ((i>>1)<<(shift+3));
1632
1584
//        c->direct_basis_mv[1][i][0]= c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(shift+3);
1708
1660
    int fmin, bmin, dmin, fbmin, bimin, fimin;
1709
1661
    int type=0;
1710
1662
    const int xy = mb_y*s->mb_stride + mb_x;
1711
 
    init_ref(c, s->new_picture.data, s->last_picture.data, s->next_picture.data, 16*mb_x, 16*mb_y, 2);
 
1663
    init_ref(c, s->new_picture.f.data, s->last_picture.f.data,
 
1664
             s->next_picture.f.data, 16 * mb_x, 16 * mb_y, 2);
1712
1665
 
1713
1666
    get_limits(s, 16*mb_x, 16*mb_y);
1714
1667
 
1715
1668
    c->skip=0;
1716
1669
 
1717
 
    if(s->codec_id == CODEC_ID_MPEG4 && s->next_picture.mbskip_table[xy]){
 
1670
    if (s->codec_id == CODEC_ID_MPEG4 && s->next_picture.f.mbskip_table[xy]) {
1718
1671
        int score= direct_search(s, mb_x, mb_y); //FIXME just check 0,0
1719
1672
 
1720
1673
        score= ((unsigned)(score*score + 128*256))>>16;
1849
1802
        if(dmin>256*256*16) type&= ~CANDIDATE_MB_TYPE_DIRECT; //do not try direct mode if it is invalid for this MB
1850
1803
        if(s->codec_id == CODEC_ID_MPEG4 && type&CANDIDATE_MB_TYPE_DIRECT && s->flags&CODEC_FLAG_MV0 && *(uint32_t*)s->b_direct_mv_table[xy])
1851
1804
            type |= CANDIDATE_MB_TYPE_DIRECT0;
1852
 
#if 0
1853
 
        if(s->out_format == FMT_MPEG1)
1854
 
            type |= CANDIDATE_MB_TYPE_INTRA;
1855
 
#endif
1856
1805
    }
1857
1806
 
1858
1807
    s->mb_type[mb_y*s->mb_stride + mb_x]= type;
1947
1896
                    int block;
1948
1897
                    for(block=0; block<4; block++){
1949
1898
                        int off= (block& 1) + (block>>1)*wrap;
1950
 
                        int mx= s->current_picture.motion_val[0][ xy + off ][0];
1951
 
                        int my= s->current_picture.motion_val[0][ xy + off ][1];
 
1899
                        int mx = s->current_picture.f.motion_val[0][ xy + off ][0];
 
1900
                        int my = s->current_picture.f.motion_val[0][ xy + off ][1];
1952
1901
 
1953
1902
                        if(   mx >=range || mx <-range
1954
1903
                           || my >=range || my <-range){
1955
1904
                            s->mb_type[i] &= ~CANDIDATE_MB_TYPE_INTER4V;
1956
1905
                            s->mb_type[i] |= CANDIDATE_MB_TYPE_INTRA;
1957
 
                            s->current_picture.mb_type[i]= CANDIDATE_MB_TYPE_INTRA;
 
1906
                            s->current_picture.f.mb_type[i] = CANDIDATE_MB_TYPE_INTRA;
1958
1907
                        }
1959
1908
                    }
1960
1909
                }