Function photon_rs::colour_spaces::mix_with_colour
source · pub fn mix_with_colour(
photon_image: &mut PhotonImage,
mix_colour: Rgb,
opacity: f32
)
Expand description
Mix image with a single color, supporting passing opacity
.
The algorithm comes from Jimp. See function mix
and function colorFn
at following link:
https://github.com/oliver-moran/jimp/blob/29679faa597228ff2f20d34c5758e4d2257065a3/packages/plugin-color/src/index.js
Specifically, result_value = (mix_color_value - origin_value) * opacity + origin_value =
mix_color_value * opacity + (1 - opacity) * origin_value for each
of RGB channel.
Arguments
photon_image
- A PhotonImage that contains a view into the image.mix_color
- the color to be mixed in, as an RGB value.opacity
- the opacity of color when mixed to image. Float value from 0 to 1.
Example
// For example, to mix an image with rgb (50, 255, 254) and opacity 0.4:
use photon_rs::Rgb;
use photon_rs::colour_spaces::mix_with_colour;
use photon_rs::native::open_image;
let mix_colour = Rgb::new(50_u8, 255_u8, 254_u8);
let mut img = open_image("img.jpg").expect("File should open");
mix_with_colour(&mut img, mix_colour, 0.4_f32);