2026-07-25 12:39:32 +02:00
|
|
|
|
extension Graphics {
|
2026-09-18 12:45:39 +02:00
|
|
|
|
/// An 8×8 pattern. Mirrors `LCDPattern`: 8 image rows then 8 mask rows,
|
|
|
|
|
|
/// one byte per row, one bit per pixel.
|
2026-07-25 12:39:32 +02:00
|
|
|
|
public struct Pattern: Sendable {
|
|
|
|
|
|
public var bytes: (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
|
|
|
|
|
|
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)
|
|
|
|
|
|
|
|
|
|
|
|
public init(bytes: (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
|
|
|
|
|
|
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)) {
|
|
|
|
|
|
self.bytes = bytes
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-18 12:45:39 +02:00
|
|
|
|
/// An opaque pattern (mask rows all `0xff`).
|
2026-07-25 12:39:32 +02:00
|
|
|
|
public init(rows r: (UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8)) {
|
|
|
|
|
|
bytes = (r.0, r.1, r.2, r.3, r.4, r.5, r.6, r.7,
|
|
|
|
|
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-09-18 12:30:54 +02:00
|
|
|
|
|
2026-09-18 12:45:39 +02:00
|
|
|
|
// InlineArray needs macOS 26 on the host; device and Linux are unrestricted.
|
|
|
|
|
|
// Conversions reinterpret the same 16 bytes.
|
2026-09-18 12:30:54 +02:00
|
|
|
|
@available(macOS 26, *)
|
|
|
|
|
|
extension Graphics.Pattern {
|
|
|
|
|
|
public init(bytes: [16 of UInt8]) {
|
|
|
|
|
|
self.init(bytes: unsafeBitCast(bytes, to: Bytes.self))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-18 12:45:39 +02:00
|
|
|
|
/// An opaque pattern (mask rows all `0xff`).
|
2026-09-18 12:30:54 +02:00
|
|
|
|
public init(rows: [8 of UInt8]) {
|
|
|
|
|
|
self.init(bytes: [16 of UInt8] { $0 < 8 ? rows[$0] : 0xff })
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-09-18 12:45:39 +02:00
|
|
|
|
/// `bytes` as an inline array.
|
2026-09-18 12:30:54 +02:00
|
|
|
|
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)
|
|
|
|
|
|
}
|