55namespace Intervention \Image \Colors \Oklab ;
66
77use Intervention \Image \Colors \AbstractColor ;
8+ use Intervention \Image \Colors \Oklab \Channels \A ;
9+ use Intervention \Image \Colors \Oklab \Channels \B ;
10+ use Intervention \Image \Colors \Oklab \Channels \Alpha ;
11+ use Intervention \Image \Colors \Oklab \Channels \Lightness ;
812use Intervention \Image \Colors \Rgb \Colorspace as RgbColorspace ;
913use Intervention \Image \Exceptions \ColorDecoderException ;
1014use Intervention \Image \Exceptions \DriverException ;
@@ -19,14 +23,13 @@ class Color extends AbstractColor
1923 /**
2024 * Create new color object.
2125 */
22- public function __construct (float $ l , float $ a , float $ b , float $ alpha = 1 )
26+ public function __construct (float | Lightness $ l , float | A $ a , float | B $ b , float | Alpha $ alpha = 1 )
2327 {
24- /** @throws void */
2528 $ this ->channels = [
26- new Channels \ Lightness ($ l ),
27- new Channels \ A ($ a ),
28- new Channels \ B ($ b ),
29- new Channels \ Alpha ($ alpha ),
29+ is_float ( $ l ) ? new Lightness ($ l ) : $ l ,
30+ is_float ( $ a ) ? new A ($ a ) : $ a ,
31+ is_float ( $ b ) ? new B ($ b ) : $ b ,
32+ is_float ( $ alpha ) ? new Alpha ($ alpha ) : $ alpha ,
3033 ];
3134 }
3235
@@ -86,7 +89,7 @@ public function colorspace(): ColorspaceInterface
8689 public function lightness (): ColorChannelInterface
8790 {
8891 /** @throws void */
89- return $ this ->channel (Channels \ Lightness::class);
92+ return $ this ->channel (Lightness::class);
9093 }
9194
9295 /**
@@ -95,7 +98,7 @@ public function lightness(): ColorChannelInterface
9598 public function a (): ColorChannelInterface
9699 {
97100 /** @throws void */
98- return $ this ->channel (Channels \ A::class);
101+ return $ this ->channel (A::class);
99102 }
100103
101104 /**
@@ -104,7 +107,7 @@ public function a(): ColorChannelInterface
104107 public function b (): ColorChannelInterface
105108 {
106109 /** @throws void */
107- return $ this ->channel (Channels \ B::class);
110+ return $ this ->channel (B::class);
108111 }
109112
110113 /**
@@ -113,7 +116,7 @@ public function b(): ColorChannelInterface
113116 public function alpha (): ColorChannelInterface
114117 {
115118 /** @throws void */
116- return $ this ->channel (Channels \ Alpha::class);
119+ return $ this ->channel (Alpha::class);
117120 }
118121
119122 /**
@@ -148,7 +151,7 @@ public function toString(): string
148151 $ this ->lightness ()->value (),
149152 $ this ->a ()->value (),
150153 $ this ->b ()->value (),
151- round ( $ this ->alpha ()->value (), 2 )
154+ $ this ->alpha ()->toString (),
152155 );
153156 }
154157
0 commit comments