首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CoreVideo / IOSurface:未知像素格式

CoreVideo / IOSurface:未知像素格式
EN

Stack Overflow用户
提问于 2019-04-22 12:14:39
回答 1查看 462关注 0票数 1

我正在尝试使用CVPixelBufferCreateWithIOSurface和从IOSurfaceGetBaseAddressOfPlane读取像素来捕获IOSurface。

然而,在较新的设备(iPhone XS)上,我得到了一个未知的像素格式&wq2 (同样,使用IOSurfaceGetPixelFormatCVPixelBufferGetPixelFormatType)。

CVPixelFormatDescriptionCreateWithPixelFormatType返回以下内容:

代码语言:javascript
复制
@"{\n    BitsPerComponent = 10;\n    ComponentRange = FullRange;\n    ContainsAlpha = 1;\n    ContainsGrayscale = 0;\n    ContainsRGB = 1;\n    ContainsYCbCr = 0;\n    PixelFormat = 645346401;\n    Planes =     (\n                {\n            BitsPerBlock = 64;\n            CompressionType = 2;\n            TileHeight = 16;\n            TileWidth = 16;\n        }\n    );\n}"

我的代码在较旧的设备上运行良好(它返回BGRA作为像素格式),但在我认为是较新的设备上出现故障。如何从这种未记录的格式中解组像素。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-03 22:01:40

我有个坏习惯,就是回答我自己的问题。

要将此IOSurface转换为具有已知像素类型的IOSurface,应使用IOAccelerator

代码语言:javascript
复制
    CFMutableDictionary dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);;
    char pixelFormat[4] = {'A', 'R', 'G', 'B'};

    CFDictionarySetValue(dict, kIOSurfaceBytesPerRow, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &bytesPerRow));
    CFDictionarySetValue(dict, kIOSurfaceBytesPerElement, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &bytesPerElement));
    CFDictionarySetValue(dict, kIOSurfaceWidth, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &width));
    CFDictionarySetValue(dict, kIOSurfaceHeight, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &height));
    CFDictionarySetValue(dict, kIOSurfacePixelFormat, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, pixelFormat));
    CFDictionarySetValue(dict, kIOSurfaceAllocSize, CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &bufferSize));
    IOSurfaceRef surface = IOSurfaceCreate(dict);

    auto const didCreateAccelerator = IOSurfaceAcceleratorCreate(kCFAllocatorDefault, 0, &accelerator);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55789031

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档