mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-20 03:25:47 +00:00
blend: conditionally blend in alpha
This commit is contained in:
parent
f280db744d
commit
2ebc3e2bfe
@ -1117,13 +1117,19 @@ channels_blend(unsigned c1, unsigned c2, unsigned blends){
|
||||
unsigned rsum, gsum, bsum;
|
||||
if(blends == 0){
|
||||
// don't just return c2, or you set wide status and all kinds of crap
|
||||
channel_rgb(c2, &rsum, &gsum, &bsum);
|
||||
channel_set_rgb(&c1, rsum, gsum, bsum);
|
||||
if(channel_default_p(c2)){
|
||||
channel_set_default(&c1);
|
||||
}else{
|
||||
channel_rgb(c2, &rsum, &gsum, &bsum);
|
||||
channel_set_rgb(&c1, rsum, gsum, bsum);
|
||||
}
|
||||
channel_set_alpha(&c1, channel_alpha(c2));
|
||||
}else if(!channel_default_p(c2) && !channel_default_p(c1)){
|
||||
rsum = (channel_r(c1) * blends + channel_r(c2)) / (blends + 1);
|
||||
gsum = (channel_g(c1) * blends + channel_g(c2)) / (blends + 1);
|
||||
bsum = (channel_b(c1) * blends + channel_b(c2)) / (blends + 1);
|
||||
channel_set_rgb(&c1, rsum, gsum, bsum);
|
||||
channel_set_alpha(&c1, channel_alpha(c2));
|
||||
}
|
||||
return c1;
|
||||
}
|
||||
|
@ -17,6 +17,12 @@ mathplane(struct notcurses* nc){
|
||||
const int HEIGHT = 9;
|
||||
const int WIDTH = dimx;
|
||||
struct ncplane* n = ncplane_new(nc, HEIGHT, WIDTH, dimy - HEIGHT - 1, dimx - WIDTH, NULL);
|
||||
cell b = CELL_TRIVIAL_INITIALIZER;
|
||||
cell_set_fg_rgb(&b, 0xff, 0xff, 0xff);
|
||||
cell_set_fg_alpha(&b, CELL_ALPHA_BLEND);
|
||||
cell_set_bg_alpha(&b, CELL_ALPHA_TRANSPARENT);
|
||||
ncplane_set_base(n, &b);
|
||||
cell_release(n, &b);
|
||||
ncplane_set_fg_rgb(n, 0xff, 0xff, 0xff);
|
||||
if(n){
|
||||
ncplane_printf_aligned(n, 0, NCALIGN_RIGHT, "∮E⋅da=Q,n→∞,∑f(i)=∏g(i)⎧⎡⎛┌─────┐⎞⎤⎫");
|
||||
@ -67,6 +73,7 @@ surrounding_cells(struct ncplane* n, cell* cells, int y, int x){
|
||||
static int
|
||||
lightup_surrounding_cells(struct ncplane* n, const cell* cells, int y, int x){
|
||||
cell c = CELL_TRIVIAL_INITIALIZER;
|
||||
/*
|
||||
cell_duplicate(n, &c, &cells[0]);
|
||||
lighten(n, &c, 2, y - 1, x - 1);
|
||||
cell_duplicate(n, &c, &cells[1]);
|
||||
@ -91,6 +98,7 @@ lightup_surrounding_cells(struct ncplane* n, const cell* cells, int y, int x){
|
||||
lighten(n, &c, 2, y, x - 2);
|
||||
cell_duplicate(n, &c, &cells[11]);
|
||||
lighten(n, &c, 2, y, x + 2);
|
||||
*/
|
||||
cell_duplicate(n, &c, &cells[12]);
|
||||
lighten(n, &c, 0, y, x);
|
||||
cell_release(n, &c);
|
||||
|
@ -143,16 +143,13 @@ TEST_CASE("ChannelBlendDefaultRight") {
|
||||
uint32_t c1 = 0;
|
||||
uint32_t c2 = 0;
|
||||
channel_set_rgb(&c1, 0x80, 0x40, 0x20);
|
||||
CHECK(!channel_default_p(c1));
|
||||
CHECK(channel_default_p(c2));
|
||||
uint32_t c = channels_blend(c1, c2, 0);
|
||||
CHECK(channel_default_p(c));
|
||||
unsigned r, g, b;
|
||||
channel_rgb(c, &r, &g, &b);
|
||||
CHECK(0 == r);
|
||||
CHECK(0 == g);
|
||||
CHECK(0 == b);
|
||||
c = channels_blend(c1, c2, 1);
|
||||
CHECK(!channel_default_p(c));
|
||||
unsigned r, g, b;
|
||||
channel_rgb(c, &r, &g, &b);
|
||||
CHECK(0x80 == r);
|
||||
CHECK(0x40 == g);
|
||||
|
Loading…
Reference in New Issue
Block a user