Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vg_lite): add ARGB1555 ARGB4444 ARGB2222 support #7028

Merged
merged 7 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/draw/vg_lite/lv_vg_lite_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ bool lv_vg_lite_is_dest_cf_supported(lv_color_format_t cf)
case LV_COLOR_FORMAT_RGB565:
case LV_COLOR_FORMAT_ARGB8888:
case LV_COLOR_FORMAT_XRGB8888:
case LV_COLOR_FORMAT_ARGB1555:
case LV_COLOR_FORMAT_ARGB4444:
case LV_COLOR_FORMAT_ARGB2222:
return true;

case LV_COLOR_FORMAT_ARGB8565:
Expand All @@ -425,6 +428,9 @@ bool lv_vg_lite_is_src_cf_supported(lv_color_format_t cf)
case LV_COLOR_FORMAT_RGB565:
case LV_COLOR_FORMAT_ARGB8888:
case LV_COLOR_FORMAT_XRGB8888:
case LV_COLOR_FORMAT_ARGB1555:
case LV_COLOR_FORMAT_ARGB4444:
case LV_COLOR_FORMAT_ARGB2222:
return true;

case LV_COLOR_FORMAT_I1:
Expand Down Expand Up @@ -476,6 +482,15 @@ vg_lite_buffer_format_t lv_vg_lite_vg_fmt(lv_color_format_t cf)
case LV_COLOR_FORMAT_I8:
return VG_LITE_INDEX_8;

case LV_COLOR_FORMAT_ARGB1555:
return VG_LITE_BGRA5551;

case LV_COLOR_FORMAT_ARGB4444:
return VG_LITE_BGRA4444;

case LV_COLOR_FORMAT_ARGB2222:
return VG_LITE_BGRA2222;

case LV_COLOR_FORMAT_RGB565:
return VG_LITE_BGR565;

Expand Down
6 changes: 6 additions & 0 deletions src/misc/lv_color.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ uint8_t lv_color_format_get_bpp(lv_color_format_t cf)
case LV_COLOR_FORMAT_L8:
case LV_COLOR_FORMAT_A8:
case LV_COLOR_FORMAT_I8:
case LV_COLOR_FORMAT_ARGB2222:
return 8;

case LV_COLOR_FORMAT_RGB565A8:
case LV_COLOR_FORMAT_RGB565:
case LV_COLOR_FORMAT_YUY2:
case LV_COLOR_FORMAT_AL88:
case LV_COLOR_FORMAT_ARGB1555:
case LV_COLOR_FORMAT_ARGB4444:
return 16;

case LV_COLOR_FORMAT_ARGB8565:
Expand Down Expand Up @@ -91,6 +94,9 @@ bool lv_color_format_has_alpha(lv_color_format_t cf)
case LV_COLOR_FORMAT_ARGB8565:
case LV_COLOR_FORMAT_ARGB8888:
case LV_COLOR_FORMAT_AL88:
case LV_COLOR_FORMAT_ARGB2222:
case LV_COLOR_FORMAT_ARGB1555:
case LV_COLOR_FORMAT_ARGB4444:
return true;
default:
return false;
Expand Down
6 changes: 6 additions & 0 deletions src/misc/lv_color.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,13 @@ enum {
(cf) == LV_COLOR_FORMAT_L8 ? 8 : \
(cf) == LV_COLOR_FORMAT_A8 ? 8 : \
(cf) == LV_COLOR_FORMAT_I8 ? 8 : \
(cf) == LV_COLOR_FORMAT_ARGB2222 ? 8 : \
(cf) == LV_COLOR_FORMAT_AL88 ? 16 : \
(cf) == LV_COLOR_FORMAT_RGB565 ? 16 : \
(cf) == LV_COLOR_FORMAT_RGB565A8 ? 16 : \
(cf) == LV_COLOR_FORMAT_YUY2 ? 16 : \
(cf) == LV_COLOR_FORMAT_ARGB1555 ? 16 : \
(cf) == LV_COLOR_FORMAT_ARGB4444 ? 16 : \
(cf) == LV_COLOR_FORMAT_ARGB8565 ? 24 : \
(cf) == LV_COLOR_FORMAT_RGB888 ? 24 : \
(cf) == LV_COLOR_FORMAT_ARGB8888 ? 32 : \
Expand Down Expand Up @@ -154,6 +157,9 @@ typedef enum {
LV_COLOR_FORMAT_A1 = 0x0B,
LV_COLOR_FORMAT_A2 = 0x0C,
LV_COLOR_FORMAT_A4 = 0x0D,
LV_COLOR_FORMAT_ARGB1555 = 0x16,
LV_COLOR_FORMAT_ARGB4444 = 0x17,
LV_COLOR_FORMAT_ARGB2222 = 0X18,

/* reference to https://wiki.videolan.org/YUV/ */
/*YUV planar formats*/
Expand Down
3 changes: 3 additions & 0 deletions src/others/snapshot/lv_snapshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ lv_result_t lv_snapshot_take_to_draw_buf(lv_obj_t * obj, lv_color_format_t cf, l
case LV_COLOR_FORMAT_A8:
case LV_COLOR_FORMAT_L8:
case LV_COLOR_FORMAT_I1:
case LV_COLOR_FORMAT_ARGB2222:
case LV_COLOR_FORMAT_ARGB4444:
case LV_COLOR_FORMAT_ARGB1555:
yushuailong marked this conversation as resolved.
Show resolved Hide resolved
break;
default:
LV_LOG_WARN("Not supported color format");
Expand Down
127 changes: 127 additions & 0 deletions src/others/vg_lite_tvg/vg_lite_tvg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,27 @@ typedef struct {
uint8_t alpha;
} vg_color32_t;

typedef struct {
uint8_t blue : 4;
uint8_t green : 4;
uint8_t red : 4;
uint8_t alpha : 4;
} vg_color_bgra4444_t;

typedef struct {
uint8_t blue : 2;
uint8_t green : 2;
uint8_t red : 2;
uint8_t alpha : 2;
} vg_color_bgra2222_t;

typedef struct {
uint8_t blue : 5;
uint8_t green : 5;
uint8_t red : 5;
uint8_t alpha : 1;
} vg_color_bgra5551_t;

typedef struct {
vg_lite_float_t x;
vg_lite_float_t y;
Expand Down Expand Up @@ -441,6 +462,45 @@ static vg_lite_converter<vg_color32_t, uint8_t> conv_l8_to_bgra8888(
}
});

static vg_lite_converter<vg_color32_t, vg_color_bgra5551_t> conv_bgra5551_to_bgra8888(
[](vg_color32_t * dest, const vg_color_bgra5551_t * src, vg_lite_uint32_t px_size, vg_lite_uint32_t /* color */)
{
while(px_size--) {
dest->red = src->red * 0xFF / 0x1F;
dest->green = src->green * 0xFF / 0x1F;
dest->blue = src->blue * 0xFF / 0x1F;
dest->alpha = src->alpha ? 0xFF : 0;
src++;
dest++;
}
});

static vg_lite_converter<vg_color32_t, vg_color_bgra4444_t> conv_bgra4444_to_bgra8888(
[](vg_color32_t * dest, const vg_color_bgra4444_t * src, vg_lite_uint32_t px_size, vg_lite_uint32_t /* color */)
{
while(px_size--) {
dest->red = src->red * 0xFF / 0xF;
dest->green = src->green * 0xFF / 0xF;
dest->blue = src->blue * 0xFF / 0xF;
dest->alpha = src->alpha * 0xFF / 0xF;
src++;
dest++;
}
});

static vg_lite_converter<vg_color32_t, vg_color_bgra2222_t> conv_bgra2222_to_bgra8888(
[](vg_color32_t * dest, const vg_color_bgra2222_t * src, vg_lite_uint32_t px_size, vg_lite_uint32_t /* color */)
{
while(px_size--) {
dest->red = src->red * 0xFF / 0x3;
dest->green = src->green * 0xFF / 0x3;
dest->blue = src->blue * 0xFF / 0x3;
dest->alpha = src->alpha * 0xFF / 0x3;
src++;
dest++;
}
});

/**********************
* MACROS
**********************/
Expand Down Expand Up @@ -686,6 +746,43 @@ extern "C" {
}
}

static void picture_bgra8888_to_bgra5551(vg_color_bgra5551_t * dest, const vg_color32_t * src, vg_lite_uint32_t px_size)
{
while(px_size--) {
dest->red = src->red * 0x1F / 0xFF;
dest->green = src->green * 0x1F / 0xFF;
dest->blue = src->blue * 0x1F / 0xFF;
dest->alpha = src->alpha > (0xFF / 2) ? 1 : 0;
src++;
dest++;
}
}

static void picture_bgra8888_to_bgra4444(vg_color_bgra4444_t * dest, const vg_color32_t * src, vg_lite_uint32_t px_size)
{
while(px_size--) {
dest->red = src->red * 0xF / 0xFF;
dest->green = src->green * 0xF / 0xFF;
dest->blue = src->blue * 0xF / 0xFF;
dest->alpha = src->alpha * 0xF / 0xFF;
src++;
dest++;
}
}

static void picture_bgra8888_to_bgra2222(vg_color_bgra2222_t * dest, const vg_color32_t * src, vg_lite_uint32_t px_size)
{
while(px_size--) {
dest->red = src->red * 0x3 / 0xFF;
dest->green = src->green * 0x3 / 0xFF;
dest->blue = src->blue * 0x3 / 0xFF;
dest->alpha = src->alpha * 0x3 / 0xFF;
src++;
dest++;
}
}


vg_lite_error_t vg_lite_finish(void)
{
vg_lite_ctx * ctx = vg_lite_ctx::get_instance();
Expand Down Expand Up @@ -732,6 +829,21 @@ extern "C" {
(const vg_color32_t *)ctx->get_temp_target_buffer(),
ctx->target_px_size);
break;
case VG_LITE_BGRA5551:
picture_bgra8888_to_bgra5551((vg_color_bgra5551_t *)ctx->target_buffer,
(const vg_color32_t *)ctx->get_temp_target_buffer(),
ctx->target_px_size);
break;
case VG_LITE_BGRA4444:
picture_bgra8888_to_bgra4444((vg_color_bgra4444_t *)ctx->target_buffer,
(const vg_color32_t *)ctx->get_temp_target_buffer(),
ctx->target_px_size);
break;
case VG_LITE_BGRA2222:
picture_bgra8888_to_bgra2222((vg_color_bgra2222_t *)ctx->target_buffer,
(const vg_color32_t *)ctx->get_temp_target_buffer(),
ctx->target_px_size);
break;
case VG_LITE_BGRA8888:
case VG_LITE_BGRX8888:
/* No conversion required. */
Expand Down Expand Up @@ -2547,6 +2659,21 @@ static Result picture_load(vg_lite_ctx * ctx, std::unique_ptr<Picture> & picture
}
break;

case VG_LITE_BGRA5551: {
conv_bgra5551_to_bgra8888.convert(&target, source);
}
break;

case VG_LITE_BGRA4444: {
conv_bgra4444_to_bgra8888.convert(&target, source);
}
break;

case VG_LITE_BGRA2222: {
conv_bgra2222_to_bgra8888.convert(&target, source);
}
break;

#if LV_VG_LITE_THORVG_YUV_SUPPORT
case VG_LITE_NV12: {
libyuv::NV12ToARGB((const uint8_t *)source->memory, source->stride, (const uint8_t *)source->yuv.uv_memory,
Expand Down
FASTSHIFT marked this conversation as resolved.
Show resolved Hide resolved
FASTSHIFT marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
FASTSHIFT marked this conversation as resolved.
Show resolved Hide resolved
FASTSHIFT marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
FASTSHIFT marked this conversation as resolved.
Show resolved Hide resolved
56 changes: 56 additions & 0 deletions tests/src/test_cases/draw/test_render_to_argb1555.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#if LV_BUILD_TEST
#include "../lvgl.h"
#include "../../lvgl_private.h"
#include "../demos/lv_demos.h"

#include "unity/unity.h"

void setUp(void)
{
/* Function run before every test */
}

void tearDown(void)
{
/* Function run after every test */
}

void test_render_to_argb1555(void)
{
/**
* There is a slight color deviation between thorvg on 32-bit and 64-bit platforms.
* The deviation will be amplified when using lower precision color formats.
* Only 64-bit platforms are tested here.
*/
#if LV_USE_DRAW_VG_LITE && LV_USE_SNAPSHOT && !defined(NON_AMD64_BUILD)

lv_opa_t opa_values[2] = {0xff, 0x80};
uint32_t opa;
for(opa = 0; opa < 2; opa++) {
uint32_t i;
for(i = 0; i < LV_DEMO_RENDER_SCENE_NUM; i++) {

/*Skip test with transformed indexed images if they are not loaded to RAM*/
if(LV_BIN_DECODER_RAM_LOAD == 0 &&
(i == LV_DEMO_RENDER_SCENE_IMAGE_NORMAL_2 ||
i == LV_DEMO_RENDER_SCENE_IMAGE_RECOLOR_2)) continue;

lv_demo_render(i, opa_values[opa]);
lv_draw_buf_t * draw_buf = lv_snapshot_take(lv_screen_active(), LV_COLOR_FORMAT_ARGB1555);
lv_obj_t * img = lv_image_create(lv_layer_top());
lv_image_set_src(img, draw_buf);

char buf[128];
lv_snprintf(buf, sizeof(buf), "draw/render/argb1555/demo_render_%s_opa_%d.png",
lv_demo_render_get_scene_name(i), opa_values[opa]);
TEST_ASSERT_EQUAL_SCREENSHOT(buf);
lv_obj_delete(img);
lv_draw_buf_destroy(draw_buf);
}
}
#else
TEST_PASS();
#endif
}

#endif
56 changes: 56 additions & 0 deletions tests/src/test_cases/draw/test_render_to_argb2222.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#if LV_BUILD_TEST
#include "../lvgl.h"
#include "../../lvgl_private.h"
#include "../demos/lv_demos.h"

#include "unity/unity.h"

void setUp(void)
{
/* Function run before every test */
}

void tearDown(void)
{
/* Function run after every test */
}

void test_render_to_argb2222(void)
{
/**
* There is a slight color deviation between thorvg on 32-bit and 64-bit platforms.
* The deviation will be amplified when using lower precision color formats.
* Only 64-bit platforms are tested here.
*/
#if LV_USE_DRAW_VG_LITE && LV_USE_SNAPSHOT && !defined(NON_AMD64_BUILD)

lv_opa_t opa_values[2] = {0xff, 0x80};
uint32_t opa;
for(opa = 0; opa < 2; opa++) {
uint32_t i;
for(i = 0; i < LV_DEMO_RENDER_SCENE_NUM; i++) {

/*Skip test with transformed indexed images if they are not loaded to RAM*/
if(LV_BIN_DECODER_RAM_LOAD == 0 &&
(i == LV_DEMO_RENDER_SCENE_IMAGE_NORMAL_2 ||
i == LV_DEMO_RENDER_SCENE_IMAGE_RECOLOR_2)) continue;

lv_demo_render(i, opa_values[opa]);
lv_draw_buf_t * draw_buf = lv_snapshot_take(lv_screen_active(), LV_COLOR_FORMAT_ARGB2222);
lv_obj_t * img = lv_image_create(lv_layer_top());
lv_image_set_src(img, draw_buf);

char buf[128];
lv_snprintf(buf, sizeof(buf), "draw/render/argb2222/demo_render_%s_opa_%d.png",
lv_demo_render_get_scene_name(i), opa_values[opa]);
TEST_ASSERT_EQUAL_SCREENSHOT(buf);
lv_obj_delete(img);
lv_draw_buf_destroy(draw_buf);
}
}
#else
TEST_PASS();
#endif
}

#endif
Loading
Loading