File Coverage

blib/lib/PDF/Builder/Resource/ColorSpace/Indexed/ACTFile.pm
Criterion Covered Total %
statement 18 38 47.3
branch 0 8 0.0
condition n/a
subroutine 6 7 85.7
pod 1 1 100.0
total 25 54 46.3


line stmt bran cond sub pod time code
1             package PDF::Builder::Resource::ColorSpace::Indexed::ACTFile;
2              
3 1     1   979 use base 'PDF::Builder::Resource::ColorSpace::Indexed';
  1         2  
  1         156  
4              
5 1     1   7 use strict;
  1         2  
  1         20  
6 1     1   4 use warnings;
  1         2  
  1         76  
7              
8             our $VERSION = '3.028'; # VERSION
9             our $LAST_UPDATE = '3.027'; # manually update whenever code is changed
10              
11 1     1   5 use PDF::Builder::Basic::PDF::Utils;
  1         1  
  1         83  
12 1     1   4 use PDF::Builder::Util;
  1         2  
  1         123  
13 1     1   5 use Scalar::Util qw(weaken);
  1         2  
  1         335  
14              
15             =head1 NAME
16              
17             PDF::Builder::Resource::ColorSpace::Indexed::ACTFile - Adobe Color Table support
18              
19             Inherits from L<PDF::Builder::Resource::ColorSpace::Indexed>
20              
21             =head1 METHODS
22              
23             =head2 new
24              
25             $cs = PDF::Builder::Resource::ColorSpace::Indexed::ACTFile->new($pdf, $actfile)
26              
27             =over
28              
29             Returns a new colorspace object created from an Adobe color table file (ACT/8BCT).
30             See
31             Adobe Photoshop(R) 6.0 --
32             File Formats Specification Version 6.0 Release 2,
33             November 2000
34             for details.
35              
36             =back
37              
38             =cut
39              
40             sub new {
41 0     0 1   my ($class, $pdf, $file) = @_;
42              
43 0 0         die "could not find act-file '$file'." unless -f $file;
44 0 0         $class = ref($class) if ref($class);
45 0           my $self = $class->SUPER::new($pdf, pdfkey());
46 0 0         $pdf->new_obj($self) unless $self->is_obj($pdf);
47 0           $self->{' apipdf'} = $pdf;
48 0           weaken $self->{' apipdf'};
49 0           my $csd = PDFDict();
50 0           $pdf->new_obj($csd);
51 0           $csd->{'Filter'} = PDFArray(PDFName('FlateDecode'));
52             # default values in case file is missing or bad??
53             #$csd->{'WhitePoint'} = PDFArray(map {PDFNum($_)} (0.95049, 1, 1.08897));
54             #$csd->{'BlackPoint'} = PDFArray(map {PDFNum($_)} (0, 0, 0));
55             #$csd->{'Gamma'} = PDFArray(map {PDFNum($_)} (2.22218, 2.22218, 2.22218));
56              
57 0           my $fh;
58 0 0         open($fh, "<", $file) or die "$!: $file";
59 0           binmode($fh, ':raw');
60 0           read($fh, $csd->{' stream'}, 768);
61 0           close($fh);
62              
63 0           $csd->{' stream'} .= "\x00" x 768;
64 0           $csd->{' stream'} = substr($csd->{' stream'}, 0, 768);
65              
66 0           $self->add_elements(PDFName('DeviceRGB'), PDFNum(255), $csd);
67 0           $self->{' csd'} = $csd;
68              
69 0           return $self;
70             }
71              
72             1;