From d845e979c296ee45e921962ebfac05d4ae6bba83 Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 19 Feb 2021 12:15:44 -0500 Subject: [PATCH 1/3] tighten up CELL_BG_ALPHA_MASK --- include/notcurses/notcurses.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index eb795f94f..24ee83a35 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -104,8 +104,6 @@ API int ncstrwidth(const char* mbs); API int notcurses_ucs32_to_utf8(const char32_t* ucs32, unsigned ucs32count, unsigned char* resultbuf, size_t buflen); -// extract these bits to get a channel's alpha value -#define CHANNEL_ALPHA_MASK 0x30000000ull // background cannot be highcontrast, only foreground #define CELL_ALPHA_HIGHCONTRAST 0x30000000ull #define CELL_ALPHA_TRANSPARENT 0x20000000ull @@ -128,7 +126,7 @@ API int notcurses_ucs32_to_utf8(const char32_t* ucs32, unsigned ucs32count, // palette-indexed foreground color #define CELL_FG_PALETTE (CELL_BG_PALETTE << 32u) // extract these bits to get the background alpha mask -#define CELL_BG_ALPHA_MASK CHANNEL_ALPHA_MASK +#define CELL_BG_ALPHA_MASK 0x30000000ull // extract these bits to get the foreground alpha mask #define CELL_FG_ALPHA_MASK (CELL_BG_ALPHA_MASK << 32u) @@ -227,7 +225,7 @@ channel_set(unsigned* channel, unsigned rgb){ // Extract the 2-bit alpha component from a 32-bit channel. static inline unsigned channel_alpha(unsigned channel){ - return channel & CHANNEL_ALPHA_MASK; + return channel & CELL_BG_ALPHA_MASK; } static inline unsigned @@ -238,10 +236,10 @@ channel_palindex(uint32_t channel){ // Set the 2-bit alpha component of the 32-bit channel. static inline int channel_set_alpha(unsigned* channel, unsigned alpha){ - if(alpha & ~CHANNEL_ALPHA_MASK){ + if(alpha & ~CELL_BG_ALPHA_MASK){ return -1; } - *channel = alpha | (*channel & ~CHANNEL_ALPHA_MASK); + *channel = alpha | (*channel & ~CELL_BG_ALPHA_MASK); if(alpha != CELL_ALPHA_OPAQUE){ *channel |= CELL_BGDEFAULT_MASK; } From 4951ea3d881ba38a142326fc922248222fc38a07 Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 19 Feb 2021 12:36:25 -0500 Subject: [PATCH 2/3] update comment on notcurses_lex_scalemode() --- include/notcurses/notcurses.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index 24ee83a35..a40099562 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -891,7 +891,7 @@ API int notcurses_lex_blitter(const char* op, ncblitter_e* blitter); // Get the name of a blitter. API const char* notcurses_str_blitter(ncblitter_e blitter); -// Lex a visual scaling mode (one of "none", "stretch", or "scale"). +// Lex a scaling mode (one of "none", "stretch", "scale", "nonehi", or "scalehi"). API int notcurses_lex_scalemode(const char* op, ncscale_e* scalemode); // Get the name of a scaling mode. From 925870bd7a033387d5927a4d9bdf8e654dd8bec7 Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 19 Feb 2021 12:41:43 -0500 Subject: [PATCH 3/3] update some definitions in USAGE.md --- USAGE.md | 15 +++++++++------ include/notcurses/notcurses.h | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/USAGE.md b/USAGE.md index 0340b0417..be6de93da 100644 --- a/USAGE.md +++ b/USAGE.md @@ -245,10 +245,10 @@ you off guard. Utility functions operating on the toplevel `notcurses` object include: ```c -// Return the topmost ncplane, of which there is always at least one. +// Return the topmost ncplane of the standard pile. struct ncplane* notcurses_top(struct notcurses* n); -// Return the bottommost ncplane, of which there is always at least one. +// Return the bottommost ncplane of the standard pile. struct ncplane* notcurses_bottom(struct notcurses* n); // Return our current idea of the terminal dimensions in rows and cols. @@ -2569,16 +2569,19 @@ channel_set(unsigned* channel, unsigned rgb){ // 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 & CELL_BG_ALPHA_MASK; } // Set the 2-bit alpha component of the 32-bit channel. static inline int channel_set_alpha(unsigned* channel, unsigned alpha){ - if(alpha < CELL_ALPHA_OPAQUE || alpha > CELL_ALPHA_TRANS){ + if(alpha & ~CELL_BG_ALPHA_MASK){ return -1; } - *channel = (alpha << CELL_ALPHA_SHIFT) | (*channel & ~CELL_ALPHA_MASK); + *channel = alpha | (*channel & ~CHANNEL_ALPHA_MASK); + if(alpha != CELL_ALPHA_OPAQUE){ + *channel |= CELL_BGDEFAULT_MASK; + } return 0; } @@ -2894,7 +2897,7 @@ typedef enum { NCSCALE_STRETCH, } ncscale_e; -// Lex a visual scaling mode (one of "none", "stretch", or "scale"). +// Lex a scaling mode (one of "none", "stretch", "scale", "nonehi", or "scalehi"). int notcurses_lex_scalemode(const char* op, ncscale_e* scalemode); // Get the name of a scaling mode. diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index a40099562..9eca6ee98 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -938,10 +938,10 @@ API int notcurses_render_to_buffer(struct notcurses* nc, char** buf, size_t* buf // notcurses_render() has not yet been called, nothing will be written. API int notcurses_render_to_file(struct notcurses* nc, FILE* fp); -// Return the topmost ncplane, of which there is always at least one. +// Return the topmost ncplane of the standard pile. API struct ncplane* notcurses_top(struct notcurses* n); -// Return the bottommost ncplane, of which there is always at least one. +// Return the bottommost ncplane of the standard pile. API struct ncplane* notcurses_bottom(struct notcurses* n); // Destroy all ncplanes other than the stdplane.