gpt4 book ai didi

ios - 核心视频/IOSurface : unknown pixel format

转载 作者:行者123 更新时间:2023-11-29 11:28:49 26 4
gpt4 key购买 nike

我正在尝试使用 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 作为像素格式),但在我假设的较新设备上出现故障。我如何从这种未记录的格式中解码像素。

最佳答案

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

要将此 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);

关于ios - 核心视频/IOSurface : unknown pixel format,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55789031/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com