#[repr(transparent)]
pub struct NcChannels(pub NcChannels_u64);
Expand description

64 bits containing a foreground and background NcChannel

At render time, both 24-bit NcRgb values are quantized down to terminal capabilities, if necessary. There’s a clear path to 10-bit support should we one day need it.

Default Color

The “default color” is best explained by color(3NCURSES) and default_colors(3NCURSES). Ours is the same concept.

Until the “not default color” bit is set, any color you load will be ignored.

Diagram

~~AA~~~~|RRRRRRRR|GGGGGGGG|BBBBBBBB║~~AA~~~~|RRRRRRRR|GGGGGGGG|BBBBBBBB
↑↑↑↑↑↑↑↑↑↑↑↑ foreground ↑↑↑↑↑↑↑↑↑↑↑║↑↑↑↑↑↑↑↑↑↑↑↑ background ↑↑↑↑↑↑↑↑↑↑↑

Detailed info (specially on the context-dependent bits on each NcChannel’s 4th byte):

                            ~foreground channel~
reserved, must be 0                                  ↓bits view↓               ↓hex mask↓
0·······|········|········|········║········|········|········|········  =  8·······|········

NcChannels::FG_DEFAULT_MASK: foreground is NOT "default color"
·1······|········|········|········║········|········|········|········  =  4·······|········

NcChannels::FG_ALPHA_MASK: foreground alpha (2bits)
··11····|········|········|········║········|········|········|········  =  3·······|········

NcChannels::FG_PALETTE: foreground uses palette index
····1···|········|········|········║········|········|········|········  =  ·8······|········

NcChannels::NOBACKGROUND_MASK: glyph is entirely foreground
·····1··|········|········|········║········|········|········|········  =  ·4······|········

reserved, must be 0
······00|········|········|········║········|········|········|········  =  ·3······|········

NcChannels::FG_RGB_MASK: foreground in 3x8 RGB (rrggbb)
········|11111111|11111111|11111111║········|········|········|········  =  ··FFFFFF|········
                            ~background channel~
reserved, must be 0                                  ↓bits view↓               ↓hex mask↓
········|········|········|········║0·······|········|········|········  =  ········|8·······

NcChannels::BGDEFAULT_MASK: background is NOT "default color"
········|········|········|········║·1······|········|········|········  =  ········|4·······

NcChannels::BG_ALPHA_MASK: background alpha (2 bits)
········|········|········|········║··11····|········|········|········  =  ········|3·······

NcChannels::BG_PALETTE: background uses palette index
········|········|········|········║····1···|········|········|········  =  ········|·8······

reserved, must be 0
········|········|········|········║·····000|········|········|········  =  ········|·7······

NcChannels::BG_RGB_MASK: background in 3x8 RGB (rrggbb)
········|········|········|········║········|11111111|11111111|11111111  =  ········|··FFFFFF

type in C: channels (uint64_t)

NcChannels Mask Flags

Tuple Fields§

§0: NcChannels_u64

Implementations§

source§

impl NcChannels

source

pub const BG_DEFAULT_MASK: u32 = 1_073_741_824u32

If this bit is set, we are not using the default background color.

See the detailed diagram at NcChannels

source

pub const BG_ALPHA_MASK: u32 = 805_306_368u32

Extract these bits to get the background NcAlpha mask.

See the detailed diagram at NcChannels

source

pub const BG_PALETTE_MASK: u32 = 134_217_728u32

If this bit and BG_DEFAULT_MASK are set, we’re using a palette-indexed background color.

See the detailed diagram at NcChannels

source

pub const BG_RGB_MASK: u32 = 16_777_215u32

Extract these bits to get the background NcRgb value.

source

pub const NOBACKGROUND_MASK: u64 = 9_727_775_195_120_271_360u64

Does this glyph completely obscure the background? If so, there’s no need to emit a background when rasterizing, a small optimization. These are also used to track regions into which we must not cellblit.

source§

impl NcChannels

source

pub fn new() -> Self

New NcChannels, set to black and NOT using the “default color”.

source

pub fn with_default() -> Self

New NcChannels, set to black and using the “default color”.

source

pub fn from_rgb(fg_rgb: impl Into<NcRgb>, bg_rgb: impl Into<NcRgb>) -> Self

New NcChannels, expects two separate NcRgbs for the foreground and background channels.

source

pub fn from_rgb_both(rgb: impl Into<NcRgb>) -> Self

New NcChannels, expects a single NcRgb for both foreground and background channels.

source

pub fn from_rgb_alpha( fg_rgb: impl Into<NcRgb>, fg_alpha: impl Into<NcAlpha>, bg_rgb: impl Into<NcRgb>, bg_alpha: impl Into<NcAlpha> ) -> Self

New NcChannels, expects two separate NcRgb & NcAlpha for the foreground and background channels.

source

pub fn from_rgb_alpha_both( rgb: impl Into<NcRgb>, alpha: impl Into<NcAlpha> ) -> Self

New NcChannels, expects NcRgb & NcAlpha for both channels.

source

pub fn combine( fchannel: impl Into<NcChannel>, bchannel: impl Into<NcChannel> ) -> Self

Combines two NcChannels into an NcChannels.

C style function: channels_combine().

source

pub fn reverse(&mut self) -> Self

Returns the NcChannels with the fore- and background’s color information swapped, but without touching housekeeping bits.

Alpha is retained unless it would lead to an illegal state: HIGHCONTRAST, TRANSPARENT and BLEND are taken to OPAQUE unless the new value is RGB.

HIGHCONTRAST TRANSPARENT BLEND OPAQUE

C style function: ncchannels_reverse().

source§

impl NcChannels

source

pub fn fchannel(&self) -> NcChannel

Gets the foreground alpha and coloring bits as an NcChannel.

C style function: ncchannels_fchannel().

source

pub fn bchannel(&self) -> NcChannel

Gets the background alpha and coloring bits as an NcChannel.

C style function: ncchannels_bchannel().

source

pub fn set_fchannel(&mut self, fchannel: impl Into<NcChannel>) -> Self

Sets the foreground alpha and coloring bits from an NcChannel.

C style function: ncchannels_set_fchannel().

source

pub fn set_bchannel(&mut self, bchannel: impl Into<NcChannel>) -> Self

Sets the background alpha and coloring bits from an NcChannel.

C style function: ncchannels_set_bchannel().

source

pub fn channels(&self) -> NcChannels

Gets the alpha and coloring bits as an NcChannels.

C style function: ncchannels_bchannel().

source

pub fn set_channels(&mut self, from_channels: impl Into<NcChannels>) -> Self

Sets the foreground alpha and coloring bits as an NcChannels, from another NcChannels.

C style function: ncchannels_set_fchannel().

source

pub fn fg_alpha(&self) -> NcAlpha

Gets the foreground NcAlpha.

C style function: ncchannels_fg_alpha().

source

pub fn bg_alpha(&self) -> NcAlpha

Gets the background NcAlpha.

C style function: ncchannels_bg_alpha().

source

pub fn set_fg_alpha(&mut self, alpha: impl Into<NcAlpha>) -> NcResult<()>

Sets the foreground NcAlpha.

C style function: ncchannels_set_fg_alpha().

source

pub fn set_bg_alpha(&mut self, alpha: impl Into<NcAlpha>) -> NcResult<()>

Sets the background NcAlpha.

C style function: ncchannels_set_bg_alpha().

source

pub fn fg_rgb_p(&self) -> bool

Returns true if the foreground channel is set to RGB color.

C style function: ncchannels_fg_rgb_p().

source

pub fn bg_rgb_p(&self) -> bool

Returns true if the background channel is set to RGB color.

C style function: ncchannels_bg_rgb_p().

source

pub fn fg_rgb(&self) -> NcRgb

Gets the foreground NcRgb.

C style function: ncchannels_fg_rgb().

source

pub fn bg_rgb(&self) -> NcRgb

Gets the background NcRgb.

C style function: ncchannels_bg_rgb().

source

pub fn set_fg_rgb(&mut self, rgb: impl Into<NcRgb>) -> Self

Sets the foreground NcRgb.

C style function: channels_set_fg_rgb().

source

pub fn set_bg_rgb(&mut self, rgb: impl Into<NcRgb>) -> Self

Sets the background NcRgb.

C style function: channels_set_bg_rgb().

source

pub fn fg_r(&self) -> u8

Gets the foreground red component.

(No equivalent C style function)

source

pub fn fg_g(&self) -> u8

Gets the foreground green component.

(No equivalent C style function)

source

pub fn fg_b(&self) -> u8

Gets the foreground blue component.

(No equivalent C style function)

source

pub fn bg_r(&self) -> u8

Gets the background red component.

(No equivalent C style function)

source

pub fn bg_g(&self) -> u8

Gets the background green component.

(No equivalent C style function)

source

pub fn bg_b(&self) -> u8

Gets the background blue component.

(No equivalent C style function)

source

pub fn fg_set_r(&mut self, r: impl Into<u8>) -> Self

Sets the foreground red component, and returns the new NcChannels.

(No equivalent C style function)

source

pub fn fg_set_g(&mut self, g: impl Into<u8>) -> Self

Sets the foreground green component, and returns the new NcChannels.

(No equivalent C style function)

source

pub fn fg_set_b(&mut self, b: impl Into<u8>) -> Self

Sets the foreground blue component, and returns the new NcChannels.

(No equivalent C style function)

source

pub fn bg_set_r(&mut self, r: impl Into<u8>) -> Self

Sets the background red component, and returns the new NcChannels.

(No equivalent C style function)

source

pub fn bg_set_g(&mut self, g: impl Into<u8>) -> Self

Sets the background green component, and returns the new NcChannels.

(No equivalent C style function)

source

pub fn bg_set_b(&mut self, b: impl Into<u8>) -> Self

Sets the background blue component, and returns the new NcChannels.

(No equivalent C style function)

source

pub fn fg_default_p(&self) -> bool

Is the background using the “default background color”?

C style function: channels_fg_default_p().

source

pub fn bg_default_p(&self) -> bool

Is the background using the “default background color”?

The “default background color” must generally be used to take advantage of terminal-effected transparency.

C style function: channels_bg_default_p().

source

pub fn set_fg_default(&mut self) -> Self

Marks the foreground as using its “default color”, and returns the new NcChannels.

C style function: channels_set_fg_default().

source

pub fn set_bg_default(&mut self) -> Self

Marks the background as using its “default color”, and returns the new NcChannels.

C style function: channels_set_bg_default().

source

pub fn set_fg_not_default(&mut self) -> Self

Marks the foreground as NOT using its “default color”, and returns the new NcChannels.

C style function: channels_set_fg_default().

source

pub fn set_bg_not_default(&mut self) -> Self

Marks the background as NOT using its “default color”, and returns the new NcChannels.

C style function: channels_set_bg_not_default().

source

pub fn set_default(&mut self) -> Self

Marks both the foreground and background as using its “default color”, and returns the new NcChannels.

source

pub fn set_not_default(&mut self) -> Self

Marks both the foreground and background as NOT using its “default color”, and returns the new NcChannels.

source

pub fn fg_palindex(&self) -> NcPaletteIndex

Gets the NcPaletteIndex from the foreground NcChannel.

C style function: channels_fg_palindex().

source

pub fn bg_palindex(&self) -> NcPaletteIndex

Gets the NcPaletteIndex from the background NcChannel.

C style function: channels_bg_palindex().

source

pub fn fg_palindex_p(&self) -> bool

Is the foreground of using an indexed NcPalette color?

C style function: channels_fg_palindex_p().

source

pub fn bg_palindex_p(&self) -> bool

Is the background of using an indexed NcPalette color?

C style function: channels_bg_palindex_p().

source

pub fn set_fg_palindex(&mut self, index: impl Into<NcPaletteIndex>) -> Self

Sets the foreground of an NcChannels as using an indexed NcPalette color.

C style function: channels_set_fg_palindex().

source

pub fn set_bg_palindex(&mut self, index: impl Into<NcPaletteIndex>) -> Self

Sets the background of an NcChannels as using an indexed NcPalette color.

C style function: channels_set_bg_palindex().

Trait Implementations§

source§

impl Binary for NcChannels

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl Clone for NcChannels

source§

fn clone(&self) -> NcChannels

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for NcChannels

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for NcChannels

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Display for NcChannels

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> From<&'a NcChannels> for &'a NcChannels_u64

source§

fn from(s: &'a NcChannels) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a mut NcChannels> for &'a mut NcChannels_u64

source§

fn from(s: &'a mut NcChannels) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a mut u64> for NcChannels

source§

fn from(p: &'a mut NcChannels_u64) -> Self

Converts to this type from the input type.
source§

impl<'a> From<&'a u64> for NcChannels

source§

fn from(p: &'a NcChannels_u64) -> Self

Converts to this type from the input type.
source§

impl From<&NcChannels> for *const NcChannels_u64

source§

fn from(s: &NcChannels) -> Self

Converts to this type from the input type.
source§

impl From<&mut NcChannels> for *mut NcChannels_u64

source§

fn from(s: &mut NcChannels) -> Self

Converts to this type from the input type.
source§

impl From<[u8; 6]> for NcChannels

source§

fn from(a: [u8; 6]) -> Self

Converts to this type from the input type.
source§

impl From<(u8, u8, u8, u8, u8, u8)> for NcChannels

source§

fn from(t: (u8, u8, u8, u8, u8, u8)) -> Self

Converts to this type from the input type.
source§

impl From<NcChannels> for [u8; 6]

source§

fn from(rgb: NcChannels) -> Self

Converts to this type from the input type.
source§

impl From<NcChannels> for (u8, u8, u8, u8, u8, u8)

source§

fn from(rgb: NcChannels) -> Self

Converts to this type from the input type.
source§

impl From<NcChannels> for NcChannels_u64

source§

fn from(s: NcChannels) -> Self

Converts to this type from the input type.
source§

impl From<u64> for NcChannels

source§

fn from(p: NcChannels_u64) -> Self

Converts to this type from the input type.
source§

impl LowerHex for NcChannels

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl Octal for NcChannels

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl PartialEq<NcChannels> for NcChannels

source§

fn eq(&self, other: &NcChannels) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl UpperHex for NcChannels

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter.
source§

impl Copy for NcChannels

source§

impl Eq for NcChannels

source§

impl StructuralEq for NcChannels

source§

impl StructuralPartialEq for NcChannels

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.