Skip to content

Commit 4022b4c

Browse files
committed
obvious fixes in space hub due API changes
1 parent e3958e6 commit 4022b4c

File tree

6 files changed

+24
-57
lines changed

6 files changed

+24
-57
lines changed

dev/TODO.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ TODO:
55
+ OKLAB
66
+ HunterLAB
77
+ HSI
8+
+ NCS
9+
+ Yxy
810

911
- Set methods
1012
+ bowl

lib/Graphics/Toolkit/Color/Space/Hub.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ sub add_space {
2828

2929
sub remove_space {
3030
my $name = shift;
31-
return "got no name as argument" unless defind $nam and $name;
31+
return "got no name as argument" unless defined $name and $name;
3232
return "no known color space with name $name" unless ref get_space( $name );
3333
delete $space_lookup{ $name };
3434
}
@@ -43,7 +43,7 @@ sub _check_values_and_space {
4343
$space_name //= $base_package;
4444
check_space_name( $space_name ) and return;
4545
my $space = get_space($space_name);
46-
$space->is_array( $values ) ? $space
46+
$space->is_value_tuple( $values ) ? $space
4747
: 'need an ARRAY ref with '.$space->axis." $space_name values as first argument of $sub_name";
4848
}
4949

lib/Graphics/Toolkit/Color/Space/Instance/LCHab.pm

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
use v5.12;
22
use warnings;
33

4-
# CIE LCh(ab) linear color space specific code
4+
# CIE LCh(ab) cylindrical color space specific code
55

66
package Graphics::Toolkit::Color::Space::Instance::LCHab;
77
use Graphics::Toolkit::Color::Space;
88
use Graphics::Toolkit::Color::Space::Util qw/mult_matrix apply_d65 remove_d65/;
99

10-
my $hcl_def = Graphics::Toolkit::Color::Space->new(prefix => 'CIE', name => 'LCHab',
10+
my $hcl_def = Graphics::Toolkit::Color::Space->new(prefix => 'CIE', name => 'LCHab',
1111
axis => [qw/luminance croma hue/],
1212
#short => [qw/luminance croma hue/],
13-
range => [100, 1, 1.08883] );
13+
range => [100, 539, 360] );
1414

1515
$hcl_def->add_converter('RGB', \&to_rgb, \&from_rgb );
1616

1717
sub from_rgb {
1818
my ($r, $g, $b) = @_;
1919
my ($x, $y, $z) = mult_matrix([[0.4124564, 0.2126729, 0.0193339],
2020
[0.3575761, 0.7151522, 0.1191920],
21-
[0.1804375, 0.0721750, 0.9503041]],
21+
[0.1804375, 0.0721750, 0.9503041]],
2222
apply_d65( $r ), apply_d65( $g ), apply_d65( $b ));
2323
$x /= 0.95047;
2424
$z /= 0.108883;
25-
25+
2626
$x = ($x > 0.008856) ? ($x ** (1/3)) : (7.7870689 * $x + 0.137931034);
2727
$y = ($y > 0.008856) ? ($y ** (1/3)) : (7.7870689 * $y + 0.137931034);
2828
$z = ($z > 0.008856) ? ($z ** (1/3)) : (7.7870689 * $z + 0.137931034);

lib/Graphics/Toolkit/Color/Space/Instance/LCHuv.pm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v5.12;
22
use warnings;
33

4-
# CIE LCh(uv) linear color space specific code
4+
# CIE LCh(uv) cylindrical color space specific code
55

66
package Graphics::Toolkit::Color::Space::Instance::LCHuv;
77
use Graphics::Toolkit::Color::Space;
@@ -17,11 +17,11 @@ sub from_rgb {
1717
my ($r, $g, $b) = @_;
1818
my ($x, $y, $z) = mult_matrix([[0.4124564, 0.2126729, 0.0193339],
1919
[0.3575761, 0.7151522, 0.1191920],
20-
[0.1804375, 0.0721750, 0.9503041]],
20+
[0.1804375, 0.0721750, 0.9503041]],
2121
apply_d65( $r ), apply_d65( $g ), apply_d65( $b ));
2222
$x /= 0.95047;
2323
$z /= 0.108883;
24-
24+
2525
$x = ($x > 0.008856) ? ($x ** (1/3)) : (7.7870689 * $x + 0.137931034);
2626
$y = ($y > 0.008856) ? ($y ** (1/3)) : (7.7870689 * $y + 0.137931034);
2727
$z = ($z > 0.008856) ? ($z ** (1/3)) : (7.7870689 * $z + 0.137931034);

t/23_luv_space.t

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -14,55 +14,20 @@ is( not($@), 1, 'could load the module');
1414
is( ref $def, 'Graphics::Toolkit::Color::Space', 'got tight return value by loading module');
1515
is( $def->name, 'CIELUV', 'color space has right name');
1616
is( $def->axis, 3, 'color space has 3 dimensions');
17-
is( $def->is_array([0,0,0]), 1, 'vector has 3 elements');
18-
is( $def->is_partial_hash({i => 1, quadrature => 0}), 1, 'found hash with some keys');
17+
is( $def->is_value_tuple([0,0,0]), 1, 'tuple has 3 elements');
18+
is( $def->is_partial_hash({u => 1, v => 0}), 1, 'found hash with some axis names');
19+
is( $def->is_partial_hash({u => 1, v => 0, l => 0}), 1, 'found hash with all axis names');
20+
is( $def->is_partial_hash({a => 1, v => 0, l => 0}), 0, 'found hash with onw wrong axis name');
1921
is( $def->can_convert('rgb'), 1, 'do only convert from and to rgb');
2022
is( $def->can_convert('yiq'), 0, 'can not convert to itself');
21-
is( $def->format([0,0,0], 'css_string'), 'yiq(0,0,0)', 'can format css string');
22-
my @val = $def->deformat(['LUV', 1, 0, -0.1]);
23-
is( int @val, 3, 'deformated value triplet (vector)');
24-
is( $val[0], 1, 'first value good');
25-
is( $val[1], 0, 'second value good');
26-
is( $val[2], -0.1, 'third value good');
23+
is( $def->format([0,0,0], 'css_string'), 'cieluv(0, 0, 0)', 'can format css string');
2724

28-
ok( !$def->check([0, -0.5959, -0.5227]), 'check YIO values works on lower bound values');
29-
ok( !$def->check([1, 0.5959, 0.5227]), 'check YIO values works on upper bound values');
30-
warning_like {$def->check([0,0])} {carped => qr/needs 3 values/}, "check YIQ got too few values";
31-
warning_like {$def->check([0, 0, 0, 0])} {carped => qr/needs 3 values/}, "check YIQ got too many values";
25+
my $val = $def->deformat(['CIELUV', 1, 0, -0.1]);
26+
is( ref $val, 'ARRAY', 'deformated random value tuple');
27+
is( int @$val, 3, 'right amount of values');
28+
is( $val->[0], 1, 'first value good');
29+
is( $val->[1], 0, 'second value good');
30+
is( $val->[2], -0.1, 'third value good');
3231

33-
is( $def->check([0,0,0]), undef, 'checked neutral values');
34-
warning_like {$def->check([-0.1, 0, 0])} {carped => qr/luminance value is below/}, "luminance value is too small";
35-
warning_like {$def->check([ 1.1, 0,0])} {carped => qr/luminance value is above/}, "luminance value is too big";
36-
warning_like {$def->check([0, -0.6, 0])} {carped => qr/in-phase value is below/}, "whiteness value is too small";
37-
warning_like {$def->check([0, 0.6,0])} {carped => qr/in-phase value is above/}, "whiteness value is too big";
38-
warning_like {$def->check([0,0, -0.53 ])} {carped => qr/quadrature value is below/},"quadrature value is too small";
39-
warning_like {$def->check([0,0, 0.53])} {carped => qr/quadrature value is above/}, "quadrature value is too big";
40-
41-
42-
43-
my @yiq = $def->deconvert( [ 0.5, 0.5, 0.5], 'RGB');
44-
is( int @yiq, 3, 'converted color grey has three YIQ values');
45-
is( $yiq[0], 0.5, 'converted color grey has computed right luminance value');
46-
is( $yiq[1], 0.5, 'converted color grey has computed right in-phase');
47-
is( $yiq[2], 0.5, 'converted color grey has computed right quadrature');
48-
49-
my @rgb = $def->convert( [0.5, 0.5, 0.5], 'RGB');
50-
is( int @rgb, 3, 'converted back color grey has three rgb values');
51-
is( $rgb[0], 0.5, 'converted back color grey has right red value');
52-
is( $rgb[1], 0.5, 'converted back color grey has right green value');
53-
is( $rgb[2], 0.5, 'converted back color grey has right blue value');
54-
55-
@yiq = $def->deconvert( [0.1, 0, 1], 'RGB');
56-
is( int @yiq, 3, 'converted blue has three YIQ values');
57-
is( close_enough( $yiq[0], 0.1439 ) , 1 , 'converted nice blue has right Y value');
58-
is( close_enough( $yiq[1], 0.280407787), 1 , 'converted nice blue has right I value');
59-
is( close_enough( $yiq[2], 0.817916587), 1 , 'converted nice blue has right Q value');
60-
61-
62-
@rgb = $def->convert( [0.1439, 0.280407787, 0.817916587], 'RGB');
63-
is( int @rgb, 3, 'converted back nice blue');
64-
is( close_enough($rgb[0], 0.1), 1, 'right red value');
65-
is( close_enough($rgb[1], 0 ), 1, 'right green value');
66-
is( close_enough($rgb[2], 1, ), 1, 'right blue value');
6732

6833
exit 0;

t/lib/Test/Color.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use v5.12;
22
use warnings;
33

4-
# utilities for any sub module of the distribution
4+
# utilities for tests
55

66
package Test::Color;
77

0 commit comments

Comments
 (0)