mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 14:58:05 +08:00
Improve node macro and add more diagnostics (#1999)
* Improve node macro ergonomics * Fix type error in stub import * Fix wasm nodes * Code review --------- Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
@@ -271,7 +271,7 @@ impl From<BlendMode> for vello::peniko::Mix {
|
||||
#[node_macro::node(category("Raster: Adjustment"))] // Unique to Graphite
|
||||
async fn luminance<T: Adjust<Color>>(
|
||||
footprint: Footprint,
|
||||
#[implementations((Footprint, Color), (Footprint, ImageFrame<Color>))] input: impl Node<Footprint, Output = T>,
|
||||
#[implementations(Footprint -> Color, Footprint -> ImageFrame<Color>)] input: impl Node<Footprint, Output = T>,
|
||||
luminance_calc: LuminanceCalculation,
|
||||
) -> T {
|
||||
let mut input = input.eval(footprint).await;
|
||||
@@ -291,7 +291,7 @@ async fn luminance<T: Adjust<Color>>(
|
||||
#[node_macro::node(category("Raster"))]
|
||||
async fn extract_channel<T: Adjust<Color>>(
|
||||
footprint: Footprint,
|
||||
#[implementations((Footprint, Color), (Footprint, ImageFrame<Color>))] input: impl Node<Footprint, Output = T>,
|
||||
#[implementations(Footprint -> Color, Footprint -> ImageFrame<Color>)] input: impl Node<Footprint, Output = T>,
|
||||
channel: RedGreenBlueAlpha,
|
||||
) -> T {
|
||||
let mut input = input.eval(footprint).await;
|
||||
@@ -308,7 +308,7 @@ async fn extract_channel<T: Adjust<Color>>(
|
||||
}
|
||||
|
||||
#[node_macro::node(category("Raster"))]
|
||||
async fn make_opaque<T: Adjust<Color>>(footprint: Footprint, #[implementations((Footprint, Color), (Footprint, ImageFrame<Color>))] input: impl Node<Footprint, Output = T>) -> T {
|
||||
async fn make_opaque<T: Adjust<Color>>(footprint: Footprint, #[implementations(Footprint -> Color, Footprint -> ImageFrame<Color>)] input: impl Node<Footprint, Output = T>) -> T {
|
||||
let mut input = input.eval(footprint).await;
|
||||
input.adjust(|color| {
|
||||
if color.a() == 0. {
|
||||
@@ -323,7 +323,7 @@ async fn make_opaque<T: Adjust<Color>>(footprint: Footprint, #[implementations((
|
||||
#[node_macro::node(category("Raster: Adjustment"))]
|
||||
async fn levels<T: Adjust<Color>>(
|
||||
footprint: Footprint,
|
||||
#[implementations((Footprint, Color), (Footprint, ImageFrame<Color>))] image: impl Node<Footprint, Output = T>,
|
||||
#[implementations(Footprint -> Color, Footprint -> ImageFrame<Color>)] image: impl Node<Footprint, Output = T>,
|
||||
#[default(0.)] shadows: Percentage,
|
||||
#[default(50.)] midtones: Percentage,
|
||||
#[default(100.)] highlights: Percentage,
|
||||
@@ -381,7 +381,7 @@ async fn levels<T: Adjust<Color>>(
|
||||
#[node_macro::node(name("Black & White"), category("Raster: Adjustment"))]
|
||||
async fn black_and_white<T: Adjust<Color>>(
|
||||
footprint: Footprint,
|
||||
#[implementations((Footprint, Color), (Footprint, ImageFrame<Color>))] image: impl Node<Footprint, Output = T>,
|
||||
#[implementations(Footprint -> Color, Footprint -> ImageFrame<Color>)] image: impl Node<Footprint, Output = T>,
|
||||
#[default(000000ff)] tint: Color,
|
||||
#[default(40.)]
|
||||
#[range((-200., 300.))]
|
||||
@@ -446,7 +446,7 @@ async fn black_and_white<T: Adjust<Color>>(
|
||||
#[node_macro::node(name("Hue/Saturation"), category("Raster: Adjustment"))]
|
||||
async fn hue_saturation<T: Adjust<Color>>(
|
||||
footprint: Footprint,
|
||||
#[implementations((Footprint, Color), (Footprint, ImageFrame<Color>))] input: impl Node<Footprint, Output = T>,
|
||||
#[implementations(Footprint -> Color, Footprint -> ImageFrame<Color>)] input: impl Node<Footprint, Output = T>,
|
||||
hue_shift: Angle,
|
||||
saturation_shift: SignedPercentage,
|
||||
lightness_shift: SignedPercentage,
|
||||
@@ -472,7 +472,7 @@ async fn hue_saturation<T: Adjust<Color>>(
|
||||
}
|
||||
|
||||
#[node_macro::node(category("Raster: Adjustment"))]
|
||||
async fn invert<T: Adjust<Color>>(footprint: Footprint, #[implementations((Footprint, Color), (Footprint, ImageFrame<Color>))] input: impl Node<Footprint, Output = T>) -> T {
|
||||
async fn invert<T: Adjust<Color>>(footprint: Footprint, #[implementations(Footprint -> Color, Footprint -> ImageFrame<Color>)] input: impl Node<Footprint, Output = T>) -> T {
|
||||
let mut input = input.eval(footprint).await;
|
||||
input.adjust(|color| {
|
||||
let color = color.to_gamma_srgb();
|
||||
@@ -487,7 +487,7 @@ async fn invert<T: Adjust<Color>>(footprint: Footprint, #[implementations((Footp
|
||||
#[node_macro::node(category("Raster: Adjustment"))]
|
||||
async fn threshold<T: Adjust<Color>>(
|
||||
footprint: Footprint,
|
||||
#[implementations((Footprint, Color), (Footprint, ImageFrame<Color>))] image: impl Node<Footprint, Output = T>,
|
||||
#[implementations(Footprint -> Color, Footprint -> ImageFrame<Color>)] image: impl Node<Footprint, Output = T>,
|
||||
#[default(50.)] min_luminance: Percentage,
|
||||
#[default(100.)] max_luminance: Percentage,
|
||||
luminance_calc: LuminanceCalculation,
|
||||
@@ -574,22 +574,22 @@ impl Blend<Color> for GradientStops {
|
||||
async fn blend<F: 'n + Copy + Send, T: Blend<Color> + Send>(
|
||||
#[implementations((), (), (), Footprint)] footprint: F,
|
||||
#[implementations(
|
||||
((), Color),
|
||||
((), ImageFrame<Color>),
|
||||
((), GradientStops),
|
||||
(Footprint, Color),
|
||||
(Footprint, ImageFrame<Color>),
|
||||
(Footprint, GradientStops),
|
||||
() -> Color,
|
||||
() -> ImageFrame<Color>,
|
||||
() -> GradientStops,
|
||||
Footprint -> Color,
|
||||
Footprint -> ImageFrame<Color>,
|
||||
Footprint -> GradientStops,
|
||||
)]
|
||||
over: impl Node<F, Output = T>,
|
||||
#[expose]
|
||||
#[implementations(
|
||||
((), Color),
|
||||
((), ImageFrame<Color>),
|
||||
((), GradientStops),
|
||||
(Footprint, Color),
|
||||
(Footprint, ImageFrame<Color>),
|
||||
(Footprint, GradientStops),
|
||||
() -> Color,
|
||||
() -> ImageFrame<Color>,
|
||||
() -> GradientStops,
|
||||
Footprint -> Color,
|
||||
Footprint -> ImageFrame<Color>,
|
||||
Footprint -> GradientStops,
|
||||
)]
|
||||
under: impl Node<F, Output = T>,
|
||||
blend_mode: BlendMode,
|
||||
@@ -693,12 +693,12 @@ pub fn blend_colors(foreground: Color, background: Color, blend_mode: BlendMode,
|
||||
async fn gradient_map<F: 'n + Copy + Send, T: Adjust<Color>>(
|
||||
#[implementations((), (), (), Footprint)] footprint: F,
|
||||
#[implementations(
|
||||
((), Color),
|
||||
((), ImageFrame<Color>),
|
||||
((), GradientStops),
|
||||
(Footprint, Color),
|
||||
(Footprint, ImageFrame<Color>),
|
||||
(Footprint, GradientStops),
|
||||
() -> Color,
|
||||
() -> ImageFrame<Color>,
|
||||
() -> GradientStops,
|
||||
Footprint -> Color,
|
||||
Footprint -> ImageFrame<Color>,
|
||||
Footprint -> GradientStops,
|
||||
)]
|
||||
image: impl Node<F, Output = T>,
|
||||
gradient: GradientStops,
|
||||
@@ -720,7 +720,7 @@ async fn gradient_map<F: 'n + Copy + Send, T: Adjust<Color>>(
|
||||
#[node_macro::node(category("Raster: Adjustment"))]
|
||||
async fn vibrance<T: Adjust<Color>>(
|
||||
footprint: Footprint,
|
||||
#[implementations((Footprint, Color), (Footprint, ImageFrame<Color>))] image: impl Node<Footprint, Output = T>,
|
||||
#[implementations(Footprint -> Color, Footprint -> ImageFrame<Color>)] image: impl Node<Footprint, Output = T>,
|
||||
vibrance: SignedPercentage,
|
||||
) -> T {
|
||||
let mut input = image.eval(footprint).await;
|
||||
@@ -1003,7 +1003,7 @@ impl DomainWarpType {
|
||||
#[node_macro::node(category("Raster: Adjustment"))]
|
||||
async fn channel_mixer<T: Adjust<Color>>(
|
||||
footprint: Footprint,
|
||||
#[implementations((Footprint, Color), (Footprint, ImageFrame<Color>))] image: impl Node<Footprint, Output = T>,
|
||||
#[implementations(Footprint -> Color, Footprint -> ImageFrame<Color>)] image: impl Node<Footprint, Output = T>,
|
||||
|
||||
monochrome: bool,
|
||||
#[default(40.)]
|
||||
@@ -1145,7 +1145,7 @@ impl core::fmt::Display for SelectiveColorChoice {
|
||||
#[node_macro::node(category("Raster: Adjustment"))]
|
||||
async fn selective_color<T: Adjust<Color>>(
|
||||
footprint: Footprint,
|
||||
#[implementations((Footprint, Color), (Footprint, ImageFrame<Color>))] image: impl Node<Footprint, Output = T>,
|
||||
#[implementations(Footprint -> Color, Footprint -> ImageFrame<Color>)] image: impl Node<Footprint, Output = T>,
|
||||
mode: RelativeAbsolute,
|
||||
#[name("(Reds) Cyan")] r_c: f64,
|
||||
#[name("(Reds) Magenta")] r_m: f64,
|
||||
@@ -1293,7 +1293,7 @@ impl<P: Pixel> MultiplyAlpha for ImageFrame<P> {
|
||||
#[node_macro::node(category("Raster: Adjustment"))]
|
||||
async fn posterize<T: Adjust<Color>>(
|
||||
footprint: Footprint,
|
||||
#[implementations((Footprint, Color), (Footprint, ImageFrame<Color>))] input: impl Node<Footprint, Output = T>,
|
||||
#[implementations(Footprint -> Color, Footprint -> ImageFrame<Color>)] input: impl Node<Footprint, Output = T>,
|
||||
#[default(4)]
|
||||
#[min(2.)]
|
||||
levels: u32,
|
||||
@@ -1317,7 +1317,7 @@ async fn posterize<T: Adjust<Color>>(
|
||||
#[node_macro::node(category("Raster: Adjustment"))]
|
||||
async fn exposure<T: Adjust<Color>>(
|
||||
footprint: Footprint,
|
||||
#[implementations((Footprint, Color), (Footprint, ImageFrame<Color>))] input: impl Node<Footprint, Output = T>,
|
||||
#[implementations(Footprint -> Color, Footprint -> ImageFrame<Color>)] input: impl Node<Footprint, Output = T>,
|
||||
exposure: f64,
|
||||
offset: f64,
|
||||
#[default(1.)]
|
||||
@@ -1387,12 +1387,12 @@ fn generate_curves<C: Channel + super::Linear>(_: (), curve: Curve, #[implementa
|
||||
async fn color_overlay<F: 'n + Copy + Send, T: Adjust<Color>>(
|
||||
#[implementations((), (), (), Footprint)] footprint: F,
|
||||
#[implementations(
|
||||
((), Color),
|
||||
((), ImageFrame<Color>),
|
||||
((), GradientStops),
|
||||
(Footprint, Color),
|
||||
(Footprint, ImageFrame<Color>),
|
||||
(Footprint, GradientStops),
|
||||
() -> Color,
|
||||
() -> ImageFrame<Color>,
|
||||
() -> GradientStops,
|
||||
Footprint -> Color,
|
||||
Footprint -> ImageFrame<Color>,
|
||||
Footprint -> GradientStops,
|
||||
)]
|
||||
image: impl Node<F, Output = T>,
|
||||
#[default(000000ff)] color: Color,
|
||||
|
||||
Reference in New Issue
Block a user