mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-06 03:20:26 +00:00
add VisualFromRGBxPacked unit test
This commit is contained in:
parent
c5542cbd1a
commit
1bfb230553
@ -655,7 +655,7 @@ ncvisual* ncvisual_from_rgb_loose(const void* rgba, int rows, int rowstride,
|
||||
//fprintf(stderr, "ROWS: %d STRIDE: %d (%d) COLS: %d %08x\n", ncv->pixy, ncv->rowstride, ncv->rowstride / 4, cols, data[ncv->rowstride * y / 4]);
|
||||
memcpy(data + (ncv->rowstride * y) / 4, (const char*)rgba + rowstride * y, rowstride);
|
||||
for(int x = 0 ; x < cols ; ++x){
|
||||
ncpixel_set_a(&data[y * cols + x], alpha);
|
||||
ncpixel_set_a(&data[y * ncv->rowstride / 4 + x], alpha);
|
||||
}
|
||||
}
|
||||
ncvisual_set_data(ncv, data, true);
|
||||
|
@ -12,7 +12,7 @@ TEST_CASE("Visual") {
|
||||
|
||||
// check that we properly populate RGB + A -> RGBA
|
||||
SUBCASE("VisualFromRGBPacked") {
|
||||
unsigned char rgb[13] = "\x88\x77\x66\x55\x44\x33\x22\x11\x00\x99\xaa\xbb";
|
||||
unsigned char rgb[] = "\x88\x77\x66\x55\x44\x33\x22\x11\x00\x99\xaa\xbb";
|
||||
unsigned char alpha = 0xff;
|
||||
auto ncv = ncvisual_from_rgb_packed(rgb, 2, 6, 2, alpha);
|
||||
REQUIRE(nullptr != ncv);
|
||||
@ -20,7 +20,6 @@ TEST_CASE("Visual") {
|
||||
for(int x = 0 ; x < 2 ; ++x){
|
||||
uint32_t p;
|
||||
CHECK(0 == ncvisual_at_yx(ncv, y, x, &p));
|
||||
fprintf(stderr, "rgba: 0x%02x 0x%02x 0x%02x 0x%02x\n", ncpixel_r(p), ncpixel_g(p), ncpixel_b(p), ncpixel_a(p));
|
||||
CHECK(ncpixel_r(p) == rgb[y * 6 + x * 3]);
|
||||
CHECK(ncpixel_g(p) == rgb[y * 6 + x * 3 + 1]);
|
||||
CHECK(ncpixel_b(p) == rgb[y * 6 + x * 3 + 2]);
|
||||
@ -29,6 +28,24 @@ fprintf(stderr, "rgba: 0x%02x 0x%02x 0x%02x 0x%02x\n", ncpixel_r(p), ncpixel_g(p
|
||||
}
|
||||
}
|
||||
|
||||
// check that we properly populate RGBx + A -> RGBA
|
||||
SUBCASE("VisualFromRGBxPacked") {
|
||||
unsigned char rgb[] = "\x88\x77\x66\x12\x55\x44\x33\x10\x22\x11\x00\xdd\x99\xaa\xbb\xcc";
|
||||
unsigned char alpha = 0xff;
|
||||
auto ncv = ncvisual_from_rgb_loose(rgb, 2, 8, 2, alpha);
|
||||
REQUIRE(nullptr != ncv);
|
||||
for(int y = 0 ; y < 2 ; ++y){
|
||||
for(int x = 0 ; x < 2 ; ++x){
|
||||
uint32_t p;
|
||||
CHECK(0 == ncvisual_at_yx(ncv, y, x, &p));
|
||||
CHECK(ncpixel_r(p) == rgb[y * 8 + x * 4]);
|
||||
CHECK(ncpixel_g(p) == rgb[y * 8 + x * 4 + 1]);
|
||||
CHECK(ncpixel_b(p) == rgb[y * 8 + x * 4 + 2]);
|
||||
CHECK(ncpixel_a(p) == alpha);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check that NCVISUAL_OPTION_HORALIGNED works in all three cases
|
||||
SUBCASE("VisualAligned") {
|
||||
const uint32_t pixels[4] = { htole(0xffff0000), htole(0xff00ff00), htole(0xff0000ff), htole(0xffffffff) };
|
||||
|
Loading…
Reference in New Issue
Block a user