Mercurial > libavcodec.hg
comparison snow.c @ 6412:1f70d64c00bc libavcodec
cosmetics: spelling/grammar
author | diego |
---|---|
date | Tue, 26 Feb 2008 17:06:31 +0000 |
parents | 7f615bfc21a2 |
children | c58ea608e191 |
comparison
equal
deleted
inserted
replaced
6411:5d50e8a7eb09 | 6412:1f70d64c00bc |
---|---|
404 typedef struct SubBand{ | 404 typedef struct SubBand{ |
405 int level; | 405 int level; |
406 int stride; | 406 int stride; |
407 int width; | 407 int width; |
408 int height; | 408 int height; |
409 int qlog; ///< log(qscale)/log[2^(1/6)] | 409 int qlog; ///< log(qscale)/log[2^(1/6)] |
410 DWTELEM *buf; | 410 DWTELEM *buf; |
411 IDWTELEM *ibuf; | 411 IDWTELEM *ibuf; |
412 int buf_x_offset; | 412 int buf_x_offset; |
413 int buf_y_offset; | 413 int buf_y_offset; |
414 int stride_line; ///< Stride measured in lines, not pixels. | 414 int stride_line; ///< Stride measured in lines, not pixels. |
431 int8_t last_hcoeff[HTAPS_MAX/2]; | 431 int8_t last_hcoeff[HTAPS_MAX/2]; |
432 int last_diag_mc; | 432 int last_diag_mc; |
433 }Plane; | 433 }Plane; |
434 | 434 |
435 typedef struct SnowContext{ | 435 typedef struct SnowContext{ |
436 // MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to make the motion estimation eventually independent of MpegEncContext, so this will be removed then (FIXME/XXX) | 436 // MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to eventually make the motion estimation independent of MpegEncContext, so this will be removed then (FIXME/XXX) |
437 | 437 |
438 AVCodecContext *avctx; | 438 AVCodecContext *avctx; |
439 RangeCoder c; | 439 RangeCoder c; |
440 DSPContext dsp; | 440 DSPContext dsp; |
441 AVFrame new_picture; | 441 AVFrame new_picture; |
485 #define ME_CACHE_SIZE 1024 | 485 #define ME_CACHE_SIZE 1024 |
486 int me_cache[ME_CACHE_SIZE]; | 486 int me_cache[ME_CACHE_SIZE]; |
487 int me_cache_generation; | 487 int me_cache_generation; |
488 slice_buffer sb; | 488 slice_buffer sb; |
489 | 489 |
490 MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to make the motion estimation eventually independent of MpegEncContext, so this will be removed then (FIXME/XXX) | 490 MpegEncContext m; // needed for motion estimation, should not be used for anything else, the idea is to eventually make the motion estimation independent of MpegEncContext, so this will be removed then (FIXME/XXX) |
491 }SnowContext; | 491 }SnowContext; |
492 | 492 |
493 typedef struct { | 493 typedef struct { |
494 IDWTELEM *b0; | 494 IDWTELEM *b0; |
495 IDWTELEM *b1; | 495 IDWTELEM *b1; |
2414 } | 2414 } |
2415 } | 2415 } |
2416 } | 2416 } |
2417 } | 2417 } |
2418 | 2418 |
2419 //FIXME name clenup (b_w, block_w, b_width stuff) | 2419 //FIXME name cleanup (b_w, block_w, b_width stuff) |
2420 static av_always_inline void add_yblock(SnowContext *s, int sliced, slice_buffer *sb, IDWTELEM *dst, uint8_t *dst8, const uint8_t *obmc, int src_x, int src_y, int b_w, int b_h, int w, int h, int dst_stride, int src_stride, int obmc_stride, int b_x, int b_y, int add, int offset_dst, int plane_index){ | 2420 static av_always_inline void add_yblock(SnowContext *s, int sliced, slice_buffer *sb, IDWTELEM *dst, uint8_t *dst8, const uint8_t *obmc, int src_x, int src_y, int b_w, int b_h, int w, int h, int dst_stride, int src_stride, int obmc_stride, int b_x, int b_y, int add, int offset_dst, int plane_index){ |
2421 const int b_width = s->b_width << s->block_max_depth; | 2421 const int b_width = s->b_width << s->block_max_depth; |
2422 const int b_height= s->b_height << s->block_max_depth; | 2422 const int b_height= s->b_height << s->block_max_depth; |
2423 const int b_stride= b_width; | 2423 const int b_stride= b_width; |
2424 BlockNode *lt= &s->block[b_x + b_y*b_stride]; | 2424 BlockNode *lt= &s->block[b_x + b_y*b_stride]; |
2444 }else if(b_y + 1 >= b_height){ | 2444 }else if(b_y + 1 >= b_height){ |
2445 lb= lt; | 2445 lb= lt; |
2446 rb= rt; | 2446 rb= rt; |
2447 } | 2447 } |
2448 | 2448 |
2449 if(src_x<0){ //FIXME merge with prev & always round internal width upto *16 | 2449 if(src_x<0){ //FIXME merge with prev & always round internal width up to *16 |
2450 obmc -= src_x; | 2450 obmc -= src_x; |
2451 b_w += src_x; | 2451 b_w += src_x; |
2452 if(!sliced && !offset_dst) | 2452 if(!sliced && !offset_dst) |
2453 dst -= src_x; | 2453 dst -= src_x; |
2454 src_x=0; | 2454 src_x=0; |
2728 int d; | 2728 int d; |
2729 if(y<0) obmc_v += obmc[index + block_w*obmc_stride]; | 2729 if(y<0) obmc_v += obmc[index + block_w*obmc_stride]; |
2730 if(x<0) obmc_v += obmc[index + block_w]; | 2730 if(x<0) obmc_v += obmc[index + block_w]; |
2731 if(y+block_w>h) obmc_v += obmc[index - block_w*obmc_stride]; | 2731 if(y+block_w>h) obmc_v += obmc[index - block_w*obmc_stride]; |
2732 if(x+block_w>w) obmc_v += obmc[index - block_w]; | 2732 if(x+block_w>w) obmc_v += obmc[index - block_w]; |
2733 //FIXME precalc this or simplify it somehow else | 2733 //FIXME precalculate this or simplify it somehow else |
2734 | 2734 |
2735 d = -dst[index] + (1<<(FRAC_BITS-1)); | 2735 d = -dst[index] + (1<<(FRAC_BITS-1)); |
2736 dst[index] = d; | 2736 dst[index] = d; |
2737 ab += (src[x2 + y2*ref_stride] - (d>>FRAC_BITS)) * obmc_v; | 2737 ab += (src[x2 + y2*ref_stride] - (d>>FRAC_BITS)) * obmc_v; |
2738 aa += obmc_v * obmc_v; //FIXME precalclate this | 2738 aa += obmc_v * obmc_v; //FIXME precalculate this |
2739 } | 2739 } |
2740 } | 2740 } |
2741 } | 2741 } |
2742 *b= backup; | 2742 *b= backup; |
2743 | 2743 |
2765 001XX 3-6 2-3 | 2765 001XX 3-6 2-3 |
2766 0001XXX 7-14 4-7 | 2766 0001XXX 7-14 4-7 |
2767 00001XXXX 15-30 8-15 | 2767 00001XXXX 15-30 8-15 |
2768 */ | 2768 */ |
2769 //FIXME try accurate rate | 2769 //FIXME try accurate rate |
2770 //FIXME intra and inter predictors if surrounding blocks arent the same type | 2770 //FIXME intra and inter predictors if surrounding blocks are not the same type |
2771 if(b->type & BLOCK_INTRA){ | 2771 if(b->type & BLOCK_INTRA){ |
2772 return 3+2*( av_log2(2*FFABS(left->color[0] - b->color[0])) | 2772 return 3+2*( av_log2(2*FFABS(left->color[0] - b->color[0])) |
2773 + av_log2(2*FFABS(left->color[1] - b->color[1])) | 2773 + av_log2(2*FFABS(left->color[1] - b->color[1])) |
2774 + av_log2(2*FFABS(left->color[2] - b->color[2]))); | 2774 + av_log2(2*FFABS(left->color[2] - b->color[2]))); |
2775 }else{ | 2775 }else{ |
2844 } | 2844 } |
2845 | 2845 |
2846 if(block_w==16){ | 2846 if(block_w==16){ |
2847 /* FIXME rearrange dsputil to fit 32x32 cmp functions */ | 2847 /* FIXME rearrange dsputil to fit 32x32 cmp functions */ |
2848 /* FIXME check alignment of the cmp wavelet vs the encoding wavelet */ | 2848 /* FIXME check alignment of the cmp wavelet vs the encoding wavelet */ |
2849 /* FIXME cmps overlap but don't cover the wavelet's whole support, | 2849 /* FIXME cmps overlap but do not cover the wavelet's whole support. |
2850 * so improving the score of one block is not strictly guaranteed to | 2850 * So improving the score of one block is not strictly guaranteed |
2851 * improve the score of the whole frame, so iterative motion est | 2851 * to improve the score of the whole frame, thus iterative motion |
2852 * doesn't always converge. */ | 2852 * estimation does not always converge. */ |
2853 if(s->avctx->me_cmp == FF_CMP_W97) | 2853 if(s->avctx->me_cmp == FF_CMP_W97) |
2854 distortion = w97_32_c(&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); | 2854 distortion = w97_32_c(&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); |
2855 else if(s->avctx->me_cmp == FF_CMP_W53) | 2855 else if(s->avctx->me_cmp == FF_CMP_W53) |
2856 distortion = w53_32_c(&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); | 2856 distortion = w53_32_c(&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); |
2857 else{ | 2857 else{ |
2980 *block= backup; | 2980 *block= backup; |
2981 return 0; | 2981 return 0; |
2982 } | 2982 } |
2983 } | 2983 } |
2984 | 2984 |
2985 /* special case for int[2] args we discard afterward, fixes compilation prob with gcc 2.95 */ | 2985 /* special case for int[2] args we discard afterwards, |
2986 * fixes compilation problem with gcc 2.95 */ | |
2986 static av_always_inline int check_block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, const uint8_t *obmc_edged, int *best_rd){ | 2987 static av_always_inline int check_block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, const uint8_t *obmc_edged, int *best_rd){ |
2987 int p[2] = {p0, p1}; | 2988 int p[2] = {p0, p1}; |
2988 return check_block(s, mb_x, mb_y, p, 0, obmc_edged, best_rd); | 2989 return check_block(s, mb_x, mb_y, p, 0, obmc_edged, best_rd); |
2989 } | 2990 } |
2990 | 2991 |
3072 | 3073 |
3073 if(!s->me_cache_generation) | 3074 if(!s->me_cache_generation) |
3074 memset(s->me_cache, 0, sizeof(s->me_cache)); | 3075 memset(s->me_cache, 0, sizeof(s->me_cache)); |
3075 s->me_cache_generation += 1<<22; | 3076 s->me_cache_generation += 1<<22; |
3076 | 3077 |
3077 //FIXME precalc | 3078 //FIXME precalculate |
3078 { | 3079 { |
3079 int x, y; | 3080 int x, y; |
3080 memcpy(obmc_edged, obmc_tab[s->block_max_depth], b_w*b_w*4); | 3081 memcpy(obmc_edged, obmc_tab[s->block_max_depth], b_w*b_w*4); |
3081 if(mb_x==0) | 3082 if(mb_x==0) |
3082 for(y=0; y<b_w*2; y++) | 3083 for(y=0; y<b_w*2; y++) |
3155 check_block_inter(s, mb_x, mb_y, mvr[1][0], mvr[1][1], *obmc_edged, &best_rd); | 3156 check_block_inter(s, mb_x, mb_y, mvr[1][0], mvr[1][1], *obmc_edged, &best_rd); |
3156 if(bb) | 3157 if(bb) |
3157 check_block_inter(s, mb_x, mb_y, mvr[b_stride][0], mvr[b_stride][1], *obmc_edged, &best_rd); | 3158 check_block_inter(s, mb_x, mb_y, mvr[b_stride][0], mvr[b_stride][1], *obmc_edged, &best_rd); |
3158 | 3159 |
3159 /* fullpel ME */ | 3160 /* fullpel ME */ |
3160 //FIXME avoid subpel interpol / round to nearest integer | 3161 //FIXME avoid subpel interpolation / round to nearest integer |
3161 do{ | 3162 do{ |
3162 dia_change=0; | 3163 dia_change=0; |
3163 for(i=0; i<FFMAX(s->avctx->dia_size, 1); i++){ | 3164 for(i=0; i<FFMAX(s->avctx->dia_size, 1); i++){ |
3164 for(j=0; j<i; j++){ | 3165 for(j=0; j<i; j++){ |
3165 dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+4*(i-j), block->my+(4*j), *obmc_edged, &best_rd); | 3166 dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+4*(i-j), block->my+(4*j), *obmc_edged, &best_rd); |
3698 | 3699 |
3699 width= s->avctx->width; | 3700 width= s->avctx->width; |
3700 height= s->avctx->height; | 3701 height= s->avctx->height; |
3701 | 3702 |
3702 s->spatial_idwt_buffer= av_mallocz(width*height*sizeof(IDWTELEM)); | 3703 s->spatial_idwt_buffer= av_mallocz(width*height*sizeof(IDWTELEM)); |
3703 s->spatial_dwt_buffer= av_mallocz(width*height*sizeof(DWTELEM)); //FIXME this doesnt belong here | 3704 s->spatial_dwt_buffer= av_mallocz(width*height*sizeof(DWTELEM)); //FIXME this does not belong here |
3704 | 3705 |
3705 for(i=0; i<MAX_REF_FRAMES; i++) | 3706 for(i=0; i<MAX_REF_FRAMES; i++) |
3706 for(j=0; j<MAX_REF_FRAMES; j++) | 3707 for(j=0; j<MAX_REF_FRAMES; j++) |
3707 scale_mv_ref[i][j] = 256*(i+1)/(j+1); | 3708 scale_mv_ref[i][j] = 256*(i+1)/(j+1); |
3708 | 3709 |
3769 + 61*QROOT/8; //<64 >60 | 3770 + 61*QROOT/8; //<64 >60 |
3770 } | 3771 } |
3771 | 3772 |
3772 static int ratecontrol_1pass(SnowContext *s, AVFrame *pict) | 3773 static int ratecontrol_1pass(SnowContext *s, AVFrame *pict) |
3773 { | 3774 { |
3774 /* estimate the frame's complexity as a sum of weighted dwt coefs. | 3775 /* Estimate the frame's complexity as a sum of weighted dwt coefficients. |
3775 * FIXME we know exact mv bits at this point, | 3776 * FIXME we know exact mv bits at this point, |
3776 * but ratecontrol isn't set up to include them. */ | 3777 * but ratecontrol isn't set up to include them. */ |
3777 uint32_t coef_sum= 0; | 3778 uint32_t coef_sum= 0; |
3778 int level, orientation, delta_qlog; | 3779 int level, orientation, delta_qlog; |
3779 | 3780 |
3862 if(orientation&1) | 3863 if(orientation&1) |
3863 xo= step>>1; | 3864 xo= step>>1; |
3864 if(orientation&2) | 3865 if(orientation&2) |
3865 yo= step>>1; | 3866 yo= step>>1; |
3866 | 3867 |
3867 //FIXME bias for non zero ? | 3868 //FIXME bias for nonzero ? |
3868 //FIXME optimize | 3869 //FIXME optimize |
3869 memset(score, 0, sizeof(*score)*score_stride*((p->height + Q2_STEP-1)/Q2_STEP)); | 3870 memset(score, 0, sizeof(*score)*score_stride*((p->height + Q2_STEP-1)/Q2_STEP)); |
3870 for(y=0; y<p->height; y++){ | 3871 for(y=0; y<p->height; y++){ |
3871 for(x=0; x<p->width; x++){ | 3872 for(x=0; x<p->width; x++){ |
3872 int sx= (x-xo + step/2) / step / Q2_STEP; | 3873 int sx= (x-xo + step/2) / step / Q2_STEP; |
3910 for(level=0; level<s->spatial_decomposition_count; level++){ | 3911 for(level=0; level<s->spatial_decomposition_count; level++){ |
3911 for(orientation=level ? 1 : 0; orientation<4; orientation++){ | 3912 for(orientation=level ? 1 : 0; orientation<4; orientation++){ |
3912 SubBand *b= &p->band[level][orientation]; | 3913 SubBand *b= &p->band[level][orientation]; |
3913 IDWTELEM *dst= best_dequant + (b->ibuf - s->spatial_idwt_buffer); | 3914 IDWTELEM *dst= best_dequant + (b->ibuf - s->spatial_idwt_buffer); |
3914 DWTELEM *src= buffer + (b-> buf - s->spatial_dwt_buffer); | 3915 DWTELEM *src= buffer + (b-> buf - s->spatial_dwt_buffer); |
3915 assert(src == b->buf); // code doesnt depen on this but its true currently | 3916 assert(src == b->buf); // code does not depend on this but it is true currently |
3916 | 3917 |
3917 quantize(s, b, dst, src, b->stride, s->qbias); | 3918 quantize(s, b, dst, src, b->stride, s->qbias); |
3918 } | 3919 } |
3919 } | 3920 } |
3920 for(pass=0; pass<1; pass++){ | 3921 for(pass=0; pass<1; pass++){ |
3935 memcpy(idwt2_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); | 3936 memcpy(idwt2_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); |
3936 for(y=ys; y<b->height; y+= Q2_STEP){ | 3937 for(y=ys; y<b->height; y+= Q2_STEP){ |
3937 for(x=xs; x<b->width; x+= Q2_STEP){ | 3938 for(x=xs; x<b->width; x+= Q2_STEP){ |
3938 if(dst[x + y*b->stride]<0) dst[x + y*b->stride]++; | 3939 if(dst[x + y*b->stride]<0) dst[x + y*b->stride]++; |
3939 if(dst[x + y*b->stride]>0) dst[x + y*b->stride]--; | 3940 if(dst[x + y*b->stride]>0) dst[x + y*b->stride]--; |
3940 //FIXME try more then just -- | 3941 //FIXME try more than just -- |
3941 } | 3942 } |
3942 } | 3943 } |
3943 dequantize_all(s, p, idwt2_buffer, width, height); | 3944 dequantize_all(s, p, idwt2_buffer, width, height); |
3944 ff_spatial_idwt(idwt2_buffer, width, height, stride, type, s->spatial_decomposition_count); | 3945 ff_spatial_idwt(idwt2_buffer, width, height, stride, type, s->spatial_decomposition_count); |
3945 find_sse(s, p, score, score_stride, idwt2_buffer, s->spatial_idwt_buffer, level, orientation); | 3946 find_sse(s, p, score, score_stride, idwt2_buffer, s->spatial_idwt_buffer, level, orientation); |
3957 } | 3958 } |
3958 } | 3959 } |
3959 } | 3960 } |
3960 } | 3961 } |
3961 } | 3962 } |
3962 memcpy(s->spatial_idwt_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); //FIXME work with that directly insteda of copy at the end | 3963 memcpy(s->spatial_idwt_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); //FIXME work with that directly instead of copy at the end |
3963 } | 3964 } |
3964 | 3965 |
3965 #endif /* QUANTIZE2==1 */ | 3966 #endif /* QUANTIZE2==1 */ |
3966 | 3967 |
3967 static int encode_init(AVCodecContext *avctx) | 3968 static int encode_init(AVCodecContext *avctx) |
3968 { | 3969 { |
3969 SnowContext *s = avctx->priv_data; | 3970 SnowContext *s = avctx->priv_data; |
3970 int plane_index; | 3971 int plane_index; |
3971 | 3972 |
3972 if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){ | 3973 if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){ |
3973 av_log(avctx, AV_LOG_ERROR, "this codec is under development, files encoded with it may not be decodable with future versions!!!\n" | 3974 av_log(avctx, AV_LOG_ERROR, "This codec is under development, files encoded with it may not be decodable with future versions!!!\n" |
3974 "use vstrict=-2 / -strict -2 to use it anyway\n"); | 3975 "Use vstrict=-2 / -strict -2 to use it anyway.\n"); |
3975 return -1; | 3976 return -1; |
3976 } | 3977 } |
3977 | 3978 |
3978 if(avctx->prediction_method == DWT_97 | 3979 if(avctx->prediction_method == DWT_97 |
3979 && (avctx->flags & CODEC_FLAG_QSCALE) | 3980 && (avctx->flags & CODEC_FLAG_QSCALE) |
3980 && avctx->global_quality == 0){ | 3981 && avctx->global_quality == 0){ |
3981 av_log(avctx, AV_LOG_ERROR, "the 9/7 wavelet is incompatible with lossless mode\n"); | 3982 av_log(avctx, AV_LOG_ERROR, "The 9/7 wavelet is incompatible with lossless mode.\n"); |
3982 return -1; | 3983 return -1; |
3983 } | 3984 } |
3984 | 3985 |
3985 s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type | 3986 s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type |
3986 | 3987 |
4195 s->lambda = pict->quality * 3/2; | 4196 s->lambda = pict->quality * 3/2; |
4196 } | 4197 } |
4197 if(s->qlog < 0 || (!pict->quality && (avctx->flags & CODEC_FLAG_QSCALE))){ | 4198 if(s->qlog < 0 || (!pict->quality && (avctx->flags & CODEC_FLAG_QSCALE))){ |
4198 s->qlog= LOSSLESS_QLOG; | 4199 s->qlog= LOSSLESS_QLOG; |
4199 s->lambda = 0; | 4200 s->lambda = 0; |
4200 }//else keep previous frame's qlog until after motion est | 4201 }//else keep previous frame's qlog until after motion estimation |
4201 | 4202 |
4202 frame_start(s); | 4203 frame_start(s); |
4203 | 4204 |
4204 s->m.current_picture_ptr= &s->m.current_picture; | 4205 s->m.current_picture_ptr= &s->m.current_picture; |
4205 if(pict->pict_type == P_TYPE){ | 4206 if(pict->pict_type == P_TYPE){ |
4506 } | 4507 } |
4507 | 4508 |
4508 if(!s->block) alloc_blocks(s); | 4509 if(!s->block) alloc_blocks(s); |
4509 | 4510 |
4510 frame_start(s); | 4511 frame_start(s); |
4511 //keyframe flag dupliaction mess FIXME | 4512 //keyframe flag duplication mess FIXME |
4512 if(avctx->debug&FF_DEBUG_PICT_INFO) | 4513 if(avctx->debug&FF_DEBUG_PICT_INFO) |
4513 av_log(avctx, AV_LOG_ERROR, "keyframe:%d qlog:%d\n", s->keyframe, s->qlog); | 4514 av_log(avctx, AV_LOG_ERROR, "keyframe:%d qlog:%d\n", s->keyframe, s->qlog); |
4514 | 4515 |
4515 decode_blocks(s); | 4516 decode_blocks(s); |
4516 | 4517 |