Image/ExifTool/PhotoMechanic.pm

filter: Statementstmt 90.7% 59 / 65 Branchbran 54.5% 12 / 22 Conditioncond 42.8% 6 / 14 MC/DCmcdc 11.1% 1 / 9 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 1 totaltotal 72.0% 85 / 118 CC 17 SCAR 29.7
CC
17
Cov
76%
ProcessPhotoMechanic
26.1
BEGIN
1.0
BEGIN
1.0
CRAP 19.6
« Image/ExifTool/DSF.pm ↑ Summary Image/ExifTool/GPS.pm »
1 #------------------------------------------------------------------------------
2 # File: PhotoMechanic.pm
3 #
4 # Description: Read/write Camera Bits Photo Mechanic information
5 #
6 # Revisions: 10/28/2006 - P. Harvey Created
7 #------------------------------------------------------------------------------
8  
9 package Image::ExifTool::PhotoMechanic;
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 13 ▶use Image::ExifTool::Exif;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 13 ▶use Image::ExifTool::IPTC;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 13 ▶use Image::ExifTool::XMP;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 13 $VERSION = '1.08';
19  
20 sub ProcessPhotoMechanic($$);
21  
22 # color class names
23 13 my %colorClasses = (
24 0 => '0 (None)',
25 1 => '1 (Winner)',
26 2 => '2 (Winner alt)',
27 3 => '3 (Superior)',
28 4 => '4 (Superior alt)',
29 5 => '5 (Typical)',
30 6 => '6 (Typical alt)',
31 7 => '7 (Extras)',
32 8 => '8 (Trash)',
33 );
34  
35 # main tag table IPTC-format records in PhotoMechanic trailer
36 13 %Image::ExifTool::PhotoMechanic::Main = (
37 GROUPS => { 2 => 'Image' },
38 PROCESS_PROC => \&Image::ExifTool::IPTC::ProcessIPTC,
39 WRITE_PROC => \&Image::ExifTool::IPTC::WriteIPTC,
40 NOTES => q{
41 The Photo Mechanic trailer contains data in an IPTC-format structure, with
42 soft edit information stored under record number 2.
43 },
44 2 => {
45 Name => 'SoftEdit',
46 SubDirectory => {
47 TagTable => 'Image::ExifTool::PhotoMechanic::SoftEdit',
48 },
49 },
50 );
51  
52 # raw/preview crop coordinate conversions
53 13 my %rawCropConv = (
54 ValueConv => '$val / 655.36',
55 ValueConvInv => 'int($val * 655.36 + 0.5)',
56 PrintConv => 'sprintf("%.3f%%",$val)',
57 PrintConvInv => '$val=~tr/ %//d; $val',
58 );
59  
60 # Record 2 -- PhotoMechanic soft edit information
61 13 %Image::ExifTool::PhotoMechanic::SoftEdit = (
62 GROUPS => { 2 => 'Image' },
63 WRITE_PROC => \&Image::ExifTool::IPTC::WriteIPTC,
64 CHECK_PROC => \&Image::ExifTool::IPTC::CheckIPTC,
65 WRITABLE => 1,
66 FORMAT => 'int32s',
67 209 => { Name => 'RawCropLeft', %rawCropConv },
68 210 => { Name => 'RawCropTop', %rawCropConv },
69 211 => { Name => 'RawCropRight', %rawCropConv },
70 212 => { Name => 'RawCropBottom', %rawCropConv },
71 213 => 'ConstrainedCropWidth',
72 214 => 'ConstrainedCropHeight',
73 215 => 'FrameNum',
74 216 => {
75 Name => 'Rotation',
76 PrintConv => {
77 0 => '0',
78 1 => '90',
79 2 => '180',
80 3 => '270',
81 },
82 },
83 217 => 'CropLeft',
84 218 => 'CropTop',
85 219 => 'CropRight',
86 220 => 'CropBottom',
87 221 => {
88 Name => 'Tagged',
89 PrintConv => { 0 => 'No', 1 => 'Yes' },
90 },
91 222 => {
92 Name => 'ColorClass',
93 PrintConv => \%colorClasses,
94 },
95 223 => 'Rating',
96 236 => { Name => 'PreviewCropLeft', %rawCropConv },
97 237 => { Name => 'PreviewCropTop', %rawCropConv },
98 238 => { Name => 'PreviewCropRight', %rawCropConv },
99 239 => { Name => 'PreviewCropBottom', %rawCropConv },
100 );
101  
102 # PhotoMechanic XMP properties
103 13 %Image::ExifTool::PhotoMechanic::XMP = (
104 GROUPS => { 0 => 'XMP', 1 => 'XMP-photomech', 2 => 'Image' },
105 NAMESPACE => { photomechanic => 'http://ns.camerabits.com/photomechanic/1.0/' },
106 WRITE_PROC => \&Image::ExifTool::XMP::WriteXMP,
107 WRITABLE => 'string',
108 NOTES => q{
109 Below is a list of the observed PhotoMechanic XMP tags. The actual
110 namespace prefix is "photomechanic" but ExifTool shortens this in
111 the family 1 group name.
112 },
113 ColorClass => {
114 Writable => 'integer',
115 PrintConv => \%colorClasses,
116 },
117 CountryCode => { Avoid => 1, Groups => { 2 => 'Location' } },
118 EditStatus => { },
119 PMVersion => { },
120 Prefs => {
121 Notes => 'format is "Tagged:0, ColorClass:1, Rating:2, FrameNum:3"',
122 PrintConv => q{
123 $val =~ s[\s*(\d+):\s*(\d+):\s*(\d+):\s*(\S*)]
124 [Tagged:$1, ColorClass:$2, Rating:$3, FrameNum:$4];
125 return $val;
126 },
127 PrintConvInv => q{
128 $val =~ s[Tagged:\s*(\d+).*ColorClass:\s*(\d+).*Rating:\s*(\d+).*FrameNum:\s*(\S*)]
129 [$1:$2:$3:$4]is;
130 return $val;
131 },
132 },
133 Tagged => { Writable => 'boolean', PrintConv => { False => 'No', True => 'Yes' } },
134 TimeCreated => {
135 Avoid => 1,
136 Groups => { 2 => 'Time' },
137 Shift => 'Time',
138 ValueConv => 'Image::ExifTool::Exif::ExifTime($val)',
139 ValueConvInv => 'Image::ExifTool::IPTC::IptcTime($val)',
140 },
141 CreatorIdentity => { List => 'Seq' },
142 );
143  
144 #------------------------------------------------------------------------------
145 # Read/write PhotoMechanic information in a file
146 # Inputs: 0) ExifTool object reference, 1) dirInfo reference
147 # Returns: 1 on success, 0 if this file didn't contain PhotoMechanic information
148 # - updates DataPos to point to start of PhotoMechanic information
149 # - updates DirLen to trailer length
150 sub ProcessPhotoMechanic($$)
151 34 ▶{
Subroutine ProcessPhotoMechanic: called CC=17 SCAR=32.6
Pod undocumented
152 34 my ($et, $dirInfo) = @_;
153 34 my $raf = $$dirInfo{RAF};
154 34 ▶ my $offset = $$dirInfo{Offset} || 0;
Condition100%2/2
$dirInfo->{'Offset'} || 0
l!l
268
MC/DC100%1/1
$dirInfo->{'Offset'} || 0
$dirInfo->{'Offset'}
Truth table100%2/2
A
A= $dirInfo->{'Offset'}
Aresult
11
00
155 34 my $outfile = $$dirInfo{OutFile};
156 34 my $verbose = $et->Options('Verbose');
157 34 my $out = $et->Options('TextOut');
158 34 my $rtnVal = 0;
159 34 my ($buff, $footer);
160  
161 34 for (;;) {
162 # read and validate trailer footer (last 12 bytes)
163 34 ▶ last unless $raf->Seek(-12-$offset, 2) and $raf->Read($footer, 12) == 12;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Seek(-12 - $offset, 2) and $raf->Read($footer, 12) == 12 0 34 34
Condition33%1/3
$raf->Seek(-12 - $offset, 2) and $raf->Read($footer, 12) == 12
!ll&&!rl&&r
0034
MC/DC0%0/2
$raf->Seek(-12 - $offset, 2) and $raf->Read($footer, 12) == 12
$raf->Seek(-12 - $offset, 2) $raf->Read($footer, 12) == 12
Truth table33%1/3
A and B
A= $raf->Seek(-12 - $offset, 2)B= $raf->Read($footer, 12) == 12
ABresult
0X0
100
111
164 34 ▶ last unless $footer =~ /cbipcbbl$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $footer =~ /cbipcbbl$/ 0 34 34
165 34 my $size = unpack('N', $footer);
166  
167 34 ▶ if ($size & 0x80000000 or not $raf->Seek(-$size-12, 1)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size & 2147483648 or not $raf->Seek(-$size - 12, 1)) 0 34 34
Condition33%1/3
$size & 2147483648 or not $raf->Seek(-$size - 12, 1)
l!l&&r!l&&!r
0034
MC/DC0%0/2
$size & 2147483648 or not $raf->Seek(-$size - 12, 1)
$size & 2147483648 not $raf->Seek(-$size - 12, 1)
Truth table33%1/3
A or not(B)
A= $size & 2147483648B= not $raf->Seek(-$size - 12, 1)
ABresult
1X1
011
000
168 0 $et->Warn('Bad PhotoMechanic trailer');
169 0 last;
170 }
171 34 ▶ unless ($raf->Read($buff, $size) == $size) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($raf->Read($buff, $size) == $size) 0 34 34
172 0 $et->Warn('Error reading PhotoMechanic trailer');
173 0 last;
174 }
175 34 $rtnVal = 1; # we read the trailer successfully
176  
177 # set variables returned in dirInfo hash
178 34 $$dirInfo{DataPos} = $raf->Tell() - $size;
179 34 $$dirInfo{DirLen} = $size + 12;
180  
181 my %dirInfo = (
182 DataPt => \$buff,
183 DataPos => $$dirInfo{DataPos},
184 34 DirStart => 0,
185 DirLen => $size,
186 Parent => 'PhotoMechanic',
187 );
188 34 my $tagTablePtr = GetTagTable('Image::ExifTool::PhotoMechanic::Main');
189 34 ▶ if (not $outfile) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $outfile) { } 25 9 34
elsif ($et->{'DEL_GROUP'}{'PhotoMechanic'}) { } 0 9 9
190 # extract trailer information
191 25 ▶ $et->DumpTrailer($dirInfo) if $verbose or $$et{HTML_DUMP};
Branch: 1 branch
BranchTrueFalseTotal
if $verbose or $et->{"HTML_DUMP"} 0 25 25
Condition33%1/3
$verbose or $et->{"HTML_DUMP"}
l!l&&r!l&&!r
0025
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
192 25 $et->ProcessDirectory(\%dirInfo, $tagTablePtr);
193 } elsif ($$et{DEL_GROUP}{PhotoMechanic}) {
194 # delete the trailer
195 0 ▶ $verbose and print $out " Deleting PhotoMechanic trailer\n";
Branch: 1 branch
BranchTrueFalseTotal
$verbose and print $out " Deleting PhotoMechanic trailer\n" 0 0 0
196 0 ++$$et{CHANGED};
197 } else {
198 # rewrite the trailer
199 9 my $newPt;
200 9 my $newBuff = $et->WriteDirectory(\%dirInfo, $tagTablePtr);
201 9 ▶ if (defined $newBuff) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newBuff) { } 2 7 9
202 2 $newPt = \$newBuff; # write out the modified trailer
203 2 my $pad = 0x800 - length($newBuff);
204 2 ▶ if ($pad > 0 and not $$et{OPTIONS}{Compact}{NoPadding}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pad > 0 and not $et->{"OPTIONS"}{"Compact"}{"NoPadding"}) 2 0 2
Condition33%1/3
$pad > 0 and not $et->{"OPTIONS"}{"Compact"}{"NoPadding"}
!ll&&!rl&&r
002
MC/DC0%0/2
$pad > 0 and not $et->{"OPTIONS"}{"Compact"}{"NoPadding"}
$pad > 0 not $et->{"OPTIONS"}{"Compact"}{"NoPadding"}
Truth table33%1/3
A and not(B)
A= $pad > 0B= not $et->{"OPTIONS"}{"Compact"}{"NoPadding"}
ABresult
0X0
100
111
205 # pad out to 2kB like PhotoMechanic does
206 2 $newBuff .= "\0" x $pad;
207 }
208 # generate new footer
209 2 $footer = pack('N', length($$newPt)) . 'cbipcbbl';
210 } else {
211 7 $newPt = \$buff; # just copy existing trailer
212 }
213 # write out the trailer
214 9 ▶ Write($outfile, $$newPt, $footer) or $rtnVal = -1;
Branch: 1 branch
BranchTrueFalseTotal
&Write($outfile, $$newPt, $footer) or $rtnVal = -1 9 0 9
215 }
216 34 last;
217 }
218 34 return $rtnVal;
219 }
220  
221 13 1; # end
222  
223 __END__
« Image/ExifTool/DSF.pm ↑ Summary Image/ExifTool/GPS.pm »