mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 14:47:54 +08:00
* Rename spread method to gradient spread so it matches the other gradient attribute names * Keep the legacy gradient struct's spread method field name matching its on-disk key
37 lines
1.2 KiB
Rust
37 lines
1.2 KiB
Rust
//! Not immediately shader compatible due to needing [`Gradient`] as a param, which needs [`Vec`]
|
|
|
|
use crate::adjust::Adjust;
|
|
use core_types::{Color, Ctx};
|
|
use raster_types::{CPU, Raster};
|
|
use vector_types::Gradient;
|
|
|
|
// Aims for interoperable compatibility with:
|
|
// https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#:~:text=%27grdm%27%20%3D%20Gradient%20Map
|
|
// https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#:~:text=Gradient%20settings%20(Photoshop%206.0)
|
|
#[node_macro::node(category("Raster: Adjustment"))]
|
|
fn gradient_map<T: Adjust<Color> + Clone + Send + Sync + core_types::CacheHash + 'static>(
|
|
_: impl Ctx,
|
|
#[implementations(
|
|
Raster<CPU>,
|
|
Color,
|
|
Gradient,
|
|
)]
|
|
mut image: T,
|
|
#[default(Color::BLACK, Color::WHITE)] gradient: IList<Gradient>,
|
|
reverse: bool,
|
|
) -> T {
|
|
if gradient.is_empty() {
|
|
return image;
|
|
}
|
|
let gradient_spread = gradient.lane(0).attr::<vector_types::markers::GradientSpread>();
|
|
let gradient = gradient.element_ref(0);
|
|
|
|
image.adjust(|color| {
|
|
let intensity = color.luminance_rec_709();
|
|
let intensity = if reverse { 1. - intensity } else { intensity };
|
|
gradient.evaluate(intensity as f64, gradient_spread)
|
|
});
|
|
|
|
image
|
|
}
|