| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
# utilities for color value calculation |
|
3
|
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Graphics::Toolkit::Color::Space::Util; |
|
5
|
49
|
|
|
49
|
|
986259
|
use v5.12; |
|
|
49
|
|
|
|
|
202
|
|
|
6
|
49
|
|
|
49
|
|
315
|
use warnings; |
|
|
49
|
|
|
|
|
89
|
|
|
|
49
|
|
|
|
|
2779
|
|
|
7
|
49
|
|
|
49
|
|
285
|
use Exporter 'import'; |
|
|
49
|
|
|
|
|
101
|
|
|
|
49
|
|
|
|
|
45081
|
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw/min max uniq round_int round_decimals mod_real gamma_correct mult_matrix_vector_3 is_nr number_re/; |
|
9
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all => [@EXPORT_OK]); |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#### lists ############################################################# |
|
12
|
|
|
|
|
|
|
sub min { |
|
13
|
101
|
|
|
101
|
0
|
1428
|
my $v = shift; |
|
14
|
101
|
50
|
|
|
|
188
|
for (@_) { next unless defined $_; $v = $_ if $v > $_ } |
|
|
200
|
100
|
|
|
|
446
|
|
|
|
200
|
|
|
|
|
497
|
|
|
15
|
101
|
|
|
|
|
281
|
return $v; |
|
16
|
|
|
|
|
|
|
} |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub max { |
|
19
|
110
|
|
|
110
|
0
|
183
|
my $v = shift; |
|
20
|
110
|
50
|
|
|
|
288
|
for (@_) { next unless defined $_; $v = $_ if $v < $_ } |
|
|
219
|
100
|
|
|
|
405
|
|
|
|
219
|
|
|
|
|
480
|
|
|
21
|
110
|
|
|
|
|
353
|
return $v; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub uniq { |
|
25
|
562
|
100
|
|
562
|
0
|
8378
|
return undef unless @_; |
|
26
|
561
|
|
|
|
|
786
|
my %seen = (); |
|
27
|
561
|
|
|
|
|
901
|
grep {not $seen{$_}++} @_; |
|
|
1375
|
|
|
|
|
4638
|
|
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#### basic math ######################################################## |
|
31
|
|
|
|
|
|
|
my $half = 0.50000000000008; |
|
32
|
|
|
|
|
|
|
my $tolerance = 0.00000000000008; |
|
33
|
|
|
|
|
|
|
sub round_int { |
|
34
|
3877
|
100
|
|
3877
|
0
|
19303
|
$_[0] >= 0 ? int ($_[0] + $half) |
|
35
|
|
|
|
|
|
|
: int ($_[0] - $half) |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub round_decimals { |
|
39
|
3869
|
|
|
3869
|
0
|
13135
|
my ($nr, $precision) = @_; |
|
40
|
3869
|
100
|
100
|
|
|
11511
|
return round_int( $nr ) unless defined $precision and $precision; |
|
41
|
1269
|
|
|
|
|
1930
|
$precision = 10 ** $precision; |
|
42
|
1269
|
|
|
|
|
2767
|
return round_int( $nr * $precision ) / $precision; |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub mod_real { # real value modulo |
|
46
|
105
|
100
|
100
|
105
|
0
|
436
|
return 0 unless defined $_[1] and $_[1]; |
|
47
|
102
|
|
|
|
|
339
|
return $_[0] - (int($_[0] / $_[1]) * $_[1]); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub gamma_correct { # spow: sign preserving power function |
|
51
|
296
|
|
|
296
|
0
|
575
|
my ($base, $exponent) = @_; |
|
52
|
296
|
100
|
|
|
|
1330
|
return $base ** $exponent if $base >= 0; |
|
53
|
23
|
|
|
|
|
109
|
return -((-$base) ** $exponent); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
my $number_re = qr/^\-?(?:\d+|(?:\d*\.\d+))(?:e-?\d+)?$/; |
|
57
|
|
|
|
|
|
|
|
|
58
|
445
|
|
|
445
|
0
|
908
|
sub number_re { $number_re } |
|
59
|
5512
|
100
|
|
5512
|
0
|
41139
|
sub is_nr { ($_[0] =~ $number_re) ? 1 : 0 } |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
#### color computation ################################################# |
|
62
|
|
|
|
|
|
|
sub mult_matrix_vector_3 { |
|
63
|
162
|
|
|
162
|
0
|
5037
|
my ($mat, $v1, $v2, $v3) = @_; |
|
64
|
162
|
50
|
33
|
|
|
637
|
return unless ref $mat eq 'ARRAY' and defined $v3; |
|
65
|
162
|
|
|
|
|
1023
|
return ($v1 * $mat->[0][0] + $v2 * $mat->[0][1] + $v3 * $mat->[0][2]) , |
|
66
|
|
|
|
|
|
|
($v1 * $mat->[1][0] + $v2 * $mat->[1][1] + $v3 * $mat->[1][2]) , |
|
67
|
|
|
|
|
|
|
($v1 * $mat->[2][0] + $v2 * $mat->[2][1] + $v3 * $mat->[2][2]) ; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
1; |