Skip to content

Commit

Permalink
fix YIQ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lichtkind committed Apr 12, 2024
1 parent bd5316d commit 4657bbf
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 87 deletions.
1 change: 0 additions & 1 deletion t/14_hsv_space.t
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ is( not($@), 1, 'could load the module');
is( ref $def, 'Graphics::Toolkit::Color::Space', 'got tight return value by loading module');
is( $def->name, 'HSV', 'color space has right name');
is( $def->dimensions, 3, 'color space has 3 dimensions');

is( ref $def->in_range([0, 0, 0]), 'ARRAY', 'check HSV values works on lower bound values');
is( ref $def->in_range([360,100,100]), 'ARRAY', 'check HSV values works on upper bound values');
is( ref $def->in_range([0,0]), '', "HSV got too few values");
Expand Down
91 changes: 44 additions & 47 deletions t/16_hwb_space.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,53 +15,50 @@ is( not($@), 1, 'could load the module');
is( ref $def, 'Graphics::Toolkit::Color::Space', 'got tight return value by loading module');
is( $def->name, 'HWB', 'color space has right name');
is( $def->dimensions, 3, 'color space has 3 dimensions');

ok( !$def->check([0,0,0]), 'check hsl values works on lower bound values');
ok( !$def->check([360,100,100]), 'check hsl values works on upper bound values');
warning_like {$def->check([0,0])} {carped => qr/needs 3 values/}, "check cmy got too few values";
warning_like {$def->check([0, 0, 0, 0])} {carped => qr/needs 3 values/}, "check cmy got too many values";

warning_like {$def->check([-1, 0, 0])} {carped => qr/hue value/}, "hue value is too small";
warning_like {$def->check([0.5, 0,0])} {carped => qr/hue value/}, "hue value is not integer";
warning_like {$def->check([361, 0,0])} {carped => qr/hue value/}, "hue value is too big";
warning_like {$def->check([0, -1, 0])} {carped => qr/whiteness value/}, "whiteness value is too small";
warning_like {$def->check([0, 0.5,0])} {carped => qr/whiteness value/}, "whiteness value is not integer";
warning_like {$def->check([0, 101,0])} {carped => qr/whiteness value/}, "whiteness value is too big";
warning_like {$def->check([0,0, -1 ])} {carped => qr/blackness value/}, "blackness value is too small";
warning_like {$def->check([0,0, 0.5])} {carped => qr/blackness value/}, "blackness value is not integer";
warning_like {$def->check([0,0, 101])} {carped => qr/blackness value/}, "blackness value is too big";



my @hwb = $def->deconvert( [ .5, .5, .5], 'RGB');
is( int @hwb, 3, 'converted color grey has three hwb values');
is( $hwb[0], 0, 'converted color grey has computed right hue value');
is( $hwb[1], .5, 'converted color grey has computed right whiteness');
is( $hwb[2], .5, 'converted color grey has computed right blackness');

my @rgb = $def->convert( [0, 0.5, .5], 'RGB');
is( int @rgb, 3, 'converted back color grey has three rgb values');
is( $rgb[0], 0.5, 'converted back color grey has right red value');
is( $rgb[1], 0.5, 'converted back color grey has right green value');
is( $rgb[2], 0.5, 'converted back color grey has right blue value');

@hwb = $def->deconvert( [210/255, 20/255, 70/255], 'RGB');
is( int @hwb, 3, 'converted nice magents has three hwb values');
is( close_enough( $hwb[0], 0.95555), 1, 'converted nice magenta has computed right hue value');
is( close_enough( $hwb[1], 0.08, ), 1, 'converted nice magenta has computed right whiteness');
is( close_enough( $hwb[2], 0.18, ), 1, 'converted nice magenta has computed right blackness');

@rgb = $def->convert( [0.95555, 0.08, 0.18], 'RGB');
is( int @rgb, 3, 'converted back nice magenta');
is( close_enough( $rgb[0], 210/255), 1, 'right red value');
is( close_enough( $rgb[1], 20/255) , 1, 'right green value');
is( close_enough( $rgb[2], 70/255) , 1, 'right blue value');

@rgb = $def->convert( [0.83333, 0, 1], 'RGB'); # should become black despite color value
is( int @rgb, 3, 'converted black');
is( $rgb[0], 0, 'right red value');
is( $rgb[1], 0, 'right green value');
is( $rgb[2], 0, 'right blue value');
is( ref $def->in_range([0, 0, 0]), 'ARRAY', 'check HWB values works on lower bound values');
is( ref $def->in_range([360,100,100]), 'ARRAY', 'check HWB values works on upper bound values');
is( ref $def->in_range([0,0]), '', "HWB got too few values");
is( ref $def->in_range([0, 0, 0, 0]), '', "HWB got too many values");
is( ref $def->in_range([-1, 0, 0]), '', "hue value is too small");
is( ref $def->in_range([1.1, 0, 0]), '', "hue is not integer");
is( ref $def->in_range([361, 0, 0]), '', "hue value is too big");
is( ref $def->in_range([0, -1, 0]), '', "whiteness value is too small");
is( ref $def->in_range([0, 1.1, 0]), '', "whiteness value is not integer");
is( ref $def->in_range([0, 101, 0]), '', "whiteness value is too big");
is( ref $def->in_range([0, 0, -1 ] ), '', "blackness value is too small");
is( ref $def->in_range([0, 0, 1.1] ), '', "blackness value is not integer");
is( ref $def->in_range([0, 0, 101] ), '', "blackness value is too big");


my $hwb = $def->deconvert( [ .5, .5, .5], 'RGB');
is( int @$hwb, 3, 'converted color grey has three hwb values');
is( $hwb->[0], 0, 'converted color grey has computed right hue value');
is( $hwb->[1], .5, 'converted color grey has computed right whiteness');
is( $hwb->[2], .5, 'converted color grey has computed right blackness');

my $rgb = $def->convert( [0, 0.5, .5], 'RGB');
is( int @$rgb, 3, 'converted back color grey has three rgb values');
is( $rgb->[0], 0.5, 'converted back color grey has right red value');
is( $rgb->[1], 0.5, 'converted back color grey has right green value');
is( $rgb->[2], 0.5, 'converted back color grey has right blue value');

$hwb = $def->deconvert( [210/255, 20/255, 70/255], 'RGB');
is( int @$hwb, 3, 'converted nice magents has three hwb values');
is( close_enough( $hwb->[0], 0.95555), 1, 'converted nice magenta has computed right hue value');
is( close_enough( $hwb->[1], 0.08, ), 1, 'converted nice magenta has computed right whiteness');
is( close_enough( $hwb->[2], 0.18, ), 1, 'converted nice magenta has computed right blackness');

$rgb = $def->convert( [0.95555, 0.08, 0.18], 'RGB');
is( int @$rgb, 3, 'converted back nice magenta');
is( close_enough( $rgb->[0], 210/255), 1, 'right red value');
is( close_enough( $rgb->[1], 20/255) , 1, 'right green value');
is( close_enough( $rgb->[2], 70/255) , 1, 'right blue value');

$rgb = $def->convert( [0.83333, 0, 1], 'RGB'); # should become black despite color value
is( int @$rgb, 3, 'converted black');
is( $rgb->[0], 0, 'right red value');
is( $rgb->[1], 0, 'right green value');
is( $rgb->[2], 0, 'right blue value');


exit 0;
Expand Down
77 changes: 38 additions & 39 deletions t/17_yiq_space.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,55 +15,54 @@ 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( 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');
is( ref $def->in_range([0,0]), '', "YIQ got too few values");
is( ref $def->in_range([0, 0, 0, 0]), '', "YIQ got too many values");
is( ref $def->in_range([-1, 0, 0]), '', "luminance value is too small");
is( ref $def->in_range([1.1, 0, 0]), '', "luminance value is too big");
is( ref $def->in_range([0, -1, 0]), '', "in_phase value is too small");
is( ref $def->in_range([0, 1, 0]), '', "in_phase value is too big");
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_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');
is( $def->format([0,0,0], 'css_string'), 'yiq(0,0,0)', 'can format css string');
my @val = $def->deformat(['YIQ', 1, 0, -0.1]);
is( int @val, 3, 'deformated value triplet (vector)');
is( $val[0], 1, 'first value good');
is( $val[1], 0, 'second value good');
is( $val[2], -0.1, 'third value good');

ok( !$def->check([0, -0.5959, -0.5227]), 'check YIO values works on lower bound values');
ok( !$def->check([1, 0.5959, 0.5227]), 'check YIO values works on upper bound values');
warning_like {$def->check([0,0])} {carped => qr/needs 3 values/}, "check YIQ got too few values";
warning_like {$def->check([0, 0, 0, 0])} {carped => qr/needs 3 values/}, "check YIQ got too many values";

is( $def->check([0,0,0]), undef, 'checked neutral values');
warning_like {$def->check([-0.1, 0, 0])} {carped => qr/luminance value is below/}, "luminance value is too small";
warning_like {$def->check([ 1.1, 0,0])} {carped => qr/luminance value is above/}, "luminance value is too big";
warning_like {$def->check([0, -0.6, 0])} {carped => qr/in_phase value is below/}, "in_phase value is too small";
warning_like {$def->check([0, 0.6,0])} {carped => qr/in_phase value is above/}, "in_phase value is too big";
warning_like {$def->check([0,0, -0.53 ])} {carped => qr/quadrature value is below/},"quadrature value is too small";
warning_like {$def->check([0,0, 0.53])} {carped => qr/quadrature value is above/}, "quadrature value is too big";


my $val = $def->deformat(['YIQ', 1, 0, -0.1]);
is( int @$val, 3, 'deformated value triplet (vector)');
is( $val->[0], 1, 'first value good');
is( $val->[1], 0, 'second value good');
is( $val->[2], -0.1, 'third value good');

my @yiq = $def->deconvert( [ 0.5, 0.5, 0.5], 'RGB');
is( int @yiq, 3, 'converted color grey has three YIQ values');
is( $yiq[0], 0.5, 'converted color grey has computed right luminance value');
is( $yiq[1], 0.5, 'converted color grey has computed right in-phase');
is( $yiq[2], 0.5, 'converted color grey has computed right quadrature');

my @rgb = $def->convert( [0.5, 0.5, 0.5], 'RGB');
is( int @rgb, 3, 'converted back color grey has three rgb values');
is( $rgb[0], 0.5, 'converted back color grey has right red value');
is( $rgb[1], 0.5, 'converted back color grey has right green value');
is( $rgb[2], 0.5, 'converted back color grey has right blue value');
my $yiq = $def->deconvert( [ 0.5, 0.5, 0.5], 'RGB');
is( int @$yiq, 3, 'converted color grey has three YIQ values');
is( $yiq->[0], 0.5, 'converted color grey has computed right luminance value');
is( $yiq->[1], 0.5, 'converted color grey has computed right in-phase');
is( $yiq->[2], 0.5, 'converted color grey has computed right quadrature');

@yiq = $def->deconvert( [0.1, 0, 1], 'RGB');
is( int @yiq, 3, 'converted blue has three YIQ values');
is( close_enough( $yiq[0], 0.1439 ) , 1 , 'converted nice blue has right Y value');
is( close_enough( $yiq[1], 0.280407787), 1 , 'converted nice blue has right I value');
is( close_enough( $yiq[2], 0.817916587), 1 , 'converted nice blue has right Q value');
my $rgb = $def->convert( [0.5, 0.5, 0.5], 'RGB');
is( int @$rgb, 3, 'converted back color grey has three rgb values');
is( $rgb->[0], 0.5, 'converted back color grey has right red value');
is( $rgb->[1], 0.5, 'converted back color grey has right green value');
is( $rgb->[2], 0.5, 'converted back color grey has right blue value');

$yiq = $def->deconvert( [0.1, 0, 1], 'RGB');
is( int @$yiq, 3, 'converted blue has three YIQ values');
is( close_enough( $yiq->[0], 0.1439 ) , 1 , 'converted nice blue has right Y value');
is( close_enough( $yiq->[1], 0.280407787), 1 , 'converted nice blue has right I value');
is( close_enough( $yiq->[2], 0.817916587), 1 , 'converted nice blue has right Q value');

@rgb = $def->convert( [0.1439, 0.280407787, 0.817916587], 'RGB');
is( int @rgb, 3, 'converted back nice blue');
is( close_enough($rgb[0], 0.1), 1, 'right red value');
is( close_enough($rgb[1], 0 ), 1, 'right green value');
is( close_enough($rgb[2], 1, ), 1, 'right blue value');
$rgb = $def->convert( [0.1439, 0.280407787, 0.817916587], 'RGB');
is( int @$rgb, 3, 'converted back nice blue');
is( close_enough($rgb->[0], 0.1), 1, 'right red value');
is( close_enough($rgb->[1], 0 ), 1, 'right green value');
is( close_enough($rgb->[2], 1, ), 1, 'right blue value');

exit 0;

0 comments on commit 4657bbf

Please sign in to comment.