Skip to content

Commit

Permalink
fix cmyk tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lichtkind committed Apr 29, 2024
1 parent 36f52a0 commit 25c2d46
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/Graphics/Toolkit/Color/Space/Format.pm
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ sub deformat {
my $values = $deformatter->( $self, $color );
next unless $self->basis->is_value_tuple( $values );
$values = $self->remove_suffix($values, $suffix);
return ($values, $name)
return wantarray ? ($values, $name) : $values;
}
return undef;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Graphics/Toolkit/Color/Space/Instance/CMYK.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ my $cmyk_def = Graphics::Toolkit::Color::Space->new( axis => [qw/cyan magenta ye
$cmyk_def->add_converter('RGB', \&to_rgb, \&from_rgb );

sub from_rgb {
my ($r, $g, $b) = @_;
my ($r, $g, $b) = @{$_[0]};
return unless defined $b;
my $km = max($r, $g, $b);
return (0,0,0,1) unless $km; # prevent / 0
Expand All @@ -23,7 +23,7 @@ sub from_rgb {
}

sub to_rgb {
my ($c, $m, $y, $k) = @_;
my ($c, $m, $y, $k) = @{$_[0]};
return ( (1-$c) * (1-$k) ,
(1-$m) * (1-$k) ,
(1-$y) * (1-$k) ,
Expand Down
3 changes: 2 additions & 1 deletion t/12_cmyk_space.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ my $def = eval "require $module";
is( not($@), 1, 'could load the module');
is( ref $def, 'Graphics::Toolkit::Color::Space', 'got tight return value by loading module');
is( $def->name, 'CMYK', 'color space has right name');
is( $def->dimensions, 4, 'color space has 4 dimensions');
is( $def->axis, 4, 'color space has 4 axis');

is( ref $def->in_range([0,0,0, 0]), 'ARRAY', 'check CMYK values works on lower bound values');
is( ref $def->in_range([1, 1, 1, 1]), 'ARRAY', 'check CMYK values works on upper bound values');
Expand Down Expand Up @@ -83,6 +83,7 @@ is( $rgb->[0], 0.3, 'right red value');
is( $rgb->[1], 0.4, 'right green value');
is( $rgb->[2], 0.5, 'right blue value');


$cmyk = $def->deformat([cmyk => 11, 22, 256, -1]);
is( int @$cmyk, 4, 'deformat lc named ARRAY: got 4 values');
is( $cmyk->[0], 11, 'cyan got transported');
Expand Down

0 comments on commit 25c2d46

Please sign in to comment.