using System.Globalization; using Titano.Core.Imaging; using Titano.Core.Metadata.Tiff; namespace Titano.Core.Metadata.MakerNotes; /// /// 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. /// 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, }; } } }