]>
Commit | Line | Data |
---|---|---|
d192eff4 | 1 | package Convert::Color::HPLuv; |
1f72b051 | 2 | |
4e59696a | 3 | use 5.008009; |
1f72b051 MG |
4 | use strict; |
5 | use warnings; | |
d192eff4 | 6 | use parent qw/Convert::Color::HSLuv/; |
1f72b051 MG |
7 | |
8 | use Convert::Color::XYZ; | |
9 | use Convert::Color::LUV; | |
10 | use Convert::Color::LCh; | |
11 | use List::Util qw/min/; | |
12 | use Math::Trig qw/:pi/; | |
13 | ||
14 | BEGIN { | |
d192eff4 | 15 | *_get_bounds = *Convert::Color::HSLuv::_get_bounds; ## no critic (ProtectPrivate) |
1f72b051 MG |
16 | } |
17 | ||
a34159d9 | 18 | our $VERSION = '1.000001'; |
1f72b051 | 19 | |
d192eff4 | 20 | __PACKAGE__->register_color_space('hpluv'); |
1f72b051 MG |
21 | |
22 | sub _intersect_line_line { | |
23 | my ($l1, $l2) = @_; | |
24 | ($l1->[1] - $l2->[1]) / ($l2->[0] - $l1->[0]) | |
25 | } | |
26 | ||
27 | sub _distance_from_pole { | |
28 | my ($x, $y) = @_; | |
29 | sqrt $x * $x + $y * $y | |
30 | } | |
31 | ||
32 | sub max_chroma_for_lh { | |
33 | my ($self, $l) = @_; | |
34 | min map { | |
35 | my ($m, $n) = @$_; | |
36 | my $x = _intersect_line_line $_, [-1 / $m, 0]; | |
37 | _distance_from_pole $x, $n + $x * $m | |
38 | } _get_bounds $l | |
39 | } | |
40 | ||
41 | 1; | |
42 | __END__ | |
43 | ||
44 | =encoding utf-8 | |
45 | ||
46 | =head1 NAME | |
47 | ||
d192eff4 | 48 | Convert::Color::HPLuv - a color value in the HPLuv color space |
1f72b051 MG |
49 | |
50 | =head1 SYNOPSIS | |
51 | ||
d192eff4 MG |
52 | use Convert::Color::HPLuv; |
53 | my $reddish = Convert::Color::HPLuv->new(12.17705, 100, 53.23712); | |
54 | my $greenish = Convert::Color::HPLuv->new('127.71501,100,87.73552'); | |
1f72b051 MG |
55 | |
56 | use Convert::Color; | |
d192eff4 | 57 | my $bluish = Convert::Color->new('hpluv:265.87432,100,32.30087'); |
1f72b051 MG |
58 | |
59 | say $reddish->H; # 12.17705 | |
60 | say $reddish->S; # 100 | |
61 | say $reddish->L; # 53.23712 | |
62 | say join ',', $bluish->hsl; # 265.87432,100,32.30087 | |
63 | ||
64 | =head1 DESCRIPTION | |
65 | ||
d192eff4 | 66 | Objects of this class represent colors in the HPLuv color space, revision 4. |
1f72b051 MG |
67 | |
68 | Methods: | |
69 | ||
70 | =over | |
71 | ||
d192eff4 | 72 | =item Convert::Color::HPLuv->B<new>(I<$h>, I<$s>, I<$l>) |
1f72b051 MG |
73 | |
74 | Construct a color from its components. | |
75 | ||
d192eff4 | 76 | =item Convert::Color::HPLuv->B<new>(I<"$h,$s,$l">) |
1f72b051 MG |
77 | |
78 | Construct a color from a string. The string should contain the three | |
79 | components, separated by commas. | |
80 | ||
d192eff4 | 81 | =item $hpluv->B<H> |
1f72b051 | 82 | |
d192eff4 | 83 | =item $hpluv->B<S> |
1f72b051 | 84 | |
d192eff4 | 85 | =item $hpluv->B<L> |
1f72b051 MG |
86 | |
87 | Accessors for the three components of the color. | |
88 | ||
d192eff4 | 89 | =item $hpluv->B<hsl> |
1f72b051 MG |
90 | |
91 | Returns the three components as a list. | |
92 | ||
93 | =back | |
94 | ||
95 | =head1 SEE ALSO | |
96 | ||
d192eff4 | 97 | L<Convert::Color>, L<http://www.hsluv.org/> |
1f72b051 MG |
98 | |
99 | =head1 AUTHOR | |
100 | ||
101 | Marius Gavrilescu, E<lt>marius@ieval.roE<gt> | |
102 | ||
103 | =head1 COPYRIGHT AND LICENSE | |
104 | ||
2f15aa62 | 105 | Copyright (C) 2015-2017 by Marius Gavrilescu |
1f72b051 MG |
106 | |
107 | This library is free software; you can redistribute it and/or modify | |
108 | it under the same terms as Perl itself, either Perl version 5.20.2 or, | |
109 | at your option, any later version of Perl 5 you may have available. | |
110 | ||
111 | ||
112 | =cut |