mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 17:19:03 -04:00
ncvisual_from_bgra: swap r and b bytes #1084
This commit is contained in:
parent
b245c8191c
commit
e3d6696812
@ -437,10 +437,12 @@ quadrant_blit(ncplane* nc, int placey, int placex, int linesize,
|
||||
cell_set_fg_alpha(c, CELL_ALPHA_BLEND);
|
||||
}
|
||||
}
|
||||
if(*egc && pool_blit_direct(&nc->pool, c, egc, strlen(egc), 1) <= 0){
|
||||
return -1;
|
||||
if(*egc){
|
||||
if(pool_blit_direct(&nc->pool, c, egc, strlen(egc), 1) <= 0){
|
||||
return -1;
|
||||
}
|
||||
++total;
|
||||
}
|
||||
++total;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
|
@ -465,7 +465,7 @@ int ncvisual_blit(ncvisual* ncv, int rows, int cols, ncplane* n,
|
||||
}
|
||||
//fprintf(stderr, "place: %d/%d rows/cols: %d/%d %d/%d+%d/%d\n", placey, placex, rows, cols, begy, begx, leny, lenx);
|
||||
if(rgba_blit_dispatch(n, bset, placey, placex, stride, data, begy, begx,
|
||||
leny, lenx, blendcolors) <= 0){
|
||||
leny, lenx, blendcolors) < 0){
|
||||
//fprintf(stderr, "rgba dispatch failed!\n");
|
||||
if(sframe){
|
||||
av_freep(sframe->data);
|
||||
|
@ -142,7 +142,7 @@ int ncvisual_blit(struct ncvisual* ncv, int rows, int cols,
|
||||
stride = ncv->rowstride;
|
||||
}
|
||||
if(rgba_blit_dispatch(n, bset, placey, placex, stride, data, begy, begx,
|
||||
leny, lenx, blendcolors) <= 0){
|
||||
leny, lenx, blendcolors) < 0){
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -346,6 +346,11 @@ auto ncvisual_from_bgra(const void* bgra, int rows, int rowstride,
|
||||
ncv->cols = cols;
|
||||
ncv->rows = rows;
|
||||
auto data = static_cast<uint32_t*>(memdup(bgra, rowstride * ncv->rows));
|
||||
for(int p = 0 ; p < rowstride / 4 * ncv->rows ; ++p){
|
||||
const unsigned r = (data[p] & 0xffllu) << 16u;
|
||||
const unsigned b = (data[p] & 0xff0000llu) >> 16u;
|
||||
data[p] = (data[p] & 0xff00ff00llu) | r | b;
|
||||
}
|
||||
if(data == nullptr){
|
||||
ncvisual_destroy(ncv);
|
||||
return nullptr;
|
||||
@ -608,7 +613,7 @@ auto ncvisual_blit(ncvisual* ncv, int rows, int cols, ncplane* n,
|
||||
(void)rows;
|
||||
(void)cols;
|
||||
if(rgba_blit_dispatch(n, bset, placey, placex, ncv->rowstride, ncv->data,
|
||||
begy, begx, leny, lenx, blendcolors) <= 0){
|
||||
begy, begx, leny, lenx, blendcolors) < 0){
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
@ -151,13 +151,14 @@ TEST_CASE("Visual") {
|
||||
SUBCASE("LoadRGBAFromMemory") {
|
||||
int dimy, dimx;
|
||||
ncplane_dim_yx(ncp_, &dimy, &dimx);
|
||||
std::vector<uint32_t> rgba(dimx * dimy * 2, 0x88bbccff);
|
||||
std::vector<uint32_t> rgba(dimx * dimy * 2, 0xff88bbcc);
|
||||
auto ncv = ncvisual_from_rgba(rgba.data(), dimy * 2, dimx * 4, dimx);
|
||||
REQUIRE(ncv);
|
||||
struct ncvisual_options opts{};
|
||||
opts.n = ncp_;
|
||||
CHECK(ncvisual_render(nc_, ncv, &opts));
|
||||
CHECK(nullptr != ncvisual_render(nc_, ncv, &opts));
|
||||
CHECK(0 == notcurses_render(nc_));
|
||||
// FIXME check cell for color -- want ccbb88
|
||||
ncvisual_destroy(ncv);
|
||||
CHECK(0 == notcurses_render(nc_));
|
||||
}
|
||||
@ -165,13 +166,14 @@ TEST_CASE("Visual") {
|
||||
SUBCASE("LoadBGRAFromMemory") {
|
||||
int dimy, dimx;
|
||||
ncplane_dim_yx(ncp_, &dimy, &dimx);
|
||||
std::vector<uint32_t> rgba(dimx * dimy * 2, 0x88bbccff);
|
||||
std::vector<uint32_t> rgba(dimx * dimy * 2, 0xff88bbcc);
|
||||
auto ncv = ncvisual_from_bgra(rgba.data(), dimy * 2, dimx * 4, dimx);
|
||||
REQUIRE(ncv);
|
||||
struct ncvisual_options opts{};
|
||||
opts.n = ncp_;
|
||||
CHECK(ncvisual_render(nc_, ncv, &opts));
|
||||
CHECK(nullptr != ncvisual_render(nc_, ncv, &opts));
|
||||
CHECK(0 == notcurses_render(nc_));
|
||||
// FIXME check cell for color -- want 88bbcc
|
||||
ncvisual_destroy(ncv);
|
||||
CHECK(0 == notcurses_render(nc_));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user