| 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 | 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 | # Radiance tags | ||||||||||||||||||||||||||||
| 21 | 1 | %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 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
ProcessHDR: called CC=14 SCAR=32.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | 1 | my ($et, $dirInfo) = @_; | |||||||||||||||||||||||||||
| 66 | 1 | my $raf = $$dirInfo{RAF}; | |||||||||||||||||||||||||||
| 67 | 1 | my $buff; | |||||||||||||||||||||||||||
| 68 | 1 | local $/ = "\x0a"; # set newline character for reading | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # verify this is a valid RIFF file | ||||||||||||||||||||||||||||
| 71 | 1 | ▶ | return 0 unless $raf->ReadLine($buff) and $buff =~ /^#\?(RADIANCE|RGBE)\x0a/s; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$raf->ReadLine($buff) and $buff =~ /^#\?(RADIANCE|RGBE)\x0a/s
MC/DC0%0/2
$raf->ReadLine($buff) and $buff =~ /^#\?(RADIANCE|RGBE)\x0a/s
$raf->ReadLine($buff)
$buff =~ /^#\?(RADIANCE|RGBE)\x0a/s
Truth table33%1/3
A and B
A= $raf->ReadLine($buff)B= $buff =~ /^#\?(RADIANCE|RGBE)\x0a/s
| |||||||||||||||||||||||||||||
| 72 | 1 | $et->SetFileType(); | |||||||||||||||||||||||||||
| 73 | 1 | my $tagTablePtr = GetTagTable('Image::ExifTool::Radiance::Main'); | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 1 | ▶ | while ($raf->ReadLine($buff)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 9 | chomp $buff; | |||||||||||||||||||||||||||
| 77 | 9 | ▶ | last unless length($buff) > 0 and length($buff) < 4096; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $buff > 0 and length $buff < 4096
MC/DC50%1/2
length $buff > 0 and length $buff < 4096
length $buff > 0
length $buff < 4096
Truth table66%2/3
A and B
A= length $buff > 0B= length $buff < 4096
| |||||||||||||||||||||||||||||
| 78 | 8 | ▶ | if ($buff =~ s/^#\s*//) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $et->HandleTag($tagTablePtr, '_comment', $buff) if length $buff; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | 0 | next; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | 8 | ▶ | unless ($buff =~ /^(.*)?\s*=\s*(.*)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | 4 | ▶ | $et->HandleTag($tagTablePtr, '_command', $buff) if length $buff; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 4 | next; | |||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | # use lower-case tag names to avoid conflicts with reserved tag table entries | ||||||||||||||||||||||||||||
| 87 | 4 | my ($tag, $val) = (lc $1, $2); | |||||||||||||||||||||||||||
| 88 | 4 | my $tagInfo = $et->GetTagInfo($tagTablePtr, $tag); | |||||||||||||||||||||||||||
| 89 | 4 | ▶ | unless ($tagInfo) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | my $name = $tag; | |||||||||||||||||||||||||||
| 91 | 0 | $name =~ tr/-_a-zA-Z0-9//dc; | |||||||||||||||||||||||||||
| 92 | 0 | ▶ | next unless length($name) > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | $name = ucfirst $name; | |||||||||||||||||||||||||||
| 94 | 0 | $tagInfo = { Name => $name }; | |||||||||||||||||||||||||||
| 95 | 0 | AddTagToTable($tagTablePtr, $tag, $tagInfo); | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | 4 | $et->FoundTag($tagInfo, $val); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | # get image dimensions | ||||||||||||||||||||||||||||
| 100 | 1 | ▶ | if ($raf->ReadLine($buff) and $buff =~ /([-+][XY])\s*(\d+)\s*([-+][XY])\s*(\d+)/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$raf->ReadLine($buff) and $buff =~ /([-+][XY])\s*(\d+)\s*([-+][XY])\s*(\d+)/
MC/DC0%0/2
$raf->ReadLine($buff) and $buff =~ /([-+][XY])\s*(\d+)\s*([-+][XY])\s*(\d+)/
$raf->ReadLine($buff)
$buff =~ /([-+][XY])\s*(\d+)\s*([-+][XY])\s*(\d+)/
Truth table33%1/3
A and B
A= $raf->ReadLine($buff)B= $buff =~ /([-+][XY])\s*(\d+)\s*([-+][XY])\s*(\d+)/
| |||||||||||||||||||||||||||||
| 101 | 1 | $et->HandleTag($tagTablePtr, '_orient', "$1 $3"); | |||||||||||||||||||||||||||
| 102 | 1 | $et->FoundTag('ImageHeight', $2); | |||||||||||||||||||||||||||
| 103 | 1 | $et->FoundTag('ImageWidth', $4); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | 1 | return 1; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 1 | 1; # end | |||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | __END__ | ||||||||||||||||||||||||||||