Breakup an UnsafeMutableBufferPointer<UInt32> in swift 5.x

97 Views Asked by At

iOS 15, Swift 5.5

Sorry, stupid easy question??

I am working on an image processing app, and I have this.

let pixels = UnsafeMutableBufferPointer<UInt32>(start: rawData, count: width * height)

Which I want to break into two pieces, so I tried this.

let fullSet = width * height
let halfSet = fullSet / 2
let pix1 = UnsafeMutableBufferPointer<UInt32>(start: rawData, count: halfSet)
let pix2 = UnsafeMutableBufferPointer<UInt32>(start: (rawData + halfSet), count: halfSet)

I suspect my problem is that the UInt32 is in fact a UInt24 + UInt8, as in red+green+blue and alpha channel.

I count the colours in my pixel Set and I got 120,433... but if I convert to an array I end up with 57,142.

1

There are 1 best solutions below

0
user3069232 On

Ok,

I found the answer, thanks everyone for your comments. And yes, it is stupid obvious, you just use a subset.

let pix1 = pixels[(0..<pixels.count / 2)]
let pix2 = pixels[(pixels.count / 2)...]

I was trying too hard I think.