X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FConvert%2FColor%2FHPLuv.pm;fp=lib%2FConvert%2FColor%2FHPLuv.pm;h=ee04f22eac70ad795607775bc3644bb0818d4e15;hb=d192eff48feed45b10dadcc7135c6d1cc58250ca;hp=0000000000000000000000000000000000000000;hpb=a17d2402f10384cb86b2b33118be1b0c2eb47024;p=convert-color-hsluv.git diff --git a/lib/Convert/Color/HPLuv.pm b/lib/Convert/Color/HPLuv.pm new file mode 100644 index 0000000..ee04f22 --- /dev/null +++ b/lib/Convert/Color/HPLuv.pm @@ -0,0 +1,112 @@ +package Convert::Color::HPLuv; + +use 5.008009; +use strict; +use warnings; +use parent qw/Convert::Color::HSLuv/; + +use Convert::Color::XYZ; +use Convert::Color::LUV; +use Convert::Color::LCh; +use List::Util qw/min/; +use Math::Trig qw/:pi/; + +BEGIN { + *_get_bounds = *Convert::Color::HSLuv::_get_bounds; ## no critic (ProtectPrivate) +} + +our $VERSION = '1.000'; + +__PACKAGE__->register_color_space('hpluv'); + +sub _intersect_line_line { + my ($l1, $l2) = @_; + ($l1->[1] - $l2->[1]) / ($l2->[0] - $l1->[0]) +} + +sub _distance_from_pole { + my ($x, $y) = @_; + sqrt $x * $x + $y * $y +} + +sub max_chroma_for_lh { + my ($self, $l) = @_; + min map { + my ($m, $n) = @$_; + my $x = _intersect_line_line $_, [-1 / $m, 0]; + _distance_from_pole $x, $n + $x * $m + } _get_bounds $l +} + +1; +__END__ + +=encoding utf-8 + +=head1 NAME + +Convert::Color::HPLuv - a color value in the HPLuv color space + +=head1 SYNOPSIS + + use Convert::Color::HPLuv; + my $reddish = Convert::Color::HPLuv->new(12.17705, 100, 53.23712); + my $greenish = Convert::Color::HPLuv->new('127.71501,100,87.73552'); + + use Convert::Color; + my $bluish = Convert::Color->new('hpluv:265.87432,100,32.30087'); + + say $reddish->H; # 12.17705 + say $reddish->S; # 100 + say $reddish->L; # 53.23712 + say join ',', $bluish->hsl; # 265.87432,100,32.30087 + +=head1 DESCRIPTION + +Objects of this class represent colors in the HPLuv color space, revision 4. + +Methods: + +=over + +=item Convert::Color::HPLuv->B(I<$h>, I<$s>, I<$l>) + +Construct a color from its components. + +=item Convert::Color::HPLuv->B(I<"$h,$s,$l">) + +Construct a color from a string. The string should contain the three +components, separated by commas. + +=item $hpluv->B + +=item $hpluv->B + +=item $hpluv->B + +Accessors for the three components of the color. + +=item $hpluv->B + +Returns the three components as a list. + +=back + +=head1 SEE ALSO + +L, L + +=head1 AUTHOR + +Marius Gavrilescu, Emarius@ieval.roE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2015 by Marius Gavrilescu + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.20.2 or, +at your option, any later version of Perl 5 you may have available. + + +=cut