@@ -15,7 +15,7 @@ sub is_space { (defined $_[0] and ref get_space($_[0])) ? 1 : 0 }
15
15
sub base_space { $space_lookup { $base_package } }
16
16
sub space_names { keys %{%space_lookup } }
17
17
18
- # ############## #########################################################
18
+ # ### space API #########################################################
19
19
20
20
sub add_space {
21
21
my $space = shift ;
@@ -47,15 +47,16 @@ sub _check_values_and_space {
47
47
: ' need an ARRAY ref with ' .$space -> dimensions." $space_name values as first argument of $sub_name " ;
48
48
}
49
49
50
- # ############## #########################################################
50
+ # ### value API #########################################################
51
51
52
52
sub partial_hash_deformat { # convert partial hash into
53
53
my ($value_hash ) = @_ ;
54
54
return unless ref $value_hash eq ' HASH' ;
55
55
for my $space_name (space_names()) {
56
56
my $color_space = get_space( $space_name );
57
57
my $pos_hash = $color_space -> basis-> deformat_partial_hash( $value_hash );
58
- return $pos_hash , $color_space -> name if ref $pos_hash eq ' HASH' ;
58
+ next unless ref $pos_hash eq ' HASH' ;
59
+ return wantarray ? ($pos_hash , $color_space -> name) : $pos_hash ;
59
60
}
60
61
return undef ;
61
62
}
@@ -79,24 +80,6 @@ sub format { # @tuple --> % | % |~ ...
79
80
return @values == 1 ? $values [0] : @values ;
80
81
}
81
82
82
- sub deconvert { # @... --> @RGB (base color space) # normalized values only
83
- my ($values , $space_name ) = @_ ;
84
- my $space = _check_values_and_space( ' deconvert' , $values , $space_name );
85
- return unless ref $space ;
86
- $values = $space -> clamp( $values , ' normal' , -1);
87
- return $values if $space -> name eq base_space-> name;
88
- $space -> convert( $values , $base_package );
89
- }
90
-
91
- sub convert { # @RGB --> $@...|!~ # normalized values only
92
- my ($values , $space_name ) = @_ ;
93
- my $space = _check_values_and_space( ' convert' , $values , $space_name );
94
- return $space unless ref $space ;
95
- $values = base_space-> clamp( $values , ' normal' , -1);
96
- return $values if $space -> name eq base_space-> name;
97
- $space -> deconvert( $values , $base_package );
98
- }
99
-
100
83
sub denormalize { # result clamped, alway in space
101
84
my ($values , $space_name , $range ) = @_ ;
102
85
my $space = _check_values_and_space( ' denormalize' , $values , $space_name );
@@ -114,6 +97,23 @@ sub normalize {
114
97
$space -> normalize( $values , $range );
115
98
}
116
99
100
+ sub deconvert { # @... --> @RGB (base color space) # normalized values only
101
+ my ($values , $space_name ) = @_ ;
102
+ my $space = _check_values_and_space( ' deconvert' , $values , $space_name );
103
+ return unless ref $space ;
104
+ $values = $space -> clamp( $values , ' normal' , -1);
105
+ return $values if $space -> name eq base_space-> name;
106
+ $space -> convert( $values , $base_package );
107
+ }
108
+
109
+ sub convert { # @RGB --> $@...|!~ # normalized values only
110
+ my ($values , $space_name ) = @_ ;
111
+ my $space = _check_values_and_space( ' convert' , $values , $space_name );
112
+ return $space unless ref $space ;
113
+ $values = base_space-> clamp( $values , ' normal' , -1);
114
+ return $values if $space -> name eq base_space-> name;
115
+ $space -> deconvert( $values , $base_package );
116
+ }
117
117
118
118
1;
119
119
@@ -211,6 +211,17 @@ B<whiteness> and B<blackness>, desribing how much white or black are mixed in.
211
211
If both are zero, than we have a pure color. I<whiteness > of 100 always
212
212
leads to pure white and I<blackness > of 100 always leads to pure black.
213
213
214
+ =head2 NCol
215
+
216
+ Is a human readable derivation of the HWB space with altered B<hue > axis
217
+ that consicts of a letter and nwo digits. The letter demarks one of the
218
+ six areas around the rainbow B<R > (I<Red > ), B<Y > (I<Yellow > ), B<G > (I<Green),
219
+ B<C > (I<Cyan > ), B<B > (I<Blue > ), B<M > (I<Magenta). The two digits after this
220
+ letter are a percentual value, pointing to a position on the rainbow,
221
+ between the stated color by the letter and the next. The B<whiteness > and
222
+ B<blackness > axis have values with the suffix I<% > , since they are
223
+ percentual values as well.
224
+
214
225
=head2 YIQ
215
226
216
227
Has three linear dimensions:
@@ -244,6 +255,7 @@ Their ranges are 0 .. 100, -500 .. 500 and -200 .. 200.
244
255
Has three linear real valued dimension named B<luminance > , B<croma > and B<hue > .
245
256
Their ranges are 0 .. 100, -500 .. 500 and -200 .. 200.
246
257
258
+
247
259
=head1 RANGES
248
260
249
261
As pointed out in the previous paragraph, each dimension of color space has
0 commit comments