Mercurial > libavcodec.hg
comparison mpegvideo.c @ 1778:34466835920f libavcodec
simplify
author | michael |
---|---|
date | Mon, 02 Feb 2004 14:59:43 +0000 |
parents | d183026acdfa |
children | 65f7bd09f37b |
comparison
equal
deleted
inserted
replaced
1777:d183026acdfa | 1778:34466835920f |
---|---|
3296 const int mb_x= s->mb_x; | 3296 const int mb_x= s->mb_x; |
3297 const int mb_y= s->mb_y; | 3297 const int mb_y= s->mb_y; |
3298 int i; | 3298 int i; |
3299 int skip_dct[6]; | 3299 int skip_dct[6]; |
3300 int dct_offset = s->linesize*8; //default for progressive frames | 3300 int dct_offset = s->linesize*8; //default for progressive frames |
3301 uint8_t *ptr_y, *ptr_cb, *ptr_cr; | |
3302 int wrap_y, wrap_c; | |
3303 int emu=0; | |
3301 | 3304 |
3302 for(i=0; i<6; i++) skip_dct[i]=0; | 3305 for(i=0; i<6; i++) skip_dct[i]=0; |
3303 | 3306 |
3304 if(s->adaptive_quant){ | 3307 if(s->adaptive_quant){ |
3305 const int last_qp= s->qscale; | 3308 const int last_qp= s->qscale; |
3322 } | 3325 } |
3323 } | 3326 } |
3324 ff_set_qscale(s, last_qp + s->dquant); | 3327 ff_set_qscale(s, last_qp + s->dquant); |
3325 } | 3328 } |
3326 | 3329 |
3330 wrap_y = s->linesize; | |
3331 wrap_c = s->uvlinesize; | |
3332 ptr_y = s->new_picture.data[0] + (mb_y * 16 * wrap_y) + mb_x * 16; | |
3333 ptr_cb = s->new_picture.data[1] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
3334 ptr_cr = s->new_picture.data[2] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
3335 | |
3336 if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){ | |
3337 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, wrap_y, 16, 16, mb_x*16, mb_y*16, s->width, s->height); | |
3338 ptr_y= s->edge_emu_buffer; | |
3339 emu=1; | |
3340 } | |
3341 | |
3327 if (s->mb_intra) { | 3342 if (s->mb_intra) { |
3328 uint8_t *ptr_y, *ptr_cb, *ptr_cr; | |
3329 int wrap_y, wrap_c; | |
3330 int emu=0; | |
3331 | |
3332 wrap_y = s->linesize; | |
3333 wrap_c = s->uvlinesize; | |
3334 ptr_y = s->new_picture.data[0] + (mb_y * 16 * wrap_y) + mb_x * 16; | |
3335 ptr_cb = s->new_picture.data[1] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
3336 ptr_cr = s->new_picture.data[2] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
3337 | |
3338 if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){ | |
3339 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, wrap_y, 16, 16, mb_x*16, mb_y*16, s->width, s->height); | |
3340 ptr_y= s->edge_emu_buffer; | |
3341 emu=1; | |
3342 } | |
3343 | |
3344 if(s->flags&CODEC_FLAG_INTERLACED_DCT){ | 3343 if(s->flags&CODEC_FLAG_INTERLACED_DCT){ |
3345 int progressive_score, interlaced_score; | 3344 int progressive_score, interlaced_score; |
3346 | 3345 |
3347 s->interlaced_dct=0; | 3346 s->interlaced_dct=0; |
3348 progressive_score= s->dsp.ildct_cmp[4](s, ptr_y , NULL, wrap_y, 8) | 3347 progressive_score= s->dsp.ildct_cmp[4](s, ptr_y , NULL, wrap_y, 8) |
3367 | 3366 |
3368 if(s->flags&CODEC_FLAG_GRAY){ | 3367 if(s->flags&CODEC_FLAG_GRAY){ |
3369 skip_dct[4]= 1; | 3368 skip_dct[4]= 1; |
3370 skip_dct[5]= 1; | 3369 skip_dct[5]= 1; |
3371 }else{ | 3370 }else{ |
3372 if(emu){ | 3371 if(emu){ //FIXME move out of loop and fix edge_emu_buffer mess |
3373 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_cb, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); | 3372 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_cb, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); |
3374 ptr_cb= s->edge_emu_buffer; | 3373 ptr_cb= s->edge_emu_buffer; |
3374 ff_emulated_edge_mc(s->edge_emu_buffer+8, ptr_cr, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); | |
3375 ptr_cr= s->edge_emu_buffer+8; | |
3375 } | 3376 } |
3376 s->dsp.get_pixels(s->block[4], ptr_cb, wrap_c); | 3377 s->dsp.get_pixels(s->block[4], ptr_cb, wrap_c); |
3377 | |
3378 if(emu){ | |
3379 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_cr, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); | |
3380 ptr_cr= s->edge_emu_buffer; | |
3381 } | |
3382 s->dsp.get_pixels(s->block[5], ptr_cr, wrap_c); | 3378 s->dsp.get_pixels(s->block[5], ptr_cr, wrap_c); |
3383 } | |
3384 | |
3385 if(s->avctx->quantizer_noise_shaping){ | |
3386 get_vissual_weight(weight[0], ptr_y , wrap_y); | |
3387 get_vissual_weight(weight[1], ptr_y + 8, wrap_y); | |
3388 get_vissual_weight(weight[2], ptr_y + dct_offset , wrap_y); | |
3389 get_vissual_weight(weight[3], ptr_y + dct_offset + 8, wrap_y); | |
3390 get_vissual_weight(weight[4], ptr_cb , wrap_c); | |
3391 get_vissual_weight(weight[5], ptr_cr , wrap_c); | |
3392 memcpy(orig[0], s->block[0], sizeof(DCTELEM)*64*6); | |
3393 } | 3379 } |
3394 }else{ | 3380 }else{ |
3395 op_pixels_func (*op_pix)[4]; | 3381 op_pixels_func (*op_pix)[4]; |
3396 qpel_mc_func (*op_qpix)[16]; | 3382 qpel_mc_func (*op_qpix)[16]; |
3397 uint8_t *dest_y, *dest_cb, *dest_cr; | 3383 uint8_t *dest_y, *dest_cb, *dest_cr; |
3398 uint8_t *ptr_y, *ptr_cb, *ptr_cr; | |
3399 int wrap_y, wrap_c; | |
3400 int emu=0; | |
3401 | 3384 |
3402 dest_y = s->dest[0]; | 3385 dest_y = s->dest[0]; |
3403 dest_cb = s->dest[1]; | 3386 dest_cb = s->dest[1]; |
3404 dest_cr = s->dest[2]; | 3387 dest_cr = s->dest[2]; |
3405 wrap_y = s->linesize; | |
3406 wrap_c = s->uvlinesize; | |
3407 ptr_y = s->new_picture.data[0] + (mb_y * 16 * wrap_y) + mb_x * 16; | |
3408 ptr_cb = s->new_picture.data[1] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
3409 ptr_cr = s->new_picture.data[2] + (mb_y * 8 * wrap_c) + mb_x * 8; | |
3410 | 3388 |
3411 if ((!s->no_rounding) || s->pict_type==B_TYPE){ | 3389 if ((!s->no_rounding) || s->pict_type==B_TYPE){ |
3412 op_pix = s->dsp.put_pixels_tab; | 3390 op_pix = s->dsp.put_pixels_tab; |
3413 op_qpix= s->dsp.put_qpel_pixels_tab; | 3391 op_qpix= s->dsp.put_qpel_pixels_tab; |
3414 }else{ | 3392 }else{ |
3423 } | 3401 } |
3424 if (s->mv_dir & MV_DIR_BACKWARD) { | 3402 if (s->mv_dir & MV_DIR_BACKWARD) { |
3425 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix); | 3403 MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix); |
3426 } | 3404 } |
3427 | 3405 |
3428 if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){ | |
3429 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_y, wrap_y, 16, 16, mb_x*16, mb_y*16, s->width, s->height); | |
3430 ptr_y= s->edge_emu_buffer; | |
3431 emu=1; | |
3432 } | |
3433 | |
3434 if(s->flags&CODEC_FLAG_INTERLACED_DCT){ | 3406 if(s->flags&CODEC_FLAG_INTERLACED_DCT){ |
3435 int progressive_score, interlaced_score; | 3407 int progressive_score, interlaced_score; |
3436 | 3408 |
3437 s->interlaced_dct=0; | 3409 s->interlaced_dct=0; |
3438 progressive_score= s->dsp.ildct_cmp[0](s, dest_y , ptr_y , wrap_y, 8) | 3410 progressive_score= s->dsp.ildct_cmp[0](s, dest_y , ptr_y , wrap_y, 8) |
3463 skip_dct[5]= 1; | 3435 skip_dct[5]= 1; |
3464 }else{ | 3436 }else{ |
3465 if(emu){ | 3437 if(emu){ |
3466 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_cb, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); | 3438 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_cb, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); |
3467 ptr_cb= s->edge_emu_buffer; | 3439 ptr_cb= s->edge_emu_buffer; |
3440 ff_emulated_edge_mc(s->edge_emu_buffer+8, ptr_cr, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); | |
3441 ptr_cr= s->edge_emu_buffer+8; | |
3468 } | 3442 } |
3469 s->dsp.diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c); | 3443 s->dsp.diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c); |
3470 if(emu){ | |
3471 ff_emulated_edge_mc(s->edge_emu_buffer, ptr_cr, wrap_c, 8, 8, mb_x*8, mb_y*8, s->width>>1, s->height>>1); | |
3472 ptr_cr= s->edge_emu_buffer; | |
3473 } | |
3474 s->dsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c); | 3444 s->dsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c); |
3475 } | 3445 } |
3476 /* pre quantization */ | 3446 /* pre quantization */ |
3477 if(s->current_picture.mc_mb_var[s->mb_stride*mb_y+ mb_x]<2*s->qscale*s->qscale){ | 3447 if(s->current_picture.mc_mb_var[s->mb_stride*mb_y+ mb_x]<2*s->qscale*s->qscale){ |
3478 //FIXME optimize | 3448 //FIXME optimize |
3481 if(s->dsp.sad[1](NULL, ptr_y +dct_offset , dest_y +dct_offset , wrap_y, 8) < 20*s->qscale) skip_dct[2]= 1; | 3451 if(s->dsp.sad[1](NULL, ptr_y +dct_offset , dest_y +dct_offset , wrap_y, 8) < 20*s->qscale) skip_dct[2]= 1; |
3482 if(s->dsp.sad[1](NULL, ptr_y +dct_offset+ 8, dest_y +dct_offset+ 8, wrap_y, 8) < 20*s->qscale) skip_dct[3]= 1; | 3452 if(s->dsp.sad[1](NULL, ptr_y +dct_offset+ 8, dest_y +dct_offset+ 8, wrap_y, 8) < 20*s->qscale) skip_dct[3]= 1; |
3483 if(s->dsp.sad[1](NULL, ptr_cb , dest_cb , wrap_c, 8) < 20*s->qscale) skip_dct[4]= 1; | 3453 if(s->dsp.sad[1](NULL, ptr_cb , dest_cb , wrap_c, 8) < 20*s->qscale) skip_dct[4]= 1; |
3484 if(s->dsp.sad[1](NULL, ptr_cr , dest_cr , wrap_c, 8) < 20*s->qscale) skip_dct[5]= 1; | 3454 if(s->dsp.sad[1](NULL, ptr_cr , dest_cr , wrap_c, 8) < 20*s->qscale) skip_dct[5]= 1; |
3485 } | 3455 } |
3486 | 3456 } |
3487 if(s->avctx->quantizer_noise_shaping){ | 3457 |
3488 if(!skip_dct[0]) get_vissual_weight(weight[0], ptr_y , wrap_y); | 3458 if(s->avctx->quantizer_noise_shaping){ |
3489 if(!skip_dct[1]) get_vissual_weight(weight[1], ptr_y + 8, wrap_y); | 3459 if(!skip_dct[0]) get_vissual_weight(weight[0], ptr_y , wrap_y); |
3490 if(!skip_dct[2]) get_vissual_weight(weight[2], ptr_y + dct_offset , wrap_y); | 3460 if(!skip_dct[1]) get_vissual_weight(weight[1], ptr_y + 8, wrap_y); |
3491 if(!skip_dct[3]) get_vissual_weight(weight[3], ptr_y + dct_offset + 8, wrap_y); | 3461 if(!skip_dct[2]) get_vissual_weight(weight[2], ptr_y + dct_offset , wrap_y); |
3492 if(!skip_dct[4]) get_vissual_weight(weight[4], ptr_cb , wrap_c); | 3462 if(!skip_dct[3]) get_vissual_weight(weight[3], ptr_y + dct_offset + 8, wrap_y); |
3493 if(!skip_dct[5]) get_vissual_weight(weight[5], ptr_cr , wrap_c); | 3463 if(!skip_dct[4]) get_vissual_weight(weight[4], ptr_cb , wrap_c); |
3494 memcpy(orig[0], s->block[0], sizeof(DCTELEM)*64*6); | 3464 if(!skip_dct[5]) get_vissual_weight(weight[5], ptr_cr , wrap_c); |
3495 } | 3465 memcpy(orig[0], s->block[0], sizeof(DCTELEM)*64*6); |
3496 } | 3466 } |
3497 | 3467 |
3498 /* DCT & quantize */ | 3468 /* DCT & quantize */ |
3499 if(s->out_format==FMT_MJPEG){ | 3469 assert(s->out_format!=FMT_MJPEG || s->qscale==8); |
3500 for(i=0;i<6;i++) { | 3470 { |
3501 int overflow; | |
3502 s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, 8, &overflow); | |
3503 if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); | |
3504 } | |
3505 }else{ | |
3506 for(i=0;i<6;i++) { | 3471 for(i=0;i<6;i++) { |
3507 if(!skip_dct[i]){ | 3472 if(!skip_dct[i]){ |
3508 int overflow; | 3473 int overflow; |
3509 s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow); | 3474 s->block_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow); |
3510 // FIXME we could decide to change to quantizer instead of clipping | 3475 // FIXME we could decide to change to quantizer instead of clipping |
4035 | 4000 |
4036 s->intra_matrix[j] = CLAMP_TO_8BIT((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3); | 4001 s->intra_matrix[j] = CLAMP_TO_8BIT((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3); |
4037 } | 4002 } |
4038 convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16, | 4003 convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16, |
4039 s->intra_matrix, s->intra_quant_bias, 8, 8); | 4004 s->intra_matrix, s->intra_quant_bias, 8, 8); |
4005 s->qscale= 8; | |
4040 } | 4006 } |
4041 | 4007 |
4042 //FIXME var duplication | 4008 //FIXME var duplication |
4043 s->current_picture.key_frame= s->pict_type == I_TYPE; | 4009 s->current_picture.key_frame= s->pict_type == I_TYPE; |
4044 s->current_picture.pict_type= s->pict_type; | 4010 s->current_picture.pict_type= s->pict_type; |