libkmstest: cleanup colors and add xbgr8888 support
authorTomi Valkeinen <tomi.valkeinen@ti.com>
Wed, 7 Oct 2015 07:30:23 +0000 (10:30 +0300)
committerTomi Valkeinen <tomi.valkeinen@ti.com>
Wed, 7 Oct 2015 07:30:23 +0000 (10:30 +0300)
libkmstest/color.cpp
libkmstest/color.h
libkmstest/colorbar.cpp
libkmstest/testpat.cpp

index b5b90019646b6b244bf5b70e1c5495cae8acecc0..4d4a7414a37f8f06967b5755a5566d9487856832 100644 (file)
@@ -15,12 +15,19 @@ RGB::RGB(uint8_t r, uint8_t g, uint8_t b)
        this->a = 0;
 }
 
+uint32_t RGB::rgb888() const
+{
+       return (r << 16) | (g << 8) | (b << 0);
+}
+
+uint32_t RGB::bgr888() const
+{
+       return (b << 16) | (g << 8) | (r << 0);
+}
+
 uint16_t RGB::rgb565() const
 {
-       uint16_t r = (this->r >> 3) << 11;
-       uint16_t g = (this->g >> 2) << 5;
-       uint16_t b = (this->b >> 3) << 0;
-       return r | g | b;
+       return ((r >> 3) << 11) | ((g >> 2) << 5) | ((b >> 3) << 0);
 }
 
 YUV RGB::yuv() const
index 1db47e8a930be9ddb7d72ea25a33cd4a7ff2fc5d..f84fc689d6c0d28406b6acfac2d55a87977648bb 100644 (file)
@@ -11,19 +11,17 @@ struct RGB
        RGB();
        RGB(uint8_t r, uint8_t g, uint8_t b);
 
+       uint32_t rgb888() const;
+       uint32_t bgr888() const;
        uint16_t rgb565() const;
        YUV yuv() const;
 
-       union {
-               struct
-               {
-                       uint8_t b;
-                       uint8_t g;
-                       uint8_t r;
-                       uint8_t a;
-               };
-
-               uint32_t raw;
+       struct
+       {
+               uint8_t b;
+               uint8_t g;
+               uint8_t r;
+               uint8_t a;
        };
 };
 
@@ -33,16 +31,12 @@ struct YUV
        YUV(uint8_t y, uint8_t u, uint8_t v);
        YUV(const RGB& rgb);
 
-       union {
-               struct
-               {
-                       uint8_t v;
-                       uint8_t u;
-                       uint8_t y;
-                       uint8_t a;
-               };
-
-               uint32_t raw;
+       struct
+       {
+               uint8_t v;
+               uint8_t u;
+               uint8_t y;
+               uint8_t a;
        };
 };
 }
index 31a4510fc3fa63401393d00139bf2bcdb4682c53..c1b6c16588d2656100eec0f0db69d9b7b0da1e6c 100644 (file)
@@ -49,7 +49,7 @@ static void drm_draw_color_bar_rgb888(DumbFramebuffer& buf, int old_xpos, int xp
                }
 
                for (int x = xpos; x < xpos + width; ++x)
-                       line[x] = bcol.raw;
+                       line[x] = bcol.rgb888();
        }
 }
 
index c8188d8a00b2e56d00834d49c24c3be3b5f4ba0b..f621b911da772f96c456dcd5e43d4c6da6b78452 100644 (file)
@@ -24,7 +24,13 @@ static void draw_pixel(DumbFramebuffer& buf, unsigned x, unsigned y, RGB color)
        case PixelFormat::XRGB8888:
        {
                uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
-               *p = color.raw;
+               *p = color.rgb888();
+               break;
+       }
+       case PixelFormat::XBGR8888:
+       {
+               uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
+               *p = color.bgr888();
                break;
        }
        case PixelFormat::RGB565: