1 package Convert
::Color
::XYZ
;
6 use parent qw
/Convert::Color/;
8 use Convert
::Color
::RGB
;
9 use List
::Util qw
/sum/;
11 our $VERSION = '0.001';
13 use constant
+{ ## no critic (Capitalization)
14 MAT_R
=> [ 3.240969941904521, -1.537383177570093, -0.498610760293 ],
15 MAT_G
=> [ -0.96924363628087, 1.87596750150772, 0.041555057407175 ],
16 MAT_B
=> [ 0.055630079696993, -0.20397695888897, 1.056971514242878 ],
18 IMAT_X
=> [ 0.41239079926595, 0.35758433938387, 0.18048078840183 ],
19 IMAT_Y
=> [ 0.21263900587151, 0.71516867876775, 0.072192315360733 ],
20 IMAT_Z
=> [ 0.019330818715591, 0.11919477979462, 0.95053215224966 ],
23 __PACKAGE__
->register_color_space('xyz');
26 my ($class, $x, $y, $z) = @_;
27 ($x, $y, $z) = split /,/s, $x unless defined $y;
28 bless [$x, $y, $z], $class
39 sum
map { $x->[$_] * $y->[$_] } 0 .. $#{$x}
44 $c <= 0.0031308 ?
12.92 * $c : 1.055 * $c ** (1 / 2.4) - 0.055
49 $c <= 0.04045 ?
$c / 12.92 : (($c + 0.055) / 1.055) ** 2.4
54 map { _from_linear _dot_product
$_, $self } MAT_R
, MAT_G
, MAT_B
;
59 my $vector = [map { _to_linear
$_ } @_];
60 $class->new(map { _dot_product
$_, $vector } IMAT_X
, IMAT_Y
, IMAT_Z
)
70 Convert::Color::XYZ - a color value in the CIE 1931 XYZ color space
74 use Convert::Color::XYZ;
75 my $red = Convert::Color::XYZ->new(0.41239, 0.21264, 0.01933);
76 my $green = Convert::Color::XYZ->new('0.35758,0.71517,0.11919');
79 my $blue = Convert::Color->new('xyz:0.18048,0.07219,0.95053');
81 say $red->X; # 0.41239
82 say $red->Y; # 0.21264
83 say $red->Z; # 0.01933
84 say join ',', $blue->xyz; # 0.18048,0.07219,0.95053
88 Objects of this class represent colors in the CIE 1931 XYZ color space.
94 =item Convert::Color::XYZ->B<new>(I<$x>, I<$y>, I<$z>)
96 Construct a color from its components.
98 =item Convert::Color::XYZ->B<new>(I<"$x,$y,$z">)
100 Construct a color from a string. The string should contain the three
101 components, separated by commas.
109 Accessors for the three components of the color.
113 Returns the three components as a list.
123 Marius Gavrilescu, E<lt>marius@ieval.roE<gt>
125 =head1 COPYRIGHT AND LICENSE
127 Copyright (C) 2015 by Marius Gavrilescu
129 This library is free software; you can redistribute it and/or modify
130 it under the same terms as Perl itself, either Perl version 5.20.2 or,
131 at your option, any later version of Perl 5 you may have available.