From 209d4f41f4c073520093dc3b2e2ccfee92cc7f9d Mon Sep 17 00:00:00 2001 From: nick black Date: Wed, 15 Jan 2020 08:00:13 -0500 Subject: [PATCH] palette: add necessary predicates #230 --- include/notcurses.h | 30 +++++++++++++++++++++++++++++- src/lib/render.c | 1 + 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/include/notcurses.h b/include/notcurses.h index 77e512a84..9d6329770 100644 --- a/include/notcurses.h +++ b/include/notcurses.h @@ -932,12 +932,18 @@ channel_set_alpha(unsigned* channel, int alpha){ return 0; } -// Is this channel using the "default color" rather than its RGB? +// Is this channel using the "default color" rather than RGB/palette-indexed? static inline bool channel_default_p(unsigned channel){ return !(channel & CELL_BGDEFAULT_MASK); } +// Is this channel using palette-indexed color rather than RGB? +static inline bool +channel_palindex_p(unsigned channel){ + return !channel_default_p(channel) && (channel & CELL_BG_PALETTE); +} + // Mark the channel as using its default color, which also marks it opaque. static inline unsigned channel_set_default(unsigned* channel){ @@ -1096,6 +1102,12 @@ channels_fg_default_p(uint64_t channels){ return channel_default_p(channels_fchannel(channels)); } +// Is the foreground using indexed palette color? +static inline bool +channels_fg_palindex_p(uint64_t channels){ + return channel_palindex_p(channels_fchannel(channels)); +} + // Is the background using the "default background color"? The "default // background color" must generally be used to take advantage of // terminal-effected transparency. @@ -1104,6 +1116,12 @@ channels_bg_default_p(uint64_t channels){ return channel_default_p(channels_bchannel(channels)); } +// Is the background using indexed palette color? +static inline bool +channels_bg_palindex_p(uint64_t channels){ + return channel_palindex_p(channels_bchannel(channels)); +} + // Mark the foreground channel as using its default color. static inline uint64_t channels_set_fg_default(uint64_t* channels){ @@ -1301,6 +1319,11 @@ cell_fg_default_p(const cell* cl){ return channels_fg_default_p(cl->channels); } +static inline bool +cell_fg_palindex_p(const cell* cl){ + return channels_fg_palindex_p(cl->channels); +} + // Is the background using the "default background color"? The "default // background color" must generally be used to take advantage of // terminal-effected transparency. @@ -1309,6 +1332,11 @@ cell_bg_default_p(const cell* cl){ return channels_bg_default_p(cl->channels); } +static inline bool +cell_bg_palindex_p(const cell* cl){ + return channels_bg_palindex_p(cl->channels); +} + // Get the current channels or attribute word for ncplane 'n'. API uint64_t ncplane_channels(const struct ncplane* n); API uint32_t ncplane_attr(const struct ncplane* n); diff --git a/src/lib/render.c b/src/lib/render.c index a7a643138..0810b0ee0 100644 --- a/src/lib/render.c +++ b/src/lib/render.c @@ -271,6 +271,7 @@ paint(notcurses* nc, ncplane* p, struct crender* rvec, cell* fb){ cell_set_wide(targc); } } + // FIXME blend in palette-indexed colors? if(cell_fg_alpha(targc) > CELL_ALPHA_OPAQUE && cell_fg_alpha(vis) < CELL_ALPHA_TRANSPARENT){ cell_blend_fchannel(targc, cell_fchannel(vis), crender->fgblends); ++crender->fgblends;