Skip to content

Commit

Permalink
fix yiq color space tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lichtkind committed Apr 29, 2024
1 parent 06add0a commit f0f72c3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions lib/Graphics/Toolkit/Color/Space.pm
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ sub basis { $_[0]{'basis'} }
sub name { $_[0]->basis->space_name } # --> ~
sub axis { $_[0]->basis->count } # --> +
sub is_value_tuple { $_[0]->basis->is_value_tuple( $_[1] ) } # @+values --> ?
sub is_partial_hash { $_[0]->basis->is_partial_hash( $_[1] ) }# %+values --> ?

########################################################################

Expand Down
4 changes: 2 additions & 2 deletions lib/Graphics/Toolkit/Color/Space/Instance/YIQ.pm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ my $yiq_def = Graphics::Toolkit::Color::Space->new( axis => [qw/luminance in_p
$yiq_def->add_converter('RGB', \&to_rgb, \&from_rgb );

sub from_rgb {
my ($r, $g, $b) = @_;
my ($r, $g, $b) = @{$_[0]};
my $y = (0.299 * $r) + ( 0.587 * $g) + ( 0.114 * $b);
my $i = ($i_max + (0.5959 * $r) + (-0.2746 * $g) + (-0.3213 * $b)) / $i_size;
my $q = ($q_max + (0.2115 * $r) + (-0.5227 * $g) + ( 0.3112 * $b)) / $q_size;
Expand All @@ -25,7 +25,7 @@ sub from_rgb {


sub to_rgb {
my ($y, $i, $q) = @_;
my ($y, $i, $q) = @{$_[0]};
$i = ($i * $i_size) - $i_max;
$q = ($q * $q_size) - $q_max;
my $r = $y + ( 0.956 * $i) + ( 0.619 * $q);
Expand Down
4 changes: 2 additions & 2 deletions t/17_yiq_space.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use Graphics::Toolkit::Color::Space::Util ':all';
is( not($@), 1, 'could load the module');
is( ref $def, 'Graphics::Toolkit::Color::Space', 'got tight return value by loading module');
is( $def->name, 'YIQ', 'color space has right name');
is( $def->dimensions, 3, 'color space has 3 dimensions');
is( $def->axis, 3, 'color space has 3 axis');
is( ref $def->in_range([0, 0, 0]), 'ARRAY', 'check neutral YIQ values are in bounds');
is( ref $def->in_range([0, -0.5959, 0.5227]), 'ARRAY', 'check YIQ values works on lower bound values');
is( ref $def->in_range([1, 0.5959, 0.5227]), 'ARRAY', 'check YIQ values works on upper bound values');
Expand All @@ -27,7 +27,7 @@ is( ref $def->in_range([0, 0, -1 ] ), '', "quadrature value is too small
is( ref $def->in_range([0, 0, 1] ), '', "quadrature value is too big");


is( $def->is_array([0,0,0]), 1, 'vector has 3 elements');
is( $def->is_value_tuple([0,0,0]), 1, 'value vector has 3 elements');
is( $def->is_partial_hash({i => 1, quadrature => 0}), 1, 'found hash with some keys');
is( $def->can_convert('rgb'), 1, 'do only convert from and to rgb');
is( $def->can_convert('yiq'), 0, 'can not convert to itself');
Expand Down

0 comments on commit f0f72c3

Please sign in to comment.