ncvisual_from_bgra: swap r and b bytes #1084

pull/1083/head
nick black 4 years ago
parent b245c8191c
commit e3d6696812
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -437,12 +437,14 @@ quadrant_blit(ncplane* nc, int placey, int placex, int linesize,
cell_set_fg_alpha(c, CELL_ALPHA_BLEND); cell_set_fg_alpha(c, CELL_ALPHA_BLEND);
} }
} }
if(*egc && pool_blit_direct(&nc->pool, c, egc, strlen(egc), 1) <= 0){ if(*egc){
if(pool_blit_direct(&nc->pool, c, egc, strlen(egc), 1) <= 0){
return -1; return -1;
} }
++total; ++total;
} }
} }
}
return 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); //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, 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"); //fprintf(stderr, "rgba dispatch failed!\n");
if(sframe){ if(sframe){
av_freep(sframe->data); av_freep(sframe->data);

@ -142,7 +142,7 @@ int ncvisual_blit(struct ncvisual* ncv, int rows, int cols,
stride = ncv->rowstride; stride = ncv->rowstride;
} }
if(rgba_blit_dispatch(n, bset, placey, placex, stride, data, begy, begx, if(rgba_blit_dispatch(n, bset, placey, placex, stride, data, begy, begx,
leny, lenx, blendcolors) <= 0){ leny, lenx, blendcolors) < 0){
return -1; return -1;
} }
return 0; return 0;

@ -346,6 +346,11 @@ auto ncvisual_from_bgra(const void* bgra, int rows, int rowstride,
ncv->cols = cols; ncv->cols = cols;
ncv->rows = rows; ncv->rows = rows;
auto data = static_cast<uint32_t*>(memdup(bgra, rowstride * ncv->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){ if(data == nullptr){
ncvisual_destroy(ncv); ncvisual_destroy(ncv);
return nullptr; return nullptr;
@ -608,7 +613,7 @@ auto ncvisual_blit(ncvisual* ncv, int rows, int cols, ncplane* n,
(void)rows; (void)rows;
(void)cols; (void)cols;
if(rgba_blit_dispatch(n, bset, placey, placex, ncv->rowstride, ncv->data, 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 -1;
} }
return 0; return 0;

@ -151,13 +151,14 @@ TEST_CASE("Visual") {
SUBCASE("LoadRGBAFromMemory") { SUBCASE("LoadRGBAFromMemory") {
int dimy, dimx; int dimy, dimx;
ncplane_dim_yx(ncp_, &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); auto ncv = ncvisual_from_rgba(rgba.data(), dimy * 2, dimx * 4, dimx);
REQUIRE(ncv); REQUIRE(ncv);
struct ncvisual_options opts{}; struct ncvisual_options opts{};
opts.n = ncp_; opts.n = ncp_;
CHECK(ncvisual_render(nc_, ncv, &opts)); CHECK(nullptr != ncvisual_render(nc_, ncv, &opts));
CHECK(0 == notcurses_render(nc_)); CHECK(0 == notcurses_render(nc_));
// FIXME check cell for color -- want ccbb88
ncvisual_destroy(ncv); ncvisual_destroy(ncv);
CHECK(0 == notcurses_render(nc_)); CHECK(0 == notcurses_render(nc_));
} }
@ -165,13 +166,14 @@ TEST_CASE("Visual") {
SUBCASE("LoadBGRAFromMemory") { SUBCASE("LoadBGRAFromMemory") {
int dimy, dimx; int dimy, dimx;
ncplane_dim_yx(ncp_, &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); auto ncv = ncvisual_from_bgra(rgba.data(), dimy * 2, dimx * 4, dimx);
REQUIRE(ncv); REQUIRE(ncv);
struct ncvisual_options opts{}; struct ncvisual_options opts{};
opts.n = ncp_; opts.n = ncp_;
CHECK(ncvisual_render(nc_, ncv, &opts)); CHECK(nullptr != ncvisual_render(nc_, ncv, &opts));
CHECK(0 == notcurses_render(nc_)); CHECK(0 == notcurses_render(nc_));
// FIXME check cell for color -- want 88bbcc
ncvisual_destroy(ncv); ncvisual_destroy(ncv);
CHECK(0 == notcurses_render(nc_)); CHECK(0 == notcurses_render(nc_));
} }

Loading…
Cancel
Save