@@ -141,6 +141,38 @@ fn make_opaque<T: Adjust<Color>>(
141
141
input
142
142
}
143
143
144
+ /// See [`brightness_contrast`]
145
+ #[ node_macro:: node(
146
+ name( "Brightness/Contrast classic" ) ,
147
+ category( "Raster: Adjustment" ) ,
148
+ properties( "brightness_contrast_properties" ) ,
149
+ shader_node( PerPixelAdjust )
150
+ ) ]
151
+ fn brightness_contrast_classic < T : Adjust < Color > > (
152
+ _: impl Ctx ,
153
+ #[ implementations(
154
+ Table <Raster <CPU >>,
155
+ Table <Color >,
156
+ Table <GradientStops >,
157
+ GradientStops ,
158
+ ) ]
159
+ #[ gpu_image]
160
+ mut input : T ,
161
+ brightness : SignedPercentageF32 ,
162
+ contrast : SignedPercentageF32 ,
163
+ ) -> T {
164
+ let brightness = brightness / 255. ;
165
+
166
+ let contrast = contrast / 100. ;
167
+ let contrast = if contrast > 0. { ( contrast * core:: f32:: consts:: FRAC_PI_2 - 0.01 ) . tan ( ) } else { contrast } ;
168
+
169
+ let offset = brightness * contrast + brightness - contrast / 2. ;
170
+
171
+ input. adjust ( |color| color. to_gamma_srgb ( ) . map_rgb ( |c| ( c + c * contrast + offset) . clamp ( 0. , 1. ) ) . to_linear_srgb ( ) ) ;
172
+
173
+ input
174
+ }
175
+
144
176
// Aims for interoperable compatibility with:
145
177
// https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#:~:text=%27brit%27%20%3D%20Brightness/Contrast
146
178
// https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#:~:text=Padding-,Brightness%20and%20Contrast,-Key%20is%20%27brit
@@ -149,7 +181,7 @@ fn make_opaque<T: Adjust<Color>>(
149
181
// https://geraldbakker.nl/psnumbers/brightness-contrast.html
150
182
#[ node_macro:: node( name( "Brightness/Contrast" ) , category( "Raster: Adjustment" ) , properties( "brightness_contrast_properties" ) , cfg( feature = "std" ) ) ]
151
183
fn brightness_contrast < T : Adjust < Color > > (
152
- _ : impl Ctx ,
184
+ _ctx : impl Ctx ,
153
185
#[ implementations(
154
186
Table <Raster <CPU >>,
155
187
Table <Color >,
@@ -163,16 +195,7 @@ fn brightness_contrast<T: Adjust<Color>>(
163
195
use_classic : bool ,
164
196
) -> T {
165
197
if use_classic {
166
- let brightness = brightness / 255. ;
167
-
168
- let contrast = contrast / 100. ;
169
- let contrast = if contrast > 0. { ( contrast * core:: f32:: consts:: FRAC_PI_2 - 0.01 ) . tan ( ) } else { contrast } ;
170
-
171
- let offset = brightness * contrast + brightness - contrast / 2. ;
172
-
173
- input. adjust ( |color| color. to_gamma_srgb ( ) . map_rgb ( |c| ( c + c * contrast + offset) . clamp ( 0. , 1. ) ) . to_linear_srgb ( ) ) ;
174
-
175
- return input;
198
+ return brightness_contrast_classic ( _ctx, input, brightness, contrast) ;
176
199
}
177
200
178
201
const WINDOW_SIZE : usize = 1024 ;
0 commit comments