[PATCH] Add avpicture_layout test.

Stefano Sabatini stefano.sabatini-lala
Sun Nov 7 22:52:02 CET 2010


---
 libavcodec/imgconvert.c |   98 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 98 insertions(+), 0 deletions(-)

diff --git a/libavcodec/imgconvert.c b/libavcodec/imgconvert.c
index 10c5f64..ff8f86b 100644
--- a/libavcodec/imgconvert.c
+++ b/libavcodec/imgconvert.c
@@ -1174,3 +1174,101 @@ int avpicture_deinterlace(AVPicture *dst, const AVPicture *src,
     return 0;
 }
 
+#ifdef TEST
+
+#undef printf
+
+static void avpicture_layout_test(enum PixelFormat pix_fmt, int width, int height)
+{
+    const PixFmtInfo* pf = &pix_fmt_info[pix_fmt];
+    const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
+    int i, w, ow, h, oh, data_planes;
+    int size = avpicture_get_size(pix_fmt, width, height);
+    if (size < 0)
+        return;
+
+    printf("%s\n", desc->name);
+
+    if (pf->pixel_type == FF_PIXEL_PACKED || pf->pixel_type == FF_PIXEL_PALETTE) {
+        if (pix_fmt == PIX_FMT_YUYV422 ||
+            pix_fmt == PIX_FMT_UYVY422 ||
+            pix_fmt == PIX_FMT_BGR565BE ||
+            pix_fmt == PIX_FMT_BGR565LE ||
+            pix_fmt == PIX_FMT_BGR555BE ||
+            pix_fmt == PIX_FMT_BGR555LE ||
+            pix_fmt == PIX_FMT_BGR444BE ||
+            pix_fmt == PIX_FMT_BGR444LE ||
+            pix_fmt == PIX_FMT_RGB565BE ||
+            pix_fmt == PIX_FMT_RGB565LE ||
+            pix_fmt == PIX_FMT_RGB555BE ||
+            pix_fmt == PIX_FMT_RGB555LE ||
+            pix_fmt == PIX_FMT_RGB444BE ||
+            pix_fmt == PIX_FMT_RGB444LE)
+            w = width * 2;
+        else if (pix_fmt == PIX_FMT_UYYVYY411)
+            w = width + width/2;
+        else if (pix_fmt == PIX_FMT_PAL8)
+            w = width;
+        else
+            w = width * (pf->depth * pf->nb_channels / 8);
+
+        data_planes = 1;
+        h = height;
+    } else {
+        data_planes = pf->nb_channels;
+        w = (width*pf->depth + 7)/8;
+        h = height;
+    }
+
+    ow = w;
+    oh = h;
+
+    for (i=0; i<data_planes; i++) {
+        if (i == 1) {
+            w = (- ((-width) >> desc->log2_chroma_w) * pf->depth + 7) / 8;
+            h = -((-height) >> desc->log2_chroma_h);
+            if (pix_fmt == PIX_FMT_NV12 || pix_fmt == PIX_FMT_NV21)
+                w <<= 1;
+        } else if (i == 3) {
+            w = ow;
+            h = oh;
+        }
+        printf("\tplane:%d w:%d h:%d\n", i, w, h);
+    }
+}
+
+static void avpicture_layout_test2(enum PixelFormat pix_fmt, int width, int height)
+{
+    int i, nb_planes = 0;
+    int linesizes[4];
+    const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt];
+
+    if (desc->flags & PIX_FMT_HWACCEL)
+        return;
+    printf("%s\n", desc->name);
+
+    for (i = 0; i < desc->nb_components; i++)
+        nb_planes = FFMAX(desc->comp[i].plane, nb_planes);
+    nb_planes++;
+
+    av_image_fill_linesizes(linesizes, pix_fmt, width);
+    for (i = 0; i < nb_planes; i++) {
+        int h, s = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;
+        h = (height + (1 << s) - 1) >> s;
+        printf("\tplane:%d w:%d h:%d\n", i, linesizes[i], h);
+    }
+}
+
+int main(void)
+{
+    int i, w = 103, h = 103;
+
+    for (i = 0; i < PIX_FMT_NB; i++) {
+        avpicture_layout_test(i, w, h);
+        avpicture_layout_test2(i, w, h);
+    }
+
+    return 0;
+}
+
+#endif
-- 
1.7.1


--G4iJoqBmSsgzjUCe
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="layout_test12.diff"

--- layout_test1.txt	2010-11-19 00:50:18.000000000 +0100
+++ layout_test2.txt	2010-11-19 00:54:54.000000000 +0100
@@ -3,7 +3,7 @@
 	plane:1 w:52 h:52
 	plane:2 w:52 h:52
 yuyv422
-	plane:0 w:206 h:103
+	plane:0 w:208 h:103
 rgb24
 	plane:0 w:309 h:103
 bgr24
@@ -45,19 +45,19 @@
 	plane:1 w:103 h:103
 	plane:2 w:103 h:103
 uyvy422
-	plane:0 w:206 h:103
+	plane:0 w:208 h:103
 uyyvyy411
-	plane:0 w:154 h:103
+	plane:0 w:156 h:103
 bgr8
 	plane:0 w:103 h:103
 bgr4
-	plane:0 w:0 h:103
+	plane:0 w:52 h:103
 bgr4_byte
 	plane:0 w:103 h:103
 rgb8
 	plane:0 w:103 h:103
 rgb4
-	plane:0 w:0 h:103
+	plane:0 w:52 h:103
 rgb4_byte
 	plane:0 w:103 h:103
 nv12
@@ -144,3 +144,4 @@
 bgr444le
 	plane:0 w:206 h:103
 y400a
+	plane:0 w:206 h:103

--G4iJoqBmSsgzjUCe--



More information about the ffmpeg-devel mailing list