2018-10-10 17:30:59 +08:00
|
|
|
|
#include "base/pixel.h"
|
2018-12-15 17:22:05 +08:00
|
|
|
|
#include "tkc/color.h"
|
2018-10-10 17:30:59 +08:00
|
|
|
|
#include "base/bitmap.h"
|
|
|
|
|
#include "blend/image_g2d.h"
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
2018-10-24 15:39:19 +08:00
|
|
|
|
static void test_blend_image(uint32_t stride, bitmap_format_t bgfmt, bitmap_format_t fgfmt) {
|
2018-10-10 17:30:59 +08:00
|
|
|
|
uint32_t w = 8;
|
|
|
|
|
uint32_t h = 8;
|
|
|
|
|
rect_t r = rect_init(2, 2, 3, 3);
|
2018-10-24 15:39:19 +08:00
|
|
|
|
rect_t r_all = rect_init(0, 0, w, h);
|
2021-09-13 09:24:27 +08:00
|
|
|
|
rectf_t rf = rect_to_rectf((const rect_t*)(&r));
|
|
|
|
|
rectf_t rf_all = rect_to_rectf((const rect_t*)(&r_all));
|
2018-10-24 15:39:19 +08:00
|
|
|
|
uint32_t bpp = bitmap_get_bpp_of_format(bgfmt);
|
|
|
|
|
bitmap_t* bg = bitmap_create_ex(w, h, bpp * (w + stride), bgfmt);
|
|
|
|
|
bitmap_t* fg = bitmap_create_ex(w, h, bpp * (w + stride), fgfmt);
|
2018-10-10 17:30:59 +08:00
|
|
|
|
|
2018-10-24 15:39:19 +08:00
|
|
|
|
color_t c = color_init(0x40, 0x60, 0x80, 0xff);
|
|
|
|
|
color_t c_clear = color_init(0x0, 0x0, 0x0, 0xff);
|
2018-10-10 17:30:59 +08:00
|
|
|
|
|
2019-04-18 16:08:33 +08:00
|
|
|
|
ASSERT_EQ(image_clear(fg, &r, c), RET_OK);
|
2021-09-13 09:24:27 +08:00
|
|
|
|
ASSERT_EQ(image_blend(bg, fg, &rf, &rf, 0xff), RET_OK);
|
2018-10-10 17:30:59 +08:00
|
|
|
|
|
2018-10-24 15:39:19 +08:00
|
|
|
|
bitmap_dump(bg);
|
|
|
|
|
bitmap_check(bg, &r, c.rgba);
|
2018-10-10 17:30:59 +08:00
|
|
|
|
|
2019-04-18 16:08:33 +08:00
|
|
|
|
ASSERT_EQ(image_clear(bg, &r_all, c_clear), RET_OK);
|
2018-10-24 15:39:19 +08:00
|
|
|
|
bitmap_dump(bg);
|
2018-10-10 17:30:59 +08:00
|
|
|
|
|
2021-09-13 09:24:27 +08:00
|
|
|
|
ASSERT_EQ(image_blend(bg, fg, &rf_all, &rf, 0xff), RET_OK);
|
2018-10-24 15:39:19 +08:00
|
|
|
|
bitmap_dump(bg);
|
|
|
|
|
bitmap_check(bg, &r_all, c.rgba);
|
2018-10-10 17:30:59 +08:00
|
|
|
|
|
2018-10-24 15:39:19 +08:00
|
|
|
|
bitmap_destroy(bg);
|
2018-10-10 17:30:59 +08:00
|
|
|
|
bitmap_destroy(fg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(BlendImage, BITMAP_FMT_BGRA8888) {
|
2018-10-24 15:39:19 +08:00
|
|
|
|
test_blend_image(0, BITMAP_FMT_BGRA8888, BITMAP_FMT_BGRA8888);
|
|
|
|
|
test_blend_image(0, BITMAP_FMT_BGRA8888, BITMAP_FMT_RGBA8888);
|
|
|
|
|
test_blend_image(0, BITMAP_FMT_BGRA8888, BITMAP_FMT_BGR565);
|
2018-10-10 17:30:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(BlendImage, BITMAP_FMT_BGR888) {
|
2018-10-24 15:39:19 +08:00
|
|
|
|
test_blend_image(0, BITMAP_FMT_BGR888, BITMAP_FMT_BGRA8888);
|
|
|
|
|
test_blend_image(0, BITMAP_FMT_BGR888, BITMAP_FMT_RGBA8888);
|
|
|
|
|
test_blend_image(0, BITMAP_FMT_BGR888, BITMAP_FMT_BGR565);
|
2018-10-10 17:30:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(BlendImage, BITMAP_FMT_BGR565) {
|
2018-10-24 15:39:19 +08:00
|
|
|
|
test_blend_image(0, BITMAP_FMT_BGR565, BITMAP_FMT_BGRA8888);
|
|
|
|
|
test_blend_image(0, BITMAP_FMT_BGR565, BITMAP_FMT_RGBA8888);
|
|
|
|
|
test_blend_image(0, BITMAP_FMT_BGR888, BITMAP_FMT_BGR565);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(BlendImage, BITMAP_FMT_BGRA8888_stride) {
|
|
|
|
|
test_blend_image(1, BITMAP_FMT_BGRA8888, BITMAP_FMT_BGRA8888);
|
|
|
|
|
test_blend_image(2, BITMAP_FMT_BGRA8888, BITMAP_FMT_RGBA8888);
|
|
|
|
|
test_blend_image(3, BITMAP_FMT_BGRA8888, BITMAP_FMT_BGR565);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(BlendImage, BITMAP_FMT_BGR888_stride) {
|
|
|
|
|
test_blend_image(1, BITMAP_FMT_BGR888, BITMAP_FMT_BGRA8888);
|
|
|
|
|
test_blend_image(2, BITMAP_FMT_BGR888, BITMAP_FMT_RGBA8888);
|
|
|
|
|
test_blend_image(3, BITMAP_FMT_BGR888, BITMAP_FMT_BGR565);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(BlendImage, BITMAP_FMT_BGR565_stride) {
|
|
|
|
|
test_blend_image(1, BITMAP_FMT_BGR565, BITMAP_FMT_BGRA8888);
|
|
|
|
|
test_blend_image(2, BITMAP_FMT_BGR565, BITMAP_FMT_RGBA8888);
|
|
|
|
|
test_blend_image(3, BITMAP_FMT_BGR888, BITMAP_FMT_BGR565);
|
2018-10-10 17:30:59 +08:00
|
|
|
|
}
|