SPB Git

Repository Public License

CameraSheets.swift 16.5 KB 306 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/CameraSheets.swift10// Description      : The two camera sheets: capture format (photo format and11//                    size, video resolution, frame rate, codec, audio) and12//                    tools (composition and monitoring aids, looks).13//                    Unavailable options stay visible with their reason.14// Module           : Features15// 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 ORIXDesign94import ORIXImaging95import SwiftUI9697struct FormatSheet: View {98    @Bindable var model: CameraModel99    @Environment(\.dismiss) private var dismiss100101    var body: some View {102        NavigationStack {103            Form {104                if model.mode == .video { video } else { photo }105            }106            .navigationTitle(model.mode == .video ? Text("Video format") : Text("Photo format"))107            .navigationBarTitleDisplayMode(.inline)108            .toolbar { ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() }.accessibilityIdentifier("sheet.done") } }109        }110        .presentationDetents(DebugHooks.isUITest ? [.large] : [.medium, .large])111    }112113    private func reason(_ feature: CameraCapabilities.Feature) -> String? { model.capabilities?.localizedExplanation(for: feature) }114115    @ViewBuilder private var photo: some View {116        Section {117            ForEach(PhotoFormat.allCases, id: \.self) { format in118                let why: String? = format == .proRAW ? reason(.proRAW) : (format == .raw || format == .rawPlusHEIC ? reason(.bayerRAW) : nil)119                Button {120                    model.settings.photoFormat = format; model.haptic()121                } label: {122                    HStack {123                        VStack(alignment: .leading, spacing: 2) {124                            Text(format.title).foregroundStyle(why == nil ? Color.primary : Color.secondary)125                            Text(why ?? Self.detail(format)).font(.caption).foregroundStyle(.secondary)126                        }127                        Spacer()128                        if model.settings.photoFormat == format { Image(systemName: "checkmark").foregroundStyle(.tint) }129                    }130                }131                .disabled(why != nil)132                .accessibilityIdentifier("format.\(format.rawValue)")133            }134        } header: { Text("Format") } footer: {135            Text("Auto mode always captures HEIC. RAW formats are used in Pro Photo and Analysis.")136        }137        Section {138            Toggle("Largest photo size", isOn: $model.settings.highResolutionPhotos)139            if let caps = model.capabilities {140                LabeledContent("Largest size on this camera", value: "\(caps.maxPhotoWidth) × \(caps.maxPhotoHeight)")141            }142        } header: { Text("Resolution") } footer: {143            Text("Off limits photos to 12 megapixels. Bayer RAW uses the sensor's RAW size.")144        }145        Section("Shooting") {146            Picker("Aspect ratio", selection: $model.settings.aspect) {147                ForEach(AspectGuide.allCases, id: \.self) { Text($0.title).tag($0) }148            }149            Picker("Timer", selection: $model.settings.timerSeconds) {150                Text("Off").tag(0); Text("3 s").tag(3); Text("10 s").tag(10)151            }152            if let why = reason(.flash) { LabeledContent("Flash", value: why) } else {153                Picker("Flash", selection: $model.settings.flash) {154                    Text("Off").tag(FlashSetting.off); Text("Auto").tag(FlashSetting.auto); Text("On").tag(FlashSetting.on)155                }156            }157            Toggle("Mirror front camera photos", isOn: $model.settings.mirrorFrontPhotos)158        }159    }160161    static func detail(_ format: PhotoFormat) -> String {162        switch format {163        case .heic: String(localized: "Processed, compact. Best for everyday photos.")164        case .jpeg: String(localized: "Processed, most compatible.")165        case .raw: String(localized: "Unprocessed Bayer sensor data in a DNG file.")166        case .rawPlusHEIC: String(localized: "A Bayer DNG and a processed HEIC of the same shot.")167        case .proRAW: String(localized: "Apple ProRAW: a linear DNG with Apple's multi-frame processing, plus a HEIC.")168        }169    }170171    @ViewBuilder private var video: some View {172        if let caps = model.capabilities {173            Section("Resolution") {174                ForEach(caps.resolutions) { resolution in175                    Button {176                        let rates = caps.frameRates(width: resolution.width, height: resolution.height)177                        let rate = rates.contains(model.settings.videoFrameRate) ? model.settings.videoFrameRate : (rates.contains(30) ? 30 : rates.first ?? 30)178                        model.setVideoFormat(VideoFormatOption(width: resolution.width, height: resolution.height, frameRate: rate))179                    } label: {180                        HStack {181                            Text(resolution.resolutionLabel).foregroundStyle(Color.primary)182                            Text("\(resolution.width) × \(resolution.height)").font(.caption).foregroundStyle(.secondary)183                            Spacer()184                            if resolution.width == model.settings.videoWidth && resolution.height == model.settings.videoHeight { Image(systemName: "checkmark").foregroundStyle(.tint) }185                        }186                    }187                    .accessibilityIdentifier("resolution.\(resolution.resolutionLabel)")188                }189            }190            Section {191                Picker("Frame rate", selection: Binding(get: { model.settings.videoFrameRate }, set: {192                    model.setVideoFormat(VideoFormatOption(width: model.settings.videoWidth, height: model.settings.videoHeight, frameRate: $0))193                })) {194                    ForEach(caps.frameRates(width: model.settings.videoWidth, height: model.settings.videoHeight), id: \.self) { Text("\(Int($0)) fps").tag($0) }195                }196                if model.settings.videoFrameRate > 60 {197                    Toggle("Play back in slow motion (30 fps)", isOn: $model.settings.slowMotionPlayback)198                }199            } header: { Text("Frame rate") } footer: {200                if model.settings.videoFrameRate > 60 { Text("Slow-motion files hold every captured frame, retimed to 30 fps, without sound.") }201            }202            Section {203                ForEach(VideoCodec.allCases, id: \.self) { codec in204                    let available = caps.videoCodecs.contains(codec)205                    Button { model.settings.videoCodec = codec; model.haptic() } label: {206                        HStack {207                            VStack(alignment: .leading, spacing: 2) {208                                Text(codec.title).foregroundStyle(available ? Color.primary : Color.secondary)209                                Text(available ? Self.detail(codec, model: model) : (caps.localizedExplanation(for: .proRes) ?? "")).font(.caption).foregroundStyle(.secondary)210                            }211                            Spacer()212                            if model.settings.videoCodec == codec { Image(systemName: "checkmark").foregroundStyle(.tint) }213                        }214                    }215                    .disabled(!available)216                    .accessibilityIdentifier("codec.\(codec.rawValue)")217                }218            } header: { Text("Codec") } footer: {219                Text("ORIX Camera records 8-bit SDR video. 10-bit HDR and Apple Log are not recorded in this version\(caps.deviceOffersAppleLog || caps.deviceOffersHDRVideo ? String(localized: ", although this camera offers them") : "").")220            }221            Section("Sound and stabilization") {222                Toggle("Record sound", isOn: Binding(get: { model.settings.recordAudio }, set: { model.setVideoOption(audio: $0) }))223                if caps.supportsVideoStabilization {224                    Toggle("Stabilization", isOn: Binding(get: { model.settings.stabilization }, set: { model.setVideoOption(stabilization: $0) }))225                } else {226                    LabeledContent("Stabilization", value: String(localized: "Not offered by this camera in this format"))227                }228            }229        }230    }231232    static func detail(_ codec: VideoCodec, model: CameraModel) -> String {233        let rate = ExposureMath.bytesPerSecond(codec: codec, width: model.settings.videoWidth, height: model.settings.videoHeight, frameRate: model.settings.videoFrameRate, audio: model.settings.recordAudio)234        let perMinute = Measurement(value: rate * 60, unit: UnitInformationStorage.bytes).converted(to: .megabytes)235        return String(localized: "About \(perMinute.value.formatted(.number.precision(.fractionLength(0)))) MB per minute at this format")236    }237}238239struct ToolsSheet: View {240    @Bindable var model: CameraModel241    @Environment(\.dismiss) private var dismiss242243    var body: some View {244        NavigationStack {245            Form {246                Section("Composition") {247                    Picker("Grid", selection: $model.settings.grid) {248                        Text("Off").tag(GridOverlay.none); Text("Rule of thirds").tag(GridOverlay.thirds); Text("Golden ratio").tag(GridOverlay.golden)249                        Text("Square grid").tag(GridOverlay.square); Text("Diagonals").tag(GridOverlay.diagonals)250                        Text("Centre cross").tag(GridOverlay.centre); Text("Symmetry").tag(GridOverlay.symmetry)251                    }252                    Picker("Aspect guide", selection: $model.settings.aspect) {253                        ForEach(AspectGuide.allCases, id: \.self) { Text($0.title).tag($0) }254                    }255                    Toggle("Level", isOn: $model.settings.showLevel)256                    Toggle("Safe framing (action and title)", isOn: $model.settings.safeFraming)257                }258                Section {259                    Toggle("Histogram", isOn: $model.settings.showHistogram)260                    Picker("Histogram type", selection: $model.settings.histogramStyle) {261                        Text("Luminance").tag(HistogramStyle.luma); Text("RGB").tag(HistogramStyle.rgb)262                    }263                    Toggle("Large histogram", isOn: $model.settings.histogramExpanded)264                } header: { Text("Histogram") }265                Section {266                    Toggle("Focus peaking", isOn: $model.settings.peaking).accessibilityIdentifier("tools.peaking")267                    LabeledContent("Sensitivity") { Slider(value: $model.settings.peakingSensitivity, in: 0...1).accessibilityLabel(Text("Peaking sensitivity")) }268                    Picker("Colour", selection: $model.settings.peakingColor) {269                        ForEach(PeakingColor.allCases, id: \.self) { Text(LocalizedStringKey($0.rawValue.capitalized)).tag($0) }270                    }271                    Toggle("Magnify while focusing manually", isOn: $model.settings.focusMagnifier)272                } header: { Text("Focus peaking") } footer: {273                    Text("Peaking marks strong local contrast (a Sobel gradient above the threshold). It estimates sharpness; it does not guarantee focus. White, yellow and cyan stay visible with colour-vision deficiencies.")274                }275                Section {276                    Toggle("Highlight zebras", isOn: $model.settings.zebra.highlightsEnabled).accessibilityIdentifier("tools.zebra")277                    Picker("Highlight threshold", selection: $model.settings.zebra.highlightThreshold) {278                        ForEach(ZebraSettings.presets, id: \.self) { Text("\(Int($0)) %").tag($0) }279                    }280                    Toggle("Shadow warning", isOn: $model.settings.zebra.shadowsEnabled)281                    LabeledContent("Opacity") { Slider(value: $model.settings.zebra.opacity, in: 0.3...1).accessibilityLabel(Text("Zebra opacity")) }282                } header: { Text("Zebras") } footer: {283                    Text("Thresholds are percentages of the 8-bit monitoring signal (Rec. 709 luma, gamma-encoded): 100 % is code 255. They are not sensor or log values.")284                }285                Section {286                    Picker(model.mode == .video ? "Monitor look" : "Capture look", selection: model.mode == .video ? $model.settings.monitorLookID : $model.settings.captureLookID) {287                        Text("None").tag(String?.none)288                        ForEach(ColorLUT.builtIn.dropFirst()) { Text(LocalizedStringKey($0.title)).tag(String?.some($0.id)) }289                    }290                    .accessibilityIdentifier("tools.look")291                } header: { Text("Look") } footer: {292                    if model.mode == .video {293                        Text("In video the look is a monitoring transform only: the recorded file is not graded.")294                    } else {295                        Text("Photos keep the full original. The look is stored as an edit you can change or remove later.")296                    }297                }298            }299            .navigationTitle("Tools")300            .navigationBarTitleDisplayMode(.inline)301            .toolbar { ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() }.accessibilityIdentifier("sheet.done") } }302        }303        .presentationDetents(DebugHooks.isUITest ? [.large] : [.medium, .large])304    }305}306
Files main
Menu

Theme