summaryrefslogtreecommitdiff
path: root/libkmstest
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ti.com>2016-03-08 15:27:27 +0200
committerTomi Valkeinen <tomi.valkeinen@ti.com>2016-03-08 15:42:47 +0200
commita41cbe24c45975aab44389e7e894582ee2622806 (patch)
tree2a12638e08a0f64b1714e7792f2cacb07f0b4c81 /libkmstest
parent3f0a0230676d9d38ec677f88143222ffd70a9f7d (diff)
libkmstest: color & draw_rect
Diffstat (limited to 'libkmstest')
-rw-r--r--libkmstest/color.cpp19
-rw-r--r--libkmstest/color.h28
-rw-r--r--libkmstest/colorbar.cpp2
-rw-r--r--libkmstest/kmstest.h5
-rw-r--r--libkmstest/testpat.cpp20
5 files changed, 52 insertions, 22 deletions
diff --git a/libkmstest/color.cpp b/libkmstest/color.cpp
index 78012ac..3ad8203 100644
--- a/libkmstest/color.cpp
+++ b/libkmstest/color.cpp
@@ -9,19 +9,32 @@ RGB::RGB()
}
RGB::RGB(uint8_t r, uint8_t g, uint8_t b)
+ :RGB(255, r, g, b)
+{
+}
+
+RGB::RGB(uint8_t a, uint8_t r, uint8_t g, uint8_t b)
{
this->r = r;
this->g = g;
this->b = b;
- this->a = 255;
+ this->a = a;
+}
+
+RGB::RGB(uint32_t argb)
+{
+ this->b = (argb >> 0) & 0xff;
+ this->g = (argb >> 8) & 0xff;
+ this->r = (argb >> 16) & 0xff;
+ this->a = (argb >> 24) & 0xff;
}
-uint32_t RGB::rgb888() const
+uint32_t RGB::argb8888() const
{
return (a << 24) | (r << 16) | (g << 8) | (b << 0);
}
-uint32_t RGB::bgr888() const
+uint32_t RGB::abgr8888() const
{
return (a << 24) | (b << 16) | (g << 8) | (r << 0);
}
diff --git a/libkmstest/color.h b/libkmstest/color.h
index f84fc68..f99a951 100644
--- a/libkmstest/color.h
+++ b/libkmstest/color.h
@@ -10,19 +10,18 @@ struct RGB
{
RGB();
RGB(uint8_t r, uint8_t g, uint8_t b);
+ RGB(uint8_t a, uint8_t r, uint8_t g, uint8_t b);
+ RGB(uint32_t argb);
- uint32_t rgb888() const;
- uint32_t bgr888() const;
+ uint32_t argb8888() const;
+ uint32_t abgr8888() const;
uint16_t rgb565() const;
YUV yuv() const;
- struct
- {
- uint8_t b;
- uint8_t g;
- uint8_t r;
- uint8_t a;
- };
+ uint8_t b;
+ uint8_t g;
+ uint8_t r;
+ uint8_t a;
};
struct YUV
@@ -31,12 +30,9 @@ struct YUV
YUV(uint8_t y, uint8_t u, uint8_t v);
YUV(const RGB& rgb);
- struct
- {
- uint8_t v;
- uint8_t u;
- uint8_t y;
- uint8_t a;
- };
+ uint8_t v;
+ uint8_t u;
+ uint8_t y;
+ uint8_t a;
};
}
diff --git a/libkmstest/colorbar.cpp b/libkmstest/colorbar.cpp
index c1b6c16..811b81c 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.rgb888();
+ line[x] = bcol.argb8888();
}
}
diff --git a/libkmstest/kmstest.h b/libkmstest/kmstest.h
index 0482072..0564ab5 100644
--- a/libkmstest/kmstest.h
+++ b/libkmstest/kmstest.h
@@ -1,5 +1,7 @@
#pragma once
+#include "color.h"
+
namespace kms
{
class MappedBuffer;
@@ -9,4 +11,7 @@ void draw_color_bar(kms::DumbFramebuffer& buf, int old_xpos, int xpos, int width
void draw_test_pattern(MappedBuffer& fb);
void draw_test_pattern(DumbFramebuffer &fb);
+
+void draw_rect(MappedBuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color);
+void draw_rect(DumbFramebuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color);
}
diff --git a/libkmstest/testpat.cpp b/libkmstest/testpat.cpp
index 33a4ec1..059c1bc 100644
--- a/libkmstest/testpat.cpp
+++ b/libkmstest/testpat.cpp
@@ -26,14 +26,14 @@ static void draw_rgb_pixel(MappedBuffer& buf, unsigned x, unsigned y, RGB color)
case PixelFormat::ARGB8888:
{
uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
- *p = color.rgb888();
+ *p = color.argb8888();
break;
}
case PixelFormat::XBGR8888:
case PixelFormat::ABGR8888:
{
uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
- *p = color.bgr888();
+ *p = color.abgr8888();
break;
}
case PixelFormat::RGB565:
@@ -290,4 +290,20 @@ void draw_test_pattern(MappedBuffer &fb)
printf("draw took %u us\n", (unsigned)time_span.count());
#endif
}
+
+void draw_rect(MappedBuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color)
+{
+ for (unsigned i = x; i < x + w; ++i) {
+ for (unsigned j = y; j < y + h; ++j) {
+ draw_rgb_pixel(fb, i, j, color);
+ }
+ }
+}
+
+void draw_rect(DumbFramebuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color)
+{
+ MappedDumbBuffer mfb(fb);
+ draw_rect(mfb, x, y, w, h, color);
+}
+
}