Image/ExifTool/FotoStation.pm

filter: Statementstmt 81.0% 60 / 74 Branchbran 52.6% 20 / 38 Conditioncond 55.0% 11 / 20 MC/DCmcdc 18.1% 2 / 11 Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 65.5% 97 / 148 CC 26 SCAR 38.9
CC
26
Cov
69%
ProcessFotoStation
54.4
BEGIN
1.0
BEGIN
1.0
CRAP 48.8
« Image/ExifTool/MISB.pm ↑ Summary Image/ExifTool/JVC.pm »
1 #------------------------------------------------------------------------------
2 # File: FotoStation.pm
3 #
4 # Description: Read/write FotoWare FotoStation trailer
5 #
6 # Revisions: 10/28/2006 - P. Harvey Created
7 #------------------------------------------------------------------------------
8  
9 package Image::ExifTool::FotoStation;
10  
11 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 13 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 13 ▶use Image::ExifTool qw(:DataAccess :Utils);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 13 $VERSION = '1.04';
16  
17 sub ProcessFotoStation($$);
18  
19 13 %Image::ExifTool::FotoStation::Main = (
20 PROCESS_PROC => \&ProcessFotoStation,
21 WRITE_PROC => \&ProcessFotoStation,
22 GROUPS => { 2 => 'Image' },
23 NOTES => q{
24 The following tables define information found in the FotoWare FotoStation
25 trailer.
26 },
27 0x01 => {
28 Name => 'IPTC',
29 SubDirectory => {
30 TagTable => 'Image::ExifTool::IPTC::Main',
31 },
32 },
33 0x02 => {
34 Name => 'SoftEdit',
35 SubDirectory => {
36 TagTable => 'Image::ExifTool::FotoStation::SoftEdit',
37 },
38 },
39 0x03 => {
40 Name => 'ThumbnailImage',
41 Groups => { 2 => 'Preview' },
42 Writable => 1,
43 RawConv => '$self->ValidateImage(\$val,$tag)',
44 },
45 0x04 => {
46 Name => 'PreviewImage',
47 Groups => { 2 => 'Preview' },
48 Writable => 1,
49 RawConv => '$self->ValidateImage(\$val,$tag)',
50 },
51 );
52  
53 # crop coordinate conversions
54 13 my %cropConv = (
55 ValueConv => '$val / 1000',
56 ValueConvInv => '$val * 1000',
57 PrintConv => '"$val%"',
58 PrintConvInv => '$val=~tr/ %//d; $val',
59 );
60  
61 # soft crop record
62 13 %Image::ExifTool::FotoStation::SoftEdit = (
63 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
64 WRITE_PROC => \&Image::ExifTool::WriteBinaryData,
65 CHECK_PROC => \&Image::ExifTool::CheckBinaryData,
66 WRITABLE => 1,
67 FORMAT => 'int32s',
68 FIRST_ENTRY => 0,
69 GROUPS => { 2 => 'Image' },
70 0 => {
71 Name => 'OriginalImageWidth',
72 },
73 1 => 'OriginalImageHeight',
74 2 => 'ColorPlanes',
75 3 => {
76 Name => 'XYResolution',
77 ValueConv => '$val / 1000',
78 ValueConvInv => '$val * 1000',
79 },
80 4 => {
81 Name => 'Rotation',
82 Notes => q{
83 rotations are stored as degrees CCW * 100, but converted to degrees CW by
84 ExifTool
85 },
86 # raw value is 0, 9000, 18000 or 27000
87 ValueConv => '$val ? 360 - $val / 100 : 0',
88 ValueConvInv => '$val ? (360 - $val) * 100 : 0',
89 },
90 # 5 Validity Check (0x11222211)
91 6 => {
92 Name => 'CropLeft',
93 %cropConv,
94 },
95 7 => {
96 Name => 'CropTop',
97 %cropConv,
98 },
99 8 => {
100 Name => 'CropRight',
101 %cropConv,
102 },
103 9 => {
104 Name => 'CropBottom',
105 %cropConv,
106 },
107 11 => {
108 Name => 'CropRotation',
109 # raw value in the range -4500 to 4500
110 ValueConv => '-$val / 100',
111 ValueConvInv => '-$val * 100',
112 },
113 );
114  
115 #------------------------------------------------------------------------------
116 # Read/write FotoStation information in a file
117 # Inputs: 0) ExifTool object reference, 1) dirInfo reference
118 # Returns: 1 on success, 0 if this file didn't contain FotoStation information
119 # - updates DataPos to point to start of FotoStation information
120 # - updates DirLen to trailer length
121 sub ProcessFotoStation($$)
122 67 ▶{
Subroutine ProcessFotoStation: called CC=26 SCAR=40.0
Pod undocumented
123 67 my ($et, $dirInfo) = @_;
124 67 ▶ $et or return 1; # allow dummy access to autoload this package
Branch: 1 branch
BranchTrueFalseTotal
$et or return 1 29 38 67
125 29 my ($buff, $footer, $dirBuff, $tagTablePtr);
126 29 my $raf = $$dirInfo{RAF};
127 29 my $outfile = $$dirInfo{OutFile};
128 29 ▶ my $offset = $$dirInfo{Offset} || 0;
Condition100%2/2
$dirInfo->{'Offset'} || 0
l!l
263
MC/DC100%1/1
$dirInfo->{'Offset'} || 0
$dirInfo->{'Offset'}
Truth table100%2/2
A
A= $dirInfo->{'Offset'}
Aresult
11
00
129 29 my $verbose = $et->Options('Verbose');
130 29 my $out = $et->Options('TextOut');
131 29 my $rtnVal = 0;
132  
133 29 $$dirInfo{DirLen} = 0; # initialize returned trailer length
134 29 $raf->Seek(-$offset, 2); # seek to specified offset from end of file
135  
136 # loop through FotoStation records
137 29 for (;;) {
138 # look for trailer signature
139 87 ▶ last unless $raf->Seek(-10, 1) and $raf->Read($footer, 10) == 10;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Seek(-10, 1) and $raf->Read($footer, 10) == 10 0 87 87
Condition33%1/3
$raf->Seek(-10, 1) and $raf->Read($footer, 10) == 10
!ll&&!rl&&r
0087
MC/DC0%0/2
$raf->Seek(-10, 1) and $raf->Read($footer, 10) == 10
$raf->Seek(-10, 1) $raf->Read($footer, 10) == 10
Truth table33%1/3
A and B
A= $raf->Seek(-10, 1)B= $raf->Read($footer, 10) == 10
ABresult
0X0
100
111
140 87 my ($tag, $size, $sig) = unpack('nNN', $footer);
141 87 ▶ last unless $sig == 0xa1b2c3d4 and $size >= 10 and $raf->Seek(-$size, 1);
Branch: 1 branch
BranchTrueFalseTotal
unless $sig == 2712847316 and $size >= 10 and $raf->Seek(-$size, 1) 29 58 87
Condition66%4/6
$sig == 2712847316 and $size >= 10 and $raf->Seek(-$size, 1)
!ll&&!rl&&r
29058
$sig == 2712847316 and $size >= 10
!ll&&!rl&&r
29058
MC/DC33%1/3
$sig == 2712847316 and $size >= 10 and $raf->Seek(-$size, 1)
$sig == 2712847316 $size >= 10 $raf->Seek(-$size, 1)
Truth table50%2/4
A and B and C
A= $sig == 2712847316B= $size >= 10C= $raf->Seek(-$size, 1)
ABCresult
0XX0
10X0
1100
1111
142 58 $size -= 10; # size of data only
143 58 ▶ last unless $raf->Read($buff, $size) == $size;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($buff, $size) == $size 0 58 58
144 58 $raf->Seek(-$size, 1);
145 # set variables returned in dirInfo hash
146 58 $$dirInfo{DataPos} = $raf->Tell();
147 58 $$dirInfo{DirLen} += $size + 10;
148  
149 58 ▶ unless ($tagTablePtr) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagTablePtr) 29 29 58
150 29 $tagTablePtr = GetTagTable('Image::ExifTool::FotoStation::Main');
151 29 SetByteOrder('MM'); # necessary for the binary data
152 29 $rtnVal = 1; # we found a valid FotoStation trailer
153 }
154 58 ▶ unless ($outfile) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($outfile) 42 16 58
155 # print verbose trailer information
156 42 ▶ if ($verbose or $$et{HTML_DUMP}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose or $et->{"HTML_DUMP"}) 0 42 42
Condition33%1/3
$verbose or $et->{"HTML_DUMP"}
l!l&&r!l&&!r
0042
MC/DC0%0/2
$verbose or $et->{"HTML_DUMP"}
$verbose $et->{"HTML_DUMP"}
Truth table33%1/3
A or B
A= $verboseB= $et->{"HTML_DUMP"}
ABresult
1X1
011
000
157 $et->DumpTrailer({
158 RAF => $raf,
159 DataPos => $$dirInfo{DataPos},
160 0 DirLen => $size + 10,
161 DirName => "FotoStation_$tag",
162 });
163 }
164 # extract information for this tag
165 $et->HandleTag($tagTablePtr, $tag, $buff,
166 DataPt => \$buff,
167 Start => 0,
168 Size => $size,
169 DataPos => $$dirInfo{DataPos},
170 42 );
171 42 next;
172 }
173 16 ▶ if ($$et{DEL_GROUP}{FotoStation}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"DEL_GROUP"}{"FotoStation"}) 0 16 16
174 0 ▶ $verbose and print $out " Deleting FotoStation trailer\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out " Deleting FotoStation trailer\n" 0 0 0
175 0 $verbose = 0; # no more verbose messages after this
176 0 ++$$et{CHANGED};
177 0 next;
178 }
179 # rewrite this information
180 16 my $tagInfo = $et->GetTagInfo($tagTablePtr, $tag);
181 16 ▶ if ($tagInfo) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo) 16 0 16
182 16 my $newVal;
183 16 my $tagName = $$tagInfo{Name};
184 16 ▶ if ($$tagInfo{SubDirectory}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tagInfo->{'SubDirectory'}) { } 16 0 16
185 my %subdirInfo = (
186 DataPt => \$buff,
187 DirStart => 0,
188 DirLen => $size,
189 DataPos => $$dirInfo{DataPos},
190 16 DirName => $tagName,
191 Parent => 'FotoStation',
192 );
193 16 my $subTable = GetTagTable($tagInfo->{SubDirectory}->{TagTable});
194 16 $newVal = $et->WriteDirectory(\%subdirInfo, $subTable);
195 } else {
196 0 my $nvHash = $et->GetNewValueHash($tagInfo);
197 0 ▶ if ($et->IsOverwriting($nvHash) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->IsOverwriting($nvHash) > 0) 0 0 0
198 0 $newVal = $et->GetNewValue($nvHash);
199 0 ▶ $newVal = '' unless defined $newVal;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $newVal 0 0 0
200 0 ▶ if ($verbose > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verbose > 1) 0 0 0
201 0 my $n = length $newVal;
202 0 ▶ print $out " - FotoStation:$tagName ($size bytes)\n" if $size;
Branch: 1 branch
BranchTrueFalseTotal
if $size 0 0 0
203 0 ▶ print $out " + FotoStation:$tagName ($n bytes)\n" if $n;
Branch: 1 branch
BranchTrueFalseTotal
if $n 0 0 0
204 }
205 0 ++$$et{CHANGED};
206 }
207 }
208 16 ▶ if (defined $newVal) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newVal) 9 7 16
209 # note: length may be 0 here, but we write the empty record anyway
210 9 $buff = $newVal;
211 9 $size = length($newVal) + 10;
212 9 $footer = pack('nNN', $tag, $size, $sig);
213 }
214 }
215 16 ▶ if (defined $dirBuff) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dirBuff) { } 8 8 16
216 # maintain original record order
217 8 $dirBuff = $buff . $footer . $dirBuff;
218 } else {
219 8 $dirBuff = $buff . $footer;
220 }
221 }
222 # write the modified FotoStation trailer
223 29 ▶ Write($outfile, $dirBuff) or $rtnVal = -1 if $dirBuff;
Branch: 1 branch
BranchTrueFalseTotal
if $dirBuff 8 21 29
Condition50%3/6
$dirBuff && (&Write($outfile, $dirBuff) || ($rtnVal = -1))
!ll&&!rl&&r
2180
&Write($outfile, $dirBuff) or $rtnVal = -1
l!l&&r!l&&!r
800
MC/DC0%0/3
$dirBuff && (&Write($outfile, $dirBuff) || ($rtnVal = -1))
$dirBuff &Write($outfile, $dirBuff) $rtnVal = -1
Truth table0%0/4
A && B or C
A= $dirBuffB= &Write($outfile, $dirBuff)C= $rtnVal = -1
ABCresult
0XX0
1000
11X1
1011
224 29 return $rtnVal;
225 }
226  
227 13 1; # end
228  
229 __END__
« Image/ExifTool/MISB.pm ↑ Summary Image/ExifTool/JVC.pm »