Skip to main content

NonSeperableBlendMode

Enum NonSeperableBlendMode 

Source
pub enum NonSeperableBlendMode {
    Hue,
    Saturation,
    Color,
    Luminosity,
}
Expand description

Since the nonseparable blend modes consider all color components in combination, their computation depends on the blending color space in which the components are interpreted. They may be applied to all multiple-component color spaces that are allowed as blending color spaces (see Section 7.2.3, “Blending Color Space”).

All of these blend modes conceptually entail the following steps:

  1. Convert the backdrop and source colors from the blending color space to an intermediate HSL (hue-saturation-luminosity) representation.
  2. Create a new color from some combination of hue, saturation, and luminosity components selected from the backdrop and source colors.
  3. Convert the result back to the original (blending) color space.

However, the formulas given below do not actually perform these conversions. Instead, they start with whichever color (backdrop or source) is providing the hue for the result; then they adjust this color to have the proper saturation and luminosity.

§For RGB color spaces

The nonseparable blend mode formulas make use of several auxiliary functions. These functions operate on colors that are assumed to have red, green, and blue components.

fn luminosity(input: Rgb) -> f32 {
    0.3 * input.r + 0.59 * input.g + 0.11 * input.b
}

fn set_luminosity(input: Rgb, target_luminosity: f32) -> Rgb {
    let d = target_luminosity - luminosity(input);
    Rgb {
        r: input.r + d,
        g: input.g + d,
        b: input.b + d,
        icc_profile: input.icc_profile,
    }
}

fn clip_color(mut input: Rgb) -> Rgb {

    let lum = luminosity(input);

    let mut cur_r = (input.r * 1000.0) as i64;
    let mut cur_g = (input.g * 1000.0) as i64;
    let mut cur_b = (input.b * 1000.0) as i64;

    /// min! and max! is defined in printpdf/src/glob_macros.rs
    let mut min = min!(cur_r, cur_g, cur_b);
    let mut max = max!(cur_r, cur_g, cur_b);

    let new_min = (min as f32) / 1000.0;
    let new_max = (max as f32) / 1000.0;

    if new_min < 0.0 {
        input.r = lum + (((input.r - lum) * lum) / (lum - new_min));
        input.g = lum + (((input.g - lum) * lum) / (lum - new_min));
        input.b = lum + (((input.b - lum) * lum) / (lum - new_min));
    } else if new_max > 1.0 {
        input.r = lum + ((input.r - lum) * (1.0 - lum) / (new_max - lum));
        input.g = lum + ((input.g - lum) * (1.0 - lum) / (new_max - lum));
        input.b = lum + ((input.b - lum) * (1.0 - lum) / (new_max - lum));
    }

    return input;
}

fn saturation(input: Rgb) -> f32 {
    let mut cur_r = (input.r * 1000.0) as i64;
    let mut cur_g = (input.g * 1000.0) as i64;
    let mut cur_b = (input.b * 1000.0) as i64;

    /// min! and max! is defined in printpdf/src/glob_macros.rs
    let mut min = min!(cur_r, cur_g, cur_b);
    let mut max = max!(cur_r, cur_g, cur_b);

    let new_min = (min as f32) / 1000.0;
    let new_max = (max as f32) / 1000.0;
    new_max - new_min
}

§For CMYK color spaces

The C, M, and Y components are converted to their complementary R, G, and B components in the usual way. The formulas above are applied to the RGB color values. The results are converted back to C, M, and Y.

For the K component, the result is the K component of Cb for the Hue, Saturation, and Color blend modes; it is the K component of Cs for the Luminosity blend mode.

Variants§

§

Hue

§

Saturation

§

Color

§

Luminosity

Trait Implementations§

Source§

impl Clone for NonSeperableBlendMode

Source§

fn clone(&self) -> NonSeperableBlendMode

Returns a duplicate 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 NonSeperableBlendMode

Source§

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

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

impl<'de> Deserialize<'de> for NonSeperableBlendMode

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for NonSeperableBlendMode

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for NonSeperableBlendMode

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for NonSeperableBlendMode

Source§

impl StructuralPartialEq for NonSeperableBlendMode

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Finish for T

Source§

fn finish(self)

Does nothing but move self, equivalent to drop.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

Source§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
Source§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

Source§

fn to_owned_table(&self) -> U

Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<G1, G2> Within<G2> for G1
where G2: Contains<G1>,

Source§

fn is_within(&self, b: &G2) -> bool

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,