summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libkmstest/color.cpp15
-rw-r--r--libkmstest/color.h34
-rw-r--r--libkmstest/colorbar.cpp2
-rw-r--r--libkmstest/testpat.cpp8
4 files changed, 33 insertions, 26 deletions
diff --git a/libkmstest/color.cpp b/libkmstest/color.cpp
index b5b9001..4d4a741 100644
--- a/libkmstest/color.cpp
+++ b/libkmstest/color.cpp
@@ -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
diff --git a/libkmstest/color.h b/libkmstest/color.h
index 1db47e8..f84fc68 100644
--- a/libkmstest/color.h
+++ b/libkmstest/color.h
@@ -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;
};
};
}
diff --git a/libkmstest/colorbar.cpp b/libkmstest/colorbar.cpp
index 31a4510..c1b6c16 100644
--- a/libkmstest/colorbar.cpp
+++ b/libkmstest/colorbar.cpp
@@ -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();
}
}
diff --git a/libkmstest/testpat.cpp b/libkmstest/testpat.cpp
index c8188d8..f621b91 100644
--- a/libkmstest/testpat.cpp
+++ b/libkmstest/testpat.cpp
@@ -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: