File Coverage

blib/lib/Image/ExifTool/PGF.pm
Criterion Covered Total %
statement 24 26 92.3
branch 4 10 40.0
condition 3 9 33.3
subroutine 4 4 100.0
pod 0 1 0.0
total 35 50 70.0


line stmt bran cond sub pod time code
1             #------------------------------------------------------------------------------
2             # File: PGF.pm
3             #
4             # Description: Read Progressive Graphics File meta information
5             #
6             # Revisions: 2011/01/25 - P. Harvey Created
7             #
8             # References: 1) http://www.libpgf.org/
9             # 2) http://www.exiv2.org/
10             #------------------------------------------------------------------------------
11              
12             package Image::ExifTool::PGF;
13              
14 1     1   4359 use strict;
  1         3  
  1         32  
15 1     1   6 use vars qw($VERSION);
  1         2  
  1         39  
16 1     1   5 use Image::ExifTool qw(:DataAccess :Utils);
  1         2  
  1         582  
17              
18             $VERSION = '1.02';
19              
20             # PGF header information
21             %Image::ExifTool::PGF::Main = (
22             GROUPS => { 0 => 'File', 1 => 'File', 2 => 'Image' },
23             PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
24             PRIORITY => 2, # (to take precedence over PNG tags from embedded image)
25             NOTES => q{
26             The following table lists information extracted from the header of
27             Progressive Graphics File (PGF) images. As well, information is extracted
28             from the embedded PNG metadata image if it exists. See
29             L for the PGF specification.
30             },
31             3 => {
32             Name => 'PGFVersion',
33             PrintConv => 'sprintf("0x%.2x", $val)',
34             # this is actually a bitmask (ref digikam PGFtypes.h):
35             # 0x02 - data structure PGFHeader of major version 2
36             # 0x04 - 32-bit values
37             # 0x08 - supports regions of interest
38             # 0x10 - new coding scheme since major version 5
39             # 0x20 - new HeaderSize: 32 bits instead of 16 bits
40             },
41             8 => { Name => 'ImageWidth', Format => 'int32u' },
42             12 => { Name => 'ImageHeight', Format => 'int32u' },
43             16 => 'PyramidLevels',
44             17 => 'Quality',
45             18 => 'BitsPerPixel',
46             19 => 'ColorComponents',
47             20 => {
48             Name => 'ColorMode',
49             RawConv => '$$self{PGFColorMode} = $val',
50             PrintConvColumns => 2,
51             PrintConv => {
52             0 => 'Bitmap',
53             1 => 'Grayscale',
54             2 => 'Indexed',
55             3 => 'RGB',
56             4 => 'CMYK',
57             7 => 'Multichannel',
58             8 => 'Duotone',
59             9 => 'Lab',
60             },
61             },
62             21 => { Name => 'BackgroundColor', Format => 'int8u[3]' },
63             );
64              
65             #------------------------------------------------------------------------------
66             # Extract information from a PGF image
67             # Inputs: 0) ExifTool object reference, 1) dirInfo reference
68             # Returns: 1 on success, 0 if this wasn't a valid PGF file
69             sub ProcessPGF($$)
70             {
71 1     1 0 3 my ($et, $dirInfo) = @_;
72 1         3 my $raf = $$dirInfo{RAF};
73 1         2 my $buff;
74              
75             # read header and check magic number
76 1 50 33     4 return 0 unless $raf->Read($buff, 24) == 24 and $buff =~ /^PGF(.)/s;
77 1         5 my $ver = ord $1;
78 1         8 $et->SetFileType();
79 1         17 SetByteOrder('II');
80              
81             # currently support only version 0x36
82 1 50       4 unless ($ver == 0x36) {
83 0         0 $et->Error(sprintf('Unsupported PGF version 0x%.2x', $ver));
84 0         0 return 1;
85             }
86             # extract information from the PGF header
87 1         3 my $tagTablePtr = GetTagTable('Image::ExifTool::PGF::Main');
88 1         8 $et->ProcessDirectory({ DataPt => \$buff, DataPos => 0 }, $tagTablePtr);
89              
90 1         6 my $len = Get32u(\$buff, 4) - 16; # length of post-header data
91              
92             # skip colour table if necessary
93 1 0       5 $len -= $raf->Seek(1024, 1) ? 1024 : $len if $$et{PGFColorMode} == 2;
    50          
94              
95             # extract information from the embedded metadata image (PNG format)
96 1 50 33     12 if ($len > 0 and $len < 0x1000000 and $raf->Read($buff, $len) == $len) {
      33        
97 1         28 $et->ExtractInfo(\$buff, { ReEntry => 1 });
98             }
99 1         4 return 1;
100             }
101              
102              
103             1; # end
104              
105             __END__