diff --git a/NEWS.md b/NEWS.md index f95d4407f..0e937c65d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,14 @@ rearrangements of Notcurses. * The default blitter when `NCSCALE_STRETCH` is used is now `NCBLIT_2x2`, replacing `NCBLIT_2x1`. It is not the default for `NCSCALE_NONE` and `NCSCALE_SCALE` because it does not preserve aspect ratio. + * The values of `CELL_ALPHA_OPAQUE` and friends have been redefined to + match their values within a channel representation. If you've been + using the named constants, this should have no effect on you; they sort + the same, subtract the same, and a zero initialization remains just as + opaque as it ever was. If you weren't using their named constants, now's + an excellent time to revise that policy. `CELL_ALPHA_SHIFT` has been + eliminated; if you happened to be using this, the redefinition of the + other `CELL_*` constants (probably) means you no longer need to. * 1.5.2 (2020-06-19) * The `ncneofetch` program has been added, of no great consequence. diff --git a/USAGE.md b/USAGE.md index 6acd07aea..25ea102fa 100644 --- a/USAGE.md +++ b/USAGE.md @@ -1367,8 +1367,8 @@ ncplane_bg_alpha(const struct ncplane* nc){ } // Set the alpha parameters for ncplane 'n'. -int ncplane_set_fg_alpha(struct ncplane* n, int alpha); -int ncplane_set_bg_alpha(struct ncplane* n, int alpha); +int ncplane_set_fg_alpha(struct ncplane* n, unsigned alpha); +int ncplane_set_bg_alpha(struct ncplane* n, unsigned alpha); // Extract 24 bits of foreground RGB from 'n', split into subcomponents. static inline unsigned @@ -1463,13 +1463,13 @@ typedef struct cell { // corresponding default color bit *is not* set, and the corresponding // palette index bit *is* set. uint32_t attrword; // + 4B -> 8B - // (channels & 0x8000000000000000ull): left half of wide character + // (channels & 0x8000000000000000ull): part of a wide glyph // (channels & 0x4000000000000000ull): foreground is *not* "default color" // (channels & 0x3000000000000000ull): foreground alpha (2 bits) // (channels & 0x0800000000000000ull): foreground uses palette index // (channels & 0x0700000000000000ull): reserved, must be 0 // (channels & 0x00ffffff00000000ull): foreground in 3x8 RGB (rrggbb) - // (channels & 0x0000000080000000ull): right half of wide character + // (channels & 0x0000000080000000ull): reserved, must be 0 // (channels & 0x0000000040000000ull): background is *not* "default color" // (channels & 0x0000000030000000ull): background alpha (2 bits) // (channels & 0x0000000008000000ull): background uses palette index @@ -1483,19 +1483,18 @@ typedef struct cell { uint64_t channels; // + 8B == 16B } cell; -#define CELL_WIDEASIAN_MASK 0x8000000080000000ull +#define CELL_WIDEASIAN_MASK 0x8000000000000000ull #define CELL_BGDEFAULT_MASK 0x0000000040000000ull #define CELL_FGDEFAULT_MASK (CELL_BGDEFAULT_MASK << 32u) #define CELL_BG_MASK 0x0000000000ffffffull #define CELL_FG_MASK (CELL_BG_MASK << 32u) #define CELL_BG_PALETTE 0x0000000008000000ull #define CELL_FG_PALETTE (CELL_BG_PALETTE << 32u) -#define CELL_ALPHA_MASK 0x0000000030000000ull -#define CELL_ALPHA_SHIFT 28u -#define CELL_ALPHA_HIGHCONTRAST 3 -#define CELL_ALPHA_TRANSPARENT 2 -#define CELL_ALPHA_BLEND 1 -#define CELL_ALPHA_OPAQUE 0 +#define NCCHANNEL_ALPHA_MASK 0x30000000ull +#define CELL_ALPHA_HIGHCONTRAST 0x30000000ull +#define CELL_ALPHA_TRANSPARENT 0x20000000ull +#define CELL_ALPHA_BLEND 0x10000000ull +#define CELL_ALPHA_OPAQUE 0x00000000ull ``` `cell`s must be initialized with an initialization macro or `cell_init()` @@ -1763,12 +1762,12 @@ cell_set_bg(cell* c, uint32_t channel){ } static inline int -cell_set_fg_alpha(cell* c, int alpha){ +cell_set_fg_alpha(cell* c, unsigned alpha){ return channels_set_fg_alpha(&c->channels, alpha); } static inline int -cell_set_bg_alpha(cell* c, int alpha){ +cell_set_bg_alpha(cell* c, unsigned alpha){ return channels_set_bg_alpha(&c->channels, alpha); } @@ -2332,7 +2331,7 @@ channel_alpha(unsigned channel){ // Set the 2-bit alpha component of the 32-bit channel. static inline int -channel_set_alpha(unsigned* channel, int alpha){ +channel_set_alpha(unsigned* channel, unsigned alpha){ if(alpha < CELL_ALPHA_OPAQUE || alpha > CELL_ALPHA_TRANS){ return -1; } @@ -2447,7 +2446,7 @@ channels_set_bg(uint64_t* channels, unsigned rgb){ // Set the 2-bit alpha component of the foreground channel. static inline int -channels_set_fg_alpha(uint64_t* channels, int alpha){ +channels_set_fg_alpha(uint64_t* channels, unsigned alpha){ unsigned channel = channels_fchannel(*channels); if(channel_set_alpha(&channel, alpha) < 0){ return -1; @@ -2458,7 +2457,7 @@ channels_set_fg_alpha(uint64_t* channels, int alpha){ // Set the 2-bit alpha component of the background channel. static inline int -channels_set_bg_alpha(uint64_t* channels, int alpha){ +channels_set_bg_alpha(uint64_t* channels, unsigned alpha){ if(alpha == CELL_ALPHA_HIGHCONTRAST){ // forbidden for background alpha return -1; } diff --git a/doc/man/man3/notcurses_plane.3.md b/doc/man/man3/notcurses_plane.3.md index f3b9b7ef3..4fa68e403 100644 --- a/doc/man/man3/notcurses_plane.3.md +++ b/doc/man/man3/notcurses_plane.3.md @@ -110,9 +110,9 @@ notcurses_plane - operations on ncplanes **void ncplane_set_bg_default(struct ncplane* n);** -**int ncplane_set_fg_alpha(struct ncplane* n, int alpha);** +**int ncplane_set_fg_alpha(struct ncplane* n, unsigned alpha);** -**int ncplane_set_bg_alpha(struct ncplane* n, int alpha);** +**int ncplane_set_bg_alpha(struct ncplane* n, unsigned alpha);** **int ncplane_set_fg_palindex(struct ncplane* n, int idx);** diff --git a/include/ncpp/Cell.hh b/include/ncpp/Cell.hh index 416c6901d..96f1a8788 100644 --- a/include/ncpp/Cell.hh +++ b/include/ncpp/Cell.hh @@ -17,11 +17,11 @@ namespace ncpp public: static constexpr uint64_t WideAsianMask = CELL_WIDEASIAN_MASK; static constexpr uint64_t FGDefaultMask = CELL_FGDEFAULT_MASK; - static constexpr uint64_t FGMask = CELL_FG_MASK; + static constexpr uint64_t FGRGBMask = CELL_FG_RGB_MASK; static constexpr uint64_t BGDefaultMask = CELL_BGDEFAULT_MASK; - static constexpr uint64_t BGMask = CELL_BG_MASK; - static constexpr uint64_t AlphaMask = CELL_ALPHA_MASK; - static constexpr uint32_t AlphaShift = CELL_ALPHA_SHIFT; + static constexpr uint64_t BGRGBMask = CELL_BG_RGB_MASK; + static constexpr uint64_t BGAlphaMask = CELL_BG_ALPHA_MASK; + static constexpr uint64_t FGAlphaMask = CELL_FG_ALPHA_MASK; static constexpr int AlphaHighContrast = CELL_ALPHA_HIGHCONTRAST; static constexpr int AlphaTransparent = CELL_ALPHA_TRANSPARENT; static constexpr int AlphaBlend = CELL_ALPHA_BLEND; diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index 7f21f854b..4b459f0d8 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -163,19 +163,41 @@ mbswidth(const char* mbs){ return cols; } -#define CELL_WIDEASIAN_MASK 0x8000000080000000ull +// extract these bits to get a channel's alpha value +#define NCCHANNEL_ALPHA_MASK 0x30000000ull +// background cannot be highcontrast, only foreground +#define CELL_ALPHA_HIGHCONTRAST 0x30000000ull +#define CELL_ALPHA_TRANSPARENT 0x20000000ull +#define CELL_ALPHA_BLEND 0x10000000ull +#define CELL_ALPHA_OPAQUE 0x00000000ull + +// if this bit is set, the cell is part of a multicolumn glyph. whether a +// cell is the left or right side of the glyph can be determined by checking +// whether ->gcluster is zero. +#define CELL_WIDEASIAN_MASK 0x8000000000000000ull +// if this bit is set, we are *not* using the default background color #define CELL_BGDEFAULT_MASK 0x0000000040000000ull +// if this bit is set, we are *not* using the default foreground color #define CELL_FGDEFAULT_MASK (CELL_BGDEFAULT_MASK << 32u) -#define CELL_BG_MASK 0x0000000000ffffffull -#define CELL_FG_MASK (CELL_BG_MASK << 32u) +// extract these bits to get the background RGB value +#define CELL_BG_RGB_MASK 0x0000000000ffffffull +// extract these bits to get the foreground RGB value +#define CELL_FG_RGB_MASK (CELL_BG_RGB_MASK << 32u) +// if this bit *and* CELL_BGDEFAULT_MASK are set, we're using a +// palette-indexed background color #define CELL_BG_PALETTE 0x0000000008000000ull +// if this bit *and* CELL_FGDEFAULT_MASK are set, we're using a +// palette-indexed foreground color #define CELL_FG_PALETTE (CELL_BG_PALETTE << 32u) -#define CELL_ALPHA_MASK 0x0000000030000000ull -#define CELL_ALPHA_SHIFT 28u -#define CELL_ALPHA_HIGHCONTRAST 3 -#define CELL_ALPHA_TRANSPARENT 2 -#define CELL_ALPHA_BLEND 1 -#define CELL_ALPHA_OPAQUE 0 +// extract these bits to get the background alpha mask +#define CELL_BG_ALPHA_MASK NCCHANNEL_ALPHA_MASK +// extract these bits to get the foreground alpha mask +#define CELL_FG_ALPHA_MASK (CELL_BG_ALPHA_MASK << 32u) + +// initialize a 64-bit channel pair with specified RGB fg/bg +#define CHANNELS_RGB_INITIALIZER(fr, fg, fb, br, bg, bb) \ + (((((uint64_t)(fr) << 16u) + ((uint64_t)(fg) << 8u) + (uint64_t)(fb)) << 32ull) + \ + (((br) << 16u) + ((bg) << 8u) + (bb)) + CELL_BGDEFAULT_MASK + CELL_FGDEFAULT_MASK) // These lowest-level functions manipulate a 64-bit channel encoding directly. // Users will typically manipulate ncplane and cell channels through those APIs, @@ -220,7 +242,7 @@ channel_set_rgb(unsigned* channel, int r, int g, int b){ return -1; } unsigned c = (r << 16u) | (g << 8u) | b; - *channel = (*channel & ~CELL_BG_MASK) | CELL_BGDEFAULT_MASK | c; + *channel = (*channel & ~CELL_BG_RGB_MASK) | CELL_BGDEFAULT_MASK | c; return 0; } @@ -324,7 +346,7 @@ channel_set_rgb_clipped(unsigned* channel, int r, int g, int b){ b = 0; } unsigned c = (r << 16u) | (g << 8u) | b; - *channel = (*channel & ~CELL_BG_MASK) | CELL_BGDEFAULT_MASK | c; + *channel = (*channel & ~CELL_BG_RGB_MASK) | CELL_BGDEFAULT_MASK | c; } // Same, but provide an assembled, packed 24 bits of rgb. @@ -333,23 +355,23 @@ channel_set(unsigned* channel, unsigned rgb){ if(rgb > 0xffffffu){ return -1; } - *channel = (*channel & ~CELL_BG_MASK) | CELL_BGDEFAULT_MASK | rgb; + *channel = (*channel & ~CELL_BG_RGB_MASK) | CELL_BGDEFAULT_MASK | rgb; return 0; } // Extract the 2-bit alpha component from a 32-bit channel. static inline unsigned channel_alpha(unsigned channel){ - return (channel & CELL_ALPHA_MASK) >> CELL_ALPHA_SHIFT; + return channel & NCCHANNEL_ALPHA_MASK; } // Set the 2-bit alpha component of the 32-bit channel. static inline int -channel_set_alpha(unsigned* channel, int alpha){ - if(alpha < CELL_ALPHA_OPAQUE || alpha > CELL_ALPHA_HIGHCONTRAST){ +channel_set_alpha(unsigned* channel, unsigned alpha){ + if(alpha & ~NCCHANNEL_ALPHA_MASK){ return -1; } - *channel = (alpha << CELL_ALPHA_SHIFT) | (*channel & ~CELL_ALPHA_MASK); + *channel = alpha | (*channel & ~NCCHANNEL_ALPHA_MASK); if(alpha != CELL_ALPHA_OPAQUE){ *channel |= CELL_BGDEFAULT_MASK; } @@ -409,13 +431,13 @@ channels_combine(uint32_t fchan, uint32_t bchan){ // Extract 24 bits of foreground RGB from 'channels', shifted to LSBs. static inline unsigned channels_fg(uint64_t channels){ - return channels_fchannel(channels) & CELL_BG_MASK; + return channels_fchannel(channels) & CELL_BG_RGB_MASK; } // Extract 24 bits of background RGB from 'channels', shifted to LSBs. static inline unsigned channels_bg(uint64_t channels){ - return channels_bchannel(channels) & CELL_BG_MASK; + return channels_bchannel(channels) & CELL_BG_RGB_MASK; } // Extract 2 bits of foreground alpha from 'channels', shifted to LSBs. @@ -506,7 +528,7 @@ channels_set_bg(uint64_t* channels, unsigned rgb){ // Set the 2-bit alpha component of the foreground channel. static inline int -channels_set_fg_alpha(uint64_t* channels, int alpha){ +channels_set_fg_alpha(uint64_t* channels, unsigned alpha){ unsigned channel = channels_fchannel(*channels); if(channel_set_alpha(&channel, alpha) < 0){ return -1; @@ -517,7 +539,7 @@ channels_set_fg_alpha(uint64_t* channels, int alpha){ // Set the 2-bit alpha component of the background channel. static inline int -channels_set_bg_alpha(uint64_t* channels, int alpha){ +channels_set_bg_alpha(uint64_t* channels, unsigned alpha){ if(alpha == CELL_ALPHA_HIGHCONTRAST){ // forbidden for background alpha return -1; } @@ -631,13 +653,13 @@ typedef struct cell { // corresponding default color bit *is not* set, and the corresponding // palette index bit *is* set. uint32_t attrword; // + 4B -> 8B - // (channels & 0x8000000000000000ull): left half of wide character + // (channels & 0x8000000000000000ull): part of a wide glyph // (channels & 0x4000000000000000ull): foreground is *not* "default color" // (channels & 0x3000000000000000ull): foreground alpha (2 bits) // (channels & 0x0800000000000000ull): foreground uses palette index // (channels & 0x0700000000000000ull): reserved, must be 0 // (channels & 0x00ffffff00000000ull): foreground in 3x8 RGB (rrggbb) - // (channels & 0x0000000080000000ull): right half of wide character + // (channels & 0x0000000080000000ull): reserved, must be 0 // (channels & 0x0000000040000000ull): background is *not* "default color" // (channels & 0x0000000030000000ull): background alpha (2 bits) // (channels & 0x0000000008000000ull): background uses palette index @@ -1917,7 +1939,7 @@ cell_set_fg_palindex(cell* cl, int idx){ } cl->channels |= CELL_FGDEFAULT_MASK; cl->channels |= CELL_FG_PALETTE; - cl->channels &= ~(CELL_ALPHA_MASK << 32u); + cell_set_fg_alpha(cl, CELL_ALPHA_OPAQUE); cl->attrword &= 0xffff00ff; cl->attrword |= (idx << 8u); return 0; @@ -1957,7 +1979,7 @@ cell_set_bg_palindex(cell* cl, int idx){ } cl->channels |= CELL_BGDEFAULT_MASK; cl->channels |= CELL_BG_PALETTE; - cl->channels &= ~CELL_ALPHA_MASK; + cell_set_bg_alpha(cl, CELL_ALPHA_OPAQUE); cl->attrword &= 0xffffff00; cl->attrword |= idx; return 0; diff --git a/python/src/notcurses/build_notcurses.py b/python/src/notcurses/build_notcurses.py index 9b8381bf2..6d3ab88f2 100644 --- a/python/src/notcurses/build_notcurses.py +++ b/python/src/notcurses/build_notcurses.py @@ -166,8 +166,8 @@ int ncplane_set_fg(struct ncplane* n, unsigned channel); int ncplane_set_bg(struct ncplane* n, unsigned channel); void ncplane_set_fg_default(struct ncplane* n); void ncplane_set_bg_default(struct ncplane* n); -int ncplane_set_fg_alpha(struct ncplane* n, int alpha); -int ncplane_set_bg_alpha(struct ncplane* n, int alpha); +int ncplane_set_fg_alpha(struct ncplane* n, unsigned alpha); +int ncplane_set_bg_alpha(struct ncplane* n, unsigned alpha); int ncplane_set_fg_palindex(struct ncplane* n, int idx); int ncplane_set_bg_palindex(struct ncplane* n, int idx); void ncplane_styles_set(struct ncplane* n, unsigned stylebits); @@ -218,8 +218,8 @@ void cell_styles_on(cell* c, unsigned stylebits); void cell_styles_off(cell* c, unsigned stylebits); void cell_set_fg_default(cell* c); void cell_set_bg_default(cell* c); -int cell_set_fg_alpha(cell* c, int alpha); -int cell_set_bg_alpha(cell* c, int alpha); +int cell_set_fg_alpha(cell* c, unsigned alpha); +int cell_set_bg_alpha(cell* c, unsigned alpha); bool cell_double_wide_p(const cell* c); bool cell_simple_p(const cell* c); const char* cell_extended_gcluster(const struct ncplane* n, const cell* c); diff --git a/src/demo/mojibake.c b/src/demo/mojibake.c index f6a0d36c1..d9bf0de40 100644 --- a/src/demo/mojibake.c +++ b/src/demo/mojibake.c @@ -3,11 +3,12 @@ static struct ncplane* mojiplane(struct ncplane* title, int y, int rows, const char* summary){ struct ncplane* n = ncplane_aligned(title, rows, 64, y, NCALIGN_CENTER, NULL); - if(ncplane_perimeter_rounded(n, 0, 0, 0) < 0){ + uint64_t channels = CHANNELS_RGB_INITIALIZER(0xf0, 0xa0, 0xf0, 0x10, 0x10, 0x60); + if(ncplane_perimeter_rounded(n, 0, channels, 0) < 0){ ncplane_destroy(n); return NULL; } - uint64_t channels = 0; + channels = 0; channels_set_bg(&channels, 0x0); if(ncplane_set_fg(n, 0x40d0d0) || ncplane_set_bg(n, 0)){ ncplane_destroy(n); @@ -154,19 +155,21 @@ maketitle(struct ncplane* std, int dimx){ } uint64_t channels = 0; channels_set_bg(&channels, 0x0); - if(ncplane_set_base(title, " ", 0, channels) < 0 || ncplane_set_fg(title, 0xffffff) - || ncplane_set_bg(title, 0)){ + if(ncplane_set_base(title, " ", 0, channels) < 0 || ncplane_set_bg(title, 0)){ ncplane_destroy(title); return NULL; } + ncplane_set_fg(title, 0x80f0f0); if(ncplane_putstr_aligned(title, 0, NCALIGN_CENTER, "mojibake 文字化けmodʑibake (english: \"garbled\")") < 0){ ncplane_destroy(title); return NULL; } + ncplane_set_fg(title, 0xa0ffff); if(ncplane_putstr_aligned(title, 1, NCALIGN_CENTER, "Display of emoji depends upon terminal, font, and font rendering engine.") < 0){ ncplane_destroy(title); return NULL; } + ncplane_set_fg(title, 0xe0ffff); if(ncplane_putstr_aligned(title, 2, NCALIGN_CENTER, "Not all symbols are emoji, and not all emoji map to a single code point.") < 0){ ncplane_destroy(title); return NULL; @@ -180,6 +183,7 @@ int mojibake_demo(struct notcurses* nc){ } int dimy, dimx; struct ncplane* std = notcurses_stddim_yx(nc, &dimy, &dimx); + ncplane_greyscale(std); struct ncplane* title = maketitle(std, dimx); if(title == NULL){ return -1; diff --git a/src/lib/internal.h b/src/lib/internal.h index 40ace40e2..f3af5ade1 100644 --- a/src/lib/internal.h +++ b/src/lib/internal.h @@ -327,7 +327,7 @@ typedef struct notcurses { void sigwinch_handler(int signo); -int term_verify_seq(char** gseq, const char* name); +int terminfostr(char** gseq, const char* name); int interrogate_terminfo(tinfo* ti); // Search the provided multibyte (UTF8) string 's' for the provided unicode diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 6f7944b90..a7e292ee7 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -347,7 +347,7 @@ void ncplane_home(ncplane* n){ inline int ncplane_cursor_move_yx(ncplane* n, int y, int x){ if(x >= n->lenx){ - logerror(n->nc, "Target x %d exceeded length %d\n", x, n->lenx); + logerror(n->nc, "Target x %d >= length %d\n", x, n->lenx); return -1; }else if(x < 0){ if(x < -1){ @@ -358,7 +358,7 @@ inline int ncplane_cursor_move_yx(ncplane* n, int y, int x){ n->x = x; } if(y >= n->leny){ - logerror(n->nc, "Target y %d exceeded length %d\n", y, n->leny); + logerror(n->nc, "Target y %d >= length %d\n", y, n->leny); return -1; }else if(y < 0){ if(y < -1){ @@ -861,8 +861,8 @@ notcurses* notcurses_init(const notcurses_options* opts, FILE* outfp){ } // Neither of these is supported on e.g. the "linux" virtual console. if(!(opts->flags & NCOPTION_NO_ALTERNATE_SCREEN)){ - term_verify_seq(&ret->tcache.smcup, "smcup"); - term_verify_seq(&ret->tcache.rmcup, "rmcup"); + terminfostr(&ret->tcache.smcup, "smcup"); + terminfostr(&ret->tcache.rmcup, "rmcup"); } ret->bottom = ret->top = ret->stdscr = NULL; ret->loglevel = opts->loglevel; @@ -1050,7 +1050,7 @@ int ncplane_set_fg_palindex(ncplane* n, int idx){ } n->channels |= CELL_FGDEFAULT_MASK; n->channels |= CELL_FG_PALETTE; - n->channels &= ~(CELL_ALPHA_MASK << 32u); + channels_set_fg_alpha(&n->channels, CELL_ALPHA_OPAQUE); n->attrword &= 0xffff00ff; n->attrword |= (idx << 8u); return 0; @@ -1062,7 +1062,7 @@ int ncplane_set_bg_palindex(ncplane* n, int idx){ } n->channels |= CELL_BGDEFAULT_MASK; n->channels |= CELL_BG_PALETTE; - n->channels &= ~CELL_ALPHA_MASK; + channels_set_bg_alpha(&n->channels, CELL_ALPHA_OPAQUE); n->attrword &= 0xffffff00; n->attrword |= idx; return 0; @@ -1653,11 +1653,11 @@ int ncplane_box(ncplane* n, const cell* ul, const cell* ur, ncplane_cursor_yx(n, &yoff, &xoff); // must be at least 2x2, with its upper-left corner at the current cursor if(ystop < yoff + 1){ - logerror(n->nc, "Ystop (%d) insufficient for yoff (%d)\n", ystop, yoff); + logerror(n->nc, "ystop (%d) insufficient for yoff (%d)\n", ystop, yoff); return -1; } if(xstop < xoff + 1){ - logerror(n->nc, "Xstop (%d) insufficient for xoff (%d)\n", xstop, xoff); + logerror(n->nc, "xstop (%d) insufficient for xoff (%d)\n", xstop, xoff); return -1; } ncplane_dim_yx(n, &ymax, &xmax); diff --git a/tests/channel.cpp b/tests/channel.cpp index 7db99e4b0..f1ededd67 100644 --- a/tests/channel.cpp +++ b/tests/channel.cpp @@ -24,12 +24,12 @@ TEST_CASE("ChannelGetAlpha") { uint32_t channel; int a; } test[] = { - { .channel = 0x00000000, .a = 0, }, - { .channel = 0x10808080, .a = 1, }, - { .channel = 0x20080808, .a = 2, }, - { .channel = 0xe0080808, .a = 2, }, - { .channel = 0x3fffffff, .a = 3, }, - { .channel = 0xffffffff, .a = 3, }, + { .channel = 0x00000000, .a = CELL_ALPHA_OPAQUE, }, + { .channel = 0x10808080, .a = CELL_ALPHA_BLEND, }, + { .channel = 0x20080808, .a = CELL_ALPHA_TRANSPARENT, }, + { .channel = 0xe0080808, .a = CELL_ALPHA_TRANSPARENT, }, + { .channel = 0x3fffffff, .a = CELL_ALPHA_HIGHCONTRAST, }, + { .channel = 0xffffffff, .a = CELL_ALPHA_HIGHCONTRAST, }, }; for(auto i = 0u ; i < sizeof(test) / sizeof(*test) ; ++i){ CHECK(test[i].a == channel_alpha(test[i].channel)); diff --git a/tests/rotate.cpp b/tests/rotate.cpp index 6513b0ab6..6f9433799 100644 --- a/tests/rotate.cpp +++ b/tests/rotate.cpp @@ -120,7 +120,7 @@ TEST_CASE("Rotate") { uint32_t* rgbaret = ncplane_rgba(rendered, NCBLIT_DEFAULT, 0, 0, -1, -1); REQUIRE(rgbaret); for(int i = 0 ; i < height * width / 2 ; ++i){ - if(rgbaret[i] & CELL_BG_MASK){ + if(rgbaret[i] & CELL_BG_RGB_MASK){ CHECK(rgbaret[i] == rgba[i]); } } @@ -132,11 +132,11 @@ TEST_CASE("Rotate") { char* c = notcurses_at_yx(nc_, 0, x, &attrword, &channels); REQUIRE(c); CHECK(0 == strcmp(c, " ")); - if(channels_fg(channels) & CELL_BG_MASK){ - CHECK(0xffccbb == (channels_fg(channels) & CELL_BG_MASK)); + if(channels_fg(channels) & CELL_BG_RGB_MASK){ + CHECK(0xffccbb == channels_fg(channels)); } - if(channels_bg(channels) & CELL_BG_MASK){ - CHECK(0xffccbb == (channels_bg(channels) & CELL_BG_MASK)); + if(channels_bg(channels) & CELL_BG_RGB_MASK){ + CHECK(0xffccbb == channels_bg(channels)); } free(c); } @@ -171,7 +171,7 @@ TEST_CASE("Rotate") { uint32_t* rgbaret = ncplane_rgba(rendered, NCBLIT_DEFAULT, 0, 0, -1, -1); REQUIRE(rgbaret); for(int i = 0 ; i < height * width / 2 ; ++i){ - if(rgbaret[i] & CELL_BG_MASK){ + if(rgbaret[i] & CELL_BG_RGB_MASK){ CHECK(rgbaret[i] == rgba[i]); } } @@ -183,11 +183,11 @@ TEST_CASE("Rotate") { char* c = notcurses_at_yx(nc_, 0, x, &attrword, &channels); REQUIRE(c); CHECK(0 == strcmp(c, " ")); - if(channels_fg(channels) & CELL_BG_MASK){ - CHECK(0xffccbb == (channels_fg(channels) & CELL_BG_MASK)); + if(channels_fg(channels) & CELL_BG_RGB_MASK){ + CHECK(0xffccbb == channels_fg(channels)); } - if(channels_bg(channels) & CELL_BG_MASK){ - CHECK(0xffccbb == (channels_bg(channels) & CELL_BG_MASK)); + if(channels_bg(channels) & CELL_BG_RGB_MASK){ + CHECK(0xffccbb == channels_bg(channels)); } free(c); }