Skip to content

Commit

Permalink
Extend Bitmap with init with parameter ContiguousArray
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriyvan committed May 1, 2024
1 parent 04072ef commit 31efdcb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions Sources/geometrize/Bitmap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public struct Bitmap { // swiftlint:disable:this type_body_length
/// - data: The byte data to fill the bitmap with, must be width * height * depth (4) long.
/// - blending: Background color to be blended. If nil, data provided is used as is.
/// If not nil, background is blended into bitmap making it opaque (alpha 255), alpha of background itself is ignored.
public init(width: Int, height: Int, data: [UInt8], blending background: Rgba? = nil) {
public init(width: Int, height: Int, data: ContiguousArray<UInt8>, blending background: Rgba? = nil) {
assert(width > 0 && height > 0)
assert(width * height * 4 == data.count)
self.width = width
Expand All @@ -62,10 +62,14 @@ public struct Bitmap { // swiftlint:disable:this type_body_length
initializedCapacity = width * height * 4
}
} else {
self.backing = ContiguousArray(data)
self.backing = data
}
}

public init(width: Int, height: Int, data: [UInt8], blending background: Rgba? = nil) {
self = Bitmap(width: width, height: height, data: ContiguousArray(data), blending: background)
}

public init(width: Int, height: Int, initializer: (_: Int, _: Int) -> Rgba) {
assert(width > 0 && height > 0)
self.width = width
Expand Down
2 changes: 1 addition & 1 deletion Tests/geometrizeTests/BitmapTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ final class BitmapTests: XCTestCase {
let bitmapWithYellowBackgroundBlended = Bitmap(
width: bitmap.width,
height: bitmap.height,
data: Array(bitmap.backing),
data: bitmap.backing,
blending: .yellow
)
assertSnapshot(
Expand Down

0 comments on commit 31efdcb

Please sign in to comment.