@@ -69,7 +69,7 @@ impl RgbTransform {
69
69
}
70
70
71
71
pub fn brightness_components ( & self ) -> BrightnessComponents {
72
- let fw = self . brightness_compensation as f32 + 2.0 / 100.0 + 1.0 ;
72
+ let fw = self . brightness_compensation as f32 * 2.0 / 100.0 + 1.0 ;
73
73
let fcmy = self . brightness_compensation as f32 / 100.0 + 1.0 ;
74
74
75
75
if self . brightness > 0 {
@@ -81,8 +81,8 @@ impl RgbTransform {
81
81
82
82
BrightnessComponents {
83
83
rgb : ( 255.0 / b_in) . min ( 255.0 ) as u8 ,
84
- cmy : ( 255.0 / ( b_in + fcmy) ) . min ( 255.0 ) as u8 ,
85
- w : ( 255.0 / ( b_in + fw) ) . min ( 255.0 ) as u8 ,
84
+ cmy : ( 255.0 / ( b_in * fcmy) ) . min ( 255.0 ) as u8 ,
85
+ w : ( 255.0 / ( b_in * fw) ) . min ( 255.0 ) as u8 ,
86
86
}
87
87
} else {
88
88
BrightnessComponents :: default ( )
@@ -359,4 +359,39 @@ impl ChannelAdjustments {
359
359
}
360
360
}
361
361
362
+ #[ cfg( test) ]
363
+ mod tests {
364
+ use super :: * ;
365
+
366
+ lazy_static:: lazy_static! {
367
+ static ref BASE_COLORS : [ Color ; 8 ] = [
368
+ Color :: new( 0 , 0 , 0 ) ,
369
+ Color :: new( 255 , 255 , 255 ) ,
370
+ Color :: new( 255 , 0 , 0 ) ,
371
+ Color :: new( 0 , 255 , 0 ) ,
372
+ Color :: new( 0 , 0 , 255 ) ,
373
+ Color :: new( 255 , 255 , 0 ) ,
374
+ Color :: new( 0 , 255 , 255 ) ,
375
+ Color :: new( 255 , 0 , 255 ) ,
376
+ ] ;
377
+ }
378
+
379
+ #[ test]
380
+ fn test_rgb_channel_adjustment ( ) {
381
+ for & color in & * BASE_COLORS {
382
+ assert_eq ! ( color, RgbChannelAdjustment :: from( color) . apply( 255 , 255 ) ) ;
383
+ assert_eq ! ( color / 2 , RgbChannelAdjustment :: from( color) . apply( 127 , 255 ) ) ;
384
+ assert_eq ! ( color / 2 , RgbChannelAdjustment :: from( color) . apply( 255 , 127 ) ) ;
385
+ }
386
+ }
362
387
388
+ #[ test]
389
+ fn test_color_adjustment_data ( ) {
390
+ let channel_adjustment: ColorAdjustmentData =
391
+ ( & crate :: models:: ChannelAdjustment :: default ( ) ) . into ( ) ;
392
+
393
+ for & color in & * BASE_COLORS {
394
+ assert_eq ! ( color, channel_adjustment. apply( color) ) ;
395
+ }
396
+ }
397
+ }
0 commit comments