Add support for YVYU and VYUY
authorTomi Valkeinen <tomi.valkeinen@iki.fi>
Thu, 8 Oct 2015 16:12:24 +0000 (19:12 +0300)
committerTomi Valkeinen <tomi.valkeinen@iki.fi>
Thu, 8 Oct 2015 16:12:24 +0000 (19:12 +0300)
libkms++/dumbframebuffer.cpp
libkms++/pixelformats.h
libkmstest/testpat.cpp

index cb815dacfca96093ce67f585a733a3a86f11c40d..f422081536acb883d65fc767e7cef65698ab0391 100644 (file)
@@ -55,6 +55,8 @@ static const map<PixelFormat, FormatInfo> format_info_array = {
        /* YUV packed */
        { PixelFormat::UYVY, { 1, { { 32, 2, 1 } }, } },
        { PixelFormat::YUYV, { 1, { { 32, 2, 1 } }, } },
+       { PixelFormat::YVYU, { 1, { { 32, 2, 1 } }, } },
+       { PixelFormat::VYUY, { 1, { { 32, 2, 1 } }, } },
        /* YUV semi-planar */
        { PixelFormat::NV12, { 2, { { 8, 1, 1, }, { 16, 2, 2 } }, } },
        /* RGB16 */
index 6741ea4583f5c173b04b43817332d1f8abc330ce..4432cace7c542e179de52790ac0493c4c0fe9b39 100644 (file)
@@ -11,8 +11,12 @@ enum class PixelFormat : uint32_t
 {
        NV12 = MakeFourCC("NV12"),
        NV21 = MakeFourCC("NV21"),
+
        UYVY = MakeFourCC("UYVY"),
        YUYV = MakeFourCC("YUYV"),
+       YVYU = MakeFourCC("YVYU"),
+       VYUY = MakeFourCC("VYUY"),
+
        XRGB8888 = MakeFourCC("XR24"),
        XBGR8888 = MakeFourCC("XB24"),
        RGB565 = MakeFourCC("RG16"),
index f621b911da772f96c456dcd5e43d4c6da6b78452..5c6766045a935ccc4c7b34c35ef2dc8e48ec66eb 100644 (file)
@@ -40,6 +40,9 @@ static void draw_pixel(DumbFramebuffer& buf, unsigned x, unsigned y, RGB color)
                break;
        }
        case PixelFormat::UYVY:
+       case PixelFormat::YUYV:
+       case PixelFormat::YVYU:
+       case PixelFormat::VYUY:
        {
                if ((x & 1) == 0) {
                        c1 = color;
@@ -51,28 +54,38 @@ static void draw_pixel(DumbFramebuffer& buf, unsigned x, unsigned y, RGB color)
                YUV yuv1 = c1.yuv();
                YUV yuv2 = color.yuv();
 
-               p[0] = (yuv1.u + yuv2.u) / 2;
-               p[1] = yuv1.y;
-               p[2] = (yuv1.v + yuv2.v) / 2;
-               p[3] = yuv2.y;
-               break;
-       }
-       case PixelFormat::YUYV:
-       {
-               if ((x & 1) == 0) {
-                       c1 = color;
-                       return;
+               switch (buf.format()) {
+               case PixelFormat::UYVY:
+                       p[0] = (yuv1.u + yuv2.u) / 2;
+                       p[1] = yuv1.y;
+                       p[2] = (yuv1.v + yuv2.v) / 2;
+                       p[3] = yuv2.y;
+                       break;
+
+               case PixelFormat::YUYV:
+                       p[0] = yuv1.y;
+                       p[1] = (yuv1.u + yuv2.u) / 2;
+                       p[2] = yuv2.y;
+                       p[3] = (yuv1.v + yuv2.v) / 2;
+                       break;
+
+               case PixelFormat::YVYU:
+                       p[0] = yuv1.y;
+                       p[1] = (yuv1.v + yuv2.v) / 2;
+                       p[2] = yuv2.y;
+                       p[3] = (yuv1.u + yuv2.u) / 2;
+                       break;
+
+               case PixelFormat::VYUY:
+                       p[0] = (yuv1.v + yuv2.v) / 2;
+                       p[1] = yuv1.y;
+                       p[2] = (yuv1.u + yuv2.u) / 2;
+                       p[3] = yuv2.y;
+                       break;
+               default:
+                       break;
                }
 
-               uint8_t *p = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x * 2);
-
-               YUV yuv1 = c1.yuv();
-               YUV yuv2 = color.yuv();
-
-               p[0] = yuv1.y;
-               p[1] = (yuv1.u + yuv2.u) / 2;
-               p[2] = yuv2.y;
-               p[3] = (yuv1.v + yuv2.v) / 2;
                break;
        }
        default: