[PATCH] Make ff_fill_linesize() use the information stored in av_pix_fmt_descriptors.

Stefano Sabatini stefano.sabatini-lala
Fri Mar 5 01:13:39 CET 2010


Allow simplification and a more generic implementation.
---
 libavcodec/imgconvert.c |  117 ++++++++++-------------------------------------
 1 files changed, 25 insertions(+), 92 deletions(-)

diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index ea5914d..5bb79f8 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -468,103 +468,36 @@ int ff_set_systematic_pal(uint32_t pal[256], enum PixelFormat pix_fmt){
 
 int ff_fill_linesize(AVPicture *picture, enum PixelFormat pix_fmt, int width)
 {
-    int w2;
-    const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
+    int i;
+    int max_plane_step     [4];
+    int max_plane_step_comp[4];
 
+    const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
     memset(picture->linesize, 0, sizeof(picture->linesize));
 
-    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:
-        w2 = (width + (1 << desc->log2_chroma_w) - 1) >> desc->log2_chroma_w;
-        picture->linesize[0] = width;
-        picture->linesize[1] = w2;
-        picture->linesize[2] = w2;
-        break;
-    case PIX_FMT_YUV420P16LE:
-    case PIX_FMT_YUV422P16LE:
-    case PIX_FMT_YUV444P16LE:
-    case PIX_FMT_YUV420P16BE:
-    case PIX_FMT_YUV422P16BE:
-    case PIX_FMT_YUV444P16BE:
-        w2 = (width + (1 << desc->log2_chroma_w) - 1) >> desc->log2_chroma_w;
-        picture->linesize[0] = 2*width;
-        picture->linesize[1] = 2*w2;
-        picture->linesize[2] = 2*w2;
-        break;
-    case PIX_FMT_YUVA420P:
-        w2 = (width + (1 << desc->log2_chroma_w) - 1) >> desc->log2_chroma_w;
-        picture->linesize[0] = width;
-        picture->linesize[1] = w2;
-        picture->linesize[2] = w2;
-        picture->linesize[3] = width;
-        break;
-    case PIX_FMT_NV12:
-    case PIX_FMT_NV21:
-        w2 = (width + (1 << desc->log2_chroma_w) - 1) >> desc->log2_chroma_w;
-        picture->linesize[0] = width;
-        picture->linesize[1] = 2 * w2;
-        break;
-    case PIX_FMT_RGB24:
-    case PIX_FMT_BGR24:
-        picture->linesize[0] = width * 3;
-        break;
-    case PIX_FMT_ARGB:
-    case PIX_FMT_ABGR:
-    case PIX_FMT_RGBA:
-    case PIX_FMT_BGRA:
-        picture->linesize[0] = width * 4;
-        break;
-    case PIX_FMT_RGB48BE:
-    case PIX_FMT_RGB48LE:
-        picture->linesize[0] = width * 6;
-        break;
-    case PIX_FMT_GRAY16BE:
-    case PIX_FMT_GRAY16LE:
-    case PIX_FMT_BGR555BE:
-    case PIX_FMT_BGR555LE:
-    case PIX_FMT_BGR565BE:
-    case PIX_FMT_BGR565LE:
-    case PIX_FMT_RGB555BE:
-    case PIX_FMT_RGB555LE:
-    case PIX_FMT_RGB565BE:
-    case PIX_FMT_RGB565LE:
-    case PIX_FMT_YUYV422:
-        picture->linesize[0] = width * 2;
-        break;
-    case PIX_FMT_UYVY422:
-        picture->linesize[0] = width * 2;
-        break;
-    case PIX_FMT_UYYVYY411:
-        picture->linesize[0] = width + width/2;
-        break;
-    case PIX_FMT_RGB4:
-    case PIX_FMT_BGR4:
-        picture->linesize[0] = width / 2;
-        break;
-    case PIX_FMT_MONOWHITE:
-    case PIX_FMT_MONOBLACK:
-        picture->linesize[0] = (width + 7) >> 3;
-        break;
-    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:
-        picture->linesize[0] = width;
-        break;
-    default:
+    if (desc->flags & PIX_FMT_HWACCEL)
         return -1;
+
+    if (desc->flags & PIX_FMT_BITSTREAM) {
+        picture->linesize[0] = ((width - 1) * (desc->comp[0].step_minus1+1) + 8) >> 3;
+        return 0;
     }
+
+    memset(max_plane_step     , 0, sizeof(max_plane_step     ));
+    memset(max_plane_step_comp, 0, sizeof(max_plane_step_comp));
+    for (i = 0; i < 4; i++) {
+        const AVComponentDescriptor *comp = &(desc->comp[i]);
+        if ((comp->step_minus1+1) > max_plane_step[comp->plane]) {
+            max_plane_step     [comp->plane] = comp->step_minus1+1;
+            max_plane_step_comp[comp->plane] = i;
+        }
+    }
+
+    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;
+    }
+
     return 0;
 }
 
-- 
1.6.6.1


--eHhjakXzOLJAF9wJ--



More information about the ffmpeg-devel mailing list