source: main/trunk/greenstone2/perllib/cpan/Image/ExifTool/Radiance.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.

File size: 4.6 KB
Line 
1#------------------------------------------------------------------------------
2# File: Radiance.pm
3#
4# Description: Read Radiance RGBE HDR meta information
5#
6# Revisions: 2011/12/10 - P. Harvey Created
7#
8# References: 1) http://www.graphics.cornell.edu/online/formats/rgbe/
9# 2) http://radsite.lbl.gov/radiance/refer/filefmts.pdf
10#------------------------------------------------------------------------------
11
12package Image::ExifTool::Radiance;
13
14use strict;
15use vars qw($VERSION);
16use Image::ExifTool qw(:DataAccess :Utils);
17
18$VERSION = '1.02';
19
20# Radiance tags
21%Image::ExifTool::Radiance::Main = (
22 GROUPS => { 2 => 'Image' },
23 NOTES => q{
24 Information extracted from Radiance RGBE HDR images. Tag ID's are all
25 uppercase as stored in the file, but converted to lowercase by when
26 extracting to avoid conflicts with internal ExifTool variables. See
27 L<http://radsite.lbl.gov/radiance/refer/filefmts.pdf> and
28 L<http://www.graphics.cornell.edu/online/formats/rgbe/> for the
29 specification.
30 },
31 _orient => {
32 Name => 'Orientation',
33 PrintConv => {
34 '-Y +X' => 'Horizontal (normal)',
35 '-Y -X' => 'Mirror horizontal',
36 '+Y -X' => 'Rotate 180',
37 '+Y +X' => 'Mirror vertical',
38 '+X -Y' => 'Mirror horizontal and rotate 270 CW',
39 '+X +Y' => 'Rotate 90 CW',
40 '-X +Y' => 'Mirror horizontal and rotate 90 CW',
41 '-X -Y' => 'Rotate 270 CW',
42 },
43 },
44 _command => 'Command',
45 _comment => 'Comment',
46 software => 'Software',
47 view => 'View',
48 'format' => 'Format', # <-- this is the one that caused the conflict when uppercase
49 exposure => {
50 Name => 'Exposure',
51 Notes => 'divide pixel values by this to get watts/steradian/meter^2',
52 },
53 gamma => 'Gamma',
54 colorcorr => 'ColorCorrection',
55 pixaspect => 'PixelAspectRatio',
56 primaries => 'ColorPrimaries',
57);
58
59#------------------------------------------------------------------------------
60# Extract information from a Radiance HDR file
61# Inputs: 0) ExifTool object reference, 1) DirInfo reference
62# Returns: 1 on success, 0 if this wasn't a valid RGBE image
63sub ProcessHDR($$)
64{
65 my ($et, $dirInfo) = @_;
66 my $raf = $$dirInfo{RAF};
67 my $buff;
68 local $/ = "\x0a"; # set newline character for reading
69
70 # verify this is a valid RIFF file
71 return 0 unless $raf->ReadLine($buff) and $buff =~ /^#\?(RADIANCE|RGBE)\x0a/s;
72 $et->SetFileType();
73 my $tagTablePtr = GetTagTable('Image::ExifTool::Radiance::Main');
74
75 while ($raf->ReadLine($buff)) {
76 chomp $buff;
77 last unless length($buff) > 0 and length($buff) < 4096;
78 if ($buff =~ s/^#\s*//) {
79 $et->HandleTag($tagTablePtr, '_comment', $buff) if length $buff;
80 next;
81 }
82 unless ($buff =~ /^(.*)?\s*=\s*(.*)/) {
83 $et->HandleTag($tagTablePtr, '_command', $buff) if length $buff;
84 next;
85 }
86 # use lower-case tag names to avoid conflicts with reserved tag table entries
87 my ($tag, $val) = (lc $1, $2);
88 my $tagInfo = $et->GetTagInfo($tagTablePtr, $tag);
89 unless ($tagInfo) {
90 my $name = $tag;
91 $name =~ tr/-_a-zA-Z0-9//dc;
92 next unless length($name) > 1;
93 $name = ucfirst $name;
94 $tagInfo = { Name => $name };
95 AddTagToTable($tagTablePtr, $tag, $tagInfo);
96 }
97 $et->FoundTag($tagInfo, $val);
98 }
99 # get image dimensions
100 if ($raf->ReadLine($buff) and $buff =~ /([-+][XY])\s*(\d+)\s*([-+][XY])\s*(\d+)/) {
101 $et->HandleTag($tagTablePtr, '_orient', "$1 $3");
102 $et->FoundTag('ImageHeight', $2);
103 $et->FoundTag('ImageWidth', $4);
104 }
105 return 1;
106}
107
1081; # end
109
110__END__
111
112=head1 NAME
113
114Image::ExifTool::Radiance - Read Radiance RGBE HDR meta information
115
116=head1 SYNOPSIS
117
118This module is used by Image::ExifTool
119
120=head1 DESCRIPTION
121
122This module contains definitions required by Image::ExifTool to extract meta
123information from Radiance RGBE images. RGBE (Red Green Blue Exponent)
124images are a type of high dynamic-range image.
125
126=head1 AUTHOR
127
128Copyright 2003-2021, Phil Harvey (philharvey66 at gmail.com)
129
130This library is free software; you can redistribute it and/or modify it
131under the same terms as Perl itself.
132
133=head1 REFERENCES
134
135=over 4
136
137=item L<http://radsite.lbl.gov/radiance/refer/filefmts.pdf>
138
139=item L<http://www.graphics.cornell.edu/online/formats/rgbe/>
140
141=back
142
143=head1 SEE ALSO
144
145L<Image::ExifTool::TagNames/Radiance Tags>,
146L<Image::ExifTool(3pm)|Image::ExifTool>
147
148=cut
149
Note: See TracBrowser for help on using the repository browser.