-
Notifications
You must be signed in to change notification settings - Fork 4
/
ExifRewriteFiles.cs
2443 lines (2391 loc) · 116 KB
/
ExifRewriteFiles.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
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace KMZ_Viewer
{
/// <summary>
/// ExifInfo READ/WRITE
/// </summary>
public class ExifInfo
{
public List<IFD_Entry> Entries = new List<IFD_Entry>();
public int Count
{
get
{
if (Entries == null) return 0;
return Entries.Count;
}
}
public void TrimUnknown()
{
if (Count == 0) return;
for (int i = Entries.Count - 1; i >= 0; i--)
if (Entries[i].entry_tag_name == "unknown")
Entries.RemoveAt(i);
}
public static IFD_Entry[] ParseExifSrc(byte[] ff00_exif_data)
{
List<byte> normal = new List<byte>();
normal.Add(ff00_exif_data[0]);
for (int i = 1; i < ff00_exif_data.Length; i++)
{
if ((ff00_exif_data[i - 1] == 0xFF) && (ff00_exif_data[i] == 0x00))
continue;
else
normal.Add(ff00_exif_data[i]);
};
return ParseExifNrm(normal.ToArray());
}
public static IFD_Entry[] ParseExifNrm(byte[] normallized_exif_data)
{
string exif_header = System.Text.Encoding.ASCII.GetString(normallized_exif_data, 0, 6);
if (exif_header != "Exif\0\0") return null; // No Valid Data
byte[] data = new byte[normallized_exif_data.Length - 6];
Array.Copy(normallized_exif_data, 6, data, 0, data.Length);
bool littleEndian = false;
if ((data[0] == 0x49) && (data[1] == 0x49)) // Intel type byte align
littleEndian = true;
if ((data[0] == 0x4D) && (data[1] == 0x4D)) // Motorola type byte align
littleEndian = false;
MyBitConverter bc = new MyBitConverter(littleEndian);
bool valid_tiff_header = false;
if (littleEndian && (data[2] == 0x2A) && (data[3] == 0x00)) valid_tiff_header = true;
if ((!littleEndian) && (data[3] == 0x2A) && (data[2] == 0x00)) valid_tiff_header = true;
if (!valid_tiff_header) throw new IOException("Invalid Tiff Header");
List<ushort> entry_no = new List<ushort>();
List<uint> entry_offsets = new List<uint>();
entry_no.Add(0); entry_offsets.Add(bc.ToUInt32(data, 4)); // offset to IFD record // IFD0
List<IFD_Entry> Exif = new List<IFD_Entry>();
ushort IFD_ID = 0;
while (entry_offsets.Count > 0)
{
ushort number = entry_no[0]; entry_no.RemoveAt(0);
uint offset = entry_offsets[0]; entry_offsets.RemoveAt(0);
int maxEntNo = (data.Length - 2 - 4 - 8) / 12;
ushort entNo = bc.ToUInt16(data, (int)offset); // number of entries in IFD // 2 bytes
if (entNo > 890) continue; // wrong data
bool add = true;
for (int i = 0; i < entNo; i++)
{
try
{
int _eo = (int)offset + 2 + i * 12;
if(_eo >= data.Length) continue;
IFD_Entry ent = new IFD_Entry(number, bc, data, _eo);
if (ent.entry_tag_number == 0x0000 ) continue;
if (ent.data_length_calculated == 0) continue;
if (ent.entry_tag_number == 0x8769) // ExifOffset(0x8769). Its value is an offset to Exif SubIFD
{
entry_no.Add(0x8769);
entry_offsets.Add((uint)ent.entry_value);
add = false;
};
if (ent.entry_tag_number == 0x8825) // ExifOffset(0x8825). Its value is an offset to GPS SubIFD
{
entry_no.Add(0x8825);
entry_offsets.Add((uint)ent.entry_value);
add = false;
}
if (ent.entry_tag_number == 0xA005) // ExifOffset(0xA005). Its value is an offset to Interoperability SubIFD
{
entry_no.Add(0xA005);
entry_offsets.Add((uint)ent.entry_value);
add = false;
}
if ((ent.entry_tag_number == 0x927C) && (ent.entry_value is byte[])) // MakerNote
{
string bs = System.Text.Encoding.ASCII.GetString((byte[])ent.entry_value,0,5);
if (bs == "Nikon")
{
byte[] NikonData = new byte[ent.data_length_calculated-10+6];
Array.Copy(System.Text.Encoding.ASCII.GetBytes("Exif\0\0"), 0, NikonData, 0, 6);
Array.Copy((byte[])ent.entry_value, 10, NikonData, 6, ent.data_length_calculated - 10);
IFD_Entry[] NikonEntries = ParseExifNrm(NikonData);
if ((NikonEntries != null) && (NikonEntries.Length > 0))
{
foreach (IFD_Entry en in NikonEntries)
en.entry_IFD_number = 0x927C;
Exif.AddRange(NikonEntries);
};
};
};
if (add)
Exif.Add(ent);
}
catch { };
};
offset = offset + (uint)2 + (uint)entNo * (uint)12;
if (offset >= data.Length) continue;
offset = bc.ToUInt32(data, (int)offset);
if ((offset > 10) && (offset < normallized_exif_data.Length))
{
entry_no.Add(IFD_ID++);
entry_offsets.Add(offset);
};
};
return Exif.ToArray();
}
public static ExifInfo ParseExifFile(string jpeg_file_name)
{
ExifInfo exi = new ExifInfo();
FileStream fs = new FileStream(jpeg_file_name, FileMode.Open, FileAccess.Read);
int prev_byte = fs.ReadByte();
if ((prev_byte == 0xFF) && ((prev_byte = fs.ReadByte()) == 0xD8)) // JPEG TAG
{
while (prev_byte >= 0)
{
if ((prev_byte == 0xFF) && ((prev_byte = fs.ReadByte()) >= 0xE0)) // JFIF
{
int len = (((byte)fs.ReadByte()) << 8) + fs.ReadByte() - 2; // Exif Length
byte[] exif_data = new byte[len];
fs.Read(exif_data, 0, len);
if (prev_byte == 0xE1) // Exif
{
IFD_Entry[] entries = ExifInfo.ParseExifSrc(exif_data);
if ((entries != null) && (entries.Length != 0))
exi.Entries.AddRange(entries);
};
}
else
prev_byte = fs.ReadByte();
};
};
fs.Close();
return exi;
}
public IFD_Entry this[string name]
{
get
{
string nm = name.ToLower().Trim();
if (Entries.Count == 0) return null;
for (int i = 0; i < Entries.Count; i++)
if (Entries[i].entry_tag_name.ToLower() == nm)
return Entries[i];
return null;
}
}
public IFD_Entry this[int index]
{
get
{
if (Entries.Count == 0) return null;
for (int i = 0; i < Entries.Count; i++)
if (Entries[i].entry_tag_number == index)
return Entries[i];
return null;
}
}
public string this[string key, string nullValue]
{
get
{
IFD_Entry result = this[key];
if (result == null)
return nullValue;
else
return result.entry_text;
}
}
public string this[int index, string nullValue]
{
get
{
IFD_Entry result = this[index];
if (result == null)
return nullValue;
else
return result.entry_text;
}
}
public class IFD_Entry
{
public int entry_IFD_number;
public ushort entry_tag_number;
public ushort entry_data_format;
public Type entry_format_type;
public object entry_value;
public uint data_number_of_components;
public uint data_value_or_offset;
public uint data_length_calculated;
public uint data_offset_in_exif;
private int _offset;
public override string ToString()
{
return String.Format("0x{0:X4} {1}: {2}", new object[] { entry_tag_number, entry_tag_name, entry_value });
}
public string entry_text
{
get
{
if (entry_tag_number == 0xa460) // CompositeImage
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 0: return "Unknown";
case 1: return "Not a Composite Image";
case 2: return "General Composite Image";
case 3: return "Composite Image Captured While Shooting";
};
};
if (entry_tag_number == 0xa40C) // SubjectDistanceRange
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 0: return "Unknown";
case 1: return "Macro";
case 2: return "Close";
case 3: return "Distant";
};
};
if (entry_tag_number == 0xa40A) // Sharpness
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 0: return "Normal";
case 1: return "Soft";
case 2: return "Hard";
};
};
if (entry_tag_number == 0xa409) // Saturation
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 0: return "Normal";
case 1: return "Low";
case 2: return "High";
};
};
if (entry_tag_number == 0xa408) // Contrast
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 0: return "Normal";
case 1: return "Low";
case 2: return "High";
};
};
if (entry_tag_number == 0xa407) // GainControl
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 0: return "None";
case 1: return "Low gain up";
case 2: return "High gain up";
case 3: return "Low gain down";
case 4: return "High gain down";
};
};
if (entry_tag_number == 0xa406) // SceneCaptureType
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 0: return "Standard";
case 1: return "Landscape";
case 2: return "Portrait";
case 3: return "Night";
case 4: return "Other";
};
};
if (entry_tag_number == 0xa403) // WhiteBalance
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 0: return "Auto";
case 1: return "Manual";
};
};
if (entry_tag_number == 0xa402) // ExposureMode
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 0: return "Auto";
case 1: return "Manual";
case 2: return "Auto bracket";
};
};
if (entry_tag_number == 0xa401) // CustomRendered
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 0: return "Normal";
case 1: return "Custom";
case 2: return "HDR (no original saved)";
case 3: return "HDR (original saved)";
case 4: return "Original (for HDR)";
case 6: return "Panorama";
case 7: return "Portrait HDR";
case 8: return "Portrait";
};
};
if (entry_tag_number == 0xa217) // SensingMethod
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 1: return "Not defined";
case 2: return "One-chip color area";
case 3: return "Two-chip color area";
case 4: return "Three-chip color area";
case 5: return "Color sequential area";
case 7: return "Trilinear";
case 8: return "Color sequential linear";
};
};
if (entry_tag_number == 0xa210) // FocalPlaneResolutionUnit
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 1: return "None";
case 2: return "inches";
case 3: return "cm";
case 4: return "mm";
case 5: return "um";
};
};
if (entry_tag_number == 0xa001) // ColorSpace
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 0x0001: return "sRGB";
case 0x0002: return "Adobe RGB";
case 0xfffd: return "Wide Gamut RGB";
case 0xfffe: return "ICC Profile";
case 0xffff: return "Uncalibrated";
};
};
if (entry_tag_number == 0x9209) // FLASH
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 0x0: return "No Flash";
case 0x1: return "Fired";
case 0x5: return "Fired, Return not detected";
case 0x7: return "Fired, Return detected";
case 0x8: return "On, Did not fire";
case 0x9: return "On, Fired";
case 0xd: return "On, Return not detected";
case 0xf: return "On, Return detected";
case 0x10: return "Off, Did not fire";
case 0x14: return "Off, Did not fire, Return not detected";
case 0x18: return "Auto, Did not fire";
case 0x19: return "Auto, Fired";
case 0x1d: return "Auto, Fired, Return not detected";
case 0x1f: return "Auto, Fired, Return detected";
case 0x20: return "No flash function";
case 0x30: return "Off, No flash function";
case 0x41: return "Fired, Red-eye reduction";
case 0x45: return "Fired, Red-eye reduction, Return not detected";
case 0x47: return "Fired, Red-eye reduction, Return detected";
case 0x49: return "On, Red-eye reduction";
case 0x4d: return "On, Red-eye reduction, Return not detected";
case 0x4f: return "On, Red-eye reduction, Return detected";
case 0x50: return "Off, Red-eye reduction";
case 0x58: return "Auto, Did not fire, Red-eye reduction";
case 0x59: return "Auto, Fired, Red-eye reduction";
case 0x5d: return "Auto, Fired, Red-eye reduction, Return not detected";
case 0x5f: return "Auto, Fired, Red-eye reduction, Return detected";
};
};
if (entry_tag_number == 0x9208) // LightSource
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 0: return "Unknown";
case 1: return "Daylight";
case 2: return "Fluorescent";
case 3: return "Tungsten (Incandescent)";
case 4: return "Flash";
case 9: return "Fine Weather";
case 10: return "Cloudy";
case 11: return "Shade";
case 12: return "Daylight Fluorescent";
case 13: return "Day White Fluorescent";
case 14: return "Cool White Fluorescent";
case 15: return "White Fluorescent";
case 16: return "Warm White Fluorescent";
case 17: return "Standard Light A";
case 18: return "Standard Light B";
case 19: return "Standard Light C";
case 20: return "D55";
case 21: return "D65";
case 22: return "D75";
case 23: return "D50";
case 24: return "ISO Studio Tungsten";
case 255: return "Other";
};
};
if (entry_tag_number == 0x9207) // MeteringMode
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 0: return "Unknown";
case 1: return "Average";
case 2: return "Center-weighted average";
case 3: return "Spot";
case 4: return "Multi-spot";
case 5: return "Multi-segment";
case 6: return "Partial";
case 255: return "Other";
};
};
if (entry_tag_number == 0x9000) // ExifVersion
{
byte[] val = new byte[0];
try {
val = (byte[])entry_value;
return System.Text.Encoding.ASCII.GetString(val);
}
catch { };
};
if (entry_tag_number == 0x8830) // SensitivityType
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 0: return "Unknown";
case 1: return "Standard Output Sensitivity";
case 2: return "Recommended Exposure Index";
case 3: return "ISO Speed";
case 4: return "Standard Output Sensitivity and Recommended Exposure Index";
case 5: return "Standard Output Sensitivity and ISO Speed";
case 6: return "Recommended Exposure Index and ISO Speed";
case 7: return "Standard Output Sensitivity, Recommended Exposure Index and ISO Speed";
};
};
if (entry_tag_number == 0x8822) // ExposureProgram
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 0: return "Not Defined";
case 1: return "Manual";
case 2: return "Program AE";
case 3: return "Aperture-priority AE";
case 4: return "Shutter speed priority AE";
case 5: return "Creative (Slow speed)";
case 6: return "Action (High speed)";
case 7: return "Portrait";
case 8: return "Landscape";
case 9: return "Bulb";
};
};
if (entry_tag_number == 0x013D) // Predictor
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 1: return "None";
case 2: return "Horizontal differencing";
};
};
if (entry_tag_number == 0x0128) // ResolutionUnit
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 1: return "None ";
case 2: return "inches ";
case 3: return "cm";
};
};
if (entry_tag_number == 0x0122) // GrayResponseUnit
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 1: return "0.1";
case 2: return "0.001";
case 3: return "0.0001";
case 4: return "1e-05";
case 5: return "1e-06";
};
};
if (entry_tag_number == 0x011C) // PlanarConfiguration
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 1: return "Chunky";
case 2: return "Planar";
};
};
if (entry_tag_number == 0x0112) // Orientation
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 1: return "Horizontal (normal)";
case 2: return "Mirror horizontal";
case 3: return "Rotate 180";
case 4: return "Mirror vertical";
case 5: return "Mirror horizontal and rotate 270 CW";
case 6: return "Rotate 90 CW";
case 7: return "Mirror horizontal and rotate 90 CW";
case 8: return "Rotate 270 CW";
};
};
if (entry_tag_number == 0x010A) // FillOrder
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 1: return "Normal";
case 2: return "Reversed";
};
};
if (entry_tag_number == 0x0107) // Thresholding
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 1: return "No dithering or halftoning";
case 2: return "Ordered dither or halftone";
case 3: return "Randomized dither";
};
};
if (entry_tag_number == 0x0106) // PhotometricInterpretation
{
ushort val = 0;
try { val = (ushort)entry_value; }
catch { return entry_value.ToString().Trim('\0').Trim(); };
switch (val)
{
case 0: return "WhiteIsZero";
case 1: return "BlackIsZero";
case 2: return "RGB";
case 3: return "RGB Palette";
case 4: return "Transparency Mask";
case 5: return "CMYK";
case 6: return "YCbCr";
case 8: return "CIELab";
case 9: return "ICCLab";
case 10: return "ITULab";
case 32803: return "Color Filter Array";
case 32844: return "Pixar LogL";
case 32845: return "Pixar LogLuv";
case 32892: return "Sequential Color Filter";
case 34892: return "Linear Raw";
};
};
return entry_value.ToString().Trim('\0').Trim();
}
}
public string entry_tag_name
{
get
{
if (entry_IFD_number == 0x8825) // GPSInfo
return TagNameForGPS(entry_tag_number);
if (entry_IFD_number == 0x927C) // Nikon IFD
return TagNameForNikon(entry_tag_number);
return TagNameByNumber(entry_tag_number);
}
}
// https://exiv2.org/tags-nikon.html
public static string TagNameForNikon(int number)
{
switch (number)
{
case 0x0001: return "Nikon.Version";
case 0x0002: return "Nikon.ISOSpeed";
case 0x0003: return "Nikon.ColorMode";
case 0x0004: return "Nikon.Quality";
case 0x0005: return "Nikon.WhiteBalance";
case 0x0006: return "Nikon.Sharpening";
case 0x0007: return "Nikon.Focus";
case 0x0008: return "Nikon.FlashSetting";
case 0x0009: return "Nikon.FlashDevice";
case 0x000a: return "Nikon.0x000a";
case 0x000b: return "Nikon.WhiteBalanceBias";
case 0x000c: return "Nikon.WB_RBLevels";
case 0x000d: return "Nikon.ProgramShift";
case 0x000e: return "Nikon.ExposureDiff";
case 0x000f: return "Nikon.ISOSelection";
case 0x0010: return "Nikon.DataDump";
case 0x0011: return "Nikon.Preview";
case 0x0012: return "Nikon.FlashComp";
case 0x0013: return "Nikon.ISOSettings";
case 0x0016: return "Nikon.ImageBoundary";
case 0x0017: return "Nikon.FlashExposureComp";
case 0x0018: return "Nikon.FlashBracketComp";
case 0x0019: return "Nikon.ExposureBracketComp";
case 0x001a: return "Nikon.ImageProcessing";
case 0x001b: return "Nikon.CropHiSpeed";
case 0x001c: return "Nikon.ExposureTuning";
case 0x001d: return "Nikon.SerialNumber";
case 0x001e: return "Nikon.ColorSpace";
case 0x001f: return "Nikon.VRInfo";
case 0x0020: return "Nikon.ImageAuthentication";
case 0x0022: return "Nikon.ActiveDLighting";
case 0x0023: return "Nikon.PictureControl";
case 0x0024: return "Nikon.WorldTime";
case 0x0025: return "Nikon.ISOInfo";
case 0x002a: return "Nikon.VignetteControl";
case 0x0080: return "Nikon.ImageAdjustment";
case 0x0081: return "Nikon.ToneComp";
case 0x0082: return "Nikon.AuxiliaryLens";
case 0x0083: return "Nikon.LensType";
case 0x0084: return "Nikon.Lens";
case 0x0085: return "Nikon.FocusDistance";
case 0x0086: return "Nikon.DigitalZoom";
case 0x0087: return "Nikon.FlashMode";
case 0x0088: return "Nikon.AFInfo";
case 0x0089: return "Nikon.ShootingMode";
case 0x008a: return "Nikon.AutoBracketRelease";
case 0x008b: return "Nikon.LensFStops";
case 0x008c: return "Nikon.ContrastCurve";
case 0x008d: return "Nikon.ColorHue";
case 0x008f: return "Nikon.SceneMode";
case 0x0090: return "Nikon.LightSource";
case 0x0091: return "Nikon.ShotInfo";
case 0x0092: return "Nikon.HueAdjustment";
case 0x0093: return "Nikon.NEFCompression";
case 0x0094: return "Nikon.Saturation";
case 0x0095: return "Nikon.NoiseReduction";
case 0x0096: return "Nikon.LinearizationTable";
case 0x0097: return "Nikon.ColorBalance";
case 0x0098: return "Nikon.LensData";
case 0x0099: return "Nikon.RawImageCenter";
case 0x009a: return "Nikon.SensorPixelSize";
case 0x009b: return "Nikon.0x009b";
case 0x009c: return "Nikon.SceneAssist";
case 0x009e: return "Nikon.RetouchHistory";
case 0x009f: return "Nikon.0x009f";
case 0x00a0: return "Nikon.SerialNO";
case 0x00a2: return "Nikon.ImageDataSize";
case 0x00a3: return "Nikon.0x00a3";
case 0x00a5: return "Nikon.ImageCount";
case 0x00a6: return "Nikon.DeletedImageCount";
case 0x00a7: return "Nikon.ShutterCount";
case 0x00a8: return "Nikon.FlashInfo";
case 0x00a9: return "Nikon.ImageOptimization";
case 0x00aa: return "Nikon.Saturation";
case 0x00ab: return "Nikon.VariProgram";
case 0x00ac: return "Nikon.ImageStabilization";
case 0x00ad: return "Nikon.AFResponse";
case 0x00b0: return "Nikon.MultiExposure";
case 0x00b1: return "Nikon.HighISONoiseReduction";
case 0x00b3: return "Nikon.ToningEffect";
case 0x00b7: return "Nikon.AFInfo2";
case 0x00b8: return "Nikon.FileInfo";
case 0x00b9: return "Nikon.AFTune";
case 0x00c3: return "Nikon.BarometerInfo";
case 0x0e00: return "Nikon.PrintIM";
case 0x0e01: return "Nikon.CaptureData";
case 0x0e09: return "Nikon.CaptureVersion";
case 0x0e0e: return "Nikon.CaptureOffsets";
case 0x0e10: return "Nikon.ScanIFD";
case 0x0e1d: return "Nikon.ICCProfile";
case 0x0e1e: return "Nikon.CaptureOutput";
};
return "unknown";
}
public static string TagNameForGPS(int number)
{
switch (number)
{
/* GPS */
case 0x0000: return "GPSVersionID";
case 0x0001: return "GPSLatitudeRef";
case 0x0002: return "GPSLatitude";
case 0x0003: return "GPSLongitudeRef";
case 0x0004: return "GPSLongitude";
case 0x0005: return "GPSAltitudeRef";
case 0x0006: return "GPSAltitude";
case 0x0007: return "GPSTimeStamp";
case 0x0008: return "GPSSatellites";
case 0x0009: return "GPSStatus";
case 0x000A: return "GPSMeasureMode";
case 0x000B: return "GPSDOP";
case 0x000C: return "GPSSpeedRef";
case 0x000D: return "GPSSpeed";
case 0x000E: return "GPSTrackRef";
case 0x000F: return "GPSTrack";
case 0x0010: return "GPSImgDirectionRef";
case 0x0011: return "GPSImgDirection";
case 0x0012: return "GPSMapDatum";
case 0x0013: return "GPSDestLatitudeRef";
case 0x0014: return "GPSDestLatitude";
case 0x0015: return "GPSDestLongitudeRef";
case 0x0016: return "GPSDestLongitude";
case 0x0017: return "GPSDestBearingRef";
case 0x0018: return "GPSDestBearing";
case 0x0019: return "GPSDestDistanceRef";
case 0x001A: return "GPSDestDistance";
case 0x001B: return "GPSProcessingMethod";
case 0x001C: return "GPSAreaInformation";
case 0x001D: return "GPSDateStamp";
case 0x001E: return "GPSDifferential";
};
return "unknown";
}
public static ushort TagNumberByName(string name)
{
string ntl = name.ToLower();
for(int i=1;i<=0xFFFF;i++)
if(ntl == TagNameByNumber(i).ToLower())
return (ushort)i;
return 0;
}
public static string TagNameByNumber(int number)
{
switch (number)
{
case 0x0001: return "InteropIndex";
case 0x0002: return "InteropVersion";
case 0x000b: return "ProcessingSoftware";
case 0x00FE: return "SubfileType";
case 0x00FF: return "OldSubfileType";
case 0x0100: return "ImageWidth";
case 0x0101: return "ImageHeight";
case 0x0102: return "BitsPerSample";
case 0x0103: return "Compression";
case 0x0106: return "PhotometricInterpretation";
case 0x0107: return "Thresholding";
case 0x0108: return "CellWidth";
case 0x0109: return "CellLength";
case 0x010A: return "FillOrder";
case 0x010D: return "DocumentName";
case 0x010E: return "ImageDescription";
case 0x010F: return "Make";
case 0x0110: return "Model";
case 0x0111: return "StripOffsets";
case 0x0112: return "Orientation";
case 0x0115: return "SamplesPerPixel";
case 0x0116: return "RowsPerStrip";
case 0x0117: return "StripByteCounts";
case 0x0118: return "MinSampleValue";
case 0x0119: return "MaxSampleValue";
case 0x011A: return "XResolution";
case 0x011B: return "YResolution";
case 0x011C: return "PlanarConfiguration";
case 0x011D: return "PageName";
case 0x011E: return "XPosition";
case 0x011F: return "YPosition";
case 0x0120: return "FreeOffsets";
case 0x0121: return "FreeByteCounts";
case 0x0122: return "GrayResponseUnit";
case 0x0123: return "GrayResponseCurve";
case 0x0124: return "T4Options";
case 0x0125: return "T6Options";
case 0x0128: return "ResolutionUnit";
case 0x0129: return "PageNumber";
case 0x012C: return "ColorResponseUnit";
case 0x012D: return "TransferFunction";
case 0x0131: return "Software";
case 0x0132: return "DateTime";
case 0x013B: return "Artist";
case 0x013C: return "HostComputer";
case 0x013D: return "Predictor";
case 0x013E: return "WhitePoint";
case 0x013F: return "PrimaryChromaticities";
case 0x0140: return "ColorMap";
case 0x0141: return "HalftoneHints";
case 0x0142: return "TileWidth";
case 0x0143: return "TileLength";
case 0x0144: return "TileOffsets";
case 0x0145: return "TileByteCounts";
case 0x0146: return "BadFaxLines";
case 0x0147: return "CleanFaxData";
case 0x0148: return "ConsecutiveBadFaxLines";
case 0x014A: return "SubIFD_A100DataOffset";
case 0x014C: return "InkSet";
case 0x014D: return "InkNames";
case 0x014E: return "NumberofInks";
case 0x0150: return "DotRange";
case 0x0151: return "TargetPrinter";
case 0x0152: return "ExtraSamples";
case 0x0153: return "SampleFormat";
case 0x0154: return "SMinSampleValue";
case 0x0155: return "SMaxSampleValue";
case 0x0156: return "TransferRange";
case 0x0157: return "ClipPath";
case 0x0158: return "XClipPathUnits";
case 0x0159: return "YClipPathUnits";
case 0x015A: return "Indexed";
case 0x015B: return "JPEGTables";
case 0x015F: return "OPIProxy";
case 0x0190: return "GlobalParametersIFD";
case 0x0191: return "ProfileType";
case 0x0192: return "FaxProfile";
case 0x0193: return "CodingMethods";
case 0x0194: return "VersionYear";
case 0x0195: return "ModeNumber";
case 0x01B1: return "Decode";
case 0x01B2: return "DefaultImageColor";
case 0x01B3: return "T82Options";
case 0x01B5: return "JPEGTables";
case 0x0200: return "JPEGProc";
case 0x0201: return "JPEGInterchangeFormat";
case 0x0202: return "JPEGInterchangeFormatLength";
case 0x0203: return "JPEGRestartInterval";
case 0x0205: return "JPEGLosslessPredictors";
case 0x0206: return "JPEGPointTransforms";
case 0x0207: return "JPEGQTables";
case 0x0208: return "JPEGDCTables";
case 0x0209: return "JPEGACTables";
case 0x0211: return "YCbCrCoefficients";
case 0x0212: return "YCbCrSubSampling";
case 0x0213: return "YCbCrPositioning";
case 0x0214: return "ReferenceBlackWhite";
case 0x022F: return "StripRowCounts";
case 0x02BC: return "ApplicationNotes";
case 0x03E7: return "USPTOMiscellaneous";
case 0x1000: return "RelatedImageFileFormat";
case 0x1001: return "RelatedImageWidth";
case 0x1002: return "RelatedImageHeight";
case 0x4746: return "Rating";
case 0x4747: return "XP_DIP_XML";
case 0x4748: return "StitchInfo";
case 0x4749: return "RatingPercent";
case 0x7000: return "SonyRawFileType";
case 0x7010: return "SonyToneCurve";
case 0x7031: return "VignettingCorrection";
case 0x7032: return "VignettingCorrParams";
case 0x7034: return "ChromaticAberrationCorrection";
case 0x7035: return "ChromaticAberrationCorrParams";
case 0x7036: return "DistortionCorrection";
case 0x7037: return "DistortionCorrParams";
case 0x74C7: return "SonyCropTopLeft";
case 0x74C8: return "SonyCropSize";
case 0x800D: return "ImageID";
case 0x80A3: return "WangTag1";
case 0x80A4: return "WangAnnotation";
case 0x80A5: return "WangTag3";
case 0x80A6: return "WangTag4"; //
case 0x80b9: return "ImageReferencePoints";
case 0x80ba: return "RegionXformTackPoint";
case 0x80bb: return "WarpQuadrilateral";
case 0x80bc: return "AffineTransformMat";
case 0x80e3: return "Matteing";
case 0x80e4: return "DataType";
case 0x80e5: return "ImageDepth";
case 0x80e6: return "TileDepth";
case 0x8214: return "ImageFullWidth";
case 0x8215: return "ImageFullHeight";
case 0x8216: return "TextureFormat";
case 0x8217: return "WrapModes";
case 0x8218: return "FovCot";
case 0x8219: return "MatrixWorldToScreen";
case 0x821a: return "MatrixWorldToCamera";
case 0x827d: return "Model2";
case 0x828d: return "CFARepeatPatternDim";
case 0x828e: return "CFAPattern2";
case 0x828f: return "BatteryLevel";
case 0x8290: return "KodakIFD";
case 0x8298: return "Copyright";
case 0x829A: return "ExposureTime";
case 0x829D: return "FNumber";
case 0x82a5: return "MDFileTag";
case 0x82a6: return "MDScalePixel";
case 0x82a7: return "MDColorTable";
case 0x82a8: return "MDLabName";
case 0x82a9: return "MDSampleInfo";
case 0x82aa: return "MDPrepDate";
case 0x82ab: return "MDPrepTime";
case 0x82ac: return "MDFileUnits";
case 0x830e: return "PixelScale";
case 0x8335: return "AdventScale";
case 0x8336: return "AdventRevision";
case 0x835c: return "UIC1Tag";
case 0x835d: return "UIC2Tag";
case 0x835e: return "UIC3Tag";
case 0x835f: return "UIC4Tag";
case 0x83bb: return "IPTC-NAA";
case 0x847e: return "IntergraphPacketData";
case 0x847f: return "IntergraphFlagRegisters";
case 0x8480: return "IntergraphMatrix";
case 0x8481: return "INGRReserved";
case 0x8482: return "ModelTiePoint";
case 0x84e0: return "Site";
case 0x84e1: return "ColorSequence";
case 0x84e2: return "IT8Header";