22
33use crate :: adjust:: Adjust ;
44use crate :: cubic_spline:: CubicSplines ;
5- use dyn_any:: DynAny ;
6- use graphene_core:: color:: Color ;
7- use graphene_core:: context:: Ctx ;
5+ use core:: fmt:: Debug ;
6+ #[ cfg( feature = "std" ) ]
87use graphene_core:: gradient:: GradientStops ;
8+ #[ cfg( feature = "std" ) ]
99use graphene_core:: raster_types:: { CPU , RasterDataTable } ;
10- use graphene_core:: registry:: types:: { Angle , Percentage , SignedPercentage } ;
11- use std:: fmt:: Debug ;
10+ use graphene_core_shaders:: color:: Color ;
11+ use graphene_core_shaders:: context:: Ctx ;
12+ use graphene_core_shaders:: registry:: types:: { Angle , Percentage , SignedPercentage } ;
1213
1314// TODO: Implement the following:
1415// Color Balance
@@ -25,7 +26,8 @@ use std::fmt::Debug;
2526// https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#:~:text=%27clrL%27%20%3D%20Color%20Lookup
2627// https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#:~:text=Color%20Lookup%20(Photoshop%20CS6
2728
28- #[ derive( Debug , Default , Clone , Copy , Eq , PartialEq , DynAny , Hash , node_macro:: ChoiceType , specta:: Type , serde:: Serialize , serde:: Deserialize ) ]
29+ #[ derive( Debug , Default , Clone , Copy , Eq , PartialEq , Hash , node_macro:: ChoiceType ) ]
30+ #[ cfg_attr( feature = "std" , derive( dyn_any:: DynAny , specta:: Type , serde:: Serialize , serde:: Deserialize ) ) ]
2931#[ widget( Dropdown ) ]
3032pub enum LuminanceCalculation {
3133 #[ default]
@@ -37,7 +39,7 @@ pub enum LuminanceCalculation {
3739 MaximumChannels ,
3840}
3941
40- #[ node_macro:: node( category( "Raster: Adjustment" ) ) ]
42+ #[ node_macro:: node( category( "Raster: Adjustment" ) , shader_node ( PerPixelAdjust ) ) ]
4143fn luminance < T : Adjust < Color > > (
4244 _: impl Ctx ,
4345 #[ implementations(
@@ -61,7 +63,7 @@ fn luminance<T: Adjust<Color>>(
6163 input
6264}
6365
64- #[ node_macro:: node( category( "Raster" ) ) ]
66+ #[ node_macro:: node( category( "Raster" ) , shader_node ( PerPixelAdjust ) ) ]
6567fn gamma_correction < T : Adjust < Color > > (
6668 _: impl Ctx ,
6769 #[ implementations(
@@ -81,7 +83,7 @@ fn gamma_correction<T: Adjust<Color>>(
8183 input
8284}
8385
84- #[ node_macro:: node( category( "Raster: Channels" ) ) ]
86+ #[ node_macro:: node( category( "Raster: Channels" ) , shader_node ( PerPixelAdjust ) ) ]
8587fn extract_channel < T : Adjust < Color > > (
8688 _: impl Ctx ,
8789 #[ implementations(
@@ -104,7 +106,7 @@ fn extract_channel<T: Adjust<Color>>(
104106 input
105107}
106108
107- #[ node_macro:: node( category( "Raster: Channels" ) ) ]
109+ #[ node_macro:: node( category( "Raster: Channels" ) , shader_node ( PerPixelAdjust ) ) ]
108110fn make_opaque < T : Adjust < Color > > (
109111 _: impl Ctx ,
110112 #[ implementations(
@@ -129,7 +131,7 @@ fn make_opaque<T: Adjust<Color>>(
129131//
130132// Some further analysis available at:
131133// https://geraldbakker.nl/psnumbers/brightness-contrast.html
132- #[ node_macro:: node( name( "Brightness/Contrast" ) , category( "Raster: Adjustment" ) , properties( "brightness_contrast_properties" ) ) ]
134+ #[ node_macro:: node( name( "Brightness/Contrast" ) , category( "Raster: Adjustment" ) , properties( "brightness_contrast_properties" ) , shader_node ( PerPixelAdjust ) ) ]
133135fn brightness_contrast < T : Adjust < Color > > (
134136 _: impl Ctx ,
135137 #[ implementations(
@@ -146,7 +148,7 @@ fn brightness_contrast<T: Adjust<Color>>(
146148 let brightness = brightness as f32 / 255. ;
147149
148150 let contrast = contrast as f32 / 100. ;
149- let contrast = if contrast > 0. { ( contrast * std :: f32:: consts:: FRAC_PI_2 - 0.01 ) . tan ( ) } else { contrast } ;
151+ let contrast = if contrast > 0. { ( contrast * core :: f32:: consts:: FRAC_PI_2 - 0.01 ) . tan ( ) } else { contrast } ;
150152
151153 let offset = brightness * contrast + brightness - contrast / 2. ;
152154
@@ -168,13 +170,13 @@ fn brightness_contrast<T: Adjust<Color>>(
168170 y : [ 0. , 130. + brightness * 51. , 233. + brightness * 10. , 255. ] . map ( |x| x / 255. ) ,
169171 } ;
170172 let brightness_curve_solutions = brightness_curve_points. solve ( ) ;
171- let mut brightness_lut: [ f32 ; WINDOW_SIZE ] = std :: array:: from_fn ( |i| {
173+ let mut brightness_lut: [ f32 ; WINDOW_SIZE ] = core :: array:: from_fn ( |i| {
172174 let x = i as f32 / ( WINDOW_SIZE as f32 - 1. ) ;
173175 brightness_curve_points. interpolate ( x, & brightness_curve_solutions)
174176 } ) ;
175177 // Special handling for when brightness is negative
176178 if brightness_is_negative {
177- brightness_lut = std :: array:: from_fn ( |i| {
179+ brightness_lut = core :: array:: from_fn ( |i| {
178180 let mut x = i;
179181 while x > 1 && brightness_lut[ x] > i as f32 / WINDOW_SIZE as f32 {
180182 x -= 1 ;
@@ -193,7 +195,7 @@ fn brightness_contrast<T: Adjust<Color>>(
193195 y : [ 0. , 64. - contrast * 30. , 192. + contrast * 30. , 255. ] . map ( |x| x / 255. ) ,
194196 } ;
195197 let contrast_curve_solutions = contrast_curve_points. solve ( ) ;
196- let contrast_lut: [ f32 ; WINDOW_SIZE ] = std :: array:: from_fn ( |i| {
198+ let contrast_lut: [ f32 ; WINDOW_SIZE ] = core :: array:: from_fn ( |i| {
197199 let x = i as f32 / ( WINDOW_SIZE as f32 - 1. ) ;
198200 contrast_curve_points. interpolate ( x, & contrast_curve_solutions)
199201 } ) ;
@@ -218,7 +220,7 @@ fn brightness_contrast<T: Adjust<Color>>(
218220//
219221// Some further analysis available at:
220222// https://geraldbakker.nl/psnumbers/levels.html
221- #[ node_macro:: node( category( "Raster: Adjustment" ) ) ]
223+ #[ node_macro:: node( category( "Raster: Adjustment" ) , shader_node ( PerPixelAdjust ) ) ]
222224fn levels < T : Adjust < Color > > (
223225 _: impl Ctx ,
224226 #[ implementations(
@@ -285,7 +287,7 @@ fn levels<T: Adjust<Color>>(
285287// Algorithm from:
286288// https://stackoverflow.com/a/55233732/775283
287289// Works the same for gamma and linear color
288- #[ node_macro:: node( name( "Black & White" ) , category( "Raster: Adjustment" ) ) ]
290+ #[ node_macro:: node( name( "Black & White" ) , category( "Raster: Adjustment" ) , shader_node ( PerPixelAdjust ) ) ]
289291async fn black_and_white < T : Adjust < Color > > (
290292 _: impl Ctx ,
291293 #[ implementations(
@@ -357,7 +359,7 @@ async fn black_and_white<T: Adjust<Color>>(
357359// Aims for interoperable compatibility with:
358360// https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#:~:text=%27hue%20%27%20%3D%20Old,saturation%2C%20Photoshop%205.0
359361// https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#:~:text=0%20%3D%20Use%20other.-,Hue/Saturation,-Hue/Saturation%20settings
360- #[ node_macro:: node( name( "Hue/Saturation" ) , category( "Raster: Adjustment" ) ) ]
362+ #[ node_macro:: node( name( "Hue/Saturation" ) , category( "Raster: Adjustment" ) , shader_node ( PerPixelAdjust ) ) ]
361363async fn hue_saturation < T : Adjust < Color > > (
362364 _: impl Ctx ,
363365 #[ implementations(
@@ -391,7 +393,7 @@ async fn hue_saturation<T: Adjust<Color>>(
391393
392394// Aims for interoperable compatibility with:
393395// https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#:~:text=%27%20%3D%20Color%20Lookup-,%27nvrt%27%20%3D%20Invert,-%27post%27%20%3D%20Posterize
394- #[ node_macro:: node( category( "Raster: Adjustment" ) ) ]
396+ #[ node_macro:: node( category( "Raster: Adjustment" ) , shader_node ( PerPixelAdjust ) ) ]
395397async fn invert < T : Adjust < Color > > (
396398 _: impl Ctx ,
397399 #[ implementations(
@@ -413,7 +415,7 @@ async fn invert<T: Adjust<Color>>(
413415
414416// Aims for interoperable compatibility with:
415417// https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#:~:text=post%27%20%3D%20Posterize-,%27thrs%27%20%3D%20Threshold,-%27grdm%27%20%3D%20Gradient
416- #[ node_macro:: node( category( "Raster: Adjustment" ) ) ]
418+ #[ node_macro:: node( category( "Raster: Adjustment" ) , shader_node ( PerPixelAdjust ) ) ]
417419async fn threshold < T : Adjust < Color > > (
418420 _: impl Ctx ,
419421 #[ implementations(
@@ -458,7 +460,7 @@ async fn threshold<T: Adjust<Color>>(
458460// It's not the same as the saturation component of Hue/Saturation/Value. Vibrance and Saturation are both separable.
459461// When both parameters are set, it is equivalent to running this adjustment twice, with only vibrance set and then only saturation set.
460462// (Except for some noise probably due to rounding error.)
461- #[ node_macro:: node( category( "Raster: Adjustment" ) ) ]
463+ #[ node_macro:: node( category( "Raster: Adjustment" ) , shader_node ( PerPixelAdjust ) ) ]
462464async fn vibrance < T : Adjust < Color > > (
463465 _: impl Ctx ,
464466 #[ implementations(
@@ -520,7 +522,8 @@ async fn vibrance<T: Adjust<Color>>(
520522}
521523
522524/// Color Channel
523- #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Hash , DynAny , node_macro:: ChoiceType , specta:: Type , serde:: Serialize , serde:: Deserialize ) ]
525+ #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Hash , node_macro:: ChoiceType ) ]
526+ #[ cfg_attr( feature = "std" , derive( dyn_any:: DynAny , specta:: Type , serde:: Serialize , serde:: Deserialize ) ) ]
524527#[ widget( Radio ) ]
525528pub enum RedGreenBlue {
526529 #[ default]
@@ -530,7 +533,8 @@ pub enum RedGreenBlue {
530533}
531534
532535/// Color Channel
533- #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Hash , DynAny , node_macro:: ChoiceType , specta:: Type , serde:: Serialize , serde:: Deserialize ) ]
536+ #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Hash , node_macro:: ChoiceType ) ]
537+ #[ cfg_attr( feature = "std" , derive( dyn_any:: DynAny , specta:: Type , serde:: Serialize , serde:: Deserialize ) ) ]
534538#[ widget( Radio ) ]
535539pub enum RedGreenBlueAlpha {
536540 #[ default]
@@ -541,7 +545,8 @@ pub enum RedGreenBlueAlpha {
541545}
542546
543547/// Style of noise pattern
544- #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Hash , DynAny , node_macro:: ChoiceType , specta:: Type , serde:: Serialize , serde:: Deserialize ) ]
548+ #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Hash , node_macro:: ChoiceType ) ]
549+ #[ cfg_attr( feature = "std" , derive( dyn_any:: DynAny , specta:: Type , serde:: Serialize , serde:: Deserialize ) ) ]
545550#[ widget( Dropdown ) ]
546551pub enum NoiseType {
547552 #[ default]
@@ -556,7 +561,8 @@ pub enum NoiseType {
556561 WhiteNoise ,
557562}
558563
559- #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Hash , DynAny , node_macro:: ChoiceType , specta:: Type , serde:: Serialize , serde:: Deserialize ) ]
564+ #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Hash , node_macro:: ChoiceType ) ]
565+ #[ cfg_attr( feature = "std" , derive( dyn_any:: DynAny , specta:: Type , serde:: Serialize , serde:: Deserialize ) ) ]
560566/// Style of layered levels of the noise pattern
561567pub enum FractalType {
562568 #[ default]
@@ -572,7 +578,8 @@ pub enum FractalType {
572578}
573579
574580/// Distance function used by the cellular noise
575- #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Hash , DynAny , node_macro:: ChoiceType , specta:: Type , serde:: Serialize , serde:: Deserialize ) ]
581+ #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Hash , node_macro:: ChoiceType ) ]
582+ #[ cfg_attr( feature = "std" , derive( dyn_any:: DynAny , specta:: Type , serde:: Serialize , serde:: Deserialize ) ) ]
576583pub enum CellularDistanceFunction {
577584 #[ default]
578585 Euclidean ,
@@ -582,7 +589,8 @@ pub enum CellularDistanceFunction {
582589 Hybrid ,
583590}
584591
585- #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Hash , DynAny , node_macro:: ChoiceType , specta:: Type , serde:: Serialize , serde:: Deserialize ) ]
592+ #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Hash , node_macro:: ChoiceType ) ]
593+ #[ cfg_attr( feature = "std" , derive( dyn_any:: DynAny , specta:: Type , serde:: Serialize , serde:: Deserialize ) ) ]
586594pub enum CellularReturnType {
587595 CellValue ,
588596 #[ default]
@@ -601,7 +609,8 @@ pub enum CellularReturnType {
601609}
602610
603611/// Type of domain warp
604- #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Hash , DynAny , node_macro:: ChoiceType , specta:: Type , serde:: Serialize , serde:: Deserialize ) ]
612+ #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Hash , node_macro:: ChoiceType ) ]
613+ #[ cfg_attr( feature = "std" , derive( dyn_any:: DynAny , specta:: Type , serde:: Serialize , serde:: Deserialize ) ) ]
605614#[ widget( Dropdown ) ]
606615pub enum DomainWarpType {
607616 #[ default]
@@ -616,7 +625,7 @@ pub enum DomainWarpType {
616625// Aims for interoperable compatibility with:
617626// https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#:~:text=%27mixr%27%20%3D%20Channel%20Mixer
618627// https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#:~:text=Lab%20color%20only-,Channel%20Mixer,-Key%20is%20%27mixr
619- #[ node_macro:: node( category( "Raster: Adjustment" ) , properties( "channel_mixer_properties" ) ) ]
628+ #[ node_macro:: node( category( "Raster: Adjustment" ) , properties( "channel_mixer_properties" ) , shader_node ( PerPixelAdjust ) ) ]
620629async fn channel_mixer < T : Adjust < Color > > (
621630 _: impl Ctx ,
622631 #[ implementations(
@@ -711,7 +720,8 @@ async fn channel_mixer<T: Adjust<Color>>(
711720 image
712721}
713722
714- #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Hash , DynAny , node_macro:: ChoiceType , specta:: Type , serde:: Serialize , serde:: Deserialize ) ]
723+ #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Hash , node_macro:: ChoiceType ) ]
724+ #[ cfg_attr( feature = "std" , derive( dyn_any:: DynAny , specta:: Type , serde:: Serialize , serde:: Deserialize ) ) ]
715725#[ widget( Radio ) ]
716726pub enum RelativeAbsolute {
717727 #[ default]
@@ -720,7 +730,8 @@ pub enum RelativeAbsolute {
720730}
721731
722732#[ repr( C ) ]
723- #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Hash , DynAny , node_macro:: ChoiceType , specta:: Type , serde:: Serialize , serde:: Deserialize ) ]
733+ #[ derive( Debug , Clone , Copy , Default , PartialEq , Eq , Hash , node_macro:: ChoiceType ) ]
734+ #[ cfg_attr( feature = "std" , derive( dyn_any:: DynAny , specta:: Type , serde:: Serialize , serde:: Deserialize ) ) ]
724735pub enum SelectiveColorChoice {
725736 #[ default]
726737 Reds ,
@@ -742,7 +753,7 @@ pub enum SelectiveColorChoice {
742753//
743754// Algorithm based on:
744755// https://blog.pkh.me/p/22-understanding-selective-coloring-in-adobe-photoshop.html
745- #[ node_macro:: node( category( "Raster: Adjustment" ) , properties( "selective_color_properties" ) ) ]
756+ #[ node_macro:: node( category( "Raster: Adjustment" ) , properties( "selective_color_properties" ) , shader_node ( PerPixelAdjust ) ) ]
746757async fn selective_color < T : Adjust < Color > > (
747758 _: impl Ctx ,
748759 #[ implementations(
@@ -884,7 +895,7 @@ async fn selective_color<T: Adjust<Color>>(
884895// Algorithm based on:
885896// https://www.axiomx.com/posterize.htm
886897// This algorithm produces fully accurate output in relation to the industry standard.
887- #[ node_macro:: node( category( "Raster: Adjustment" ) ) ]
898+ #[ node_macro:: node( category( "Raster: Adjustment" ) , shader_node ( PerPixelAdjust ) ) ]
888899async fn posterize < T : Adjust < Color > > (
889900 _: impl Ctx ,
890901 #[ implementations(
@@ -917,7 +928,7 @@ async fn posterize<T: Adjust<Color>>(
917928//
918929// Algorithm based on:
919930// https://geraldbakker.nl/psnumbers/exposure.html
920- #[ node_macro:: node( category( "Raster: Adjustment" ) , properties( "exposure_properties" ) ) ]
931+ #[ node_macro:: node( category( "Raster: Adjustment" ) , properties( "exposure_properties" ) , shader_node ( PerPixelAdjust ) ) ]
921932async fn exposure < T : Adjust < Color > > (
922933 _: impl Ctx ,
923934 #[ implementations(
0 commit comments