1

我正在尝试使用两者CVPixelBufferCreateWithIOSurface以及通过读取像素来捕获 IOSurface IOSurfaceGetBaseAddressOfPlane

但是,在较新的设备(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以像素格式返回),但在我认为是较新设备的情况下分解。如何从这种未记录的格式中解组像素。

4

1 回答 1

1

我有回答自己问题的坏习惯。

要将其转换IOSurfaceIOSurface具有已知像素类型的 an,IOAccelerator应使用 an。

    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);
于 2019-05-03T14:01:39.670 回答