@@ -15,7 +15,7 @@ sub is_space { (defined $_[0] and ref get_space($_[0])) ? 1 : 0 }
1515sub base_space { $space_lookup { $base_package } }
1616sub space_names { keys %{%space_lookup } }
1717
18- # ############## #########################################################
18+ # ### space API #########################################################
1919
2020sub add_space {
2121 my $space = shift ;
@@ -47,15 +47,16 @@ sub _check_values_and_space {
4747 : ' need an ARRAY ref with ' .$space -> dimensions." $space_name values as first argument of $sub_name " ;
4848}
4949
50- # ############## #########################################################
50+ # ### value API #########################################################
5151
5252sub partial_hash_deformat { # convert partial hash into
5353 my ($value_hash ) = @_ ;
5454 return unless ref $value_hash eq ' HASH' ;
5555 for my $space_name (space_names()) {
5656 my $color_space = get_space( $space_name );
5757 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 ;
5960 }
6061 return undef ;
6162}
@@ -79,24 +80,6 @@ sub format { # @tuple --> % | % |~ ...
7980 return @values == 1 ? $values [0] : @values ;
8081}
8182
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-
10083sub denormalize { # result clamped, alway in space
10184 my ($values , $space_name , $range ) = @_ ;
10285 my $space = _check_values_and_space( ' denormalize' , $values , $space_name );
@@ -114,6 +97,23 @@ sub normalize {
11497 $space -> normalize( $values , $range );
11598}
11699
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+ }
117117
1181181;
119119
@@ -211,6 +211,17 @@ B<whiteness> and B<blackness>, desribing how much white or black are mixed in.
211211If both are zero, than we have a pure color. I<whiteness > of 100 always
212212leads to pure white and I<blackness > of 100 always leads to pure black.
213213
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+
214225=head2 YIQ
215226
216227Has three linear dimensions:
@@ -244,6 +255,7 @@ Their ranges are 0 .. 100, -500 .. 500 and -200 .. 200.
244255Has three linear real valued dimension named B<luminance > , B<croma > and B<hue > .
245256Their ranges are 0 .. 100, -500 .. 500 and -200 .. 200.
246257
258+
247259=head1 RANGES
248260
249261As pointed out in the previous paragraph, each dimension of color space has
0 commit comments