Color/Values.pm

filter: Statementstmt 100% 62 / 62 Branchbran 77.7% 28 / 36 Conditioncond 93.3% 14 / 15 MC/DCmcdc 87.5% 7 / 8 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 7 totaltotal 87.7% 122 / 139 CC 24 SCAR 16.5
CC
24
Cov
92%
shaped
8.1
new_from_any_input
6.0
new_from_tuple
6.0
CRAP 5.2
« Color/Space/Instance/HSB.pm ↑ Summary Color/Space/Instance/HSL.pm »
1  
2 # read only store of a single color: name + values in default and original space
3  
4 package Graphics::Toolkit::Color::Values;
5 10 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use Graphics::Toolkit::Color::Name;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use Graphics::Toolkit::Color::Space::Hub;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 10 my $RGB = Graphics::Toolkit::Color::Space::Hub::default_space();
11  
12 #### constructor #######################################################
13 172 ▶sub new_from_any_input { # values => %space_name => tuple , ~origin_space, ~color_name
Subroutine new_from_any_input: called CC=6 SCAR=17.9
Pod undocumented
14 172 my ($pkg, $color_def, $space_name, $range_def, $raw) = @_;
15 172 ▶ return "Can not create color value object without color definition!" unless defined $color_def;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $color_def 2 170 172
16 170 ▶ if (not ref $color_def) { # try to resolve color name
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $color_def) 74 96 170
17 74 my $rgb = Graphics::Toolkit::Color::Name::get_values( $color_def );
18 74 ▶ if (ref $rgb){
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rgb) 43 31 74
19 43 $rgb = $RGB->clamp( $RGB->normalize( $rgb ), 'normal' );
20 43 return bless { color_name => $color_def, rgb_tuple => $rgb, source_tuple => '', source_space_name => ''};
21 }
22 }
23 127 ▶ my ($tuple, $found_space_name, $format) = (defined $space_name)
Branch: 1 branch
BranchTrueFalseTotal
defined $space_name ? : 0 127 127
24 ? Graphics::Toolkit::Color::Space::Hub::deformat( $color_def, $space_name )
25 : Graphics::Toolkit::Color::Space::Hub::deformat_search( $color_def );
26 127 ▶ return $tuple unless ref $tuple;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tuple 49 78 127
27 78 new_from_tuple( '', $tuple, $found_space_name, $range_def, $raw);
28 }
29 522 ▶sub new_from_tuple { #
Subroutine new_from_tuple: called CC=6 SCAR=17.9
Pod undocumented
30 522 my ($pkg, $tuple, $space_name, $range_def, $raw) = @_;
31 522 my $color_space = Graphics::Toolkit::Color::Space::Hub::try_get_space( $space_name );
32 522 ▶ return $color_space unless ref $color_space;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $color_space 0 522 522
33 522 ▶ return "Need ARRAY of ".$color_space->axis_count." ".$color_space->name." values as first argument!"
Branch: 1 branch
BranchTrueFalseTotal
unless $color_space->is_value_tuple($tuple) 1 521 522
34 unless $color_space->is_value_tuple( $tuple );
35 521 $tuple = $color_space->normalize( $tuple, $range_def );
36 521 ▶ $tuple = $color_space->clamp( $tuple, 'normal' ) unless defined $raw and $raw;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $raw and $raw 507 14 521
Condition100%3/3
defined $raw and $raw
!ll&&!rl&&r
4881914
MC/DC100%2/2
defined $raw and $raw
defined $raw $raw
Truth table100%3/3
A and B
A= defined $rawB= $raw
ABresult
0X0
100
111
37  
38 521 my $source_tuple = '';
39 521 my $source_space_name = '';
40 521 ▶ if ($color_space->name ne $RGB->name){ # convert into RGB if needed
Branch: 1 branch
BranchTrueFalseTotal
if ($color_space->name ne $RGB->name) 189 332 521
41 189 $source_tuple = $tuple;
42 189 $source_space_name = $color_space->name;
43 189 $tuple = Graphics::Toolkit::Color::Space::Hub::deconvert( $tuple, $color_space->name, 'normal' );
44 }
45  
46 521 my $name = Graphics::Toolkit::Color::Name::from_values( $RGB->round( $RGB->denormalize( $tuple ) ) );
47 521 bless { rgb_tuple => $tuple, source_tuple => $source_tuple, source_space_name => $source_space_name, color_name => $name };
48 }
49  
50 #### getter ############################################################
51 444 ▶sub normalized { # normalized (0..1) value tuple in any color space
Subroutine normalized: called CC=1 SCAR=0.0
Pod undocumented
52 444 my ($self, $space_name) = @_;
53 Graphics::Toolkit::Color::Space::Hub::convert(
54 444 $self->{'rgb_tuple'}, $space_name, 'normal', $self->{'source_tuple'}, $self->{'source_space_name'},
55 );
56 }
57 360 ▶sub shaped { # in any color space, range and precision
Subroutine shaped: called CC=8 SCAR=20.9
Pod undocumented
58 360 my ($self, $space_name, $range_def, $precision_def, $raw) = @_;
59 360 my $color_space = Graphics::Toolkit::Color::Space::Hub::try_get_space( $space_name );
60 360 ▶ return $color_space unless ref $color_space;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $color_space 0 360 360
61 360 my $tuple = $self->normalized( $color_space->name );
62 360 ▶ return $tuple if not ref $tuple;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tuple 0 360 360
63 360 $tuple = $color_space->denormalize( $tuple, $range_def );
64 360 ▶ $tuple = $color_space->clamp( $tuple, $range_def ) unless $raw;
Branch: 1 branch
BranchTrueFalseTotal
unless $raw 359 1 360
65 360 ▶ $tuple = $color_space->round( $tuple, $precision_def ) unless ($raw and not defined $precision_def)
Branch: 1 branch
BranchTrueFalseTotal
unless $raw and not defined $precision_def or defined $range_def and not defined $precision_def 349 11 360
Condition88%8/9
$raw and not defined $precision_def or defined $range_def and not defined $precision_def
l!l&&r!l&&!r
110349
$raw and not defined $precision_def
!ll&&!rl&&r
35901
defined $range_def and not defined $precision_def
!ll&&!rl&&r
347210
MC/DC75%3/4
$raw and not defined $precision_def or defined $range_def and not defined $precision_def
$raw not defined $precision_def defined $range_def not defined $precision_def
Truth table57%4/7
A and not(B) or C and not(D)
A= $rawB= not defined $precision_defC= defined $range_defD= not defined $precision_def
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
66 or (defined $range_def and not defined $precision_def);
67 360 return $tuple;
68 }
69 92 ▶sub formatted { # in shape values in any format # _ -- ~space, @~|~format, @~|~range, @~|~suffix --> @|%|$
Subroutine formatted: called CC=3 SCAR=11.2
Pod undocumented
70 92 my ($self, $space_name, $format_name, $suffix_def, $range_def, $precision_def, $raw) = @_;
71 92 my $color_space = Graphics::Toolkit::Color::Space::Hub::try_get_space( $space_name );
72 92 ▶ return \$color_space unless ref $color_space;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $color_space 0 92 92
73 92 my $tuple = $self->shaped( $color_space->name, $range_def, $precision_def, $raw );
74 92 ▶ return \$tuple unless ref $tuple;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tuple 0 92 92
75 92 return $color_space->format( $tuple, $format_name, $suffix_def );
76 }
77 72 ▶sub name { $_[0]->{'color_name'} }
Subroutine name: called CC=1 SCAR=0.0
Pod undocumented
78  
79 16 ▶sub is_in_gamut {
Subroutine is_in_gamut: called CC=5 SCAR=16.2
Pod undocumented
80 16 my ($self, $space_name) = @_;
81 16 ▶ $space_name = $self->{'source_space_name'} if not defined $space_name and $self->{'source_space_name'};
Branch: 1 branch
BranchTrueFalseTotal
if not defined $space_name and $self->{"source_space_name"} 4 12 16
Condition100%3/3
not defined $space_name and $self->{"source_space_name"}
!ll&&!rl&&r
754
MC/DC100%2/2
not defined $space_name and $self->{"source_space_name"}
not defined $space_name $self->{"source_space_name"}
Truth table100%3/3
not(A) and B
A= not defined $space_nameB= $self->{"source_space_name"}
ABresult
0X0
100
111
82 16 my $color_space = Graphics::Toolkit::Color::Space::Hub::try_get_space( $space_name ); # default to RGB
83 16 ▶ return 0 unless ref $color_space;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $color_space 0 16 16
84 16 my $tuple = $self->normalized( $space_name );
85 16 ▶ return 0 unless ref $tuple;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tuple 0 16 16
86 16 return $color_space->is_in_linear_bounds( $tuple, 'normal' );
87 }
88  
89 10 1;
« Color/Space/Instance/HSB.pm ↑ Summary Color/Space/Instance/HSL.pm »