Added InlineArray pattern overloads to the library to optimize for macOS 26.

This commit is contained in:
2026-09-18 12:30:54 +02:00
parent 52d5d2ec42
commit c9f887bacb
4 changed files with 75 additions and 0 deletions
@@ -19,3 +19,32 @@ extension Graphics {
}
}
}
// InlineArray needs macOS 26 on the host, so these conveniences are gated
// there while the tuple API keeps working on older systems. The device and
// Linux have no such restriction. Both representations are 16 contiguous
// bytes, so converting between them is a reinterpretation, not a copy.
@available(macOS 26, *)
extension Graphics.Pattern {
/// Creates a pattern from 8 rows of image data and 8 rows of mask.
public init(bytes: [16 of UInt8]) {
self.init(bytes: unsafeBitCast(bytes, to: Bytes.self))
}
/// Creates an opaque pattern from 8 rows of image data.
public init(rows: [8 of UInt8]) {
self.init(bytes: [16 of UInt8] { $0 < 8 ? rows[$0] : 0xff })
}
/// The pattern's bytes as an inline array: 8 rows of image data
/// followed by 8 rows of mask.
public var inlineBytes: [16 of UInt8] {
get { unsafeBitCast(bytes, to: [16 of UInt8].self) }
set { bytes = unsafeBitCast(newValue, to: Bytes.self) }
}
}
extension Graphics.Pattern {
typealias Bytes = (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)
}