~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavcodec/motion_est_template.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:
44
44
    COPY3_IF_LT(dmin, d, bx, hx, by, hy)\
45
45
}
46
46
 
47
 
#if 0
48
 
static int hpel_motion_search)(MpegEncContext * s,
49
 
                                  int *mx_ptr, int *my_ptr, int dmin,
50
 
                                  uint8_t *ref_data[3],
51
 
                                  int size)
52
 
{
53
 
    const int xx = 16 * s->mb_x + 8*(n&1);
54
 
    const int yy = 16 * s->mb_y + 8*(n>>1);
55
 
    const int mx = *mx_ptr;
56
 
    const int my = *my_ptr;
57
 
    const int penalty_factor= c->sub_penalty_factor;
58
 
 
59
 
    LOAD_COMMON
60
 
 
61
 
 //   INIT;
62
 
 //FIXME factorize
63
 
    me_cmp_func cmp, chroma_cmp, cmp_sub, chroma_cmp_sub;
64
 
 
65
 
    if(s->no_rounding /*FIXME b_type*/){
66
 
        hpel_put= &s->dsp.put_no_rnd_pixels_tab[size];
67
 
        chroma_hpel_put= &s->dsp.put_no_rnd_pixels_tab[size+1];
68
 
    }else{
69
 
        hpel_put=& s->dsp.put_pixels_tab[size];
70
 
        chroma_hpel_put= &s->dsp.put_pixels_tab[size+1];
71
 
    }
72
 
    cmpf= s->dsp.me_cmp[size];
73
 
    chroma_cmpf= s->dsp.me_cmp[size+1];
74
 
    cmp_sub= s->dsp.me_sub_cmp[size];
75
 
    chroma_cmp_sub= s->dsp.me_sub_cmp[size+1];
76
 
 
77
 
    if(c->skip){ //FIXME somehow move up (benchmark)
78
 
        *mx_ptr = 0;
79
 
        *my_ptr = 0;
80
 
        return dmin;
81
 
    }
82
 
 
83
 
    if(c->avctx->me_cmp != c->avctx->me_sub_cmp){
84
 
        CMP_HPEL(dmin, 0, 0, mx, my, size);
85
 
        if(mx || my)
86
 
            dmin += (mv_penalty[2*mx - pred_x] + mv_penalty[2*my - pred_y])*penalty_factor;
87
 
    }
88
 
 
89
 
    if (mx > xmin && mx < xmax &&
90
 
        my > ymin && my < ymax) {
91
 
        int bx=2*mx, by=2*my;
92
 
        int d= dmin;
93
 
 
94
 
        CHECK_HALF_MV(1, 1, mx-1, my-1)
95
 
        CHECK_HALF_MV(0, 1, mx  , my-1)
96
 
        CHECK_HALF_MV(1, 1, mx  , my-1)
97
 
        CHECK_HALF_MV(1, 0, mx-1, my  )
98
 
        CHECK_HALF_MV(1, 0, mx  , my  )
99
 
        CHECK_HALF_MV(1, 1, mx-1, my  )
100
 
        CHECK_HALF_MV(0, 1, mx  , my  )
101
 
        CHECK_HALF_MV(1, 1, mx  , my  )
102
 
 
103
 
        assert(bx >= xmin*2 || bx <= xmax*2 || by >= ymin*2 || by <= ymax*2);
104
 
 
105
 
        *mx_ptr = bx;
106
 
        *my_ptr = by;
107
 
    }else{
108
 
        *mx_ptr =2*mx;
109
 
        *my_ptr =2*my;
110
 
    }
111
 
 
112
 
    return dmin;
113
 
}
114
 
 
115
 
#else
116
47
static int hpel_motion_search(MpegEncContext * s,
117
48
                                  int *mx_ptr, int *my_ptr, int dmin,
118
49
                                  int src_index, int ref_index,
158
89
        const int b= score_map[(index+(1<<ME_MAP_SHIFT))&(ME_MAP_SIZE-1)]
159
90
                     + (mv_penalty[bx   - pred_x] + mv_penalty[by+2 - pred_y])*c->penalty_factor;
160
91
 
161
 
        int key;
162
 
        int map_generation= c->map_generation;
 
92
        unsigned key;
 
93
        unsigned map_generation= c->map_generation;
163
94
#ifndef NDEBUG
164
95
        uint32_t *map= c->map;
165
96
#endif
218
149
 
219
150
    return dmin;
220
151
}
221
 
#endif
222
152
 
223
153
static int no_sub_motion_search(MpegEncContext * s,
224
154
          int *mx_ptr, int *my_ptr, int dmin,
278
208
    const int mx = *mx_ptr;
279
209
    const int my = *my_ptr;
280
210
    const int penalty_factor= c->sub_penalty_factor;
281
 
    const int map_generation= c->map_generation;
 
211
    const unsigned map_generation = c->map_generation;
282
212
    const int subpel_quality= c->avctx->me_subpel_quality;
283
213
    uint32_t *map= c->map;
284
214
    me_cmp_func cmpf, chroma_cmpf;
321
251
        int best_pos[8][2];
322
252
 
323
253
        memset(best, 64, sizeof(int)*8);
324
 
#if 1
325
254
        if(s->me.dia_size>=2){
326
255
            const int tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
327
256
            const int bl= score_map[(index+(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
410
339
            CHECK_QUARTER_MV(nx&3, ny&3, nx>>2, ny>>2)
411
340
        }
412
341
 
413
 
#if 0
414
 
            const int tl= score_map[(index-(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
415
 
            const int bl= score_map[(index+(1<<ME_MAP_SHIFT)-1)&(ME_MAP_SIZE-1)];
416
 
            const int tr= score_map[(index-(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
417
 
            const int br= score_map[(index+(1<<ME_MAP_SHIFT)+1)&(ME_MAP_SIZE-1)];
418
 
//            if(l < r && l < t && l < b && l < tl && l < bl && l < tr && l < br && bl < tl){
419
 
            if(tl<br){
420
 
 
421
 
//            nx= FFMAX(4*mx - bx, bx - 4*mx);
422
 
//            ny= FFMAX(4*my - by, by - 4*my);
423
 
 
424
 
            static int stats[7][7], count;
425
 
            count++;
426
 
            stats[4*mx - bx + 3][4*my - by + 3]++;
427
 
            if(256*256*256*64 % count ==0){
428
 
                for(i=0; i<49; i++){
429
 
                    if((i%7)==0) printf("\n");
430
 
                    printf("%6d ", stats[0][i]);
431
 
                }
432
 
                printf("\n");
433
 
            }
434
 
            }
435
 
#endif
436
 
#else
437
 
 
438
 
        CHECK_QUARTER_MV(2, 2, mx-1, my-1)
439
 
        CHECK_QUARTER_MV(0, 2, mx  , my-1)
440
 
        CHECK_QUARTER_MV(2, 2, mx  , my-1)
441
 
        CHECK_QUARTER_MV(2, 0, mx  , my  )
442
 
        CHECK_QUARTER_MV(2, 2, mx  , my  )
443
 
        CHECK_QUARTER_MV(0, 2, mx  , my  )
444
 
        CHECK_QUARTER_MV(2, 2, mx-1, my  )
445
 
        CHECK_QUARTER_MV(2, 0, mx-1, my  )
446
 
 
447
 
        nx= bx;
448
 
        ny= by;
449
 
 
450
 
        for(i=0; i<8; i++){
451
 
            int ox[8]= {0, 1, 1, 1, 0,-1,-1,-1};
452
 
            int oy[8]= {1, 1, 0,-1,-1,-1, 0, 1};
453
 
            CHECK_QUARTER_MV((nx + ox[i])&3, (ny + oy[i])&3, (nx + ox[i])>>2, (ny + oy[i])>>2)
454
 
        }
455
 
#endif
456
 
#if 0
457
 
        //outer ring
458
 
        CHECK_QUARTER_MV(1, 3, mx-1, my-1)
459
 
        CHECK_QUARTER_MV(1, 2, mx-1, my-1)
460
 
        CHECK_QUARTER_MV(1, 1, mx-1, my-1)
461
 
        CHECK_QUARTER_MV(2, 1, mx-1, my-1)
462
 
        CHECK_QUARTER_MV(3, 1, mx-1, my-1)
463
 
        CHECK_QUARTER_MV(0, 1, mx  , my-1)
464
 
        CHECK_QUARTER_MV(1, 1, mx  , my-1)
465
 
        CHECK_QUARTER_MV(2, 1, mx  , my-1)
466
 
        CHECK_QUARTER_MV(3, 1, mx  , my-1)
467
 
        CHECK_QUARTER_MV(3, 2, mx  , my-1)
468
 
        CHECK_QUARTER_MV(3, 3, mx  , my-1)
469
 
        CHECK_QUARTER_MV(3, 0, mx  , my  )
470
 
        CHECK_QUARTER_MV(3, 1, mx  , my  )
471
 
        CHECK_QUARTER_MV(3, 2, mx  , my  )
472
 
        CHECK_QUARTER_MV(3, 3, mx  , my  )
473
 
        CHECK_QUARTER_MV(2, 3, mx  , my  )
474
 
        CHECK_QUARTER_MV(1, 3, mx  , my  )
475
 
        CHECK_QUARTER_MV(0, 3, mx  , my  )
476
 
        CHECK_QUARTER_MV(3, 3, mx-1, my  )
477
 
        CHECK_QUARTER_MV(2, 3, mx-1, my  )
478
 
        CHECK_QUARTER_MV(1, 3, mx-1, my  )
479
 
        CHECK_QUARTER_MV(1, 2, mx-1, my  )
480
 
        CHECK_QUARTER_MV(1, 1, mx-1, my  )
481
 
        CHECK_QUARTER_MV(1, 0, mx-1, my  )
482
 
#endif
483
342
        assert(bx >= xmin*4 && bx <= xmax*4 && by >= ymin*4 && by <= ymax*4);
484
343
 
485
344
        *mx_ptr = bx;
495
354
 
496
355
#define CHECK_MV(x,y)\
497
356
{\
498
 
    const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
 
357
    const unsigned key = ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
499
358
    const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
500
359
    assert((x) >= xmin);\
501
360
    assert((x) <= xmax);\
523
382
 
524
383
#define CHECK_MV_DIR(x,y,new_dir)\
525
384
{\
526
 
    const int key= ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
 
385
    const unsigned key = ((y)<<ME_MAP_MV_BITS) + (x) + map_generation;\
527
386
    const int index= (((y)<<ME_MAP_SHIFT) + (x))&(ME_MAP_SIZE-1);\
528
387
/*printf("check_mv_dir %d %d %d\n", x, y, new_dir);*/\
529
388
    if(map[index]!=key){\
561
420
    int next_dir=-1;
562
421
    LOAD_COMMON
563
422
    LOAD_COMMON2
564
 
    int map_generation= c->map_generation;
 
423
    unsigned map_generation = c->map_generation;
565
424
 
566
425
    cmpf= s->dsp.me_cmp[size];
567
426
    chroma_cmpf= s->dsp.me_cmp[size+1];
568
427
 
569
428
    { /* ensure that the best point is in the MAP as h/qpel refinement needs it */
570
 
        const int key= (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;
 
429
        const unsigned key = (best[1]<<ME_MAP_MV_BITS) + best[0] + map_generation;
571
430
        const int index= ((best[1]<<ME_MAP_SHIFT) + best[0])&(ME_MAP_SIZE-1);
572
431
        if(map[index]!=key){ //this will be executed only very rarey
573
432
            score_map[index]= cmp(s, best[0], best[1], 0, 0, size, h, ref_index, src_index, cmpf, chroma_cmpf, flags);
603
462
    int dia_size;
604
463
    LOAD_COMMON
605
464
    LOAD_COMMON2
606
 
    int map_generation= c->map_generation;
 
465
    unsigned map_generation = c->map_generation;
607
466
 
608
467
    cmpf= s->dsp.me_cmp[size];
609
468
    chroma_cmpf= s->dsp.me_cmp[size+1];
644
503
    me_cmp_func cmpf, chroma_cmpf;
645
504
    LOAD_COMMON
646
505
    LOAD_COMMON2
647
 
    int map_generation= c->map_generation;
 
506
    unsigned map_generation = c->map_generation;
648
507
    int x,y,d;
649
508
    const int dec= dia_size & (dia_size-1);
650
509
 
678
537
    me_cmp_func cmpf, chroma_cmpf;
679
538
    LOAD_COMMON
680
539
    LOAD_COMMON2
681
 
    int map_generation= c->map_generation;
 
540
    unsigned map_generation = c->map_generation;
682
541
    int x,y,i,d;
683
542
    int dia_size= c->dia_size&0xFF;
684
543
    const int dec= dia_size & (dia_size-1);
716
575
    me_cmp_func cmpf, chroma_cmpf;
717
576
    LOAD_COMMON
718
577
    LOAD_COMMON2
719
 
    int map_generation= c->map_generation;
 
578
    unsigned map_generation = c->map_generation;
720
579
    int x,y,x2,y2, i, j, d;
721
580
    const int dia_size= c->dia_size&0xFE;
722
581
    static const int hex[16][2]={{-4,-2}, {-4,-1}, {-4, 0}, {-4, 1}, {-4, 2},
763
622
    me_cmp_func cmpf, chroma_cmpf;
764
623
    LOAD_COMMON
765
624
    LOAD_COMMON2
766
 
    int map_generation= c->map_generation;
 
625
    unsigned map_generation = c->map_generation;
767
626
    int x,y, d;
768
627
    const int dia_size= c->dia_size&0xFF;
769
628
 
792
651
 
793
652
#define SAB_CHECK_MV(ax,ay)\
794
653
{\
795
 
    const int key= ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\
 
654
    const unsigned key = ((ay)<<ME_MAP_MV_BITS) + (ax) + map_generation;\
796
655
    const int index= (((ay)<<ME_MAP_SHIFT) + (ax))&(ME_MAP_SIZE-1);\
797
656
/*printf("sab check %d %d\n", ax, ay);*/\
798
657
    if(map[index]!=key){\
831
690
    int i, j;
832
691
    LOAD_COMMON
833
692
    LOAD_COMMON2
834
 
    int map_generation= c->map_generation;
 
693
    unsigned map_generation = c->map_generation;
835
694
 
836
695
    cmpf= s->dsp.me_cmp[size];
837
696
    chroma_cmpf= s->dsp.me_cmp[size+1];
916
775
    int dia_size;
917
776
    LOAD_COMMON
918
777
    LOAD_COMMON2
919
 
    int map_generation= c->map_generation;
 
778
    unsigned map_generation = c->map_generation;
920
779
 
921
780
    cmpf= s->dsp.me_cmp[size];
922
781
    chroma_cmpf= s->dsp.me_cmp[size+1];
990
849
        return   var_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags);
991
850
}
992
851
 
993
 
/*!
994
 
   \param P[10][2] a list of candidate mvs to check before starting the
 
852
/**
 
853
   @param P a list of candidate mvs to check before starting the
995
854
   iterative search. If one of the candidates is close to the optimal mv, then
996
855
   it takes fewer iterations. And it increases the chance that we find the
997
856
   optimal mv.
1001
860
                             int ref_mv_scale, int flags, int size, int h)
1002
861
{
1003
862
    MotionEstContext * const c= &s->me;
1004
 
    int best[2]={0, 0};      /*!< x and y coordinates of the best motion vector.
 
863
    int best[2]={0, 0};      /**< x and y coordinates of the best motion vector.
1005
864
                               i.e. the difference between the position of the
1006
865
                               block currently being encoded and the position of
1007
866
                               the block chosen to predict it from. */
1008
867
    int d;                   ///< the score (cmp + penalty) of any given mv
1009
 
    int dmin;                /*!< the best value of d, i.e. the score
 
868
    int dmin;                /**< the best value of d, i.e. the score
1010
869
                               corresponding to the mv stored in best[]. */
1011
 
    int map_generation;
 
870
    unsigned map_generation;
1012
871
    int penalty_factor;
1013
872
    const int ref_mv_stride= s->mb_stride; //pass as arg  FIXME
1014
873
    const int ref_mv_xy= s->mb_x + s->mb_y*ref_mv_stride; //add to last_mv beforepassing FIXME
1136
995
    MotionEstContext * const c= &s->me;
1137
996
    int best[2]={0, 0};
1138
997
    int d, dmin;
1139
 
    int map_generation;
 
998
    unsigned map_generation;
1140
999
    const int penalty_factor= c->penalty_factor;
1141
1000
    const int size=1;
1142
1001
    const int h=8;
1196
1055
    MotionEstContext * const c= &s->me;
1197
1056
    int best[2]={0, 0};
1198
1057
    int d, dmin;
1199
 
    int map_generation;
 
1058
    unsigned map_generation;
1200
1059
    const int penalty_factor= c->penalty_factor;
1201
1060
    const int size=0; //FIXME pass as arg
1202
1061
    const int h=8;