From 72678835f2088fb07da3e5d8ed7bb0ad5b2bc2f5 Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 21 Jan 2022 03:37:38 -0500 Subject: [PATCH] [ncpalette] add ncpalette_get() for orthogonality #2565 --- NEWS.md | 1 + doc/man/man3/notcurses_palette.3.md | 2 ++ include/notcurses/notcurses.h | 8 ++++++++ 3 files changed, 11 insertions(+) diff --git a/NEWS.md b/NEWS.md index 12593cafc..9c81c79d9 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,7 @@ rearrangements of Notcurses. shortucts using `modifiers`. Setting any of `alt`, `shift`, or `ctrl` will see `ncmenu_create()` fail. * `ncinput_equal_p()` considers `NCTYPE_UNKNOWN` equal to `NCTYPE_PRESS`. + * Added `ncpalette_get()` for orthogonality's sake. * 3.0.4 (2022-01-08) * We now use level 2 of `XTMODKEYS`, providing better differentiation diff --git a/doc/man/man3/notcurses_palette.3.md b/doc/man/man3/notcurses_palette.3.md index b7391cf25..a57e90460 100644 --- a/doc/man/man3/notcurses_palette.3.md +++ b/doc/man/man3/notcurses_palette.3.md @@ -27,6 +27,8 @@ typedef struct ncpalette { **int ncpalette_set(ncpalette* ***p***, int ***idx***, unsigned ***rgb***);** +**uint32_t ncpalette_get(const ncpalette* ***p***, int ***idx***);** + **int ncpalette_get_rgb8(const ncpalette* ***p***, int ***idx***, int* restrict ***r***, int* restrict ***g***, int* restrict ***b***);** **void ncpalette_free(ncpalette* ***p***);** diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index 728af8c3a..fb0fd4ae3 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -1550,6 +1550,14 @@ ncpalette_set(ncpalette* p, int idx, unsigned rgb){ return ncchannel_set(&p->chans[idx], rgb); } +static inline uint32_t +ncpalette_get(const ncpalette* p, int idx){ + if(idx < 0 || (size_t)idx > sizeof(p->chans) / sizeof(*p->chans)){ + return -1; + } + return ncchannel_rgb(p->chans[idx]); +} + static inline int ncpalette_get_rgb8(const ncpalette* p, int idx, unsigned* RESTRICT r, unsigned* RESTRICT g, unsigned* RESTRICT b){ if(idx < 0 || (size_t)idx > sizeof(p->chans) / sizeof(*p->chans)){