mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-12 10:39:04 -04:00
when HIGHCONTRAST is atop default, use queried value for bg computation #1947
This commit is contained in:
parent
d8338105b3
commit
bed16a9b7b
@ -75,7 +75,6 @@ int highcontrast_demo(struct notcurses* nc){
|
|||||||
}
|
}
|
||||||
const char motto[] = " high contrast text is evaluated relative to the solved background";
|
const char motto[] = " high contrast text is evaluated relative to the solved background";
|
||||||
nccell c = CELL_TRIVIAL_INITIALIZER;
|
nccell c = CELL_TRIVIAL_INITIALIZER;
|
||||||
nccell_set_fg_alpha(&c, NCALPHA_HIGHCONTRAST);
|
|
||||||
unsigned total = 0, r = 0, g = 0, b = 0;
|
unsigned total = 0, r = 0, g = 0, b = 0;
|
||||||
for(int out = 0 ; out < totcells ; ++out){ // build up the initial screen
|
for(int out = 0 ; out < totcells ; ++out){ // build up the initial screen
|
||||||
scrcolors[out] = generate_next_color(&total, &r, &g, &b, STEP);
|
scrcolors[out] = generate_next_color(&total, &r, &g, &b, STEP);
|
||||||
@ -83,6 +82,7 @@ int highcontrast_demo(struct notcurses* nc){
|
|||||||
total = r = g = b = 0;
|
total = r = g = b = 0;
|
||||||
}
|
}
|
||||||
nccell_load_char(n, &c, motto[out % strlen(motto)]);
|
nccell_load_char(n, &c, motto[out % strlen(motto)]);
|
||||||
|
nccell_set_fg_alpha(&c, NCALPHA_HIGHCONTRAST);
|
||||||
nccell_set_bg_rgb(&c, scrcolors[out % totcells]);
|
nccell_set_bg_rgb(&c, scrcolors[out % totcells]);
|
||||||
if(ncplane_putc_yx(n, (out + dimx) / dimx, out % dimx, &c) < 0){
|
if(ncplane_putc_yx(n, (out + dimx) / dimx, out % dimx, &c) < 0){
|
||||||
free(scrcolors);
|
free(scrcolors);
|
||||||
|
@ -98,10 +98,18 @@ int cell_duplicate(struct ncplane* n, nccell* targ, const nccell* c){
|
|||||||
|
|
||||||
// Emit fchannel with RGB changed to contrast effectively against bchannel.
|
// Emit fchannel with RGB changed to contrast effectively against bchannel.
|
||||||
static uint32_t
|
static uint32_t
|
||||||
highcontrast(uint32_t bchannel){
|
highcontrast(const tinfo* ti, uint32_t bchannel){
|
||||||
unsigned r = ncchannel_r(bchannel);
|
unsigned r, g, b;
|
||||||
unsigned g = ncchannel_g(bchannel);
|
if(ncchannel_default_p(bchannel)){
|
||||||
unsigned b = ncchannel_b(bchannel);
|
r = ncchannel_r(ti->bg_collides_default);
|
||||||
|
g = ncchannel_g(ti->bg_collides_default);
|
||||||
|
b = ncchannel_b(ti->bg_collides_default);
|
||||||
|
}else{
|
||||||
|
// FIXME need to handle palette-indexed
|
||||||
|
r = ncchannel_r(bchannel);
|
||||||
|
g = ncchannel_g(bchannel);
|
||||||
|
b = ncchannel_b(bchannel);
|
||||||
|
}
|
||||||
uint32_t conrgb = 0;
|
uint32_t conrgb = 0;
|
||||||
if(r + g + b < 320){
|
if(r + g + b < 320){
|
||||||
ncchannel_set(&conrgb, 0xffffff);
|
ncchannel_set(&conrgb, 0xffffff);
|
||||||
@ -377,7 +385,7 @@ init_rvec(struct crender* rvec, int totalcells){
|
|||||||
// should be done at the end of rendering the cell, so that contrast is solved
|
// should be done at the end of rendering the cell, so that contrast is solved
|
||||||
// against the real background.
|
// against the real background.
|
||||||
static inline void
|
static inline void
|
||||||
lock_in_highcontrast(nccell* targc, struct crender* crender){
|
lock_in_highcontrast(const tinfo* ti, nccell* targc, struct crender* crender){
|
||||||
if(nccell_fg_alpha(targc) == NCALPHA_TRANSPARENT){
|
if(nccell_fg_alpha(targc) == NCALPHA_TRANSPARENT){
|
||||||
nccell_set_fg_default(targc);
|
nccell_set_fg_default(targc);
|
||||||
}
|
}
|
||||||
@ -390,13 +398,13 @@ lock_in_highcontrast(nccell* targc, struct crender* crender){
|
|||||||
unsigned fgblends = 3;
|
unsigned fgblends = 3;
|
||||||
uint32_t fchan = cell_fchannel(targc);
|
uint32_t fchan = cell_fchannel(targc);
|
||||||
uint32_t bchan = cell_bchannel(targc);
|
uint32_t bchan = cell_bchannel(targc);
|
||||||
uint32_t hchan = channels_blend(highcontrast(bchan), fchan, &fgblends);
|
uint32_t hchan = channels_blend(highcontrast(ti, bchan), fchan, &fgblends);
|
||||||
cell_set_fchannel(targc, hchan);
|
cell_set_fchannel(targc, hchan);
|
||||||
fgblends = crender->s.hcfgblends;
|
fgblends = crender->s.hcfgblends;
|
||||||
hchan = channels_blend(hchan, crender->hcfg, &fgblends);
|
hchan = channels_blend(hchan, crender->hcfg, &fgblends);
|
||||||
cell_set_fchannel(targc, hchan);
|
cell_set_fchannel(targc, hchan);
|
||||||
}else{
|
}else{
|
||||||
nccell_set_fg_rgb(targc, highcontrast(cell_bchannel(targc)));
|
nccell_set_fg_rgb(targc, highcontrast(ti, cell_bchannel(targc)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -405,10 +413,10 @@ lock_in_highcontrast(nccell* targc, struct crender* crender){
|
|||||||
// checking for and locking in high-contrast, checking for damage, and updating
|
// checking for and locking in high-contrast, checking for damage, and updating
|
||||||
// 'lastframe' for any cells which are damaged.
|
// 'lastframe' for any cells which are damaged.
|
||||||
static inline void
|
static inline void
|
||||||
postpaint_cell(nccell* lastframe, int dimx, struct crender* crender,
|
postpaint_cell(const tinfo* ti, nccell* lastframe, int dimx,
|
||||||
egcpool* pool, int y, int* x){
|
struct crender* crender, egcpool* pool, int y, int* x){
|
||||||
nccell* targc = &crender->c;
|
nccell* targc = &crender->c;
|
||||||
lock_in_highcontrast(targc, crender);
|
lock_in_highcontrast(ti, targc, crender);
|
||||||
nccell* prevcell = &lastframe[fbcellidx(y, dimx, *x)];
|
nccell* prevcell = &lastframe[fbcellidx(y, dimx, *x)];
|
||||||
if(cellcmp_and_dupfar(pool, prevcell, crender->p, targc) > 0){
|
if(cellcmp_and_dupfar(pool, prevcell, crender->p, targc) > 0){
|
||||||
//fprintf(stderr, "damaging due to cmp [%s] %d %d\n", nccell_extended_gcluster(crender->p, &crender->c), y, *x);
|
//fprintf(stderr, "damaging due to cmp [%s] %d %d\n", nccell_extended_gcluster(crender->p, &crender->c), y, *x);
|
||||||
@ -458,11 +466,12 @@ postpaint_cell(nccell* lastframe, int dimx, struct crender* crender,
|
|||||||
// FIXME can we not do the blend a single time here, if we track sums in
|
// FIXME can we not do the blend a single time here, if we track sums in
|
||||||
// paint()? tried this before and didn't get a win...
|
// paint()? tried this before and didn't get a win...
|
||||||
static void
|
static void
|
||||||
postpaint(nccell* lastframe, int dimy, int dimx, struct crender* rvec, egcpool* pool){
|
postpaint(const tinfo* ti, nccell* lastframe, int dimy, int dimx,
|
||||||
|
struct crender* rvec, egcpool* pool){
|
||||||
for(int y = 0 ; y < dimy ; ++y){
|
for(int y = 0 ; y < dimy ; ++y){
|
||||||
for(int x = 0 ; x < dimx ; ++x){
|
for(int x = 0 ; x < dimx ; ++x){
|
||||||
struct crender* crender = &rvec[fbcellidx(y, dimx, x)];
|
struct crender* crender = &rvec[fbcellidx(y, dimx, x)];
|
||||||
postpaint_cell(lastframe, dimx, crender, pool, y, &x);
|
postpaint_cell(ti, lastframe, dimx, crender, pool, y, &x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -511,7 +520,8 @@ int ncplane_mergedown(ncplane* restrict src, ncplane* restrict dst,
|
|||||||
paint(src, rvec, dst->leny, dst->lenx, dst->absy, dst->absx, NULL);
|
paint(src, rvec, dst->leny, dst->lenx, dst->absy, dst->absx, NULL);
|
||||||
paint(dst, rvec, dst->leny, dst->lenx, dst->absy, dst->absx, NULL);
|
paint(dst, rvec, dst->leny, dst->lenx, dst->absy, dst->absx, NULL);
|
||||||
//fprintf(stderr, "Postpaint start (%dx%d)\n", dst->leny, dst->lenx);
|
//fprintf(stderr, "Postpaint start (%dx%d)\n", dst->leny, dst->lenx);
|
||||||
postpaint(rendfb, dst->leny, dst->lenx, rvec, &dst->pool);
|
const struct tinfo* ti = &ncplane_notcurses_const(dst)->tcache;
|
||||||
|
postpaint(ti, rendfb, dst->leny, dst->lenx, rvec, &dst->pool);
|
||||||
//fprintf(stderr, "Postpaint done (%dx%d)\n", dst->leny, dst->lenx);
|
//fprintf(stderr, "Postpaint done (%dx%d)\n", dst->leny, dst->lenx);
|
||||||
free(dst->fb);
|
free(dst->fb);
|
||||||
dst->fb = rendfb;
|
dst->fb = rendfb;
|
||||||
@ -1353,7 +1363,8 @@ int ncpile_rasterize(ncplane* n){
|
|||||||
struct notcurses* nc = ncplane_notcurses(n);
|
struct notcurses* nc = ncplane_notcurses(n);
|
||||||
const int miny = pile->dimy < nc->lfdimy ? pile->dimy : nc->lfdimy;
|
const int miny = pile->dimy < nc->lfdimy ? pile->dimy : nc->lfdimy;
|
||||||
const int minx = pile->dimx < nc->lfdimx ? pile->dimx : nc->lfdimx;
|
const int minx = pile->dimx < nc->lfdimx ? pile->dimx : nc->lfdimx;
|
||||||
postpaint(nc->lastframe, miny, minx, pile->crender, &nc->pool);
|
const struct tinfo* ti = &ncplane_notcurses_const(n)->tcache;
|
||||||
|
postpaint(ti, nc->lastframe, miny, minx, pile->crender, &nc->pool);
|
||||||
clock_gettime(CLOCK_MONOTONIC, &rasterdone);
|
clock_gettime(CLOCK_MONOTONIC, &rasterdone);
|
||||||
int bytes = notcurses_rasterize(nc, pile, nc->rstate.mstreamfp);
|
int bytes = notcurses_rasterize(nc, pile, nc->rstate.mstreamfp);
|
||||||
// accepts -1 as an indication of failure
|
// accepts -1 as an indication of failure
|
||||||
|
Loading…
x
Reference in New Issue
Block a user