Last active
April 26, 2022 23:05
-
-
Save warrenm/df774ebae052e93e4ba49e59cfef620c to your computer and use it in GitHub Desktop.
Example of creating a biplanar (YUV422) IOSurface
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
NSUInteger width = 1024; | |
NSUInteger height = 768; | |
OSType pixelFormat = kCVPixelFormatType_422YpCbCr8BiPlanarFullRange; | |
NSUInteger plane0BytesPerPixel = 1; | |
NSUInteger plane1BytesPerPixel = 1; | |
NSUInteger plane0BytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, plane0BytesPerPixel * width); | |
NSUInteger plane0AllocSize = IOSurfaceAlignProperty(kIOSurfaceAllocSize, plane0BytesPerRow * height); | |
NSUInteger plane1BytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, plane1BytesPerPixel * width); | |
NSUInteger plane1AllocSize = IOSurfaceAlignProperty(kIOSurfaceAllocSize, plane1BytesPerRow * height); | |
NSArray *planeInfo = @[ | |
@{ | |
(id)kIOSurfacePlaneWidth : @(width), | |
(id)kIOSurfacePlaneHeight : @(height), | |
(id)kIOSurfacePlaneBytesPerRow : @(plane0BytesPerRow), | |
(id)kIOSurfaceAllocSize : @(plane0AllocSize), | |
(id)kIOSurfacePlaneOffset : @(0), | |
}, | |
@{ | |
(id)kIOSurfacePlaneWidth : @(width), | |
(id)kIOSurfacePlaneHeight : @(height), | |
(id)kIOSurfacePlaneBytesPerRow : @(plane1BytesPerRow), | |
(id)kIOSurfaceAllocSize : @(plane1AllocSize), | |
(id)kIOSurfacePlaneOffset : @(plane0AllocSize), | |
} | |
]; | |
NSDictionary *surfaceProperties = @{ | |
(id)kIOSurfaceWidth : @(width), | |
(id)kIOSurfaceHeight : @(height), | |
(id)kIOSurfacePixelFormat : @(pixelFormat), | |
(id)kIOSurfacePlaneInfo : planeInfo, | |
(id)kIOSurfaceAllocSize : @(plane0AllocSize + plane1AllocSize) | |
}; | |
IOSurfaceRef surface = IOSurfaceCreate((__bridge CFDictionaryRef)surfaceProperties); |
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
import IOSurface | |
import CoreVideo | |
let width = 1024 | |
let height = 768 | |
let pixelFormat = kCVPixelFormatType_422YpCbCr8BiPlanarFullRange | |
let plane0BytesPerPixel = 1 | |
let plane1BytesPerPixel = 1 | |
let plane0BytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, plane0BytesPerPixel * width) | |
let plane0AllocSize = IOSurfaceAlignProperty(kIOSurfaceAllocSize, plane0BytesPerRow * height) | |
let plane1BytesPerRow = IOSurfaceAlignProperty(kIOSurfaceBytesPerRow, plane1BytesPerPixel * width) | |
let plane1AllocSize = IOSurfaceAlignProperty(kIOSurfaceAllocSize, plane1BytesPerRow * height) | |
let planeInfo = [ | |
[ | |
kIOSurfacePlaneWidth : width, | |
kIOSurfacePlaneHeight : height, | |
kIOSurfacePlaneBytesPerRow : plane0BytesPerRow, | |
kIOSurfaceAllocSize : plane0AllocSize, | |
kIOSurfacePlaneOffset : 0, | |
], | |
[ | |
kIOSurfacePlaneWidth : width, | |
kIOSurfacePlaneHeight : height, | |
kIOSurfacePlaneBytesPerRow : plane1BytesPerRow, | |
kIOSurfaceAllocSize : plane1AllocSize, | |
kIOSurfacePlaneOffset : plane0AllocSize, | |
] | |
] | |
let surfaceProperties : [CFString : Any] = [ | |
kIOSurfaceWidth : width, | |
kIOSurfaceHeight : height, | |
kIOSurfacePixelFormat : pixelFormat, | |
kIOSurfacePlaneInfo : planeInfo, | |
kIOSurfaceAllocSize : plane0AllocSize + plane1AllocSize | |
] | |
let surface = IOSurfaceCreate(surfaceProperties as CFDictionary) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment