using System;
using System.Collections;
using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
using System.Text;
-using ExifTag = ushort;
-
namespace JpegUtil;
+public enum ExifTag : ushort
+{
+ ImageWidth = 0x0100,
+ ImageHeight = 0x0101,
+ BitsPerSample = 0x0102,
+ Compression = 0x0103,
+ PhotometricInterpretation = 0x0106,
+ Thresholding = 0x0107,
+ ImageDescription = 0x010e,
+ Make = 0x010f,
+ Orientation = 0x0112,
+ XResolution = 0x011a,
+ YResolution = 0x011b,
+ PlanarConfiguration = 0x011c,
+ XPosition = 0x011e,
+ YPosition = 0x011f,
+ ResolutionUnit = 0x0128,
+ Software = 0x0131,
+ ModifyDate = 0x0132,
+ IFD = 0x8769, // special tag that is a pointer to more tags
+ ColorSpace = 0xa001,
+ ExifImageWidth = 0xa002,
+ ExifImageHeight = 0xa003,
+ FocalPlaneXResolution = 0xa20e,
+ FocalPlaneYResolution = 0xa20f,
+ FocalPlaneResolutionUnit = 0xa210,
+ // Renishaw WiRE Custom Tags
+ WiREPosition = 0xfea0,
+ WiREFoV = 0xfea1,
+ WiREObjective = 0xfea2,
+ WiRELUTLimits = 0xfea3,
+ WiRERotationAngle = 0xfea4,
+ WiRERotationCenter = 0xfea5,
+ WiREZPosition = 0xfea6,
+};
+
public enum ExifType
{
Byte = 1, // uint8_t
public ExifType Type { get; private set; }
public object Value { get; private set; }
- const ExifTag EXIF_IFD_TAG = 0x8769; // special tag that is a pointer to more tags
const ushort EXIF_IFD_SIZE = 12; // size in bytes of an IFD entry
const ushort EXIF_USHORT_SIZE = 2;
const ushort EXIF_BOM_BE = 0x4d4d;
public static IEnumerable<ExifItem> ExifParseItem(byte[] data, int off)
{
// uint item_count = 0;
- ushort tag = get_uint16(data, off);
+ ExifTag tag = (ExifTag)get_uint16(data, off);
ExifType type = (ExifType)get_uint16(data, off + 2);
int count = (int)get_uint32(data, off + 4);
int dataOffset = (int)get_uint32(data, off + 8);
{
if (count < 5)
dataOffset = hdrEnd;
- value = Encoding.ASCII.GetString(data, dataOffset, count);
+ value = Encoding.ASCII.GetString(data, dataOffset, count).TrimEnd('\0');
break;
}
case ExifType.Short:
}
case ExifType.Long:
{
- if (tag == EXIF_IFD_TAG)
+ if (ExifTag.IFD == tag)
{
ushort ifd_count = get_uint16(data, dataOffset);
dataOffset += 2;
public static string Print(this ExifItem item)
{
StringBuilder str = new(
- TagNames.ContainsKey(item.Tag) ? TagNames[item.Tag] : $"{item.Tag:X4}"
+ Enum.IsDefined(typeof(ExifTag), item.Tag) ? Enum.GetName(typeof(ExifTag), item.Tag) : $"{item.Tag:X4}"
);
int count = 1;
if (item.Value.IsGenericList())
}
return str.ToString();
}
-
- public static readonly Dictionary<ExifTag, string> TagNames = new()
- {
- { 0x0100, "ImageWidth" },
- { 0x0101, "ImageHeight" },
- { 0x0102, "BitsPerSample" },
- { 0x0103, "Compression" },
- { 0x0106, "PhotometricInterpretation" },
- { 0x0107, "Thresholding" },
- { 0x010e, "ImageDescription" },
- { 0x010f, "Make" },
- { 0x0112, "Orientation" },
- { 0x011a, "XResolution" },
- { 0x011b, "YResolution" },
- { 0x011c, "PlanarConfiguration" },
- { 0x011e, "XPosition" },
- { 0x011f, "YPosition" },
- { 0x0128, "ResolutionUnit" },
- { 0x0131, "Software" },
- { 0x0132, "ModifyDate" },
- { 0xa001, "ColorSpace" },
- { 0xa002, "ExifImageWidth" },
- { 0xa003, "ExifImageHeight" },
- { 0xa20e, "FocalPlaneXResolution" },
- { 0xa20f, "FocalPlaneYResolution" },
- { 0xa210, "FocalPlaneResolutionUnit" },
- /* Renishaw WiRE Custom Tags */
- { 0xfea0, "WiREPosition" },
- { 0xfea1, "WiREFoV" },
- { 0xfea2, "WiREObjective" },
- { 0xfea3, "WiRELUTLimits" },
- { 0xfea4, "WiRERotationAngle" },
- { 0xfea5, "WiRERotationCenter" },
- { 0xfea6, "WiREZPosition" }
- };
}