line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Convert::Color::LUV; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
14
|
use 5.008009; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
21
|
|
6
|
1
|
|
|
1
|
|
4
|
use parent qw/Convert::Color/; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
4
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
44
|
use Convert::Color::XYZ; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
58
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.002'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use constant +{ ## no critic (Capitalization) |
13
|
1
|
|
|
|
|
170
|
KAPPA => (29/3) ** 3, |
14
|
|
|
|
|
|
|
EPS => (6/29) ** 3, |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
REF_X => 3127/3290, |
17
|
|
|
|
|
|
|
REF_Z => 3583/3290, |
18
|
1
|
|
|
1
|
|
5
|
}; |
|
1
|
|
|
|
|
2
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use constant +{ ## no critic (Capitalization) |
21
|
1
|
|
|
|
|
497
|
REF_U => 4 * REF_X / (REF_X + 15 + 3 * REF_Z), |
22
|
|
|
|
|
|
|
REF_V => 9 / (REF_X + 15 + 3 * REF_Z), |
23
|
1
|
|
|
1
|
|
8
|
}; |
|
1
|
|
|
|
|
1
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
__PACKAGE__->register_color_space('luv'); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new { |
28
|
16384
|
|
|
16384
|
1
|
17957
|
my ($class, $l, $u, $v) = @_; |
29
|
16384
|
50
|
|
|
|
23742
|
($l, $u, $v) = split /,/s, $l unless defined $u; |
30
|
16384
|
|
|
|
|
73035
|
bless [$l, $u, $v], $class |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
0
|
1
|
0
|
sub L { shift->[0] } |
34
|
0
|
|
|
0
|
1
|
0
|
sub u { shift->[1] } |
35
|
0
|
|
|
0
|
1
|
0
|
sub v { shift->[2] } |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
0
|
1
|
0
|
sub luv { @{$_[0]} } |
|
0
|
|
|
|
|
0
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _y_to_l { |
40
|
16384
|
|
|
16384
|
|
13912
|
my ($y) = @_; |
41
|
16384
|
100
|
|
|
|
43716
|
$y <= EPS ? $y * KAPPA : 116 * ($y ** (1/3)) - 16 |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub _l_to_y { |
45
|
0
|
|
|
0
|
|
0
|
my ($l) = @_; |
46
|
0
|
0
|
|
|
|
0
|
$l <= 8 ? $l / KAPPA : (($l + 16) / 116) ** 3 |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub convert_to_xyz { |
50
|
0
|
|
|
0
|
0
|
0
|
my ($self) = @_; |
51
|
0
|
|
|
|
|
0
|
my ($l, $u, $v) = @$self; |
52
|
0
|
0
|
|
|
|
0
|
return Convert::Color::XYZ->new(0, 0, 0) unless $l; |
53
|
0
|
|
|
|
|
0
|
my $var_u = $u / (13 * $l) + REF_U; |
54
|
0
|
|
|
|
|
0
|
my $var_v = $v / (13 * $l) + REF_V; |
55
|
0
|
|
|
|
|
0
|
my $y = _l_to_y $l; |
56
|
0
|
|
|
|
|
0
|
my $x = 9 * $y * $var_u / (4 * $var_v); |
57
|
0
|
|
|
|
|
0
|
my $z = (9 * $y - (14 * $var_v * $y) - ($var_v * $x)) / (3 * $var_v); |
58
|
0
|
|
|
|
|
0
|
Convert::Color::XYZ->new($x, $y, $z) |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub new_from_xyz { |
62
|
16384
|
|
|
16384
|
0
|
16950
|
my ($class, $xyz) = @_; |
63
|
16384
|
|
|
|
|
20147
|
my ($x, $y, $z) = @$xyz; |
64
|
16384
|
|
|
|
|
21702
|
my $l = _y_to_l $y; |
65
|
16384
|
100
|
|
|
|
27836
|
return $class->new(0, 0, 0) unless $l; |
66
|
16380
|
|
|
|
|
25643
|
my $var_u = (4 * $x) / ($x + 15 * $y + 3 * $z); |
67
|
16380
|
|
|
|
|
18957
|
my $var_v = (9 * $y) / ($x + 15 * $y + 3 * $z); |
68
|
16380
|
|
|
|
|
16782
|
my $u = 13 * $l * ($var_u - REF_U); |
69
|
16380
|
|
|
|
|
15473
|
my $v = 13 * $l * ($var_v - REF_V); |
70
|
16380
|
|
|
|
|
25949
|
$class->new($l, $u, $v) |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
0
|
1
|
0
|
sub rgb { shift->convert_to_xyz->rgb } |
74
|
16384
|
|
|
16384
|
0
|
1390192
|
sub new_rgb { shift->new_from_xyz(Convert::Color::XYZ->new_rgb(@_)) } |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
__END__ |