| 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
Condition0%0/3
defined $opts{"-name"} and not defined $opts{"name"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if (defined $opts{'-compress'} && !defined $opts{'compress'}) { $opts{'compress'} = delete($opts{'-compress'}); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $opts{"-compress"} and not defined $opts{"compress"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if (defined $opts{'-lossless'} && !defined $opts{'lossless'}) { $opts{'lossless'} = delete($opts{'-lossless'}); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $opts{"-lossless"} and not defined $opts{"lossless"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my ($name, $compress); | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | if (exists $opts{'name'}) { $name = $opts{'name'}; } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | $self = $class->SUPER::new($pdf, $name || 'Dx'.pdfkey()); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$name || 'Dx' . pdfkey()
MC/DC0%0/1
$name || 'Dx' . pdfkey()
$name
Truth table0%0/2
A
A= $name
| |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | ▶ | $pdf->new_obj($self) unless $self->is_obj($pdf); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/6
$gd->can("jpeg") and $c > 256 and not $opts{"lossless"}
$gd->can("jpeg") and $c > 256
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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | for(my $x=0; $x<$w; $x++) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||||||||||||