Skip to content

[vImage] Don't Infer Pixel Size in Buffer Copy #24389

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
Show file tree
Hide file tree
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
4 changes: 3 additions & 1 deletion stdlib/public/Darwin/Accelerate/vImage_Buffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,10 @@ extension vImage_Buffer {
/// Copies this buffer to `destinationBuffer`.
///
/// - Parameter destinationBuffer: The destination vImage buffer.
/// - Parameter pixelSize: The number of bytes for one pixel.
/// - Parameter options: The options to use when performing this operation.
public func copy(destinationBuffer: inout vImage_Buffer,
pixelSize: Int,
flags options: vImage.Options = .noFlags) throws {

if Int(width) == 0 {
Expand All @@ -218,7 +220,7 @@ extension vImage_Buffer {
_ = withUnsafePointer(to: self) {
error = vImageCopyBuffer($0,
&destinationBuffer,
rowBytes / Int(width),
pixelSize,
options.flags)
}

Expand Down
19 changes: 11 additions & 8 deletions test/stdlib/Accelerate_vImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import Accelerate
var Accelerate_vImageTests = TestSuite("Accelerate_vImage")

if #available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *) {
let width = UInt(48)
let height = UInt(12)
let widthi = 48
let heighti = 12
let width = UInt(64)
let height = UInt(32)
let widthi = 64
let heighti = 32

//===----------------------------------------------------------------------===//
//
Expand Down Expand Up @@ -269,15 +269,17 @@ if #available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *) {
var destination = try! vImage_Buffer(width: 20, height: 20, bitsPerPixel: 32)

expectCrashLater()
try! source.copy(destinationBuffer: &destination)
try! source.copy(destinationBuffer: &destination,
pixelSize: 4)
}

Accelerate_vImageTests.test("vImage/CopyBadHeight") {
var source = try! vImage_Buffer(width: 100, height: 10, bitsPerPixel: 32)
var destination = try! vImage_Buffer(width: 20, height: 20, bitsPerPixel: 32)

expectCrashLater()
try! source.copy(destinationBuffer: &destination)
try! source.copy(destinationBuffer: &destination,
pixelSize: 4)
}

Accelerate_vImageTests.test("vImage/Copy") {
Expand All @@ -294,7 +296,8 @@ if #available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *) {
var destination = try! vImage_Buffer(width: widthi, height: heighti,
bitsPerPixel: 32)

try! source.copy(destinationBuffer: &destination)
try! source.copy(destinationBuffer: &destination,
pixelSize: 4)

let sourcePixels: [UInt8] = arrayFromBuffer(buffer: source,
count: pixels.count)
Expand All @@ -306,7 +309,7 @@ if #available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *) {
source.free()
destination.free()
}

Accelerate_vImageTests.test("vImage/InitializeWithFormat") {
let pixels: [UInt8] = (0 ..< width * height * 4).map { _ in
return UInt8.random(in: 0 ..< 255)
Expand Down