[FFmpeg-devel] 8bpp planar crop patch

Stefano Sabatini stefano.sabatini-lala
Thu Nov 26 21:16:57 CET 2009


On date Thursday 2009-11-26 20:53:09 +0200, Teemu Keinonen encoded:
> Hi, I'm hoping to get this patch for 8bpp planar pixel formats cropping to
> ffmpeg trunk.
> 
> I made it to crop flashsv encoded videos.
> 
> --Teemu Keinonen

> Index: libavcodec/imgconvert.c
> ===================================================================
> --- libavcodec/imgconvert.c	(revision 20598)
> +++ libavcodec/imgconvert.c	(working copy)
> @@ -1317,19 +1317,27 @@
>      int y_shift;
>      int x_shift;
>  
> -    if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB || !is_yuv_planar(&pix_fmt_info[pix_fmt]))
> +    if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB)
>          return -1;
>  
> -    y_shift = pix_fmt_info[pix_fmt].y_chroma_shift;
> -    x_shift = pix_fmt_info[pix_fmt].x_chroma_shift;
> +    if (!is_yuv_planar(&pix_fmt_info[pix_fmt])) {
> +        if (pix_fmt_info[pix_fmt].depth != 8)
> +            return -1;
> +        dst->data[0] = src->data[0]+src->linesize[0]*top_band+(left_band*pix_fmt_info[pix_fmt].nb_channels);
> +        dst->linesize[0] = src->linesize[0];
> +    }
> +    else {
> +        y_shift = pix_fmt_info[pix_fmt].y_chroma_shift;
> +        x_shift = pix_fmt_info[pix_fmt].x_chroma_shift;
>  
> -    dst->data[0] = src->data[0] + (top_band * src->linesize[0]) + left_band;
> -    dst->data[1] = src->data[1] + ((top_band >> y_shift) * src->linesize[1]) + (left_band >> x_shift);
> -    dst->data[2] = src->data[2] + ((top_band >> y_shift) * src->linesize[2]) + (left_band >> x_shift);
> +        dst->data[0] = src->data[0] + (top_band * src->linesize[0]) + left_band;
> +        dst->data[1] = src->data[1] + ((top_band >> y_shift) * src->linesize[1]) + (left_band >> x_shift);
> +        dst->data[2] = src->data[2] + ((top_band >> y_shift) * src->linesize[2]) + (left_band >> x_shift);
>  
> -    dst->linesize[0] = src->linesize[0];
> -    dst->linesize[1] = src->linesize[1];
> -    dst->linesize[2] = src->linesize[2];
> +        dst->linesize[0] = src->linesize[0];
> +        dst->linesize[1] = src->linesize[1];
> +        dst->linesize[2] = src->linesize[2];
> +    }
>      return 0;
>  }

The cropping code in imgconvert.c is going to be deprecated, check the
libavfilter crop filter which does already what you want, also your
patch doesn't apply anymore.

Regards.
-- 
FFmpeg = Fantastic and Forgiving Mystic Perennial Elastic Geek



More information about the ffmpeg-devel mailing list