From 68c845cdba48bf0853fcd7bb7f9efe2623e24e9b Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Fri, 22 Jun 2012 15:17:33 +0200 Subject: snow: yuv444 support Signed-off-by: Michael Niedermayer --- libavcodec/snowdec.c | 53 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 22 deletions(-) (limited to 'libavcodec/snowdec.c') diff --git a/libavcodec/snowdec.c b/libavcodec/snowdec.c index a4d8d4e0d4..4a34cf8d14 100644 --- a/libavcodec/snowdec.c +++ b/libavcodec/snowdec.c @@ -41,9 +41,10 @@ static av_always_inline void predict_slice_buffered(SnowContext *s, slice_buffer const int mb_h= s->b_height << s->block_max_depth; int x, y, mb_x; int block_size = MB_SIZE >> s->block_max_depth; - int block_w = plane_index ? block_size/2 : block_size; - const uint8_t *obmc = plane_index ? ff_obmc_tab[s->block_max_depth+1] : ff_obmc_tab[s->block_max_depth]; - int obmc_stride= plane_index ? block_size : 2*block_size; + int block_w = plane_index ? block_size>>s->chroma_h_shift : block_size; + int block_h = plane_index ? block_size>>s->chroma_v_shift : block_size; + const uint8_t *obmc = plane_index ? ff_obmc_tab[s->block_max_depth+s->chroma_h_shift] : ff_obmc_tab[s->block_max_depth]; + int obmc_stride= plane_index ? (2*block_size)>>s->chroma_h_shift : 2*block_size; int ref_stride= s->current_picture.linesize[plane_index]; uint8_t *dst8= s->current_picture.data[plane_index]; int w= p->width; @@ -54,7 +55,7 @@ static av_always_inline void predict_slice_buffered(SnowContext *s, slice_buffer return; if(add){ - for(y=block_w*mb_y; yline[y]; for(x=0; xline[y]; for(x=0; xcolorspace_type= get_symbol(&s->c, s->header_state, 0); s->chroma_h_shift= get_symbol(&s->c, s->header_state, 0); s->chroma_v_shift= get_symbol(&s->c, s->header_state, 0); + + if(s->chroma_h_shift == 1 && s->chroma_v_shift==1){ + s->avctx->pix_fmt= PIX_FMT_YUV420P; + }else if(s->chroma_h_shift == 0 && s->chroma_v_shift==0){ + s->avctx->pix_fmt= PIX_FMT_YUV444P; + } else { + av_log(s, AV_LOG_ERROR, "unsupported color subsample mode %d %d\n", s->chroma_h_shift, s->chroma_v_shift); + s->chroma_h_shift = s->chroma_v_shift = 1; + s->avctx->pix_fmt= PIX_FMT_YUV420P; + return AVERROR_INVALIDDATA; + } + s->spatial_scalability= get_rac(&s->c, s->header_state); // s->rate_scalability= get_rac(&s->c, s->header_state); GET_S(s->max_ref_frames, tmp < (unsigned)MAX_REF_FRAMES) @@ -334,10 +347,6 @@ static int decode_header(SnowContext *s){ return -1; } - if (s->chroma_h_shift != 1 || s->chroma_v_shift != 1) { - av_log(s->avctx, AV_LOG_ERROR, "Invalid chroma shift\n"); - return AVERROR_PATCHWELCOME; - } s->qlog += get_symbol(&s->c, s->header_state, 1); s->mv_scale += get_symbol(&s->c, s->header_state, 1); @@ -354,8 +363,6 @@ static int decode_header(SnowContext *s){ static av_cold int decode_init(AVCodecContext *avctx) { - avctx->pix_fmt= PIX_FMT_YUV420P; - ff_snow_common_init(avctx); return 0; @@ -452,7 +459,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac { const int mb_h= s->b_height << s->block_max_depth; const int block_size = MB_SIZE >> s->block_max_depth; - const int block_w = plane_index ? block_size/2 : block_size; + const int block_w = plane_index ? block_size>>s->chroma_h_shift : block_size; + const int block_h = plane_index ? block_size>>s->chroma_v_shift : block_size; int mb_y; DWTCompose cs[MAX_DECOMPOSITIONS]; int yd=0, yq=0; @@ -462,11 +470,12 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac ff_spatial_idwt_buffered_init(cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count); for(mb_y=0; mb_y<=mb_h; mb_y++){ - int slice_starty = block_w*mb_y; - int slice_h = block_w*(mb_y+1); + int slice_starty = block_h*mb_y; + int slice_h = block_h*(mb_y+1); + if (!(s->keyframe || s->avctx->debug&512)){ - slice_starty = FFMAX(0, slice_starty - (block_w >> 1)); - slice_h -= (block_w >> 1); + slice_starty = FFMAX(0, slice_starty - (block_h >> 1)); + slice_h -= (block_h >> 1); } for(level=0; levelspatial_decomposition_count; level++){ @@ -477,11 +486,11 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac int our_mb_start = mb_y; int our_mb_end = (mb_y + 1); const int extra= 3; - start_y = (mb_y ? ((block_w * our_mb_start) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra: 0); - end_y = (((block_w * our_mb_end) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra); + start_y = (mb_y ? ((block_h * our_mb_start) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra: 0); + end_y = (((block_h * our_mb_end) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra); if (!(s->keyframe || s->avctx->debug&512)){ - start_y = FFMAX(0, start_y - (block_w >> (1+s->spatial_decomposition_count - level))); - end_y = FFMAX(0, end_y - (block_w >> (1+s->spatial_decomposition_count - level))); + start_y = FFMAX(0, start_y - (block_h >> (1+s->spatial_decomposition_count - level))); + end_y = FFMAX(0, end_y - (block_h >> (1+s->spatial_decomposition_count - level))); } start_y = FFMIN(b->height, start_y); end_y = FFMIN(b->height, end_y); -- cgit v1.2.1