move RGBtoANSI into internal header

pull/148/head
nick black 5 years ago
parent 041e6438e3
commit 8b664a14ef
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -167,6 +167,27 @@ flash_damage_map(unsigned char* damage, int count, bool val){
// mark all lines of the notcurses object touched by this plane as damaged
void ncplane_updamage(ncplane* n);
// For our first attempt, O(1) uniform conversion from 8-bit r/g/b down to
// ~2.4-bit 6x6x6 ANSI cube + greyscale (assumed on entry; I know no way to
// even semi-portably recover the palette) proceeds via: map each 8-bit to
// a 5-bit target grey. if all 3 components match, select that grey.
// otherwise, c / 42.7 to map to 6 values. this never generates pure black
// nor white, though, lame...FIXME
static inline int
rgb_to_ansi256(unsigned r, unsigned g, unsigned b){
const unsigned GREYMASK = 0xf8;
r &= GREYMASK;
g &= GREYMASK;
b &= GREYMASK;
if(r == g && g == b){ // 5 MSBs match, return grey
return 216 + (r >> 3u);
}
r /= 43;
g /= 43;
b /= 43;
return r * 36 + g * 6 + b;
}
#define NANOSECS_IN_SEC 1000000000
#ifdef __cplusplus

@ -929,27 +929,6 @@ term_esc_rgb(FILE* out, int esc, unsigned r, unsigned g, unsigned b){
return 0;
}
// For our first attempt, O(1) uniform conversion from 8-bit r/g/b down to
// ~2.4-bit 6x6x6 ANSI cube + greyscale (assumed on entry; I know no way to
// even semi-portably recover the palette) proceeds via: map each 8-bit to
// a 5-bit target grey. if all 3 components match, select that grey.
// otherwise, c / 42.7 to map to 6 values. this never generates pure black
// nor white, though, lame...FIXME
static inline int
rgb_to_ansi256(unsigned r, unsigned g, unsigned b){
const unsigned GREYMASK = 0xf8;
r &= GREYMASK;
g &= GREYMASK;
b &= GREYMASK;
if(r == g && g == b){ // 5 MSBs match, return grey
return 216 + (r >> 3u);
}
r /= 43;
g /= 43;
b /= 43;
return r * 36 + g * 6 + b;
}
static int
term_bg_rgb8(notcurses* nc, FILE* out, unsigned r, unsigned g, unsigned b){
// We typically want to use tputs() and tiperm() to acquire and write the

Loading…
Cancel
Save