line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Image::ColorCollection; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
29
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
6
|
1
|
|
|
1
|
|
6
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
73
|
|
7
|
1
|
|
|
1
|
|
5
|
use Data::Dumper; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
49
|
|
8
|
1
|
|
|
1
|
|
5
|
use Imager; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
9
|
1
|
|
|
1
|
|
41
|
use Imager::Fill; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
22
|
|
10
|
1
|
|
|
1
|
|
5
|
use List::Util qw(sum); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1748
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
16
|
0
|
|
|
|
|
|
my $self = { |
17
|
|
|
|
|
|
|
centroid => { |
18
|
|
|
|
|
|
|
r => int(rand(255)), |
19
|
|
|
|
|
|
|
g => int(rand(255)), |
20
|
|
|
|
|
|
|
b => int(rand(255)), |
21
|
|
|
|
|
|
|
}, |
22
|
|
|
|
|
|
|
colors => [] |
23
|
|
|
|
|
|
|
}; |
24
|
0
|
|
|
|
|
|
bless $self, $class; |
25
|
0
|
|
|
|
|
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
#store the centroid here.. |
28
|
|
|
|
|
|
|
#store belongstome |
29
|
|
|
|
|
|
|
sub getCentroid { |
30
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
31
|
0
|
|
|
|
|
|
return $class->{centroid}; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
sub addColor { |
34
|
0
|
|
|
0
|
0
|
|
my ($class, $c) = @_; |
35
|
0
|
|
|
|
|
|
push @{$class->{colors}}, $c; |
|
0
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
sub updateCentroid { |
38
|
0
|
|
|
0
|
0
|
|
my ($class, $c) = @_; |
39
|
0
|
|
|
|
|
|
my $shift = 0; |
40
|
0
|
|
|
|
|
|
my @colors = @{$class->{colors}}; |
|
0
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
if(scalar(@colors) == 0) |
42
|
|
|
|
|
|
|
{ |
43
|
0
|
|
|
|
|
|
return 0; |
44
|
|
|
|
|
|
|
} |
45
|
0
|
|
|
|
|
|
my $rAvg = int(sum(map {$_->{r}} @colors)/@colors); |
|
0
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
$shift += $class->{centroid}->{r} - $rAvg; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $gAvg = int(sum(map {$_->{g}} @colors)/@colors); |
|
0
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
$shift += $class->{centroid}->{g} - $gAvg; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $bAvg = int(sum(map {$_->{b}} @colors)/@colors); |
|
0
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$shift += $class->{centroid}->{b} - $bAvg; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
$class->{centroid} = { |
55
|
|
|
|
|
|
|
r => int($rAvg), |
56
|
|
|
|
|
|
|
g => int($gAvg), |
57
|
|
|
|
|
|
|
b => int($bAvg), |
58
|
|
|
|
|
|
|
}; |
59
|
0
|
|
|
|
|
|
return $shift; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub clear { |
63
|
0
|
|
|
0
|
0
|
|
my ($class, $c) = @_; |
64
|
0
|
|
|
|
|
|
$class->{colors} = []; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; # End of Image::ColorCollection |
68
|
|
|
|
|
|
|
__END__ |