API3/Compat/API2/Resource/XObject/Image/JPEG.pm

filter: Statementstmt 27.6% 21 / 76 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 20 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 70.0% 7 / 10 Podpod 66.6% 2 / 3 totaltotal 20.1% 30 / 149 CC 23 SCAR 51.7
CC
23
Cov
17%
read_jpeg
306.0
new
56.0
new_api
2.0
CRAP 175.1
« API3/Compat/API2/Basic/TTF/Ttopen.pm ↑ Summary API3/Compat/API2/Resource/CIDFont/CJKFont.pm »
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 <areibens@cpan.org>.
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: JPEG.pm,v 2.1 2007/03/17 20:38:51 areibens Exp $
31 #
32 #=======================================================================
33 package PDF::API3::Compat::API2::Resource::XObject::Image::JPEG;
34
35 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
36
37 1 ▶ use PDF::API3::Compat::API2::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶ use PDF::API3::Compat::API2::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶ use PDF::API3::Compat::API2::Resource::XObject::Image;
Subroutine BEGIN: called CC=1 SCAR=0.0
40
41 1 ▶ use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
42
43 1 ▶ use vars qw(@ISA $VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
44
45 1 @ISA = qw( PDF::API3::Compat::API2::Resource::XObject::Image );
46
47 1 ( $VERSION ) = sprintf '%i.%03i', split(/\./,('$Revision: 2.1 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2007/03/17 20:38:51 $
48
49 }
50 1 ▶no warnings qw[ deprecated recursion uninitialized ];
Subroutine BEGIN: called CC=1 SCAR=0.0
51
52 =item $res = PDF::API3::Compat::API2::Resource::XObject::Image::JPEG->new $pdf, $file [, $name]
53
54 Returns a jpeg-image object.
55
56 =cut
57
58 sub new
59 0 ▶{
Subroutine new: not called CC=7 SCAR=40.3
Pod documented
60 0 my ($class,$pdf,$file,$name) = @_;
61 0 my $self;
62 0 my $fh = IO::File->new;
63
64 0 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
65
66 0 ▶ $self=$class->SUPER::new($pdf,$name|| 'Jx'.pdfkey());
Condition0%0/2
$name || 'Jx' . pdfkey()
l!l
00
MC/DC0%0/1
$name || 'Jx' . pdfkey()
$name
Truth table0%0/2
A
A= $name
Aresult
11
00
67 0 ▶ $pdf->new_obj($self) unless($self->is_obj($pdf));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_obj($pdf) 0 0 0
68
69 0 $self->{' apipdf'}=$pdf;
70
71 0 ▶ if(ref $file)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $file) { } 0 0 0
72 {
73 0 $fh=$file;
74 }
75 else
76 {
77 0 open($fh,$file);
78 }
79 0 binmode($fh,':raw');
80
81 0 $self->read_jpeg($fh);
82
83 0 ▶ if(ref $file)
Branch: 1 branch
BranchTrueFalseTotal
if (ref $file) { } 0 0 0
84 {
85 0 seek($fh,0,0);
86 0 $self->{' stream'}='';
87 0 my $buf='';
88 0 ▶ while(!eof($fh)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eof $fh) 0 0 0
89 0 read($fh,$buf,512);
90 0 $self->{' stream'}.=$buf;
91 }
92 0 $self->{Length}=PDFNum(length $self->{' stream'});
93 }
94 else
95 {
96 0 $self->{Length}=PDFNum(-s $file);
97 0 $self->{' streamfile'}=$file;
98 }
99
100 0 $self->filters('DCTDecode');
101 0 $self->{' nofilt'}=1;
102
103 0 return($self);
104 }
105
106 =item $res = PDF::API3::Compat::API2::Resource::XObject::Image::JPEG->new_api $api, $file [, $name]
107
108 Returns a jpeg-image object. This method is different from 'new' that
109 it needs an PDF::API3::Compat::API2-object rather than a Text::PDF::File-object.
110
111 =cut
112
113 0 ▶sub new_api {
Subroutine new_api: not called CC=1 SCAR=6.9
Pod documented
114 0 my ($class,$api,@opts)=@_;
115
116 0 my $obj=$class->new($api->{pdf},@opts);
117 0 $obj->{' api'}=$api;
118
119 0 return($obj);
120 }
121
122 0 ▶sub read_jpeg {
Subroutine read_jpeg: not called CC=17 SCAR=57.2
Pod undocumented
123 0 my $self = shift @_;
124 0 my $fh = shift @_;
125
126 0 my ($buf, $p, $h, $w, $c, $ff, $mark, $len);
127
128 0 $fh->seek(0,0);
129 0 $fh->read($buf,2);
130 0 while (1) {
131 0 $fh->read($buf,4);
132 0 my($ff, $mark, $len) = unpack("CCn", $buf);
133 0 ▶ last if( $ff != 0xFF);
Branch: 1 branch
BranchTrueFalseTotal
if $ff != 255 0 0 0
134 0 ▶ last if( $mark == 0xDA || $mark == 0xD9); # SOS/EOI
Branch: 1 branch
BranchTrueFalseTotal
if $mark == 218 or $mark == 217 0 0 0
Condition0%0/3
$mark == 218 or $mark == 217
l!l&&r!l&&!r
000
MC/DC0%0/2
$mark == 218 or $mark == 217
$mark == 218 $mark == 217
Truth table0%0/3
A or B
A= $mark == 218B= $mark == 217
ABresult
1X1
011
000
135 0 ▶ last if( $len < 2);
Branch: 1 branch
BranchTrueFalseTotal
if $len < 2 0 0 0
136 0 ▶ last if( $fh->eof);
Branch: 1 branch
BranchTrueFalseTotal
if $fh->eof 0 0 0
137 0 $fh->read($buf,$len-2);
138 0 ▶ next if ($mark == 0xFE);
Branch: 1 branch
BranchTrueFalseTotal
if $mark == 254 0 0 0
139 0 ▶ next if ($mark >= 0xE0 && $mark <= 0xEF);
Branch: 1 branch
BranchTrueFalseTotal
if $mark >= 224 and $mark <= 239 0 0 0
Condition0%0/3
$mark >= 224 and $mark <= 239
!ll&&!rl&&r
000
MC/DC0%0/2
$mark >= 224 and $mark <= 239
$mark >= 224 $mark <= 239
Truth table0%0/3
A and B
A= $mark >= 224B= $mark <= 239
ABresult
0X0
100
111
140 0 ▶ if (($mark >= 0xC0) && ($mark <= 0xCF) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($mark >= 192 and $mark <= 207 and $mark != 196 and $mark != 200 and $mark != 204) 0 0 0
Condition0%0/12
$mark >= 192 and $mark <= 207 and $mark != 196 and $mark != 200 and $mark != 204
!ll&&!rl&&r
000
$mark >= 192 and $mark <= 207 and $mark != 196 and $mark != 200
!ll&&!rl&&r
000
$mark >= 192 and $mark <= 207 and $mark != 196
!ll&&!rl&&r
000
$mark >= 192 and $mark <= 207
!ll&&!rl&&r
000
MC/DC0%0/5
$mark >= 192 and $mark <= 207 and $mark != 196 and $mark != 200 and $mark != 204
$mark >= 192 $mark <= 207 $mark != 196 $mark != 200 $mark != 204
Truth table0%0/6
A and B and C and D and E
A= $mark >= 192B= $mark <= 207C= $mark != 196D= $mark != 200E= $mark != 204
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
141 ($mark != 0xC4) && ($mark != 0xC8) && ($mark != 0xCC)) {
142 0 ($p, $h, $w, $c) = unpack("CnnC", substr($buf, 0, 6));
143 0 last;
144 }
145 }
146
147 0 $self->width($w);
148 0 $self->height($h);
149
150 0 $self->bpc($p);
151
152 0 ▶ if($c==3) {
Branch: 3 branches
BranchTrueFalseTotal
if ($c == 3) { } 0 0 0
elsif ($c == 4) { } 0 0 0
elsif ($c == 1) { } 0 0 0
153 0 $self->colorspace('DeviceRGB');
154 } elsif($c==4) {
155 0 $self->colorspace('DeviceCMYK');
156 } elsif($c==1) {
157 0 $self->colorspace('DeviceGray');
158 }
159
160 0 return($self);
161 }
162
163
164
165 1 1;
166
167 __END__
« API3/Compat/API2/Basic/TTF/Ttopen.pm ↑ Summary API3/Compat/API2/Resource/CIDFont/CJKFont.pm »