Skip to content

Commit 12cb781

Browse files
authored
Merge pull request #24389 from FlexMonkey/accelerate-vImage-vImageCopyBuffer
2 parents ff208b6 + 96e181c commit 12cb781

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

stdlib/public/Darwin/Accelerate/vImage_Buffer.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,10 @@ extension vImage_Buffer {
205205
/// Copies this buffer to `destinationBuffer`.
206206
///
207207
/// - Parameter destinationBuffer: The destination vImage buffer.
208+
/// - Parameter pixelSize: The number of bytes for one pixel.
208209
/// - Parameter options: The options to use when performing this operation.
209210
public func copy(destinationBuffer: inout vImage_Buffer,
211+
pixelSize: Int,
210212
flags options: vImage.Options = .noFlags) throws {
211213

212214
if Int(width) == 0 {
@@ -218,7 +220,7 @@ extension vImage_Buffer {
218220
_ = withUnsafePointer(to: self) {
219221
error = vImageCopyBuffer($0,
220222
&destinationBuffer,
221-
rowBytes / Int(width),
223+
pixelSize,
222224
options.flags)
223225
}
224226

test/stdlib/Accelerate_vImage.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import Accelerate
1111
var Accelerate_vImageTests = TestSuite("Accelerate_vImage")
1212

1313
if #available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *) {
14-
let width = UInt(48)
15-
let height = UInt(12)
16-
let widthi = 48
17-
let heighti = 12
14+
let width = UInt(64)
15+
let height = UInt(32)
16+
let widthi = 64
17+
let heighti = 32
1818

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

271271
expectCrashLater()
272-
try! source.copy(destinationBuffer: &destination)
272+
try! source.copy(destinationBuffer: &destination,
273+
pixelSize: 4)
273274
}
274275

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

279280
expectCrashLater()
280-
try! source.copy(destinationBuffer: &destination)
281+
try! source.copy(destinationBuffer: &destination,
282+
pixelSize: 4)
281283
}
282284

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

297-
try! source.copy(destinationBuffer: &destination)
299+
try! source.copy(destinationBuffer: &destination,
300+
pixelSize: 4)
298301

299302
let sourcePixels: [UInt8] = arrayFromBuffer(buffer: source,
300303
count: pixels.count)
@@ -306,7 +309,7 @@ if #available(iOS 9999, macOS 9999, tvOS 9999, watchOS 9999, *) {
306309
source.free()
307310
destination.free()
308311
}
309-
312+
310313
Accelerate_vImageTests.test("vImage/InitializeWithFormat") {
311314
let pixels: [UInt8] = (0 ..< width * height * 4).map { _ in
312315
return UInt8.random(in: 0 ..< 255)

0 commit comments

Comments
 (0)