mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-28 19:28:11 +08:00
Convert mix and gradient value to element kernels
This commit is contained in:
@@ -861,7 +861,7 @@ fn hex_to_color(_: impl Ctx, hex_code: String) -> List<Color> {
|
|||||||
|
|
||||||
/// Constructs a gradient value which may be set to any sequence of color stops to represent the transition between colors.
|
/// Constructs a gradient value which may be set to any sequence of color stops to represent the transition between colors.
|
||||||
#[node_macro::node(category("Value"))]
|
#[node_macro::node(category("Value"))]
|
||||||
fn gradient_value(_: impl Ctx, _primary: (), gradient: List<GradientStops>) -> List<GradientStops> {
|
fn gradient_value(_: impl Ctx, _primary: (), gradient: GradientStops) -> GradientStops {
|
||||||
gradient
|
gradient
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,6 +27,18 @@ mod blend_std {
|
|||||||
use raster_types::Image;
|
use raster_types::Image;
|
||||||
use raster_types::Raster;
|
use raster_types::Raster;
|
||||||
|
|
||||||
|
impl Blend<Color> for Raster<CPU> {
|
||||||
|
fn blend(&self, under: &Self, blend_fn: impl Fn(Color, Color) -> Color) -> Self {
|
||||||
|
let data = self.data.iter().zip(under.data.iter()).map(|(a, b)| blend_fn(*a, *b)).collect();
|
||||||
|
Raster::new_cpu(Image {
|
||||||
|
data,
|
||||||
|
width: self.width,
|
||||||
|
height: self.height,
|
||||||
|
base64_string: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Blend<Color> for List<Raster<CPU>> {
|
impl Blend<Color> for List<Raster<CPU>> {
|
||||||
fn blend(&self, under: &Self, blend_fn: impl Fn(Color, Color) -> Color) -> Self {
|
fn blend(&self, under: &Self, blend_fn: impl Fn(Color, Color) -> Color) -> Self {
|
||||||
let mut result_list = self.clone();
|
let mut result_list = self.clone();
|
||||||
@@ -141,21 +153,22 @@ pub fn apply_blend_mode(foreground: Color, background: Color, blend_mode: BlendM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
#[node_macro::node(category("Raster"), cfg(feature = "std"))]
|
#[node_macro::node(category("Raster"), cfg(feature = "std"))]
|
||||||
fn mix<T: Blend<Color> + Send>(
|
fn mix<T: Blend<Color> + Clone + Send + Sync + core_types::CacheHash + 'static>(
|
||||||
_: impl Ctx,
|
_: impl Ctx,
|
||||||
#[implementations(
|
#[implementations(
|
||||||
List<Raster<CPU>>,
|
Raster<CPU>,
|
||||||
List<Color>,
|
Color,
|
||||||
List<GradientStops>,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
#[gpu_image]
|
#[gpu_image]
|
||||||
over: T,
|
over: T,
|
||||||
#[expose]
|
#[expose]
|
||||||
#[implementations(
|
#[implementations(
|
||||||
List<Raster<CPU>>,
|
Raster<CPU>,
|
||||||
List<Color>,
|
Color,
|
||||||
List<GradientStops>,
|
GradientStops,
|
||||||
)]
|
)]
|
||||||
#[gpu_image]
|
#[gpu_image]
|
||||||
under: T,
|
under: T,
|
||||||
|
|||||||
Reference in New Issue
Block a user