Image/ExifTool/PGF.pm

filter: Statementstmt 93.1% 27 / 29 Branchbran 40.0% 4 / 10 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 65.5% 38 / 58 CC 9 SCAR 23.6
CC
9
Cov
71%
ProcessPGF
13.8
BEGIN
1.0
BEGIN
1.0
CRAP 10.6
« Image/ExifTool/APP12.pm ↑ Summary Image/ExifTool/PSP.pm »
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Image::ExifTool qw(:DataAccess :Utils);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 $VERSION = '1.02';
19  
20 # PGF header information
21 1 %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<http://www.libpgf.org/> 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 1 ▶{
Subroutine ProcessPGF: called CC=9 SCAR=26.2
Pod undocumented
71 1 my ($et, $dirInfo) = @_;
72 1 my $raf = $$dirInfo{RAF};
73 1 my $buff;
74  
75 # read header and check magic number
76 1 ▶ return 0 unless $raf->Read($buff, 24) == 24 and $buff =~ /^PGF(.)/s;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($buff, 24) == 24 and $buff =~ /^PGF(.)/s 0 1 1
Condition33%1/3
$raf->Read($buff, 24) == 24 and $buff =~ /^PGF(.)/s
!ll&&!rl&&r
001
MC/DC0%0/2
$raf->Read($buff, 24) == 24 and $buff =~ /^PGF(.)/s
$raf->Read($buff, 24) == 24 $buff =~ /^PGF(.)/s
Truth table33%1/3
A and B
A= $raf->Read($buff, 24) == 24B= $buff =~ /^PGF(.)/s
ABresult
0X0
100
111
77 1 my $ver = ord $1;
78 1 $et->SetFileType();
79 1 SetByteOrder('II');
80  
81 # currently support only version 0x36
82 1 ▶ unless ($ver == 0x36) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ver == 54) 0 1 1
83 0 $et->Error(sprintf('Unsupported PGF version 0x%.2x', $ver));
84 0 return 1;
85 }
86 # extract information from the PGF header
87 1 my $tagTablePtr = GetTagTable('Image::ExifTool::PGF::Main');
88 1 $et->ProcessDirectory({ DataPt => \$buff, DataPos => 0 }, $tagTablePtr);
89  
90 1 my $len = Get32u(\$buff, 4) - 16; # length of post-header data
91  
92 # skip colour table if necessary
93 1 ▶ $len -= $raf->Seek(1024, 1) ? 1024 : $len if $$et{PGFColorMode} == 2;
Branch: 2 branches
BranchTrueFalseTotal
if $et->{"PGFColorMode"} == 2 0 1 1
$raf->Seek(1024, 1) ? : 0 0 0
94  
95 # extract information from the embedded metadata image (PNG format)
96 1 ▶ if ($len > 0 and $len < 0x1000000 and $raf->Read($buff, $len) == $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > 0 and $len < 16777216 and $raf->Read($buff, $len) == $len) 1 0 1
Condition33%2/6
$len > 0 and $len < 16777216 and $raf->Read($buff, $len) == $len
!ll&&!rl&&r
001
$len > 0 and $len < 16777216
!ll&&!rl&&r
001
MC/DC0%0/3
$len > 0 and $len < 16777216 and $raf->Read($buff, $len) == $len
$len > 0 $len < 16777216 $raf->Read($buff, $len) == $len
Truth table25%1/4
A and B and C
A= $len > 0B= $len < 16777216C= $raf->Read($buff, $len) == $len
ABCresult
0XX0
10X0
1100
1111
97 1 $et->ExtractInfo(\$buff, { ReEntry => 1 });
98 }
99 1 return 1;
100 }
101  
102  
103 1 1; # end
104  
105 __END__
« Image/ExifTool/APP12.pm ↑ Summary Image/ExifTool/PSP.pm »