| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Imager::Search::Match; |
|
2
|
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
94
|
use 5.006; |
|
|
6
|
|
|
|
|
19
|
|
|
|
6
|
|
|
|
|
215
|
|
|
4
|
6
|
|
|
6
|
|
28
|
use strict; |
|
|
6
|
|
|
|
|
11
|
|
|
|
6
|
|
|
|
|
150
|
|
|
5
|
6
|
|
|
6
|
|
27
|
use Carp (); |
|
|
6
|
|
|
|
|
7
|
|
|
|
6
|
|
|
|
|
123
|
|
|
6
|
6
|
|
|
6
|
|
29
|
use Params::Util qw{ _POSINT _NONNEGINT _INSTANCE }; |
|
|
6
|
|
|
|
|
10
|
|
|
|
6
|
|
|
|
|
331
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
6
|
|
|
6
|
|
29
|
use vars qw{$VERSION}; |
|
|
6
|
|
|
|
|
11
|
|
|
|
6
|
|
|
|
|
282
|
|
|
9
|
|
|
|
|
|
|
BEGIN { |
|
10
|
6
|
|
|
6
|
|
197
|
$VERSION = '1.01'; |
|
11
|
|
|
|
|
|
|
} |
|
12
|
|
|
|
|
|
|
|
|
13
|
6
|
|
|
|
|
44
|
use Object::Tiny::XS qw{ |
|
14
|
|
|
|
|
|
|
name |
|
15
|
|
|
|
|
|
|
top |
|
16
|
|
|
|
|
|
|
bottom |
|
17
|
|
|
|
|
|
|
left |
|
18
|
|
|
|
|
|
|
right |
|
19
|
|
|
|
|
|
|
height |
|
20
|
|
|
|
|
|
|
width |
|
21
|
|
|
|
|
|
|
center_x |
|
22
|
|
|
|
|
|
|
center_y |
|
23
|
6
|
|
|
6
|
|
30
|
}; |
|
|
6
|
|
|
|
|
10
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
##################################################################### |
|
30
|
|
|
|
|
|
|
# Constructor |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub new { |
|
33
|
10
|
|
|
10
|
0
|
108
|
my $self = shift->SUPER::new(@_); |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Temporary checks for the basic geometry |
|
36
|
10
|
50
|
|
|
|
308
|
defined(_NONNEGINT($self->top)) or die "Missing or invalid top value"; |
|
37
|
10
|
50
|
|
|
|
415
|
defined(_NONNEGINT($self->left)) or die "Missing or invalid left value"; |
|
38
|
10
|
50
|
|
|
|
323
|
defined(_NONNEGINT($self->height)) or die "Missing or invalid height value"; |
|
39
|
10
|
50
|
|
|
|
384
|
defined(_NONNEGINT($self->width)) or die "Missing or invalid width value"; |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Assume that we've been provided the basic (top/left/height/width) |
|
42
|
|
|
|
|
|
|
# geometry, and from that derive the rest. |
|
43
|
10
|
|
|
|
|
147
|
$self->{bottom} = $self->top + $self->height - 1; |
|
44
|
10
|
|
|
|
|
39
|
$self->{right} = $self->left + $self->width - 1; |
|
45
|
10
|
|
|
|
|
58
|
$self->{center_x} = int( ($self->left + $self->right ) / 2 ); |
|
46
|
10
|
|
|
|
|
47
|
$self->{center_y} = int( ($self->top + $self->bottom) / 2 ); |
|
47
|
|
|
|
|
|
|
|
|
48
|
10
|
|
|
|
|
40
|
return $self; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub from_position { |
|
52
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
|
53
|
0
|
|
|
|
|
|
my $image = _INSTANCE(shift, 'Imager::Search::Image'); |
|
54
|
0
|
|
|
|
|
|
my $pattern = _INSTANCE(shift, 'Imager::Search::Pattern'); |
|
55
|
0
|
|
|
|
|
|
my $position = _NONNEGINT(shift); |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Check params |
|
58
|
0
|
0
|
|
|
|
|
unless ( $image ) { |
|
59
|
0
|
|
|
|
|
|
Carp::croak("Failed to provide Imager::Search::Image param"); |
|
60
|
|
|
|
|
|
|
} |
|
61
|
0
|
0
|
|
|
|
|
unless ( $pattern ) { |
|
62
|
0
|
|
|
|
|
|
Carp::croak("Failed to provide Imager::Search::Pattern param"); |
|
63
|
|
|
|
|
|
|
} |
|
64
|
0
|
0
|
|
|
|
|
unless ( defined $position ) { |
|
65
|
0
|
|
|
|
|
|
Carp::croak("Failed to provide position"); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Derive additional values from the basic values |
|
69
|
0
|
|
|
|
|
|
my $width = $pattern->width; |
|
70
|
0
|
|
|
|
|
|
my $height = $pattern->height; |
|
71
|
0
|
|
|
|
|
|
my $top = int($position / $image->width); |
|
72
|
0
|
|
|
|
|
|
my $left = $position % $image->width; |
|
73
|
0
|
|
|
|
|
|
my $bottom = $top + $height - 1; |
|
74
|
0
|
|
|
|
|
|
my $right = $left + $width - 1; |
|
75
|
0
|
|
|
|
|
|
my $center_x = int(($left + $right) / 2); |
|
76
|
0
|
|
|
|
|
|
my $center_y = int(($top + $bottom) / 2); |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# Create the object |
|
79
|
0
|
|
|
|
|
|
return $class->new( |
|
80
|
|
|
|
|
|
|
left => $left, |
|
81
|
|
|
|
|
|
|
right => $right, |
|
82
|
|
|
|
|
|
|
top => $top, |
|
83
|
|
|
|
|
|
|
bottom => $bottom, |
|
84
|
|
|
|
|
|
|
height => $height, |
|
85
|
|
|
|
|
|
|
width => $width, |
|
86
|
|
|
|
|
|
|
center_x => $center_x, |
|
87
|
|
|
|
|
|
|
center_y => $center_y, |
|
88
|
|
|
|
|
|
|
); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
BEGIN { |
|
92
|
6
|
|
|
6
|
|
6231
|
*centre_x = *center_x; |
|
93
|
6
|
|
|
|
|
167
|
*centre_y = *center_y; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |