PGF.pm 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. package Image::ExifTool::PGF;
  12. use strict;
  13. use vars qw($VERSION);
  14. use Image::ExifTool qw(:DataAccess :Utils);
  15. $VERSION = '1.02';
  16. # PGF header information
  17. %Image::ExifTool::PGF::Main = (
  18. GROUPS => { 0 => 'File', 1 => 'File', 2 => 'Image' },
  19. PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
  20. PRIORITY => 2, # (to take precedence over PNG tags from embedded image)
  21. NOTES => q{
  22. The following table lists information extracted from the header of
  23. Progressive Graphics File (PGF) images. As well, information is extracted
  24. from the embedded PNG metadata image if it exists. See
  25. L<http://www.libpgf.org/> for the PGF specification.
  26. },
  27. 3 => {
  28. Name => 'PGFVersion',
  29. PrintConv => 'sprintf("0x%.2x", $val)',
  30. # this is actually a bitmask (ref digikam PGFtypes.h):
  31. # 0x02 - data structure PGFHeader of major version 2
  32. # 0x04 - 32-bit values
  33. # 0x08 - supports regions of interest
  34. # 0x10 - new coding scheme since major version 5
  35. # 0x20 - new HeaderSize: 32 bits instead of 16 bits
  36. },
  37. 8 => { Name => 'ImageWidth', Format => 'int32u' },
  38. 12 => { Name => 'ImageHeight', Format => 'int32u' },
  39. 16 => 'PyramidLevels',
  40. 17 => 'Quality',
  41. 18 => 'BitsPerPixel',
  42. 19 => 'ColorComponents',
  43. 20 => {
  44. Name => 'ColorMode',
  45. RawConv => '$$self{PGFColorMode} = $val',
  46. PrintConvColumns => 2,
  47. PrintConv => {
  48. 0 => 'Bitmap',
  49. 1 => 'Grayscale',
  50. 2 => 'Indexed',
  51. 3 => 'RGB',
  52. 4 => 'CMYK',
  53. 7 => 'Multichannel',
  54. 8 => 'Duotone',
  55. 9 => 'Lab',
  56. },
  57. },
  58. 21 => { Name => 'BackgroundColor', Format => 'int8u[3]' },
  59. );
  60. #------------------------------------------------------------------------------
  61. # Extract information from a PGF image
  62. # Inputs: 0) ExifTool object reference, 1) dirInfo reference
  63. # Returns: 1 on success, 0 if this wasn't a valid PGF file
  64. sub ProcessPGF($$)
  65. {
  66. my ($et, $dirInfo) = @_;
  67. my $raf = $$dirInfo{RAF};
  68. my $buff;
  69. # read header and check magic number
  70. return 0 unless $raf->Read($buff, 24) == 24 and $buff =~ /^PGF(.)/s;
  71. my $ver = ord $1;
  72. $et->SetFileType();
  73. SetByteOrder('II');
  74. # currently support only version 0x36
  75. unless ($ver == 0x36) {
  76. $et->Error(sprintf('Unsupported PGF version 0x%.2x', $ver));
  77. return 1;
  78. }
  79. # extract information from the PGF header
  80. my $tagTablePtr = GetTagTable('Image::ExifTool::PGF::Main');
  81. $et->ProcessDirectory({ DataPt => \$buff, DataPos => 0 }, $tagTablePtr);
  82. my $len = Get32u(\$buff, 4) - 16; # length of post-header data
  83. # skip colour table if necessary
  84. $len -= $raf->Seek(1024, 1) ? 1024 : $len if $$et{PGFColorMode} == 2;
  85. # extract information from the embedded metadata image (PNG format)
  86. if ($len > 0 and $len < 0x1000000 and $raf->Read($buff, $len) == $len) {
  87. $et->ExtractInfo(\$buff, { ReEntry => 1 });
  88. }
  89. return 1;
  90. }
  91. 1; # end
  92. __END__
  93. =head1 NAME
  94. Image::ExifTool::PGF - Read Progressive Graphics File meta information
  95. =head1 SYNOPSIS
  96. This module is used by Image::ExifTool
  97. =head1 DESCRIPTION
  98. This module contains definitions required by Image::ExifTool to extract meta
  99. information from Progressive Graphics File (PGF) images.
  100. =head1 AUTHOR
  101. Copyright 2003-2016, Phil Harvey (phil at owl.phy.queensu.ca)
  102. This library is free software; you can redistribute it and/or modify it
  103. under the same terms as Perl itself.
  104. =head1 REFERENCES
  105. =over 4
  106. =item L<http://www.libpgf.org/>
  107. =item L<http://www.exiv2.org/>
  108. =back
  109. =head1 SEE ALSO
  110. L<Image::ExifTool::TagNames/PGF Tags>,
  111. L<Image::ExifTool(3pm)|Image::ExifTool>
  112. =cut