line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Color::Similarity; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Color::Similarity - common interface to different Color::Similarity::* modules |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 SYNOPSIS |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Color::Similarity; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $package = ...; # for example Color::Similarity::HCL |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my $s = Color::Similarity->new( $package ); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $d1 = $s->distance( [ $r1, $g1, $b1 ], [ $r2, $g2, $b2 ] ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
3
|
|
|
3
|
|
7141
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
657
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 METHODS |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 new |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my $s = Color::Similarity->new( $package ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Constructs a new C object wrapping the given |
30
|
|
|
|
|
|
|
C<$package>. The module will not try to load the package, so the |
31
|
|
|
|
|
|
|
caller must have done it already. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=cut |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub new { |
36
|
2
|
|
|
2
|
1
|
17
|
my( $class, $package ) = @_; |
37
|
|
|
|
|
|
|
|
38
|
2
|
|
|
|
|
18
|
bless $package->_vtable, $class; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head2 distance_rgb |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $d = $s->distance_rgb( [ $r1, $g1, $b1 ], [ $r2, $g2, $b2 ] ); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
Converts the RGB triplets to the appropriate representation (usually a |
46
|
|
|
|
|
|
|
different colorspace) and computes their distance. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub distance_rgb { |
51
|
7
|
|
|
7
|
1
|
1367
|
my( $self, $t1, $t2 ) = @_; |
52
|
|
|
|
|
|
|
|
53
|
7
|
|
|
|
|
13
|
return &{$self->{distance_rgb}}( $t1, $t2 ); |
|
7
|
|
|
|
|
31
|
|
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 convert_rgb |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $c = $s->convert_rgb( $r, $g, $b ); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Converts the given RGB triplet to a representation suitable for |
61
|
|
|
|
|
|
|
passing it to C. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub convert_rgb { |
66
|
6
|
|
|
6
|
1
|
342
|
my( $self, $r, $g, $b ) = @_; |
67
|
|
|
|
|
|
|
|
68
|
6
|
|
|
|
|
10
|
return &{$self->{convert_rgb}}( $r, $g, $b ); |
|
6
|
|
|
|
|
26
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 distance |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $d = $s->distance( $c1, $c2 ); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Computes the distance between two colors already in an appropriate |
76
|
|
|
|
|
|
|
representation (either using C or by alternate means). |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub distance { |
81
|
3
|
|
|
3
|
1
|
372
|
my( $self, $t1, $t2 ) = @_; |
82
|
|
|
|
|
|
|
|
83
|
3
|
|
|
|
|
23
|
return &{$self->{distance}}( $t1, $t2 ); |
|
3
|
|
|
|
|
12
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SEE ALSO |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
L, L, L |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 AUTHOR |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Mattia Barbon, C<< >> |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 COPYRIGHT |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Copyright (C) 2007, Mattia Barbon |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This program is free software; you can redistribute it or modify it |
99
|
|
|
|
|
|
|
under the same terms as Perl itself. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
1; |