API2/Resource/XObject/Image/JPEG.pm

filter: Statementstmt 97.2% 71 / 73 Branchbran 65.6% 21 / 32 Conditioncond 44.8% 13 / 29 MC/DCmcdc 12.5% 2 / 16 Subroutinesub 100% 9 / 9 Podpod 50.0% 1 / 2 totaltotal 72.6% 117 / 161 SCAR 35.4
CC
27
Cov
78%
read_jpeg
38.8
new
8.0
BEGIN
1.0
CRAP 34.4
« API2/Basic/PDF/Objind.pm ↑ Summary API2/Basic/PDF/Filter/ASCII85Decode.pm »
1 package PDF::API2::Resource::XObject::Image::JPEG;
2  
3 3 ▶use base 'PDF::API2::Resource::XObject::Image';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 our $VERSION = '2.044'; # VERSION
9  
10 3 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use PDF::API2::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use PDF::API2::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 sub new {
16 4 ▶ my ($class, $pdf, $file, $name) = @_;
Subroutine new: called CC=8 SCAR=20.8
Pod documented
17 4 my $fh = IO::File->new();
18  
19 4 ▶ $class = ref($class) if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 4 4
20  
21 4 ▶ my $self = $class->SUPER::new($pdf, $name || 'Jx' . pdfkey());
Condition50%1/2
$name || 'Jx' . pdfkey()
l!l
04
MC/DC0%0/1
$name || 'Jx' . pdfkey()
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
22 4 ▶ $pdf->new_obj($self) unless $self->is_obj($pdf);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_obj($pdf) 0 4 4
23  
24 4 $self->{' apipdf'} = $pdf;
25 4 weaken $self->{' apipdf'};
26  
27 4 ▶ if (ref($file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $file) { } 1 3 4
28 1 $fh = $file;
29 }
30 else {
31 3 ▶ open $fh, "<", $file or die "$!: $file";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $file or die "$!: $file" 1 2 3
32 }
33 3 binmode $fh, ':raw';
34  
35 3 $self->read_jpeg($fh);
36  
37 3 ▶ if (ref($file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $file) { } 1 2 3
38 1 seek $fh, 0, 0;
39 1 $self->{' stream'} = '';
40 1 my $buf = '';
41 1 ▶ while (!eof($fh)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eof $fh) 2 1 3
42 2 read $fh, $buf, 512;
43 2 $self->{' stream'} .= $buf;
44 }
45 1 $self->{'Length'} = PDFNum(length $self->{' stream'});
46 }
47 else {
48 2 $self->{'Length'} = PDFNum(-s $file);
49 2 $self->{' streamfile'} = $file;
50 }
51  
52 3 $self->filters('DCTDecode');
53 3 $self->{' nofilt'} = 1;
54  
55 3 return $self;
56 }
57  
58 sub read_jpeg {
59 3 ▶ my ($self, $fh) = @_;
Subroutine read_jpeg: called CC=20 SCAR=36.6
Pod undocumented
60 3 my ($buf, $p, $h, $w, $c, $ff, $mark, $len);
61  
62 3 $fh->seek(0,0);
63 3 $fh->read($buf,2);
64 3 while (1) {
65 15 $fh->read($buf, 4);
66 15 my ($ff, $mark, $len) = unpack('CCn', $buf);
67 15 ▶ last if $ff != 0xFF;
Branch: 1 branch
BranchTrueFalseTotal
if $ff != 255 0 15 15
68 15 ▶ last if $mark == 0xDA || $mark == 0xD9; # SOS/EOI
Branch: 1 branch
BranchTrueFalseTotal
if $mark == 218 or $mark == 217 0 15 15
Condition33%1/3
$mark == 218 or $mark == 217
l!l&&r!l&&!r
0015
MC/DC0%0/2
$mark == 218 or $mark == 217
$mark == 218 $mark == 217
Truth table33%1/3
A or B
A= $mark == 218B= $mark == 217
ABresult
1X1
011
000
69 15 ▶ last if $len < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $len < 2 0 15 15
70 15 ▶ last if $fh->eof();
Branch: 1 branch
BranchTrueFalseTotal
if $fh->eof 0 15 15
71 15 $fh->read($buf, $len - 2);
72 15 ▶ next if $mark == 0xFE;
Branch: 1 branch
BranchTrueFalseTotal
if $mark == 254 3 12 15
73 12 ▶ next if $mark >= 0xE0 && $mark <= 0xEF;
Branch: 1 branch
BranchTrueFalseTotal
if $mark >= 224 and $mark <= 239 3 9 12
Condition66%2/3
$mark >= 224 and $mark <= 239
!ll&&!rl&&r
903
MC/DC50%1/2
$mark >= 224 and $mark <= 239
$mark >= 224 $mark <= 239
Truth table66%2/3
A and B
A= $mark >= 224B= $mark <= 239
ABresult
0X0
100
111
74 9 ▶ if ($mark >= 0xC0 && $mark <= 0xCF && $mark != 0xC4 && $mark != 0xC8 && $mark != 0xCC) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mark >= 192 and $mark <= 207 and $mark != 196 and $mark != 200 and $mark != 204) 3 6 9
Condition66%8/12
$mark >= 192 and $mark <= 207 and $mark != 196 and $mark != 200 and $mark != 204
!ll&&!rl&&r
603
$mark >= 192 and $mark <= 207 and $mark != 196 and $mark != 200
!ll&&!rl&&r
603
$mark >= 192 and $mark <= 207 and $mark != 196
!ll&&!rl&&r
603
$mark >= 192 and $mark <= 207
!ll&&!rl&&r
063
MC/DC20%1/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 table33%2/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
75 3 ($p, $h, $w, $c) = unpack('CnnC', substr($buf, 0, 6));
76 3 last;
77 }
78 }
79  
80 3 $self->width($w);
81 3 $self->height($h);
82 3 $self->bpc($p);
83  
84 3 ▶ if (defined($c) and $c == 3) {
Branch: 3 branches
BranchTrueFalseTotal
if (defined $c and $c == 3) { } 3 0 3
elsif (defined $c and $c == 4) { } 0 0 0
elsif (defined $c and $c == 1) { } 0 0 0
Condition33%1/3
defined $c and $c == 3
!ll&&!rl&&r
003
MC/DC0%0/2
defined $c and $c == 3
defined $c $c == 3
Truth table33%1/3
A and B
A= defined $cB= $c == 3
ABresult
0X0
100
111
85 3 $self->colorspace('DeviceRGB');
86 }
87 ▶ elsif (defined($c) and $c == 4) {
Condition0%0/3
defined $c and $c == 4
!ll&&!rl&&r
000
MC/DC0%0/2
defined $c and $c == 4
defined $c $c == 4
Truth table0%0/3
A and B
A= defined $cB= $c == 4
ABresult
0X0
100
111
88 0 $self->colorspace('DeviceCMYK');
89 }
90 ▶ elsif (defined($c) and $c == 1) {
Condition0%0/3
defined $c and $c == 1
!ll&&!rl&&r
000
MC/DC0%0/2
defined $c and $c == 1
defined $c $c == 1
Truth table0%0/3
A and B
A= defined $cB= $c == 1
ABresult
0X0
100
111
91 0 $self->colorspace('DeviceGray');
92 }
93  
94 3 return $self;
95 }
96  
97 3 1;
« API2/Basic/PDF/Objind.pm ↑ Summary API2/Basic/PDF/Filter/ASCII85Decode.pm »