Created
May 19, 2016 09:58
-
-
Save valkjsaaa/f9edfc25b4fd592caf82834fafc07759 to your computer and use it in GitHub Desktop.
deep copy of a CVImageBuffer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CVPixelBuffer { | |
func deepcopy() -> CVPixelBuffer? { | |
let width = CVPixelBufferGetWidth(self) | |
let height = CVPixelBufferGetHeight(self) | |
let format = CVPixelBufferGetPixelFormatType(self) | |
var pixelBufferCopyOptional:CVPixelBuffer? | |
CVPixelBufferCreate(nil, width, height, format, nil, &pixelBufferCopyOptional) | |
if let pixelBufferCopy = pixelBufferCopyOptional { | |
CVPixelBufferLockBaseAddress(self, kCVPixelBufferLock_ReadOnly) | |
CVPixelBufferLockBaseAddress(pixelBufferCopy, 0) | |
let baseAddress = CVPixelBufferGetBaseAddress(self) | |
let dataSize = CVPixelBufferGetDataSize(self) | |
print("dataSize: \(dataSize)") | |
let target = CVPixelBufferGetBaseAddress(pixelBufferCopy) | |
memcpy(target, baseAddress, dataSize) | |
CVPixelBufferUnlockBaseAddress(pixelBufferCopy, 0) | |
CVPixelBufferUnlockBaseAddress(self, kCVPixelBufferLock_ReadOnly) | |
} | |
return pixelBufferCopyOptional | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This crashes for me on an iPad Pro but works fine on an iPhone X.