Repository Public License
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : ORIX Camera9// File : App/Sources/Features/Camera/ModeDecks.swift10// Description : Mode-specific control rows: Creative tools and their11// parameters, and the Analysis diagnostics panel.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 ORIXDesign92import ORIXImaging93import SwiftUI9495struct CreativeDeck: View {96 @Bindable var model: CameraModel9798 var body: some View {99 VStack(spacing: 6) {100 ScrollView(.horizontal, showsIndicators: false) {101 HStack(spacing: 6) {102 ForEach(CreativeTool.allCases) { tool in103 Button { model.setCreativeTool(tool) } label: {104 Label { Text(tool.title) } icon: { Image(systemName: tool.symbol) }105 .font(.system(.caption, design: .rounded, weight: .semibold))106 .foregroundStyle(tool == model.settings.creativeTool ? Color.black : Instrument.text)107 .padding(.horizontal, 12).frame(minHeight: 34)108 .background(tool == model.settings.creativeTool ? Instrument.manual : Instrument.panelRaised, in: Capsule())109 .frame(minHeight: 44)110 }111 .buttonStyle(.plain)112 .accessibilityIdentifier("creative.\(tool.rawValue)")113 .accessibilityAddTraits(tool == model.settings.creativeTool ? .isSelected : [])114 }115 }116 .padding(.horizontal, 12)117 }118 Text(model.settings.creativeTool.explanation)119 .font(.caption2).foregroundStyle(Instrument.textDim)120 .frame(maxWidth: .infinity, alignment: .leading).padding(.horizontal, 14)121 .fixedSize(horizontal: false, vertical: true)122 parameters.padding(.horizontal, 12)123 }124 .disabled(model.isBusy || model.isRecording)125 }126127 private func option<T: Hashable>(_ title: LocalizedStringKey, _ values: [T], _ selection: Binding<T>, _ label: @escaping (T) -> String) -> some View {128 HStack(spacing: 6) {129 Text(title).font(Instrument.label).foregroundStyle(Instrument.textFaint)130 ScrollView(.horizontal, showsIndicators: false) {131 HStack(spacing: 4) {132 ForEach(values, id: \.self) { value in133 PillButton(title: LocalizedStringKey(label(value)), isOn: selection.wrappedValue == value, tint: Instrument.accent) {134 selection.wrappedValue = value; model.haptic()135 }136 }137 }138 }139 }140 }141142 @ViewBuilder private var parameters: some View {143 switch model.settings.creativeTool {144 case .longExposure, .lightTrails:145 option("TIME", [1.0, 2, 4, 8, 15, 30], $model.settings.longExposureSeconds) { "\(Int($0)) s" }146 case .noiseStack:147 option("FRAMES", [4, 8, 16], $model.settings.noiseStackFrames) { "\($0)" }148 case .hdrFusion:149 option("BRACKET", [1.0, 2, 3], $model.settings.bracketStops) { "±\(Int($0)) EV" }150 case .timeLapse:151 option("INTERVAL", [0.5, 1, 2, 5, 10], $model.settings.timeLapseInterval) { $0 < 1 ? "0.5 s" : "\(Int($0)) s" }152 case .intervalometer:153 VStack(spacing: 2) {154 option("EVERY", [2.0, 5, 10, 30, 60], $model.settings.intervalSeconds) { "\(Int($0)) s" }155 option("SHOTS", [5, 10, 25, 50, 100], $model.settings.intervalCount) { "\($0)" }156 }157 }158 }159}160161/// Analysis mode: every number is labelled by where it comes from.162struct AnalysisPanel: View {163 @Bindable var model: CameraModel164165 private enum Source { case measured, camera, estimate }166167 var body: some View {168 let s = model.snapshot, live = model.live, h = s.histogram169 let cast = ColorCast(histogram: h)170 ScrollView {171 VStack(alignment: .leading, spacing: 10) {172 HStack(spacing: 6) {173 toggle("False colour", $model.settings.falseColor, id: "analysis.falseColor")174 toggle("Clipping", $model.settings.clippingWarning, id: "analysis.clipping")175 }176 if model.settings.falseColor { falseColorLegend }177 section("Exposure") {178 row("Mean luma", percent(h.mean(.luma) / 255), .measured)179 row("Highlights clipped", percent(h.highlightClipping, digits: 2), .measured)180 row("Shadows clipped", percent(h.shadowClipping, digits: 2), .measured)181 row("1 % / 50 % / 99 % levels", "\(h.percentile(0.01)) / \(h.percentile(0.5)) / \(h.percentile(0.99))", .measured)182 row("Metered offset", String(format: "%+.2f EV", live.exposureOffset), .camera)183 }184 section("Focus and motion") {185 row("Detail score", String(format: "%.0f", s.focus.sharpness), .estimate)186 row("Peaking coverage", percent(s.focus.peakingCoverage, digits: 1), .measured)187 row("Frame-to-frame change", String(format: "%.1f / 255", s.motion), .measured)188 row("Lens position", String(format: "%.3f", live.lensPosition), .camera)189 row("Focus state", live.isAdjustingFocus ? String(localized: "adjusting") : (live.focusMode == .manual ? String(localized: "manual") : String(localized: "auto, settled")), .camera)190 }191 section("Colour") {192 row("Red / green", String(format: "%.3f", cast.redOverGreen), .measured)193 row("Blue / green", String(format: "%.3f", cast.blueOverGreen), .measured)194 row("Cast (grey-world)", cast.warmth > 0.08 ? String(localized: "warm") : (cast.warmth < -0.08 ? String(localized: "cool") : String(localized: "neutral")), .estimate)195 row("White balance", "\(Int(live.temperature.rounded())) K, tint \(Int(live.tint.rounded()))", .camera)196 }197 section("Timing") {198 row("Delivered frame rate", String(format: "%.1f fps", s.measuredFrameRate), .measured)199 row("Frame interval jitter", String(format: "%.2f ms", s.frameJitter), .measured)200 row("Frames dropped by capture", "\(s.droppedFrames)", .measured)201 row("Analysis time per frame", String(format: "%.1f ms", s.analysisMilliseconds), .measured)202 }203 section("Camera") {204 if let lens = model.capabilities?.lens {205 row("Lens", "\(lens.kind) \(lens.label), f/\(String(format: "%.2g", lens.aperture))", .camera)206 row("Focal length (35 mm eq.)", "\(Int(lens.focalLength35mm.rounded())) mm", .estimate)207 }208 row("Stream", "\(s.frameWidth) × \(s.frameHeight)", .measured)209 row("Nominal frame rate", String(format: "%.0f fps", live.activeFrameRate), .camera)210 row("ISO", ExposureMath.isoLabel(live.iso), .camera)211 row("Exposure duration", ExposureMath.shutterLabel(live.exposureDuration) + " s", .camera)212 row("Zoom factor", String(format: "%.2f×", live.zoom), .camera)213 row("Thermal / system pressure", model.pressure.rawValue, .camera)214 }215 Text("Measured = computed from the frames. Camera = value reported by the camera. Estimate = software estimate, not a measurement.")216 .font(.caption2).foregroundStyle(Instrument.textFaint)217 }218 .padding(12)219 }220 .frame(maxHeight: 270)221 .background(Instrument.panel)222 .accessibilityIdentifier("analysisPanel")223 }224225 private func percent(_ value: Double, digits: Int = 0) -> String {226 value.formatted(.percent.precision(.fractionLength(digits)))227 }228229 private func toggle(_ title: LocalizedStringKey, _ binding: Binding<Bool>, id: String) -> some View {230 PillButton(title: title, isOn: binding.wrappedValue, tint: Instrument.manual) { binding.wrappedValue.toggle(); model.haptic() }231 .accessibilityIdentifier(id)232 }233234 private var falseColorLegend: some View {235 ScrollView(.horizontal, showsIndicators: false) {236 HStack(spacing: 8) {237 ForEach(Array(FalseColorScale.bands.enumerated()), id: \.offset) { _, band in238 HStack(spacing: 4) {239 RoundedRectangle(cornerRadius: 2).fill(Color(red: Double(band.rgb.x), green: Double(band.rgb.y), blue: Double(band.rgb.z))).frame(width: 10, height: 10)240 Text("\(Int(band.range.lowerBound))–\(Int(band.range.upperBound)) %").font(.caption2.monospacedDigit()).foregroundStyle(Instrument.textDim)241 }242 }243 }244 }245 .accessibilityLabel(Text("False colour scale"))246 }247248 private func section<Content: View>(_ title: LocalizedStringKey, @ViewBuilder content: () -> Content) -> some View {249 VStack(alignment: .leading, spacing: 4) {250 Text(title).font(Instrument.label).foregroundStyle(Instrument.accent).textCase(.uppercase)251 content()252 }253 }254255 private func row(_ label: LocalizedStringKey, _ value: String, _ source: Source) -> some View {256 HStack(spacing: 6) {257 Circle().fill(source == .measured ? Instrument.good : (source == .camera ? Instrument.accent : Instrument.manual)).frame(width: 5, height: 5)258 Text(label).font(.caption).foregroundStyle(Instrument.textDim)259 Spacer(minLength: 8)260 Text(value).font(Instrument.readout(.caption)).foregroundStyle(Instrument.text)261 }262 .accessibilityElement(children: .combine)263 }264}265