Skip to content

Commit ac31cac

Browse files
committed
Implement ColorspaceInterface::channels()
1 parent 472e11c commit ac31cac

File tree

9 files changed

+49
-15
lines changed

9 files changed

+49
-15
lines changed

src/Colors/AbstractColorspace.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Intervention\Image\Colors;
6+
7+
use Intervention\Image\Interfaces\ColorspaceInterface;
8+
9+
abstract class AbstractColorspace implements ColorspaceInterface
10+
{
11+
/**
12+
* Channel class names of colorspace.
13+
*
14+
* @var array<string>
15+
*/
16+
protected static array $channels = [];
17+
18+
/**
19+
* {@inheritdoc}
20+
*
21+
* @see ColorspaceInterface::channels()
22+
*/
23+
public static function channels(): array
24+
{
25+
return static::$channels;
26+
}
27+
}

src/Colors/AlphaColorChannel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ abstract class AlphaColorChannel extends AbstractColorChannel
1616
/**
1717
* @throws InvalidArgumentException
1818
*/
19-
final public function __construct(float $value)
19+
final public function __construct(float $value = 1)
2020
{
2121
if ($value < 0 || $value > 1) {
2222
throw new InvalidArgumentException(

src/Colors/Cmyk/Colorspace.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Intervention\Image\Colors\Cmyk;
66

7+
use Intervention\Image\Colors\AbstractColorspace;
78
use Intervention\Image\Colors\Cmyk\Color as CmykColor;
89
use Intervention\Image\Colors\Hsl\Color as HslColor;
910
use Intervention\Image\Colors\Hsv\Color as HsvColor;
@@ -15,10 +16,9 @@
1516
use Intervention\Image\Exceptions\InvalidArgumentException;
1617
use Intervention\Image\Exceptions\NotSupportedException;
1718
use Intervention\Image\Interfaces\ColorInterface;
18-
use Intervention\Image\Interfaces\ColorspaceInterface;
1919
use TypeError;
2020

21-
class Colorspace implements ColorspaceInterface
21+
class Colorspace extends AbstractColorspace
2222
{
2323
/**
2424
* Channel class names of colorspace.

src/Colors/Hsl/Colorspace.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Intervention\Image\Colors\Hsl;
66

7+
use Intervention\Image\Colors\AbstractColorspace;
78
use Intervention\Image\Colors\Cmyk\Color as CmykColor;
89
use Intervention\Image\Colors\Hsl\Color as HslColor;
910
use Intervention\Image\Colors\Hsv\Color as HsvColor;
@@ -16,10 +17,9 @@
1617
use Intervention\Image\Exceptions\NotSupportedException;
1718
use Intervention\Image\Interfaces\ColorChannelInterface;
1819
use Intervention\Image\Interfaces\ColorInterface;
19-
use Intervention\Image\Interfaces\ColorspaceInterface;
2020
use TypeError;
2121

22-
class Colorspace implements ColorspaceInterface
22+
class Colorspace extends AbstractColorspace
2323
{
2424
/**
2525
* Channel class names of colorspace.

src/Colors/Hsv/Colorspace.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Intervention\Image\Colors\Hsv;
66

7+
use Intervention\Image\Colors\AbstractColorspace;
78
use Intervention\Image\Colors\Cmyk\Color as CmykColor;
89
use Intervention\Image\Colors\Hsl\Color as HslColor;
910
use Intervention\Image\Colors\Hsv\Color as HsvColor;
@@ -16,10 +17,9 @@
1617
use Intervention\Image\Exceptions\NotSupportedException;
1718
use Intervention\Image\Interfaces\ColorChannelInterface;
1819
use Intervention\Image\Interfaces\ColorInterface;
19-
use Intervention\Image\Interfaces\ColorspaceInterface;
2020
use TypeError;
2121

22-
class Colorspace implements ColorspaceInterface
22+
class Colorspace extends AbstractColorspace
2323
{
2424
/**
2525
* Channel class names of colorspace.

src/Colors/Oklab/Colorspace.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Intervention\Image\Colors\Oklab;
66

7+
use Intervention\Image\Colors\AbstractColorspace;
78
use Intervention\Image\Colors\Cmyk\Color as CmykColor;
89
use Intervention\Image\Colors\Hsl\Color as HslColor;
910
use Intervention\Image\Colors\Hsv\Color as HsvColor;
@@ -15,10 +16,9 @@
1516
use Intervention\Image\Exceptions\InvalidArgumentException;
1617
use Intervention\Image\Exceptions\NotSupportedException;
1718
use Intervention\Image\Interfaces\ColorInterface;
18-
use Intervention\Image\Interfaces\ColorspaceInterface;
1919
use TypeError;
2020

21-
class Colorspace implements ColorspaceInterface
21+
class Colorspace extends AbstractColorspace
2222
{
2323
/**
2424
* Channel class names of colorspace.

src/Colors/Oklch/Colorspace.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Intervention\Image\Colors\Oklch;
66

7+
use Intervention\Image\Colors\AbstractColorspace;
78
use Intervention\Image\Colors\Cmyk\Color as CmykColor;
89
use Intervention\Image\Colors\Hsl\Color as HslColor;
910
use Intervention\Image\Colors\Hsv\Color as HsvColor;
@@ -20,10 +21,9 @@
2021
use Intervention\Image\Exceptions\InvalidArgumentException;
2122
use Intervention\Image\Exceptions\NotSupportedException;
2223
use Intervention\Image\Interfaces\ColorInterface;
23-
use Intervention\Image\Interfaces\ColorspaceInterface;
2424
use TypeError;
2525

26-
class Colorspace implements ColorspaceInterface
26+
class Colorspace extends AbstractColorspace
2727
{
2828
/**
2929
* Channel class names of colorspace.

src/Colors/Rgb/Colorspace.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Intervention\Image\Colors\Rgb;
66

7+
use Intervention\Image\Colors\AbstractColorspace;
78
use Intervention\Image\Colors\Cmyk\Color as CmykColor;
89
use Intervention\Image\Colors\Hsl\Color as HslColor;
910
use Intervention\Image\Colors\Hsv\Color as HsvColor;
@@ -16,10 +17,9 @@
1617
use Intervention\Image\Exceptions\NotSupportedException;
1718
use Intervention\Image\Interfaces\ColorChannelInterface;
1819
use Intervention\Image\Interfaces\ColorInterface;
19-
use Intervention\Image\Interfaces\ColorspaceInterface;
2020
use TypeError;
2121

22-
class Colorspace implements ColorspaceInterface
22+
class Colorspace extends AbstractColorspace
2323
{
2424
/**
2525
* Channel class names of colorspace.

src/Interfaces/ColorspaceInterface.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@
77
interface ColorspaceInterface
88
{
99
/**
10-
* Convert given color to the format of the current colorspace.
10+
* Return array of all color channel classnames of the colorspace.
11+
*
12+
* @return array<string>
1113
*/
12-
public function importColor(ColorInterface $color): ColorInterface;
14+
public static function channels(): array;
1315

1416
/**
1517
* Create new color in colorspace from given normalized (0-1) channel values.
1618
*
1719
* @param array<float> $normalized
1820
*/
1921
public static function colorFromNormalized(array $normalized): ColorInterface;
22+
23+
/**
24+
* Convert given color to the format of the current colorspace.
25+
*/
26+
public function importColor(ColorInterface $color): ColorInterface;
2027
}

0 commit comments

Comments
 (0)