From 860d06384dedb228e62ffcb702b7e624b3991439 Mon Sep 17 00:00:00 2001 From: nick black Date: Sun, 23 Jan 2022 18:15:53 -0500 Subject: [PATCH] ncchannels_bchannel: operate only on alpha+coloring bits #2571 --- NEWS.md | 6 +++++- USAGE.md | 9 ++++++--- include/notcurses/notcurses.h | 9 ++++++--- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index 018bd6f94..81730d343 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,7 +2,11 @@ This document attempts to list user-visible changes and any major internal rearrangements of Notcurses. * 3.0.6 (not yet released) - * Remove the unsafe `ncplane_set_bchannel()` and `ncplane_set_fchannel()`. + * `ncplane_set_[fb]channel()`, `ncplane_[fb]channel()`, + `ncplane_channels()`, `ncplane_set_channels()`, + `ncchannels_set_[fb]channel()`, and `ncchannels_[fb]channel()` now + function only on the 28 alpha + coloring bits of their respective + channels, which is almost certainly what you wanted in the first place. * 3.0.5 (2022-01-21) * The Hyper and Super modifiers are now supported. CapsLock and NumLock diff --git a/USAGE.md b/USAGE.md index f254146fc..1d5767b86 100644 --- a/USAGE.md +++ b/USAGE.md @@ -3124,13 +3124,16 @@ ncchannel_set_default(uint32_t* channel){ return *channel &= ~NC_BGDEFAULT_MASK; } -// Extract the 32-bit background channel from a channel pair. +// Extract the background alpha and coloring bits from a 64-bit channel +// pair as a single 32-bit value. static inline unsigned ncchannels_bchannel(uint64_t channels){ - return channels & 0xfffffffflu; + return channels & (NC_BG_RGB_MASK | NC_BG_PALETTE | + NC_BGDEFAULT_MASK | NC_BG_ALPHA_MASK); } -// Extract the 32-bit foreground channel from a channel pair. +// Extract the foreground alpha and coloring bits from a 64-bit channel +// pair as a single 32-bit value. static inline uint32_t ncchannels_fchannel(uint64_t channels){ return ncchannels_bchannel(channels >> 32u); diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index 1cb18d7ce..d7e82eeed 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -296,13 +296,16 @@ ncchannel_set_rgb8_clipped(uint32_t* channel, int r, int g, int b){ *channel = (*channel & ~(NC_BG_RGB_MASK | NC_BG_PALETTE)) | NC_BGDEFAULT_MASK | c; } -// Extract the 32-bit background channel from a channel pair. +// Extract the background alpha and coloring bits from a 64-bit channel +// pair as a single 32-bit value. static inline uint32_t ncchannels_bchannel(uint64_t channels){ - return channels & 0xfffffffflu; + return channels & (NC_BG_RGB_MASK | NC_BG_PALETTE | + NC_BGDEFAULT_MASK | NC_BG_ALPHA_MASK); } -// Extract the 32-bit foreground channel from a channel pair. +// Extract the foreground alpha and coloring bits from a 64-bit channel +// pair as a single 32-bit value. static inline uint32_t ncchannels_fchannel(uint64_t channels){ return ncchannels_bchannel(channels >> 32u);