File Coverage

blib/lib/Image/ExifTool/PanasonicRaw.pm
Criterion Covered Total %
statement 112 130 86.1
branch 24 48 50.0
condition 12 34 35.2
subroutine 10 10 100.0
pod 0 6 0.0
total 158 228 69.3


line stmt bran cond sub pod time code
1             #------------------------------------------------------------------------------
2             # File: PanasonicRaw.pm
3             #
4             # Description: Read/write Panasonic/Leica RAW/RW2/RWL meta information
5             #
6             # Revisions: 2009/03/24 - P. Harvey Created
7             # 2009/05/12 - PH Added RWL file type (same format as RW2)
8             #
9             # References: 1) https://exiftool.org/forum/index.php/topic,1542.0.html
10             # 2) http://www.cybercom.net/~dcoffin/dcraw/
11             # 3) http://syscall.eu/#pana
12             # 4) Klaus Homeister private communication
13             # IB) Iliah Borg private communication (LibRaw)
14             # JD) Jens Duttke private communication (TZ3,FZ30,FZ50)
15             #------------------------------------------------------------------------------
16              
17             package Image::ExifTool::PanasonicRaw;
18              
19 17     17   144 use strict;
  17         50  
  17         697  
20 17     17   170 use vars qw($VERSION);
  17         54  
  17         881  
21 17     17   133 use Image::ExifTool qw(:DataAccess :Utils);
  17         46  
  17         4608  
22 17     17   158 use Image::ExifTool::Exif;
  17         45  
  17         48759  
23              
24             $VERSION = '1.28';
25              
26             sub ProcessJpgFromRaw($$$);
27             sub WriteJpgFromRaw($$$);
28             sub WriteDistortionInfo($$$);
29             sub ProcessDistortionInfo($$$);
30              
31             my %jpgFromRawMap = (
32             IFD1 => 'IFD0',
33             EXIF => 'IFD0', # to write EXIF as a block
34             ExifIFD => 'IFD0',
35             GPS => 'IFD0',
36             SubIFD => 'IFD0',
37             GlobParamIFD => 'IFD0',
38             PrintIM => 'IFD0',
39             InteropIFD => 'ExifIFD',
40             MakerNotes => 'ExifIFD',
41             IFD0 => 'APP1',
42             MakerNotes => 'ExifIFD',
43             Comment => 'COM',
44             );
45              
46             my %wbTypeInfo = (
47             PrintConv => \%Image::ExifTool::Exif::lightSource,
48             SeparateTable => 'EXIF LightSource',
49             );
50              
51             my %panasonicWhiteBalance = ( #forum9396
52             0 => 'Auto',
53             1 => 'Daylight',
54             2 => 'Cloudy',
55             3 => 'Tungsten',
56             4 => 'n/a',
57             5 => 'Flash',
58             6 => 'n/a',
59             7 => 'n/a',
60             8 => 'Custom#1',
61             9 => 'Custom#2',
62             10 => 'Custom#3',
63             11 => 'Custom#4',
64             12 => 'Shade',
65             13 => 'Kelvin',
66             16 => 'AWBc', # GH5 and G9 (Makernotes WB==19)
67             );
68              
69             # Tags found in Panasonic RAW/RW2/RWL images (ref PH)
70             %Image::ExifTool::PanasonicRaw::Main = (
71             GROUPS => { 0 => 'EXIF', 1 => 'IFD0', 2 => 'Image'},
72             WRITE_PROC => \&Image::ExifTool::Exif::WriteExif,
73             CHECK_PROC => \&Image::ExifTool::Exif::CheckExif,
74             WRITE_GROUP => 'IFD0', # default write group
75             NOTES => 'These tags are found in IFD0 of Panasonic/Leica RAW, RW2 and RWL images.',
76             0x01 => {
77             Name => 'PanasonicRawVersion',
78             Writable => 'undef',
79             },
80             0x02 => 'SensorWidth', #1/PH
81             0x03 => 'SensorHeight', #1/PH
82             0x04 => 'SensorTopBorder', #JD
83             0x05 => 'SensorLeftBorder', #JD
84             0x06 => 'SensorBottomBorder', #PH
85             0x07 => 'SensorRightBorder', #PH
86             # observed values for unknown tags - PH
87             # 0x08: 1
88             # 0x09: 1,3,4
89             # 0x0a: 12
90             # (IB gave 0x08-0x0a as BlackLevel tags, but Klaus' decoding makes more sense)
91             0x08 => { Name => 'SamplesPerPixel', Writable => 'int16u', Protected => 1 }, #4
92             0x09 => { #4
93             Name => 'CFAPattern',
94             Writable => 'int16u',
95             Protected => 1,
96             PrintConv => {
97             0 => 'n/a',
98             1 => '[Red,Green][Green,Blue]', # (CM-1, FZ70)
99             2 => '[Green,Red][Blue,Green]', # (LX-7)
100             3 => '[Green,Blue][Red,Green]', # (ZS100, FZ2500, FZ1000, ...)
101             4 => '[Blue,Green][Green,Red]', # (LC-100, G-7, V-LUX1, ...)
102             },
103             },
104             0x0a => { Name => 'BitsPerSample', Writable => 'int16u', Protected => 1 }, #4
105             0x0b => { #4
106             Name => 'Compression',
107             Writable => 'int16u',
108             Protected => 1,
109             PrintConv => {
110             34316 => 'Panasonic RAW 1', # (most models - RAW/RW2/RWL)
111             34826 => 'Panasonic RAW 2', # (DIGILUX 2 - RAW)
112             34828 => 'Panasonic RAW 3', # (D-LUX2,D-LUX3,FZ30,LX1 - RAW)
113             34830 => 'Panasonic RAW 4', #IB (Leica DIGILUX 3, Panasonic DMC-L1)
114             },
115             },
116             # 0x0c: 2 (only Leica Digilux 2)
117             # 0x0d: 0,1
118             # 0x0e,0x0f,0x10: 4095
119             0x0e => { Name => 'LinearityLimitRed', Writable => 'int16u' }, #IB
120             0x0f => { Name => 'LinearityLimitGreen', Writable => 'int16u' }, #IB
121             0x10 => { Name => 'LinearityLimitBlue', Writable => 'int16u' }, #IB
122             0x11 => { #JD
123             Name => 'RedBalance',
124             Writable => 'int16u',
125             ValueConv => '$val / 256',
126             ValueConvInv => 'int($val * 256 + 0.5)',
127             Notes => 'found in Digilux 2 RAW images',
128             },
129             0x12 => { #JD
130             Name => 'BlueBalance',
131             Writable => 'int16u',
132             ValueConv => '$val / 256',
133             ValueConvInv => 'int($val * 256 + 0.5)',
134             },
135             0x13 => { #IB
136             Name => 'WBInfo',
137             SubDirectory => { TagTable => 'Image::ExifTool::PanasonicRaw::WBInfo' },
138             },
139             0x17 => { #1
140             Name => 'ISO',
141             Writable => 'int16u',
142             },
143             # 0x18,0x19,0x1a: 0
144             0x18 => { #IB
145             Name => 'HighISOMultiplierRed',
146             Writable => 'int16u',
147             ValueConv => '$val / 256',
148             ValueConvInv => 'int($val * 256 + 0.5)',
149             },
150             0x19 => { #IB
151             Name => 'HighISOMultiplierGreen',
152             Writable => 'int16u',
153             ValueConv => '$val / 256',
154             ValueConvInv => 'int($val * 256 + 0.5)',
155             },
156             0x1a => { #IB
157             Name => 'HighISOMultiplierBlue',
158             Writable => 'int16u',
159             ValueConv => '$val / 256',
160             ValueConvInv => 'int($val * 256 + 0.5)',
161             },
162             # 0x1b: [binary data] (something to do with the camera ISO cababilities: int16u count N,
163             # followed by table of N entries: int16u ISO, int16u[3] RGB gains - ref IB)
164             0x1c => { Name => 'BlackLevelRed', Writable => 'int16u' }, #IB
165             0x1d => { Name => 'BlackLevelGreen', Writable => 'int16u' }, #IB
166             0x1e => { Name => 'BlackLevelBlue', Writable => 'int16u' }, #IB
167             0x24 => { #2
168             Name => 'WBRedLevel',
169             Writable => 'int16u',
170             },
171             0x25 => { #2
172             Name => 'WBGreenLevel',
173             Writable => 'int16u',
174             },
175             0x26 => { #2
176             Name => 'WBBlueLevel',
177             Writable => 'int16u',
178             },
179             0x27 => { #IB
180             Name => 'WBInfo2',
181             SubDirectory => { TagTable => 'Image::ExifTool::PanasonicRaw::WBInfo2' },
182             },
183             # 0x27,0x29,0x2a,0x2b,0x2c: [binary data]
184             0x2d => { #IB
185             Name => 'RawFormat',
186             Writable => 'int16u',
187             Protected => 1,
188             # 2 - RAW DMC-FZ8/FZ18
189             # 3 - RAW DMC-L10
190             # 4 - RW2 for most other models, including G9 in "pixel shift off" mode and YUNEEC CGO4
191             # (must add 15 to black levels for RawFormat == 4)
192             # 5 - RW2 DC-GH5s; G9 in "pixel shift on" mode
193             # 6 - RW2 DC-S1, DC-S1r in "pixel shift off" mode
194             # 7 - RW2 DC-S1r (and probably DC-S1, have no raw samples) in "pixel shift on" mode
195             # not used - DMC-LX1/FZ30/FZ50/L1/LX1/LX2
196             # (modes 5 and 7 are lossless)
197             },
198             0x2e => { #JD
199             Name => 'JpgFromRaw', # (writable directory!)
200             Groups => { 2 => 'Preview' },
201             Writable => 'undef',
202             # protect this tag because it contains all the metadata
203             Flags => [ 'Binary', 'Protected', 'NestedHtmlDump', 'BlockExtract' ],
204             Notes => 'processed as an embedded document because it contains full EXIF',
205             WriteCheck => '$val eq "none" ? undef : $self->CheckImage(\$val)',
206             DataTag => 'JpgFromRaw',
207             RawConv => '$self->ValidateImage(\$val,$tag)',
208             SubDirectory => {
209             # extract information from embedded image since it is metadata-rich,
210             # unless HtmlDump option set (note that the offsets will be relative,
211             # not absolute like they should be in verbose mode)
212             TagTable => 'Image::ExifTool::JPEG::Main',
213             WriteProc => \&WriteJpgFromRaw,
214             ProcessProc => \&ProcessJpgFromRaw,
215             },
216             },
217             0x2f => { Name => 'CropTop', Writable => 'int16u' },
218             0x30 => { Name => 'CropLeft', Writable => 'int16u' },
219             0x31 => { Name => 'CropBottom', Writable => 'int16u' },
220             0x32 => { Name => 'CropRight', Writable => 'int16u' },
221             # 0x44 - may contain another pointer to the raw data starting at byte 2 in this data (DC-GH6)
222             0x10f => {
223             Name => 'Make',
224             Groups => { 2 => 'Camera' },
225             Writable => 'string',
226             DataMember => 'Make',
227             # save this value as an ExifTool member variable
228             RawConv => '$self->{Make} = $val',
229             },
230             0x110 => {
231             Name => 'Model',
232             Description => 'Camera Model Name',
233             Groups => { 2 => 'Camera' },
234             Writable => 'string',
235             DataMember => 'Model',
236             # save this value as an ExifTool member variable
237             RawConv => '$self->{Model} = $val',
238             },
239             0x111 => {
240             Name => 'StripOffsets',
241             # (this value is 0xffffffff for some models, and RawDataOffset must be used)
242             Flags => [ 'IsOffset', 'PanasonicHack' ],
243             OffsetPair => 0x117, # point to associated byte counts
244             ValueConv => 'length($val) > 32 ? \$val : $val',
245             },
246             0x112 => {
247             Name => 'Orientation',
248             Writable => 'int16u',
249             PrintConv => \%Image::ExifTool::Exif::orientation,
250             Priority => 0, # so IFD1 doesn't take precedence
251             },
252             0x116 => {
253             Name => 'RowsPerStrip',
254             Priority => 0,
255             },
256             0x117 => {
257             Name => 'StripByteCounts',
258             # (note that this value may represent something like uncompressed byte count
259             # for RAW/RW2/RWL images from some models, and is zero for some other models)
260             OffsetPair => 0x111, # point to associated offset
261             ValueConv => 'length($val) > 32 ? \$val : $val',
262             },
263             0x118 => {
264             Name => 'RawDataOffset', #PH (RW2/RWL)
265             IsOffset => '$$et{TIFF_TYPE} =~ /^(RW2|RWL)$/', # (invalid in DNG-converted files)
266             PanasonicHack => 1,
267             OffsetPair => 0x117, # (use StripByteCounts as the offset pair)
268             NotRealPair => 1, # (to avoid Validate warning)
269             IsImageData => 1,
270             },
271             0x119 => {
272             Name => 'DistortionInfo',
273             SubDirectory => { TagTable => 'Image::ExifTool::PanasonicRaw::DistortionInfo' },
274             },
275             # 0x11b - chromatic aberration correction (ref 3) (also see forum9366)
276             0x11c => { #forum9373
277             Name => 'Gamma',
278             Writable => 'int16u',
279             # unfortunately it seems that the scaling factor varies with model...
280             ValueConv => '$val / ($val >= 1024 ? 1024 : ($val >= 256 ? 256 : 100))',
281             ValueConvInv => 'int($val * 256 + 0.5)',
282             },
283             0x120 => {
284             Name => 'CameraIFD',
285             SubDirectory => {
286             TagTable => 'Image::ExifTool::PanasonicRaw::CameraIFD',
287             Base => '$start',
288             ProcessProc => \&Image::ExifTool::ProcessTIFF,
289             },
290             },
291             0x121 => { #forum9295
292             Name => 'Multishot',
293             Writable => 'int32u',
294             PrintConv => {
295             0 => 'Off',
296             65536 => 'Pixel Shift',
297             },
298             },
299             # 0x122 - int32u: RAWDataOffset for the GH5s/GX9, or pointer to end of raw data for G9 (forum9295)
300             0x127 => { #github193 (newer models)
301             Name => 'JpgFromRaw2',
302             Groups => { 2 => 'Preview' },
303             DataTag => 'JpgFromRaw2',
304             RawConv => '$self->ValidateImage(\$val,$tag)',
305             },
306             0x13b => {
307             Name => 'Artist',
308             Groups => { 2 => 'Author' },
309             Permanent => 1, # (so we don't add it if the model doesn't write it)
310             Writable => 'string',
311             WriteGroup => 'IFD0',
312             RawConv => '$val =~ s/\s+$//; $val', # trim trailing blanks
313             },
314             0x2bc => { # PH Extension!!
315             Name => 'ApplicationNotes', # (writable directory!)
316             Writable => 'int8u',
317             Format => 'undef',
318             Flags => [ 'Binary', 'Protected' ],
319             SubDirectory => {
320             DirName => 'XMP',
321             TagTable => 'Image::ExifTool::XMP::Main',
322             },
323             },
324             0x001b => { #forum9250
325             Name => 'NoiseReductionParams',
326             Writable => 'undef',
327             Format => 'int16u',
328             Count => -1,
329             Flags => 'Protected',
330             Notes => q{
331             the camera's default noise reduction setup. The first number is the number
332             of entries, then for each entry there are 4 numbers: an ISO speed, and
333             noise-reduction strengths the R, G and B channels
334             },
335             },
336             0x8298 => { #github193
337             Name => 'Copyright',
338             Groups => { 2 => 'Author' },
339             Permanent => 1, # (so we don't add it if the model doesn't write it)
340             Format => 'undef',
341             Writable => 'string',
342             WriteGroup => 'IFD0',
343             RawConv => $Image::ExifTool::Exif::Main{0x8298}{RawConv},
344             RawConvInv => $Image::ExifTool::Exif::Main{0x8298}{RawConvInv},
345             PrintConvInv => $Image::ExifTool::Exif::Main{0x8298}{PrintConvInv},
346             },
347             0x83bb => { # PH Extension!!
348             Name => 'IPTC-NAA', # (writable directory!)
349             Format => 'undef', # convert binary values as undef
350             Writable => 'int32u', # but write int32u format code in IFD
351             WriteGroup => 'IFD0',
352             Flags => [ 'Binary', 'Protected' ],
353             SubDirectory => {
354             DirName => 'IPTC',
355             TagTable => 'Image::ExifTool::IPTC::Main',
356             },
357             },
358             0x8769 => {
359             Name => 'ExifOffset',
360             Groups => { 1 => 'ExifIFD' },
361             Flags => 'SubIFD',
362             SubDirectory => {
363             TagTable => 'Image::ExifTool::Exif::Main',
364             DirName => 'ExifIFD',
365             Start => '$val',
366             },
367             },
368             0x8825 => {
369             Name => 'GPSInfo',
370             Groups => { 1 => 'GPS' },
371             Flags => 'SubIFD',
372             SubDirectory => {
373             DirName => 'GPS',
374             TagTable => 'Image::ExifTool::GPS::Main',
375             Start => '$val',
376             },
377             },
378             # 0xffff => 'DCSHueShiftValues', #exifprobe (NC)
379             );
380              
381             # white balance information (ref IB)
382             # (PanasonicRawVersion<200: Digilux 2)
383             %Image::ExifTool::PanasonicRaw::WBInfo = (
384             PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
385             WRITE_PROC => \&Image::ExifTool::WriteBinaryData,
386             CHECK_PROC => \&Image::ExifTool::CheckBinaryData,
387             WRITABLE => 1,
388             FORMAT => 'int16u',
389             FIRST_ENTRY => 0,
390             0 => 'NumWBEntries',
391             1 => { Name => 'WBType1', %wbTypeInfo },
392             2 => { Name => 'WB_RBLevels1', Format => 'int16u[2]' },
393             4 => { Name => 'WBType2', %wbTypeInfo },
394             5 => { Name => 'WB_RBLevels2', Format => 'int16u[2]' },
395             7 => { Name => 'WBType3', %wbTypeInfo },
396             8 => { Name => 'WB_RBLevels3', Format => 'int16u[2]' },
397             10 => { Name => 'WBType4', %wbTypeInfo },
398             11 => { Name => 'WB_RBLevels4', Format => 'int16u[2]' },
399             13 => { Name => 'WBType5', %wbTypeInfo },
400             14 => { Name => 'WB_RBLevels5', Format => 'int16u[2]' },
401             16 => { Name => 'WBType6', %wbTypeInfo },
402             17 => { Name => 'WB_RBLevels6', Format => 'int16u[2]' },
403             19 => { Name => 'WBType7', %wbTypeInfo },
404             20 => { Name => 'WB_RBLevels7', Format => 'int16u[2]' },
405             );
406              
407             # white balance information (ref IB)
408             # (PanasonicRawVersion>=200: D-Lux2, D-Lux3, DMC-FZ18/FZ30/LX1/L10)
409             %Image::ExifTool::PanasonicRaw::WBInfo2 = (
410             PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
411             WRITE_PROC => \&Image::ExifTool::WriteBinaryData,
412             CHECK_PROC => \&Image::ExifTool::CheckBinaryData,
413             WRITABLE => 1,
414             FORMAT => 'int16u',
415             FIRST_ENTRY => 0,
416             0 => 'NumWBEntries',
417             1 => { Name => 'WBType1', %wbTypeInfo },
418             2 => { Name => 'WB_RGBLevels1', Format => 'int16u[3]' },
419             5 => { Name => 'WBType2', %wbTypeInfo },
420             6 => { Name => 'WB_RGBLevels2', Format => 'int16u[3]' },
421             9 => { Name => 'WBType3', %wbTypeInfo },
422             10 => { Name => 'WB_RGBLevels3', Format => 'int16u[3]' },
423             13 => { Name => 'WBType4', %wbTypeInfo },
424             14 => { Name => 'WB_RGBLevels4', Format => 'int16u[3]' },
425             17 => { Name => 'WBType5', %wbTypeInfo },
426             18 => { Name => 'WB_RGBLevels5', Format => 'int16u[3]' },
427             21 => { Name => 'WBType6', %wbTypeInfo },
428             22 => { Name => 'WB_RGBLevels6', Format => 'int16u[3]' },
429             25 => { Name => 'WBType7', %wbTypeInfo },
430             26 => { Name => 'WB_RGBLevels7', Format => 'int16u[3]' },
431             );
432              
433             # lens distortion information (ref 3)
434             # (distortion correction equation: Ru = scale*(Rd + a*Rd^3 + b*Rd^5 + c*Rd^7), ref 3)
435             %Image::ExifTool::PanasonicRaw::DistortionInfo = (
436             PROCESS_PROC => \&ProcessDistortionInfo,
437             WRITE_PROC => \&WriteDistortionInfo,
438             CHECK_PROC => \&Image::ExifTool::CheckBinaryData,
439             # (don't make this family 0 MakerNotes because we don't want it to be a deletable group)
440             GROUPS => { 0 => 'PanasonicRaw', 1 => 'PanasonicRaw', 2 => 'Image'},
441             WRITABLE => 1,
442             FORMAT => 'int16s',
443             FIRST_ENTRY => 0,
444             NOTES => 'Lens distortion correction information.',
445             # 0,1 - checksums
446             2 => {
447             Name => 'DistortionParam02',
448             ValueConv => '$val / 32768',
449             ValueConvInv => '$val * 32768',
450             },
451             # 3 - usually 0, but seen 0x026b when value 5 is non-zero
452             4 => {
453             Name => 'DistortionParam04',
454             ValueConv => '$val / 32768',
455             ValueConvInv => '$val * 32768',
456             },
457             5 => {
458             Name => 'DistortionScale',
459             ValueConv => '1 / (1 + $val/32768)',
460             ValueConvInv => '(1/$val - 1) * 32768',
461             },
462             # 6 - seen 0x0000-0x027f
463             7.1 => {
464             Name => 'DistortionCorrection',
465             Mask => 0x0f,
466             # (have seen the upper 4 bits set for GF5 and GX1, giving a value of -4095 - PH)
467             PrintConv => { 0 => 'Off', 1 => 'On' },
468             },
469             8 => {
470             Name => 'DistortionParam08',
471             ValueConv => '$val / 32768',
472             ValueConvInv => '$val * 32768',
473             },
474             9 => {
475             Name => 'DistortionParam09',
476             ValueConv => '$val / 32768',
477             ValueConvInv => '$val * 32768',
478             },
479             # 10 - seen 0xfc,0x0101,0x01f4,0x021d,0x0256
480             11 => {
481             Name => 'DistortionParam11',
482             ValueConv => '$val / 32768',
483             ValueConvInv => '$val * 32768',
484             },
485             12 => {
486             Name => 'DistortionN',
487             Unknown => 1,
488             },
489             # 13 - seen 0x0000,0x01f9-0x02b2
490             # 14,15 - checksums
491             );
492              
493             # Panasonic RW2 camera IFD written by GH5 (ref PH)
494             # (doesn't seem to be valid for the GF7 or GM5 -- encrypted?)
495             %Image::ExifTool::PanasonicRaw::CameraIFD = (
496             GROUPS => { 0 => 'PanasonicRaw', 1 => 'CameraIFD', 2 => 'Camera'},
497             # (don't know what format codes 0x101 and 0x102 are for, so just
498             # map them into 4 = int32u for now)
499             VARS => { MAP_FORMAT => { 0x101 => 4, 0x102 => 4 } },
500             0x1001 => { #forum9388
501             Name => 'MultishotOn',
502             Writable => 'int32u',
503             PrintConv => { 0 => 'No', 1 => 'Yes' },
504             },
505             0x1100 => { #forum9274
506             Name => 'FocusStepNear',
507             Writable => 'int16s',
508             },
509             0x1101 => { #forum9274 (was forum8484)
510             Name => 'FocusStepCount',
511             Writable => 'int16s',
512             },
513             0x1102 => { #forum9417
514             Name => 'FlashFired',
515             Writable => 'int32u',
516             PrintConv => { 0 => 'No', 1 => 'Yes' },
517             },
518             # 0x1104 - set when camera shoots on lowest possible Extended-ISO (forum9290)
519             0x1105 => { #forum9392
520             Name => 'ZoomPosition',
521             Notes => 'in the range 0-255 for most cameras',
522             Writable => 'int32u',
523             },
524             0x1200 => { #forum9278
525             Name => 'LensAttached',
526             Notes => 'many CameraIFD tags are invalid if there is no lens attached',
527             Writable => 'int32u',
528             PrintConv => { 0 => 'No', 1 => 'Yes' },
529             },
530             # Note: LensTypeMake and LensTypeModel are combined into a Composite LensType tag
531             # defined in Olympus.pm which has the same values as Olympus:LensType
532             0x1201 => { #IB
533             Name => 'LensTypeMake',
534             Condition => '$format eq "int16u"',
535             Writable => 'int16u',
536             # when format is int16u, these values have been observed:
537             # 0 - Olympus or unknown lens
538             # 2 - Leica or Lumix lens
539             # when format is int32u (S models), these values have been observed (ref IB):
540             # 256 - Leica lens
541             # 257 - Lumix lens
542             # 258 - ? (seen once)
543             },
544             0x1202 => { #IB
545             Name => 'LensTypeModel',
546             Condition => '$format eq "int16u"',
547             Writable => 'int16u',
548             RawConv => q{
549             return undef unless $val;
550             require Image::ExifTool::Olympus; # (to load Composite LensID)
551             return $val;
552             },
553             ValueConv => '$_=sprintf("%.4x",$val); s/(..)(..)/$2 $1/; $_',
554             ValueConvInv => '$val =~ s/(..) (..)/$2$1/; hex($val)',
555             },
556             0x1203 => { #4
557             Name => 'FocalLengthIn35mmFormat',
558             Writable => 'int16u',
559             PrintConv => '"$val mm"',
560             PrintConvInv => '$val=~s/\s*mm$//;$val',
561             },
562             # 0x1300 - incident light value? (ref forum11395)
563             0x1301 => { #forum11395
564             Name => 'ApertureValue',
565             Writable => 'int16s',
566             Priority => 0,
567             ValueConv => '2 ** ($val / 512)',
568             ValueConvInv => '$val>0 ? 512*log($val)/log(2) : 0',
569             PrintConv => 'sprintf("%.1f",$val)',
570             PrintConvInv => '$val',
571             },
572             0x1302 => { #forum11395
573             Name => 'ShutterSpeedValue',
574             Writable => 'int16s',
575             Priority => 0,
576             ValueConv => 'abs($val/256)<100 ? 2**(-$val/256) : 0',
577             ValueConvInv => '$val>0 ? -256*log($val)/log(2) : -25600',
578             PrintConv => 'Image::ExifTool::Exif::PrintExposureTime($val)',
579             PrintConvInv => 'Image::ExifTool::Exif::ConvertFraction($val)',
580             },
581             0x1303 => { #forum11395
582             Name => 'SensitivityValue',
583             Writable => 'int16s',
584             ValueConv => '$val / 256',
585             ValueConvInv => 'int($val * 256)',
586             },
587             0x1305 => { #forum9384
588             Name => 'HighISOMode',
589             Writable => 'int16u',
590             RawConv => '$val || undef',
591             PrintConv => { 1 => 'On', 2 => 'Off' },
592             },
593             # 0x1306 EV for some models like the GX8 (forum11395)
594             # 0x140b - scaled overall black level? (ref forum9281)
595             # 0x1411 - scaled black level per channel difference (ref forum9281)
596             0x1412 => { #forum11397
597             Name => 'FacesDetected',
598             Writable => 'int8u',
599             PrintConv => { 0 => 'No', 1 => 'Yes' },
600             },
601             # 0x2000 - WB tungsten=3, daylight=4 (ref forum9467)
602             # 0x2009 - scaled black level per channel (ref forum9281)
603             # 0x3000-0x310b - red/blue balances * 1024 (ref forum9467)
604             # 0x3000 modifiedTungsten-Red (-2?)
605             # 0x3001 modifiedTungsten-Blue (-2?)
606             # 0x3002 modifiedDaylight-Red (-2?)
607             # 0x3003 modifiedDaylight-Blue (-2?)
608             # 0x3004 modifiedTungsten-Red (-1?)
609             # 0x3005 modifiedTungsten-Blue (-1?)
610             # 0x3006 modifiedDaylight-Red (-1?)
611             # 0x3007 modifiedDaylight-Blue (-1?)
612             # 0x3100 DefaultTungsten-Red
613             # 0x3101 DefaultTungsten-Blue
614             # 0x3102 DefaultDaylight-Red
615             # 0x3103 DefaultDaylight-Blue
616             # 0x3104 modifiedTungsten-Red (+1?)
617             # 0x3105 modifiedTungsten-Blue (+1?)
618             # 0x3106 modifiedDaylight-Red (+1?)
619             # 0x3107 modifiedDaylight-Blue (+1?)
620             # 0x3108 modifiedTungsten-Red (+2?)
621             # 0x3109 modifiedTungsten-Blue (+2?)
622             # 0x310a modifiedDaylight-Red (+2?)
623             # 0x310b modifiedDaylight-Blue (+2?)
624             0x3200 => { #forum9275
625             Name => 'WB_CFA0_LevelDaylight',
626             Writable => 'int16u',
627             },
628             0x3201 => { #forum9275
629             Name => 'WB_CFA1_LevelDaylight',
630             Writable => 'int16u',
631             },
632             0x3202 => { #forum9275
633             Name => 'WB_CFA2_LevelDaylight',
634             Writable => 'int16u',
635             },
636             0x3203 => { #forum9275
637             Name => 'WB_CFA3_LevelDaylight',
638             Writable => 'int16u',
639             },
640             # 0x3204-0x3207 - user multipliers * 1024 ? (ref forum9275)
641             # 0x320a - scaled maximum value of raw data (scaling = 4x) (ref forum9281)
642             # 0x3209 - gamma (x256) (ref forum9281)
643             0x3300 => { #forum9296/9396
644             Name => 'WhiteBalanceSet',
645             Writable => 'int8u',
646             PrintConv => \%panasonicWhiteBalance,
647             SeparateTable => 'WhiteBalance',
648             },
649             0x3420 => { #forum9276
650             Name => 'WB_RedLevelAuto',
651             Writable => 'int16u',
652             },
653             0x3421 => { #forum9276
654             Name => 'WB_BlueLevelAuto',
655             Writable => 'int16u',
656             },
657             0x3501 => { #4
658             Name => 'Orientation',
659             Writable => 'int8u',
660             PrintConv => \%Image::ExifTool::Exif::orientation,
661             },
662             # 0x3504 = Tag 0x1301+0x1302-0x1303 (Bv = Av+Tv-Sv) (forum11395)
663             # 0x3505 - same as 0x1300 (forum11395)
664             0x3600 => { #forum9396
665             Name => 'WhiteBalanceDetected',
666             Writable => 'int8u',
667             PrintConv => \%panasonicWhiteBalance,
668             SeparateTable => 'WhiteBalance',
669             },
670             );
671              
672             # PanasonicRaw composite tags
673             %Image::ExifTool::PanasonicRaw::Composite = (
674             ImageWidth => {
675             Require => {
676             0 => 'IFD0:SensorLeftBorder',
677             1 => 'IFD0:SensorRightBorder',
678             },
679             ValueConv => '$val[1] - $val[0]',
680             },
681             ImageHeight => {
682             Require => {
683             0 => 'IFD0:SensorTopBorder',
684             1 => 'IFD0:SensorBottomBorder',
685             },
686             ValueConv => '$val[1] - $val[0]',
687             },
688             );
689              
690             # add our composite tags
691             Image::ExifTool::AddCompositeTags('Image::ExifTool::PanasonicRaw');
692              
693              
694             #------------------------------------------------------------------------------
695             # checksum algorithm for lens distortion correction information (ref 3)
696             # Inputs: 0) data ref, 1) start position, 2) number of bytes, 3) incement
697             # Returns: checksum value
698             sub Checksum($$$$)
699             {
700 12     12 0 24 my ($dataPt, $start, $num, $inc) = @_;
701 12         20 my $csum = 0;
702 12         16 my $i;
703 12         31 for ($i=0; $i<$num; ++$i) {
704 156         358 $csum = (73 * $csum + Get8u($dataPt, $start + $i * $inc)) % 0xffef;
705             }
706 12         63 return $csum;
707             }
708              
709             #------------------------------------------------------------------------------
710             # Read lens distortion information
711             # Inputs: 0) ExifTool ref, 1) dirInfo ref, 2) tag table ref
712             # Returns: 1 on success
713             sub ProcessDistortionInfo($$$)
714             {
715 2     2 0 6 my ($et, $dirInfo, $tagTablePtr) = @_;
716 2         8 my $dataPt = $$dirInfo{DataPt};
717 2   50     11 my $start = $$dirInfo{DirStart} || 0;
718 2   33     7 my $size = $$dirInfo{DirLen} || (length($$dataPt) - $start);
719 2 50       9 if ($size == 32) {
720             # verify the checksums (ref 3)
721 2         12 my $csum1 = Checksum($dataPt, $start + 4, 12, 1);
722 2         12 my $csum2 = Checksum($dataPt, $start + 16, 12, 1);
723 2         25 my $csum3 = Checksum($dataPt, $start + 2, 14, 2);
724 2         22 my $csum4 = Checksum($dataPt, $start + 3, 14, 2);
725 2         24 my $res = $csum1 ^ Get16u($dataPt, $start + 2) ^
726             $csum2 ^ Get16u($dataPt, $start + 28) ^
727             $csum3 ^ Get16u($dataPt, $start + 0) ^
728             $csum4 ^ Get16u($dataPt, $start + 30);
729 2 50       9 $et->Warn('Invalid DistortionInfo checksum',1) if $res;
730             } else {
731 0         0 $et->Warn('Invalid DistortionInfo',1);
732             }
733 2         14 return $et->ProcessBinaryData($dirInfo, $tagTablePtr);
734             }
735              
736             #------------------------------------------------------------------------------
737             # Write lens distortion information
738             # Inputs: 0) ExifTool ref, 1) dirInfo ref, 2) tag table ref
739             # Returns: updated distortion information or undef on error
740             sub WriteDistortionInfo($$$)
741             {
742 9     9 0 23 my ($et, $dirInfo, $tagTablePtr) = @_;
743 9 100       43 $et or return 1; # (allow dummy access)
744 1         8 my $dat = $et->WriteBinaryData($dirInfo, $tagTablePtr);
745 1 50 33     13 if (defined $dat and length($dat) == 32) {
746             # fix checksums (ref 3)
747 1         8 Set16u(Checksum(\$dat, 4, 12, 1), \$dat, 2);
748 1         7 Set16u(Checksum(\$dat, 16, 12, 1), \$dat, 28);
749 1         7 Set16u(Checksum(\$dat, 2, 14, 2), \$dat, 0);
750 1         5 Set16u(Checksum(\$dat, 3, 14, 2), \$dat, 30);
751             } else {
752 0         0 $et->Warn('Error wriing DistortionInfo',1);
753             }
754 1         3 return $dat;
755             }
756              
757             #------------------------------------------------------------------------------
758             # Patch for writing non-standard Panasonic RAW/RW2/RWL raw data
759             # Inputs: 0) offset info ref, 1) raf ref, 2) IFD number
760             # Returns: error string, or undef on success
761             # OffsetInfo is a hash by tag ID of lists with the following elements:
762             # 0 - tag info ref
763             # 1 - pointer to int32u offset in IFD or value data
764             # 2 - value count
765             # 3 - reference to list of original offset values
766             # 4 - IFD format number
767             # 5 - (pointer to StripOffsets value added by this PatchRawDataOffset routine)
768             # 6 - flag set if this is a fixed offset (Panasonic GH6 fixed-offset hack)
769             sub PatchRawDataOffset($$$)
770             {
771 1     1 0 4 my ($offsetInfo, $raf, $ifd) = @_;
772 1         4 my $stripOffsets = $$offsetInfo{0x111};
773 1         3 my $stripByteCounts = $$offsetInfo{0x117};
774 1         2 my $rawDataOffset = $$offsetInfo{0x118};
775 1         3 my $err;
776 1 50       5 $err = 1 unless $ifd == 0;
777 1 50 33     7 if ($stripOffsets or $stripByteCounts) {
778 1 50 33     9 $err = 1 unless $stripOffsets and $stripByteCounts and $$stripOffsets[2] == 1;
      33        
779             } else {
780             # the DC-GH6 and DC-GH5M2 write RawDataOffset with no Strip tags, so we need
781             # to create fake StripByteCounts information for copying the data
782 0 0       0 if ($$offsetInfo{0x118}) { # (just to be safe)
783 0         0 $stripByteCounts = $$offsetInfo{0x117} = [ $PanasonicRaw::Main{0x117}, 0, 1, [ 0 ], 4 ];
784             # set flag so the offset will be fixed (GH6 hack, see https://exiftool.org/forum/index.php?topic=13861.0)
785             # (of course, fixing up the offset is now unnecessary, but continue to do this even
786             # though the fixup adjustment will be 0 because this allows us to delete the following
787             # line to remove the fix-offset restriction if Panasonic ever sees the light, but note
788             # that in this case we should investigate the purpose of the seemily-duplicate raw
789             # data offset contained within PanasonicRaw_0x0044)
790 0         0 $$offsetInfo{0x118}[6] = 1;
791             }
792             }
793 1 50 33     6 if ($rawDataOffset and not $err) {
794 1 50       4 $err = 1 unless $$rawDataOffset[2] == 1;
795 1 50       4 if ($stripOffsets) {
796 1 50 33     7 $err = 1 unless $$stripOffsets[3][0] == 0xffffffff or $$stripByteCounts[3][0] == 0;
797             }
798             }
799 1 50       7 $err and return 'Unsupported Panasonic/Leica RAW variant';
800 1 50       2 if ($rawDataOffset) {
801             # update StripOffsets along with this tag if it contains a reasonable value
802 1 50 33     11 if ($stripOffsets and $$stripOffsets[3][0] != 0xffffffff) {
803             # save pointer to StripOffsets value for updating later
804 0         0 push @$rawDataOffset, $$stripOffsets[1];
805             }
806             # handle via RawDataOffset instead of StripOffsets
807 1         3 $stripOffsets = $$offsetInfo{0x111} = $rawDataOffset;
808 1         3 delete $$offsetInfo{0x118};
809             }
810             # determine the length of the raw data
811 1         5 my $pos = $raf->Tell();
812 1 50       9 $raf->Seek(0, 2) or $err = 1; # seek to end of file
813 1         17 my $len = $raf->Tell() - $$stripOffsets[3][0];
814 1         8 $raf->Seek($pos, 0);
815             # quick check to be sure the raw data length isn't unreasonable
816             # (the 22-byte length is for '' in our tests)
817 1 50 33     17 $err = 1 if ($len < 1000 and $len != 22) or $len & 0x80000000;
      33        
818 1 50       5 $err and return 'Error reading Panasonic raw data';
819             # update StripByteCounts info with raw data length
820             # (note that the original value is maintained in the file)
821 1         3 $$stripByteCounts[3][0] = $len;
822              
823 1         5 return undef;
824             }
825              
826             #------------------------------------------------------------------------------
827             # Write meta information to Panasonic JpgFromRaw in RAW/RW2/RWL image
828             # Inputs: 0) ExifTool object ref, 1) dirInfo ref, 2) tag table ref
829             # Returns: updated image data, or undef if nothing changed
830             sub WriteJpgFromRaw($$$)
831             {
832 1     1 0 5 my ($et, $dirInfo, $tagTablePtr) = @_;
833 1         2 my $dataPt = $$dirInfo{DataPt};
834 1         3 my $byteOrder = GetByteOrder();
835 1         3 my $fileType = $$et{TIFF_TYPE}; # RAW, RW2 or RWL
836 1         3 my $dirStart = $$dirInfo{DirStart};
837 1 50       4 if ($dirStart) { # DirStart is non-zero in DNG-converted RW2/RWL
838 0         0 my $dirLen = $$dirInfo{DirLen} | length($$dataPt) - $dirStart;
839 0         0 my $buff = substr($$dataPt, $dirStart, $dirLen);
840 0         0 $dataPt = \$buff;
841             }
842 1         6 my $raf = new File::RandomAccess($dataPt);
843 1         2 my $outbuff;
844 1         21 my %dirInfo = (
845             RAF => $raf,
846             OutFile => \$outbuff,
847             );
848 1         5 $$et{BASE} = $$dirInfo{DataPos};
849 1         4 $$et{FILE_TYPE} = $$et{TIFF_TYPE} = 'JPEG';
850             # use a specialized map so we don't write XMP or IPTC (or other junk) into the JPEG
851 1         8 my $editDirs = $$et{EDIT_DIRS};
852 1         3 my $addDirs = $$et{ADD_DIRS};
853 1         7 $et->InitWriteDirs(\%jpgFromRawMap);
854             # don't add XMP segment (IPTC won't get added because it is in Photoshop record)
855 1         3 delete $$et{ADD_DIRS}{XMP};
856 1         10 my $result = $et->WriteJPEG(\%dirInfo);
857             # restore variables we changed
858 1         6 $$et{BASE} = 0;
859 1         5 $$et{FILE_TYPE} = 'TIFF';
860 1         3 $$et{TIFF_TYPE} = $fileType;
861 1         5 $$et{EDIT_DIRS} = $editDirs;
862 1         3 $$et{ADD_DIRS} = $addDirs;
863 1         5 SetByteOrder($byteOrder);
864 1 50       21 return $result > 0 ? $outbuff : $$dataPt;
865             }
866              
867             #------------------------------------------------------------------------------
868             # Extract meta information from an Panasonic JpgFromRaw
869             # Inputs: 0) ExifTool object reference, 1) dirInfo reference
870             # Returns: 1 on success, 0 if this wasn't a valid JpgFromRaw image
871             sub ProcessJpgFromRaw($$$)
872             {
873 2     2 0 11 my ($et, $dirInfo, $tagTablePtr) = @_;
874 2         6 my $dataPt = $$dirInfo{DataPt};
875 2         22 my $byteOrder = GetByteOrder();
876 2         6 my $fileType = $$et{TIFF_TYPE}; # RAW, RW2 or RWL
877 2         4 my $tagInfo = $$dirInfo{TagInfo};
878 2         9 my $verbose = $et->Options('Verbose');
879 2         13 my ($indent, $out);
880 2 50       14 $tagInfo or $et->Warn('No tag info for Panasonic JpgFromRaw'), return 0;
881 2         10 my $dirStart = $$dirInfo{DirStart};
882 2 50       18 if ($dirStart) { # DirStart is non-zero in DNG-converted RW2/RWL
883 0         0 my $dirLen = $$dirInfo{DirLen} | length($$dataPt) - $dirStart;
884 0         0 my $buff = substr($$dataPt, $dirStart, $dirLen);
885 0         0 $dataPt = \$buff;
886             }
887 2   50     11 $$et{BASE} = $$dirInfo{DataPos} + ($dirStart || 0);
888 2         9 $$et{FILE_TYPE} = $$et{TIFF_TYPE} = 'JPEG';
889 2         6 $$et{DOC_NUM} = 1;
890             # extract information from embedded JPEG
891 2         11 my %dirInfo = (
892             Parent => 'RAF',
893             RAF => new File::RandomAccess($dataPt),
894             );
895 2 50       7 if ($verbose) {
896 0         0 my $indent = $$et{INDENT};
897 0         0 $$et{INDENT} = ' ';
898 0         0 $out = $et->Options('TextOut');
899 0         0 print $out '--- DOC1:JpgFromRaw ',('-'x56),"\n";
900             }
901             # fudge HtmlDump base offsets to show as a stand-alone JPEG
902 2         13 $$et{BASE_FUDGE} = $$et{BASE};
903 2         18 my $rtnVal = $et->ProcessJPEG(\%dirInfo);
904 2         8 $$et{BASE_FUDGE} = 0;
905             # restore necessary variables for continued RW2/RWL processing
906 2         5 $$et{BASE} = 0;
907 2         4 $$et{FILE_TYPE} = 'TIFF';
908 2         5 $$et{TIFF_TYPE} = $fileType;
909 2         7 delete $$et{DOC_NUM};
910 2         11 SetByteOrder($byteOrder);
911 2 50       24 if ($verbose) {
912 0         0 $$et{INDENT} = $indent;
913 0         0 print $out ('-'x76),"\n";
914             }
915 2         11 return $rtnVal;
916             }
917              
918             1; # end
919              
920             __END__