summaryrefslogtreecommitdiff
path: root/kms++util/src/drawing.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'kms++util/src/drawing.cpp')
-rw-r--r--kms++util/src/drawing.cpp113
1 files changed, 49 insertions, 64 deletions
diff --git a/kms++util/src/drawing.cpp b/kms++util/src/drawing.cpp
index 3752f94..79e0d90 100644
--- a/kms++util/src/drawing.cpp
+++ b/kms++util/src/drawing.cpp
@@ -15,106 +15,91 @@ void draw_rgb_pixel(IFramebuffer& buf, unsigned x, unsigned y, RGB color)
switch (buf.format()) {
case PixelFormat::XRGB8888:
- case PixelFormat::ARGB8888:
- {
- uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
+ case PixelFormat::ARGB8888: {
+ uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
*p = color.argb8888();
break;
}
case PixelFormat::XBGR8888:
- case PixelFormat::ABGR8888:
- {
- uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
+ case PixelFormat::ABGR8888: {
+ uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
*p = color.abgr8888();
break;
}
case PixelFormat::RGBX8888:
- case PixelFormat::RGBA8888:
- {
- uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
+ case PixelFormat::RGBA8888: {
+ uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
*p = color.rgba8888();
break;
}
case PixelFormat::BGRX8888:
- case PixelFormat::BGRA8888:
- {
- uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
+ case PixelFormat::BGRA8888: {
+ uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
*p = color.bgra8888();
break;
}
case PixelFormat::XRGB2101010:
- case PixelFormat::ARGB2101010:
- {
- uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
+ case PixelFormat::ARGB2101010: {
+ uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
*p = color.argb2101010();
break;
}
case PixelFormat::XBGR2101010:
- case PixelFormat::ABGR2101010:
- {
- uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
+ case PixelFormat::ABGR2101010: {
+ uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
*p = color.abgr2101010();
break;
}
case PixelFormat::RGBX1010102:
- case PixelFormat::RGBA1010102:
- {
- uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
+ case PixelFormat::RGBA1010102: {
+ uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
*p = color.rgba1010102();
break;
}
case PixelFormat::BGRX1010102:
- case PixelFormat::BGRA1010102:
- {
- uint32_t *p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
+ case PixelFormat::BGRA1010102: {
+ uint32_t* p = (uint32_t*)(buf.map(0) + buf.stride(0) * y + x * 4);
*p = color.bgra1010102();
break;
}
- case PixelFormat::RGB888:
- {
- uint8_t *p = buf.map(0) + buf.stride(0) * y + x * 3;
+ case PixelFormat::RGB888: {
+ uint8_t* p = buf.map(0) + buf.stride(0) * y + x * 3;
p[0] = color.b;
p[1] = color.g;
p[2] = color.r;
break;
}
- case PixelFormat::BGR888:
- {
- uint8_t *p = buf.map(0) + buf.stride(0) * y + x * 3;
+ case PixelFormat::BGR888: {
+ uint8_t* p = buf.map(0) + buf.stride(0) * y + x * 3;
p[0] = color.r;
p[1] = color.g;
p[2] = color.b;
break;
}
- case PixelFormat::RGB332:
- {
- uint8_t *p = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x);
+ case PixelFormat::RGB332: {
+ uint8_t* p = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x);
*p = color.rgb332();
break;
}
- case PixelFormat::RGB565:
- {
- uint16_t *p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2);
+ case PixelFormat::RGB565: {
+ uint16_t* p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2);
*p = color.rgb565();
break;
}
- case PixelFormat::BGR565:
- {
- uint16_t *p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2);
+ case PixelFormat::BGR565: {
+ uint16_t* p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2);
*p = color.bgr565();
break;
}
case PixelFormat::XRGB4444:
- case PixelFormat::ARGB4444:
- {
- uint16_t *p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2);
+ case PixelFormat::ARGB4444: {
+ uint16_t* p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2);
*p = color.argb4444();
break;
}
case PixelFormat::XRGB1555:
- case PixelFormat::ARGB1555:
- {
- uint16_t *p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2);
+ case PixelFormat::ARGB1555: {
+ uint16_t* p = (uint16_t*)(buf.map(0) + buf.stride(0) * y + x * 2);
*p = color.argb1555();
break;
}
@@ -128,9 +113,9 @@ void draw_yuv444_pixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv)
if (x >= buf.width() || y >= buf.height())
throw runtime_error("attempt to draw outside the buffer");
- uint8_t *py = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x);
- uint8_t *pu = (uint8_t*)(buf.map(1) + buf.stride(1) * y + x);
- uint8_t *pv = (uint8_t*)(buf.map(2) + buf.stride(2) * y + x);
+ uint8_t* py = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x);
+ uint8_t* pu = (uint8_t*)(buf.map(1) + buf.stride(1) * y + x);
+ uint8_t* pv = (uint8_t*)(buf.map(2) + buf.stride(2) * y + x);
switch (buf.format()) {
case PixelFormat::YUV444:
@@ -153,7 +138,7 @@ void draw_yuv444_pixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv)
static void draw_yuv422_packed_macropixel(IFramebuffer& buf, unsigned x, unsigned y,
YUV yuv1, YUV yuv2)
{
- uint8_t *p = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x * 2);
+ uint8_t* p = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x * 2);
uint8_t y0 = yuv1.y;
uint8_t y1 = yuv2.y;
@@ -197,8 +182,8 @@ static void draw_yuv422_packed_macropixel(IFramebuffer& buf, unsigned x, unsigne
static void draw_yuv422_semiplanar_macropixel(IFramebuffer& buf, unsigned x, unsigned y,
YUV yuv1, YUV yuv2)
{
- uint8_t *py = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x);
- uint8_t *puv = (uint8_t*)(buf.map(1) + buf.stride(1) * y + x);
+ uint8_t* py = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x);
+ uint8_t* puv = (uint8_t*)(buf.map(1) + buf.stride(1) * y + x);
uint8_t y0 = yuv1.y;
uint8_t y1 = yuv2.y;
@@ -228,9 +213,9 @@ static void draw_yuv422_semiplanar_macropixel(IFramebuffer& buf, unsigned x, uns
static void draw_yuv422_planar_macropixel(IFramebuffer& buf, unsigned x, unsigned y,
YUV yuv1, YUV yuv2)
{
- uint8_t *py = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x);
- uint8_t *pu = (uint8_t*)(buf.map(1) + buf.stride(1) * y + x / 2);
- uint8_t *pv = (uint8_t*)(buf.map(2) + buf.stride(2) * y + x / 2);
+ uint8_t* py = (uint8_t*)(buf.map(0) + buf.stride(0) * y + x);
+ uint8_t* pu = (uint8_t*)(buf.map(1) + buf.stride(1) * y + x / 2);
+ uint8_t* pv = (uint8_t*)(buf.map(2) + buf.stride(2) * y + x / 2);
uint8_t y0 = yuv1.y;
uint8_t y1 = yuv2.y;
@@ -290,10 +275,10 @@ void draw_yuv422_macropixel(IFramebuffer& buf, unsigned x, unsigned y, YUV yuv1,
static void draw_yuv420_semiplanar_macropixel(IFramebuffer& buf, unsigned x, unsigned y,
YUV yuv1, YUV yuv2, YUV yuv3, YUV yuv4)
{
- uint8_t *py1 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 0) + x);
- uint8_t *py2 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 1) + x);
+ uint8_t* py1 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 0) + x);
+ uint8_t* py2 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 1) + x);
- uint8_t *puv = (uint8_t*)(buf.map(1) + buf.stride(1) * (y / 2) + x);
+ uint8_t* puv = (uint8_t*)(buf.map(1) + buf.stride(1) * (y / 2) + x);
uint8_t y0 = yuv1.y;
uint8_t y1 = yuv2.y;
@@ -329,11 +314,11 @@ static void draw_yuv420_semiplanar_macropixel(IFramebuffer& buf, unsigned x, uns
static void draw_yuv420_planar_macropixel(IFramebuffer& buf, unsigned x, unsigned y,
YUV yuv1, YUV yuv2, YUV yuv3, YUV yuv4)
{
- uint8_t *py1 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 0) + x);
- uint8_t *py2 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 1) + x);
+ uint8_t* py1 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 0) + x);
+ uint8_t* py2 = (uint8_t*)(buf.map(0) + buf.stride(0) * (y + 1) + x);
- uint8_t *pu = (uint8_t*)(buf.map(1) + buf.stride(1) * (y / 2) + x / 2);
- uint8_t *pv = (uint8_t*)(buf.map(2) + buf.stride(2) * (y / 2) + x / 2);
+ uint8_t* pu = (uint8_t*)(buf.map(1) + buf.stride(1) * (y / 2) + x / 2);
+ uint8_t* pv = (uint8_t*)(buf.map(2) + buf.stride(2) * (y / 2) + x / 2);
uint8_t y0 = yuv1.y;
uint8_t y1 = yuv2.y;
@@ -391,7 +376,7 @@ void draw_yuv420_macropixel(IFramebuffer& buf, unsigned x, unsigned y,
}
}
-void draw_rect(IFramebuffer &fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color)
+void draw_rect(IFramebuffer& fb, uint32_t x, uint32_t y, uint32_t w, uint32_t h, RGB color)
{
unsigned i, j;
YUV yuvcolor = color.yuv();
@@ -565,8 +550,8 @@ static void draw_char(IFramebuffer& buf, uint32_t xpos, uint32_t ypos, char c, R
void draw_text(IFramebuffer& buf, uint32_t x, uint32_t y, const string& str, RGB color)
{
- for(unsigned i = 0; i < str.size(); i++)
+ for (unsigned i = 0; i < str.size(); i++)
draw_char(buf, (x + 8 * i), y, str[i], color);
}
-}
+} // namespace kms