[PATCH 2/2] 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 |  119 +++++++++-------------------------------------
 1 files changed, 24 insertions(+), 95 deletions(-)

diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index e525930..63471b7 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -492,107 +492,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;
+    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));
 
-    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_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:
-        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.7.0


--7JfCtLOvnd9MIVvH
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="imgconvert-test.diff"

--- imgconvert-test.ref	2010-04-04 23:50:35.000000000 +0200
+++ imgconvert-test.test	2010-04-04 23:53:37.000000000 +0200
@@ -65,7 +65,7 @@
 bgr444be[0]: 0 0 0 0
 bgr444le[0]: 0 0 0 0
 yuv420p[1]: 1 1 1 0
-yuyv422[1]: 2 0 0 0
+yuyv422[1]: 4 0 0 0
 rgb24[1]: 3 0 0 0
 bgr24[1]: 3 0 0 0
 yuv422p[1]: 1 1 1 0
@@ -81,13 +81,13 @@
 yuvj444p[1]: 1 1 1 0
 xvmcmc[1]: 0 0 0 0
 xvmcidct[1]: 0 0 0 0
-uyvy422[1]: 2 0 0 0
-uyyvyy411[1]: 1 0 0 0
+uyvy422[1]: 4 0 0 0
+uyyvyy411[1]: 6 0 0 0
 bgr8[1]: 1 0 0 0
-bgr4[1]: 0 0 0 0
+bgr4[1]: 1 0 0 0
 bgr4_byte[1]: 1 0 0 0
 rgb8[1]: 1 0 0 0
-rgb4[1]: 0 0 0 0
+rgb4[1]: 1 0 0 0
 rgb4_byte[1]: 1 0 0 0
 nv12[1]: 1 2 0 0
 nv21[1]: 1 2 0 0
@@ -148,7 +148,7 @@
 xvmcmc[2]: 0 0 0 0
 xvmcidct[2]: 0 0 0 0
 uyvy422[2]: 4 0 0 0
-uyyvyy411[2]: 3 0 0 0
+uyyvyy411[2]: 6 0 0 0
 bgr8[2]: 2 0 0 0
 bgr4[2]: 1 0 0 0
 bgr4_byte[2]: 2 0 0 0
@@ -197,7 +197,7 @@
 bgr444be[2]: 4 0 0 0
 bgr444le[2]: 4 0 0 0
 yuv420p[3]: 3 2 2 0
-yuyv422[3]: 6 0 0 0
+yuyv422[3]: 8 0 0 0
 rgb24[3]: 9 0 0 0
 bgr24[3]: 9 0 0 0
 yuv422p[3]: 3 2 2 0
@@ -213,13 +213,13 @@
 yuvj444p[3]: 3 3 3 0
 xvmcmc[3]: 0 0 0 0
 xvmcidct[3]: 0 0 0 0
-uyvy422[3]: 6 0 0 0
-uyyvyy411[3]: 4 0 0 0
+uyvy422[3]: 8 0 0 0
+uyyvyy411[3]: 6 0 0 0
 bgr8[3]: 3 0 0 0
-bgr4[3]: 1 0 0 0
+bgr4[3]: 2 0 0 0
 bgr4_byte[3]: 3 0 0 0
 rgb8[3]: 3 0 0 0
-rgb4[3]: 1 0 0 0
+rgb4[3]: 2 0 0 0
 rgb4_byte[3]: 3 0 0 0
 nv12[3]: 3 4 0 0
 nv21[3]: 3 4 0 0
@@ -346,7 +346,7 @@
 xvmcmc[234]: 0 0 0 0
 xvmcidct[234]: 0 0 0 0
 uyvy422[234]: 468 0 0 0
-uyyvyy411[234]: 351 0 0 0
+uyyvyy411[234]: 354 0 0 0
 bgr8[234]: 234 0 0 0
 bgr4[234]: 117 0 0 0
 bgr4_byte[234]: 234 0 0 0
@@ -412,7 +412,7 @@
 xvmcmc[434234]: 0 0 0 0
 xvmcidct[434234]: 0 0 0 0
 uyvy422[434234]: 868468 0 0 0
-uyyvyy411[434234]: 651351 0 0 0
+uyyvyy411[434234]: 651354 0 0 0
 bgr8[434234]: 434234 0 0 0
 bgr4[434234]: 217117 0 0 0
 bgr4_byte[434234]: 434234 0 0 0
@@ -478,7 +478,7 @@
 xvmcmc[2]: 0 0 0 0
 xvmcidct[2]: 0 0 0 0
 uyvy422[2]: 4 0 0 0
-uyyvyy411[2]: 3 0 0 0
+uyyvyy411[2]: 6 0 0 0
 bgr8[2]: 2 0 0 0
 bgr4[2]: 1 0 0 0
 bgr4_byte[2]: 2 0 0 0
@@ -593,7 +593,7 @@
 bgr444be[0]: 0 0 0 0
 bgr444le[0]: 0 0 0 0
 yuv420p[25]: 25 13 13 0
-yuyv422[25]: 50 0 0 0
+yuyv422[25]: 52 0 0 0
 rgb24[25]: 75 0 0 0
 bgr24[25]: 75 0 0 0
 yuv422p[25]: 25 13 13 0
@@ -609,13 +609,13 @@
 yuvj444p[25]: 25 25 25 0
 xvmcmc[25]: 0 0 0 0
 xvmcidct[25]: 0 0 0 0
-uyvy422[25]: 50 0 0 0
-uyyvyy411[25]: 37 0 0 0
+uyvy422[25]: 52 0 0 0
+uyyvyy411[25]: 42 0 0 0
 bgr8[25]: 25 0 0 0
-bgr4[25]: 12 0 0 0
+bgr4[25]: 13 0 0 0
 bgr4_byte[25]: 25 0 0 0
 rgb8[25]: 25 0 0 0
-rgb4[25]: 12 0 0 0
+rgb4[25]: 13 0 0 0
 rgb4_byte[25]: 25 0 0 0
 nv12[25]: 25 26 0 0
 nv21[25]: 25 26 0 0
@@ -659,7 +659,7 @@
 bgr444be[25]: 50 0 0 0
 bgr444le[25]: 50 0 0 0
 yuv420p[27]: 27 14 14 0
-yuyv422[27]: 54 0 0 0
+yuyv422[27]: 56 0 0 0
 rgb24[27]: 81 0 0 0
 bgr24[27]: 81 0 0 0
 yuv422p[27]: 27 14 14 0
@@ -675,13 +675,13 @@
 yuvj444p[27]: 27 27 27 0
 xvmcmc[27]: 0 0 0 0
 xvmcidct[27]: 0 0 0 0
-uyvy422[27]: 54 0 0 0
-uyyvyy411[27]: 40 0 0 0
+uyvy422[27]: 56 0 0 0
+uyyvyy411[27]: 42 0 0 0
 bgr8[27]: 27 0 0 0
-bgr4[27]: 13 0 0 0
+bgr4[27]: 14 0 0 0
 bgr4_byte[27]: 27 0 0 0
 rgb8[27]: 27 0 0 0
-rgb4[27]: 13 0 0 0
+rgb4[27]: 14 0 0 0
 rgb4_byte[27]: 27 0 0 0
 nv12[27]: 27 28 0 0
 nv21[27]: 27 28 0 0
@@ -791,7 +791,7 @@
 bgr444be[124]: 248 0 0 0
 bgr444le[124]: 248 0 0 0
 yuv420p[2345]: 2345 1173 1173 0
-yuyv422[2345]: 4690 0 0 0
+yuyv422[2345]: 4692 0 0 0
 rgb24[2345]: 7035 0 0 0
 bgr24[2345]: 7035 0 0 0
 yuv422p[2345]: 2345 1173 1173 0
@@ -807,13 +807,13 @@
 yuvj444p[2345]: 2345 2345 2345 0
 xvmcmc[2345]: 0 0 0 0
 xvmcidct[2345]: 0 0 0 0
-uyvy422[2345]: 4690 0 0 0
-uyyvyy411[2345]: 3517 0 0 0
+uyvy422[2345]: 4692 0 0 0
+uyyvyy411[2345]: 3522 0 0 0
 bgr8[2345]: 2345 0 0 0
-bgr4[2345]: 1172 0 0 0
+bgr4[2345]: 1173 0 0 0
 bgr4_byte[2345]: 2345 0 0 0
 rgb8[2345]: 2345 0 0 0
-rgb4[2345]: 1172 0 0 0
+rgb4[2345]: 1173 0 0 0
 rgb4_byte[2345]: 2345 0 0 0
 nv12[2345]: 2345 2346 0 0
 nv21[2345]: 2345 2346 0 0
@@ -923,7 +923,7 @@
 bgr444be[23556]: 47112 0 0 0
 bgr444le[23556]: 47112 0 0 0
 yuv420p[234545]: 234545 117273 117273 0
-yuyv422[234545]: 469090 0 0 0
+yuyv422[234545]: 469092 0 0 0
 rgb24[234545]: 703635 0 0 0
 bgr24[234545]: 703635 0 0 0
 yuv422p[234545]: 234545 117273 117273 0
@@ -939,13 +939,13 @@
 yuvj444p[234545]: 234545 234545 234545 0
 xvmcmc[234545]: 0 0 0 0
 xvmcidct[234545]: 0 0 0 0
-uyvy422[234545]: 469090 0 0 0
-uyyvyy411[234545]: 351817 0 0 0
+uyvy422[234545]: 469092 0 0 0
+uyyvyy411[234545]: 351822 0 0 0
 bgr8[234545]: 234545 0 0 0
-bgr4[234545]: 117272 0 0 0
+bgr4[234545]: 117273 0 0 0
 bgr4_byte[234545]: 234545 0 0 0
 rgb8[234545]: 234545 0 0 0
-rgb4[234545]: 117272 0 0 0
+rgb4[234545]: 117273 0 0 0
 rgb4_byte[234545]: 234545 0 0 0
 nv12[234545]: 234545 234546 0 0
 nv21[234545]: 234545 234546 0 0

--7JfCtLOvnd9MIVvH--



More information about the ffmpeg-devel mailing list