Image/ExifTool/DPX.pm

filter: Statementstmt 100% 25 / 25 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 1 totaltotal 86.8% 33 / 38 CC 5 SCAR 12.8
CC
5
Cov
88%
ProcessDPX
5.2
BEGIN
1.0
BEGIN
1.0
CRAP 3.6
« Image/ExifTool/ICO.pm ↑ Summary Image/ExifTool/MOI.pm »
1 #------------------------------------------------------------------------------
2 # File: DPX.pm
3 #
4 # Description: Read DPX meta information
5 #
6 # Revisions: 2013-09-19 - P. Harvey created
7 #
8 # References: 1) http://www.cineon.com/ff_draft.php
9 # 2) Harry Mallon private communication
10 #------------------------------------------------------------------------------
11  
12 package Image::ExifTool::DPX;
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  
18 1 $VERSION = '1.07';
19  
20 # DPX tags
21 1 %Image::ExifTool::DPX::Main = (
22 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
23 GROUPS => { 0 => 'File', 1 => 'File', 2 => 'Image' },
24 NOTES => 'Tags extracted from DPX (Digital Picture Exchange) images.',
25 0 => { Name => 'ByteOrder', Format => 'undef[4]', PrintConv => { SDPX => 'Big-endian', XPDS => 'Little-endian' } },
26 8 => { Name => 'HeaderVersion', Format => 'string[8]' },
27 # 24 => { Name => 'GenericHeaderSize', Format => 'int32u' }, # = 1664
28 # 28 => { Name => 'IndustryStandardHeaderSize', Format => 'int32u' }, # = 384
29 16 => { Name => 'DPXFileSize', Format => 'int32u' },
30 20 => { Name => 'DittoKey', Format => 'int32u', PrintConv => { 0 => 'Same', 1 => 'New' } },
31 36 => { Name => 'ImageFileName', Format => 'string[100]' },
32 136 => {
33 Name => 'CreateDate',
34 Format => 'string[24]',
35 Groups => { 2 => 'Time' },
36 ValueConv => '$val =~ s/(\d{4}:\d{2}:\d{2}):/$1 /; $val',
37 PrintConv => '$self->ConvertDateTime($val)',
38 },
39 160 => { Name => 'Creator', Format => 'string[100]', Groups => { 2 => 'Author' } },
40 260 => { Name => 'Project', Format => 'string[200]' },
41 460 => { Name => 'Copyright', Format => 'string[200]', Groups => { 2 => 'Author' } },
42 660 => { Name => 'EncryptionKey', Format => 'int32u', PrintConv => 'sprintf("%.8x",$val)' },
43 768 => {
44 Name => 'Orientation',
45 Format => 'int16u',
46 PrintConv => {
47 0 => 'Horizontal (normal)',
48 1 => 'Mirror vertical',
49 2 => 'Mirror horizontal',
50 3 => 'Rotate 180',
51 4 => 'Mirror horizontal and rotate 270 CW',
52 5 => 'Rotate 90 CW',
53 6 => 'Rotate 270 CW',
54 7 => 'Mirror horizontal and rotate 90 CW',
55 },
56 },
57 770 => { Name => 'ImageElements', Format => 'int16u' },
58 772 => { Name => 'ImageWidth', Format => 'int32u' },
59 776 => { Name => 'ImageHeight', Format => 'int32u' },
60 780 => { Name => 'DataSign', Format => 'int32u', PrintConv => { 0 => 'Unsigned', 1 => 'Signed' } },
61 800 => {
62 Name => 'ComponentsConfiguration',
63 Format => 'int8u',
64 PrintConv => {
65 0 => 'User-defined single component',
66 1 => 'Red (R)',
67 2 => 'Green (G)',
68 3 => 'Blue (B)',
69 4 => 'Alpha (matte)',
70 6 => 'Luminance (Y)',
71 7 => 'Chrominance (Cb, Cr, subsampled by two)',
72 8 => 'Depth (Z)',
73 9 => 'Composite video',
74 50 => 'R, G, B',
75 51 => 'R, G, B, Alpha',
76 52 => 'Alpha, B, G, R',
77 100 => 'Cb, Y, Cr, Y (4:2:2)',
78 101 => 'Cb, Y, A, Cr, Y, A (4:2:2:4)',
79 102 => 'Cb, Y, Cr (4:4:4)',
80 103 => 'Cb, Y, Cr, A (4:4:4:4)',
81 150 => 'User-defined 2 component element',
82 151 => 'User-defined 3 component element',
83 152 => 'User-defined 4 component element',
84 153 => 'User-defined 5 component element',
85 154 => 'User-defined 6 component element',
86 155 => 'User-defined 7 component element',
87 156 => 'User-defined 8 component element',
88 },
89 },
90 801 => { #2
91 Name => 'TransferCharacteristic',
92 Format => 'int8u',
93 PrintConv => {
94 0 => 'User-defined',
95 1 => 'Printing density',
96 2 => 'Linear',
97 3 => 'Logarithmic',
98 4 => 'Unspecified video',
99 5 => 'SMPTE 274M',
100 6 => 'ITU-R 709-4',
101 7 => 'ITU-R 601-5 system B or G (625)',
102 8 => 'ITU-R 601-5 system M (525)',
103 9 => 'Composite video (NTSC)',
104 10 => 'Composite video (PAL)',
105 11 => 'Z (depth) - linear',
106 12 => 'Z (depth) - homogeneous',
107 13 => 'SMPTE ADX',
108 14 => 'ITU-R 2020 NCL',
109 15 => 'ITU-R 2020 CL',
110 16 => 'IEC 61966-2-4 xvYCC',
111 17 => 'ITU-R 2100 NCL/PQ',
112 18 => 'ITU-R 2100 ICtCp/PQ',
113 19 => 'ITU-R 2100 NCL/HLG',
114 20 => 'ITU-R 2100 ICtCp/HLG',
115 21 => 'RP 431-2:2011 Gama 2.6',
116 22 => 'IEC 61966-2-1 sRGB',
117 },
118 },
119 802 => { #2
120 Name => 'ColorimetricSpecification',
121 Format => 'int8u',
122 PrintConv => {
123 0 => 'User-defined',
124 1 => 'Printing density',
125 4 => 'Unspecified video',
126 5 => 'SMPTE 274M',
127 6 => 'ITU-R 709-4',
128 7 => 'ITU-R 601-5 system B or G (625)',
129 8 => 'ITU-R 601-5 system M (525)',
130 9 => 'Composite video (NTSC)',
131 10 => 'Composite video (PAL)',
132 13 => 'SMPTE ADX',
133 14 => 'ITU-R 2020',
134 15 => 'P3D65',
135 16 => 'P3DCI',
136 17 => 'P3D60',
137 18 => 'ACES',
138 },
139 },
140 803 => { Name => 'BitDepth', Format => 'int8u' },
141 820 => { Name => 'ImageDescription', Format => 'string[32]' },
142 892 => { Name => 'Image2Description', Format => 'string[32]', RawConv => '$val=~/[^\xff]/ ? $val : undef' },
143 964 => { Name => 'Image3Description', Format => 'string[32]', RawConv => '$val=~/[^\xff]/ ? $val : undef' },
144 1036=> { Name => 'Image4Description', Format => 'string[32]', RawConv => '$val=~/[^\xff]/ ? $val : undef' },
145 1108=> { Name => 'Image5Description', Format => 'string[32]', RawConv => '$val=~/[^\xff]/ ? $val : undef' },
146 1180=> { Name => 'Image6Description', Format => 'string[32]', RawConv => '$val=~/[^\xff]/ ? $val : undef' },
147 1252=> { Name => 'Image7Description', Format => 'string[32]', RawConv => '$val=~/[^\xff]/ ? $val : undef' },
148 1324=> { Name => 'Image8Description', Format => 'string[32]', RawConv => '$val=~/[^\xff]/ ? $val : undef' },
149 # 1408=> { Name => 'XOffset', Format => 'int32u' },
150 # 1412=> { Name => 'YOffset', Format => 'int32u' },
151 # 1416=> { Name => 'XCenter', Format => 'float' },
152 # 1420=> { Name => 'YCenter', Format => 'float' },
153 # 1424=> { Name => 'XOriginalSize', Format => 'int32u' },
154 # 1428=> { Name => 'YOriginalSize', Format => 'int32u' },
155 1432=> { Name => 'SourceFileName', Format => 'string[100]' },
156 1532=> { Name => 'SourceCreateDate', Format => 'string[24]' },
157 1556=> { Name => 'InputDeviceName', Format => 'string[32]' },
158 1588=> { Name => 'InputDeviceSerialNumber', Format => 'string[32]' },
159 # 1620 => { Name => 'Border', Format => 'int16u[4]' },
160 1628 => {
161 Name => 'AspectRatio',
162 Format => 'int32u[2]',
163 RawConv => '$val =~ /4294967295/ ? undef : $val', # ignore undefined values
164 PrintConv => q{
165 return 'undef' if $val eq '0 0';
166 return 'inf' if $val=~/ 0$/;
167 my @a=split(' ',$val);
168 return join(':', Rationalize($a[0]/$a[1]));
169 },
170 },
171 1724 => { Name => 'OriginalFrameRate',Format => 'float' },
172 1728 => { Name => 'ShutterAngle', Format => 'float', RawConv => '($val =~ /\d/ and $val !~ /nan/i) ? $val : undef' }, #2
173 1732 => { Name => 'FrameID', Format => 'string[32]' },
174 1764 => { Name => 'SlateInformation', Format => 'string[100]' },
175 1920 => { Name => 'TimeCode', Format => 'int32u' }, #2
176 1940 => { Name => 'FrameRate', Format => 'float', RawConv => '($val =~ /\d/ and $val !~ /nan/i) ? $val : undef' }, #2
177 1972 => { Name => 'Reserved5', Format => 'string[76]', Unknown => 1 },
178 2048 => { Name => 'UserID', Format => 'string[32]' },
179 );
180  
181 #------------------------------------------------------------------------------
182 # Extract EXIF information from a DPX image
183 # Inputs: 0) ExifTool object reference, 1) dirInfo reference
184 # Returns: 1 on success, 0 if this wasn't a valid DPX file
185 sub ProcessDPX($$)
186 1 ▶{
Subroutine ProcessDPX: called CC=5 SCAR=16.4
Pod undocumented
187 1 my ($et, $dirInfo) = @_;
188 1 my $raf = $$dirInfo{RAF};
189 1 my $buff;
190  
191 # verify this is a valid DPX file
192 1 ▶ return 0 unless $raf->Read($buff, 2080) == 2080;
Branch: 1 branch
BranchTrueFalseTotal
unless $raf->Read($buff, 2080) == 2080 0 1 1
193 1 ▶ return 0 unless $buff =~ /^(SDPX|XPDS)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $buff =~ /^(SDPX|XPDS)/ 0 1 1
194 1 ▶ SetByteOrder($1 eq 'SDPX' ? 'MM' : 'II');
Branch: 1 branch
BranchTrueFalseTotal
$1 eq 'SDPX' ? : 1 0 1
195 1 $et->SetFileType(); # set the FileType tag
196 1 my $hdrLen = Get32u(\$buff,24) + Get32u(\$buff,28);
197 1 ▶ $hdrLen == 2048 or $et->Warn("Unexpected DPX header length ($hdrLen)");
Branch: 1 branch
BranchTrueFalseTotal
$hdrLen == 2048 or $et->Warn("Unexpected DPX header length ($hdrLen)") 1 0 1
198 1 my %dirInfo = (
199 DataPt => \$buff,
200 DirStart => 0,
201 DirLen => length($buff),
202 );
203 1 my $tagTablePtr = GetTagTable('Image::ExifTool::DPX::Main');
204 1 $et->ProcessDirectory(\%dirInfo, $tagTablePtr);
205  
206 1 return 1;
207 }
208  
209 1 1; # end
210  
211 __END__
« Image/ExifTool/ICO.pm ↑ Summary Image/ExifTool/MOI.pm »