File Coverage

blib/lib/PDF/Builder/Resource/XObject/Image.pm
Criterion Covered Total %
statement 30 40 75.0
branch 6 10 60.0
condition 2 3 66.6
subroutine 9 11 81.8
pod 7 7 100.0
total 54 71 76.0


line stmt bran cond sub pod time code
1             package PDF::Builder::Resource::XObject::Image;
2              
3 6     6   1579 use base 'PDF::Builder::Resource::XObject';
  6         13  
  6         759  
4              
5 6     6   41 use strict;
  6         22  
  6         171  
6 6     6   27 use warnings;
  6         15  
  6         346  
7              
8             our $VERSION = '3.025'; # VERSION
9             our $LAST_UPDATE = '3.017'; # manually update whenever code is changed
10              
11 6     6   41 use PDF::Builder::Basic::PDF::Utils;
  6         22  
  6         3609  
12              
13             =head1 NAME
14              
15             PDF::Builder::Resource::XObject::Image - Base class for external raster image objects
16              
17             =head1 METHODS
18              
19             =over
20              
21             =item $image = PDF::Builder::Resource::XObject::Image->new($pdf, $name)
22              
23             Returns an image resource object.
24              
25             =cut
26              
27             sub new {
28 17     17 1 47 my ($class, $pdf, $name) = @_;
29              
30 17         81 my $self = $class->SUPER::new($pdf, $name);
31              
32 17         83 $self->subtype('Image');
33              
34 17         48 return $self;
35             }
36              
37             =item $width = $image->width($width)
38              
39             Get or set the width value for the image object.
40              
41             =cut
42              
43             sub width {
44 22     22 1 5345 my $self = shift;
45              
46 22 100       92 $self->{'Width'} = PDFNum(shift()) if scalar @_;
47 22         71 return $self->{'Width'}->val();
48             }
49              
50             =item $height = $image->height($height)
51              
52             Get or set the height value for the image object.
53              
54             =cut
55              
56             sub height {
57 13     13 1 32 my $self = shift;
58              
59 13 50       43 $self->{'Height'} = PDFNum(shift()) if scalar @_;
60 13         37 return $self->{'Height'}->val();
61             }
62              
63             =item $image->smask($xobject)
64              
65             Set the soft-mask image object.
66              
67             =cut
68              
69             sub smask {
70 0     0 1 0 my $self = shift;
71 0         0 $self->{'SMask'} = shift;
72              
73 0         0 return $self;
74             }
75              
76             =item $image->mask(@color_range)
77              
78             =item $image->mask($xobject)
79              
80             Set the mask to an image mask XObject or an array containing a range
81             of colors to be applied as a color key mask.
82              
83             =cut
84              
85             sub mask {
86 0     0 1 0 my $self = shift();
87              
88 0 0       0 if (ref($_[0])) {
89 0         0 $self->{'Mask'} = shift();
90             } else {
91 0         0 $self->{'Mask'} = PDFArray(map { PDFNum($_) } @_);
  0         0  
92             }
93              
94 0         0 return $self;
95             }
96              
97             # imask() functionality rolled into mask()
98              
99             =item $image->colorspace($name)
100              
101             =item $image->colorspace($array)
102              
103             Set the color space used by the image. Depending on the color space,
104             this will either be just the name of the color space, or it will be an
105             array containing the color space and any required parameters.
106              
107             If passing an array, parameters must already be encoded as PDF
108             objects. The array itself may also be a PDF object. If not, one will
109             be created.
110              
111             =cut
112              
113             sub colorspace {
114 13     13 1 36 my ($self, @values) = @_;
115              
116 13 100 66     95 if (scalar @values == 1 and ref($values[0])) {
    50          
117 4         16 $self->{'ColorSpace'} = $values[0];
118             } elsif (scalar @values == 1) {
119 9         52 $self->{'ColorSpace'} = PDFName($values[0]);
120             } else {
121 0         0 $self->{'ColorSpace'} = PDFArray(@values);
122             }
123              
124 13         38 return $self;
125             }
126              
127             =item $image->bits_per_component($integer)
128              
129             Set the number of bits used to represent each color component.
130              
131             =cut
132              
133             sub bits_per_component {
134 13     13 1 30 my $self = shift;
135              
136 13         39 $self->{'BitsPerComponent'} = PDFNum(shift());
137              
138 13         30 return $self;
139             }
140              
141             # bpc() renamed to bits_per_component()
142              
143             =back
144              
145             =cut
146              
147             1;