Skip to content

Commit b291ba3

Browse files
committed
document Ncol space
1 parent 5f1f655 commit b291ba3

File tree

4 files changed

+38
-27
lines changed

4 files changed

+38
-27
lines changed

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

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ sub is_space { (defined $_[0] and ref get_space($_[0])) ? 1 : 0 }
1515
sub base_space { $space_lookup{ $base_package } }
1616
sub space_names { keys %{%space_lookup} }
1717

18-
########################################################################
18+
#### space API #########################################################
1919

2020
sub 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

5252
sub 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-
10083
sub 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

118118
1;
119119

@@ -211,6 +211,17 @@ B<whiteness> and B<blackness>, desribing how much white or black are mixed in.
211211
If both are zero, than we have a pure color. I<whiteness> of 100 always
212212
leads 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
216227
Has three linear dimensions:
@@ -244,6 +255,7 @@ Their ranges are 0 .. 100, -500 .. 500 and -200 .. 200.
244255
Has three linear real valued dimension named B<luminance>, B<croma> and B<hue>.
245256
Their ranges are 0 .. 100, -500 .. 500 and -200 .. 200.
246257
258+
247259
=head1 RANGES
248260
249261
As pointed out in the previous paragraph, each dimension of color space has

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,8 @@ sub denormalize {
161161
$range = $self->_range( $range );
162162
return "bad range definition" unless ref $range;
163163

164-
my @val = map { ($self->axis_is_numeric( $_ )) ? ($values->[$_] * ($range->[$_][1]-$range->[$_][0]) + $range->[$_][0])
165-
: $values->[$_] } $self->basis->iterator;
166-
return $self->round( \@val, $precision );
164+
return [ map { ($self->axis_is_numeric( $_ )) ? ($values->[$_] * ($range->[$_][1]-$range->[$_][0]) + $range->[$_][0])
165+
: $values->[$_] } $self->basis->iterator ];
167166
}
168167

169168
sub denormalize_delta {

lib/Graphics/Toolkit/Color/Values.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ sub distance { # _c1 _c2 -- ~space ~select @range --> +
8484
my @values1 = $self->get( $space_name, 'list', 'normal' );
8585
my @values2 = $c2->get( $space_name, 'list', 'normal' );
8686
return unless defined $values1[0] and defined $values2[0];
87-
my $delta = $space->delta( \@values1, \@values2 );
8887

88+
my $delta = $space->delta( \@values1, \@values2 );
8989
$delta = $space->denormalize_range( $delta, $range);
9090
return unless ref $delta and @$delta == $space->dimensions;
9191

t/10_rgb_space.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ is( $d->[2], -256, 'delta in B component');
137137

138138
$rgb = $def->denormalize( [0.3, 0.4, 0.5], 255, 0 );
139139
is( int @$rgb, 3, 'denormalized triplet, got 3 values');
140-
is( $rgb->[0], 77, 'right red value');
140+
is( $rgb->[0], 76.5, 'right red value');
141141
is( $rgb->[1], 102, 'right green value');
142-
is( $rgb->[2], 128, 'right blue value');
142+
is( $rgb->[2], 127.5, 'right blue value');
143143
exit 0;
144144

145145
exit 0;

0 commit comments

Comments
 (0)