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