summaryrefslogtreecommitdiff
path: root/lib/Image/ExifTool/Scalado.pm
blob: b9fd5874657850cfe84060e457b62ec2ff603b0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#------------------------------------------------------------------------------
# File:         Scalado.pm
#
# Description:  Read APP4 SCALADO metadata
#
# Revisions:    2013-09-13 - P. Harvey Created
#------------------------------------------------------------------------------

package Image::ExifTool::Scalado;

use strict;
use vars qw($VERSION);
use Image::ExifTool qw(:DataAccess :Utils);
use Image::ExifTool::PLIST;

$VERSION = '1.01';

sub ProcessScalado($$$);

# JPEG APP4 SCALADO tags
%Image::ExifTool::Scalado::Main = (
    GROUPS => { 0 => 'APP4', 1 => 'Scalado', 2 => 'Image' },
    PROCESS_PROC => \&ProcessScalado,
    TAG_PREFIX => 'Scalado',
    FORMAT => 'int32s',
    NOTES => q{
        Tags extracted from the JPEG APP4 "SCALADO" segment found in images from
        HTC, LG and Samsung phones.  (Presumably written by Scalado mobile software,
        L<http://www.scalado.com/>.)
    },
    SPMO => {
        Name => 'DataLength',
        Unknown => 1,
    },
    WDTH => {
        Name => 'PreviewImageWidth',
        ValueConv => '$val ? abs($val) : undef',
    },
    HGHT => {
        Name => 'PreviewImageHeight',
        ValueConv => '$val ? abs($val) : undef',
    },
    QUAL => {
        Name => 'PreviewQuality',
        ValueConv => '$val ? abs($val) : undef',
    },
    # tags not yet decoded with observed values:
    # CHKH: 0, various negative values
    # CHKL: various negative values
    # CLEN: -1024
    # CSPC: -2232593
    # DATA: (+ve data length)
    # HDEC: 0
    # MAIN: 0, 60
    # META: 24
    # SCI0: (+ve data length) often 36
    # SCI1: (+ve data length) 36
    # SCX0: (+ve data length)
    # SCX1: (+ve data length) often 84
    # WDEC: 0
    # VERS: -131328
);

#------------------------------------------------------------------------------
# Extract information from the JPEG APP4 SCALADO segment
# Inputs: 0) ExifTool object ref, 1) dirInfo ref, 2) tag table ref
# Returns: 1 on success
sub ProcessScalado($$$)
{
    my ($et, $dirInfo, $tagTablePtr) = @_;
    my $dataPt = $$dirInfo{DataPt};
    my $pos = 0;
    my $end = length $$dataPt;
    my $unknown = $et->Options('Unknown');

    $et->VerboseDir('APP4 SCALADO', undef, $end);
    SetByteOrder('MM');

    for (;;) {
        last if $pos + 12 > $end;
        my $tag = substr($$dataPt, $pos, 4);
        my $ver = Get32u($dataPt, $pos + 4); # (looks like a version for some tags)
        if (not $$tagTablePtr{$tag} and $unknown) {
            my $name = $tag;
            $name =~ tr/-A-Za-z0-9_//dc;
            last unless length $name;   # stop if tag is garbage
            AddTagToTable($tagTablePtr, $tag, {
                Name => "Scalado_$name",
                Description => "Scalado $name",
                Unknown => 1,
            });
        }
        $et->HandleTag($tagTablePtr, $tag, undef,
            DataPt  => $dataPt,
            Start   => $pos + 8,
            Size    => 4,
            Extra   => ", ver $ver",
        );
        if ($tag eq 'SPMO') {
            my $val = Get32u($dataPt, $pos + 8) ;
            if ($ver < 5) { # (I don't have samples for version 3 or 4, so I'm not sure about these)
                $end -= $val;     # SPMO gives trailer data length
            } else {
                $end = $val + 12; # SPMO gives length of Scalado directory (excepting this entry)
            }
        }
        $pos += 12;
    }
    return 1;
}

1;  # end

__END__

=head1 NAME

Image::ExifTool::Scalado - Read APP4 SCALADO metadata

=head1 SYNOPSIS

This module is loaded automatically by Image::ExifTool when required.

=head1 DESCRIPTION

This module contains definitions required by Image::ExifTool to read
metadata from the JPEG APP4 SCALADO segment.

=head1 AUTHOR

Copyright 2003-2019, Phil Harvey (phil at owl.phy.queensu.ca)

This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=head1 SEE ALSO

L<Image::ExifTool::TagNames/Scalado Tags>,
L<Image::ExifTool(3pm)|Image::ExifTool>

=cut