534
510
int mot_xy= s->block_index[0];
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;
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;
625
601
c->pred_x= pred_x4= P_LEFT[0];
626
602
c->pred_y= pred_y4= P_LEFT[1];
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);
705
681
offset= (s->mb_x*8 + (mx>>1)) + (s->mb_y*8 + (my>>1))*s->uvlinesize;
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);
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);
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);
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;
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;
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);
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);
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;
956
932
s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_BACKWARD_I;
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
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);
983
959
s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER4V;
985
961
if(USES_LIST(mb_type, 0)){
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;
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;
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;
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);
1008
984
s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTRA;
1075
1051
const int mot_stride = s->b8_stride;
1076
1052
const int mot_xy = s->block_index[0];
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];
1081
1057
if(P_LEFT[0] > (c->xmax<<shift)) P_LEFT[0] = (c->xmax<<shift);
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);
1215
1191
intra_score= s->dsp.mb_cmp[0](s, c->scratchpad, pix, s->linesize, 16);
1218
/* get chroma score */
1219
if(c->avctx->mb_cmp&FF_CMP_CHROMA){
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 ;)
1227
mean= (s->last_dc[i] + 4)>>3;
1229
dest_c = s->new_picture.data[i] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8;
1233
*(uint32_t*)(&c->scratchpad[i*s->uvlinesize+ 0]) = mean;
1234
*(uint32_t*)(&c->scratchpad[i*s->uvlinesize+ 4]) = mean;
1237
intra_score+= s->dsp.mb_cmp[1](s, c->scratchpad, dest_c, s->uvlinesize);
1241
1193
intra_score += c->mb_penalty_factor*16;
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
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;
1250
1202
int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100);
1708
1660
int fmin, bmin, dmin, fbmin, bimin, fimin;
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);
1713
1666
get_limits(s, 16*mb_x, 16*mb_y);
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
1720
1673
score= ((unsigned)(score*score + 128*256))>>16;
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];
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;