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

filter: Statementstmt 38.1% 21 / 55 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 70.0% 7 / 10 Podpod 66.6% 2 / 3 totaltotal 32.6% 30 / 92 CC 10 SCAR 32.3
CC
10
Cov
28%
read_gd
56.0
new
20.0
new_api
2.0
CRAP 25.3
« API3/Compat/API2/Basic/TTF/Name.pm ↑ Summary API3/Compat/API2/Basic/TTF/AATKern.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: GD.pm,v 2.0 2005/11/16 02:18:23 areibens Exp $
31 #
32 #=======================================================================
33 package PDF::API3::Compat::API2::Resource::XObject::Image::GD;
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.0 $' =~ /Revision: (\S+)\s/)[0]); # $Date: 2005/11/16 02:18:23 $
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::GD->new $pdf, $obj [, $name]
53
54 Returns a image object from a GD::Image.
55
56 =cut
57
58 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod documented
59 0 my ($class,$pdf,$obj,$name,@opts) = @_;
60 0 my $self;
61
62 0 ▶ $class = ref $class if ref $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 0 0
63
64 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
65 0 ▶ $pdf->new_obj($self) unless($self->is_obj($pdf));
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_obj($pdf) 0 0 0
66
67 0 $self->{' apipdf'}=$pdf;
68
69 0 $self->read_gd($obj,@opts);
70
71 0 return($self);
72 }
73
74 =item $res = PDF::API3::Compat::API2::Resource::XObject::Image::GD->new_api $api, $obj [, $name]
75
76 Returns a image object. This method is different from 'new' that
77 it needs an PDF::API3::Compat::API2-object rather than a Text::PDF::File-object.
78
79 =cut
80
81 0 ▶sub new_api {
Subroutine new_api: not called CC=1 SCAR=6.9
Pod documented
82 0 my ($class,$api,@opts)=@_;
83
84 0 my $obj=$class->new($api->{pdf},@opts);
85 0 $obj->{' api'}=$api;
86
87 0 return($obj);
88 }
89
90 0 ▶sub read_gd {
Subroutine read_gd: not called CC=7 SCAR=40.3
Pod undocumented
91 0 my $self = shift @_;
92 0 my $gd = shift @_;
93 0 my %opts = @_;
94
95 0 my ($w,$h) = $gd->getBounds();
96 0 my $c = $gd->colorsTotal();
97
98 0 $self->width($w);
99 0 $self->height($h);
100
101 0 $self->bpc(8);
102 0 $self->colorspace('DeviceRGB');
103
104 0 ▶ if(UNIVERSAL::can($gd,'jpeg') && ($c > 256) && !$opts{-lossless}) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::can($gd, 'jpeg') and $c > 256 and not $opts{'-lossless'}) { } 0 0 0
elsif (UNIVERSAL::can($gd, 'raw')) { } 0 0 0
Condition0%0/6
UNIVERSAL::can($gd, "jpeg") and $c > 256 and not $opts{"-lossless"}
!ll&&!rl&&r
000
UNIVERSAL::can($gd, "jpeg") and $c > 256
!ll&&!rl&&r
000
MC/DC0%0/3
UNIVERSAL::can($gd, "jpeg") and $c > 256 and not $opts{"-lossless"}
UNIVERSAL::can($gd, "jpeg") $c > 256 not $opts{"-lossless"}
Truth table0%0/4
A and B and not(C)
A= UNIVERSAL::can($gd, "jpeg")B= $c > 256C= not $opts{"-lossless"}
ABCresult
0XX0
10X0
1100
1111
105
106 0 $self->filters('DCTDecode');
107 0 $self->{' nofilt'}=1;
108 0 $self->{' stream'}=$gd->jpeg(75);
109
110 } elsif(UNIVERSAL::can($gd,'raw')) {
111
112 0 $self->filters('FlateDecode');
113 0 $self->{' stream'}=$gd->raw;
114
115 } else {
116
117 0 $self->filters('FlateDecode');
118 0 ▶ for(my $y=0;$y<$h;$y++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $h) 0 0 0
119 0 ▶ for(my $x=0;$x<$w;$x++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $w) 0 0 0
120 0 my $index=$gd->getPixel($x,$y);
121 0 my @rgb=$gd->rgb($index);
122 0 $self->{' stream'}.=pack('CCC',@rgb);
123 }
124 }
125
126 }
127
128 0 return($self);
129 }
130
131
132
133 1 1;
134
135 __END__
« API3/Compat/API2/Basic/TTF/Name.pm ↑ Summary API3/Compat/API2/Basic/TTF/AATKern.pm »