[ncsixel_as_rgba] properly scale up colors #2502

pull/2506/head
nick black 3 years ago
parent 3b7c71ee8b
commit 7f64f181aa
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -88,6 +88,7 @@ uint32_t* ncsixel_as_rgba(const char *sx, unsigned leny, unsigned lenx){
if(';' != *(sx++)){ if(';' != *(sx++)){
goto err; goto err;
} }
r = r * 255 / 100;
int g = 0; int g = 0;
do{ do{
g *= 10; g *= 10;
@ -97,24 +98,26 @@ uint32_t* ncsixel_as_rgba(const char *sx, unsigned leny, unsigned lenx){
if(';' != *(sx++)){ if(';' != *(sx++)){
goto err; goto err;
} }
g = g * 255 / 100;
int b = 0; int b = 0;
do{ do{
b *= 10; b *= 10;
b += *sx - '0'; b += *sx - '0';
++sx; ++sx;
}while(isdigit(*sx)); }while(isdigit(*sx));
uint32_t rgb = htole(0xff000000 + (r << 16u) * 255 / 100 + (g << 8u) * 255 / 100 + b * 255 / 100); b = b * 255 / 100;
//std::cerr << "Got color " << color << ": " << r << "/" << g << "/" << b << std::endl; ncpixel_set_a(&colors[color], 0xff);
ncpixel_set_rgb8(&colors[color], r, g, b);
//fprintf(stderr, "Got color %d: 0x%08x %u %u %u\n", color, colors[color], r, g, b);
if(color >= MAXCOLORS){ if(color >= MAXCOLORS){
goto err; goto err;
} }
colors[color] = rgb;
state = STATE_WANT_HASH; state = STATE_WANT_HASH;
--sx; --sx;
} }
// read until we hit next colorspec // read until we hit next colorspec
if(state == STATE_WANT_DATA){ if(state == STATE_WANT_DATA){
//std::cerr << "Character " << *sx << std::endl; //fprintf(stderr, "Character %c\n", *sx);
if(*sx == '#'){ if(*sx == '#'){
state = STATE_WANT_HASH; state = STATE_WANT_HASH;
--sx; --sx;

@ -36,6 +36,7 @@ compare(const struct ncvisual* n1, const struct ncvisual* n2,
rdelta += rd; rdelta += rd;
gdelta += gd; gdelta += gd;
bdelta += bd; bdelta += bd;
//fprintf(stderr, "0x%08x 0x%08x\n", p0, p1);
} }
ncplane_printf_yx(stdn, -1, 1, "%08u pixels analyzed", (y + 1) * lx); ncplane_printf_yx(stdn, -1, 1, "%08u pixels analyzed", (y + 1) * lx);
ncplane_printf(stdn, " Δr %"PRIu64" Δg %"PRIu64" Δb %"PRIu64, ncplane_printf(stdn, " Δr %"PRIu64" Δg %"PRIu64" Δb %"PRIu64,

Loading…
Cancel
Save