using Titano.Core.Metadata;
using Titano.Core.Model;
namespace Titano.Core.Analysis;
/// The metadata the light analysis needs from one frame (BRIEF §10.1).
public sealed record LightFrame
{
public int Index { get; init; }
/// Camera wall-clock capture time (unspecified kind).
public DateTime? CapturedAt { get; init; }
/// UTC offset of in minutes, when recorded.
public int? UtcOffsetMinutes { get; init; }
public double? ExposureTime { get; init; }
public double? FNumber { get; init; }
public int? Iso { get; init; }
public double? ExposureBias { get; init; }
public int Width { get; init; }
public int Height { get; init; }
public int Orientation { get; init; } = 1;
public string? CameraMake { get; init; }
public string? CameraModel { get; init; }
public string? CameraSerial { get; init; }
public string? Lens { get; init; }
public double? Latitude { get; init; }
public double? Longitude { get; init; }
/// GPS (satellite) UTC time stamp, used to infer the camera clock's UTC offset.
public DateTime? GpsUtc { get; init; }
/// Exposure value at ISO 100: log2(N²/t) − log2(ISO/100).
public double? ExposureValue => ExposureTime is > 0 && FNumber is > 0
? Math.Log2(FNumber.Value * FNumber.Value / ExposureTime.Value) - Math.Log2((Iso is > 0 ? Iso.Value : 100) / 100.0)
: null;
/// Width and height after Exif orientations 5–8 (90° rotations).
public (int Width, int Height) OrientedSize => Orientation is >= 5 and <= 8 ? (Height, Width) : (Width, Height);
public static LightFrame From(Frame frame)
{
ArgumentNullException.ThrowIfNull(frame);
return new LightFrame
{
Index = frame.Index,
CapturedAt = frame.CapturedAt,
UtcOffsetMinutes = frame.UtcOffsetMinutes,
ExposureTime = frame.ExposureTime,
FNumber = frame.FNumber,
Iso = frame.Iso,
ExposureBias = frame.ExposureBias,
Width = frame.Width,
Height = frame.Height,
Orientation = frame.Orientation,
};
}
public static LightFrame From(FrameMetadata metadata, int index)
{
ArgumentNullException.ThrowIfNull(metadata);
return new LightFrame
{
Index = index,
CapturedAt = metadata.CapturedAt,
UtcOffsetMinutes = metadata.UtcOffsetMinutes,
ExposureTime = metadata.ExposureTime,
FNumber = metadata.FNumber,
Iso = metadata.Iso,
ExposureBias = metadata.ExposureBias,
Width = metadata.Width,
Height = metadata.Height,
Orientation = metadata.Orientation,
CameraMake = metadata.Make,
CameraModel = metadata.Model,
CameraSerial = metadata.BodySerial,
Lens = metadata.LensModel,
Latitude = metadata.Gps?.Latitude,
Longitude = metadata.Gps?.Longitude,
GpsUtc = metadata.Gps?.UtcTimestamp,
};
}
}