mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 09:09:03 -04:00
[ncvisual] pipe transcolor through #1518
This commit is contained in:
parent
932f4c1b7c
commit
0c566cd74a
3
NEWS.md
3
NEWS.md
@ -15,6 +15,9 @@ rearrangements of Notcurses.
|
||||
* `cell_release()` and `cell_duplicate()` have been migrated to
|
||||
`nccell_release()` and `nccell_duplicate()`, respectively. The former
|
||||
forms have been deprecated, and will be removed in API3.
|
||||
* Added `NCVISUAL_OPTION_ADDALPHA`, and the `transcolor` field to
|
||||
`ncvisual_options`. If the former flag is used, the latter color
|
||||
will be treated as transparent.
|
||||
|
||||
* 2.2.5 (2021-04-04)
|
||||
* Bugfix release, no user-visible changes.
|
||||
|
@ -34,6 +34,7 @@ typedef enum {
|
||||
#define NCVISUAL_OPTION_BLEND 0x0002
|
||||
#define NCVISUAL_OPTION_HORALIGNED 0x0004
|
||||
#define NCVISUAL_OPTION_VERALIGNED 0x0008
|
||||
#define NCVISUAL_OPTION_ADDALPHA 0x0010
|
||||
|
||||
struct ncvisual_options {
|
||||
struct ncplane* n;
|
||||
@ -43,6 +44,7 @@ struct ncvisual_options {
|
||||
int leny, lenx; // size of rendered section
|
||||
ncblitter_e blitter; // glyph set to use
|
||||
uint64_t flags; // bitmask over NCVISUAL_OPTION_*
|
||||
uint32_t transcolor; // use this color for ADDALPHA
|
||||
};
|
||||
|
||||
typedef int (*streamcb)(struct notcurses*, struct ncvisual*, void*);
|
||||
|
@ -2454,6 +2454,7 @@ API ALLOC struct ncvisual* ncvisual_from_plane(const struct ncplane* n,
|
||||
#define NCVISUAL_OPTION_BLEND 0x0002ull // use CELL_ALPHA_BLEND with visual
|
||||
#define NCVISUAL_OPTION_HORALIGNED 0x0004ull // x is an alignment, not absolute
|
||||
#define NCVISUAL_OPTION_VERALIGNED 0x0008ull // y is an alignment, not absolute
|
||||
#define NCVISUAL_OPTION_ADDALPHA 0x0010ull // transcolor is in effect
|
||||
|
||||
struct ncvisual_options {
|
||||
// if no ncplane is provided, one will be created using the exact size
|
||||
@ -2481,6 +2482,7 @@ struct ncvisual_options {
|
||||
// chosen for NCBLIT_DEFAULT.
|
||||
ncblitter_e blitter; // glyph set to use (maps input to output cells)
|
||||
uint64_t flags; // bitmask over NCVISUAL_OPTION_*
|
||||
uint32_t transcolor; // treat this color as transparent under NCVISUAL_OPTION_ADDALPHA
|
||||
};
|
||||
|
||||
// Create an RGBA flat array from the selected region of the ncplane 'nc'.
|
||||
|
@ -506,6 +506,7 @@ typedef struct {
|
||||
int begx;
|
||||
int placey; // placement within ncplane
|
||||
int placex;
|
||||
uint32_t transcolor; // if non-zero, treat the lower 24 bits as a transparent color
|
||||
union { // cell vs pixel-specific arguments
|
||||
struct {
|
||||
int blendcolors; // use CELL_ALPHA_BLEND
|
||||
|
@ -80,7 +80,7 @@ ncvisual_blitset_geom(const notcurses* nc, const ncvisual* n,
|
||||
const struct ncvisual_options* vopts,
|
||||
int* y, int* x, int* toy, int* tox,
|
||||
int* leny, int* lenx, const struct blitset** blitter){
|
||||
if(vopts && vopts->flags > NCVISUAL_OPTION_HORALIGNED){
|
||||
if(vopts && vopts->flags > NCVISUAL_OPTION_ADDALPHA){
|
||||
logwarn(nc, "Warning: unknown ncvisual options %016jx\n", (uintmax_t)vopts->flags);
|
||||
}
|
||||
int begy, begx;
|
||||
@ -490,7 +490,7 @@ ncvisual* ncvisual_from_bgra(const void* bgra, int rows, int rowstride, int cols
|
||||
ncplane* ncvisual_render_cells(notcurses* nc, ncvisual* ncv, const struct blitset* bset,
|
||||
int placey, int placex, int begy, int begx,
|
||||
int leny, int lenx, ncplane* n, ncscale_e scaling,
|
||||
uint64_t flags){
|
||||
uint64_t flags, uint32_t transcolor){
|
||||
int disprows, dispcols;
|
||||
ncplane* createdn = NULL;
|
||||
//fprintf(stderr, "INPUT N: %p\n", n);
|
||||
@ -560,6 +560,7 @@ ncplane* ncvisual_render_cells(notcurses* nc, ncvisual* ncv, const struct blitse
|
||||
lenx = (lenx / (double)ncv->cols) * ((double)dispcols);
|
||||
//fprintf(stderr, "blit: %dx%d:%d+%d of %d/%d stride %u %p\n", begy, begx, leny, lenx, ncv->rows, ncv->cols, ncv->rowstride, ncv->data);
|
||||
blitterargs bargs;
|
||||
bargs.transcolor = transcolor;
|
||||
bargs.begy = begy;
|
||||
bargs.begx = begx;
|
||||
bargs.placey = placey;
|
||||
@ -580,7 +581,8 @@ ncplane* ncvisual_render_cells(notcurses* nc, ncvisual* ncv, const struct blitse
|
||||
// ncv->cols define the source geometry in pixels.
|
||||
ncplane* ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const struct blitset* bset,
|
||||
int placey, int placex, int begy, int begx,
|
||||
ncplane* n, ncscale_e scaling, uint64_t flags){
|
||||
ncplane* n, ncscale_e scaling, uint64_t flags,
|
||||
uint32_t transcolor){
|
||||
ncplane* stdn = notcurses_stdplane(nc);
|
||||
if(stdn == n){
|
||||
logerror(nc, "Won't render bitmaps to the standard plane\n");
|
||||
@ -660,6 +662,7 @@ ncplane* ncvisual_render_pixels(notcurses* nc, ncvisual* ncv, const struct blits
|
||||
}
|
||||
//fprintf(stderr, "pblit: %dx%d <- %dx%d of %d/%d stride %u @%dx%d %p %u\n", disprows, dispcols, begy, begx, ncv->rows, ncv->cols, ncv->rowstride, placey, placex, ncv->data, nc->tcache.cellpixx);
|
||||
blitterargs bargs;
|
||||
bargs.transcolor = transcolor;
|
||||
bargs.begy = begy;
|
||||
bargs.begx = begx;
|
||||
bargs.placey = placey;
|
||||
@ -710,12 +713,16 @@ ncplane* ncvisual_render(notcurses* nc, ncvisual* ncv, const struct ncvisual_opt
|
||||
ncplane* n = (vopts ? vopts->n : NULL);
|
||||
//fprintf(stderr, "%p tacache: %p\n", n, n->tacache);
|
||||
ncscale_e scaling = vopts ? vopts->scaling : NCSCALE_NONE;
|
||||
uint32_t transcolor = 0;
|
||||
if(vopts && vopts->flags & NCVISUAL_OPTION_ADDALPHA){
|
||||
transcolor = 0x1000000ull | vopts->transcolor;
|
||||
}
|
||||
if(bset->geom != NCBLIT_PIXEL){
|
||||
n = ncvisual_render_cells(nc, ncv, bset, placey, placex, begy, begx, leny, lenx,
|
||||
n, scaling, vopts ? vopts->flags : 0);
|
||||
n, scaling, vopts ? vopts->flags : 0, transcolor);
|
||||
}else{
|
||||
n = ncvisual_render_pixels(nc, ncv, bset, placey, placex, begy, begx, n, scaling,
|
||||
vopts ? vopts->flags : 0);
|
||||
vopts ? vopts->flags : 0, transcolor);
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ TEST_CASE("Blitting") {
|
||||
.lenx = 4,
|
||||
.blitter = NCBLIT_1x1,
|
||||
.flags = 0,
|
||||
.transcolor = 0,
|
||||
};
|
||||
ncblit_bgrx(data, 16, &vopts);
|
||||
for(int y = 0 ; y < 2 ; ++y){
|
||||
@ -87,6 +88,7 @@ TEST_CASE("Blitting") {
|
||||
.lenx = 4,
|
||||
.blitter = NCBLIT_1x1,
|
||||
.flags = 0,
|
||||
.transcolor = 0,
|
||||
};
|
||||
ncblit_bgrx(data, 20, &vopts);
|
||||
for(int y = 0 ; y < 2 ; ++y){
|
||||
@ -139,6 +141,7 @@ TEST_CASE("Blitting") {
|
||||
.n = nullptr, .scaling = NCSCALE_NONE,
|
||||
.y = 0, .x = 0, .begy = 0, .begx = 0, .leny = 0, .lenx = 0,
|
||||
.blitter = NCBLIT_2x2, .flags = 0,
|
||||
.transcolor = 0,
|
||||
};
|
||||
auto ncp = ncvisual_render(nc_, ncv, &vopts);
|
||||
ncvisual_destroy(ncv);
|
||||
|
@ -52,6 +52,7 @@ TEST_CASE("Pixel") {
|
||||
.leny = y, .lenx = x,
|
||||
.blitter = NCBLIT_PIXEL,
|
||||
.flags = NCVISUAL_OPTION_NODEGRADE,
|
||||
.transcolor = 0,
|
||||
};
|
||||
auto n = ncvisual_render(nc_, ncv, &vopts);
|
||||
REQUIRE(nullptr != n);
|
||||
@ -89,6 +90,7 @@ TEST_CASE("Pixel") {
|
||||
.leny = y, .lenx = x,
|
||||
.blitter = NCBLIT_PIXEL,
|
||||
.flags = NCVISUAL_OPTION_NODEGRADE,
|
||||
.transcolor = 0,
|
||||
};
|
||||
auto n = ncvisual_render(nc_, ncv, &vopts);
|
||||
REQUIRE(nullptr != n);
|
||||
@ -126,6 +128,7 @@ TEST_CASE("Pixel") {
|
||||
.leny = y, .lenx = x,
|
||||
.blitter = NCBLIT_PIXEL,
|
||||
.flags = NCVISUAL_OPTION_NODEGRADE,
|
||||
.transcolor = 0,
|
||||
};
|
||||
auto n = ncvisual_render(nc_, ncv, &vopts);
|
||||
REQUIRE(nullptr != n);
|
||||
@ -171,6 +174,7 @@ TEST_CASE("Pixel") {
|
||||
.leny = y, .lenx = x,
|
||||
.blitter = NCBLIT_PIXEL,
|
||||
.flags = NCVISUAL_OPTION_NODEGRADE,
|
||||
.transcolor = 0,
|
||||
};
|
||||
auto n = ncvisual_render(nc_, ncv, &vopts);
|
||||
REQUIRE(nullptr != n);
|
||||
|
@ -40,6 +40,7 @@ TEST_CASE("Stacking") {
|
||||
struct ncvisual_options vopts = {
|
||||
.n = top, .scaling = NCSCALE_NONE, .y = 0, .x = 0, .begy = 0, .begx = 0,
|
||||
.leny = 2, .lenx = 1, .blitter = NCBLIT_2x1, .flags = 0,
|
||||
.transcolor = 0,
|
||||
};
|
||||
CHECK(top == ncvisual_render(nc_, ncv, &vopts));
|
||||
ncvisual_destroy(ncv);
|
||||
@ -77,6 +78,7 @@ TEST_CASE("Stacking") {
|
||||
struct ncvisual_options vopts = {
|
||||
.n = top, .scaling = NCSCALE_NONE, .y = 0, .x = 0, .begy = 0, .begx = 0,
|
||||
.leny = 2, .lenx = 1, .blitter = NCBLIT_2x1, .flags = 0,
|
||||
.transcolor = 0,
|
||||
};
|
||||
CHECK(top == ncvisual_render(nc_, ncv, &vopts));
|
||||
ncvisual_destroy(ncv);
|
||||
@ -115,6 +117,7 @@ TEST_CASE("Stacking") {
|
||||
struct ncvisual_options vopts = {
|
||||
.n = top, .scaling = NCSCALE_NONE, .y = 0, .x = 0, .begy = 0, .begx = 0,
|
||||
.leny = 2, .lenx = 2, .blitter = NCBLIT_2x2, .flags = 0,
|
||||
.transcolor = 0,
|
||||
};
|
||||
CHECK(top == ncvisual_render(nc_, ncv, &vopts));
|
||||
ncvisual_destroy(ncv);
|
||||
@ -156,6 +159,7 @@ TEST_CASE("Stacking") {
|
||||
struct ncvisual_options vopts = {
|
||||
.n = top, .scaling = NCSCALE_NONE, .y = 0, .x = 0, .begy = 0, .begx = 0,
|
||||
.leny = 2, .lenx = 2, .blitter = NCBLIT_2x2, .flags = 0,
|
||||
.transcolor = 0,
|
||||
};
|
||||
CHECK(top == ncvisual_render(nc_, ncv, &vopts));
|
||||
ncvisual_destroy(ncv);
|
||||
|
@ -23,6 +23,7 @@ TEST_CASE("Visual") {
|
||||
.lenx = 2,
|
||||
.blitter = NCBLIT_1x1,
|
||||
.flags = NCVISUAL_OPTION_HORALIGNED,
|
||||
.transcolor = 0,
|
||||
};
|
||||
auto ncv = ncvisual_from_rgba(pixels, 2, 2 * sizeof(*pixels), 2);
|
||||
REQUIRE(nullptr != ncv);
|
||||
@ -239,6 +240,7 @@ TEST_CASE("Visual") {
|
||||
.lenx = 0,
|
||||
.blitter = NCBLIT_2x2,
|
||||
.flags = 0,
|
||||
.transcolor = 0,
|
||||
};
|
||||
auto ncvp = ncvisual_render(nc_, ncv, &vopts);
|
||||
REQUIRE(nullptr != ncvp);
|
||||
@ -283,6 +285,7 @@ TEST_CASE("Visual") {
|
||||
.lenx = 0,
|
||||
.blitter = NCBLIT_2x2,
|
||||
.flags = 0,
|
||||
.transcolor = 0,
|
||||
};
|
||||
auto ncvp = ncvisual_render(nc_, ncv, &vopts);
|
||||
REQUIRE(nullptr != ncvp);
|
||||
@ -330,6 +333,7 @@ TEST_CASE("Visual") {
|
||||
.lenx = 0,
|
||||
.blitter = NCBLIT_2x2,
|
||||
.flags = 0,
|
||||
.transcolor = 0,
|
||||
};
|
||||
auto ncvp = ncvisual_render(nc_, ncv, &vopts);
|
||||
REQUIRE(nullptr != ncvp);
|
||||
@ -382,6 +386,7 @@ TEST_CASE("Visual") {
|
||||
.lenx = 0,
|
||||
.blitter = NCBLIT_2x2,
|
||||
.flags = 0,
|
||||
.transcolor = 0,
|
||||
};
|
||||
auto ncvp = ncvisual_render(nc_, ncv, &vopts);
|
||||
REQUIRE(nullptr != ncvp);
|
||||
@ -433,6 +438,7 @@ TEST_CASE("Visual") {
|
||||
.lenx = 0,
|
||||
.blitter = NCBLIT_2x2,
|
||||
.flags = 0,
|
||||
.transcolor = 0,
|
||||
};
|
||||
auto ncvp = ncvisual_render(nc_, ncv, &vopts);
|
||||
REQUIRE(nullptr != ncvp);
|
||||
|
Loading…
x
Reference in New Issue
Block a user