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 |
|
---|
12 | package Image::ExifTool::Radiance;
|
---|
13 |
|
---|
14 | use strict;
|
---|
15 | use vars qw($VERSION);
|
---|
16 | use 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
|
---|
63 | sub 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 |
|
---|
108 | 1; # end
|
---|
109 |
|
---|
110 | __END__
|
---|
111 |
|
---|
112 | =head1 NAME
|
---|
113 |
|
---|
114 | Image::ExifTool::Radiance - Read Radiance RGBE HDR meta information
|
---|
115 |
|
---|
116 | =head1 SYNOPSIS
|
---|
117 |
|
---|
118 | This module is used by Image::ExifTool
|
---|
119 |
|
---|
120 | =head1 DESCRIPTION
|
---|
121 |
|
---|
122 | This module contains definitions required by Image::ExifTool to extract meta
|
---|
123 | information from Radiance RGBE images. RGBE (Red Green Blue Exponent)
|
---|
124 | images are a type of high dynamic-range image.
|
---|
125 |
|
---|
126 | =head1 AUTHOR
|
---|
127 |
|
---|
128 | Copyright 2003-2021, Phil Harvey (philharvey66 at gmail.com)
|
---|
129 |
|
---|
130 | This library is free software; you can redistribute it and/or modify it
|
---|
131 | under 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 |
|
---|
145 | L<Image::ExifTool::TagNames/Radiance Tags>,
|
---|
146 | L<Image::ExifTool(3pm)|Image::ExifTool>
|
---|
147 |
|
---|
148 | =cut
|
---|
149 |
|
---|