mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 17:19:03 -04:00
RGBtoANSI: fixup lower grey onversions, looks reasonable now #4
This commit is contained in:
parent
cfccd0c39c
commit
a916d929db
Binary file not shown.
Before Width: | Height: | Size: 6.6 MiB After Width: | Height: | Size: 938 KiB |
@ -180,7 +180,9 @@ rgb_to_ansi256(unsigned r, unsigned g, unsigned b){
|
||||
g &= GREYMASK;
|
||||
b &= GREYMASK;
|
||||
if(r == g && g == b){ // 5 MSBs match, return grey
|
||||
return 224 + (r >> 3u);
|
||||
r >>= 3u;
|
||||
r += 232;
|
||||
return r > 255 ? 255: r;
|
||||
}
|
||||
r /= 43;
|
||||
g /= 43;
|
||||
|
49
src/poc/rgbbg.c
Normal file
49
src/poc/rgbbg.c
Normal file
@ -0,0 +1,49 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <locale.h>
|
||||
#include <notcurses.h>
|
||||
|
||||
int main(void){
|
||||
if(!setlocale(LC_ALL, "")){
|
||||
fprintf(stderr, "Couldn't set locale\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
struct notcurses_options opts;
|
||||
memset(&opts, 0, sizeof(opts));
|
||||
opts.inhibit_alternate_screen = true;
|
||||
struct notcurses* nc = notcurses_init(&opts, stdout);
|
||||
if(nc == NULL){
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
int y, x, dimy, dimx;
|
||||
struct ncplane* n = notcurses_stdplane(nc);
|
||||
ncplane_dim_yx(n, &dimy, &dimx);
|
||||
int r , g, b;
|
||||
r = 0;
|
||||
g = 0x80;
|
||||
b = 0;
|
||||
ncplane_set_fg_rgb(n, 0x80, 0x80, 0x80);
|
||||
for(y = 0 ; y < dimy ; ++y){
|
||||
for(x = 0 ; x < dimx ; ++x){
|
||||
ncplane_set_bg_rgb(n, r, g, b);
|
||||
ncplane_putsimple(n, 'x');
|
||||
if(g % 2){
|
||||
if(b-- == 0){
|
||||
++g;
|
||||
b = 0;
|
||||
}
|
||||
}else{
|
||||
if(b++ >= 256){
|
||||
++g;
|
||||
b = 256;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(notcurses_render(nc)){
|
||||
notcurses_stop(nc);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
notcurses_stop(nc);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
@ -16,3 +16,9 @@ TEST_F(InternalsTest, RGBtoANSIWhite) {
|
||||
r = g = b = 0xff;
|
||||
EXPECT_EQ(255, rgb_to_ansi256(r, g, b));
|
||||
}
|
||||
|
||||
TEST_F(InternalsTest, RGBtoANSIBlack) {
|
||||
unsigned r, g, b;
|
||||
r = g = b = 0x0;
|
||||
EXPECT_EQ(232, rgb_to_ansi256(r, g, b));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user