Image/ExifTool/CaptureOne.pm

filter: Statementstmt 93.9% 93 / 99 Branchbran 65.0% 26 / 40 Conditioncond 66.6% 8 / 12 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 4 totaltotal 80.1% 137 / 171 CC 27 SCAR 25.2
CC
27
Cov
84%
ProcessEIP
19.9
HandleCOSAttrs
7.3
FoundCOS
4.2
CRAP 12.4
« Image/ExifTool/Olympus.pm ↑ Summary Image/ExifTool/NikonSettings.pm »
1 #------------------------------------------------------------------------------
2 # File: CaptureOne.pm
3 #
4 # Description: Read Capture One EIP and COS files
5 #
6 # Revisions: 2009/11/01 - P. Harvey Created
7 #
8 # Notes: The EIP format is a ZIP file containing an image (IIQ or TIFF)
9 # and some settings files (COS). COS files are XML based.
10 #------------------------------------------------------------------------------
11  
12 package Image::ExifTool::CaptureOne;
13  
14 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Image::ExifTool qw(:DataAccess :Utils);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Image::ExifTool::XMP;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Image::ExifTool::ZIP;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 $VERSION = '1.05';
21  
22 # CaptureOne COS XML tags
23 # - tags are added dynamically when encountered
24 # - this table is not listed in tag name docs
25 1 %Image::ExifTool::CaptureOne::Main = (
26 GROUPS => { 0 => 'XML', 1 => 'XML', 2 => 'Image' },
27 PROCESS_PROC => \&Image::ExifTool::XMP::ProcessXMP,
28 VARS => { ID_FMT => 'none' },
29 ColorCorrections => { ValueConv => '\$val', Hidden => 1 }, # (long list of floating point numbers)
30 );
31  
32 #------------------------------------------------------------------------------
33 # We found an XMP property name/value
34 # Inputs: 0) attribute list ref, 1) attr hash ref,
35 # 2) property name ref, 3) property value ref
36 # Returns: true if value was changed
37 sub HandleCOSAttrs($$$$)
38 58 ▶{
Subroutine HandleCOSAttrs: called CC=7 SCAR=19.9
Pod undocumented
39 58 my ($attrList, $attrs, $prop, $valPt) = @_;
40 58 my $changed;
41 58 ▶ if (not length $$valPt and defined $$attrs{K} and defined $$attrs{V}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not length $$valPt and defined $attrs->{"K"} and defined $attrs->{"V"}) 53 5 58
Condition66%4/6
not length $$valPt and defined $attrs->{"K"} and defined $attrs->{"V"}
!ll&&!rl&&r
5053
not length $$valPt and defined $attrs->{"K"}
!ll&&!rl&&r
5053
MC/DC33%1/3
not length $$valPt and defined $attrs->{"K"} and defined $attrs->{"V"}
not length $$valPt defined $attrs->{"K"} defined $attrs->{"V"}
Truth table50%2/4
not(A) and B and C
A= not length $$valPtB= defined $attrs->{"K"}C= defined $attrs->{"V"}
ABCresult
0XX0
10X0
1100
1111
42 53 $$prop = $$attrs{K};
43 53 $$valPt = $$attrs{V};
44 # remove these attributes from the list
45 53 my @attrs = @$attrList;
46 53 @$attrList = ( );
47 53 my $a;
48 53 foreach $a (@attrs) {
49 106 ▶ if ($a eq 'K' or $a eq 'V') {
Branch: 1 branch
BranchTrueFalseTotal
if ($a eq 'K' or $a eq 'V') { } 106 0 106
Condition66%2/3
$a eq "K" or $a eq "V"
l!l&&r!l&&!r
53530
MC/DC0%0/2
$a eq "K" or $a eq "V"
$a eq "K" $a eq "V"
Truth table66%2/3
A or B
A= $a eq "K"B= $a eq "V"
ABresult
1X1
011
000
50 106 delete $$attrs{$a};
51 } else {
52 0 push @$attrList, $a;
53 }
54 }
55 53 $changed = 1;
56 }
57 58 return $changed;
58 }
59  
60 #------------------------------------------------------------------------------
61 # We found a COS property name/value
62 # Inputs: 0) ExifTool object ref, 1) tag table ref
63 # 2) reference to array of XMP property names (last is current property)
64 # 3) property value, 4) attribute hash ref (not used here)
65 # Returns: 1 if valid tag was found
66 sub FoundCOS($$$$;$)
67 53 ▶{
Subroutine FoundCOS: called CC=4 SCAR=14.3
Pod undocumented
68 53 my ($et, $tagTablePtr, $props, $val, $attrs) = @_;
69  
70 53 my $tag = $$props[-1];
71 53 ▶ unless ($$tagTablePtr{$tag}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tagTablePtr->{$tag}) 48 5 53
72 48 $et->VPrint(0, " | [adding $tag]\n");
73 48 my $name = ucfirst $tag;
74 48 $name =~ tr/-_a-zA-Z0-9//dc;
75 48 ▶ return 0 unless length $tag;
Branch: 1 branch
BranchTrueFalseTotal
unless length $tag 0 48 48
76 48 my %tagInfo = ( Name => $tag );
77 # try formatting any tag with "Date" in the name as a date
78 # (shouldn't affect non-date tags)
79 48 ▶ if ($name =~ /Date(?![a-z])/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /Date(?![a-z])/) 0 48 48
80 0 $tagInfo{Groups} = { 2 => 'Time' };
81 0 $tagInfo{ValueConv} = 'Image::ExifTool::XMP::ConvertXMPDate($val,1)';
82 0 $tagInfo{PrintConv} = '$self->ConvertDateTime($val)';
83 }
84 48 AddTagToTable($tagTablePtr, $tag, \%tagInfo);
85 }
86 # convert from UTF8 to ExifTool Charset
87 53 $val = $et->Decode($val, "UTF8");
88 # un-escape XML character entities
89 53 $val = Image::ExifTool::XMP::UnescapeXML($val);
90 53 $et->HandleTag($tagTablePtr, $tag, $val);
91 53 return 0;
92 }
93  
94 #------------------------------------------------------------------------------
95 # Extract information from a COS file
96 # Inputs: 0) ExifTool object reference, 1) dirInfo reference
97 # Returns: 1 on success, 0 if this wasn't a valid XML file
98 sub ProcessCOS($$)
99 1 ▶{
Subroutine ProcessCOS: called CC=1 SCAR=0.0
Pod undocumented
100 1 my ($et, $dirInfo) = @_;
101  
102 # process using XMP module, but override handling of attributes and tags
103 $$dirInfo{XMPParseOpts} = {
104 1 AttrProc => \&HandleCOSAttrs,
105 FoundProc => \&FoundCOS,
106 };
107 1 my $tagTablePtr = GetTagTable('Image::ExifTool::CaptureOne::Main');
108 1 my $success = $et->ProcessDirectory($dirInfo, $tagTablePtr);
109 1 delete $$dirInfo{XMLParseArgs};
110 1 return $success;
111 }
112  
113 #------------------------------------------------------------------------------
114 # Extract information from a CaptureOne EIP file
115 # Inputs: 0) ExifTool object reference, 1) dirInfo reference
116 # Returns: 1
117 # Notes: Upon entry to this routine, the file type has already been verified
118 # and the dirInfo hash contains a ZIP element unique to this process proc:
119 # ZIP - reference to Archive::Zip object for this file
120 sub ProcessEIP($$)
121 1 ▶{
Subroutine ProcessEIP: called CC=18 SCAR=29.9
Pod undocumented
122 1 my ($et, $dirInfo) = @_;
123 1 my $zip = $$dirInfo{ZIP};
124 1 my ($file, $buff, $status, $member, %parseFile);
125  
126 1 $et->SetFileType('EIP');
127  
128 # must catch all Archive::Zip warnings
129 1 local $SIG{'__WARN__'} = \&Image::ExifTool::ZIP::WarnProc;
130 # find all manifest files
131 1 my @members = $zip->membersMatching('^manifest\d*.xml$');
132 # and choose the one with the highest version number (any better ideas?)
133 1 ▶ while (@members) {
Branch: 1 branch
BranchTrueFalseTotal
if (@members) 2 1 3
134 2 my $m = shift @members;
135 2 my $f = $m->fileName();
136 2 ▶ next if $file and $file gt $f;
Branch: 1 branch
BranchTrueFalseTotal
if $file and $file gt $f 0 2 2
Condition66%2/3
$file and $file gt $f
!ll&&!rl&&r
110
MC/DC0%0/2
$file and $file gt $f
$file $file gt $f
Truth table66%2/3
A and B
A= $fileB= $file gt $f
ABresult
0X0
100
111
137 2 $member = $m;
138 2 $file = $f;
139 }
140 # get file names from our chosen manifest file
141 1 ▶ if ($member) {
Branch: 1 branch
BranchTrueFalseTotal
if ($member) 1 0 1
142 1 ($buff, $status) = $zip->contents($member);
143 1 ▶ if (not $status) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($status) 1 0 1
144 1 my $foundImage;
145 1 ▶ while ($buff =~ m{<(RawPath|SettingsPath)>(.*?)</\1>}sg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buff =~ m[<(RawPath|SettingsPath)>(.*?)</\1>]gs) 2 1 3
146 2 $file = $2;
147 2 ▶ next unless $file =~ /\.(cos|iiq|jpe?g|tiff?)$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ /\.(cos|iiq|jpe?g|tiff?)$/i 0 2 2
148 2 $parseFile{$file} = 1; # set flag to parse this file
149 2 ▶ $foundImage = 1 unless $file =~ /\.cos$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ /\.cos$/i 1 1 2
150 }
151 # ignore manifest unless it contained a valid image
152 1 ▶ undef %parseFile unless $foundImage;
Branch: 1 branch
BranchTrueFalseTotal
unless $foundImage 0 1 1
153 }
154 }
155 # extract meta information from embedded files
156 1 my $docNum = 0;
157 1 @members = $zip->members(); # get all members
158 1 foreach $member (@members) {
159 # get filename of this ZIP member
160 5 $file = $member->fileName();
161 5 ▶ next unless defined $file;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 5 5
162 5 $et->VPrint(0, "File: $file\n");
163 # set the document number and extract ZIP tags
164 5 $$et{DOC_NUM} = ++$docNum;
165 5 Image::ExifTool::ZIP::HandleMember($et, $member);
166 5 ▶ if (%parseFile) {
Branch: 1 branch
BranchTrueFalseTotal
if (%parseFile) { } 5 0 5
167 5 ▶ next unless $parseFile{$file};
Branch: 1 branch
BranchTrueFalseTotal
unless $parseFile{$file} 3 2 5
168 } else {
169 # reading the manifest didn't work, so look for image files in the
170 # root directory and .cos files in the CaptureOne directory
171 0 ▶ next unless $file =~ m{^([^/]+\.(iiq|jpe?g|tiff?)|CaptureOne/.*\.cos)$}i;
Branch: 1 branch
BranchTrueFalseTotal
unless $file =~ m[^([^/]+\.(iiq|jpe?g|tiff?)|CaptureOne/.*\.cos)$]i 0 0 0
172 }
173 # extract the contents of the file
174 # Note: this could use a LOT of memory here for RAW images...
175 2 ($buff, $status) = $zip->contents($member);
176 2 ▶ $status and $et->Warn("Error extracting $file"), next;
Branch: 1 branch
BranchTrueFalseTotal
$status and $et->Warn("Error extracting $file"), next 0 2 2
177 2 ▶ if ($file =~ /\.cos$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /\.cos$/i) { } 1 1 2
178 # process Capture One Settings files
179 1 my %dirInfo = (
180 DataPt => \$buff,
181 DirLen => length $buff,
182 DataLen => length $buff,
183 );
184 1 ProcessCOS($et, \%dirInfo);
185 } else {
186 # set HtmlDump error if necessary because it doesn't work with embedded files
187 1 ▶ if ($$et{HTML_DUMP}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($et->{"HTML_DUMP"}) 0 1 1
188 0 $$et{HTML_DUMP}{Error} = "Sorry, can't dump images embedded in ZIP files";
189 }
190 # process IIQ, JPEG and TIFF images
191 1 $et->ExtractInfo(\$buff, { ReEntry => 1 });
192 }
193 2 undef $buff; # (free memory now)
194 }
195 1 delete $$et{DOC_NUM};
196 1 return 1;
197 }
198  
199 1 1; # end
200  
201 __END__
« Image/ExifTool/Olympus.pm ↑ Summary Image/ExifTool/NikonSettings.pm »