mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-18 03:25:55 +00:00
sexblitter: honor nointerpolate throughout #1763
This commit is contained in:
parent
048f2f5e77
commit
350f531a5a
@ -528,20 +528,17 @@ quadrant_blit(ncplane* nc, int linesize, const void* data, int leny, int lenx,
|
|||||||
// (all six pixels are different colors). We want to solve for the 2-partition
|
// (all six pixels are different colors). We want to solve for the 2-partition
|
||||||
// of pixels that minimizes total source distance from the resulting lerps.
|
// of pixels that minimizes total source distance from the resulting lerps.
|
||||||
static const char*
|
static const char*
|
||||||
sex_solver(const uint32_t rgbas[6], uint64_t* channels, unsigned blendcolors){
|
sex_solver(const uint32_t rgbas[6], uint64_t* channels, unsigned blendcolors,
|
||||||
|
unsigned nointerpolate){
|
||||||
// each element within the set of 64 has an inverse element within the set,
|
// each element within the set of 64 has an inverse element within the set,
|
||||||
// for which we would calculate the same total differences, so just handle
|
// for which we would calculate the same total differences, so just handle
|
||||||
// the first 32. the partition[] bit masks represent combinations of
|
// the first 32. the partition[] bit masks represent combinations of
|
||||||
// sextants, and their indices correspond to sex[].
|
// sextants, and their indices correspond to sex[].
|
||||||
static const char* sex[32] = {
|
static const char* sex[32] = {
|
||||||
" ", "🬀", "🬁", "🬃", "🬇", "🬏", "🬞", "🬂", // 0..7
|
" ", "🬀", "🬁", "🬃", "🬇", "🬏", "🬞", "🬂", // 0..7
|
||||||
|
|
||||||
"🬄", "🬈", "🬐", "🬟", "🬅", "🬉", "🬑", "🬠", // 8..15
|
"🬄", "🬈", "🬐", "🬟", "🬅", "🬉", "🬑", "🬠", // 8..15
|
||||||
|
|
||||||
"🬋", "🬓", "🬢", "🬖", "🬦", "🬭", "🬆", "🬊", // 16..23
|
"🬋", "🬓", "🬢", "🬖", "🬦", "🬭", "🬆", "🬊", // 16..23
|
||||||
|
|
||||||
"🬒", "🬡", "🬌", "▌", "🬣", "🬗", "🬧", "🬍", // 24..31
|
"🬒", "🬡", "🬌", "▌", "🬣", "🬗", "🬧", "🬍", // 24..31
|
||||||
|
|
||||||
};
|
};
|
||||||
static const unsigned partitions[32] = {
|
static const unsigned partitions[32] = {
|
||||||
0, // 1 way to arrange 0
|
0, // 1 way to arrange 0
|
||||||
@ -561,20 +558,26 @@ sex_solver(const uint32_t rgbas[6], uint64_t* channels, unsigned blendcolors){
|
|||||||
unsigned gsum0 = 0, gsum1 = 0;
|
unsigned gsum0 = 0, gsum1 = 0;
|
||||||
unsigned bsum0 = 0, bsum1 = 0;
|
unsigned bsum0 = 0, bsum1 = 0;
|
||||||
int insum = 0;
|
int insum = 0;
|
||||||
|
int outsum = 0;
|
||||||
for(unsigned mask = 0 ; mask < 6 ; ++mask){
|
for(unsigned mask = 0 ; mask < 6 ; ++mask){
|
||||||
if(partitions[glyph] & (1u << mask)){
|
if(partitions[glyph] & (1u << mask)){
|
||||||
rsum0 += ncpixel_r(rgbas[mask]);
|
if(!nointerpolate || !insum){
|
||||||
gsum0 += ncpixel_g(rgbas[mask]);
|
rsum0 += ncpixel_r(rgbas[mask]);
|
||||||
bsum0 += ncpixel_b(rgbas[mask]);
|
gsum0 += ncpixel_g(rgbas[mask]);
|
||||||
++insum;
|
bsum0 += ncpixel_b(rgbas[mask]);
|
||||||
|
++insum;
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
rsum1 += ncpixel_r(rgbas[mask]);
|
if(!nointerpolate || !outsum){
|
||||||
gsum1 += ncpixel_g(rgbas[mask]);
|
rsum1 += ncpixel_r(rgbas[mask]);
|
||||||
bsum1 += ncpixel_b(rgbas[mask]);
|
gsum1 += ncpixel_g(rgbas[mask]);
|
||||||
|
bsum1 += ncpixel_b(rgbas[mask]);
|
||||||
|
++outsum;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uint32_t l0 = generalerp(rsum0, gsum0, bsum0, insum);
|
uint32_t l0 = generalerp(rsum0, gsum0, bsum0, insum);
|
||||||
uint32_t l1 = generalerp(rsum1, gsum1, bsum1, 6 - insum);
|
uint32_t l1 = generalerp(rsum1, gsum1, bsum1, outsum);
|
||||||
//fprintf(stderr, "sum0: %06x sum1: %06x insum: %d\n", l0 & 0xffffffu, l1 & 0xffffffu, insum);
|
//fprintf(stderr, "sum0: %06x sum1: %06x insum: %d\n", l0 & 0xffffffu, l1 & 0xffffffu, insum);
|
||||||
uint32_t totaldiff = 0;
|
uint32_t totaldiff = 0;
|
||||||
for(unsigned mask = 0 ; mask < 6 ; ++mask){
|
for(unsigned mask = 0 ; mask < 6 ; ++mask){
|
||||||
@ -629,22 +632,14 @@ sex_trans_check(cell* c, const uint32_t rgbas[6], unsigned blendcolors,
|
|||||||
unsigned transstring = 0;
|
unsigned transstring = 0;
|
||||||
unsigned r = 0, g = 0, b = 0;
|
unsigned r = 0, g = 0, b = 0;
|
||||||
unsigned div = 0;
|
unsigned div = 0;
|
||||||
bool locked = false; // for nointerpolate case, we pick first non-trans
|
|
||||||
for(unsigned mask = 0 ; mask < 6 ; ++mask){
|
for(unsigned mask = 0 ; mask < 6 ; ++mask){
|
||||||
if(rgba_trans_p(rgbas[mask], transcolor)){
|
if(rgba_trans_p(rgbas[mask], transcolor)){
|
||||||
transstring |= (1u << mask);
|
transstring |= (1u << mask);
|
||||||
}else{
|
}else if(!nointerpolate || !div){
|
||||||
if(!nointerpolate){
|
r += ncpixel_r(rgbas[mask]);
|
||||||
r += ncpixel_r(rgbas[mask]);
|
g += ncpixel_g(rgbas[mask]);
|
||||||
g += ncpixel_g(rgbas[mask]);
|
b += ncpixel_b(rgbas[mask]);
|
||||||
b += ncpixel_b(rgbas[mask]);
|
++div;
|
||||||
++div;
|
|
||||||
}else if(!locked){
|
|
||||||
r = ncpixel_r(rgbas[mask]);
|
|
||||||
g = ncpixel_g(rgbas[mask]);
|
|
||||||
b = ncpixel_b(rgbas[mask]);
|
|
||||||
div = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(transstring == 0){ // there was no transparency
|
if(transstring == 0){ // there was no transparency
|
||||||
@ -719,7 +714,7 @@ sextant_blit(ncplane* nc, int linesize, const void* data, int leny, int lenx,
|
|||||||
c->stylemask = 0;
|
c->stylemask = 0;
|
||||||
const char* egc = sex_trans_check(c, rgbas, blendcolors, bargs->transcolor, nointerpolate);
|
const char* egc = sex_trans_check(c, rgbas, blendcolors, bargs->transcolor, nointerpolate);
|
||||||
if(egc == NULL){ // no transparency; run a full solver
|
if(egc == NULL){ // no transparency; run a full solver
|
||||||
egc = sex_solver(rgbas, &c->channels, blendcolors);
|
egc = sex_solver(rgbas, &c->channels, blendcolors, nointerpolate);
|
||||||
cell_set_blitquadrants(c, 1, 1, 1, 1);
|
cell_set_blitquadrants(c, 1, 1, 1, 1);
|
||||||
}
|
}
|
||||||
//fprintf(stderr, "sex EGC: %s channels: %016lx\n", egc, c->channels);
|
//fprintf(stderr, "sex EGC: %s channels: %016lx\n", egc, c->channels);
|
||||||
|
Loading…
Reference in New Issue
Block a user