Color/Space/Hub.pm

filter: Statementstmt 94.7% 162 / 171 Branchbran 73.5% 100 / 136 Conditioncond 57.3% 43 / 75 MC/DCmcdc 33.3% 16 / 48 Subroutinesub 100% 16 / 16 Podpod 0.0% 0 / 14 totaltotal 73.2% 337 / 460 CC 97 SCAR 34.1
CC
97
Cov
80%
deconvert
83.0
convert
26.3
add_space
13.7
CRAP 30.3
↑ Summary Color/Space.pm »
1  
2 # store all color space objects, to convert check, convert and measure color values
3  
4 package Graphics::Toolkit::Color::Space::Hub;
5 15 ▶use v5.12;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 #### internal space loading ############################################
9 15 our $default_space_name = 'RGB';
10 15 our @load_order = ($default_space_name,
11 qw/RGBLinear CMY CMYK HSL HSV HSB HWB NCol YIQ YPbPr/,
12 qw/CIEXYZ CIERGB CIELAB CIELUV CIELCHab CIELCHuv HunterLAB/,
13 qw/AppleRGB AdobeRGB ProPhotoRGB WideGamutRGB/,
14 qw/DisplayP3Linear DisplayP3 DCIP3Linear DCIP3 Rec709 Rec2020/,
15 qw/OKLAB OKLCH OKHSL OKHSV OKHWB/);
16 15 add_space( require "Graphics/Toolkit/Color/Space/Instance/$_.pm" ) for @load_order;
17 15 my ($default_space, @search_order, %space_obj, %next_conversion_node, %space_family);
18  
19 #### space API #########################################################
20 146 ▶sub is_space_name {
Subroutine is_space_name: called CC=2 SCAR=6.9
Pod undocumented
21 146 ▶ (ref get_space( $default_space->normalize_name( $_[0] ))) ? 1 : 0 }
Branch: 1 branch
BranchTrueFalseTotal
ref get_space($default_space->normalize_name($_[0])) ? : 144 2 146
22 11 ▶sub all_space_names { sort keys %space_obj }
Subroutine all_space_names: called CC=1 SCAR=0.0
Pod undocumented
23 18 ▶sub default_space_name { $default_space_name }
Subroutine default_space_name: called CC=1 SCAR=0.0
Pod undocumented
24 10512 ▶sub default_space { $default_space }
Subroutine default_space: called CC=1 SCAR=0.0
Pod undocumented
25 7550 ▶sub get_space { # takes only normal names or alias names
Subroutine get_space: called CC=4 SCAR=13.9
Pod undocumented
26 7550 my $name = shift;
27 7550 ▶ return unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 2 7548 7550
28 7548 ▶ $name = default_space()->normalize_name( $name ) if ref $default_space;
Branch: 1 branch
BranchTrueFalseTotal
if ref $default_space 7533 15 7548
29 7548 ▶ exists $space_obj{ $name } ? $space_obj{ $name } : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $space_obj{$name} ? : 6801 747 7548
30 }
31 3026 ▶sub try_get_space { # takes any name variant and defaults to $default_space_name
Subroutine try_get_space: called CC=5 SCAR=16.2
Pod undocumented
32 3026 ▶ my $name = shift || $default_space_name;
Condition66%2/3
shift() || $Graphics::Toolkit::Color::Space::Hub::default_space_name
l!l&&r!l&&!r
22467800
MC/DC0%0/2
shift() || $Graphics::Toolkit::Color::Space::Hub::default_space_name
shift() $Graphics::Toolkit::Color::Space::Hub::default_space_name
Truth table66%2/3
A || B
A= shift()B= $Graphics::Toolkit::Color::Space::Hub::default_space_name
ABresult
1X1
011
000
33 3026 ▶ return $name if ref $name eq 'Graphics::Toolkit::Color::Space' and is_space_name( $name->name );
Branch: 1 branch
BranchTrueFalseTotal
if ref $name eq "Graphics::Toolkit::Color::Space" and is_space_name($name->name) 60 2966 3026
Condition66%2/3
ref $name eq "Graphics::Toolkit::Color::Space" and is_space_name($name->name)
!ll&&!rl&&r
2966060
MC/DC50%1/2
ref $name eq "Graphics::Toolkit::Color::Space" and is_space_name($name->name)
ref $name eq "Graphics::Toolkit::Color::Space" is_space_name($name->name)
Truth table66%2/3
A and B
A= ref $name eq "Graphics::Toolkit::Color::Space"B= is_space_name($name->name)
ABresult
0X0
100
111
34 2966 $name = default_space()->normalize_name( $name );
35 2966 my $space = get_space( $name );
36 2966 ▶ return (ref $space) ? $space
Branch: 1 branch
BranchTrueFalseTotal
ref $space ? : 2958 8 2966
37 : "$name is an unknown color space, try one of: ".(join ', ', all_space_names());
38 }
39  
40 496 ▶sub add_space {
Subroutine add_space: called CC=13 SCAR=26.1
Pod undocumented
41 496 my $space = shift;
42 496 ▶ return 'add_space got no Graphics::Toolkit::Color::Space object as argument' if ref $space ne 'Graphics::Toolkit::Color::Space';
Branch: 1 branch
BranchTrueFalseTotal
if ref $space ne "Graphics::Toolkit::Color::Space" 0 496 496
43 496 my $name = $space->name;
44 496 my $alias = $space->name('alias');
45 496 ▶ return "can not add color space object without a name" unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 496 496
46 496 ▶ return "color space name $name is already taken" if ref get_space( $name );
Branch: 1 branch
BranchTrueFalseTotal
if ref get_space($name) 0 496 496
47 496 ▶ if ($name eq $default_space_name) { # there is no parent
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq $Graphics::Toolkit::Color::Space::Hub::default_space_name) { } 15 481 496
48 15 $default_space = $space;
49 } else {
50 481 my $conversion_parent = $space->conversion_tree_parent;
51 481 ▶ return "can not add color space $name, it has no converter" unless defined $conversion_parent and $conversion_parent;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $conversion_parent and $conversion_parent 0 481 481
Condition33%1/3
defined $conversion_parent and $conversion_parent
!ll&&!rl&&r
00481
MC/DC0%0/2
defined $conversion_parent and $conversion_parent
defined $conversion_parent $conversion_parent
Truth table33%1/3
A and B
A= defined $conversion_parentB= $conversion_parent
ABresult
0X0
100
111
52 481 $conversion_parent = $space->normalize_name( $conversion_parent );
53 481 my $parent_space = get_space( $conversion_parent );
54 481 ▶ return "color space $name does only convert into '$conversion_parent', which is no known color space" unless ref $parent_space;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $parent_space 0 481 481
55 481 my $parent_name = $parent_space->name;
56 481 $next_conversion_node{ $parent_name }{ $name } = $name;
57 481 ▶ unless ($parent_name eq $default_space_name){
Branch: 1 branch
BranchTrueFalseTotal
unless ($parent_name eq $Graphics::Toolkit::Color::Space::Hub::default_space_name) 330 151 481
58 330 my $upper_space_name = $default_space_name;
59 330 ▶ while ($upper_space_name ne $parent_name){
Branch: 1 branch
BranchTrueFalseTotal
if ($upper_space_name ne $parent_name) 660 330 990
60 $upper_space_name = $next_conversion_node{ $upper_space_name }{ $name }
61 660 = $next_conversion_node{ $upper_space_name }{ $parent_name };
62 }
63 }
64 }
65 496 push @search_order, $name;
66 496 $space_obj{ $name } = $space;
67 496 ▶ $space_obj{ $alias } = $space if $alias and not ref get_space( $alias );
Branch: 1 branch
BranchTrueFalseTotal
if $alias and not ref get_space($alias) 240 256 496
Condition66%2/3
$alias and not ref get_space($alias)
!ll&&!rl&&r
2560240
MC/DC50%1/2
$alias and not ref get_space($alias)
$alias not ref get_space($alias)
Truth table66%2/3
A and not(B)
A= $aliasB= not ref get_space($alias)
ABresult
0X0
100
111
68 496 ▶ push @{$space_family{ $space->family }}, $space if $space->family;
Branch: 1 branch
BranchTrueFalseTotal
if $space->family 465 31 496
69 496 return 1;
70 }
71 3 ▶sub remove_space {
Subroutine remove_space: called CC=8 SCAR=21.6
Pod undocumented
72 3 my $name = shift;
73 3 ▶ return "need name of color space as argument in order to remove the space" unless defined $name and $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and $name 0 3 3
Condition33%1/3
defined $name and $name
!ll&&!rl&&r
003
MC/DC0%0/2
defined $name and $name
defined $name $name
Truth table33%1/3
A and B
A= defined $nameB= $name
ABresult
0X0
100
111
74 3 my $space = try_get_space( $name );
75 3 ▶ return "can not remove unknown color space: $name" if not ref $space;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $space 2 1 3
76 1 ▶ return "can not remove default color space: $name" if $space->name eq $default_space_name;
Branch: 1 branch
BranchTrueFalseTotal
if $space->name eq $Graphics::Toolkit::Color::Space::Hub::default_space_name 0 1 1
77  
78 1 $name = $space->name;
79 1 my $upper_space_name = $default_space_name;
80 1 ▶ while ($upper_space_name ne $name){
Branch: 1 branch
BranchTrueFalseTotal
if ($upper_space_name ne $name) 1 1 2
81 1 $upper_space_name = delete $next_conversion_node{ $upper_space_name }{ $name };
82 }
83 1 ▶ delete $space_family{ $space->family } if $space->family;
Branch: 1 branch
BranchTrueFalseTotal
if $space->family 0 1 1
84 1 ▶ delete $space_obj{ $space->name('alias') } if $space->name('alias');
Branch: 1 branch
BranchTrueFalseTotal
if $space->name("alias") 0 1 1
85 1 delete $space_obj{ $name };
86 }
87  
88 #### tuple API ##########################################################
89 530 ▶sub convert { # normalized RGB tuple, ~space_name --> |normalized tuple in wanted space
Subroutine convert: called CC=24 SCAR=32.7
Pod undocumented
90 530 my ($tuple, $target_space_name, $want_result_normalized, $source_tuple, $source_space_name) = @_;
91 530 ▶ return "need an ARRAY ref with 3 normalized RGB values as first argument in order to convert them"
Branch: 1 branch
BranchTrueFalseTotal
unless $default_space->is_number_tuple($tuple) 3 527 530
92 unless $default_space->is_number_tuple( $tuple );
93 527 my $target_space = try_get_space( $target_space_name );
94 527 ▶ return "got unknown space name: '$target_space_name' as second argument, can not convert " unless ref $target_space;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $target_space 1 526 527
95 526 my $source_space = try_get_space( $source_space_name );
96 526 ▶ return "did not found target color space !'$target_space_name'" unless ref $target_space;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $target_space 0 526 526
97 526 ▶ if ($source_space_name xor $source_tuple){
Branch: 2 branches
BranchTrueFalseTotal
if ($source_space_name xor $source_tuple) { } 0 526 526
elsif ($source_space_name and $source_tuple) { } 72 908 980
Condition50%2/4
$source_space_name xor $source_tuple
l&&rl&&!r!l&&r!l&&!r
7200454
MC/DC0%0/2
$source_space_name xor $source_tuple
$source_space_name $source_tuple
Truth table50%2/4
A xor B
A= $source_space_nameB= $source_tuple
ABresult
110
101
011
000
98 0 return "arguments source_space_name and source_values (nr. 4 and 5) have to be provided both or none of them";
99 ▶ } elsif ($source_space_name and $source_tuple) {
Condition66%2/3
$source_space_name and $source_tuple
!ll&&!rl&&r
454072
MC/DC50%1/2
$source_space_name and $source_tuple
$source_space_name $source_tuple
Truth table66%2/3
A and B
A= $source_space_nameB= $source_tuple
ABresult
0X0
100
111
100 72 ▶ return "got unknown source color space $source_space_name" if not ref $source_space;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $source_space 0 72 72
101 72 ▶ return "argument source_values has to be a tuple, if provided" unless $source_space->is_number_tuple( $source_tuple );
Branch: 1 branch
BranchTrueFalseTotal
unless $source_space->is_number_tuple($source_tuple) 0 72 72
102 }
103  
104 526 $tuple = [@$tuple]; # unwrap ref to avoid spooky action
105 526 my $current_space_name = $default_space_name; # we start in RGB
106 526 $target_space_name = $target_space->name; # use only normalized name
107 526 ▶ $want_result_normalized //= 0; # normal flags to start state
Condition100%2/2
$want_result_normalized //= 0
l!l
50521
MC/DC100%1/1
$want_result_normalized //= 0
$want_result_normalized
Truth table100%2/2
A
A= $want_result_normalized
Aresult
11
00
108 526 my $tuple_is_normal = 1;
109  
110 526 ▶ while ($current_space_name ne $target_space_name){
Branch: 1 branch
BranchTrueFalseTotal
if ($current_space_name ne $target_space_name) 525 526 1051
111 525 my $next_space_name = $next_conversion_node{ $current_space_name }{ $target_space_name };
112 525 my $next_space = get_space( $next_space_name );
113 # replace tuple with values from constructor if possible
114 525 ▶ if (defined $source_space_name and $next_space->is_name($source_space_name)){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $source_space_name and $next_space->is_name($source_space_name)) { } 49 476 525
Condition100%3/3
defined $source_space_name and $next_space->is_name($source_space_name)
!ll&&!rl&&r
9138549
MC/DC100%2/2
defined $source_space_name and $next_space->is_name($source_space_name)
defined $source_space_name $next_space->is_name($source_space_name)
Truth table100%3/3
A and B
A= defined $source_space_nameB= $next_space->is_name($source_space_name)
ABresult
0X0
100
111
115 49 $tuple = [@$source_tuple];
116 49 $tuple_is_normal = 1;
117 } else {
118 476 my @normal_in_out = $next_space->converter_normal_states( 'from', $current_space_name );
119 476 ▶ $tuple = $next_space->normalize( $tuple ) if not $tuple_is_normal and $normal_in_out[0];
Branch: 1 branch
BranchTrueFalseTotal
if not $tuple_is_normal and $normal_in_out[0] 0 476 476
Condition33%1/3
not $tuple_is_normal and $normal_in_out[0]
!ll&&!rl&&r
47600
MC/DC0%0/2
not $tuple_is_normal and $normal_in_out[0]
not $tuple_is_normal $normal_in_out[0]
Truth table33%1/3
not(A) and B
A= not $tuple_is_normalB= $normal_in_out[0]
ABresult
0X0
100
111
120 476 ▶ $tuple = $next_space->denormalize( $tuple ) if $tuple_is_normal and not $normal_in_out[0];
Branch: 1 branch
BranchTrueFalseTotal
if $tuple_is_normal and not $normal_in_out[0] 0 476 476
Condition33%1/3
$tuple_is_normal and not $normal_in_out[0]
!ll&&!rl&&r
04760
MC/DC0%0/2
$tuple_is_normal and not $normal_in_out[0]
$tuple_is_normal not $normal_in_out[0]
Truth table33%1/3
A and not(B)
A= $tuple_is_normalB= not $normal_in_out[0]
ABresult
0X0
100
111
121 476 $tuple = $next_space->convert_from( $current_space_name, $tuple );
122 476 $tuple_is_normal = $normal_in_out[1];
123 476 ▶ if (not $tuple_is_normal and $next_space_name ne $target_space_name){
Branch: 1 branch
BranchTrueFalseTotal
if (not $tuple_is_normal and $next_space_name ne $target_space_name) 106 370 476
Condition100%3/3
not $tuple_is_normal and $next_space_name ne $target_space_name
!ll&&!rl&&r
35713106
MC/DC100%2/2
not $tuple_is_normal and $next_space_name ne $target_space_name
not $tuple_is_normal $next_space_name ne $target_space_name
Truth table100%3/3
not(A) and B
A= not $tuple_is_normalB= $next_space_name ne $target_space_name
ABresult
0X0
100
111
124 106 $tuple_is_normal = 1;
125 106 $tuple = $next_space->normalize( $tuple );
126 }
127 }
128 525 $current_space_name = $next_space_name;
129 }
130 526 ▶ $tuple = $target_space->normalize( $tuple ) if not $tuple_is_normal and $want_result_normalized;
Branch: 1 branch
BranchTrueFalseTotal
if not $tuple_is_normal and $want_result_normalized 10 516 526
Condition100%3/3
not $tuple_is_normal and $want_result_normalized
!ll&&!rl&&r
513310
MC/DC100%2/2
not $tuple_is_normal and $want_result_normalized
not $tuple_is_normal $want_result_normalized
Truth table100%3/3
not(A) and B
A= not $tuple_is_normalB= $want_result_normalized
ABresult
0X0
100
111
131 526 ▶ $tuple = $target_space->denormalize( $tuple ) if $tuple_is_normal and not $want_result_normalized;
Branch: 1 branch
BranchTrueFalseTotal
if $tuple_is_normal and not $want_result_normalized 18 508 526
Condition100%3/3
$tuple_is_normal and not $want_result_normalized
!ll&&!rl&&r
1349518
MC/DC100%2/2
$tuple_is_normal and not $want_result_normalized
$tuple_is_normal not $want_result_normalized
Truth table100%3/3
A and not(B)
A= $tuple_is_normalB= not $want_result_normalized
ABresult
0X0
100
111
132 526 return $tuple;
133 }
134 214 ▶sub deconvert { # normalized value tuple --> RGB tuple
Subroutine deconvert: called CC=28 SCAR=44.2
Pod undocumented
135 214 my ($tuple, $original_space_name, $want_result_normalized, $source_tuple, $source_space_name) = @_;
136 214 my $original_space = try_get_space( $original_space_name );
137 214 my $source_space = try_get_space( $source_space_name );
138 214 ▶ $want_result_normalized //= 0;
Condition100%2/2
$want_result_normalized //= 0
l!l
2059
MC/DC100%1/1
$want_result_normalized //= 0
$want_result_normalized
Truth table100%2/2
A
A= $want_result_normalized
Aresult
11
00
139 214 ▶ return "need a space name to convert from as second argument" unless defined $original_space_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $original_space_name 2 212 214
140 212 ▶ return "got unknown color space name as second argument" unless ref $original_space;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $original_space 2 210 212
141 210 ▶ return "need as first argument an ARRAY with valid number of normalized values from the color space ". $original_space->name
Branch: 1 branch
BranchTrueFalseTotal
unless $original_space->is_number_tuple($tuple) 0 210 210
142 unless $original_space->is_number_tuple( $tuple );
143
144 210 ▶ if ($source_space_name xor $source_tuple){
Branch: 2 branches
BranchTrueFalseTotal
if ($source_space_name xor $source_tuple) { } 0 210 210
elsif ($source_space_name and $source_tuple) { } 0 420 420
Condition25%1/4
$source_space_name xor $source_tuple
l&&rl&&!r!l&&r!l&&!r
000210
MC/DC0%0/2
$source_space_name xor $source_tuple
$source_space_name $source_tuple
Truth table25%1/4
A xor B
A= $source_space_nameB= $source_tuple
ABresult
110
101
011
000
145 0 return "arguments source_space_name and source_values (nr. 4 and 5) have to be provided both or none of them";
146 ▶ } elsif ($source_space_name and $source_tuple) {
Condition33%1/3
$source_space_name and $source_tuple
!ll&&!rl&&r
21000
MC/DC0%0/2
$source_space_name and $source_tuple
$source_space_name $source_tuple
Truth table33%1/3
A and B
A= $source_space_nameB= $source_tuple
ABresult
0X0
100
111
147 0 ▶ return "got unknown source color space $source_space_name" if not ref $source_space;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $source_space 0 0 0
148 0 ▶ return "argument source_values has to be a tuple, if provided" unless $source_space->is_number_tuple( $source_tuple );
Branch: 1 branch
BranchTrueFalseTotal
unless $source_space->is_number_tuple($source_tuple) 0 0 0
149 }
150
151 # none conversion cases
152 210 ▶ if ($original_space->name eq $default_space_name) { # nothing to convert
Branch: 1 branch
BranchTrueFalseTotal
if ($original_space->name eq $Graphics::Toolkit::Color::Space::Hub::default_space_name) 0 210 210
153 0 ▶ return ($want_result_normalized) ? $tuple : $original_space->denormalize( $tuple );
Branch: 1 branch
BranchTrueFalseTotal
$want_result_normalized ? : 0 0 0
154 }
155 210 my $current_space = $original_space;
156 210 my $tuple_is_normal = 1;
157 # actual conversion
158 210 ▶ while ($current_space->name ne $default_space_name){
Branch: 1 branch
BranchTrueFalseTotal
if ($current_space->name ne $Graphics::Toolkit::Color::Space::Hub::default_space_name) 372 210 582
159 372 my ($next_space_name, @next_options) = $current_space->conversion_tree_parent;
160 372 ▶ $next_space_name = shift @next_options while @next_options and $next_space_name ne $default_space_name;
Branch: 1 branch
BranchTrueFalseTotal
@next_options and $next_space_name ne $Graphics::Toolkit::Color::Space::Hub::default_space_name and do { $next_space_name = shift @next_options } 0 372 372
Condition33%1/3
@next_options and $next_space_name ne $Graphics::Toolkit::Color::Space::Hub::default_space_name
!ll&&!rl&&r
37200
MC/DC0%0/2
@next_options and $next_space_name ne $Graphics::Toolkit::Color::Space::Hub::default_space_name
@next_options $next_space_name ne $Graphics::Toolkit::Color::Space::Hub::default_space_name
Truth table33%1/3
A and B
A= @next_optionsB= $next_space_name ne $Graphics::Toolkit::Color::Space::Hub::default_space_name
ABresult
0X0
100
111
161 # replace tuple with values from constructor if possible
162 372 ▶ if (defined $source_space_name and $current_space->is_name( $source_space_name )){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $source_space_name and $current_space->is_name($source_space_name)) { } 0 372 372
Condition33%1/3
defined $source_space_name and $current_space->is_name($source_space_name)
!ll&&!rl&&r
37200
MC/DC0%0/2
defined $source_space_name and $current_space->is_name($source_space_name)
defined $source_space_name $current_space->is_name($source_space_name)
Truth table33%1/3
A and B
A= defined $source_space_nameB= $current_space->is_name($source_space_name)
ABresult
0X0
100
111
163 0 $tuple = [@$source_tuple];
164 0 $tuple_is_normal = 1;
165 } else {
166 372 my @normal_in_out = $current_space->converter_normal_states( 'to', $next_space_name );
167 372 ▶ $tuple = $current_space->normalize( $tuple ) if not $tuple_is_normal and $normal_in_out[0];
Branch: 1 branch
BranchTrueFalseTotal
if not $tuple_is_normal and $normal_in_out[0] 0 372 372
Condition33%1/3
not $tuple_is_normal and $normal_in_out[0]
!ll&&!rl&&r
37200
MC/DC0%0/2
not $tuple_is_normal and $normal_in_out[0]
not $tuple_is_normal $normal_in_out[0]
Truth table33%1/3
not(A) and B
A= not $tuple_is_normalB= $normal_in_out[0]
ABresult
0X0
100
111
168 372 ▶ $tuple = $current_space->denormalize( $tuple ) if $tuple_is_normal and not $normal_in_out[0];
Branch: 1 branch
BranchTrueFalseTotal
if $tuple_is_normal and not $normal_in_out[0] 75 297 372
Condition66%2/3
$tuple_is_normal and not $normal_in_out[0]
!ll&&!rl&&r
029775
MC/DC50%1/2
$tuple_is_normal and not $normal_in_out[0]
$tuple_is_normal not $normal_in_out[0]
Truth table66%2/3
A and not(B)
A= $tuple_is_normalB= not $normal_in_out[0]
ABresult
0X0
100
111
169 372 $tuple = $current_space->convert_to( $next_space_name, $tuple);
170 372 $tuple_is_normal = $normal_in_out[1];
171 372 ▶ if (not $tuple_is_normal and $current_space->name ne $default_space_name){
Branch: 1 branch
BranchTrueFalseTotal
if (not $tuple_is_normal and $current_space->name ne $Graphics::Toolkit::Color::Space::Hub::default_space_name) 0 372 372
Condition33%1/3
not $tuple_is_normal and $current_space->name ne $Graphics::Toolkit::Color::Space::Hub::default_space_name
!ll&&!rl&&r
37200
MC/DC0%0/2
not $tuple_is_normal and $current_space->name ne $Graphics::Toolkit::Color::Space::Hub::default_space_name
not $tuple_is_normal $current_space->name ne $Graphics::Toolkit::Color::Space::Hub::default_space_name
Truth table33%1/3
not(A) and B
A= not $tuple_is_normalB= $current_space->name ne $Graphics::Toolkit::Color::Space::Hub::default_space_name
ABresult
0X0
100
111
172 0 $tuple_is_normal = 1;
173 0 $tuple = $current_space->normalize( $tuple );
174 }
175 }
176 372 $current_space = get_space( $next_space_name );
177 }
178 210 ▶ $tuple = $current_space->normalize( $tuple ) if not $tuple_is_normal and $want_result_normalized;
Branch: 1 branch
BranchTrueFalseTotal
if not $tuple_is_normal and $want_result_normalized 0 210 210
Condition33%1/3
not $tuple_is_normal and $want_result_normalized
!ll&&!rl&&r
21000
MC/DC0%0/2
not $tuple_is_normal and $want_result_normalized
not $tuple_is_normal $want_result_normalized
Truth table33%1/3
not(A) and B
A= not $tuple_is_normalB= $want_result_normalized
ABresult
0X0
100
111
179 210 ▶ $tuple = $current_space->denormalize( $tuple ) if $tuple_is_normal and not $want_result_normalized;
Branch: 1 branch
BranchTrueFalseTotal
if $tuple_is_normal and not $want_result_normalized 5 205 210
Condition66%2/3
$tuple_is_normal and not $want_result_normalized
!ll&&!rl&&r
02055
MC/DC50%1/2
$tuple_is_normal and not $want_result_normalized
$tuple_is_normal not $want_result_normalized
Truth table66%2/3
A and not(B)
A= $tuple_is_normalB= not $want_result_normalized
ABresult
0X0
100
111
180 210 return $tuple;
181 }
182  
183 2264 ▶sub deformat { # formatted color def --> tuple
Subroutine deformat: called CC=4 SCAR=14.0
Pod undocumented
184 2264 my ($color_def, $space_name, $suffix) = @_;
185 2264 ▶ return 'Got no color definition!' unless defined $color_def;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $color_def 0 2264 2264
186 2264 my ($tuple, $original_space, $format_name);
187 2264 my $color_space = get_space( $space_name );
188 2264 ▶ return "$color_space is an unknown space!" unless ref $color_space;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $color_space 0 2264 2264
189 2264 ($tuple, $format_name) = $color_space->deformat( $color_def ); #, $suffix
190 2264 ▶ return "Could not deformat color definition: '$color_def' in space: ".$color_space->name unless defined $format_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $format_name 2175 89 2264
191 89 return $tuple, $color_space->name, $format_name;
192 }
193 142 ▶sub deformat_search { # formatted color def --> tuple
Subroutine deformat_search: called CC=6 SCAR=17.9
Pod undocumented
194 142 my ($color_def, $suffix) = @_;
195 142 ▶ return 'got no color definition to deformat!' unless defined $color_def;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $color_def 0 142 142
196 142 for my $space_name (@search_order) {
197 2264 my @tuple_space_format = deformat( $color_def, $space_name, $suffix);
198 2264 ▶ return @tuple_space_format if @tuple_space_format > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @tuple_space_format > 1 89 2175 2264
199 }
200 53 ▶ return "Could not deformat color definition in any space: '@$color_def'!" if ref $color_def eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $color_def eq "ARRAY" 29 24 53
201 24 ▶ return "Could not deformat color definition in any space: '%$color_def'!" if ref $color_def eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $color_def eq "HASH" 9 15 24
202 15 return "Could not deformat color definition in any space: '$color_def'!";
203 }
204 49 ▶sub deformat_search_partial_hash { # convert partial hash into
Subroutine deformat_search_partial_hash: called CC=8 SCAR=20.9
Pod undocumented
205 49 my ($value_hash, $space_name) = @_;
206 49 ▶ return unless ref $value_hash eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value_hash eq "HASH" 1 48 49
207 48 my $space = try_get_space( $space_name );
208 48 ▶ return $space unless ref $space;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $space 0 48 48
209 48 ▶ my @space_name_options = (defined $space_name and $space_name) ? ($space->name) : (@search_order);
Branch: 1 branch
BranchTrueFalseTotal
defined $space_name && $space_name ? : 22 26 48
Condition66%2/3
defined $space_name and $space_name
!ll&&!rl&&r
26022
MC/DC50%1/2
defined $space_name and $space_name
defined $space_name $space_name
Truth table66%2/3
A and B
A= defined $space_nameB= $space_name
ABresult
0X0
100
111
210 48 for my $space_name (@space_name_options) {
211 379 my $color_space = try_get_space( $space_name );
212 379 my $tuple = $color_space->tuple_from_partial_hash( $value_hash );
213 379 ▶ next unless ref $tuple;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tuple 346 33 379
214 33 ▶ return wantarray ? ($tuple, $color_space->name) : $tuple;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 33 0 33
215 }
216 15 return undef;
217 }
218  
219 28 ▶sub distance { # @c1 @c2 -- ~space ~select @range --> +
Subroutine distance: called CC=5 SCAR=16.1
Pod undocumented
220 28 my ($tuple_a, $tuple_b, $space_name, $select_axis, $range) = @_;
221 28 my $color_space = try_get_space( $space_name );
222 28 ▶ return $color_space unless ref $color_space;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $color_space 0 28 28
223 28 $tuple_a = convert( $tuple_a, $space_name, 'normal' );
224 28 $tuple_b = convert( $tuple_b, $space_name, 'normal' );
225 28 my $delta = $color_space->delta( $tuple_a, $tuple_b );
226 28 $delta = $color_space->denormalize_delta( $delta, $range );
227 28 ▶ if (defined $select_axis){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $select_axis) 17 11 28
228 17 ▶ $select_axis = [$select_axis] unless ref $select_axis;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $select_axis 13 4 17
229 21 my @selected_values = grep {defined $_} map {$delta->[$_]}
230 17 grep {defined $_} map {$color_space->pos_from_axis_name($_)} @$select_axis;
231 17 $delta = \@selected_values;
232 }
233 28 my $d = 0;
234 28 $d += $_ * $_ for @$delta;
235 28 return sqrt $d;
236 }
237  
238 15 1;
↑ Summary Color/Space.pm »