Builder/Resource/XObject/Image/GD.pm

filter: Statementstmt 35.5% 21 / 59 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 75.0% 6 / 8 Podpod 50.0% 1 / 2 totaltotal 24.1% 28 / 116 CC 17 SCAR 43.4
CC
17
Cov
22%
new
132.0
read_gd
56.0
BEGIN
1.0
CRAP 77.1
« Builder/Resource/XObject/Image/TIFF_GT.pm ↑ Summary Builder/Outline.pm »
1 package PDF::Builder::Resource::XObject::Image::GD;
2  
3 1 ▶use base 'PDF::Builder::Resource::XObject::Image';
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '3.028'; # VERSION
9 1 our $LAST_UPDATE = '3.027'; # manually update whenever code is changed
10  
11 1 ▶use PDF::Builder::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use PDF::Builder::Basic::PDF::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 =head1 NAME
16  
17 PDF::Builder::Resource::XObject::Image::GD - Support routines for Graphics Development image library
18  
19 Inherits from L<PDF::Builder::Resource::XObject::Image>
20  
21 =head1 METHODS
22  
23 =head2 new
24  
25 $res = PDF::Builder::Resource::XObject::Image::GD->new($pdf, $file, %opts)
26  
27 =over
28  
29 Options:
30  
31 =over
32  
33 =item 'name' => 'string'
34  
35 This is the name you can give for the GD image object. The default is Dxnnnn.
36  
37 =item 'lossless' => 1
38  
39 Use lossless compression.
40  
41 =back
42  
43 An image object is created from GD input. Note that this should be invoked
44 from Builder.pm's method.
45  
46 =back
47  
48 =cut
49  
50 0 ▶sub new {
Subroutine new: not called CC=11 SCAR=48.8
Pod documented
51 0 my ($class, $pdf, $obj, %opts) = @_;
52 # copy dashed option names to preferred undashed names
53 0 ▶ if (defined $opts{'-name'} && !defined $opts{'name'}) { $opts{'name'} = delete($opts{'-name'}); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"-name"} and not defined $opts{"name"}) 0 0 0
Condition0%0/3
defined $opts{"-name"} and not defined $opts{"name"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts{"-name"} and not defined $opts{"name"}
defined $opts{"-name"} not defined $opts{"name"}
Truth table0%0/3
A and not(B)
A= defined $opts{"-name"}B= not defined $opts{"name"}
ABresult
0X0
100
111
54 0 ▶ if (defined $opts{'-compress'} && !defined $opts{'compress'}) { $opts{'compress'} = delete($opts{'-compress'}); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"-compress"} and not defined $opts{"compress"}) 0 0 0
Condition0%0/3
defined $opts{"-compress"} and not defined $opts{"compress"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts{"-compress"} and not defined $opts{"compress"}
defined $opts{"-compress"} not defined $opts{"compress"}
Truth table0%0/3
A and not(B)
A= defined $opts{"-compress"}B= not defined $opts{"compress"}
ABresult
0X0
100
111
55 0 ▶ if (defined $opts{'-lossless'} && !defined $opts{'lossless'}) { $opts{'lossless'} = delete($opts{'-lossless'}); }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts{"-lossless"} and not defined $opts{"lossless"}) 0 0 0
Condition0%0/3
defined $opts{"-lossless"} and not defined $opts{"lossless"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $opts{"-lossless"} and not defined $opts{"lossless"}
defined $opts{"-lossless"} not defined $opts{"lossless"}
Truth table0%0/3
A and not(B)
A= defined $opts{"-lossless"}B= not defined $opts{"lossless"}
ABresult
0X0
100
111
56  
57 0 my ($name, $compress);
58 0 ▶ if (exists $opts{'name'}) { $name = $opts{'name'}; }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts{"name"}) 0 0 0
59 #if (exists $opts{'compress'}) { $compress = $opts{'compress'}; }
60  
61 0 my $self;
62  
63 0 ▶ $class = ref($class) if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
64  
65 0 ▶ $self = $class->SUPER::new($pdf, $name || 'Dx'.pdfkey());
Condition0%0/2
$name || 'Dx' . pdfkey()
l!l
00
MC/DC0%0/1
$name || 'Dx' . pdfkey()
$name
Truth table0%0/2
A
A= $name
Aresult
11
00
66 0 ▶ $pdf->new_obj($self) unless $self->is_obj($pdf);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_obj($pdf) 0 0 0
67  
68 0 $self->{' apipdf'} = $pdf;
69 0 weaken $self->{' apipdf'};
70  
71 0 $self->read_gd($obj, %opts);
72  
73 0 return $self;
74 }
75  
76 0 ▶sub read_gd {
Subroutine read_gd: not called CC=7 SCAR=40.3
Pod undocumented
77 0 my ($self, $gd, %opts) = @_;
78  
79 0 my ($w,$h) = $gd->getBounds();
80 0 my $c = $gd->colorsTotal();
81  
82 0 $self->width($w);
83 0 $self->height($h);
84  
85 0 $self->bits_per_component(8);
86 0 $self->colorspace('DeviceRGB');
87  
88 0 ▶ if ($gd->can('jpeg') && ($c > 256) && !$opts{'lossless'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($gd->can('jpeg') and $c > 256 and not $opts{'lossless'}) { } 0 0 0
elsif ($gd->can('raw')) { } 0 0 0
Condition0%0/6
$gd->can("jpeg") and $c > 256 and not $opts{"lossless"}
!ll&&!rl&&r
000
$gd->can("jpeg") and $c > 256
!ll&&!rl&&r
000
MC/DC0%0/3
$gd->can("jpeg") and $c > 256 and not $opts{"lossless"}
$gd->can("jpeg") $c > 256 not $opts{"lossless"}
Truth table0%0/4
A and B and not(C)
A= $gd->can("jpeg")B= $c > 256C= not $opts{"lossless"}
ABCresult
0XX0
10X0
1100
1111
89  
90 0 $self->filters('DCTDecode');
91 0 $self->{' nofilt'} = 1;
92 0 $self->{' stream'} = $gd->jpeg(75);
93  
94 } elsif ($gd->can('raw')) {
95  
96 0 $self->filters('FlateDecode');
97 0 $self->{' stream'} = $gd->raw();
98  
99 } else {
100  
101 0 $self->filters('FlateDecode');
102 0 ▶ for(my $y=0; $y<$h; $y++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $h) 0 0 0
103 0 ▶ for(my $x=0; $x<$w; $x++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $w) 0 0 0
104 0 my $index = $gd->getPixel($x,$y);
105 0 my @rgb = $gd->rgb($index);
106 0 $self->{' stream'} .= pack('CCC', @rgb);
107 }
108 }
109  
110 }
111  
112 0 return $self;
113 }
114  
115 1 1;
« Builder/Resource/XObject/Image/TIFF_GT.pm ↑ Summary Builder/Outline.pm »