ncvisual_from_bgra(): use ncpixel API to work on big-endian #1714

pull/1730/head
nick black 3 years ago
parent 7f2635ced1
commit 97bfd726e4

@ -624,9 +624,12 @@ ncvisual* ncvisual_from_bgra(const void* bgra, int rows, int rowstride, int cols
for(int x = 0 ; x < cols ; ++x){
uint32_t src;
memcpy(&src, (const char*)bgra + y * rowstride + x * 4, 4);
const uint32_t r = (src & 0xffllu) << 16u;
const uint32_t b = (src & 0xff0000llu) >> 16u;
data[ncv->rowstride * y / 4 + x] = (src & 0xff00ff00llu) | r | b;
uint32_t* dst = &data[ncv->rowstride * y / 4 + x];
ncpixel_set_a(dst, ncpixel_a(src));
ncpixel_set_r(dst, ncpixel_b(src));
ncpixel_set_g(dst, ncpixel_g(src));
ncpixel_set_b(dst, ncpixel_r(src));
fprintf(stderr, "BGRA PIXEL: %02x%02x%02x%02x RGBA result: %02x%02x%02x%02x\n", ((const char*)&src)[0], ((const char*)&src)[1], ((const char*)&src)[2], ((const char*)&src)[3], ((const char*)dst)[0], ((const char*)dst)[1], ((const char*)dst)[2], ((const char*)dst)[3]);
}
}
ncvisual_set_data(ncv, data, true);

@ -175,6 +175,8 @@ TEST_CASE("Visual") {
auto ncv = ncvisual_from_rgba(rgba.data(), dimy * 2, dimx * 4, dimx);
REQUIRE(ncv);
struct ncvisual_options opts{};
opts.blitter = NCBLIT_1x1;
opts.scaling = NCSCALE_STRETCH;
opts.n = ncp_;
CHECK(ncp_ == ncvisual_render(nc_, ncv, &opts));
CHECK(0 == notcurses_render(nc_));
@ -185,7 +187,7 @@ TEST_CASE("Visual") {
auto c = ncplane_at_yx(ncp_, y, x, &stylemask, &channels);
CHECK(0 == strcmp(c, " "));
free(c);
CHECK(ncchannels_bg_rgb(channels) == 0xccbb88);
CHECK(htole(ncchannels_bg_rgb(channels)) == htole(0xccbb88));
CHECK(stylemask == 0);
}
}
@ -202,6 +204,8 @@ TEST_CASE("Visual") {
auto ncv = ncvisual_from_bgra(rgba.data(), dimy * 2, dimx * 4, dimx);
REQUIRE(ncv);
struct ncvisual_options opts{};
opts.blitter = NCBLIT_1x1;
opts.scaling = NCSCALE_STRETCH;
opts.n = ncp_;
CHECK(nullptr != ncvisual_render(nc_, ncv, &opts));
CHECK(0 == notcurses_render(nc_));

Loading…
Cancel
Save