line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#=======================================================================
|
2
|
|
|
|
|
|
|
# ____ ____ _____ _ ____ ___ ____
|
3
|
|
|
|
|
|
|
# | _ \| _ \| ___| _ _ / \ | _ \_ _| |___ \
|
4
|
|
|
|
|
|
|
# | |_) | | | | |_ (_) (_) / _ \ | |_) | | __) |
|
5
|
|
|
|
|
|
|
# | __/| |_| | _| _ _ / ___ \| __/| | / __/
|
6
|
|
|
|
|
|
|
# |_| |____/|_| (_) (_) /_/ \_\_| |___| |_____|
|
7
|
|
|
|
|
|
|
#
|
8
|
|
|
|
|
|
|
# A Perl Module Chain to faciliate the Creation and Modification
|
9
|
|
|
|
|
|
|
# of High-Quality "Portable Document Format (PDF)" Files.
|
10
|
|
|
|
|
|
|
#
|
11
|
|
|
|
|
|
|
# Copyright 1999-2005 Alfred Reibenschuh .
|
12
|
|
|
|
|
|
|
#
|
13
|
|
|
|
|
|
|
#=======================================================================
|
14
|
|
|
|
|
|
|
#
|
15
|
|
|
|
|
|
|
# This library is free software; you can redistribute it and/or
|
16
|
|
|
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
17
|
|
|
|
|
|
|
# License as published by the Free Software Foundation; either
|
18
|
|
|
|
|
|
|
# version 2 of the License, or (at your option) any later version.
|
19
|
|
|
|
|
|
|
#
|
20
|
|
|
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
21
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
23
|
|
|
|
|
|
|
# Lesser General Public License for more details.
|
24
|
|
|
|
|
|
|
#
|
25
|
|
|
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
26
|
|
|
|
|
|
|
# License along with this library; if not, write to the
|
27
|
|
|
|
|
|
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
28
|
|
|
|
|
|
|
# Boston, MA 02111-1307, USA.
|
29
|
|
|
|
|
|
|
#
|
30
|
|
|
|
|
|
|
# $Id: PNM.pm,v 2.1 2007/05/24 19:29:46 areibens Exp $
|
31
|
|
|
|
|
|
|
#
|
32
|
|
|
|
|
|
|
#=======================================================================
|
33
|
|
|
|
|
|
|
package PDF::API3::Compat::API2::Resource::XObject::Image::PNM;
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
BEGIN {
|
36
|
|
|
|
|
|
|
|
37
|
1
|
|
|
1
|
|
8
|
use PDF::API3::Compat::API2::Util;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
248
|
|
38
|
1
|
|
|
1
|
|
6
|
use PDF::API3::Compat::API2::Basic::PDF::Utils;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
132
|
|
39
|
1
|
|
|
1
|
|
5
|
use PDF::API3::Compat::API2::Resource::XObject::Image;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
1
|
|
6
|
use POSIX;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
1
|
|
3428
|
use vars qw(@ISA $VERSION);
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
171
|
|
44
|
1
|
|
|
1
|
|
36
|
@ISA = qw( PDF::API3::Compat::API2::Resource::XObject::Image );
|
45
|
1
|
|
|
|
|
44
|
( $VERSION ) = sprintf '%i.%03i', split(/\./,('$Revision: 2.1 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2007/05/24 19:29:46 $
|
46
|
|
|
|
|
|
|
}
|
47
|
1
|
|
|
1
|
|
6
|
no warnings qw[ deprecated recursion uninitialized ];
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1185
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item $res = PDF::API3::Compat::API2::Resource::XObject::Image::PNM->new $pdf, $file [, $name]
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Returns a pnm-image object.
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub new {
|
56
|
0
|
|
|
0
|
1
|
|
my ($class,$pdf,$file,$name) = @_;
|
57
|
0
|
|
|
|
|
|
my $self;
|
58
|
0
|
|
|
|
|
|
my $fh = IO::File->new;
|
59
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
$class = ref $class if ref $class;
|
61
|
|
|
|
|
|
|
|
62
|
0
|
|
0
|
|
|
|
$self=$class->SUPER::new($pdf,$name || 'Nx'.pdfkey());
|
63
|
0
|
0
|
|
|
|
|
$pdf->new_obj($self) unless($self->is_obj($pdf));
|
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$self->{' apipdf'}=$pdf;
|
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$self->read_pnm($pdf,$file);
|
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
return($self);
|
70
|
|
|
|
|
|
|
}
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item $res = PDF::API3::Compat::API2::Resource::XObject::Image::PNM->new_api $api, $file [, $name]
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Returns a pnm-image object. This method is different from 'new' that
|
75
|
|
|
|
|
|
|
it needs an PDF::API3::Compat::API2-object rather than a Text::PDF::File-object.
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub new_api {
|
80
|
0
|
|
|
0
|
1
|
|
my ($class,$api,@opts)=@_;
|
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
my $obj=$class->new($api->{pdf},@opts);
|
83
|
0
|
|
|
|
|
|
$obj->{' api'}=$api;
|
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return($obj);
|
86
|
|
|
|
|
|
|
}
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
# READPPMHEADER
|
89
|
|
|
|
|
|
|
# taken from Image::PBMLib
|
90
|
|
|
|
|
|
|
# Copyright by Benjamin Elijah Griffin (28 Feb 2003)
|
91
|
|
|
|
|
|
|
#
|
92
|
|
|
|
|
|
|
sub readppmheader($) {
|
93
|
0
|
|
|
0
|
0
|
|
my $gr = shift; # input file glob ref
|
94
|
0
|
|
|
|
|
|
my $in = '';
|
95
|
0
|
|
|
|
|
|
my $no_comments;
|
96
|
|
|
|
|
|
|
my %info;
|
97
|
0
|
|
|
|
|
|
my $rc;
|
98
|
0
|
|
|
|
|
|
$info{error} = undef;
|
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
$rc = read($gr, $in, 3);
|
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
0
|
|
|
|
if (!defined($rc) or $rc != 3) {
|
103
|
0
|
|
|
|
|
|
$info{error} = 'Read error or EOF';
|
104
|
0
|
|
|
|
|
|
return \%info;
|
105
|
|
|
|
|
|
|
}
|
106
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
if ($in =~ /^P([123456])\s/) {
|
108
|
0
|
|
|
|
|
|
$info{type} = $1;
|
109
|
0
|
0
|
|
|
|
|
if ($info{type} > 3) {
|
110
|
0
|
|
|
|
|
|
$info{raw} = 1;
|
111
|
|
|
|
|
|
|
} else {
|
112
|
0
|
|
|
|
|
|
$info{raw} = 0;
|
113
|
|
|
|
|
|
|
}
|
114
|
|
|
|
|
|
|
|
115
|
0
|
0
|
0
|
|
|
|
if ($info{type} == 1 or $info{type} == 4) {
|
|
|
0
|
0
|
|
|
|
|
116
|
0
|
|
|
|
|
|
$info{max} = 1;
|
117
|
0
|
|
|
|
|
|
$info{bgp} = 'b';
|
118
|
|
|
|
|
|
|
} elsif ($info{type} == 2 or $info{type} == 5) {
|
119
|
0
|
|
|
|
|
|
$info{bgp} = 'g';
|
120
|
|
|
|
|
|
|
} else {
|
121
|
0
|
|
|
|
|
|
$info{bgp} = 'p';
|
122
|
|
|
|
|
|
|
}
|
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
while(1) {
|
125
|
0
|
|
|
|
|
|
$rc = read($gr, $in, 1, length($in));
|
126
|
0
|
0
|
0
|
|
|
|
if (!defined($rc) or $rc != 1) {
|
127
|
0
|
|
|
|
|
|
$info{error} = 'Read error or EOF';
|
128
|
0
|
|
|
|
|
|
return \%info;
|
129
|
|
|
|
|
|
|
}
|
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
$no_comments = $in;
|
132
|
0
|
|
|
|
|
|
$info{comments} = '';
|
133
|
0
|
|
|
|
|
|
while ($no_comments =~ /#.*\n/) {
|
134
|
0
|
|
|
|
|
|
$no_comments =~ s/#(.*\n)/ /;
|
135
|
0
|
|
|
|
|
|
$info{comments} .= $1;
|
136
|
|
|
|
|
|
|
}
|
137
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
if ($info{bgp} eq 'b') {
|
139
|
0
|
0
|
|
|
|
|
if ($no_comments =~ /^P\d\s+(\d+)\s+(\d+)\s/) {
|
140
|
0
|
|
|
|
|
|
$info{width} = $1;
|
141
|
0
|
|
|
|
|
|
$info{height} = $2;
|
142
|
0
|
|
|
|
|
|
last;
|
143
|
|
|
|
|
|
|
}
|
144
|
|
|
|
|
|
|
} else {
|
145
|
0
|
0
|
|
|
|
|
if ($no_comments =~ /^P\d\s+(\d+)\s+(\d+)\s+(\d+)\s/) {
|
146
|
0
|
|
|
|
|
|
$info{width} = $1;
|
147
|
0
|
|
|
|
|
|
$info{height} = $2;
|
148
|
0
|
|
|
|
|
|
$info{max} = $3;
|
149
|
0
|
|
|
|
|
|
last;
|
150
|
|
|
|
|
|
|
}
|
151
|
|
|
|
|
|
|
}
|
152
|
|
|
|
|
|
|
} # while reading header
|
153
|
|
|
|
|
|
|
|
154
|
0
|
|
|
|
|
|
$info{fullheader} = $in;
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
} else {
|
157
|
0
|
|
|
|
|
|
$info{error} = 'Wrong magic number';
|
158
|
|
|
|
|
|
|
}
|
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
return \%info;
|
161
|
|
|
|
|
|
|
}
|
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub read_pnm {
|
164
|
0
|
|
|
0
|
0
|
|
my $self = shift @_;
|
165
|
0
|
|
|
|
|
|
my $pdf = shift @_;
|
166
|
0
|
|
|
|
|
|
my $file = shift @_;
|
167
|
|
|
|
|
|
|
|
168
|
0
|
|
|
|
|
|
my ($buf,$t,$s,$line);
|
169
|
0
|
|
|
|
|
|
my ($w,$h,$bpc,$cs,$img,@img)=(0,0,'','','');
|
170
|
0
|
|
|
|
|
|
open(INF,$file);
|
171
|
0
|
|
|
|
|
|
binmode(INF,':raw');
|
172
|
0
|
|
|
|
|
|
my $info=readppmheader(INF);
|
173
|
0
|
0
|
|
|
|
|
if($info->{type} == 4) {
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
$bpc=1;
|
175
|
0
|
|
|
|
|
|
read(INF,$self->{' stream'},($info->{width}*$info->{height}/8));
|
176
|
0
|
|
|
|
|
|
$cs='DeviceGray';
|
177
|
0
|
|
|
|
|
|
$self->{Decode}=PDFArray(PDFNum(1),PDFNum(0));
|
178
|
|
|
|
|
|
|
} elsif($info->{type} == 5) {
|
179
|
0
|
|
|
|
|
|
$buf.=;
|
180
|
0
|
0
|
|
|
|
|
if($info->{max}==255){
|
181
|
0
|
|
|
|
|
|
$s=0;
|
182
|
|
|
|
|
|
|
} else {
|
183
|
0
|
|
|
|
|
|
$s=255/$info->{max};
|
184
|
|
|
|
|
|
|
}
|
185
|
0
|
|
|
|
|
|
$bpc=8;
|
186
|
0
|
0
|
|
|
|
|
if($s>0) {
|
187
|
0
|
|
|
|
|
|
for($line=($info->{width}*$info->{height});$line>0;$line--) {
|
188
|
0
|
|
|
|
|
|
read(INF,$buf,1);
|
189
|
0
|
|
|
|
|
|
$self->{' stream'}.=pack('C',(unpack('C',$buf)*$s));
|
190
|
|
|
|
|
|
|
}
|
191
|
|
|
|
|
|
|
} else {
|
192
|
0
|
|
|
|
|
|
read(INF,$self->{' stream'},$info->{width}*$info->{height});
|
193
|
|
|
|
|
|
|
}
|
194
|
0
|
|
|
|
|
|
$cs='DeviceGray';
|
195
|
|
|
|
|
|
|
} elsif($info->{type} == 6) {
|
196
|
0
|
0
|
|
|
|
|
if($info->{max}==255){
|
197
|
0
|
|
|
|
|
|
$s=0;
|
198
|
|
|
|
|
|
|
} else {
|
199
|
0
|
|
|
|
|
|
$s=255/$info->{max};
|
200
|
|
|
|
|
|
|
}
|
201
|
0
|
|
|
|
|
|
$bpc=8;
|
202
|
0
|
0
|
|
|
|
|
if($s>0) {
|
203
|
0
|
|
|
|
|
|
for($line=($info->{width}*$info->{height});$line>0;$line--) {
|
204
|
0
|
|
|
|
|
|
read(INF,$buf,1);
|
205
|
0
|
|
|
|
|
|
$self->{' stream'}.=pack('C',(unpack('C',$buf)*$s));
|
206
|
0
|
|
|
|
|
|
read(INF,$buf,1);
|
207
|
0
|
|
|
|
|
|
$self->{' stream'}.=pack('C',(unpack('C',$buf)*$s));
|
208
|
0
|
|
|
|
|
|
read(INF,$buf,1);
|
209
|
0
|
|
|
|
|
|
$self->{' stream'}.=pack('C',(unpack('C',$buf)*$s));
|
210
|
|
|
|
|
|
|
}
|
211
|
|
|
|
|
|
|
} else {
|
212
|
0
|
|
|
|
|
|
read(INF,$self->{' stream'},$info->{width}*$info->{height}*3);
|
213
|
|
|
|
|
|
|
}
|
214
|
0
|
|
|
|
|
|
$cs='DeviceRGB';
|
215
|
|
|
|
|
|
|
}
|
216
|
0
|
|
|
|
|
|
close(INF);
|
217
|
|
|
|
|
|
|
|
218
|
0
|
|
|
|
|
|
$self->width($info->{width});
|
219
|
0
|
|
|
|
|
|
$self->height($info->{height});
|
220
|
|
|
|
|
|
|
|
221
|
0
|
|
|
|
|
|
$self->bpc($bpc);
|
222
|
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
$self->filters('FlateDecode');
|
224
|
|
|
|
|
|
|
|
225
|
0
|
|
|
|
|
|
$self->colorspace($cs);
|
226
|
|
|
|
|
|
|
|
227
|
0
|
|
|
|
|
|
return($self);
|
228
|
|
|
|
|
|
|
}
|
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
1;
|
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
__END__
|