From 555a3262b11fb2c0720ff0e43fcc53295b350fd2 Mon Sep 17 00:00:00 2001 From: nick black Date: Sat, 2 Jan 2021 21:23:38 -0500 Subject: [PATCH] add channel_palindex and friends --- doc/man/man3/notcurses_channels.3.md | 12 +++++++++--- include/notcurses/notcurses.h | 19 +++++++++++++++++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/doc/man/man3/notcurses_channels.3.md b/doc/man/man3/notcurses_channels.3.md index 58d7aede4..286174e52 100644 --- a/doc/man/man3/notcurses_channels.3.md +++ b/doc/man/man3/notcurses_channels.3.md @@ -25,11 +25,13 @@ notcurses_channels - operations on notcurses channels **uint32_t channel_b(uint32_t ***channel***);** -**uint32_t channel_rgb8(uint32_t channel, uint32_t* restrict ***r***, uint32_t* restrict ***g***, uint32_t* restrict ***b***);** +**uint32_t channel_rgb8(uint32_t ***channel***, uint32_t* restrict ***r***, uint32_t* restrict ***g***, uint32_t* restrict ***b***);** -**int channel_set_rgb8(uint32_t* channel, int ***r***, int ***g***, int ***b***);** +**unsigned channel_palindex(uint32_t ***channel***);** -**int channel_set(uint32_t* channel, uint32_t rg***b***);** +**int channel_set_rgb8(uint32_t* ***channel***, int ***r***, int ***g***, int ***b***);** + +**int channel_set(uint32_t* ***channel***, uint32_t rg***b***);** **uint32_t channel_alpha(uint32_t ***channel***);** @@ -55,6 +57,10 @@ notcurses_channels - operations on notcurses channels **unsigned channels_bg_alpha(uint64_t ***channels***);** +**unsigned channels_fg_palindex(uint64_t ***channels***);** + +**unsigned channels_bg_palindex(uint64_t ***channels***);** + **unsigned channels_fg_rgb8(uint64_t ***channels***, unsigned* ***r***, unsigned* ***g***, unsigned* ***b***);** **unsigned channels_bg_rgb8(uint64_t ***channels***, unsigned* ***r***, unsigned* ***g***, unsigned* ***b***);** diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index e8f78fade..394b4414a 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -232,6 +232,11 @@ channel_alpha(unsigned channel){ return channel & CHANNEL_ALPHA_MASK; } +static inline unsigned +channel_palindex(uint32_t channel){ + return channel & 0xff; +} + // Set the 2-bit alpha component of the 32-bit channel. static inline int channel_set_alpha(unsigned* channel, unsigned alpha){ @@ -295,6 +300,16 @@ channels_combine(uint32_t fchan, uint32_t bchan){ return channels; } +static inline unsigned +channels_fg_palindex(uint64_t channels){ + return channel_palindex(channels_fchannel(channels)); +} + +static inline unsigned +channels_bg_palindex(uint64_t channels){ + return channel_palindex(channels_bchannel(channels)); +} + // Extract 24 bits of foreground RGB from 'channels', shifted to LSBs. static inline unsigned channels_fg_rgb(uint64_t channels){ @@ -1961,7 +1976,7 @@ cell_set_fg_palindex(nccell* cl, int idx){ static inline uint32_t cell_fg_palindex(const nccell* cl){ - return (cl->channels & 0xff00000000ull) >> 32u; + return channels_fg_palindex(cl->channels); } // Set the r, g, and b cell for the background component of this 64-bit @@ -1993,7 +2008,7 @@ cell_set_bg_palindex(nccell* cl, int idx){ static inline uint32_t cell_bg_palindex(const nccell* cl){ - return (cl->channels & 0xff); + return channels_bg_palindex(cl->channels); } // Is the foreground using the "default foreground color"?