updating CELL_ -> NC_ references

This commit is contained in:
nick black 2021-07-10 18:34:00 -04:00
parent ec4320f215
commit 83d8724e63
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
7 changed files with 46 additions and 60 deletions

View File

@ -1850,13 +1850,6 @@ typedef struct nccell {
uint64_t channels; // + 8B == 16B uint64_t channels; // + 8B == 16B
} nccell; } nccell;
#define CELL_BGDEFAULT_MASK 0x0000000040000000ull
#define CELL_FGDEFAULT_MASK (CELL_BGDEFAULT_MASK << 32u)
#define CELL_BG_RGB_MASK 0x0000000000ffffffull
#define CELL_FG_RGB_MASK (CELL_BG_MASK << 32u)
#define CELL_BG_PALETTE 0x0000000008000000ull
#define CELL_FG_PALETTE (CELL_BG_PALETTE << 32u)
#define NCCHANNEL_ALPHA_MASK 0x30000000ull
#define NCALPHA_HIGHCONTRAST 0x30000000ull #define NCALPHA_HIGHCONTRAST 0x30000000ull
#define NCALPHA_TRANSPARENT 0x20000000ull #define NCALPHA_TRANSPARENT 0x20000000ull
#define NCALPHA_BLEND 0x10000000ull #define NCALPHA_BLEND 0x10000000ull
@ -2881,8 +2874,8 @@ channel_set_rgb8(unsigned* channel, int r, int g, int b){
return -1; return -1;
} }
unsigned c = (r << 16u) | (g << 8u) | b; unsigned c = (r << 16u) | (g << 8u) | b;
c |= CELL_BGDEFAULT_MASK; c |= NC_BGDEFAULT_MASK;
const uint64_t mask = CELL_BGDEFAULT_MASK | CELL_BG_MASK; const uint64_t mask = NC_BGDEFAULT_MASK | NC_BG_MASK;
*channel = (*channel & ~mask) | c; *channel = (*channel & ~mask) | c;
return 0; return 0;
} }
@ -2893,25 +2886,25 @@ channel_set(unsigned* channel, unsigned rgb){
if(rgb > 0xffffffu){ if(rgb > 0xffffffu){
return -1; return -1;
} }
*channel = (*channel & ~CELL_BG_MASK) | CELL_BGDEFAULT_MASK | rgb; *channel = (*channel & ~NC_BG_MASK) | NC_BGDEFAULT_MASK | rgb;
return 0; return 0;
} }
// Extract the 2-bit alpha component from a 32-bit channel. // Extract the 2-bit alpha component from a 32-bit channel.
static inline unsigned static inline unsigned
channel_alpha(unsigned channel){ channel_alpha(unsigned channel){
return channel & CELL_BG_ALPHA_MASK; return channel & NC_BG_ALPHA_MASK;
} }
// Set the 2-bit alpha component of the 32-bit channel. // Set the 2-bit alpha component of the 32-bit channel.
static inline int static inline int
channel_set_alpha(unsigned* channel, unsigned alpha){ channel_set_alpha(unsigned* channel, unsigned alpha){
if(alpha & ~CELL_BG_ALPHA_MASK){ if(alpha & ~NC_BG_ALPHA_MASK){
return -1; return -1;
} }
*channel = alpha | (*channel & ~CHANNEL_ALPHA_MASK); *channel = alpha | (*channel & ~CHANNEL_ALPHA_MASK);
if(alpha != NCALPHA_OPAQUE){ if(alpha != NCALPHA_OPAQUE){
*channel |= CELL_BGDEFAULT_MASK; *channel |= NC_BGDEFAULT_MASK;
} }
return 0; return 0;
} }
@ -2919,13 +2912,13 @@ channel_set_alpha(unsigned* channel, unsigned alpha){
// Is this channel using the "default color" rather than its RGB? // Is this channel using the "default color" rather than its RGB?
static inline bool static inline bool
channel_default_p(unsigned channel){ channel_default_p(unsigned channel){
return !(channel & CELL_BGDEFAULT_MASK); return !(channel & NC_BGDEFAULT_MASK);
} }
// Mark the channel as using its default color. // Mark the channel as using its default color.
static inline unsigned static inline unsigned
channel_set_default(unsigned* channel){ channel_set_default(unsigned* channel){
return *channel &= ~CELL_BGDEFAULT_MASK; return *channel &= ~NC_BGDEFAULT_MASK;
} }
// Extract the 32-bit background channel from a channel pair. // Extract the 32-bit background channel from a channel pair.
@ -2946,8 +2939,8 @@ static inline uint64_t
ncchannels_reverse(uint64_t channels){ ncchannels_reverse(uint64_t channels){
const uint64_t raw = ((uint64_t)ncchannels_bchannel(channels) << 32u) + const uint64_t raw = ((uint64_t)ncchannels_bchannel(channels) << 32u) +
ncchannels_fchannel(channels); ncchannels_fchannel(channels);
const uint64_t statemask = (CELL_NOBACKGROUND_MASK | CELL_FG_ALPHA_MASK | const uint64_t statemask = (NC_NOBACKGROUND_MASK | NC_FG_ALPHA_MASK |
CELL_BG_ALPHA_MASK | (CELL_NOBACKGROUND_MASK >> 32u)); NC_BG_ALPHA_MASK | (NC_NOBACKGROUND_MASK >> 32u));
uint64_t ret = raw & ~statemask; uint64_t ret = raw & ~statemask;
ret |= channels & statemask; ret |= channels & statemask;
return ret; return ret;
@ -2956,13 +2949,13 @@ ncchannels_reverse(uint64_t channels){
// Extract 24 bits of foreground RGB from 'channels', shifted to LSBs. // Extract 24 bits of foreground RGB from 'channels', shifted to LSBs.
static inline unsigned static inline unsigned
ncchannels_fg_rgb(uint64_t channels){ ncchannels_fg_rgb(uint64_t channels){
return ncchannels_fchannel(channels) & CELL_BG_MASK; return ncchannels_fchannel(channels) & NC_BG_MASK;
} }
// Extract 24 bits of background RGB from 'channels', shifted to LSBs. // Extract 24 bits of background RGB from 'channels', shifted to LSBs.
static inline unsigned static inline unsigned
ncchannels_bg_rgb(uint64_t channels){ ncchannels_bg_rgb(uint64_t channels){
return ncchannels_bchannel(channels) & CELL_BG_MASK; return ncchannels_bchannel(channels) & NC_BG_MASK;
} }
// Extract 2 bits of foreground alpha from 'channels', shifted to LSBs. // Extract 2 bits of foreground alpha from 'channels', shifted to LSBs.

View File

@ -20,7 +20,7 @@ def channel_rgb8(channel):
def channel_set_rgb8(channel, r, g, b): def channel_set_rgb8(channel, r, g, b):
checkRGB(r, g, b) checkRGB(r, g, b)
c = (r << 16) | (g << 8) | b c = (r << 16) | (g << 8) | b
return (channel & ~lib.CELL_BG_RGB_MASK) | lib.CELL_BGDEFAULT_MASK | c return (channel & ~lib.NC_BG_RGB_MASK) | lib.NC_BGDEFAULT_MASK | c
def channels_fchannel(channels): def channels_fchannel(channels):
return channels & 0xffffffff00000000 return channels & 0xffffffff00000000

View File

@ -27,13 +27,6 @@ typedef struct nccell {
#define CELL_INITIALIZER(c, s, chan) \ #define CELL_INITIALIZER(c, s, chan) \
{ .gcluster = (c), .stylemask = (s), .channels = (chan), } { .gcluster = (c), .stylemask = (s), .channels = (chan), }
#define CELL_BGDEFAULT_MASK 0x0000000040000000ull
#define CELL_FGDEFAULT_MASK (CELL_BGDEFAULT_MASK << 32u)
#define CELL_BG_RGB_MASK 0x0000000000ffffffull
#define CELL_FG_RGB_MASK (CELL_BG_MASK << 32u)
#define CELL_BG_PALETTE 0x0000000008000000ull
#define CELL_FG_PALETTE (CELL_BG_PALETTE << 32u)
#define CHANNEL_ALPHA_MASK 0x30000000ull
#define NCALPHA_HIGHCONTRAST 0x30000000ull #define NCALPHA_HIGHCONTRAST 0x30000000ull
#define NCALPHA_TRANSPARENT 0x20000000ull #define NCALPHA_TRANSPARENT 0x20000000ull
#define NCALPHA_BLEND 0x10000000ull #define NCALPHA_BLEND 0x10000000ull

View File

@ -13,10 +13,10 @@ notcurses_channels - operations on notcurses channels
```c ```c
#define NCCHANNELS_INITIALIZER(fr, fg, fb, br, bg, bb) \ #define NCCHANNELS_INITIALIZER(fr, fg, fb, br, bg, bb) \
(((((uint64_t)(fr) << 16u) + ((uint64_t)(fg) << 8u) + (uint64_t)(fb)) << 32ull) + \ (((((uint64_t)(fr) << 16u) + ((uint64_t)(fg) << 8u) + (uint64_t)(fb)) << 32ull) + \
(((br) << 16u) + ((bg) << 8u) + (bb)) + CELL_BGDEFAULT_MASK + CELL_FGDEFAULT_MASK) (((br) << 16u) + ((bg) << 8u) + (bb)) + NC_BGDEFAULT_MASK + NC_FGDEFAULT_MASK)
#define CHANNEL_INITIALIZER(r, g, b) \ #define CHANNEL_INITIALIZER(r, g, b) \
(((uint32_t)r << 16u) + ((uint32_t)g << 8u) + (b) + CELL_BGDEFAULT_MASK) (((uint32_t)r << 16u) + ((uint32_t)g << 8u) + (b) + NC_BGDEFAULT_MASK)
``` ```
**uint32_t ncchannel_r(uint32_t ***channel***);** **uint32_t ncchannel_r(uint32_t ***channel***);**

View File

@ -54,30 +54,30 @@ PyInit_notcurses(void)
GNU_PY_MODULE_ADD_OBJECT(py_module, (PyObject *)&NcPlane_Type, "NcPlane"); GNU_PY_MODULE_ADD_OBJECT(py_module, (PyObject *)&NcPlane_Type, "NcPlane");
// background cannot be highcontrast, only foreground // background cannot be highcontrast, only foreground
GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, CELL_ALPHA_HIGHCONTRAST)); GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, NCALPHA_HIGHCONTRAST));
GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, CELL_ALPHA_TRANSPARENT)); GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, NCALPHA_TRANSPARENT));
GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, CELL_ALPHA_BLEND)); GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, NCALPHA_BLEND));
GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, CELL_ALPHA_OPAQUE)); GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, NCALPHA_OPAQUE));
// if this bit is set, we are *not* using the default background color // if this bit is set, we are *not* using the default background color
GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, CELL_BGDEFAULT_MASK)); GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, NC_BGDEFAULT_MASK));
// if this bit is set, we are *not* using the default foreground color // if this bit is set, we are *not* using the default foreground color
GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, CELL_FGDEFAULT_MASK)); GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, NC_FGDEFAULT_MASK));
// extract these bits to get the background RGB value // extract these bits to get the background RGB value
GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, CELL_BG_RGB_MASK)); GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, NC_BG_RGB_MASK));
// extract these bits to get the foreground RGB value // extract these bits to get the foreground RGB value
GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, CELL_FG_RGB_MASK)); GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, NC_FG_RGB_MASK));
// if this bit *and* CELL_BGDEFAULT_MASK are set, we're using a // if this bit *and* NC_BGDEFAULT_MASK are set, we're using a
// palette-indexed background color // palette-indexed background color
GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, CELL_BG_PALETTE)); GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, NC_BG_PALETTE));
GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, NCPALETTESIZE)); GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, NCPALETTESIZE));
// if this bit *and* CELL_FGDEFAULT_MASK are set, we're using a // if this bit *and* CELL_FGDEFAULT_MASK are set, we're using a
// palette-indexed foreground color // palette-indexed foreground color
GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, CELL_FG_PALETTE)); GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, NC_FG_PALETTE));
// extract these bits to get the background alpha mask // extract these bits to get the background alpha mask
GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, CELL_BG_ALPHA_MASK)); GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, NC_BG_ALPHA_MASK));
// extract these bits to get the foreground alpha mask // extract these bits to get the foreground alpha mask
GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, CELL_FG_ALPHA_MASK)); GNU_PY_CHECK_INT(PyModule_AddIntMacro(py_module, NC_FG_ALPHA_MASK));
PyObject *traceback_module CLEANUP_PY_OBJ = GNU_PY_CHECK(PyImport_ImportModule("traceback")); PyObject *traceback_module CLEANUP_PY_OBJ = GNU_PY_CHECK(PyImport_ImportModule("traceback"));
traceback_format_exception = GNU_PY_CHECK(PyObject_GetAttrString(traceback_module, "format_exception")); traceback_format_exception = GNU_PY_CHECK(PyObject_GetAttrString(traceback_module, "format_exception"));
@ -85,4 +85,4 @@ PyInit_notcurses(void)
Py_INCREF(py_module); Py_INCREF(py_module);
return py_module; return py_module;
} }

View File

@ -47,14 +47,14 @@ pub use ffi::{
// NCALPHA_HIGHCONTRAST, // NCALPHA_HIGHCONTRAST,
// NCALPHA_OPAQUE, // NCALPHA_OPAQUE,
// NCALPHA_TRANSPARENT, // NCALPHA_TRANSPARENT,
// CELL_BGDEFAULT_MASK, // NC_BGDEFAULT_MASK,
// CELL_BG_ALPHA_MASK, // NC_BG_ALPHA_MASK,
// CELL_BG_PALETTE, // NC_BG_PALETTE,
// CELL_BG_RGB_MASK, // NC_BG_RGB_MASK,
// CELL_FGDEFAULT_MASK, // NC_FGDEFAULT_MASK,
// CELL_FG_ALPHA_MASK, // NC_FG_ALPHA_MASK,
// CELL_FG_PALETTE, // NC_FG_PALETTE,
// CELL_FG_RGB_MASK, // NC_FG_RGB_MASK,
#[doc(inline)] #[doc(inline)]
pub use ffi::{ pub use ffi::{

View File

@ -100,7 +100,7 @@ pub use reimplemented::*;
pub type NcChannel = u32; pub type NcChannel = u32;
/// Extract these bits to get a channel's alpha value /// Extract these bits to get a channel's alpha value
pub const NCCHANNEL_ALPHA_MASK: u32 = crate::bindings::ffi::CELL_BG_ALPHA_MASK; pub const NCCHANNEL_ALPHA_MASK: u32 = crate::bindings::ffi::NC_BG_ALPHA_MASK;
// NcAlphaBits // NcAlphaBits
// //
@ -140,7 +140,7 @@ pub const NCALPHA_TRANSPARENT: u32 = crate::bindings::ffi::NCALPHA_TRANSPARENT;
/// See the detailed diagram at [`NcChannels`][crate::NcChannels] /// See the detailed diagram at [`NcChannels`][crate::NcChannels]
/// ///
/// Note: This can also be used against a single [`NcChannel`] /// Note: This can also be used against a single [`NcChannel`]
pub const NCALPHA_BGDEFAULT_MASK: u32 = crate::bindings::ffi::CELL_BGDEFAULT_MASK; pub const NCALPHA_BGDEFAULT_MASK: u32 = crate::bindings::ffi::NC_BGDEFAULT_MASK;
/// Extract these bits to get the background alpha mask /// Extract these bits to get the background alpha mask
/// ([`NcAlphaBits`]) /// ([`NcAlphaBits`])
@ -148,7 +148,7 @@ pub const NCALPHA_BGDEFAULT_MASK: u32 = crate::bindings::ffi::CELL_BGDEFAULT_MAS
/// See the detailed diagram at [`NcChannels`][crate::NcChannels] /// See the detailed diagram at [`NcChannels`][crate::NcChannels]
/// ///
/// Note: This can also be used against a single [`NcChannel`] /// Note: This can also be used against a single [`NcChannel`]
pub const NCALPHA_BG_ALPHA_MASK: u32 = crate::bindings::ffi::CELL_BG_ALPHA_MASK; pub const NCALPHA_BG_ALPHA_MASK: u32 = crate::bindings::ffi::NC_BG_ALPHA_MASK;
/// If this bit *and* [`NCALPHA_BGDEFAULT_MASK`] are set, we're using a /// If this bit *and* [`NCALPHA_BGDEFAULT_MASK`] are set, we're using a
/// palette-indexed background color /// palette-indexed background color
@ -156,21 +156,21 @@ pub const NCALPHA_BG_ALPHA_MASK: u32 = crate::bindings::ffi::CELL_BG_ALPHA_MASK;
/// See the detailed diagram at [`NcChannels`][crate::NcChannels] /// See the detailed diagram at [`NcChannels`][crate::NcChannels]
/// ///
/// Note: This can also be used against a single [`NcChannel`] /// Note: This can also be used against a single [`NcChannel`]
pub const NCALPHA_BG_PALETTE: u32 = crate::bindings::ffi::CELL_BG_PALETTE; pub const NCALPHA_BG_PALETTE: u32 = crate::bindings::ffi::NC_BG_PALETTE;
/// Extract these bits to get the background [`NcRgb`][crate::NcRgb] value /// Extract these bits to get the background [`NcRgb`][crate::NcRgb] value
/// ///
/// See the detailed diagram at [`NcChannels`][crate::NcChannels] /// See the detailed diagram at [`NcChannels`][crate::NcChannels]
/// ///
/// Note: This can also be used against a single [`NcChannel`] /// Note: This can also be used against a single [`NcChannel`]
pub const NCALPHA_BG_RGB_MASK: u32 = crate::bindings::ffi::CELL_BG_RGB_MASK; pub const NCALPHA_BG_RGB_MASK: u32 = crate::bindings::ffi::NC_BG_RGB_MASK;
/// If this bit is set, we are *not* using the default foreground color /// If this bit is set, we are *not* using the default foreground color
/// ///
/// See the detailed diagram at [`NcChannels`][crate::NcChannels] /// See the detailed diagram at [`NcChannels`][crate::NcChannels]
/// ///
/// Note: When working with a single [`NcChannel`] use [`NCALPHA_BGDEFAULT_MASK`]; /// Note: When working with a single [`NcChannel`] use [`NCALPHA_BGDEFAULT_MASK`];
pub const NCALPHA_FGDEFAULT_MASK: u64 = crate::bindings::ffi::CELL_FGDEFAULT_MASK; pub const NCALPHA_FGDEFAULT_MASK: u64 = crate::bindings::ffi::NC_FGDEFAULT_MASK;
/// Extract these bits to get the foreground alpha mask /// Extract these bits to get the foreground alpha mask
/// ([`NcAlphaBits`]) /// ([`NcAlphaBits`])
@ -178,7 +178,7 @@ pub const NCALPHA_FGDEFAULT_MASK: u64 = crate::bindings::ffi::CELL_FGDEFAULT_MAS
/// See the detailed diagram at [`NcChannels`][crate::NcChannels] /// See the detailed diagram at [`NcChannels`][crate::NcChannels]
/// ///
/// Note: When working with a single [`NcChannel`] use [`NCALPHA_BG_ALPHA_MASK`]; /// Note: When working with a single [`NcChannel`] use [`NCALPHA_BG_ALPHA_MASK`];
pub const NCALPHA_FG_ALPHA_MASK: u64 = crate::bindings::ffi::CELL_FG_ALPHA_MASK; pub const NCALPHA_FG_ALPHA_MASK: u64 = crate::bindings::ffi::NC_FG_ALPHA_MASK;
/// If this bit *and* [`NCALPHA_FGDEFAULT_MASK`] are set, we're using a /// If this bit *and* [`NCALPHA_FGDEFAULT_MASK`] are set, we're using a
/// palette-indexed background color /// palette-indexed background color
@ -186,14 +186,14 @@ pub const NCALPHA_FG_ALPHA_MASK: u64 = crate::bindings::ffi::CELL_FG_ALPHA_MASK;
/// See the detailed diagram at [`NcChannels`][crate::NcChannels] /// See the detailed diagram at [`NcChannels`][crate::NcChannels]
/// ///
/// Note: When working with a single [`NcChannel`] use [`NCALPHA_BG_PALETTE`]; /// Note: When working with a single [`NcChannel`] use [`NCALPHA_BG_PALETTE`];
pub const NCALPHA_FG_PALETTE: u64 = crate::bindings::ffi::CELL_FG_PALETTE; pub const NCALPHA_FG_PALETTE: u64 = crate::bindings::ffi::NC_FG_PALETTE;
/// Extract these bits to get the foreground [`NcRgb`][crate::NcRgb] value /// Extract these bits to get the foreground [`NcRgb`][crate::NcRgb] value
/// ///
/// See the detailed diagram at [`NcChannels`][crate::NcChannels] /// See the detailed diagram at [`NcChannels`][crate::NcChannels]
/// ///
/// Note: When working with a single [`NcChannel`] use [`NCALPHA_BG_RGB_MASK`]; /// Note: When working with a single [`NcChannel`] use [`NCALPHA_BG_RGB_MASK`];
pub const NCALPHA_FG_RGB_MASK: u64 = crate::bindings::ffi::CELL_FG_RGB_MASK; pub const NCALPHA_FG_RGB_MASK: u64 = crate::bindings::ffi::NC_FG_RGB_MASK;
// NcChannels // NcChannels
// //