Repository Public License
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Camera9// File : Packages/ORIXCameraKit/Sources/ORIXImaging/Capture/Capabilities.swift10// Description : Device-independent description of what a camera can do.11// The app fills it from AVCaptureDevice at run time; every12// control in the interface is enabled from these values,13// never from assumptions about a model.14// Module : ORIXImaging15// Repository : https://git.spboucher.ai/orix-camera16// Project Website : https://www.orixlab.dev17// Created : 2026-11-2118// Last Modified : 2026-11-2119//20// =============================================================================21// AUTHOR & PROFESSIONAL AFFILIATION22// =============================================================================23//24// Author : Simon-Pierre Boucher25// Position : Professor of Finance26// Institution : Université du Québec en Outaouais (UQO)27// Department : Département des sciences administratives28// Organization : SP Boucher29//30// Website : https://spboucher.ai31// Git : https://git.spboucher.ai32//33// =============================================================================34// OFFICIAL CONTACT DIRECTORY35// =============================================================================36//37// General : info@spboucher.ai38// Professional : contact@spboucher.ai39// Direct : simon@spboucher.ai40// Research : research@spboucher.ai41// Development : dev@spboucher.ai42// Support : support@spboucher.ai43// Security/Admin : admin@spboucher.ai44// Notifications : notifications@spboucher.ai45//46// Preferred Contact: support@spboucher.ai47//48// =============================================================================49// COPYRIGHT & INTELLECTUAL PROPERTY50// =============================================================================51//52// Copyright (c) 202653// Simon-Pierre Boucher54//55// All rights reserved where applicable.56//57// This file is governed by the applicable project license,58// copyright notices, institutional agreements and relevant law.59//60// Unless expressly authorized by the applicable license or61// rights holder, copying, redistribution, sublicensing,62// publication and commercial exploitation are not permitted.63//64// Existing third-party rights and notices remain unaffected.65//66// =============================================================================67// CONFIDENTIALITY & SECURITY68// =============================================================================69//70// Classification : Public71// Distribution : Public repository; use is governed by the project license72// Security Contact : admin@spboucher.ai73//74// Access to this source does not independently grant permission75// to redistribute or disclose confidential materials.76//77// Do not embed credentials, private keys, access tokens,78// certificates or confidential personal information.79//80// =============================================================================81// LICENSE & MAINTENANCE82// =============================================================================83//84// License : Proprietary, all rights reserved (see license file)85// License File : LICENSE86// Maintainer : Simon-Pierre Boucher87// Technical Contact: dev@spboucher.ai88//89// =============================================================================90// END OF SP BOUCHER SOURCE HEADER91// =============================================================================9293import Foundation9495public enum LensPosition: String, Sendable, Codable { case back, front }9697public struct LensDescriptor: Sendable, Equatable, Identifiable, Codable {98 /// AVCaptureDevice.uniqueID (or a synthetic id in the simulator).99 public var id: String100 public var position: LensPosition101 /// "ultraWide", "wide", "telephoto", "front", "frontUltraWide".102 public var kind: String103 /// Short label for the lens selector, derived from the field of view relative to the wide camera: "0.5×", "1×", "5×".104 public var label: String105 public var fieldOfView: Double106 /// 35 mm-equivalent focal length computed from the field of view (an estimate, not EXIF).107 public var focalLength35mm: Double108 public var aperture: Double109 public init(id: String, position: LensPosition, kind: String, label: String, fieldOfView: Double, focalLength35mm: Double, aperture: Double) {110 self.id = id; self.position = position; self.kind = kind; self.label = label111 self.fieldOfView = fieldOfView; self.focalLength35mm = focalLength35mm; self.aperture = aperture112 }113114 /// 35 mm-equivalent focal length for a horizontal field of view in degrees (36 mm frame width).115 public static func focalLength35(fieldOfView degrees: Double) -> Double {116 guard degrees > 1, degrees < 179 else { return 0 }117 return 18 / tan(degrees * .pi / 360)118 }119}120121public struct VideoFormatOption: Sendable, Equatable, Identifiable, Codable, Hashable {122 public var width: Int123 public var height: Int124 public var frameRate: Double125 public var id: String { "\(width)x\(height)@\(Int(frameRate))" }126 public init(width: Int, height: Int, frameRate: Double) { self.width = width; self.height = height; self.frameRate = frameRate }127128 public var resolutionLabel: String {129 switch (width, height) {130 case (3840, 2160): "4K"131 case (1920, 1080): "1080p"132 case (1280, 720): "720p"133 default: "\(width)×\(height)"134 }135 }136 public var isSlowMotion: Bool { frameRate > 60 }137}138139public struct CameraCapabilities: Sendable, Equatable, Codable {140 public var lens: LensDescriptor141 public var minISO: Double142 public var maxISO: Double143 /// Seconds.144 public var minExposureDuration: Double145 public var maxExposureDuration: Double146 public var minExposureBias: Double147 public var maxExposureBias: Double148 public var supportsManualExposure: Bool149 public var supportsManualFocus: Bool150 public var supportsFocusPointOfInterest: Bool151 public var supportsExposurePointOfInterest: Bool152 public var supportsWhiteBalanceLock: Bool153 public var maxWhiteBalanceGain: Double154 public var hasFlash: Bool155 public var hasTorch: Bool156 public var minZoom: Double157 public var maxZoom: Double158 public var supportsBayerRAW: Bool159 public var supportsProRAW: Bool160 public var maxBracketCount: Int161 public var supportsHEVCPhoto: Bool162 /// Largest still size (pixels) the photo output offers in the current configuration.163 public var maxPhotoWidth: Int164 public var maxPhotoHeight: Int165 public var videoFormats: [VideoFormatOption]166 public var videoCodecs: [VideoCodec]167 public var supportsVideoStabilization: Bool168 /// Reported for information only: 10-bit HDR and Apple Log recording are not implemented in this version.169 public var deviceOffersHDRVideo: Bool170 public var deviceOffersAppleLog: Bool171 /// True in the simulator: frames come from the synthetic scene and no optical hardware exists.172 public var isSynthetic: Bool173174 public init(lens: LensDescriptor) {175 self.lens = lens176 minISO = 0; maxISO = 0; minExposureDuration = 0; maxExposureDuration = 0; minExposureBias = 0; maxExposureBias = 0177 supportsManualExposure = false; supportsManualFocus = false; supportsFocusPointOfInterest = false178 supportsExposurePointOfInterest = false; supportsWhiteBalanceLock = false; maxWhiteBalanceGain = 1179 hasFlash = false; hasTorch = false; minZoom = 1; maxZoom = 1; supportsBayerRAW = false; supportsProRAW = false180 maxBracketCount = 0; supportsHEVCPhoto = false; maxPhotoWidth = 0; maxPhotoHeight = 0; videoFormats = []181 videoCodecs = []; supportsVideoStabilization = false; deviceOffersHDRVideo = false; deviceOffersAppleLog = false182 isSynthetic = false183 }184185 public func frameRates(width: Int, height: Int) -> [Double] {186 videoFormats.filter { $0.width == width && $0.height == height }.map(\.frameRate).sorted()187 }188189 public var resolutions: [VideoFormatOption] {190 var seen = Set<String>(), out: [VideoFormatOption] = []191 for format in videoFormats.sorted(by: { $0.width * $0.height > $1.width * $1.height }) {192 let key = "\(format.width)x\(format.height)"193 if seen.insert(key).inserted { out.append(format) }194 }195 return out196 }197198 /// Why a capability is unavailable, for the interface ("every unavailable capability must be explained").199 public func explanation(for feature: Feature) -> String? {200 switch feature {201 case .bayerRAW: supportsBayerRAW ? nil : (isSynthetic ? "RAW needs a real sensor; the simulator has none." : "This camera does not offer Bayer RAW in the current configuration.")202 case .proRAW: supportsProRAW ? nil : (isSynthetic ? "Apple ProRAW needs a supported iPhone." : "Apple ProRAW is not offered by this iPhone or this lens.")203 case .manualFocus: supportsManualFocus ? nil : "This lens has a fixed focus."204 case .manualExposure: supportsManualExposure ? nil : "This camera does not accept manual exposure."205 case .flash: hasFlash ? nil : "This camera has no flash."206 case .proRes: videoCodecs.contains(.proRes422) ? nil : "Apple ProRes encoding is not available on this device."207 case .bracketing: maxBracketCount >= 2 ? nil : "Exposure bracketing is not offered by this camera."208 case .whiteBalanceLock: supportsWhiteBalanceLock ? nil : "This camera does not accept locked white-balance gains."209 }210 }211212 public enum Feature: String, Sendable, CaseIterable { case bayerRAW, proRAW, manualFocus, manualExposure, flash, proRes, bracketing, whiteBalanceLock }213}214