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/Monitoring/Zebra.swift10// Description : Zebra exposure thresholds. Levels are percentages of the11// full 8-bit scale of the gamma-encoded preview signal (Rec.12// 709 luma). They describe the monitoring stream, not raw13// sensor values and not a log signal.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 struct ZebraSettings: Sendable, Equatable, Codable {96 public var highlightsEnabled: Bool97 /// Stripes are drawn where luma is at or above this percentage (50…100).98 public var highlightThreshold: Double99 public var shadowsEnabled: Bool100 /// Shadow warning where luma is at or below this percentage (0…20).101 public var shadowThreshold: Double102 public var opacity: Double103104 public init(highlightsEnabled: Bool = true, highlightThreshold: Double = 95, shadowsEnabled: Bool = false, shadowThreshold: Double = 3, opacity: Double = 0.85) {105 self.highlightsEnabled = highlightsEnabled106 self.highlightThreshold = highlightThreshold107 self.shadowsEnabled = shadowsEnabled108 self.shadowThreshold = shadowThreshold109 self.opacity = opacity110 }111112 /// Common presets: 70 % (skin-tone exposure aid), 95 % and 100 % (clipping).113 public static let presets: [Double] = [70, 80, 90, 95, 100]114}115116public enum Zebra {117 /// 8-bit code value for a percentage of full scale.118 public static func level(percent: Double) -> Int {119 Int((min(max(percent, 0), 100) / 100 * 255).rounded())120 }121122 /// Whether a pixel of luma `value` (0…255) is striped as a highlight.123 public static func isHighlight(_ value: UInt8, settings: ZebraSettings) -> Bool {124 settings.highlightsEnabled && Int(value) >= level(percent: settings.highlightThreshold)125 }126127 public static func isShadow(_ value: UInt8, settings: ZebraSettings) -> Bool {128 settings.shadowsEnabled && Int(value) <= level(percent: settings.shadowThreshold)129 }130131 /// Fractions of the frame covered by the highlight and shadow warnings.132 public static func coverage(_ histogram: HistogramData, settings: ZebraSettings) -> (highlights: Double, shadows: Double) {133 let hi = settings.highlightsEnabled ? histogram.fraction(atOrAbove: level(percent: settings.highlightThreshold)) : 0134 let lo = settings.shadowsEnabled ? histogram.fraction(atOrBelow: level(percent: settings.shadowThreshold)) : 0135 return (hi, lo)136 }137}138