line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package RGB2HSI; |
2
|
1
|
|
|
1
|
|
474
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
547
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
require Exporter; |
5
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
6
|
|
|
|
|
|
|
our @EXPORT = qw(rgb2hsi); |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = 0.012; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub rgb2hsi { |
11
|
18
|
|
|
18
|
0
|
21024
|
my ($R, $G, $B) = @_; |
12
|
18
|
|
|
|
|
32
|
my ($H, $S, $I) = (0,0,0); |
13
|
|
|
|
|
|
|
|
14
|
18
|
|
|
|
|
25
|
my $min = 1e-6; |
15
|
|
|
|
|
|
|
|
16
|
18
|
|
|
|
|
52
|
$I = (my $i = $R+$G+$B) / 3.0; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# gray colors |
19
|
18
|
100
|
100
|
|
|
66
|
if ($R == $G && $G == $B){ |
20
|
3
|
|
|
|
|
5
|
$S = 0; |
21
|
3
|
|
|
|
|
3
|
$H = 0; |
22
|
|
|
|
|
|
|
}else{ |
23
|
15
|
|
|
|
|
26
|
my ($r,$g,$b) = (($R/$i), ($G/$i), ($B/$i)); |
24
|
|
|
|
|
|
|
|
25
|
15
|
|
|
|
|
25
|
$H = &rgb_hue($R,$G,$B); |
26
|
|
|
|
|
|
|
|
27
|
15
|
100
|
100
|
|
|
79
|
if ($r <= $g && $r <= $b){ |
|
|
100
|
100
|
|
|
|
|
28
|
5
|
|
|
|
|
9
|
$S = 1- 3 * $r |
29
|
|
|
|
|
|
|
}elsif ($g <= $r && $g <= $b){ |
30
|
6
|
|
|
|
|
10
|
$S = 1- 3 * $g |
31
|
|
|
|
|
|
|
}else{ |
32
|
4
|
|
|
|
|
9
|
$S = 1- 3 * $b; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
18
|
|
|
|
|
49
|
return ($H, $S, $I); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub rgb_hue |
39
|
|
|
|
|
|
|
{ |
40
|
15
|
|
|
15
|
0
|
21
|
my ($r, $g, $b)= @_; |
41
|
15
|
|
|
|
|
14
|
my ($h, $s); |
42
|
|
|
|
|
|
|
|
43
|
15
|
|
|
|
|
25
|
my $min= &_min($r, $g, $b); |
44
|
15
|
|
|
|
|
27
|
my $max= &_max($r, $g, $b); |
45
|
|
|
|
|
|
|
|
46
|
15
|
|
|
|
|
16
|
my $delta = $max - $min; |
47
|
|
|
|
|
|
|
|
48
|
15
|
50
|
|
|
|
30
|
return 0 if ( $delta == 0 ); |
49
|
|
|
|
|
|
|
|
50
|
15
|
100
|
|
|
|
31
|
if( $r == $max ) |
|
|
100
|
|
|
|
|
|
51
|
|
|
|
|
|
|
{ |
52
|
5
|
|
|
|
|
6
|
$h = ( $g - $b ) / $delta; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
elsif ( $g == $max ) |
55
|
|
|
|
|
|
|
{ |
56
|
5
|
|
|
|
|
8
|
$h = 2 + ( $b - $r ) / $delta; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
else # if $b == $max |
59
|
|
|
|
|
|
|
{ |
60
|
5
|
|
|
|
|
8
|
$h = 4 + ( $r - $g ) / $delta; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
15
|
|
|
|
|
17
|
$h *= 60; |
64
|
15
|
100
|
|
|
|
27
|
if( $h < 0 ) { $h += 360; } |
|
1
|
|
|
|
|
2
|
|
65
|
15
|
|
|
|
|
65
|
return $h; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
15
|
100
|
|
15
|
|
17
|
sub _min { my $min = shift(@_); foreach my $v (@_) { if ($v <= $min) { $min = $v; } }; return $min; } |
|
15
|
|
|
|
|
24
|
|
|
30
|
|
|
|
|
68
|
|
|
16
|
|
|
|
|
31
|
|
|
15
|
|
|
|
|
30
|
|
69
|
15
|
100
|
|
15
|
|
16
|
sub _max { my $max = shift(@_); foreach my $v (@_) { if ($v >= $max) { $max = $v; } }; return $max; } |
|
15
|
|
|
|
|
20
|
|
|
30
|
|
|
|
|
58
|
|
|
14
|
|
|
|
|
20
|
|
|
15
|
|
|
|
|
26
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__END__ |