SPB Git

Repository Public License

CameraSettings.swift 11.3 KB 254 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : ORIX Camera9// File             : App/Sources/Features/Camera/CameraSettings.swift10// Description      : User settings of the camera (persisted as JSON in11//                    UserDefaults) and the mode vocabulary.12// Module           : Features13// Repository       : https://git.spboucher.ai/orix-camera14// Project Website  : https://www.orixlab.dev15// Created          : 2026-11-2116// Last Modified    : 2026-11-2117//18// =============================================================================19// AUTHOR & PROFESSIONAL AFFILIATION20// =============================================================================21//22// Author           : Simon-Pierre Boucher23// Position         : Professor of Finance24// Institution      : Université du Québec en Outaouais (UQO)25// Department       : Département des sciences administratives26// Organization     : SP Boucher27//28// Website          : https://spboucher.ai29// Git              : https://git.spboucher.ai30//31// =============================================================================32// OFFICIAL CONTACT DIRECTORY33// =============================================================================34//35// General          : info@spboucher.ai36// Professional     : contact@spboucher.ai37// Direct           : simon@spboucher.ai38// Research         : research@spboucher.ai39// Development      : dev@spboucher.ai40// Support          : support@spboucher.ai41// Security/Admin   : admin@spboucher.ai42// Notifications    : notifications@spboucher.ai43//44// Preferred Contact: support@spboucher.ai45//46// =============================================================================47// COPYRIGHT & INTELLECTUAL PROPERTY48// =============================================================================49//50// Copyright (c) 202651// Simon-Pierre Boucher52//53// All rights reserved where applicable.54//55// This file is governed by the applicable project license,56// copyright notices, institutional agreements and relevant law.57//58// Unless expressly authorized by the applicable license or59// rights holder, copying, redistribution, sublicensing,60// publication and commercial exploitation are not permitted.61//62// Existing third-party rights and notices remain unaffected.63//64// =============================================================================65// CONFIDENTIALITY & SECURITY66// =============================================================================67//68// Classification   : Public69// Distribution     : Public repository; use is governed by the project license70// Security Contact : admin@spboucher.ai71//72// Access to this source does not independently grant permission73// to redistribute or disclose confidential materials.74//75// Do not embed credentials, private keys, access tokens,76// certificates or confidential personal information.77//78// =============================================================================79// LICENSE & MAINTENANCE80// =============================================================================81//82// License          : Proprietary, all rights reserved (see license file)83// License File     : LICENSE84// Maintainer       : Simon-Pierre Boucher85// Technical Contact: dev@spboucher.ai86//87// =============================================================================88// END OF SP BOUCHER SOURCE HEADER89// =============================================================================9091import Foundation92import ORIXImaging9394nonisolated enum CameraMode: String, CaseIterable, Codable, Sendable, Identifiable {95    case auto, photo, video, creative, analysis96    var id: String { rawValue }97    var title: LocalizedStringResource {98        switch self {99        case .auto: "Auto"100        case .photo: "Pro Photo"101        case .video: "Pro Video"102        case .creative: "Creative"103        case .analysis: "Analysis"104        }105    }106    var shortTitle: LocalizedStringResource {107        switch self {108        case .auto: "AUTO"109        case .photo: "PHOTO"110        case .video: "VIDEO"111        case .creative: "CREATIVE"112        case .analysis: "ANALYSIS"113        }114    }115}116117nonisolated enum CreativeTool: String, CaseIterable, Codable, Sendable, Identifiable {118    case longExposure, lightTrails, noiseStack, hdrFusion, timeLapse, intervalometer119    var id: String { rawValue }120    var title: LocalizedStringResource {121        switch self {122        case .longExposure: "Long Exposure"123        case .lightTrails: "Light Trails"124        case .noiseStack: "Night Stack"125        case .hdrFusion: "Bracket Fusion"126        case .timeLapse: "Time-lapse"127        case .intervalometer: "Intervalometer"128        }129    }130    var symbol: String {131        switch self {132        case .longExposure: "water.waves"133        case .lightTrails: "scribble.variable"134        case .noiseStack: "moon.stars"135        case .hdrFusion: "square.3.layers.3d"136        case .timeLapse: "timelapse"137        case .intervalometer: "timer"138        }139    }140    /// What the tool really does, shown under the tool name.141    var explanation: LocalizedStringResource {142        switch self {143        case .longExposure: "Averages video frames for the chosen time. A computed long exposure, not a long shutter. Use a tripod."144        case .lightTrails: "Keeps the brightest value each pixel reaches. Moving lights draw trails. Use a tripod."145        case .noiseStack: "Aligns and merges a burst of frames, rejecting what moved. Less noise in still scenes."146        case .hdrFusion: "Captures an exposure bracket and fuses it (Mertens). Keeps highlights and shadows."147        case .timeLapse: "Records one frame per interval and plays them at 30 fps."148        case .intervalometer: "Takes a photo at a fixed interval."149        }150    }151    var usesVideoPipeline: Bool { self == .timeLapse }152}153154nonisolated enum HistogramStyle: String, Codable, Sendable, CaseIterable { case luma, rgb }155156nonisolated enum ProDial: String, Sendable, CaseIterable, Identifiable {157    case iso, shutter, bias, focus, whiteBalance, tint, zoom158    var id: String { rawValue }159}160161nonisolated struct CameraSettings: Codable, Sendable, Equatable {162    var mode: CameraMode = .auto163    var creativeTool: CreativeTool = .longExposure164    // Photo165    var photoFormat: PhotoFormat = .heic166    var flash: FlashSetting = .off167    var timerSeconds = 0168    var highResolutionPhotos = true169    var mirrorFrontPhotos = false170    var captureLookID: String?171    var aspect: AspectGuide = .native172    // Video173    var videoWidth = 1920174    var videoHeight = 1080175    var videoFrameRate: Double = 30176    var videoCodec: VideoCodec = .hevc177    var stabilization = true178    var recordAudio = true179    var slowMotionPlayback = true180    var monitorLookID: String?181    // Creative182    var longExposureSeconds: Double = 4183    var noiseStackFrames = 8184    var bracketStops: Double = 2185    var timeLapseInterval: Double = 1186    var intervalSeconds: Double = 5187    var intervalCount = 10188    var deepComputationalFiles = false189    // Monitoring190    var grid: GridOverlay = .thirds191    var showLevel = true192    var showHistogram = true193    var histogramExpanded = false194    var histogramStyle: HistogramStyle = .luma195    var zebra = ZebraSettings(highlightsEnabled: false)196    var peaking = false197    var peakingSensitivity = 0.5198    var peakingColor: PeakingColor = .red199    var focusMagnifier = false200    var safeFraming = false201    var falseColor = false202    var clippingWarning = false203    // General204    var saveToPhotos = false205    var haptics = true206    var stripLocationOnExport = true207    var hasSeenWelcome = false208209    private static let key = "orix.camera.settings.v1"210211    static func load(from defaults: UserDefaults = .standard) -> CameraSettings {212        guard let data = defaults.data(forKey: key), let value = try? JSONDecoder().decode(CameraSettings.self, from: data) else { return CameraSettings() }213        return value214    }215216    func save(to defaults: UserDefaults = .standard) {217        if let data = try? JSONEncoder().encode(self) { defaults.set(data, forKey: CameraSettings.key) }218    }219220    static func reset(in defaults: UserDefaults = .standard) { defaults.removeObject(forKey: key) }221222    // Decoding tolerates settings saved by an older build: missing keys keep their defaults.223    init() {}224    init(from decoder: Decoder) throws {225        let c = try decoder.container(keyedBy: CodingKeys.self)226        func get<T: Decodable>(_ key: CodingKeys, _ fallback: T) -> T { (try? c.decodeIfPresent(T.self, forKey: key)) ?? fallback }227        let d = CameraSettings()228        mode = get(.mode, d.mode); creativeTool = get(.creativeTool, d.creativeTool); photoFormat = get(.photoFormat, d.photoFormat)229        flash = get(.flash, d.flash); timerSeconds = get(.timerSeconds, d.timerSeconds); highResolutionPhotos = get(.highResolutionPhotos, d.highResolutionPhotos)230        mirrorFrontPhotos = get(.mirrorFrontPhotos, d.mirrorFrontPhotos); captureLookID = get(.captureLookID, d.captureLookID); aspect = get(.aspect, d.aspect)231        videoWidth = get(.videoWidth, d.videoWidth); videoHeight = get(.videoHeight, d.videoHeight); videoFrameRate = get(.videoFrameRate, d.videoFrameRate)232        videoCodec = get(.videoCodec, d.videoCodec); stabilization = get(.stabilization, d.stabilization); recordAudio = get(.recordAudio, d.recordAudio)233        slowMotionPlayback = get(.slowMotionPlayback, d.slowMotionPlayback); monitorLookID = get(.monitorLookID, d.monitorLookID)234        longExposureSeconds = get(.longExposureSeconds, d.longExposureSeconds); noiseStackFrames = get(.noiseStackFrames, d.noiseStackFrames)235        bracketStops = get(.bracketStops, d.bracketStops); timeLapseInterval = get(.timeLapseInterval, d.timeLapseInterval)236        intervalSeconds = get(.intervalSeconds, d.intervalSeconds); intervalCount = get(.intervalCount, d.intervalCount)237        deepComputationalFiles = get(.deepComputationalFiles, d.deepComputationalFiles); grid = get(.grid, d.grid); showLevel = get(.showLevel, d.showLevel)238        showHistogram = get(.showHistogram, d.showHistogram); histogramExpanded = get(.histogramExpanded, d.histogramExpanded)239        histogramStyle = get(.histogramStyle, d.histogramStyle); zebra = get(.zebra, d.zebra); peaking = get(.peaking, d.peaking)240        peakingSensitivity = get(.peakingSensitivity, d.peakingSensitivity); peakingColor = get(.peakingColor, d.peakingColor)241        focusMagnifier = get(.focusMagnifier, d.focusMagnifier); safeFraming = get(.safeFraming, d.safeFraming); falseColor = get(.falseColor, d.falseColor)242        clippingWarning = get(.clippingWarning, d.clippingWarning); saveToPhotos = get(.saveToPhotos, d.saveToPhotos); haptics = get(.haptics, d.haptics)243        stripLocationOnExport = get(.stripLocationOnExport, d.stripLocationOnExport); hasSeenWelcome = get(.hasSeenWelcome, d.hasSeenWelcome)244    }245}246247extension CameraCapabilities {248    /// The imaging package explains unavailable features in English; the interface shows the localized text249    /// (the keys are listed in Scripts/manual-keys.json).250    nonisolated func localizedExplanation(for feature: Feature) -> String? {251        explanation(for: feature).map { String(localized: String.LocalizationValue($0)) }252    }253}254
Files main
Menu

Theme