hide blending functions #917

This commit is contained in:
nick black 2020-08-18 08:41:55 -04:00
parent 3e3c8c1514
commit 05da44b06b
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
7 changed files with 51 additions and 75 deletions

View File

@ -4,6 +4,12 @@ rearrangements of Notcurses.
* 1.6.16 (not yet released)
* `cell_simple_p()` has been removed. It is no longer a useful concept for
user code, and its presence is indicative of a likely error.
* `channels_blend()` has been removed. It wasn't really useful to users,
and was difficult to explain.
* `ncplane_mergedown()` has been renamed `ncplane_mergedown_simple()`. A
more general form, capable of projecting arbitrary subregions of the source
plane down to the destination plane. The source argument to
`ncplane_mergedown_simple()` is now `const`.
* 1.6.15 (2020-08-16)
* Styles now work properly with `ncdirect`, which apparently has never

View File

@ -82,10 +82,6 @@ typedef struct cell {
**uint64_t cell_set_fchannel(cell* cl, uint32_t channel);**
**uint64_t cell_blend_fchannel(cell* cl, unsigned channel, unsigned blends)**
**uint64_t cell_blend_bchannel(cell* cl, unsigned channel, unsigned blends)**
**unsigned cell_fg(const cell* cl);**
**unsigned cell_bg(const cell* cl);**

View File

@ -81,21 +81,11 @@ namespace ncpp
return cell_set_fchannel (&_cell, channel);
}
uint64_t blend_fchannel (unsigned channel, unsigned* blends) noexcept
{
return cell_blend_fchannel (&_cell, channel, blends);
}
uint64_t set_bchannel (uint32_t channel) noexcept
{
return cell_set_bchannel (&_cell, channel);
}
uint64_t blend_bchannel (unsigned channel, unsigned* blends) noexcept
{
return cell_blend_bchannel (&_cell, channel, blends);
}
void set_styles (CellStyle styles) noexcept
{
cell_styles_set (&_cell, static_cast<unsigned>(styles));

View File

@ -1700,40 +1700,6 @@ API void ncplane_erase(struct ncplane* n);
#define NCPALETTESIZE 256
// Returns the result of blending two channels. 'blends' indicates how heavily
// 'c1' ought be weighed. If 'blends' is 0, 'c1' will be entirely replaced by
// 'c2'. If 'c1' is otherwise the default color, 'c1' will not be touched,
// since we can't blend default colors. Likewise, if 'c2' is a default color,
// it will not be used (unless 'blends' is 0).
//
// Palette-indexed colors do not blend. Do not pass me palette-indexed channels!
static inline unsigned
channels_blend(unsigned c1, unsigned c2, unsigned* blends){
if(channel_alpha(c2) == CELL_ALPHA_TRANSPARENT){
return c1; // do *not* increment *blends
}
unsigned rsum, gsum, bsum;
channel_rgb(c2, &rsum, &gsum, &bsum);
bool c2default = channel_default_p(c2);
if(*blends == 0){
// don't just return c2, or you set wide status and all kinds of crap
if(c2default){
channel_set_default(&c1);
}else{
channel_set_rgb(&c1, rsum, gsum, bsum);
}
channel_set_alpha(&c1, channel_alpha(c2));
}else if(!c2default && !channel_default_p(c1)){
rsum = (channel_r(c1) * *blends + rsum) / (*blends + 1);
gsum = (channel_g(c1) * *blends + gsum) / (*blends + 1);
bsum = (channel_b(c1) * *blends + bsum) / (*blends + 1);
channel_set_rgb(&c1, rsum, gsum, bsum);
channel_set_alpha(&c1, channel_alpha(c2));
}
++*blends;
return c1;
}
// Extract the 32-bit background channel from a cell.
static inline unsigned
cell_bchannel(const cell* cl){
@ -1758,17 +1724,6 @@ cell_set_fchannel(cell* cl, uint32_t channel){
return channels_set_fchannel(&cl->channels, channel);
}
// do not pass palette-indexed channels!
static inline uint64_t
cell_blend_fchannel(cell* cl, unsigned channel, unsigned* blends){
return cell_set_fchannel(cl, channels_blend(cell_fchannel(cl), channel, blends));
}
static inline uint64_t
cell_blend_bchannel(cell* cl, unsigned channel, unsigned* blends){
return cell_set_bchannel(cl, channels_blend(cell_bchannel(cl), channel, blends));
}
// Extract 24 bits of foreground RGB from 'cell', shifted to LSBs.
static inline unsigned
cell_fg(const cell* cl){

View File

@ -206,8 +206,6 @@ unsigned cell_bchannel(const cell* cl);
unsigned cell_fchannel(const cell* cl);
uint64_t cell_set_bchannel(cell* cl, uint32_t channel);
uint64_t cell_set_fchannel(cell* cl, uint32_t channel);
uint64_t cell_blend_fchannel(cell* cl, unsigned channel, unsigned* blends);
uint64_t cell_blend_bchannel(cell* cl, unsigned channel, unsigned* blends);
unsigned cell_fg(const cell* cl);
unsigned cell_bg(const cell* cl);
unsigned cell_fg_alpha(const cell* cl);

View File

@ -19,8 +19,6 @@
// cell_bg_palindex
// cell_bg_palindex_p
//+cell_bg_rgb
// cell_blend_bchannel
// cell_blend_fchannel
//+cellcmp
//+cell_double_wide_p
//+cell_extract
@ -302,18 +300,6 @@ pub fn cell_set_fchannel(cell: &mut cell, channel: Channel) -> ChannelPair {
ffi::channels_set_fchannel(&mut cell.channels, channel)
}
// NOTE: do not pass palette-indexed channels!
// static inline uint64_t
// cell_blend_fchannel(cell* cl, unsigned channel, unsigned* blends){
// return cell_set_fchannel(cl, channels_blend(cell_fchannel(cl), channel, blends));
// }
// NOTE: do not pass palette-indexed channels!
// static inline uint64_t
// cell_blend_bchannel(cell* cl, unsigned channel, unsigned* blends){
// return cell_set_bchannel(cl, channels_blend(cell_bchannel(cl), channel, blends));
// }
/// Extract 24 bits of foreground RGB from 'cell', shifted to LSBs.
// TODO: TEST
#[inline]

View File

@ -828,6 +828,51 @@ cell_nobackground_p(const cell* c){
// Destroy a plane and all its bound descendants.
int ncplane_genocide(ncplane *ncp);
// Returns the result of blending two channels. 'blends' indicates how heavily
// 'c1' ought be weighed. If 'blends' is 0, 'c1' will be entirely replaced by
// 'c2'. If 'c1' is otherwise the default color, 'c1' will not be touched,
// since we can't blend default colors. Likewise, if 'c2' is a default color,
// it will not be used (unless 'blends' is 0).
//
// Palette-indexed colors do not blend. Do not pass me palette-indexed channels!
static inline unsigned
channels_blend(unsigned c1, unsigned c2, unsigned* blends){
if(channel_alpha(c2) == CELL_ALPHA_TRANSPARENT){
return c1; // do *not* increment *blends
}
unsigned rsum, gsum, bsum;
channel_rgb(c2, &rsum, &gsum, &bsum);
bool c2default = channel_default_p(c2);
if(*blends == 0){
// don't just return c2, or you set wide status and all kinds of crap
if(channel_default_p(c2)){
channel_set_default(&c1);
}else{
channel_set_rgb(&c1, rsum, gsum, bsum);
}
channel_set_alpha(&c1, channel_alpha(c2));
}else if(!c2default && !channel_default_p(c1)){
rsum = (channel_r(c1) * *blends + rsum) / (*blends + 1);
gsum = (channel_g(c1) * *blends + gsum) / (*blends + 1);
bsum = (channel_b(c1) * *blends + bsum) / (*blends + 1);
channel_set_rgb(&c1, rsum, gsum, bsum);
channel_set_alpha(&c1, channel_alpha(c2));
}
++*blends;
return c1;
}
// do not pass palette-indexed channels!
static inline uint64_t
cell_blend_fchannel(cell* cl, unsigned channel, unsigned* blends){
return cell_set_fchannel(cl, channels_blend(cell_fchannel(cl), channel, blends));
}
static inline uint64_t
cell_blend_bchannel(cell* cl, unsigned channel, unsigned* blends){
return cell_set_bchannel(cl, channels_blend(cell_bchannel(cl), channel, blends));
}
#ifdef __cplusplus
}
#endif