Mercurial > libavcodec.hg
comparison motion_est.c @ 2987:8f9eab06237b libavcodec
dont discard least significant bits
author | michael |
---|---|
date | Sun, 25 Dec 2005 16:34:12 +0000 |
parents | 83934bcab3cc |
children | 10934895be5a |
comparison
equal
deleted
inserted
replaced
2986:83934bcab3cc | 2987:8f9eab06237b |
---|---|
1162 c->skip=0; | 1162 c->skip=0; |
1163 | 1163 |
1164 /* intra / predictive decision */ | 1164 /* intra / predictive decision */ |
1165 pix = c->src[0][0]; | 1165 pix = c->src[0][0]; |
1166 sum = s->dsp.pix_sum(pix, s->linesize); | 1166 sum = s->dsp.pix_sum(pix, s->linesize); |
1167 varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500 + 128)>>8; | 1167 varc = s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500; |
1168 | 1168 |
1169 pic->mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8; | 1169 pic->mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8; |
1170 pic->mb_var [s->mb_stride * mb_y + mb_x] = varc; | 1170 pic->mb_var [s->mb_stride * mb_y + mb_x] = (varc+128)>>8; |
1171 c->mb_var_sum_temp += varc; | 1171 c->mb_var_sum_temp += (varc+128)>>8; |
1172 | 1172 |
1173 if(c->avctx->me_threshold){ | 1173 if(c->avctx->me_threshold){ |
1174 vard= (check_input_motion(s, mb_x, mb_y, 1)+128)>>8; | 1174 vard= check_input_motion(s, mb_x, mb_y, 1); |
1175 | 1175 |
1176 if(vard<c->avctx->me_threshold){ | 1176 if((vard+128)>>8 < c->avctx->me_threshold){ |
1177 pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = vard; | 1177 pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8; |
1178 c->mc_mb_var_sum_temp += vard; | 1178 c->mc_mb_var_sum_temp += (vard+128)>>8; |
1179 if (vard <= 64 || vard < varc) { //FIXME | 1179 if (vard <= 64<<8 || vard < varc) { //FIXME |
1180 c->scene_change_score+= ff_sqrt(vard<<8) - ff_sqrt(varc<<8); | 1180 c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); |
1181 }else{ | 1181 }else{ |
1182 c->scene_change_score+= s->qscale; | 1182 c->scene_change_score+= s->qscale; |
1183 } | 1183 } |
1184 return; | 1184 return; |
1185 } | 1185 } |
1186 if(vard<c->avctx->mb_threshold) | 1186 if((vard+128)>>8 < c->avctx->mb_threshold) |
1187 mb_type= s->mb_type[mb_x + mb_y*s->mb_stride]; | 1187 mb_type= s->mb_type[mb_x + mb_y*s->mb_stride]; |
1188 } | 1188 } |
1189 | 1189 |
1190 switch(s->me_method) { | 1190 switch(s->me_method) { |
1191 case ME_ZERO: | 1191 case ME_ZERO: |
1254 } | 1254 } |
1255 | 1255 |
1256 /* At this point (mx,my) are full-pell and the relative displacement */ | 1256 /* At this point (mx,my) are full-pell and the relative displacement */ |
1257 ppix = c->ref[0][0] + (my * s->linesize) + mx; | 1257 ppix = c->ref[0][0] + (my * s->linesize) + mx; |
1258 | 1258 |
1259 vard = (s->dsp.sse[0](NULL, pix, ppix, s->linesize, 16)+128)>>8; | 1259 vard = s->dsp.sse[0](NULL, pix, ppix, s->linesize, 16); |
1260 | 1260 |
1261 pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = vard; | 1261 pic->mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8; |
1262 // pic->mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin; | 1262 // pic->mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin; |
1263 c->mc_mb_var_sum_temp += vard; | 1263 c->mc_mb_var_sum_temp += (vard+128)>>8; |
1264 | 1264 |
1265 #if 0 | 1265 #if 0 |
1266 printf("varc=%4d avg_var=%4d (sum=%4d) vard=%4d mx=%2d my=%2d\n", | 1266 printf("varc=%4d avg_var=%4d (sum=%4d) vard=%4d mx=%2d my=%2d\n", |
1267 varc, s->avg_mb_var, sum, vard, mx - xx, my - yy); | 1267 varc, s->avg_mb_var, sum, vard, mx - xx, my - yy); |
1268 #endif | 1268 #endif |
1269 if(mb_type){ | 1269 if(mb_type){ |
1270 if (vard <= 64 || vard < varc) | 1270 if (vard <= 64<<8 || vard < varc) |
1271 c->scene_change_score+= ff_sqrt(vard<<8) - ff_sqrt(varc<<8); | 1271 c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); |
1272 else | 1272 else |
1273 c->scene_change_score+= s->qscale; | 1273 c->scene_change_score+= s->qscale; |
1274 | 1274 |
1275 if(mb_type == CANDIDATE_MB_TYPE_INTER){ | 1275 if(mb_type == CANDIDATE_MB_TYPE_INTER){ |
1276 c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); | 1276 c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); |
1286 } | 1286 } |
1287 if(mb_type == CANDIDATE_MB_TYPE_INTER_I){ | 1287 if(mb_type == CANDIDATE_MB_TYPE_INTER_I){ |
1288 interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 1); | 1288 interlaced_search(s, 0, s->p_field_mv_table, s->p_field_select_table, mx, my, 1); |
1289 } | 1289 } |
1290 }else if(c->avctx->mb_decision > FF_MB_DECISION_SIMPLE){ | 1290 }else if(c->avctx->mb_decision > FF_MB_DECISION_SIMPLE){ |
1291 if (vard <= 64 || vard < varc) | 1291 if (vard <= 64<<8 || vard < varc) |
1292 c->scene_change_score+= ff_sqrt(vard<<8) - ff_sqrt(varc<<8); | 1292 c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); |
1293 else | 1293 else |
1294 c->scene_change_score+= s->qscale; | 1294 c->scene_change_score+= s->qscale; |
1295 | 1295 |
1296 if (vard*2 + 200 > varc) | 1296 if (vard*2 + 200*256 > varc) |
1297 mb_type|= CANDIDATE_MB_TYPE_INTRA; | 1297 mb_type|= CANDIDATE_MB_TYPE_INTRA; |
1298 if (varc*2 + 200 > vard){ | 1298 if (varc*2 + 200*256 > vard){ |
1299 mb_type|= CANDIDATE_MB_TYPE_INTER; | 1299 mb_type|= CANDIDATE_MB_TYPE_INTER; |
1300 c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); | 1300 c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); |
1301 if(s->flags&CODEC_FLAG_MV0) | 1301 if(s->flags&CODEC_FLAG_MV0) |
1302 if(mx || my) | 1302 if(mx || my) |
1303 mb_type |= CANDIDATE_MB_TYPE_SKIPPED; //FIXME check difference | 1303 mb_type |= CANDIDATE_MB_TYPE_SKIPPED; //FIXME check difference |
1304 }else{ | 1304 }else{ |
1305 mx <<=shift; | 1305 mx <<=shift; |
1306 my <<=shift; | 1306 my <<=shift; |
1307 } | 1307 } |
1308 if((s->flags&CODEC_FLAG_4MV) | 1308 if((s->flags&CODEC_FLAG_4MV) |
1309 && !c->skip && varc>50 && vard>10){ | 1309 && !c->skip && varc>50<<8 && vard>10<<8){ |
1310 if(h263_mv4_search(s, mx, my, shift) < INT_MAX) | 1310 if(h263_mv4_search(s, mx, my, shift) < INT_MAX) |
1311 mb_type|=CANDIDATE_MB_TYPE_INTER4V; | 1311 mb_type|=CANDIDATE_MB_TYPE_INTER4V; |
1312 | 1312 |
1313 set_p_mv_tables(s, mx, my, 0); | 1313 set_p_mv_tables(s, mx, my, 0); |
1314 }else | 1314 }else |
1325 dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); | 1325 dmin= c->sub_motion_search(s, &mx, &my, dmin, 0, 0, 0, 16); |
1326 if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip) | 1326 if(c->avctx->me_sub_cmp != c->avctx->mb_cmp && !c->skip) |
1327 dmin= ff_get_mb_score(s, mx, my, 0, 0, 0, 16, 1); | 1327 dmin= ff_get_mb_score(s, mx, my, 0, 0, 0, 16, 1); |
1328 | 1328 |
1329 if((s->flags&CODEC_FLAG_4MV) | 1329 if((s->flags&CODEC_FLAG_4MV) |
1330 && !c->skip && varc>50 && vard>10){ | 1330 && !c->skip && varc>50<<8 && vard>10<<8){ |
1331 int dmin4= h263_mv4_search(s, mx, my, shift); | 1331 int dmin4= h263_mv4_search(s, mx, my, shift); |
1332 if(dmin4 < dmin){ | 1332 if(dmin4 < dmin){ |
1333 mb_type= CANDIDATE_MB_TYPE_INTER4V; | 1333 mb_type= CANDIDATE_MB_TYPE_INTER4V; |
1334 dmin=dmin4; | 1334 dmin=dmin4; |
1335 } | 1335 } |
1346 // pic->mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin; | 1346 // pic->mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin; |
1347 set_p_mv_tables(s, mx, my, mb_type!=CANDIDATE_MB_TYPE_INTER4V); | 1347 set_p_mv_tables(s, mx, my, mb_type!=CANDIDATE_MB_TYPE_INTER4V); |
1348 | 1348 |
1349 /* get intra luma score */ | 1349 /* get intra luma score */ |
1350 if((c->avctx->mb_cmp&0xFF)==FF_CMP_SSE){ | 1350 if((c->avctx->mb_cmp&0xFF)==FF_CMP_SSE){ |
1351 intra_score= (varc<<8) - 500; //FIXME dont scale it down so we dont have to fix it | 1351 intra_score= varc - 500; |
1352 }else{ | 1352 }else{ |
1353 int mean= (sum+128)>>8; | 1353 int mean= (sum+128)>>8; |
1354 mean*= 0x01010101; | 1354 mean*= 0x01010101; |
1355 | 1355 |
1356 for(i=0; i<16; i++){ | 1356 for(i=0; i<16; i++){ |
1392 mb_type= CANDIDATE_MB_TYPE_INTRA; | 1392 mb_type= CANDIDATE_MB_TYPE_INTRA; |
1393 s->current_picture.mb_type[mb_y*s->mb_stride + mb_x]= CANDIDATE_MB_TYPE_INTRA; //FIXME cleanup | 1393 s->current_picture.mb_type[mb_y*s->mb_stride + mb_x]= CANDIDATE_MB_TYPE_INTRA; //FIXME cleanup |
1394 }else | 1394 }else |
1395 s->current_picture.mb_type[mb_y*s->mb_stride + mb_x]= 0; | 1395 s->current_picture.mb_type[mb_y*s->mb_stride + mb_x]= 0; |
1396 | 1396 |
1397 if (vard <= 64 || vard < varc) { //FIXME | 1397 if (vard <= 64<<8 || vard < varc) { //FIXME |
1398 c->scene_change_score+= ff_sqrt(vard<<8) - ff_sqrt(varc<<8); | 1398 c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); |
1399 }else{ | 1399 }else{ |
1400 c->scene_change_score+= s->qscale; | 1400 c->scene_change_score+= s->qscale; |
1401 } | 1401 } |
1402 } | 1402 } |
1403 | 1403 |
1813 | 1813 |
1814 get_limits(s, 16*mb_x, 16*mb_y); | 1814 get_limits(s, 16*mb_x, 16*mb_y); |
1815 | 1815 |
1816 c->skip=0; | 1816 c->skip=0; |
1817 if(c->avctx->me_threshold){ | 1817 if(c->avctx->me_threshold){ |
1818 int vard= (check_input_motion(s, mb_x, mb_y, 0)+128)>>8; | 1818 int vard= check_input_motion(s, mb_x, mb_y, 0); |
1819 | 1819 |
1820 if(vard<c->avctx->me_threshold){ | 1820 if((vard+128)>>8 < c->avctx->me_threshold){ |
1821 // pix = c->src[0][0]; | 1821 // pix = c->src[0][0]; |
1822 // sum = s->dsp.pix_sum(pix, s->linesize); | 1822 // sum = s->dsp.pix_sum(pix, s->linesize); |
1823 // varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500 + 128)>>8; | 1823 // varc = s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500; |
1824 | 1824 |
1825 // pic->mb_var [s->mb_stride * mb_y + mb_x] = varc; | 1825 // pic->mb_var [s->mb_stride * mb_y + mb_x] = (varc+128)>>8; |
1826 s->current_picture.mc_mb_var[s->mb_stride * mb_y + mb_x] = vard; | 1826 s->current_picture.mc_mb_var[s->mb_stride * mb_y + mb_x] = (vard+128)>>8; |
1827 /* pic->mb_mean [s->mb_stride * mb_y + mb_x] = (sum+128)>>8; | 1827 /* pic->mb_mean [s->mb_stride * mb_y + mb_x] = (sum+128)>>8; |
1828 c->mb_var_sum_temp += varc;*/ | 1828 c->mb_var_sum_temp += (varc+128)>>8;*/ |
1829 c->mc_mb_var_sum_temp += vard; | 1829 c->mc_mb_var_sum_temp += (vard+128)>>8; |
1830 /* if (vard <= 64 || vard < varc) { | 1830 /* if (vard <= 64<<8 || vard < varc) { |
1831 c->scene_change_score+= ff_sqrt(vard<<8) - ff_sqrt(varc<<8); | 1831 c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); |
1832 }else{ | 1832 }else{ |
1833 c->scene_change_score+= s->qscale; | 1833 c->scene_change_score+= s->qscale; |
1834 }*/ | 1834 }*/ |
1835 return; | 1835 return; |
1836 } | 1836 } |
1837 if(vard<c->avctx->mb_threshold){ | 1837 if((vard+128)>>8 < c->avctx->mb_threshold){ |
1838 type= s->mb_type[mb_y*s->mb_stride + mb_x]; | 1838 type= s->mb_type[mb_y*s->mb_stride + mb_x]; |
1839 if(type == CANDIDATE_MB_TYPE_DIRECT){ | 1839 if(type == CANDIDATE_MB_TYPE_DIRECT){ |
1840 direct_search(s, mb_x, mb_y); | 1840 direct_search(s, mb_x, mb_y); |
1841 } | 1841 } |
1842 if(type == CANDIDATE_MB_TYPE_FORWARD || type == CANDIDATE_MB_TYPE_BIDIR){ | 1842 if(type == CANDIDATE_MB_TYPE_FORWARD || type == CANDIDATE_MB_TYPE_BIDIR){ |