Mercurial > libavcodec.hg
comparison snow.c @ 6414:f2d49842ea63 libavcodec
cosmetics: Demplayerify indentation.
author | diego |
---|---|
date | Tue, 26 Feb 2008 17:56:00 +0000 |
parents | c58ea608e191 |
children | fd74b42a19f4 |
comparison
equal
deleted
inserted
replaced
6413:c58ea608e191 | 6414:f2d49842ea63 |
---|---|
1302 | 1302 |
1303 for(level=decomposition_count-1; level>=0; level--){ | 1303 for(level=decomposition_count-1; level>=0; level--){ |
1304 while(cs[level].y <= FFMIN((y>>level)+support, height>>level)){ | 1304 while(cs[level].y <= FFMIN((y>>level)+support, height>>level)){ |
1305 switch(type){ | 1305 switch(type){ |
1306 case DWT_97: spatial_compose97i_dy(cs+level, buffer, width>>level, height>>level, stride<<level); | 1306 case DWT_97: spatial_compose97i_dy(cs+level, buffer, width>>level, height>>level, stride<<level); |
1307 break; | 1307 break; |
1308 case DWT_53: spatial_compose53i_dy(cs+level, buffer, width>>level, height>>level, stride<<level); | 1308 case DWT_53: spatial_compose53i_dy(cs+level, buffer, width>>level, height>>level, stride<<level); |
1309 break; | 1309 break; |
1310 } | 1310 } |
1311 } | 1311 } |
1312 } | 1312 } |
1313 } | 1313 } |
1314 | 1314 |
1319 | 1319 |
1320 for(level=decomposition_count-1; level>=0; level--){ | 1320 for(level=decomposition_count-1; level>=0; level--){ |
1321 while(cs[level].y <= FFMIN((y>>level)+support, height>>level)){ | 1321 while(cs[level].y <= FFMIN((y>>level)+support, height>>level)){ |
1322 switch(type){ | 1322 switch(type){ |
1323 case DWT_97: spatial_compose97i_dy_buffered(dsp, cs+level, slice_buf, width>>level, height>>level, stride_line<<level); | 1323 case DWT_97: spatial_compose97i_dy_buffered(dsp, cs+level, slice_buf, width>>level, height>>level, stride_line<<level); |
1324 break; | 1324 break; |
1325 case DWT_53: spatial_compose53i_dy_buffered(cs+level, slice_buf, width>>level, height>>level, stride_line<<level); | 1325 case DWT_53: spatial_compose53i_dy_buffered(cs+level, slice_buf, width>>level, height>>level, stride_line<<level); |
1326 break; | 1326 break; |
1327 } | 1327 } |
1328 } | 1328 } |
1329 } | 1329 } |
1330 } | 1330 } |
1331 | 1331 |
2465 b_h = h - src_y; | 2465 b_h = h - src_y; |
2466 } | 2466 } |
2467 | 2467 |
2468 if(b_w<=0 || b_h<=0) return; | 2468 if(b_w<=0 || b_h<=0) return; |
2469 | 2469 |
2470 assert(src_stride > 2*MB_SIZE + 5); | 2470 assert(src_stride > 2*MB_SIZE + 5); |
2471 | |
2471 if(!sliced && offset_dst) | 2472 if(!sliced && offset_dst) |
2472 dst += src_x + src_y*dst_stride; | 2473 dst += src_x + src_y*dst_stride; |
2473 dst8+= src_x + src_y*src_stride; | 2474 dst8+= src_x + src_y*src_stride; |
2474 // src += src_x + src_y*src_stride; | 2475 // src += src_x + src_y*src_stride; |
2475 | 2476 |
2668 } | 2669 } |
2669 | 2670 |
2670 return; | 2671 return; |
2671 } | 2672 } |
2672 | 2673 |
2673 for(mb_x=0; mb_x<=mb_w; mb_x++){ | 2674 for(mb_x=0; mb_x<=mb_w; mb_x++){ |
2674 add_yblock(s, 0, NULL, buf, dst8, obmc, | 2675 add_yblock(s, 0, NULL, buf, dst8, obmc, |
2675 block_w*mb_x - block_w/2, | 2676 block_w*mb_x - block_w/2, |
2676 block_w*mb_y - block_w/2, | 2677 block_w*mb_y - block_w/2, |
2677 block_w, block_w, | 2678 block_w, block_w, |
2678 w, h, | 2679 w, h, |
2679 w, ref_stride, obmc_stride, | 2680 w, ref_stride, obmc_stride, |
2680 mb_x - 1, mb_y - 1, | 2681 mb_x - 1, mb_y - 1, |
2681 add, 1, plane_index); | 2682 add, 1, plane_index); |
2682 } | 2683 } |
2683 } | 2684 } |
2684 | 2685 |
2685 static av_always_inline void predict_plane(SnowContext *s, IDWTELEM *buf, int plane_index, int add){ | 2686 static av_always_inline void predict_plane(SnowContext *s, IDWTELEM *buf, int plane_index, int add){ |
2686 const int mb_h= s->b_height << s->block_max_depth; | 2687 const int mb_h= s->b_height << s->block_max_depth; |
2687 int mb_y; | 2688 int mb_y; |
3529 p->last_htaps = p->htaps; | 3530 p->last_htaps = p->htaps; |
3530 memcpy(p->last_hcoeff, p->hcoeff, sizeof(p->hcoeff)); | 3531 memcpy(p->last_hcoeff, p->hcoeff, sizeof(p->hcoeff)); |
3531 } | 3532 } |
3532 } | 3533 } |
3533 | 3534 |
3534 s->last_spatial_decomposition_type= s->spatial_decomposition_type; | 3535 s->last_spatial_decomposition_type = s->spatial_decomposition_type; |
3535 s->last_qlog = s->qlog; | 3536 s->last_qlog = s->qlog; |
3536 s->last_qbias = s->qbias; | 3537 s->last_qbias = s->qbias; |
3537 s->last_mv_scale = s->mv_scale; | 3538 s->last_mv_scale = s->mv_scale; |
3538 s->last_block_max_depth = s->block_max_depth; | 3539 s->last_block_max_depth = s->block_max_depth; |
3539 s->last_spatial_decomposition_count= s->spatial_decomposition_count; | 3540 s->last_spatial_decomposition_count = s->spatial_decomposition_count; |
3540 } | 3541 } |
3541 | 3542 |
3542 static void decode_qlogs(SnowContext *s){ | 3543 static void decode_qlogs(SnowContext *s){ |
3543 int plane_index, level, orientation; | 3544 int plane_index, level, orientation; |
3544 | 3545 |
4278 int w= p->width; | 4279 int w= p->width; |
4279 int h= p->height; | 4280 int h= p->height; |
4280 int x, y; | 4281 int x, y; |
4281 // int bits= put_bits_count(&s->c.pb); | 4282 // int bits= put_bits_count(&s->c.pb); |
4282 | 4283 |
4283 if(!(avctx->flags2 & CODEC_FLAG2_MEMC_ONLY)){ | 4284 if(!(avctx->flags2 & CODEC_FLAG2_MEMC_ONLY)){ |
4284 //FIXME optimize | 4285 //FIXME optimize |
4285 if(pict->data[plane_index]) //FIXME gray hack | 4286 if(pict->data[plane_index]) //FIXME gray hack |
4286 for(y=0; y<h; y++){ | 4287 for(y=0; y<h; y++){ |
4287 for(x=0; x<w; x++){ | 4288 for(x=0; x<w; x++){ |
4288 s->spatial_idwt_buffer[y*w + x]= pict->data[plane_index][y*pict->linesize[plane_index] + x]<<FRAC_BITS; | 4289 s->spatial_idwt_buffer[y*w + x]= pict->data[plane_index][y*pict->linesize[plane_index] + x]<<FRAC_BITS; |
4289 } | 4290 } |
4290 } | |
4291 predict_plane(s, s->spatial_idwt_buffer, plane_index, 0); | |
4292 | |
4293 if( plane_index==0 | |
4294 && pict->pict_type == P_TYPE | |
4295 && !(avctx->flags&CODEC_FLAG_PASS2) | |
4296 && s->m.me.scene_change_score > s->avctx->scenechange_threshold){ | |
4297 ff_init_range_encoder(c, buf, buf_size); | |
4298 ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); | |
4299 pict->pict_type= FF_I_TYPE; | |
4300 s->keyframe=1; | |
4301 s->current_picture.key_frame=1; | |
4302 goto redo_frame; | |
4303 } | |
4304 | |
4305 if(s->qlog == LOSSLESS_QLOG){ | |
4306 for(y=0; y<h; y++){ | |
4307 for(x=0; x<w; x++){ | |
4308 s->spatial_dwt_buffer[y*w + x]= (s->spatial_idwt_buffer[y*w + x] + (1<<(FRAC_BITS-1))-1)>>FRAC_BITS; | |
4309 } | 4291 } |
4310 } | 4292 predict_plane(s, s->spatial_idwt_buffer, plane_index, 0); |
4293 | |
4294 if( plane_index==0 | |
4295 && pict->pict_type == P_TYPE | |
4296 && !(avctx->flags&CODEC_FLAG_PASS2) | |
4297 && s->m.me.scene_change_score > s->avctx->scenechange_threshold){ | |
4298 ff_init_range_encoder(c, buf, buf_size); | |
4299 ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); | |
4300 pict->pict_type= FF_I_TYPE; | |
4301 s->keyframe=1; | |
4302 s->current_picture.key_frame=1; | |
4303 goto redo_frame; | |
4304 } | |
4305 | |
4306 if(s->qlog == LOSSLESS_QLOG){ | |
4307 for(y=0; y<h; y++){ | |
4308 for(x=0; x<w; x++){ | |
4309 s->spatial_dwt_buffer[y*w + x]= (s->spatial_idwt_buffer[y*w + x] + (1<<(FRAC_BITS-1))-1)>>FRAC_BITS; | |
4310 } | |
4311 } | |
4312 }else{ | |
4313 for(y=0; y<h; y++){ | |
4314 for(x=0; x<w; x++){ | |
4315 s->spatial_dwt_buffer[y*w + x]=s->spatial_idwt_buffer[y*w + x]<<ENCODER_EXTRA_BITS; | |
4316 } | |
4317 } | |
4318 } | |
4319 | |
4320 /* if(QUANTIZE2) | |
4321 dwt_quantize(s, p, s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type); | |
4322 else*/ | |
4323 ff_spatial_dwt(s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); | |
4324 | |
4325 if(s->pass1_rc && plane_index==0){ | |
4326 int delta_qlog = ratecontrol_1pass(s, pict); | |
4327 if (delta_qlog <= INT_MIN) | |
4328 return -1; | |
4329 if(delta_qlog){ | |
4330 //reordering qlog in the bitstream would eliminate this reset | |
4331 ff_init_range_encoder(c, buf, buf_size); | |
4332 memcpy(s->header_state, rc_header_bak, sizeof(s->header_state)); | |
4333 memcpy(s->block_state, rc_block_bak, sizeof(s->block_state)); | |
4334 encode_header(s); | |
4335 encode_blocks(s, 0); | |
4336 } | |
4337 } | |
4338 | |
4339 for(level=0; level<s->spatial_decomposition_count; level++){ | |
4340 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | |
4341 SubBand *b= &p->band[level][orientation]; | |
4342 | |
4343 if(!QUANTIZE2) | |
4344 quantize(s, b, b->ibuf, b->buf, b->stride, s->qbias); | |
4345 if(orientation==0) | |
4346 decorrelate(s, b, b->ibuf, b->stride, pict->pict_type == P_TYPE, 0); | |
4347 encode_subband(s, b, b->ibuf, b->parent ? b->parent->ibuf : NULL, b->stride, orientation); | |
4348 assert(b->parent==NULL || b->parent->stride == b->stride*2); | |
4349 if(orientation==0) | |
4350 correlate(s, b, b->ibuf, b->stride, 1, 0); | |
4351 } | |
4352 } | |
4353 | |
4354 for(level=0; level<s->spatial_decomposition_count; level++){ | |
4355 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | |
4356 SubBand *b= &p->band[level][orientation]; | |
4357 | |
4358 dequantize(s, b, b->ibuf, b->stride); | |
4359 } | |
4360 } | |
4361 | |
4362 ff_spatial_idwt(s->spatial_idwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); | |
4363 if(s->qlog == LOSSLESS_QLOG){ | |
4364 for(y=0; y<h; y++){ | |
4365 for(x=0; x<w; x++){ | |
4366 s->spatial_idwt_buffer[y*w + x]<<=FRAC_BITS; | |
4367 } | |
4368 } | |
4369 } | |
4370 predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); | |
4311 }else{ | 4371 }else{ |
4312 for(y=0; y<h; y++){ | |
4313 for(x=0; x<w; x++){ | |
4314 s->spatial_dwt_buffer[y*w + x]=s->spatial_idwt_buffer[y*w + x]<<ENCODER_EXTRA_BITS; | |
4315 } | |
4316 } | |
4317 } | |
4318 | |
4319 /* if(QUANTIZE2) | |
4320 dwt_quantize(s, p, s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type); | |
4321 else*/ | |
4322 ff_spatial_dwt(s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); | |
4323 | |
4324 if(s->pass1_rc && plane_index==0){ | |
4325 int delta_qlog = ratecontrol_1pass(s, pict); | |
4326 if (delta_qlog <= INT_MIN) | |
4327 return -1; | |
4328 if(delta_qlog){ | |
4329 //reordering qlog in the bitstream would eliminate this reset | |
4330 ff_init_range_encoder(c, buf, buf_size); | |
4331 memcpy(s->header_state, rc_header_bak, sizeof(s->header_state)); | |
4332 memcpy(s->block_state, rc_block_bak, sizeof(s->block_state)); | |
4333 encode_header(s); | |
4334 encode_blocks(s, 0); | |
4335 } | |
4336 } | |
4337 | |
4338 for(level=0; level<s->spatial_decomposition_count; level++){ | |
4339 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | |
4340 SubBand *b= &p->band[level][orientation]; | |
4341 | |
4342 if(!QUANTIZE2) | |
4343 quantize(s, b, b->ibuf, b->buf, b->stride, s->qbias); | |
4344 if(orientation==0) | |
4345 decorrelate(s, b, b->ibuf, b->stride, pict->pict_type == P_TYPE, 0); | |
4346 encode_subband(s, b, b->ibuf, b->parent ? b->parent->ibuf : NULL, b->stride, orientation); | |
4347 assert(b->parent==NULL || b->parent->stride == b->stride*2); | |
4348 if(orientation==0) | |
4349 correlate(s, b, b->ibuf, b->stride, 1, 0); | |
4350 } | |
4351 } | |
4352 | |
4353 for(level=0; level<s->spatial_decomposition_count; level++){ | |
4354 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | |
4355 SubBand *b= &p->band[level][orientation]; | |
4356 | |
4357 dequantize(s, b, b->ibuf, b->stride); | |
4358 } | |
4359 } | |
4360 | |
4361 ff_spatial_idwt(s->spatial_idwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); | |
4362 if(s->qlog == LOSSLESS_QLOG){ | |
4363 for(y=0; y<h; y++){ | |
4364 for(x=0; x<w; x++){ | |
4365 s->spatial_idwt_buffer[y*w + x]<<=FRAC_BITS; | |
4366 } | |
4367 } | |
4368 } | |
4369 predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); | |
4370 }else{ | |
4371 //ME/MC only | 4372 //ME/MC only |
4372 if(pict->pict_type == I_TYPE){ | 4373 if(pict->pict_type == I_TYPE){ |
4373 for(y=0; y<h; y++){ | 4374 for(y=0; y<h; y++){ |
4374 for(x=0; x<w; x++){ | 4375 for(x=0; x<w; x++){ |
4375 s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]= | 4376 s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]= |
4378 } | 4379 } |
4379 }else{ | 4380 }else{ |
4380 memset(s->spatial_idwt_buffer, 0, sizeof(IDWTELEM)*w*h); | 4381 memset(s->spatial_idwt_buffer, 0, sizeof(IDWTELEM)*w*h); |
4381 predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); | 4382 predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); |
4382 } | 4383 } |
4383 } | 4384 } |
4384 if(s->avctx->flags&CODEC_FLAG_PSNR){ | 4385 if(s->avctx->flags&CODEC_FLAG_PSNR){ |
4385 int64_t error= 0; | 4386 int64_t error= 0; |
4386 | 4387 |
4387 if(pict->data[plane_index]) //FIXME gray hack | 4388 if(pict->data[plane_index]) //FIXME gray hack |
4388 for(y=0; y<h; y++){ | 4389 for(y=0; y<h; y++){ |
4389 for(x=0; x<w; x++){ | 4390 for(x=0; x<w; x++){ |
4390 int d= s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x] - pict->data[plane_index][y*pict->linesize[plane_index] + x]; | 4391 int d= s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x] - pict->data[plane_index][y*pict->linesize[plane_index] + x]; |
4391 error += d*d; | 4392 error += d*d; |
4393 } | |
4392 } | 4394 } |
4393 } | |
4394 s->avctx->error[plane_index] += error; | 4395 s->avctx->error[plane_index] += error; |
4395 s->current_picture.error[plane_index] = error; | 4396 s->current_picture.error[plane_index] = error; |
4396 } | 4397 } |
4398 | |
4397 } | 4399 } |
4398 | 4400 |
4399 update_last_header_values(s); | 4401 update_last_header_values(s); |
4400 | 4402 |
4401 if(s->last_picture[s->max_ref_frames-1].data[0]){ | 4403 if(s->last_picture[s->max_ref_frames-1].data[0]){ |
4520 int w= p->width; | 4522 int w= p->width; |
4521 int h= p->height; | 4523 int h= p->height; |
4522 int x, y; | 4524 int x, y; |
4523 int decode_state[MAX_DECOMPOSITIONS][4][1]; /* Stored state info for unpack_coeffs. 1 variable per instance. */ | 4525 int decode_state[MAX_DECOMPOSITIONS][4][1]; /* Stored state info for unpack_coeffs. 1 variable per instance. */ |
4524 | 4526 |
4525 if(s->avctx->debug&2048){ | 4527 if(s->avctx->debug&2048){ |
4526 memset(s->spatial_dwt_buffer, 0, sizeof(DWTELEM)*w*h); | 4528 memset(s->spatial_dwt_buffer, 0, sizeof(DWTELEM)*w*h); |
4527 predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); | 4529 predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); |
4528 | 4530 |
4529 for(y=0; y<h; y++){ | 4531 for(y=0; y<h; y++){ |
4530 for(x=0; x<w; x++){ | 4532 for(x=0; x<w; x++){ |
4531 int v= s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]; | 4533 int v= s->current_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]; |
4532 s->mconly_picture.data[plane_index][y*s->mconly_picture.linesize[plane_index] + x]= v; | 4534 s->mconly_picture.data[plane_index][y*s->mconly_picture.linesize[plane_index] + x]= v; |
4533 } | 4535 } |
4534 } | 4536 } |
4535 } | 4537 } |
4536 | 4538 |
4537 { | 4539 { |
4538 for(level=0; level<s->spatial_decomposition_count; level++){ | |
4539 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | |
4540 SubBand *b= &p->band[level][orientation]; | |
4541 unpack_coeffs(s, b, b->parent, orientation); | |
4542 } | |
4543 } | |
4544 } | |
4545 | |
4546 { | |
4547 const int mb_h= s->b_height << s->block_max_depth; | |
4548 const int block_size = MB_SIZE >> s->block_max_depth; | |
4549 const int block_w = plane_index ? block_size/2 : block_size; | |
4550 int mb_y; | |
4551 dwt_compose_t cs[MAX_DECOMPOSITIONS]; | |
4552 int yd=0, yq=0; | |
4553 int y; | |
4554 int end_y; | |
4555 | |
4556 ff_spatial_idwt_buffered_init(cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count); | |
4557 for(mb_y=0; mb_y<=mb_h; mb_y++){ | |
4558 | |
4559 int slice_starty = block_w*mb_y; | |
4560 int slice_h = block_w*(mb_y+1); | |
4561 if (!(s->keyframe || s->avctx->debug&512)){ | |
4562 slice_starty = FFMAX(0, slice_starty - (block_w >> 1)); | |
4563 slice_h -= (block_w >> 1); | |
4564 } | |
4565 | |
4566 for(level=0; level<s->spatial_decomposition_count; level++){ | 4540 for(level=0; level<s->spatial_decomposition_count; level++){ |
4567 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | 4541 for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
4568 SubBand *b= &p->band[level][orientation]; | 4542 SubBand *b= &p->band[level][orientation]; |
4569 int start_y; | 4543 unpack_coeffs(s, b, b->parent, orientation); |
4570 int end_y; | 4544 } |
4571 int our_mb_start = mb_y; | 4545 } |
4572 int our_mb_end = (mb_y + 1); | 4546 } |
4573 const int extra= 3; | 4547 |
4574 start_y = (mb_y ? ((block_w * our_mb_start) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra: 0); | 4548 { |
4575 end_y = (((block_w * our_mb_end) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra); | 4549 const int mb_h= s->b_height << s->block_max_depth; |
4576 if (!(s->keyframe || s->avctx->debug&512)){ | 4550 const int block_size = MB_SIZE >> s->block_max_depth; |
4577 start_y = FFMAX(0, start_y - (block_w >> (1+s->spatial_decomposition_count - level))); | 4551 const int block_w = plane_index ? block_size/2 : block_size; |
4578 end_y = FFMAX(0, end_y - (block_w >> (1+s->spatial_decomposition_count - level))); | 4552 int mb_y; |
4553 dwt_compose_t cs[MAX_DECOMPOSITIONS]; | |
4554 int yd=0, yq=0; | |
4555 int y; | |
4556 int end_y; | |
4557 | |
4558 ff_spatial_idwt_buffered_init(cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count); | |
4559 for(mb_y=0; mb_y<=mb_h; mb_y++){ | |
4560 | |
4561 int slice_starty = block_w*mb_y; | |
4562 int slice_h = block_w*(mb_y+1); | |
4563 if (!(s->keyframe || s->avctx->debug&512)){ | |
4564 slice_starty = FFMAX(0, slice_starty - (block_w >> 1)); | |
4565 slice_h -= (block_w >> 1); | |
4566 } | |
4567 | |
4568 for(level=0; level<s->spatial_decomposition_count; level++){ | |
4569 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | |
4570 SubBand *b= &p->band[level][orientation]; | |
4571 int start_y; | |
4572 int end_y; | |
4573 int our_mb_start = mb_y; | |
4574 int our_mb_end = (mb_y + 1); | |
4575 const int extra= 3; | |
4576 start_y = (mb_y ? ((block_w * our_mb_start) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra: 0); | |
4577 end_y = (((block_w * our_mb_end) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra); | |
4578 if (!(s->keyframe || s->avctx->debug&512)){ | |
4579 start_y = FFMAX(0, start_y - (block_w >> (1+s->spatial_decomposition_count - level))); | |
4580 end_y = FFMAX(0, end_y - (block_w >> (1+s->spatial_decomposition_count - level))); | |
4581 } | |
4582 start_y = FFMIN(b->height, start_y); | |
4583 end_y = FFMIN(b->height, end_y); | |
4584 | |
4585 if (start_y != end_y){ | |
4586 if (orientation == 0){ | |
4587 SubBand * correlate_band = &p->band[0][0]; | |
4588 int correlate_end_y = FFMIN(b->height, end_y + 1); | |
4589 int correlate_start_y = FFMIN(b->height, (start_y ? start_y + 1 : 0)); | |
4590 decode_subband_slice_buffered(s, correlate_band, &s->sb, correlate_start_y, correlate_end_y, decode_state[0][0]); | |
4591 correlate_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, 1, 0, correlate_start_y, correlate_end_y); | |
4592 dequantize_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, start_y, end_y); | |
4593 } | |
4594 else | |
4595 decode_subband_slice_buffered(s, b, &s->sb, start_y, end_y, decode_state[level][orientation]); | |
4596 } | |
4579 } | 4597 } |
4580 start_y = FFMIN(b->height, start_y); | 4598 } |
4581 end_y = FFMIN(b->height, end_y); | 4599 |
4582 | 4600 for(; yd<slice_h; yd+=4){ |
4583 if (start_y != end_y){ | 4601 ff_spatial_idwt_buffered_slice(&s->dsp, cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count, yd); |
4584 if (orientation == 0){ | 4602 } |
4585 SubBand * correlate_band = &p->band[0][0]; | 4603 |
4586 int correlate_end_y = FFMIN(b->height, end_y + 1); | 4604 if(s->qlog == LOSSLESS_QLOG){ |
4587 int correlate_start_y = FFMIN(b->height, (start_y ? start_y + 1 : 0)); | 4605 for(; yq<slice_h && yq<h; yq++){ |
4588 decode_subband_slice_buffered(s, correlate_band, &s->sb, correlate_start_y, correlate_end_y, decode_state[0][0]); | 4606 IDWTELEM * line = slice_buffer_get_line(&s->sb, yq); |
4589 correlate_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, 1, 0, correlate_start_y, correlate_end_y); | 4607 for(x=0; x<w; x++){ |
4590 dequantize_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, start_y, end_y); | 4608 line[x] <<= FRAC_BITS; |
4591 } | 4609 } |
4592 else | |
4593 decode_subband_slice_buffered(s, b, &s->sb, start_y, end_y, decode_state[level][orientation]); | |
4594 } | 4610 } |
4595 } | 4611 } |
4596 } | 4612 |
4597 | 4613 predict_slice_buffered(s, &s->sb, s->spatial_idwt_buffer, plane_index, 1, mb_y); |
4598 for(; yd<slice_h; yd+=4){ | 4614 |
4599 ff_spatial_idwt_buffered_slice(&s->dsp, cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count, yd); | 4615 y = FFMIN(p->height, slice_starty); |
4600 } | 4616 end_y = FFMIN(p->height, slice_h); |
4601 | 4617 while(y < end_y) |
4602 if(s->qlog == LOSSLESS_QLOG){ | 4618 slice_buffer_release(&s->sb, y++); |
4603 for(; yq<slice_h && yq<h; yq++){ | 4619 } |
4604 IDWTELEM * line = slice_buffer_get_line(&s->sb, yq); | 4620 |
4605 for(x=0; x<w; x++){ | 4621 slice_buffer_flush(&s->sb); |
4606 line[x] <<= FRAC_BITS; | 4622 } |
4607 } | 4623 |
4608 } | |
4609 } | |
4610 | |
4611 predict_slice_buffered(s, &s->sb, s->spatial_idwt_buffer, plane_index, 1, mb_y); | |
4612 | |
4613 y = FFMIN(p->height, slice_starty); | |
4614 end_y = FFMIN(p->height, slice_h); | |
4615 while(y < end_y) | |
4616 slice_buffer_release(&s->sb, y++); | |
4617 } | |
4618 | |
4619 slice_buffer_flush(&s->sb); | |
4620 } | |
4621 } | 4624 } |
4622 | 4625 |
4623 emms_c(); | 4626 emms_c(); |
4624 | 4627 |
4625 if(s->last_picture[s->max_ref_frames-1].data[0]){ | 4628 if(s->last_picture[s->max_ref_frames-1].data[0]){ |
4627 for(i=0; i<9; i++) | 4630 for(i=0; i<9; i++) |
4628 if(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3]) | 4631 if(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3]) |
4629 av_free(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3] - EDGE_WIDTH*(1+s->current_picture.linesize[i%3])); | 4632 av_free(s->halfpel_plane[s->max_ref_frames-1][1+i/3][i%3] - EDGE_WIDTH*(1+s->current_picture.linesize[i%3])); |
4630 } | 4633 } |
4631 | 4634 |
4632 if(!(s->avctx->debug&2048)) | 4635 if(!(s->avctx->debug&2048)) |
4633 *picture= s->current_picture; | 4636 *picture= s->current_picture; |
4634 else | 4637 else |
4635 *picture= s->mconly_picture; | 4638 *picture= s->mconly_picture; |
4636 | 4639 |
4637 *data_size = sizeof(AVFrame); | 4640 *data_size = sizeof(AVFrame); |
4638 | 4641 |
4639 bytes_read= c->bytestream - c->bytestream_start; | 4642 bytes_read= c->bytestream - c->bytestream_start; |
4640 if(bytes_read ==0) av_log(s->avctx, AV_LOG_ERROR, "error at end of frame\n"); //FIXME | 4643 if(bytes_read ==0) av_log(s->avctx, AV_LOG_ERROR, "error at end of frame\n"); //FIXME |
4734 int j; | 4737 int j; |
4735 j= get_symbol(&s.c, s.header_state, 1); | 4738 j= get_symbol(&s.c, s.header_state, 1); |
4736 if(j!=i*i*i/3*FFABS(i)) printf("fsck: %d != %d\n", i, j); | 4739 if(j!=i*i*i/3*FFABS(i)) printf("fsck: %d != %d\n", i, j); |
4737 } | 4740 } |
4738 #endif | 4741 #endif |
4739 { | 4742 { |
4740 int level, orientation, x, y; | 4743 int level, orientation, x, y; |
4741 int64_t errors[8][4]; | 4744 int64_t errors[8][4]; |
4742 int64_t g=0; | 4745 int64_t g=0; |
4743 | 4746 |
4744 memset(errors, 0, sizeof(errors)); | 4747 memset(errors, 0, sizeof(errors)); |
4745 s.spatial_decomposition_count=3; | 4748 s.spatial_decomposition_count=3; |
4746 s.spatial_decomposition_type=0; | 4749 s.spatial_decomposition_type=0; |
4747 for(level=0; level<s.spatial_decomposition_count; level++){ | 4750 for(level=0; level<s.spatial_decomposition_count; level++){ |
4748 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | 4751 for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
4749 int w= width >> (s.spatial_decomposition_count-level); | 4752 int w= width >> (s.spatial_decomposition_count-level); |
4750 int h= height >> (s.spatial_decomposition_count-level); | 4753 int h= height >> (s.spatial_decomposition_count-level); |
4751 int stride= width << (s.spatial_decomposition_count-level); | 4754 int stride= width << (s.spatial_decomposition_count-level); |
4752 DWTELEM *buf= buffer[0]; | 4755 DWTELEM *buf= buffer[0]; |
4753 int64_t error=0; | 4756 int64_t error=0; |
4754 | 4757 |
4755 if(orientation&1) buf+=w; | 4758 if(orientation&1) buf+=w; |
4756 if(orientation>1) buf+=stride>>1; | 4759 if(orientation>1) buf+=stride>>1; |
4757 | 4760 |
4758 memset(buffer[0], 0, sizeof(int)*width*height); | 4761 memset(buffer[0], 0, sizeof(int)*width*height); |
4759 buf[w/2 + h/2*stride]= 256*256; | 4762 buf[w/2 + h/2*stride]= 256*256; |
4760 ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count); | 4763 ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count); |
4761 for(y=0; y<height; y++){ | 4764 for(y=0; y<height; y++){ |
4762 for(x=0; x<width; x++){ | 4765 for(x=0; x<width; x++){ |
4763 int64_t d= buffer[0][x + y*width]; | 4766 int64_t d= buffer[0][x + y*width]; |
4764 error += d*d; | 4767 error += d*d; |
4765 if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9 && level==2) printf("%8"PRId64" ", d); | 4768 if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9 && level==2) printf("%8"PRId64" ", d); |
4769 } | |
4770 if(FFABS(height/2-y)<9 && level==2) printf("\n"); | |
4766 } | 4771 } |
4767 if(FFABS(height/2-y)<9 && level==2) printf("\n"); | 4772 error= (int)(sqrt(error)+0.5); |
4768 } | 4773 errors[level][orientation]= error; |
4769 error= (int)(sqrt(error)+0.5); | 4774 if(g) g=ff_gcd(g, error); |
4770 errors[level][orientation]= error; | 4775 else g= error; |
4771 if(g) g=ff_gcd(g, error); | 4776 } |
4772 else g= error; | 4777 } |
4773 } | 4778 printf("static int const visual_weight[][4]={\n"); |
4774 } | 4779 for(level=0; level<s.spatial_decomposition_count; level++){ |
4775 printf("static int const visual_weight[][4]={\n"); | 4780 printf(" {"); |
4776 for(level=0; level<s.spatial_decomposition_count; level++){ | 4781 for(orientation=0; orientation<4; orientation++){ |
4777 printf(" {"); | 4782 printf("%8"PRId64",", errors[level][orientation]/g); |
4778 for(orientation=0; orientation<4; orientation++){ | 4783 } |
4779 printf("%8"PRId64",", errors[level][orientation]/g); | 4784 printf("},\n"); |
4780 } | 4785 } |
4781 printf("},\n"); | 4786 printf("};\n"); |
4782 } | 4787 { |
4783 printf("};\n"); | |
4784 { | |
4785 int level=2; | 4788 int level=2; |
4786 int w= width >> (s.spatial_decomposition_count-level); | 4789 int w= width >> (s.spatial_decomposition_count-level); |
4787 //int h= height >> (s.spatial_decomposition_count-level); | 4790 //int h= height >> (s.spatial_decomposition_count-level); |
4788 int stride= width << (s.spatial_decomposition_count-level); | 4791 int stride= width << (s.spatial_decomposition_count-level); |
4789 DWTELEM *buf= buffer[0]; | 4792 DWTELEM *buf= buffer[0]; |
4816 error += d*d; | 4819 error += d*d; |
4817 if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9) printf("%8"PRId64" ", d); | 4820 if(FFABS(width/2-x)<9 && FFABS(height/2-y)<9) printf("%8"PRId64" ", d); |
4818 } | 4821 } |
4819 if(FFABS(height/2-y)<9) printf("\n"); | 4822 if(FFABS(height/2-y)<9) printf("\n"); |
4820 } | 4823 } |
4821 } | 4824 } |
4822 | 4825 |
4823 } | 4826 } |
4824 return 0; | 4827 return 0; |
4825 } | 4828 } |
4826 #endif /* TEST */ | 4829 #endif /* TEST */ |