line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Imager::Search::Driver; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Imager::Search::Driver - Abstract imlementation of a Imager::Search driver |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Create the search |
12
|
|
|
|
|
|
|
my $search = Imager::Search::Driver->new( |
13
|
|
|
|
|
|
|
driver => 'HTML24', |
14
|
|
|
|
|
|
|
big => $large_imager_object, |
15
|
|
|
|
|
|
|
small => $small_imager_object, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Run the search |
19
|
|
|
|
|
|
|
my $found = $search->find_first; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Handle the result |
22
|
|
|
|
|
|
|
print "Found at row " . $found->top . " and column " . $found->left; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Given two images (we'll call them Big and Small), where Small is |
27
|
|
|
|
|
|
|
contained within Big zero or more times, determine the pixel locations |
28
|
|
|
|
|
|
|
of Small within Big. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
For example, given a screen shot or a rendered webpage, locate the |
31
|
|
|
|
|
|
|
position of a known icon or picture within the larger image. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
The intent is to provide functionality for use in various testing |
34
|
|
|
|
|
|
|
scenarios, or desktop gui automation, and so on. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 METHODS |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=cut |
39
|
|
|
|
|
|
|
|
40
|
6
|
|
|
6
|
|
120
|
use 5.006; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
236
|
|
41
|
6
|
|
|
6
|
|
38
|
use strict; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
198
|
|
42
|
6
|
|
|
6
|
|
31
|
use Carp (); |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
173
|
|
43
|
6
|
|
|
6
|
|
31
|
use Params::Util qw{ _STRING _CODELIKE _SCALAR _INSTANCE }; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
627
|
|
44
|
6
|
|
|
6
|
|
1503
|
use Imager (); |
|
6
|
|
|
|
|
56656
|
|
|
6
|
|
|
|
|
125
|
|
45
|
|
|
|
|
|
|
|
46
|
6
|
|
|
6
|
|
62
|
use vars qw{$VERSION}; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
316
|
|
47
|
|
|
|
|
|
|
BEGIN { |
48
|
6
|
|
|
6
|
|
104
|
$VERSION = '1.01'; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
6
|
|
|
6
|
|
3115
|
use Imager::Search::Match (); |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
1621
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
##################################################################### |
58
|
|
|
|
|
|
|
# Constructor and Accessors |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=pod |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head2 new |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
my $driver = Imager::Search::Driver->new; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
The C constructor takes a new search driver object. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Returns a new B object, or croaks on error. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub new { |
73
|
10
|
|
|
10
|
1
|
21
|
my $class = shift; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Apply the default driver |
76
|
10
|
50
|
|
|
|
39
|
if ( $class eq 'Imager::Search::Driver' ) { |
77
|
0
|
|
|
|
|
0
|
require Imager::Search::Driver::HTML24; |
78
|
0
|
|
|
|
|
0
|
return Imager::Search::Driver::HTML24->new(@_); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
# Create the object |
82
|
10
|
|
|
|
|
36
|
my $self = bless { @_ }, $class; |
83
|
|
|
|
|
|
|
|
84
|
10
|
|
|
|
|
78
|
return $self; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
##################################################################### |
92
|
|
|
|
|
|
|
# Driver API Methods |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=pod |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 image_string |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
The C method takes a L object, and |
99
|
|
|
|
|
|
|
generates the search string for the image. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Returns a reference to a scalar, or dies on error. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub image_string { |
106
|
0
|
|
0
|
0
|
1
|
|
my $class = ref($_[0]) || $_[0]; |
107
|
0
|
|
|
|
|
|
die "Illegal driver $class does not implement image_string"; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=pod |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 pattern_lines |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Because of the way the regular expression spans scanlines, it requires |
115
|
|
|
|
|
|
|
the width of the target image in order to be fully generated. However, |
116
|
|
|
|
|
|
|
the sub-regexp for each scanline can be (and are) generated in advance. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
When a L object is created, the driver method |
119
|
|
|
|
|
|
|
C is called to generate the scanline regexp for the |
120
|
|
|
|
|
|
|
search pattern. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Returns a reference to an ARRAY containing the regexp in string form, |
123
|
|
|
|
|
|
|
or dies on error. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub pattern_lines { |
128
|
0
|
|
0
|
0
|
1
|
|
my $class = ref($_[0]) || $_[0]; |
129
|
0
|
|
|
|
|
|
die "Illegal driver $class does not implement pattern_lines"; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=pod |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 pattern_regexp |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
The C method takes a pattern and an image is retruns a |
137
|
|
|
|
|
|
|
fully-generated search regexp for the pattern, when used on that image. |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Returns a Regexp object, or dies on error. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub pattern_regexp { |
144
|
0
|
|
0
|
0
|
1
|
|
my $class = ref($_[0] || $_[0]); |
145
|
0
|
|
|
|
|
|
die "Illegal driver $class does not implement pattern_regexp"; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=pod |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 match_object |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Once the regexp engine has located a potential match, the pattern, image |
153
|
|
|
|
|
|
|
and character position are provided to the C method. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
The C will take the raw character position, validate that |
156
|
|
|
|
|
|
|
the character position is at a legimate pixel position, and then return |
157
|
|
|
|
|
|
|
the fully-described match. |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Returns a L object if the position is valid, or |
160
|
|
|
|
|
|
|
false (undef in scalar context or a null string in list context) if the |
161
|
|
|
|
|
|
|
position is not valid. |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=cut |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub match_object { |
166
|
0
|
|
0
|
0
|
1
|
|
my $class = ref($_[0] || $_[0]); |
167
|
0
|
|
|
|
|
|
die "Illegal driver $class does not implement match_object"; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=pod |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head1 SUPPORT |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
See the SUPPORT section of the main L module. |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 AUTHOR |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Adam Kennedy Eadamk@cpan.orgE |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=head1 COPYRIGHT |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
Copyright 2007 - 2011 Adam Kennedy. |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
This program is free software; you can redistribute |
187
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
The full text of the license can be found in the |
190
|
|
|
|
|
|
|
LICENSE file included with this module. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=cut |