Scalado.pm 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #------------------------------------------------------------------------------
  2. # File: Scalado.pm
  3. #
  4. # Description: Read APP4 SCALADO metadata
  5. #
  6. # Revisions: 2013-09-13 - P. Harvey Created
  7. #------------------------------------------------------------------------------
  8. package Image::ExifTool::Scalado;
  9. use strict;
  10. use vars qw($VERSION);
  11. use Image::ExifTool qw(:DataAccess :Utils);
  12. use Image::ExifTool::PLIST;
  13. $VERSION = '1.01';
  14. sub ProcessScalado($$$);
  15. # JPEG APP4 SCALADO tags
  16. %Image::ExifTool::Scalado::Main = (
  17. GROUPS => { 0 => 'APP4', 1 => 'Scalado', 2 => 'Image' },
  18. PROCESS_PROC => \&ProcessScalado,
  19. TAG_PREFIX => 'Scalado',
  20. FORMAT => 'int32s',
  21. NOTES => q{
  22. Tags extracted from the JPEG APP4 "SCALADO" segment found in images from
  23. HTC, LG and Samsung phones. (Presumably written by Scalado mobile software,
  24. L<http://www.scalado.com/>.)
  25. },
  26. SPMO => {
  27. Name => 'DataLength',
  28. Unknown => 1,
  29. },
  30. WDTH => {
  31. Name => 'PreviewImageWidth',
  32. ValueConv => '$val ? abs($val) : undef',
  33. },
  34. HGHT => {
  35. Name => 'PreviewImageHeight',
  36. ValueConv => '$val ? abs($val) : undef',
  37. },
  38. QUAL => {
  39. Name => 'PreviewQuality',
  40. ValueConv => '$val ? abs($val) : undef',
  41. },
  42. # tags not yet decoded with observed values:
  43. # CHKH: 0, various negative values
  44. # CHKL: various negative values
  45. # CLEN: -1024
  46. # CSPC: -2232593
  47. # DATA: (+ve data length)
  48. # HDEC: 0
  49. # MAIN: 0, 60
  50. # META: 24
  51. # SCI0: (+ve data length) often 36
  52. # SCI1: (+ve data length) 36
  53. # SCX0: (+ve data length)
  54. # SCX1: (+ve data length) often 84
  55. # WDEC: 0
  56. # VERS: -131328
  57. );
  58. #------------------------------------------------------------------------------
  59. # Extract information from the JPEG APP4 SCALADO segment
  60. # Inputs: 0) ExifTool object ref, 1) dirInfo ref, 2) tag table ref
  61. # Returns: 1 on success
  62. sub ProcessScalado($$$)
  63. {
  64. my ($et, $dirInfo, $tagTablePtr) = @_;
  65. my $dataPt = $$dirInfo{DataPt};
  66. my $pos = 0;
  67. my $end = length $$dataPt;
  68. my $unknown = $et->Options('Unknown');
  69. $et->VerboseDir('APP4 SCALADO', undef, $end);
  70. SetByteOrder('MM');
  71. for (;;) {
  72. last if $pos + 12 > $end;
  73. my $tag = substr($$dataPt, $pos, 4);
  74. my $ver = Get32u($dataPt, $pos + 4); # (looks like a version for some tags)
  75. if (not $$tagTablePtr{$tag} and $unknown) {
  76. my $name = $tag;
  77. $name =~ tr/-A-Za-z0-9_//dc;
  78. last unless length $name; # stop if tag is garbage
  79. AddTagToTable($tagTablePtr, $tag, {
  80. Name => "Scalado_$name",
  81. Description => "Scalado $name",
  82. Unknown => 1,
  83. });
  84. }
  85. $et->HandleTag($tagTablePtr, $tag, undef,
  86. DataPt => $dataPt,
  87. Start => $pos + 8,
  88. Size => 4,
  89. Extra => ", ver $ver",
  90. );
  91. if ($tag eq 'SPMO') {
  92. my $val = Get32u($dataPt, $pos + 8) ;
  93. if ($ver < 5) { # (I don't have samples for version 3 or 4, so I'm not sure about these)
  94. $end -= $val; # SPMO gives trailer data length
  95. } else {
  96. $end = $val + 12; # SPMO gives length of Scalado directory (excepting this entry)
  97. }
  98. }
  99. $pos += 12;
  100. }
  101. return 1;
  102. }
  103. 1; # end
  104. __END__
  105. =head1 NAME
  106. Image::ExifTool::Scalado - Read APP4 SCALADO metadata
  107. =head1 SYNOPSIS
  108. This module is loaded automatically by Image::ExifTool when required.
  109. =head1 DESCRIPTION
  110. This module contains definitions required by Image::ExifTool to read
  111. metadata from the JPEG APP4 SCALADO segment.
  112. =head1 AUTHOR
  113. Copyright 2003-2016, Phil Harvey (phil at owl.phy.queensu.ca)
  114. This library is free software; you can redistribute it and/or modify it
  115. under the same terms as Perl itself.
  116. =head1 SEE ALSO
  117. L<Image::ExifTool::TagNames/Scalado Tags>,
  118. L<Image::ExifTool(3pm)|Image::ExifTool>
  119. =cut