[FFmpeg-devel] [PATCH 1/1] Reimplement ff_fill_pointer() using the information stored in the pixdescs.
Stefano Sabatini
stefano.sabatini-lala
Fri Jul 23 15:25:31 CEST 2010
The new implementation is more compact, and does not need to be
updated at each pixel format addition.
---
libavcodec/imgconvert.c | 125 +++++++++++------------------------------------
1 files changed, 29 insertions(+), 96 deletions(-)
diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index 68f1a75..87df0e8 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -528,105 +528,38 @@ int ff_fill_linesize(AVPicture *picture, enum PixelFormat pix_fmt, int width)
int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, enum PixelFormat pix_fmt,
int height)
{
- int size, h2, size2;
+ int i, total_size, size[4], has_plane[4];
+
const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
+ memset(picture->data, 0, sizeof(picture->linesize));
+ memset(size, 0, sizeof(size));
+ memset(has_plane, 0, sizeof(has_plane));
- size = picture->linesize[0] * height;
- switch(pix_fmt) {
- case PIX_FMT_YUV420P:
- case PIX_FMT_YUV422P:
- case PIX_FMT_YUV444P:
- case PIX_FMT_YUV410P:
- case PIX_FMT_YUV411P:
- case PIX_FMT_YUV440P:
- case PIX_FMT_YUVJ420P:
- case PIX_FMT_YUVJ422P:
- case PIX_FMT_YUVJ444P:
- case PIX_FMT_YUVJ440P:
- case PIX_FMT_YUV420P16LE:
- case PIX_FMT_YUV422P16LE:
- case PIX_FMT_YUV444P16LE:
- case PIX_FMT_YUV420P16BE:
- 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;
- 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;
- 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;
- return size + size2;
- case PIX_FMT_RGB24:
- case PIX_FMT_BGR24:
- case PIX_FMT_ARGB:
- case PIX_FMT_ABGR:
- case PIX_FMT_RGBA:
- case PIX_FMT_BGRA:
- case PIX_FMT_RGB48BE:
- case PIX_FMT_RGB48LE:
- case PIX_FMT_GRAY16BE:
- case PIX_FMT_GRAY16LE:
- case PIX_FMT_BGR444BE:
- case PIX_FMT_BGR444LE:
- case PIX_FMT_BGR555BE:
- case PIX_FMT_BGR555LE:
- case PIX_FMT_BGR565BE:
- case PIX_FMT_BGR565LE:
- case PIX_FMT_RGB444BE:
- case PIX_FMT_RGB444LE:
- case PIX_FMT_RGB555BE:
- case PIX_FMT_RGB555LE:
- case PIX_FMT_RGB565BE:
- case PIX_FMT_RGB565LE:
- case PIX_FMT_YUYV422:
- case PIX_FMT_UYVY422:
- case PIX_FMT_UYYVYY411:
- case PIX_FMT_RGB4:
- case PIX_FMT_BGR4:
- 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;
- return size;
- case PIX_FMT_PAL8:
- case PIX_FMT_RGB8:
- case PIX_FMT_BGR8:
- case PIX_FMT_RGB4_BYTE:
- 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;
- return size2 + 256 * 4;
- default:
- picture->data[0] = NULL;
- picture->data[1] = NULL;
- picture->data[2] = NULL;
- picture->data[3] = NULL;
- return -1;
+ if (desc->flags & PIX_FMT_HWACCEL)
+ return AVERROR(EINVAL);
+
+ picture->data[0] = ptr;
+ size[0] = picture->linesize[0] * height;
+
+ if (desc->flags & PIX_FMT_PAL) {
+ size[0] = (size[0] + 3) & ~3;
+ picture->data[1] = ptr + size[0]; /* palette is stored here as 256 32 bits words */
+ return size[0] + 256 * 4;
}
+
+ for (i = 0; i < 4; i++)
+ has_plane[desc->comp[i].plane] = 1;
+
+ total_size = size[0];
+ for (i = 1; has_plane[i] && i < 4; i++) {
+ int h, s = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;
+ picture->data[i] = picture->data[i-1] + size[i-1];
+ h = (height + (1 << s) - 1) >> s;
+ size[i] = h * picture->linesize[i];
+ total_size += size[i];
+ }
+
+ return total_size;
}
int avpicture_fill(AVPicture *picture, uint8_t *ptr,
--
1.6.3.3
More information about the ffmpeg-devel
mailing list