[FFmpeg-devel] [PATCH] Define ff_fill_image_linesize, ff_fill_image_data_ptr and make existing ff_fill* wrap these.

Stefano Sabatini stefano.sabatini-lala
Mon Jul 26 00:33:40 CEST 2010


On date Sunday 2010-07-25 15:24:10 -0700, S.N. Hemanth Meenakshisundaram encoded:
> 
> Defines static functions ff_fill_image_linesize and
> ff_fill_image_data_ptr. ff_fill_linesize and ff_fill_pointer now wrap
> these functions
> 
> ---
> 
>  libavcodec/imgconvert.c |   79 ++++++++++++++++++++++++++--------------------
>  1 files changed, 45 insertions(+), 34 deletions(-)
> 
> 
> 

> diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
> index 8f789c4..f99f74d 100644
> --- a/libavcodec/imgconvert.c
> +++ b/libavcodec/imgconvert.c
> @@ -490,20 +490,20 @@ int ff_set_systematic_pal(uint32_t pal[256], enum PixelFormat pix_fmt){
>      return 0;
>  }
>  
> -int ff_fill_linesize(AVPicture *picture, enum PixelFormat pix_fmt, int width)
> +static int ff_fill_image_linesize(int linesize[4], enum PixelFormat pix_fmt, int width)
>  {
>      int i;
>      const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
>      int max_plane_step     [4];
>      int max_plane_step_comp[4];
>  
> -    memset(picture->linesize, 0, sizeof(picture->linesize));
> +    memset(linesize, 0, 4*sizeof(linesize[0]));
>  
>      if (desc->flags & PIX_FMT_HWACCEL)
>          return -1;
>  
>      if (desc->flags & PIX_FMT_BITSTREAM) {
> -        picture->linesize[0] = (width * (desc->comp[0].step_minus1+1) + 7) >> 3;
> +        linesize[0] = (width * (desc->comp[0].step_minus1+1) + 7) >> 3;
>          return 0;
>      }
>  
> @@ -519,19 +519,19 @@ int ff_fill_linesize(AVPicture *picture, enum PixelFormat pix_fmt, int width)
>  
>      for (i = 0; i < 4; i++) {
>          int s = (max_plane_step_comp[i] == 1 || max_plane_step_comp[i] == 2) ? desc->log2_chroma_w : 0;
> -        picture->linesize[i] = max_plane_step[i] * (((width + (1 << s) - 1)) >> s);
> +        linesize[i] = max_plane_step[i] * (((width + (1 << s) - 1)) >> s);
>      }
>  
>      return 0;
>  }
>  
> -int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, enum PixelFormat pix_fmt,
> -                    int height)
> +static int ff_fill_image_data_ptr(uint8_t *data[4], uint8_t *ptr, enum PixelFormat pix_fmt,
> +                           int height, const int linesize[4])
>  {
>      int size, h2, size2;
>      const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
>  
> -    size = picture->linesize[0] * height;
> +    size = linesize[0] * height;
>      switch(pix_fmt) {
>      case PIX_FMT_YUV420P:
>      case PIX_FMT_YUV422P:
> @@ -550,28 +550,28 @@ int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, enum PixelFormat pix_fmt,
>      case PIX_FMT_YUV422P16BE:
>      case PIX_FMT_YUV444P16BE:
>          h2 = (height + (1 << desc->log2_chroma_h) - 1) >> desc->log2_chroma_h;
> -        size2 = picture->linesize[1] * h2;
> -        picture->data[0] = ptr;
> -        picture->data[1] = picture->data[0] + size;
> -        picture->data[2] = picture->data[1] + size2;
> -        picture->data[3] = NULL;
> +        size2 = linesize[1] * h2;
> +        data[0] = ptr;
> +        data[1] = data[0] + size;
> +        data[2] = data[1] + size2;
> +        data[3] = NULL;
>          return size + 2 * size2;
>      case PIX_FMT_YUVA420P:
>          h2 = (height + (1 << desc->log2_chroma_h) - 1) >> desc->log2_chroma_h;
> -        size2 = picture->linesize[1] * h2;
> -        picture->data[0] = ptr;
> -        picture->data[1] = picture->data[0] + size;
> -        picture->data[2] = picture->data[1] + size2;
> -        picture->data[3] = picture->data[1] + size2 + size2;
> +        size2 = linesize[1] * h2;
> +        data[0] = ptr;
> +        data[1] = data[0] + size;
> +        data[2] = data[1] + size2;
> +        data[3] = data[1] + size2 + size2;
>          return 2 * size + 2 * size2;
>      case PIX_FMT_NV12:
>      case PIX_FMT_NV21:
>          h2 = (height + (1 << desc->log2_chroma_h) - 1) >> desc->log2_chroma_h;
> -        size2 = picture->linesize[1] * h2;
> -        picture->data[0] = ptr;
> -        picture->data[1] = picture->data[0] + size;
> -        picture->data[2] = NULL;
> -        picture->data[3] = NULL;
> +        size2 = linesize[1] * h2;
> +        data[0] = ptr;
> +        data[1] = data[0] + size;
> +        data[2] = NULL;
> +        data[3] = NULL;
>          return size + size2;
>      case PIX_FMT_RGB24:
>      case PIX_FMT_BGR24:
> @@ -603,10 +603,10 @@ int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, enum PixelFormat pix_fmt,
>      case PIX_FMT_MONOWHITE:
>      case PIX_FMT_MONOBLACK:
>      case PIX_FMT_Y400A:
> -        picture->data[0] = ptr;
> -        picture->data[1] = NULL;
> -        picture->data[2] = NULL;
> -        picture->data[3] = NULL;
> +        data[0] = ptr;
> +        data[1] = NULL;
> +        data[2] = NULL;
> +        data[3] = NULL;
>          return size;
>      case PIX_FMT_PAL8:
>      case PIX_FMT_RGB8:
> @@ -615,20 +615,31 @@ int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, enum PixelFormat pix_fmt,
>      case PIX_FMT_BGR4_BYTE:
>      case PIX_FMT_GRAY8:
>          size2 = (size + 3) & ~3;
> -        picture->data[0] = ptr;
> -        picture->data[1] = ptr + size2; /* palette is stored here as 256 32 bit words */
> -        picture->data[2] = NULL;
> -        picture->data[3] = NULL;
> +        data[0] = ptr;
> +        data[1] = ptr + size2; /* palette is stored here as 256 32 bit words */
> +        data[2] = NULL;
> +        data[3] = NULL;
>          return size2 + 256 * 4;
>      default:
> -        picture->data[0] = NULL;
> -        picture->data[1] = NULL;
> -        picture->data[2] = NULL;
> -        picture->data[3] = NULL;
> +        data[0] = NULL;
> +        data[1] = NULL;
> +        data[2] = NULL;
> +        data[3] = NULL;
>          return -1;
>      }
>  }
>  
> +int ff_fill_linesize(AVPicture *picture, enum PixelFormat pix_fmt, int width)
> +{
> +    return ff_fill_image_linesize(picture->linesize, pix_fmt, width);
> +}
> +
> +int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, enum PixelFormat pix_fmt,
> +                    int height)
> +{
> +    return ff_fill_image_data_ptr(picture->data, ptr, pix_fmt, height, picture->linesize);
> +}
> +
>  int avpicture_fill(AVPicture *picture, uint8_t *ptr,
>                     enum PixelFormat pix_fmt, int width, int height)
>  {

Looks fine to me, I assumed has been tested and passes make test.

Regards.
-- 
FFmpeg = Frightening and Fast Mastodontic Powerful Ecumenical Ghost



More information about the ffmpeg-devel mailing list