| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Image::Seek; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
19563
|
use 5.006; |
|
|
1
|
|
|
|
|
4
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
20
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
9
|
|
|
|
1
|
|
|
|
|
41
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
64
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
|
9
|
1
|
|
|
1
|
|
4533
|
use AutoLoader; |
|
|
1
|
|
|
|
|
1480
|
|
|
|
1
|
|
|
|
|
6
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
12
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( add_image query_id loaddb savedb cleardb |
|
13
|
|
|
|
|
|
|
add_image_imager add_image_imlib2 remove_id) ] ); |
|
14
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|
15
|
|
|
|
|
|
|
our @EXPORT = qw( ); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
require XSLoader; |
|
20
|
|
|
|
|
|
|
XSLoader::load('Image::Seek', $VERSION); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub add_image { |
|
25
|
0
|
|
|
0
|
|
|
my ($image, $id) = @_; |
|
26
|
0
|
0
|
|
|
|
|
if (UNIVERSAL::isa($image, "Imager")) { goto &add_image_imager } |
|
|
0
|
|
|
|
|
|
|
|
27
|
0
|
0
|
|
|
|
|
if (UNIVERSAL::isa($image, "Image::Imlib2")) { goto &add_image_imlib2 } |
|
|
0
|
|
|
|
|
|
|
|
28
|
0
|
0
|
|
|
|
|
if (UNIVERSAL::isa($image, "GD::Image")) { goto &add_image_gd } |
|
|
0
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
if (UNIVERSAL::isa($image, "Image::Magick")) { goto &add_image_magick } |
|
|
0
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
croak "Don't know what sort of image $image is"; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub add_image_magick { |
|
34
|
0
|
|
|
0
|
|
|
my ($img, $id) = @_; |
|
35
|
|
|
|
|
|
|
#my ($reds, $blues, $greens); |
|
36
|
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my ($width,$height) = $img->Get('width', 'height'); |
|
38
|
0
|
|
|
|
|
|
my $thumb; |
|
39
|
|
|
|
|
|
|
|
|
40
|
0
|
0
|
0
|
|
|
|
if ($width == 128 && $height == 128) { |
|
41
|
0
|
|
|
|
|
|
$thumb = $img; |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
else { |
|
44
|
0
|
|
|
|
|
|
$thumb = $img->Clone(); |
|
45
|
0
|
|
|
|
|
|
$thumb->Scale('128x128!'); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my @red = $thumb->GetPixels('map' => 'R', 'height' => 128, 'width' =>128, 'normalize' => 1); |
|
49
|
0
|
|
|
|
|
|
my $reds = join('',(map { chr($_); } @red)); |
|
|
0
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my @blue = $thumb->GetPixels('map' => 'B', 'height' => 128, 'width' =>128, 'normalize' => 1); |
|
51
|
0
|
|
|
|
|
|
my $blues = join('',(map { chr($_); } @blue)); |
|
|
0
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
my @green = $thumb->GetPixels('map' => 'G', 'height' => 128, 'width' =>128, 'normalize' => 1); |
|
53
|
0
|
|
|
|
|
|
my $greens = join('',(map { chr($_); } @green)); |
|
|
0
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
addImage($id, $reds, $greens, $blues); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub add_image_gd { |
|
58
|
0
|
|
|
0
|
|
|
my ($img, $id) = @_; |
|
59
|
0
|
|
|
|
|
|
my ($reds, $blues, $greens); |
|
60
|
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $thumb = new GD::Image(128,128,1); |
|
62
|
0
|
|
|
|
|
|
$thumb->copyResized($img,0,0,0,0,128,128,$img->width ,$img->height); |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
for my $y (0..127) { |
|
65
|
0
|
|
|
|
|
|
for my $x (0..127) { |
|
66
|
0
|
|
|
|
|
|
my ($r, $g, $b) = $thumb->rgb($thumb->getPixel($x,$y)); |
|
67
|
0
|
|
|
|
|
|
$reds .= chr($r); $blues .= chr($b); $greens .= chr($g); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
} |
|
70
|
0
|
|
|
|
|
|
addImage($id, $reds, $greens, $blues); |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub add_image_imager { |
|
74
|
0
|
|
|
0
|
|
|
my ($img, $id) = @_; |
|
75
|
0
|
|
|
|
|
|
my ($reds, $blues, $greens); |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
my $thumb = $img->scaleX(pixels => 128)->scaleY(pixels => 128); |
|
78
|
0
|
|
|
|
|
|
for my $y (0..127) { |
|
79
|
0
|
|
|
|
|
|
my @cols = $thumb->getscanline('y' => $y); |
|
80
|
0
|
|
|
|
|
|
for (@cols) { |
|
81
|
0
|
|
|
|
|
|
my ($r, $g, $b) = $_->rgba; |
|
82
|
0
|
|
|
|
|
|
$reds .= chr($r); $blues .= chr($b); $greens .= chr($g); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
} |
|
84
|
|
|
|
|
|
|
} |
|
85
|
0
|
|
|
|
|
|
addImage($id, $reds, $greens, $blues); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub add_image_imlib2 { |
|
89
|
0
|
|
|
0
|
|
|
my ($img, $id) = @_; |
|
90
|
0
|
|
|
|
|
|
my ($reds, $blues, $greens); |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my $thumb = $img->create_scaled_image(128,128); |
|
93
|
0
|
|
|
|
|
|
for my $y (0..127) { |
|
94
|
0
|
|
|
|
|
|
for my $x (0..127) { |
|
95
|
0
|
|
|
|
|
|
my ($r, $g, $b,$a) = $thumb->query_pixel($x,$y); |
|
96
|
0
|
|
|
|
|
|
$reds .= chr($r); $blues .= chr($b); $greens .= chr($g); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
} |
|
99
|
0
|
|
|
|
|
|
addImage($id, $reds, $greens, $blues); |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub query_id { |
|
103
|
0
|
|
|
0
|
|
|
my $id = shift; |
|
104
|
0
|
|
0
|
|
|
|
my $results = shift || 10; |
|
105
|
0
|
|
|
|
|
|
queryImgID($id, $results); |
|
106
|
0
|
|
|
|
|
|
my @r = results(); |
|
107
|
0
|
|
|
|
|
|
my @rv; |
|
108
|
0
|
|
|
|
|
|
unshift @rv, [shift @r, shift @r] while @r; |
|
109
|
0
|
|
|
|
|
|
@rv; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub remove_id { |
|
113
|
0
|
|
|
0
|
|
|
my $id = shift; |
|
114
|
0
|
|
|
|
|
|
removeID($id); |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
|
118
|
|
|
|
|
|
|
__END__ |