SPB Git

spb/focale Public

Swift 100%
1.3 KB · 43 lines swift
Raw Blame History
1//2//  SceneSignal.swift3//  Focale4//5//  Author: Simon-Pierre Boucher6//  Contact: contact@spboucher.ai7//8//  Cheap physical signals read off the capture device at shutter time.9//  No inference — these come straight from the sensor.10//1112import Foundation1314struct SceneSignal: Codable, Sendable {15    /// Estimated scene brightness in EV100 (log2 scale). Lower = darker.16    var luminanceEV: Double?17    /// Rough device/subject motion classification.18    var motion: MotionLevel19    /// Subject distance in meters when LiDAR/depth is available.20    var subjectDistance: Double?21    /// Convenience flag used by recipe scene triggers.22    var isLowLight: Bool2324    static let unknown = SceneSignal(25        luminanceEV: nil, motion: .unknown, subjectDistance: nil, isLowLight: false26    )27}2829enum MotionLevel: String, Codable, Sendable {30    case still31    case moving32    case unknown33}3435extension SceneSignal {36    /// EV100 from the current exposure triplet: EV = log2(1 / (t * S/100)).37    /// Good enough to distinguish "sunlit" from "dim room" for scene triggers.38    static func estimateEV(iso: Float, shutterSeconds: Double) -> Double? {39        guard iso > 0, shutterSeconds > 0 else { return nil }40        return log2(1.0 / (shutterSeconds * Double(iso) / 100.0))41    }42}43