2019-12-14 10:33:34 +00:00
|
|
|
#include "main.h"
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
TEST_CASE("ChannelGetRGB") {
|
2019-12-14 10:33:34 +00:00
|
|
|
const struct t {
|
|
|
|
uint32_t channel;
|
|
|
|
int r, g, b;
|
|
|
|
} test[] = {
|
|
|
|
{ .channel = 0x000000, .r = 0x00, .g = 0x00, .b = 0x00, },
|
|
|
|
{ .channel = 0x808080, .r = 0x80, .g = 0x80, .b = 0x80, },
|
|
|
|
{ .channel = 0x080808, .r = 0x08, .g = 0x08, .b = 0x08, },
|
|
|
|
{ .channel = 0xffffff, .r = 0xff, .g = 0xff, .b = 0xff, },
|
|
|
|
};
|
|
|
|
for(auto i = 0u ; i < sizeof(test) / sizeof(*test) ; ++i){
|
|
|
|
unsigned r, g, b;
|
2020-09-17 19:34:28 +00:00
|
|
|
CHECK(test[i].channel == channel_rgb8(test[i].channel, &r, &g, &b));
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(test[i].r == r);
|
|
|
|
CHECK(test[i].g == g);
|
|
|
|
CHECK(test[i].b == b);
|
2019-12-14 10:33:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
TEST_CASE("ChannelGetAlpha") {
|
2019-12-14 10:33:34 +00:00
|
|
|
const struct t {
|
|
|
|
uint32_t channel;
|
|
|
|
int a;
|
|
|
|
} test[] = {
|
2020-06-28 05:53:42 +00:00
|
|
|
{ .channel = 0x00000000, .a = CELL_ALPHA_OPAQUE, },
|
|
|
|
{ .channel = 0x10808080, .a = CELL_ALPHA_BLEND, },
|
|
|
|
{ .channel = 0x20080808, .a = CELL_ALPHA_TRANSPARENT, },
|
|
|
|
{ .channel = 0xe0080808, .a = CELL_ALPHA_TRANSPARENT, },
|
|
|
|
{ .channel = 0x3fffffff, .a = CELL_ALPHA_HIGHCONTRAST, },
|
|
|
|
{ .channel = 0xffffffff, .a = CELL_ALPHA_HIGHCONTRAST, },
|
2019-12-14 10:33:34 +00:00
|
|
|
};
|
|
|
|
for(auto i = 0u ; i < sizeof(test) / sizeof(*test) ; ++i){
|
2019-12-30 04:47:42 +00:00
|
|
|
CHECK(test[i].a == channel_alpha(test[i].channel));
|
2019-12-14 10:33:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
TEST_CASE("ChannelGetDefault") {
|
2019-12-14 10:33:34 +00:00
|
|
|
const struct t {
|
|
|
|
uint32_t channel;
|
|
|
|
bool def;
|
|
|
|
} test[] = {
|
|
|
|
{ .channel = 0x00000000, .def = true, },
|
|
|
|
{ .channel = 0x0fffffff, .def = true, },
|
|
|
|
{ .channel = 0xbfffffff, .def = true, },
|
|
|
|
{ .channel = 0x40000000, .def = false, },
|
|
|
|
{ .channel = 0x40080808, .def = false, },
|
|
|
|
{ .channel = 0xffffffff, .def = false, },
|
|
|
|
};
|
|
|
|
for(auto i = 0u ; i < sizeof(test) / sizeof(*test) ; ++i){
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(test[i].def == channel_default_p(test[i].channel));
|
2019-12-14 10:33:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
TEST_CASE("ChannelSetDefault") {
|
2019-12-14 10:33:34 +00:00
|
|
|
const uint32_t channels[] = {
|
|
|
|
0x40000000, 0x4fffffff, 0xcfffffff,
|
|
|
|
0x40808080, 0x40080808, 0xffffffff,
|
|
|
|
};
|
|
|
|
for(auto i = 0u ; i < sizeof(channels) / sizeof(*channels) ; ++i){
|
|
|
|
uint32_t channel = channels[i];
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(!channel_default_p(channel));
|
2019-12-14 10:33:34 +00:00
|
|
|
channel_set_default(&channel);
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(channel_default_p(channel));
|
2019-12-14 10:33:34 +00:00
|
|
|
}
|
|
|
|
}
|
2019-12-29 22:49:38 +00:00
|
|
|
|
2019-12-29 22:54:56 +00:00
|
|
|
// blend of 0 ought set c1 to c2
|
2019-12-29 22:49:38 +00:00
|
|
|
TEST_CASE("ChannelBlend0") {
|
|
|
|
uint32_t c1 = 0;
|
|
|
|
uint32_t c2 = 0;
|
2020-09-17 19:34:28 +00:00
|
|
|
channel_set_rgb8(&c1, 0x80, 0x40, 0x20);
|
|
|
|
channel_set_rgb8(&c2, 0x88, 0x44, 0x22);
|
2020-02-07 13:12:18 +00:00
|
|
|
unsigned blends = 0;
|
|
|
|
uint32_t c = channels_blend(c1, c2, &blends);
|
2019-12-29 22:54:56 +00:00
|
|
|
CHECK(!channel_default_p(c));
|
2019-12-29 22:49:38 +00:00
|
|
|
unsigned r, g, b;
|
2020-09-17 19:34:28 +00:00
|
|
|
channel_rgb8(c, &r, &g, &b);
|
2019-12-29 22:49:38 +00:00
|
|
|
CHECK(0x88 == r);
|
|
|
|
CHECK(0x44 == g);
|
|
|
|
CHECK(0x22 == b);
|
2020-02-07 13:12:18 +00:00
|
|
|
CHECK(1 == blends);
|
2019-12-29 22:49:38 +00:00
|
|
|
}
|
|
|
|
|
2019-12-29 22:54:56 +00:00
|
|
|
// blend of 1 ought perfectly average c1 and c2
|
2019-12-29 22:49:38 +00:00
|
|
|
TEST_CASE("ChannelBlend1") {
|
|
|
|
uint32_t c1 = 0;
|
|
|
|
uint32_t c2 = 0;
|
2020-09-17 19:34:28 +00:00
|
|
|
channel_set_rgb8(&c1, 0x80, 0x40, 0x20);
|
|
|
|
channel_set_rgb8(&c2, 0x0, 0x0, 0x0);
|
2020-02-07 13:12:18 +00:00
|
|
|
unsigned blends = 1;
|
|
|
|
uint32_t c = channels_blend(c1, c2, &blends);
|
2019-12-29 22:54:56 +00:00
|
|
|
CHECK(!channel_default_p(c));
|
2019-12-29 22:49:38 +00:00
|
|
|
unsigned r, g, b;
|
2020-09-17 19:34:28 +00:00
|
|
|
channel_rgb8(c, &r, &g, &b);
|
2019-12-29 22:49:38 +00:00
|
|
|
CHECK(0x40 == r);
|
|
|
|
CHECK(0x20 == g);
|
|
|
|
CHECK(0x10 == b);
|
2020-02-07 13:12:18 +00:00
|
|
|
CHECK(2 == blends);
|
2019-12-29 22:49:38 +00:00
|
|
|
}
|
|
|
|
|
2019-12-29 22:54:56 +00:00
|
|
|
// blend of 2 ought weigh c1 twice as much as c2
|
|
|
|
TEST_CASE("ChannelBlend2") {
|
|
|
|
uint32_t c1 = 0;
|
|
|
|
uint32_t c2 = 0;
|
2020-09-17 19:34:28 +00:00
|
|
|
channel_set_rgb8(&c1, 0x60, 0x30, 0x0f);
|
|
|
|
channel_set_rgb8(&c2, 0x0, 0x0, 0x0);
|
2020-02-07 13:12:18 +00:00
|
|
|
unsigned blends = 2;
|
|
|
|
uint32_t c = channels_blend(c1, c2, &blends);
|
2019-12-29 22:54:56 +00:00
|
|
|
CHECK(!channel_default_p(c));
|
|
|
|
unsigned r, g, b;
|
2020-09-17 19:34:28 +00:00
|
|
|
channel_rgb8(c, &r, &g, &b);
|
2019-12-29 22:54:56 +00:00
|
|
|
CHECK(0x40 == r);
|
|
|
|
CHECK(0x20 == g);
|
|
|
|
CHECK(0x0a == b);
|
2020-02-07 13:12:18 +00:00
|
|
|
CHECK(3 == blends);
|
2019-12-29 22:54:56 +00:00
|
|
|
}
|
|
|
|
|
2019-12-30 00:37:24 +00:00
|
|
|
// you can't blend into a default color at any positive number of blends
|
2019-12-29 22:49:38 +00:00
|
|
|
TEST_CASE("ChannelBlendDefaultLeft") {
|
|
|
|
uint32_t c1 = 0;
|
|
|
|
uint32_t c2 = 0;
|
2020-09-17 19:34:28 +00:00
|
|
|
channel_set_rgb8(&c2, 0x80, 0x40, 0x20);
|
2020-02-07 13:12:18 +00:00
|
|
|
unsigned blends = 0;
|
|
|
|
uint32_t c = channels_blend(c1, c2, &blends); // will replace
|
2019-12-30 00:37:24 +00:00
|
|
|
CHECK(!channel_default_p(c));
|
2019-12-29 22:49:38 +00:00
|
|
|
unsigned r, g, b;
|
2020-09-17 19:34:28 +00:00
|
|
|
channel_rgb8(c, &r, &g, &b);
|
2019-12-30 00:37:24 +00:00
|
|
|
CHECK(0x80 == r);
|
|
|
|
CHECK(0x40 == g);
|
|
|
|
CHECK(0x20 == b);
|
2020-02-07 13:12:18 +00:00
|
|
|
CHECK(1 == blends);
|
|
|
|
c = channels_blend(c1, c2, &blends); // will not replace
|
2019-12-30 00:37:24 +00:00
|
|
|
CHECK(channel_default_p(c));
|
2020-09-17 19:34:28 +00:00
|
|
|
channel_rgb8(c, &r, &g, &b);
|
2019-12-29 22:49:38 +00:00
|
|
|
CHECK(0 == r);
|
|
|
|
CHECK(0 == g);
|
|
|
|
CHECK(0 == b);
|
2020-02-07 13:12:18 +00:00
|
|
|
CHECK(2 == blends);
|
|
|
|
c = channels_blend(c1, c2, &blends); // will not replace
|
2019-12-29 22:49:38 +00:00
|
|
|
CHECK(channel_default_p(c));
|
2020-09-17 19:34:28 +00:00
|
|
|
channel_rgb8(c, &r, &g, &b);
|
2019-12-29 22:49:38 +00:00
|
|
|
CHECK(0 == r);
|
|
|
|
CHECK(0 == g);
|
|
|
|
CHECK(0 == b);
|
2020-02-07 13:12:18 +00:00
|
|
|
CHECK(3 == blends);
|
2019-12-29 22:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// you can't blend from a default color, but blend 0 sets it
|
|
|
|
TEST_CASE("ChannelBlendDefaultRight") {
|
|
|
|
uint32_t c1 = 0;
|
|
|
|
uint32_t c2 = 0;
|
2020-09-17 19:34:28 +00:00
|
|
|
channel_set_rgb8(&c1, 0x80, 0x40, 0x20);
|
2020-01-12 12:42:54 +00:00
|
|
|
CHECK(!channel_default_p(c1));
|
2019-12-29 22:49:38 +00:00
|
|
|
CHECK(channel_default_p(c2));
|
2020-02-09 03:29:19 +00:00
|
|
|
unsigned blends = 0;
|
2020-02-07 13:12:18 +00:00
|
|
|
uint32_t c = channels_blend(c1, c2, &blends);
|
2019-12-29 22:49:38 +00:00
|
|
|
CHECK(channel_default_p(c));
|
2020-02-09 03:29:19 +00:00
|
|
|
CHECK(1 == blends);
|
2020-02-07 13:12:18 +00:00
|
|
|
c = channels_blend(c1, c2, &blends);
|
2019-12-29 22:49:38 +00:00
|
|
|
CHECK(!channel_default_p(c));
|
2020-01-12 12:42:54 +00:00
|
|
|
unsigned r, g, b;
|
2020-09-17 19:34:28 +00:00
|
|
|
channel_rgb8(c, &r, &g, &b);
|
2019-12-29 22:49:38 +00:00
|
|
|
CHECK(0x80 == r);
|
|
|
|
CHECK(0x40 == g);
|
|
|
|
CHECK(0x20 == b);
|
2020-02-07 13:12:18 +00:00
|
|
|
CHECK(2 == blends);
|
2019-12-29 22:49:38 +00:00
|
|
|
}
|