Skip to content

Add ColorRenderingMode implementation #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions Sources/OpenSwiftUICore/Render/ColorRenderingMode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// ColorRenderingMode.swift
// OpenSwiftUICore
//
// Audited for RELEASE_2024
// Status: Complete

/// The set of possible working color spaces for color-compositing operations.
///
/// Each color space guarantees the preservation of a particular range of color
/// values.
public enum ColorRenderingMode: Sendable {
/// The non-linear sRGB working color space.
///
/// Color component values outside the range `[0, 1]` produce undefined
/// results. This color space is gamma corrected.
case nonLinear

/// The linear sRGB working color space.
///
/// Color component values outside the range `[0, 1]` produce undefined
/// results. This color space isn't gamma corrected.
case linear

/// The extended linear sRGB working color space.
///
/// Color component values outside the range `[0, 1]` are preserved.
/// This color space isn't gamma corrected.
case extendedLinear
}

extension ColorRenderingMode: Equatable {}
extension ColorRenderingMode: Hashable {}

extension ColorRenderingMode: ProtobufEnum {
package var protobufValue: UInt {
switch self {
case .nonLinear:
return 0
case .linear:
return 1
case .extendedLinear:
return 2

Check warning on line 43 in Sources/OpenSwiftUICore/Render/ColorRenderingMode.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/ColorRenderingMode.swift#L36-L43

Added lines #L36 - L43 were not covered by tests
}
}
package init?(protobufValue value: UInt) {
switch value {
case 0:
self = .nonLinear
case 1:
self = .linear
case 2:
self = .extendedLinear
default:
return nil

Check warning on line 55 in Sources/OpenSwiftUICore/Render/ColorRenderingMode.swift

View check run for this annotation

Codecov / codecov/patch

Sources/OpenSwiftUICore/Render/ColorRenderingMode.swift#L46-L55

Added lines #L46 - L55 were not covered by tests
}
}
}
Loading