CoreVideo / IOSurface:未知像素格式

时间:2019-04-22 04:14:39

标签: ios core-video iosurface

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

但是,在较新的设备(iPhone XS)上,我得到了未知的像素格式&wq2(再次使用IOSurfaceGetPixelFormatCVPixelBufferGetPixelFormatType)。

CVPixelFormatDescriptionCreateWithPixelFormatType返回以下内容:

@"{\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作为像素格式)上运行良好,但在我认为是较新的设备上却有所欠缺。如何从这种未公开的格式中解组像素。

1 个答案:

答案 0 :(得分:1)

我习惯回答自己的问题。

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

    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);