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:
- Convert the backdrop and source colors from the blending color space to an intermediate HSL (hue-saturation-luminosity) representation.
- Create a new color from some combination of hue, saturation, and luminosity components selected from the backdrop and source colors.
- 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§
Trait Implementations§
Source§impl Clone for NonSeperableBlendMode
impl Clone for NonSeperableBlendMode
Source§fn clone(&self) -> NonSeperableBlendMode
fn clone(&self) -> NonSeperableBlendMode
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for NonSeperableBlendMode
impl Debug for NonSeperableBlendMode
Source§impl<'de> Deserialize<'de> for NonSeperableBlendMode
impl<'de> Deserialize<'de> for NonSeperableBlendMode
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl PartialEq for NonSeperableBlendMode
impl PartialEq for NonSeperableBlendMode
Source§impl Serialize for NonSeperableBlendMode
impl Serialize for NonSeperableBlendMode
impl Copy for NonSeperableBlendMode
impl StructuralPartialEq for NonSeperableBlendMode
Auto Trait Implementations§
impl Freeze for NonSeperableBlendMode
impl RefUnwindSafe for NonSeperableBlendMode
impl Send for NonSeperableBlendMode
impl Sync for NonSeperableBlendMode
impl Unpin for NonSeperableBlendMode
impl UnsafeUnpin for NonSeperableBlendMode
impl UnwindSafe for NonSeperableBlendMode
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
impl<U, T> ToOwnedObj<U> for Twhere
U: FromObjRef<T>,
Source§fn to_owned_obj(&self, data: FontData<'_>) -> U
fn to_owned_obj(&self, data: FontData<'_>) -> U
T, using the provided data to resolve any offsets.