diff --git a/Sources/geometrize/Bitmap.swift b/Sources/geometrize/Bitmap.swift index 8f39eb6..3de0877 100644 --- a/Sources/geometrize/Bitmap.swift +++ b/Sources/geometrize/Bitmap.swift @@ -52,7 +52,7 @@ public struct Bitmap { for y in 0..) { + assert(slice.count == 4) + self.r = slice[slice.startIndex] + self.g = slice[slice.startIndex + 1] + self.b = slice[slice.startIndex + 2] + self.a = slice[slice.startIndex + 3] + } + + public init(_ buffer: UnsafeBufferPointer) { + assert(buffer.count == 4) + self.r = buffer[0] + self.g = buffer[1] + self.b = buffer[2] + self.a = buffer[3] + } + + public init(_ slice: Slice>) { + assert(slice.count == 4) + self.r = slice[slice.startIndex] + self.g = slice[slice.startIndex + 1] + self.b = slice[slice.startIndex + 2] + self.a = slice[slice.startIndex + 3] + } + public func withAlphaComponent(_ alpha: UInt8) -> Rgba { Rgba(r: r, g: g, b: b, a: alpha) }