BRIEF §9 lists exposure mode, intervalometer hints and sRaw flags among the MakerNote fields; no vendor parser read them. The vendor exposure mode (Canon, Olympus, Fujifilm, Panasonic, Sony) now fills ExposureProgram when Exif has none, Panasonic's TimerRecording becomes FrameMetadata.IntervalShooting, and Canon's SRAWQuality and Nikon's ImageSizeRAW / small NEF compression become FrameMetadata.RawSize. Nikon keeps its interval-shooting state in the encrypted ShotInfo, which stays undecoded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
78 lines
3.3 KiB
C#
78 lines
3.3 KiB
C#
using Titano.Core.Metadata.Jpeg;
|
|
using Titano.Core.Metadata.Tiff;
|
|
|
|
namespace Titano.Core.Metadata.MakerNotes;
|
|
|
|
/// <summary>
|
|
/// Olympus / OM System MakerNote. "OLYMPUS\0II\3\0" (IFD at +12) and "OM SYSTEM\0\0\0II\4\0" (IFD at +16) use offsets
|
|
/// relative to the MakerNote start and their own byte order; legacy "OLYMP\0" has its IFD at +8 relative to the
|
|
/// Exif TIFF. Equipment (0x2010) gives serial and lens; CameraSettings (0x2020) gives the ORF preview, the stabiliser
|
|
/// and the exposure mode.
|
|
/// </summary>
|
|
internal static class OlympusMakerNote
|
|
{
|
|
private const ushort Equipment = 0x2010;
|
|
private const ushort CameraSettings = 0x2020;
|
|
private const ushort EquipmentSerialNumber = 0x0101;
|
|
private const ushort EquipmentLensModel = 0x0203;
|
|
private const ushort PreviewImageValid = 0x0100;
|
|
private const ushort PreviewImageStart = 0x0101;
|
|
private const ushort PreviewImageLength = 0x0102;
|
|
private const ushort ExposureMode = 0x0200;
|
|
private const ushort ImageStabilization = 0x0604;
|
|
|
|
public static void Parse(TiffReader exif, long start, ReadOnlySpan<byte> header, MetadataBuilder m)
|
|
{
|
|
if (header.StartsWith("OLYMP\0"u8))
|
|
{
|
|
MakerNoteParser.Vendor(exif, (uint)(start - exif.Base + 8), m, ParseIfd);
|
|
return;
|
|
}
|
|
var orderAt = header.StartsWith("OM SYSTEM\0"u8) ? 12 : 8;
|
|
if (header.Length < orderAt + 4 || header[orderAt] != header[orderAt + 1] || header[orderAt] is not ((byte)'I' or (byte)'M'))
|
|
{
|
|
m.Warn("Olympus MakerNote header malformed");
|
|
return;
|
|
}
|
|
var reader = TiffReader.ForEmbedded(m.Stream, start, header[orderAt] == 'I');
|
|
MakerNoteParser.Vendor(reader, (uint)(orderAt + 4), m, ParseIfd);
|
|
m.AddWarnings(reader.Warnings);
|
|
}
|
|
|
|
private static void ParseIfd(TiffReader r, Ifd ifd, MetadataBuilder m)
|
|
{
|
|
var v = m.MakerNote;
|
|
if (SubIfd(r, ifd, Equipment) is { } equipment)
|
|
{
|
|
v.BodySerial ??= IfdValue.String(r, equipment, EquipmentSerialNumber);
|
|
v.LensModel ??= IfdValue.String(r, equipment, EquipmentLensModel);
|
|
}
|
|
if (SubIfd(r, ifd, CameraSettings) is not { } settings) return;
|
|
v.ImageStabilization ??= IfdValue.UInt(r, settings, ImageStabilization) switch
|
|
{
|
|
0 => false,
|
|
>= 1 and <= 4 => true,
|
|
_ => null,
|
|
};
|
|
// 1 Manual, 2 Program, 3 Aperture priority, 4 Shutter priority, 5 Program shift.
|
|
v.ExposureProgram ??= IfdValue.UInt(r, settings, ExposureMode) switch
|
|
{
|
|
1 => 1,
|
|
2 or 5 => 2,
|
|
3 => 3,
|
|
4 => 4,
|
|
_ => null,
|
|
};
|
|
if (IfdValue.UInt(r, settings, PreviewImageValid) != 0
|
|
&& IfdValue.UInt(r, settings, PreviewImageStart) is { } offset and > 0
|
|
&& IfdValue.UInt(r, settings, PreviewImageLength) is { } length and > 0)
|
|
{
|
|
JpegParser.AddPreview(m, r.Base + offset, length);
|
|
}
|
|
}
|
|
|
|
/// <summary>Sub-IFD stored either as an IFD/LONG pointer or as an UNDEFINED block; both resolve to the value offset.</summary>
|
|
private static Ifd? SubIfd(TiffReader r, Ifd ifd, ushort tag) =>
|
|
ifd.Entries.TryGetValue(tag, out var e) && !(e.IsInline && e.Type == TiffType.Undefined) ? r.ReadIfd(e.ValueOffset) : null;
|
|
}
|