Files
Chronos/src/Titano.Core/Metadata/MakerNotes/CanonMakerNote.cs
T
Claude 61e61702c6 fix(metadata): read exposure mode, interval shooting and RAW size from MakerNotes
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
2026-10-12 09:58:21 +00:00

71 lines
2.8 KiB
C#

using System.Globalization;
using Titano.Core.Imaging;
using Titano.Core.Metadata.Tiff;
namespace Titano.Core.Metadata.MakerNotes;
/// <summary>
/// Canon MakerNote: a bare IFD whose offsets are relative to the enclosing TIFF header (also CR3 CMT3). CameraSettings
/// gives the stabiliser, the exposure mode and the sRAW size; Canon records no interval-shooting hint there.
/// </summary>
internal static class CanonMakerNote
{
private const ushort CameraSettings = 0x0001;
private const ushort SerialNumber = 0x000C;
private const ushort LensModel = 0x0095;
private const ushort InternalSerialNumber = 0x0096;
private const ushort ColorTemperature = 0x00AE;
private const int ExposureModeIndex = 20;
private const int ImageStabilizationIndex = 34;
private const int SRawQualityIndex = 46;
public static void Parse(TiffReader r, Ifd ifd, MetadataBuilder m)
{
var v = m.MakerNote;
if (IfdValue.UInt(r, ifd, SerialNumber) is { } serial and > 0)
{
// Canon prints 6 digits on EOS-1D bodies and 10 elsewhere.
var digits = m.Model?.Contains("EOS-1D", StringComparison.OrdinalIgnoreCase) == true ? "D6" : "D10";
v.BodySerial ??= serial.ToString(digits, CultureInfo.InvariantCulture);
}
v.BodySerial ??= IfdValue.String(r, ifd, InternalSerialNumber);
v.LensModel ??= IfdValue.String(r, ifd, LensModel);
v.ColorTemperature ??= IfdValue.Int(r, ifd, ColorTemperature) is { } kelvin and > 0 and < 65535 ? kelvin : null;
if (IfdValue.UInts(r, ifd, CameraSettings) is not { } settings) return;
if (settings.Length > ExposureModeIndex)
{
// CanonExposureMode: 1 Program, 2 Tv, 3 Av, 4 Manual, 5 Depth-of-field AE, 6 M-Dep, 7 Bulb, 8 Fv; 0 Easy (scene).
v.ExposureProgram ??= settings[ExposureModeIndex] switch
{
1 or 8 => 2,
2 => 4,
3 => 3,
4 or 7 => 1,
5 or 6 => 5,
_ => null,
};
}
if (settings.Length > ImageStabilizationIndex)
{
// 0 Off, 1 On, 2 Shoot only, 3 Panning, 4 Dynamic; +256 for the "(2)" variants.
v.ImageStabilization ??= (settings[ImageStabilizationIndex] & 0xFF) switch
{
0 => false,
>= 1 and <= 4 => true,
_ => null,
};
}
if (settings.Length > SRawQualityIndex && m.Format is ImageFileFormat.Cr2 or ImageFileFormat.Cr3)
{
// SRAWQuality: 0 full-size RAW, 1 sRAW1 (mRAW), 2 sRAW2 (sRAW).
v.RawSize ??= settings[SRawQualityIndex] switch
{
0 => RawSize.Full,
1 => RawSize.Medium,
2 => RawSize.Small,
_ => null,
};
}
}
}