]>
iEval git - convert-color-husl.git/blob - Color/LUV.pm
1 package Convert
::Color
::LUV
;
6 use parent qw
/Convert::Color/;
8 use Convert
::Color
::XYZ
;
10 our $VERSION = '0.001';
12 use constant
+{ ## no critic (Capitalization)
20 use constant
+{ ## no critic (Capitalization)
21 REF_U
=> 4 * REF_X
/ (REF_X
+ 15 + 3 * REF_Z
),
22 REF_V
=> 9 / (REF_X
+ 15 + 3 * REF_Z
),
25 __PACKAGE__
->register_color_space('luv');
28 my ($class, $l, $u, $v) = @_;
29 ($l, $u, $v) = split /,/s, $l unless defined $u;
30 bless [$l, $u, $v], $class
41 $y <= EPS ?
$y * KAPPA
: 116 * ($y ** (1/3)) - 16
46 $l <= 8 ?
$l / KAPPA : (($l + 16) / 116) ** 3
51 my ($l, $u, $v) = @
$self;
52 return Convert
::Color
::XYZ
->new(0, 0, 0) unless $l;
53 my $var_u = $u / (13 * $l) + REF_U
;
54 my $var_v = $v / (13 * $l) + REF_V
;
56 my $x = 9 * $y * $var_u / (4 * $var_v);
57 my $z = (9 * $y - (14 * $var_v * $y) - ($var_v * $x)) / (3 * $var_v);
58 Convert
::Color
::XYZ
->new($x, $y, $z)
62 my ($class, $xyz) = @_;
63 my ($x, $y, $z) = @
$xyz;
65 return $class->new(0, 0, 0) unless $l;
66 my $var_u = (4 * $x) / ($x + 15 * $y + 3 * $z);
67 my $var_v = (9 * $y) / ($x + 15 * $y + 3 * $z);
68 my $u = 13 * $l * ($var_u - REF_U
);
69 my $v = 13 * $l * ($var_v - REF_V
);
70 $class->new($l, $u, $v)
73 sub rgb
{ shift->convert_to_xyz->rgb }
74 sub new_rgb
{ shift->new_from_xyz(Convert
::Color
::XYZ
->new_rgb(@_)) }
83 Convert::Color::LUV - a color value in the CIE 1976 (L*, u*, v*) color space
87 use Convert::Color::LUV;
88 my $red = Convert::Color::LUV->new(53.23711, 175.00982, 37.76509);
89 my $green = Convert::Color::LUV->new('87.73552,-83.06712,107.41811');
92 my $blue = Convert::Color->new('luv:32.30087,-9.40241,-130.35109');
94 say $red->L; # 53.23711
95 say $red->u; # 175.00982
96 say $red->v; # 37.76509
97 say join ',', $blue->luv; # 32.30087,-9.40241,-130.35109
101 Objects of this class represent colors in the CIE 1976 (L*, u*, v*) color space.
107 =item Convert::Color::LUV->B<new>(I<$l>, I<$u>, I<$v>)
109 Construct a color from its components.
111 =item Convert::Color::LUV->B<new>(I<"$l,$u,$v">)
113 Construct a color from a string. The string should contain the three
114 components, separated by commas.
122 Accessors for the three components of the color.
126 Returns the three components as a list.
136 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
138 =head1 COPYRIGHT AND LICENSE
140 Copyright (C) 2015 by Marius Gavrilescu
142 This library is free software; you can redistribute it and/or modify
143 it under the same terms as Perl itself, either Perl version 5.20.2 or,
144 at your option, any later version of Perl 5 you may have available.
This page took 0.053443 seconds and 4 git commands to generate.