Color/YUV.pm

filter: Statementstmt 93.9% 31 / 33 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 3 / 3 totaltotal 90.2% 46 / 51 SCAR 16.2
CC
5
Cov
88%
equal_to
5.6
BEGIN
1.0
BEGIN
1.0
CRAP 5.0
« Color/YIQ.pm ↑ Summary Color.pm »
1 package Graphics::Color::YUV;
2 1 $Graphics::Color::YUV::VERSION = '0.30';
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use MooseX::Aliases;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 extends qw(Graphics::Color);
7  
8 # ABSTRACT: YUV color space
9  
10 1 ▶use Graphics::Color::Types qw(NumberOneOrLess);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 1 has 'luma' => (
14 is => 'rw',
15 isa => NumberOneOrLess,
16 default => 0,
17 alias => 'y'
18 );
19  
20  
21 1 has 'blue_luminance' => (
22 is => 'rw',
23 isa => NumberOneOrLess,
24 default => 0,
25 alias => 'u'
26 );
27  
28  
29 1 has 'red_luminance' => (
30 is => 'rw',
31 isa => NumberOneOrLess,
32 default => 0,
33 alias => 'v'
34 );
35  
36  
37 1 has 'name' => ( is => 'rw', isa => 'Str' );
38  
39  
40 sub as_string {
41 1 ▶ my ($self) = @_;
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
42  
43 1 return sprintf('%s,%s,%s',
44 $self->luma, $self->blue_luminance, $self->red_luminance
45 );
46 }
47  
48  
49 sub as_array {
50 1 ▶ my ($self) = @_;
Subroutine as_array: called CC=1 SCAR=0.0
Pod documented
51  
52 1 return ($self->luma, $self->blue_luminance, $self->red_luminance);
53 }
54  
55  
56 sub equal_to {
57 2 ▶ my ($self, $other) = @_;
Subroutine equal_to: called CC=5 SCAR=17.3
Pod documented
58  
59 2 ▶ return 0 unless defined($other);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $other 0 2 2
60  
61 2 ▶ unless($self->luma == $other->luma) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->luma == $other->luma) 1 1 2
62 1 return 0;
63 }
64 1 ▶ unless($self->blue_luminance == $other->blue_luminance) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->blue_luminance == $other->blue_luminance) 0 1 1
65 0 return 0;
66 }
67 1 ▶ unless($self->red_luminance == $other->red_luminance) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->red_luminance == $other->red_luminance) 0 1 1
68 0 return 0;
69 }
70  
71 1 return 1;
72 }
73  
74  
75 # TODO RGB Conversion
76 # OLD STYLE : Y' = 0.299R + 0.587G + 0.114B
77 # NEW STYLE: Y' = 0.2125R + 0.7154G + 0.0721B
78 # U = B - Y'
79 # V = R - Y'
80 #
81 # http://www.fourcc.org/fccyvrgb.php
82  
83 1 __PACKAGE__->meta->make_immutable;
84  
85 1 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
86 1 1;
87  
88 __END__
89  
90 =pod
91  
92 =head1 NAME
93  
94 Graphics::Color::YUV - YUV color space
95  
96 =head1 VERSION
97  
98 version 0.30
99  
100 =head1 SYNOPSIS
101  
102 use Graphics::Color::YUV;
103  
104 my $color = Graphics::Color::YUV->new({
105 luma => .5,
106 blue_luminance => .5,
107 red_luminance => .25,
108 });
109  
110 =head1 DESCRIPTION
111  
112 Graphics::Color::YUV represents a Color in an Y'UV color space.
113  
114 =head1 ATTRIBUTES
115  
116 =head2 luma
117  
118 =head2 y
119  
120 Set/Get the luma (Y') component of this Color. Aliased to y.
121  
122 =head2 blue_luminance
123  
124 =head2 u
125  
126 Set/Get the blue_luminance component of this Color. Aliased to u.
127  
128 =head2 red_luminance
129  
130 =head2 v
131  
132 Set/Get the red_luminance component of this Color. Aliased to v.
133  
134 =head1 METHODS
135  
136 =head2 name
137  
138 Get the name of this color. Only valid if the color was created by name.
139  
140 =head2 as_string
141  
142 Get a string version of this Color in the form of:
143 LUMA,BLUE_LUMINENCE,RED_LUMINANCE
144  
145 =head2 as_array
146  
147 Get the YUV values as an array
148  
149 =head2 equal_to
150  
151 Compares this color to the provided one. Returns 1 if true, else 0;
152  
153 =head2 not_equal_to
154  
155 The opposite of equal_to.
156  
157 =head1 AUTHOR
158  
159 Cory G Watson <gphat@cpan.org>
160  
161 =head1 COPYRIGHT AND LICENSE
162  
163 This software is copyright (c) 2014 by Cold Hard Code, LLC.
164  
165 This is free software; you can redistribute it and/or modify it under
166 the same terms as the Perl 5 programming language system itself.
167  
168 =cut
« Color/YIQ.pm ↑ Summary Color.pm »