source: main/trunk/greenstone2/perllib/cpan/Image/ExifTool/PGF.pm@ 34921

Last change on this file since 34921 was 34921, checked in by anupama, 3 years ago

Committing the improvements to EmbeddedMetaPlugin's processing of Keywords vs other metadata fields. Keywords were literally stored as arrays of words rather than phrases in PDFs (at least in Diego's sample PDF), whereas other meta fields like Subjects and Creators stored them as arrays of phrases. To get both to work, Kathy updated EXIF to a newer version, to retrieve the actual EXIF values stored in the PDF. And Kathy and Dr Bainbridge came up with a new option that I added called apply_join_before_split_to_metafields that's a regex which can list the metadata fields to apply the join_before_split to and whcih previously always got applied to all metadata fields. Now it's applied to any *Keywords metafields by default, as that's the metafield we have experience of that behaves differently to the others, as it stores by word instead of phrases. Tested on Diego's sample PDF. Diego has double-checked it to works on his sample PDF too, setting the split char to ; and turning on the join_before_split and leaving apply_join_before_split_to_metafields at its default of .*Keywords. File changes are strings.properties for the tooltip, the plugin introducing the option and working with it and Kathy's EXIF updates affecting cpan/File and cpan/Image.

  • Property svn:executable set to *
File size: 4.0 KB
Line 
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
12package Image::ExifTool::PGF;
13
14use strict;
15use vars qw($VERSION);
16use Image::ExifTool qw(:DataAccess :Utils);
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<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
69sub ProcessPGF($$)
70{
71 my ($et, $dirInfo) = @_;
72 my $raf = $$dirInfo{RAF};
73 my $buff;
74
75 # read header and check magic number
76 return 0 unless $raf->Read($buff, 24) == 24 and $buff =~ /^PGF(.)/s;
77 my $ver = ord $1;
78 $et->SetFileType();
79 SetByteOrder('II');
80
81 # currently support only version 0x36
82 unless ($ver == 0x36) {
83 $et->Error(sprintf('Unsupported PGF version 0x%.2x', $ver));
84 return 1;
85 }
86 # extract information from the PGF header
87 my $tagTablePtr = GetTagTable('Image::ExifTool::PGF::Main');
88 $et->ProcessDirectory({ DataPt => \$buff, DataPos => 0 }, $tagTablePtr);
89
90 my $len = Get32u(\$buff, 4) - 16; # length of post-header data
91
92 # skip colour table if necessary
93 $len -= $raf->Seek(1024, 1) ? 1024 : $len if $$et{PGFColorMode} == 2;
94
95 # extract information from the embedded metadata image (PNG format)
96 if ($len > 0 and $len < 0x1000000 and $raf->Read($buff, $len) == $len) {
97 $et->ExtractInfo(\$buff, { ReEntry => 1 });
98 }
99 return 1;
100}
101
102
1031; # end
104
105__END__
106
107=head1 NAME
108
109Image::ExifTool::PGF - Read Progressive Graphics File meta information
110
111=head1 SYNOPSIS
112
113This module is used by Image::ExifTool
114
115=head1 DESCRIPTION
116
117This module contains definitions required by Image::ExifTool to extract meta
118information from Progressive Graphics File (PGF) images.
119
120=head1 AUTHOR
121
122Copyright 2003-2021, Phil Harvey (philharvey66 at gmail.com)
123
124This library is free software; you can redistribute it and/or modify it
125under the same terms as Perl itself.
126
127=head1 REFERENCES
128
129=over 4
130
131=item L<http://www.libpgf.org/>
132
133=item L<http://www.exiv2.org/>
134
135=back
136
137=head1 SEE ALSO
138
139L<Image::ExifTool::TagNames/PGF Tags>,
140L<Image::ExifTool(3pm)|Image::ExifTool>
141
142=cut
143
Note: See TracBrowser for help on using the repository browser.