| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
# methods to compute one related color |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Graphics::Toolkit::Color::Calculator; |
|
5
|
6
|
|
|
6
|
|
249136
|
use v5.12; |
|
|
6
|
|
|
|
|
16
|
|
|
6
|
6
|
|
|
6
|
|
19
|
use warnings; |
|
|
6
|
|
|
|
|
6
|
|
|
|
6
|
|
|
|
|
219
|
|
|
7
|
6
|
|
|
6
|
|
1715
|
use Graphics::Toolkit::Color::Values; |
|
|
6
|
|
|
|
|
15
|
|
|
|
6
|
|
|
|
|
5977
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub apply_gamma { |
|
11
|
9
|
|
|
9
|
0
|
9382
|
my ($color_values, $gamma, $color_space) = @_; |
|
12
|
9
|
|
|
|
|
9
|
my $gamma_array; |
|
13
|
9
|
100
|
|
|
|
20
|
if (ref $gamma eq 'HASH'){ |
|
14
|
3
|
|
|
|
|
12
|
($gamma_array, my $deduced_space_name) = |
|
15
|
|
|
|
|
|
|
Graphics::Toolkit::Color::Space::Hub::deformat_partial_hash( $gamma, $color_space->name ); |
|
16
|
3
|
100
|
|
|
|
10
|
return 'axis names: '.join(', ', keys %$gamma).' do not correlate to the selected color space: '. |
|
17
|
|
|
|
|
|
|
($color_space->name).'!' unless ref $gamma_array; |
|
18
|
|
|
|
|
|
|
} else { |
|
19
|
6
|
|
|
|
|
19
|
$gamma_array = [ ($gamma) x $color_space->axis_count]; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
8
|
|
|
|
|
15
|
my $values = $color_values->normalized( $color_space->name ); |
|
22
|
8
|
|
|
|
|
16
|
for my $axis_nr ($color_space->basis->axis_iterator){ |
|
23
|
24
|
100
|
|
|
|
59
|
$values->[$axis_nr] = $values->[$axis_nr] ** $gamma_array->[$axis_nr] if exists $gamma_array->[$axis_nr]; |
|
24
|
|
|
|
|
|
|
} |
|
25
|
8
|
|
|
|
|
15
|
return $color_values->new_from_tuple( $values, $color_space->name, 'normal' ); |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub set_value { # .values, %newval -- ~space_name --> _ |
|
29
|
13
|
|
|
13
|
0
|
7573
|
my ($color_values, $partial_hash, $preselected_space_name) = @_; |
|
30
|
13
|
|
|
|
|
34
|
my ($new_values, $deduced_space_name) = |
|
31
|
|
|
|
|
|
|
Graphics::Toolkit::Color::Space::Hub::deformat_partial_hash( $partial_hash, $preselected_space_name ); |
|
32
|
13
|
100
|
|
|
|
23
|
unless (ref $new_values){ |
|
33
|
4
|
|
|
|
|
15
|
my $help_start = 'axis names: '.join(', ', keys %$partial_hash).' do not correlate to '; |
|
34
|
4
|
100
|
|
|
|
17
|
return (defined $preselected_space_name) ? $help_start.'the selected color space: '.$preselected_space_name.'!' |
|
35
|
|
|
|
|
|
|
: 'any supported color space!'; |
|
36
|
|
|
|
|
|
|
} |
|
37
|
9
|
|
|
|
|
27
|
my $values = $color_values->shaped( $deduced_space_name ); |
|
38
|
9
|
|
|
|
|
19
|
my $color_space = Graphics::Toolkit::Color::Space::Hub::get_space( $deduced_space_name ); |
|
39
|
9
|
|
|
|
|
17
|
for my $pos ($color_space->basis->axis_iterator) { |
|
40
|
27
|
100
|
|
|
|
44
|
$values->[$pos] = $new_values->[$pos] if defined $new_values->[$pos]; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
9
|
|
|
|
|
17
|
return $color_values->new_from_tuple( $values, $color_space->name ); |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub add_value { # .values, %newval -- ~space_name --> _ |
|
46
|
13
|
|
|
13
|
0
|
7550
|
my ($color_values, $partial_hash, $preselected_space_name) = @_; |
|
47
|
13
|
|
|
|
|
34
|
my ($new_values, $deduced_space_name) = |
|
48
|
|
|
|
|
|
|
Graphics::Toolkit::Color::Space::Hub::deformat_partial_hash( $partial_hash, $preselected_space_name ); |
|
49
|
13
|
100
|
|
|
|
24
|
unless (ref $new_values){ |
|
50
|
5
|
|
|
|
|
13
|
my $help_start = 'axis names: '.join(', ', keys %$partial_hash).' do not correlate to '; |
|
51
|
5
|
100
|
|
|
|
21
|
return (defined $preselected_space_name) ? $help_start.'the selected color space: '.$preselected_space_name.'!' |
|
52
|
|
|
|
|
|
|
: 'any supported color space!'; |
|
53
|
|
|
|
|
|
|
} |
|
54
|
8
|
|
|
|
|
24
|
my $values = $color_values->shaped( $deduced_space_name ); |
|
55
|
8
|
|
|
|
|
17
|
my $color_space = Graphics::Toolkit::Color::Space::Hub::get_space( $deduced_space_name ); |
|
56
|
8
|
|
|
|
|
19
|
for my $pos ($color_space->basis->axis_iterator) { |
|
57
|
24
|
100
|
|
|
|
47
|
$values->[$pos] += $new_values->[$pos] if defined $new_values->[$pos]; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
8
|
|
|
|
|
17
|
return $color_values->new_from_tuple( $values, $color_space->name ); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub mix { # @%(+percent, _color) -- ~space_name --> _ |
|
63
|
75
|
|
|
75
|
0
|
2910
|
my ($color_values, $recipe, $color_space ) = @_; |
|
64
|
75
|
50
|
|
|
|
130
|
return if ref $recipe ne 'ARRAY'; |
|
65
|
75
|
|
|
|
|
175
|
my $result_values = [(0) x $color_space->axis_count]; |
|
66
|
75
|
|
|
|
|
106
|
for my $ingredient (@$recipe){ |
|
67
|
|
|
|
|
|
|
return if ref $ingredient ne 'HASH' or not exists $ingredient->{'percent'} |
|
68
|
153
|
50
|
33
|
|
|
752
|
or not exists $ingredient->{'color'} or ref $ingredient->{'color'} ne ref $color_values; |
|
|
|
|
33
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
69
|
153
|
|
|
|
|
252
|
my $values = $ingredient->{'color'}->shaped( $color_space->name ); |
|
70
|
153
|
|
|
|
|
695
|
$result_values->[$_] += $values->[$_] * $ingredient->{'percent'} / 100 for 0 .. $#$values; |
|
71
|
|
|
|
|
|
|
} |
|
72
|
75
|
|
|
|
|
123
|
return $color_values->new_from_tuple( $result_values, $color_space->name ); |
|
73
|
|
|
|
|
|
|
} |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub invert { |
|
76
|
23
|
|
|
23
|
0
|
3403
|
my ($color_values, $only, $color_space ) = @_; |
|
77
|
23
|
50
|
|
|
|
46
|
return unless ref $color_space; |
|
78
|
23
|
100
|
100
|
|
|
60
|
$only = [$only] if defined $only and not ref $only; # check which axis selected |
|
79
|
23
|
100
|
|
|
|
70
|
my $selected_axis = (defined $only) ? [ ] : [$color_space->basis->axis_iterator]; |
|
80
|
23
|
100
|
|
|
|
45
|
if (defined $only) { |
|
81
|
5
|
|
|
|
|
8
|
for my $axis_name (@$only){ |
|
82
|
7
|
|
|
|
|
18
|
my $pos = $color_space->pos_from_axis_name( $axis_name ); |
|
83
|
7
|
50
|
|
|
|
11
|
return "axis name '$axis_name' is not part of clor space '".$color_space->name. |
|
84
|
|
|
|
|
|
|
"', please try: ".(join(' ', $color_space->long_axis_names)). |
|
85
|
|
|
|
|
|
|
' or '.(join(' ', $color_space->short_axis_names)).' !' unless defined $pos; |
|
86
|
7
|
50
|
|
|
|
16
|
return "axis '$axis_name' is already selected for inversion" if exists $selected_axis->[$pos]; |
|
87
|
7
|
|
|
|
|
13
|
$selected_axis->[$pos] = $pos; |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
} |
|
90
|
23
|
|
|
|
|
39
|
my $values = $color_values->normalized( $color_space->name ); |
|
91
|
23
|
|
|
|
|
73
|
for my $axis_nr ($color_space->basis->axis_iterator){ |
|
92
|
69
|
100
|
|
|
|
100
|
next unless defined $selected_axis->[$axis_nr]; |
|
93
|
61
|
100
|
|
|
|
91
|
if ($color_space->shape->is_axis_euclidean( $axis_nr )){ |
|
94
|
54
|
|
|
|
|
96
|
$values->[$axis_nr] = 1 - $values->[$axis_nr]; |
|
95
|
|
|
|
|
|
|
} else { |
|
96
|
7
|
100
|
|
|
|
30
|
$values->[$axis_nr] = ($values->[$axis_nr] < 0.5) |
|
97
|
|
|
|
|
|
|
? $values->[$axis_nr] + 0.5 |
|
98
|
|
|
|
|
|
|
: $values->[$axis_nr] - 0.5; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
} |
|
101
|
23
|
|
|
|
|
41
|
return $color_values->new_from_tuple( $values, $color_space->name, 'normal' ); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |