-
Notifications
You must be signed in to change notification settings - Fork 175
/
Copy pathExifDescriptorBase.cs
985 lines (871 loc) · 37.3 KB
/
ExifDescriptorBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
// Copyright (c) Drew Noakes and contributors. All Rights Reserved. Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
using static MetadataExtractor.Formats.Exif.ExifDirectoryBase;
// ReSharper disable MemberCanBePrivate.Global
namespace MetadataExtractor.Formats.Exif
{
/// <summary>Base class for several Exif format descriptor classes.</summary>
/// <author>Drew Noakes https://drewnoakes.com</author>
public abstract class ExifDescriptorBase<T>(T directory)
: TagDescriptor<T>(directory) where T : Directory
{
public override string? GetDescription(int tagType)
{
#pragma warning disable format
return tagType switch
{
TagInteropIndex => GetInteropIndexDescription(),
TagInteropVersion => GetInteropVersionDescription(),
TagOrientation => GetOrientationDescription(),
TagResolutionUnit => GetResolutionDescription(),
TagYCbCrPositioning => GetYCbCrPositioningDescription(),
TagXResolution => GetXResolutionDescription(),
TagYResolution => GetYResolutionDescription(),
TagImageWidth => GetImageWidthDescription(),
TagImageHeight => GetImageHeightDescription(),
TagBitsPerSample => GetBitsPerSampleDescription(),
TagPhotometricInterpretation => GetPhotometricInterpretationDescription(),
TagRowsPerStrip => GetRowsPerStripDescription(),
TagStripByteCounts => GetStripByteCountsDescription(),
TagSamplesPerPixel => GetSamplesPerPixelDescription(),
TagPlanarConfiguration => GetPlanarConfigurationDescription(),
TagYCbCrSubsampling => GetYCbCrSubsamplingDescription(),
TagReferenceBlackWhite => GetReferenceBlackWhiteDescription(),
TagWinAuthor => GetWindowsAuthorDescription(),
TagWinComment => GetWindowsCommentDescription(),
TagWinKeywords => GetWindowsKeywordsDescription(),
TagWinSubject => GetWindowsSubjectDescription(),
TagWinTitle => GetWindowsTitleDescription(),
TagNewSubfileType => GetNewSubfileTypeDescription(),
TagSubfileType => GetSubfileTypeDescription(),
TagThresholding => GetThresholdingDescription(),
TagFillOrder => GetFillOrderDescription(),
TagCfaPattern2 => GetCfaPattern2Description(),
TagExposureTime => GetExposureTimeDescription(),
TagShutterSpeed => GetShutterSpeedDescription(),
TagFNumber => GetFNumberDescription(),
TagCompressedAverageBitsPerPixel => GetCompressedAverageBitsPerPixelDescription(),
TagSubjectDistance => GetSubjectDistanceDescription(),
TagMeteringMode => GetMeteringModeDescription(),
TagWhiteBalance => GetWhiteBalanceDescription(),
TagFlash => GetFlashDescription(),
TagFocalLength => GetFocalLengthDescription(),
TagColorSpace => GetColorSpaceDescription(),
TagExifImageWidth => GetExifImageWidthDescription(),
TagExifImageHeight => GetExifImageHeightDescription(),
TagFocalPlaneResolutionUnit => GetFocalPlaneResolutionUnitDescription(),
TagFocalPlaneXResolution => GetFocalPlaneXResolutionDescription(),
TagFocalPlaneYResolution => GetFocalPlaneYResolutionDescription(),
TagExposureProgram => GetExposureProgramDescription(),
TagAperture => GetApertureValueDescription(),
TagBrightnessValue => GetBrightnessValueDescription(),
TagMaxAperture => GetMaxApertureValueDescription(),
TagSensingMethod => GetSensingMethodDescription(),
TagExposureBias => GetExposureBiasDescription(),
TagFileSource => GetFileSourceDescription(),
TagSceneType => GetSceneTypeDescription(),
TagCfaPattern => GetCfaPatternDescription(),
TagComponentsConfiguration => GetComponentConfigurationDescription(),
TagExifVersion => GetExifVersionDescription(),
TagFlashpixVersion => GetFlashPixVersionDescription(),
TagIsoEquivalent => GetIsoEquivalentDescription(),
TagUserComment => GetUserCommentDescription(),
TagCustomRendered => GetCustomRenderedDescription(),
TagExposureMode => GetExposureModeDescription(),
TagWhiteBalanceMode => GetWhiteBalanceModeDescription(),
TagDigitalZoomRatio => GetDigitalZoomRatioDescription(),
Tag35MMFilmEquivFocalLength => Get35MMFilmEquivFocalLengthDescription(),
TagSceneCaptureType => GetSceneCaptureTypeDescription(),
TagGainControl => GetGainControlDescription(),
TagContrast => GetContrastDescription(),
TagSaturation => GetSaturationDescription(),
TagSharpness => GetSharpnessDescription(),
TagSubjectDistanceRange => GetSubjectDistanceRangeDescription(),
TagSensitivityType => GetSensitivityTypeDescription(),
TagCompression => GetCompressionDescription(),
TagJpegProc => GetJpegProcDescription(),
TagLensSpecification => GetLensSpecificationDescription(),
TagExtraSamples => GetExtraSamplesDescription(),
TagSampleFormat => GetSampleFormatDescription(),
_ => base.GetDescription(tagType),
};
#pragma warning restore format
}
public string? GetInteropVersionDescription()
{
return GetVersionBytesDescription(TagInteropVersion, 2);
}
public string? GetInteropIndexDescription()
{
var value = Directory.GetString(TagInteropIndex);
if (value is null)
return null;
return string.Equals("R98", value.Trim(), StringComparison.OrdinalIgnoreCase)
? "Recommended Exif Interoperability Rules (ExifR98)"
: "Unknown (" + value + ")";
}
public string? GetReferenceBlackWhiteDescription()
{
var ints = Directory.GetInt32Array(TagReferenceBlackWhite);
if (ints is null || ints.Length < 6)
return null;
var blackR = ints[0];
var whiteR = ints[1];
var blackG = ints[2];
var whiteG = ints[3];
var blackB = ints[4];
var whiteB = ints[5];
return $"[{blackR},{blackG},{blackB}] [{whiteR},{whiteG},{whiteB}]";
}
public string? GetYResolutionDescription()
{
var resolution = GetRationalOrDoubleString(TagYResolution);
if (resolution is null)
return null;
var unit = GetResolutionDescription();
return $"{resolution} dots per {unit?.ToLower() ?? "unit"}";
}
public string? GetXResolutionDescription()
{
var resolution = GetRationalOrDoubleString(TagXResolution);
if (resolution is null)
return null;
var unit = GetResolutionDescription();
return $"{resolution} dots per {unit?.ToLower() ?? "unit"}";
}
public string? GetYCbCrPositioningDescription()
{
return GetIndexedDescription(TagYCbCrPositioning, 1,
"Center of pixel array",
"Datum point");
}
public string? GetOrientationDescription()
{
return GetOrientationDescription(TagOrientation);
}
public string? GetResolutionDescription()
{
// '1' means no-unit, '2' means inch, '3' means centimeter. Default value is '2'(inch)
return GetIndexedDescription(TagResolutionUnit, 1,
"(No unit)",
"Inch",
"cm");
}
/// <summary>The Windows specific tags uses plain Unicode.</summary>
private string? GetUnicodeDescription(int tag)
{
var bytes = Directory.GetByteArray(tag);
if (bytes is null)
return null;
try
{
// Decode the Unicode string and trim the Unicode zero "\0" from the end.
return Encoding.Unicode.GetString(bytes).TrimEnd('\0');
}
catch
{
return null;
}
}
public string? GetWindowsAuthorDescription()
{
return GetUnicodeDescription(TagWinAuthor);
}
public string? GetWindowsCommentDescription()
{
return GetUnicodeDescription(TagWinComment);
}
public string? GetWindowsKeywordsDescription()
{
return GetUnicodeDescription(TagWinKeywords);
}
public string? GetWindowsTitleDescription()
{
return GetUnicodeDescription(TagWinTitle);
}
public string? GetWindowsSubjectDescription()
{
return GetUnicodeDescription(TagWinSubject);
}
public string? GetYCbCrSubsamplingDescription()
{
var positions = Directory.GetInt32Array(TagYCbCrSubsampling);
if (positions is null || positions.Length < 2)
return null;
if (positions[0] == 2 && positions[1] == 1)
return "YCbCr4:2:2";
if (positions[0] == 2 && positions[1] == 2)
return "YCbCr4:2:0";
return "(Unknown)";
}
public string? GetPlanarConfigurationDescription()
{
// When image format is no compression YCbCr, this value shows byte aligns of YCbCr
// data. If value is '1', Y/Cb/Cr value is chunky format, contiguous for each subsampling
// pixel. If value is '2', Y/Cb/Cr value is separated and stored to Y plane/Cb plane/Cr
// plane format.
return GetIndexedDescription(TagPlanarConfiguration, 1, "Chunky (contiguous for each subsampling pixel)", "Separate (Y-plane/Cb-plane/Cr-plane format)");
}
public string? GetSamplesPerPixelDescription()
{
var value = Directory.GetString(TagSamplesPerPixel);
return value is null ? null : value + " samples/pixel";
}
public string? GetRowsPerStripDescription()
{
var value = Directory.GetString(TagRowsPerStrip);
return value is null ? null : value + " rows/strip";
}
public string? GetStripByteCountsDescription()
{
var value = Directory.GetString(TagStripByteCounts);
return value is null ? null : value + " bytes";
}
public string? GetPhotometricInterpretationDescription()
{
// Shows the color space of the image data components
if (!Directory.TryGetInt32(TagPhotometricInterpretation, out int value))
return null;
return value switch
{
0 => "WhiteIsZero",
1 => "BlackIsZero",
2 => "RGB",
3 => "RGB Palette",
4 => "Transparency Mask",
5 => "CMYK",
6 => "YCbCr",
8 => "CIELab",
9 => "ICCLab",
10 => "ITULab",
32803 => "Color Filter Array",
32844 => "Pixar LogL",
32845 => "Pixar LogLuv",
32892 => "Linear Raw",
_ => "Unknown colour space",
};
}
public string? GetBitsPerSampleDescription()
{
var value = Directory.GetString(TagBitsPerSample);
return value is null ? null : value + " bits/component/pixel";
}
public string? GetImageWidthDescription()
{
var value = Directory.GetString(TagImageWidth);
return value is null ? null : value + " pixels";
}
public string? GetImageHeightDescription()
{
var value = Directory.GetString(TagImageHeight);
return value is null ? null : value + " pixels";
}
public string? GetNewSubfileTypeDescription()
{
return GetIndexedDescription(TagNewSubfileType, 0,
"Full-resolution image",
"Reduced-resolution image",
"Single page of multi-page image",
"Single page of multi-page reduced-resolution image",
"Transparency mask",
"Transparency mask of reduced-resolution image",
"Transparency mask of multi-page image",
"Transparency mask of reduced-resolution multi-page image");
}
public string? GetSubfileTypeDescription()
{
return GetIndexedDescription(TagSubfileType, 1,
"Full-resolution image",
"Reduced-resolution image",
"Single page of multi-page image");
}
public string? GetThresholdingDescription()
{
return GetIndexedDescription(TagThresholding, 1,
"No dithering or halftoning",
"Ordered dither or halftone",
"Randomized dither");
}
public string? GetFillOrderDescription()
{
return GetIndexedDescription(TagFillOrder, 1,
"Normal",
"Reversed");
}
public string? GetSubjectDistanceRangeDescription()
{
return GetIndexedDescription(TagSubjectDistanceRange,
"Unknown",
"Macro",
"Close view",
"Distant view");
}
public string? GetSensitivityTypeDescription()
{
return GetIndexedDescription(TagSensitivityType,
"Unknown",
"Standard Output Sensitivity",
"Recommended Exposure Index",
"ISO Speed",
"Standard Output Sensitivity and Recommended Exposure Index",
"Standard Output Sensitivity and ISO Speed",
"Recommended Exposure Index and ISO Speed",
"Standard Output Sensitivity, Recommended Exposure Index and ISO Speed");
}
public string? GetLensSpecificationDescription()
{
return GetLensSpecificationDescription(TagLensSpecification);
}
public string? GetSharpnessDescription()
{
return GetIndexedDescription(TagSharpness,
"None",
"Low",
"Hard");
}
public string? GetSaturationDescription()
{
return GetIndexedDescription(TagSaturation,
"None",
"Low saturation",
"High saturation");
}
public string? GetContrastDescription()
{
return GetIndexedDescription(TagContrast,
"None",
"Soft",
"Hard");
}
public string? GetGainControlDescription()
{
return GetIndexedDescription(TagGainControl,
"None",
"Low gain up",
"Low gain down",
"High gain up",
"High gain down");
}
public string? GetSceneCaptureTypeDescription()
{
return GetIndexedDescription(TagSceneCaptureType,
"Standard",
"Landscape",
"Portrait",
"Night scene");
}
public string? Get35MMFilmEquivFocalLengthDescription()
{
if (!Directory.TryGetInt32(Tag35MMFilmEquivFocalLength, out int value))
return null;
return value == 0 ? "Unknown" : GetFocalLengthDescription(value);
}
public string? GetDigitalZoomRatioDescription()
{
if (!Directory.TryGetRational(TagDigitalZoomRatio, out Rational value))
return null;
return value.Numerator == 0
? "Digital zoom not used"
: value.ToDouble().ToString("0.#");
}
public string? GetWhiteBalanceModeDescription()
{
return GetIndexedDescription(TagWhiteBalanceMode,
"Auto white balance",
"Manual white balance");
}
public string? GetExposureModeDescription()
{
return GetIndexedDescription(TagExposureMode,
"Auto exposure",
"Manual exposure",
"Auto bracket");
}
public string? GetCustomRenderedDescription()
{
return GetIndexedDescription(TagCustomRendered,
"Normal process",
"Custom process");
}
public string? GetUserCommentDescription()
{
return GetEncodedTextDescription(TagUserComment);
}
public string? GetIsoEquivalentDescription()
{
// Have seen an exception here from files produced by ACDSEE that stored an int[] here with two values
// There used to be a check here that multiplied ISO values < 50 by 200.
// Issue 36 shows a smart-phone image from a Samsung Galaxy S2 with ISO-40.
if (!Directory.TryGetInt32(TagIsoEquivalent, out int value))
return null;
return value.ToString();
}
public string? GetExifVersionDescription()
{
return GetVersionBytesDescription(TagExifVersion, 2);
}
public string? GetFlashPixVersionDescription()
{
return GetVersionBytesDescription(TagFlashpixVersion, 2);
}
public string? GetSceneTypeDescription()
{
return GetIndexedDescription(TagSceneType, 1,
"Directly photographed image");
}
/// <summary>
/// String description of CFA Pattern
/// </summary>
/// <remarks>
/// Converted from Exiftool version 10.33 created by Phil Harvey
/// http://www.sno.phy.queensu.ca/~phil/exiftool/
/// lib\Image\ExifTool\Exif.pm
///
/// Indicates the color filter array (CFA) geometric pattern of the image sensor when a one-chip color area sensor is used.
/// It does not apply to all sensing methods.
/// </remarks>
public string? GetCfaPatternDescription()
{
return FormatCfaPattern(DecodeCfaPattern(TagCfaPattern));
}
/// <summary>
/// String description of CFA Pattern
/// </summary>
/// <remarks>
/// Indicates the color filter array (CFA) geometric pattern of the image sensor when a one-chip color area sensor is used.
/// It does not apply to all sensing methods.
///
/// <see cref="TagCfaPattern2"/> holds only the pixel pattern. <see cref="TagCfaRepeatPatternDim"/> is expected to exist and pass
/// some conditional tests.
/// </remarks>
public string? GetCfaPattern2Description()
{
var values = Directory.GetByteArray(TagCfaPattern2);
if (values is null)
return null;
if (Directory.GetObject(TagCfaRepeatPatternDim) is not ushort[] repeatPattern)
return $"Repeat Pattern not found for CFAPattern ({base.GetDescription(TagCfaPattern2)})";
if (repeatPattern.Length == 2 && values.Length == (repeatPattern[0] * repeatPattern[1]))
{
var intpattern = new int[2 + values.Length];
intpattern[0] = repeatPattern[0];
intpattern[1] = repeatPattern[1];
Array.Copy(values, 0, intpattern, 2, values.Length);
return FormatCfaPattern(intpattern);
}
return $"Unknown Pattern ({base.GetDescription(TagCfaPattern2)})";
}
private static string? FormatCfaPattern(int[]? pattern)
{
if (pattern is null)
return null;
if (pattern.Length < 2)
return "<truncated data>";
if (pattern[0] == 0 && pattern[1] == 0)
return "<zero pattern size>";
var end = 2 + pattern[0] * pattern[1];
if (end > pattern.Length)
return "<invalid pattern size>";
string[] cfaColors = ["Red", "Green", "Blue", "Cyan", "Magenta", "Yellow", "White"];
var ret = new StringBuilder();
ret.Append('[');
for (var pos = 2; pos < end; pos++)
{
if (pattern[pos] <= cfaColors.Length - 1)
ret.Append(cfaColors[pattern[pos]]);
else
ret.Append("Unknown"); // indicated pattern position is outside the array bounds
if ((pos - 2) % pattern[1] == 0)
ret.Append(',');
else if (pos != end - 1)
ret.Append("][");
}
ret.Append(']');
return ret.ToString();
}
/// <summary>
/// Decode raw CFAPattern value
/// </summary>
/// <remarks>
/// Converted from Exiftool version 10.33 created by Phil Harvey
/// http://www.sno.phy.queensu.ca/~phil/exiftool/
/// lib\Image\ExifTool\Exif.pm
///
/// The value consists of:
/// - Two short, being the grid width and height of the repeated pattern.
/// - Next, for every pixel in that pattern, an identification code.
/// </remarks>
private int[]? DecodeCfaPattern(int tagType)
{
int[] ret;
var values = Directory.GetByteArray(tagType);
if (values is null)
return null;
if (values.Length < 4)
{
ret = new int[values.Length];
for (var i = 0; i < values.Length; i++)
ret[i] = values[i];
return ret;
}
var reader = new BufferReader(values, isBigEndian: true);
// first two values should be read as 16-bits (2 bytes)
var item0 = reader.GetInt16(0);
var item1 = reader.GetInt16(2);
ret = new int[values.Length - 2];
var copyArray = false;
var end = 2 + item0 * item1;
if (end > values.Length) // sanity check in case of byte order problems; calculated 'end' should be <= length of the values
{
// try swapping byte order (I have seen this order different than in EXIF)
reader = new BufferReader(values, isBigEndian: !reader.IsBigEndian);
item0 = reader.GetInt16(0);
item1 = reader.GetInt16(2);
if (values.Length >= 2 + item0 * item1)
copyArray = true;
}
else
{
copyArray = true;
}
if (copyArray)
{
ret[0] = item0;
ret[1] = item1;
for (var i = 4; i < values.Length; i++)
ret[i - 2] = reader.GetByte(i);
}
return ret;
}
public string? GetFileSourceDescription()
{
return GetIndexedDescription(TagFileSource, 1,
"Film Scanner",
"Reflection Print Scanner",
"Digital Still Camera (DSC)");
}
public string? GetExposureBiasDescription()
{
if (!Directory.TryGetRational(TagExposureBias, out Rational value))
return null;
return value.ToSimpleString() + " EV";
}
public string? GetMaxApertureValueDescription()
{
if (!Directory.TryGetDouble(TagMaxAperture, out double aperture))
return null;
return GetFStopDescription(PhotographicConversions.ApertureToFStop(aperture));
}
public string? GetApertureValueDescription()
{
if (!Directory.TryGetDouble(TagAperture, out double aperture))
return null;
return GetFStopDescription(PhotographicConversions.ApertureToFStop(aperture));
}
public string? GetBrightnessValueDescription()
{
if (!Directory.TryGetRational(TagBrightnessValue, out Rational value))
return null;
if (value.Numerator == 0xFFFFFFFFL)
return "Unknown";
return $"{value.ToDouble():0.0##}";
}
public string? GetExposureProgramDescription()
{
return GetIndexedDescription(TagExposureProgram, 1,
"Manual control",
"Program normal",
"Aperture priority",
"Shutter priority",
"Program creative (slow program)",
"Program action (high-speed program)",
"Portrait mode",
"Landscape mode");
}
public string? GetFocalPlaneXResolutionDescription()
{
if (!Directory.TryGetRational(TagFocalPlaneXResolution, out Rational value))
return null;
var unit = GetFocalPlaneResolutionUnitDescription();
return value.Reciprocal.ToSimpleString() + (unit is null ? string.Empty : " " + unit.ToLower());
}
public string? GetFocalPlaneYResolutionDescription()
{
if (!Directory.TryGetRational(TagFocalPlaneYResolution, out Rational value))
return null;
var unit = GetFocalPlaneResolutionUnitDescription();
return value.Reciprocal.ToSimpleString() + (unit is null ? string.Empty : " " + unit.ToLower());
}
public string? GetFocalPlaneResolutionUnitDescription()
{
// Unit of FocalPlaneXResolution/FocalPlaneYResolution.
// '1' means no-unit, '2' inch, '3' centimeter.
return GetIndexedDescription(TagFocalPlaneResolutionUnit, 1,
"(No unit)",
"Inches",
"cm");
}
public string? GetExifImageWidthDescription()
{
if (!Directory.TryGetInt32(TagExifImageWidth, out int value))
return null;
return value + " pixels";
}
public string? GetExifImageHeightDescription()
{
if (!Directory.TryGetInt32(TagExifImageHeight, out int value))
return null;
return value + " pixels";
}
public string? GetColorSpaceDescription()
{
if (!Directory.TryGetInt32(TagColorSpace, out int value))
return null;
if (value == 1)
return "sRGB";
if (value == 65535)
return "Undefined";
return "Unknown (" + value + ")";
}
public string? GetFocalLengthDescription()
{
if (!Directory.TryGetRational(TagFocalLength, out Rational value))
return null;
return GetFocalLengthDescription(value.ToDouble());
}
public string? GetFlashDescription()
{
/*
* This is a bit mask.
* 0 = flash fired
* 1 = return detected
* 2 = return able to be detected
* 3 = unknown
* 4 = auto used
* 5 = unknown
* 6 = red eye reduction used
*/
if (!Directory.TryGetInt32(TagFlash, out int value))
return null;
var sb = new StringBuilder();
sb.Append((value & 0x1) != 0 ? "Flash fired" : "Flash did not fire");
// check if we're able to detect a return, before we mention it
if ((value & 0x4) != 0)
sb.Append((value & 0x2) != 0 ? ", return detected" : ", return not detected");
// If 0x10 is set and the lowest byte is not zero - then flash is Auto
if ((value & 0x10) != 0 && (value & 0x0F) != 0)
sb.Append(", auto");
if ((value & 0x40) != 0)
sb.Append(", red-eye reduction");
return sb.ToString();
}
public string? GetWhiteBalanceDescription()
{
if (!Directory.TryGetInt32(TagWhiteBalance, out int value))
return null;
return GetWhiteBalanceDescription(value);
}
internal static string GetWhiteBalanceDescription(int value)
{
// See http://web.archive.org/web/20131018091152/http://exif.org/Exif2-2.PDF page 35
return value switch
{
0 => "Unknown",
1 => "Daylight",
2 => "Florescent",
3 => "Tungsten (Incandescent)",
4 => "Flash",
9 => "Fine Weather",
10 => "Cloudy",
11 => "Shade",
12 => "Daylight Fluorescent", // (D 5700 - 7100K)
13 => "Day White Fluorescent", // (N 4600 - 5500K)
14 => "Cool White Fluorescent", // (W 3800 - 4500K)
15 => "White Fluorescent", // (WW 3250 - 3800K)
16 => "Warm White Fluorescent", // (L 2600 - 3250K)
17 => "Standard light A",
18 => "Standard light B",
19 => "Standard light C",
20 => "D55",
21 => "D65",
22 => "D75",
23 => "D50",
24 => "ISO Studio Tungsten",
255 => "Other",
_ => "Unknown (" + value + ")",
};
}
public string? GetMeteringModeDescription()
{
// '0' means unknown, '1' average, '2' center weighted average, '3' spot
// '4' multi-spot, '5' multi-segment, '6' partial, '255' other
if (!Directory.TryGetInt32(TagMeteringMode, out int value))
return null;
return value switch
{
0 => "Unknown",
1 => "Average",
2 => "Center weighted average",
3 => "Spot",
4 => "Multi-spot",
5 => "Multi-segment",
6 => "Partial",
255 => "(Other)",
_ => "Unknown (" + value + ")",
};
}
public string? GetCompressionDescription()
{
if (!Directory.TryGetInt32(TagCompression, out int value))
return null;
return value switch
{
1 => "Uncompressed",
2 => "CCITT 1D",
3 => "T4/Group 3 Fax",
4 => "T6/Group 4 Fax",
5 => "LZW",
6 => "JPEG (old-style)",
7 => "JPEG",
8 => "Adobe Deflate",
9 => "JBIG B&W",
10 => "JBIG Color",
99 => "JPEG",
262 => "Kodak 262",
32766 => "Next",
32767 => "Sony ARW Compressed",
32769 => "Packed RAW",
32770 => "Samsung SRW Compressed",
32771 => "CCIRLEW",
32772 => "Samsung SRW Compressed 2",
32773 => "PackBits",
32809 => "Thunderscan",
32867 => "Kodak KDC Compressed",
32895 => "IT8CTPAD",
32896 => "IT8LW",
32897 => "IT8MP",
32898 => "IT8BL",
32908 => "PixarFilm",
32909 => "PixarLog",
32946 => "Deflate",
32947 => "DCS",
34661 => "JBIG",
34676 => "SGILog",
34677 => "SGILog24",
34712 => "JPEG 2000",
34713 => "Nikon NEF Compressed",
34715 => "JBIG2 TIFF FX",
34718 => "Microsoft Document Imaging (MDI) Binary Level Codec",
34719 => "Microsoft Document Imaging (MDI) Progressive Transform Codec",
34720 => "Microsoft Document Imaging (MDI) Vector",
34892 => "Lossy JPEG",
65000 => "Kodak DCR Compressed",
65535 => "Pentax PEF Compressed",
_ => "Unknown (" + value + ")",
};
}
public string? GetSubjectDistanceDescription()
{
if (!Directory.TryGetRational(TagSubjectDistance, out Rational value))
return null;
if (value.Numerator == 0xFFFFFFFFL)
return "Infinity";
if (value.Numerator == 0)
return "Unknown";
return $"{value.ToDouble():0.0##} metres";
}
public string? GetCompressedAverageBitsPerPixelDescription()
{
if (!Directory.TryGetRational(TagCompressedAverageBitsPerPixel, out Rational value))
return null;
var ratio = value.ToSimpleString();
return value.IsInteger && value.ToInt32() == 1 ? ratio + " bit/pixel" : ratio + " bits/pixel";
}
public string? GetExposureTimeDescription()
{
var value = Directory.GetString(TagExposureTime);
return value is null ? null : value + " sec";
}
public string? GetShutterSpeedDescription()
{
return GetShutterSpeedDescription(TagShutterSpeed);
}
public string? GetFNumberDescription()
{
if (!Directory.TryGetRational(TagFNumber, out Rational value))
return null;
return GetFStopDescription(value.ToDouble());
}
public string? GetSensingMethodDescription()
{
// '1' Not defined, '2' One-chip color area sensor, '3' Two-chip color area sensor
// '4' Three-chip color area sensor, '5' Color sequential area sensor
// '7' Trilinear sensor '8' Color sequential linear sensor, 'Other' reserved
return GetIndexedDescription(TagSensingMethod, 1,
"(Not defined)",
"One-chip color area sensor",
"Two-chip color area sensor",
"Three-chip color area sensor",
"Color sequential area sensor",
null,
"Trilinear sensor",
"Color sequential linear sensor");
}
public string? GetComponentConfigurationDescription()
{
var components = Directory.GetInt32Array(TagComponentsConfiguration);
if (components is null)
return null;
var componentStrings = new[] { string.Empty, "Y", "Cb", "Cr", "R", "G", "B" };
var componentConfig = new StringBuilder();
for (var i = 0; i < Math.Min(4, components.Length); i++)
{
var j = components[i];
if (j > 0 && j < componentStrings.Length)
componentConfig.Append(componentStrings[j]);
}
return componentConfig.ToString();
}
public string? GetJpegProcDescription()
{
if (!Directory.TryGetInt32(TagJpegProc, out int value))
return null;
return value switch
{
1 => "Baseline",
14 => "Lossless",
_ => "Unknown (" + value + ")",
};
}
public string? GetExtraSamplesDescription()
{
return GetIndexedDescription(
TagExtraSamples,
"Unspecified",
"Associated alpha",
"Unassociated alpha");
}
public string? GetSampleFormatDescription()
{
var values = Directory.GetInt32Array(TagSampleFormat);
if (values is null)
return null;
var sb = new StringBuilder();
foreach (var value in values)
{
if (sb.Length != 0)
sb.Append(", ");
sb.Append(value switch
{
1 => "Unsigned",
2 => "Signed",
3 => "Float",
4 => "Undefined",
5 => "Complex int",
6 => "Complex float",
_ => $"Unknown ({value})"
});
}
return sb.ToString();
}
}
}