Radiance.pm 4.4 KB

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