4#include <CoreMedia/CMFormatDescription.h>
5#include <CoreVideo/CoreVideo.h>
8#import <CoreVideo/CoreVideo.h>
12 switch (avPixelFormat) {
13 case kCVPixelFormatType_420YpCbCr8PlanarFullRange:
14 case kCVPixelFormatType_420YpCbCr8BiPlanarFullRange:
15 case kCVPixelFormatType_420YpCbCr10BiPlanarFullRange:
17 case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange:
18 case kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange:
19 case kCVPixelFormatType_422YpCbCr8:
20 case kCVPixelFormatType_422YpCbCr8_yuvs:
29 switch (avPixelFormat) {
30 case kCVPixelFormatType_32ARGB:
32 case kCVPixelFormatType_32BGRA:
34 case kCVPixelFormatType_420YpCbCr8Planar:
35 case kCVPixelFormatType_420YpCbCr8PlanarFullRange:
37 case kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange:
38 case kCVPixelFormatType_420YpCbCr8BiPlanarFullRange:
40 case kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange:
41 case kCVPixelFormatType_420YpCbCr10BiPlanarFullRange:
43 case kCVPixelFormatType_422YpCbCr8:
45 case kCVPixelFormatType_422YpCbCr8_yuvs:
47 case kCVPixelFormatType_OneComponent8:
52 case kCMVideoCodecType_JPEG:
53 case kCMVideoCodecType_JPEG_OpenDML:
64 conv = kCVPixelFormatType_32ARGB;
67 conv = kCVPixelFormatType_32BGRA;
70 conv = kCVPixelFormatType_420YpCbCr8PlanarFullRange;
73 conv = kCVPixelFormatType_420YpCbCr8BiPlanarFullRange;
76 conv = kCVPixelFormatType_420YpCbCr10BiPlanarFullRange;
79 conv = kCVPixelFormatType_422YpCbCr8;
82 conv = kCVPixelFormatType_422YpCbCr8_yuvs;
85 conv = kCVPixelFormatType_OneComponent8;
99 auto avPixelFormat = CVPixelBufferGetPixelFormatType(
buffer);
102 if (avPixelFormat == kCVPixelFormatType_32BGRA)
105 qWarning() <<
"Accelerated macOS OpenGL video supports BGRA only, got CV pixel format" << avPixelFormat;
116 if (CFStringRef cSpace =
reinterpret_cast<CFStringRef
>(
117 CVBufferGetAttachment(
buffer, kCVImageBufferYCbCrMatrixKey,
nullptr))) {
118 if (CFEqual(cSpace, kCVImageBufferYCbCrMatrix_ITU_R_709_2)) {
120 }
else if (CFEqual(cSpace, kCVImageBufferYCbCrMatrix_ITU_R_601_4)
121 || CFEqual(cSpace, kCVImageBufferYCbCrMatrix_SMPTE_240M_1995)) {
123 }
else if (@available(macOS 10.11,
iOS 9.0, *)) {
124 if (CFEqual(cSpace, kCVImageBufferYCbCrMatrix_ITU_R_2020)) {
130 if (CFStringRef cTransfer =
reinterpret_cast<CFStringRef
>(
131 CVBufferGetAttachment(
buffer, kCVImageBufferTransferFunctionKey,
nullptr))) {
133 if (CFEqual(cTransfer, kCVImageBufferTransferFunction_ITU_R_709_2)) {
135 }
else if (CFEqual(cTransfer, kCVImageBufferTransferFunction_SMPTE_240M_1995)) {
137 }
else if (CFEqual(cTransfer, kCVImageBufferTransferFunction_sRGB)) {
139 }
else if (CFEqual(cTransfer, kCVImageBufferTransferFunction_UseGamma)) {
140 auto gamma =
reinterpret_cast<CFNumberRef
>(
141 CVBufferGetAttachment(
buffer, kCVImageBufferGammaLevelKey,
nullptr));
143 CFNumberGetValue(gamma, kCFNumberFloat32Type, &
g);
156 if (@available(macOS 10.12,
iOS 11.0, *)) {
157 if (CFEqual(cTransfer, kCVImageBufferTransferFunction_ITU_R_2020))
160 if (@available(macOS 10.12,
iOS 11.0, *)) {
161 if (CFEqual(cTransfer, kCVImageBufferTransferFunction_ITU_R_2100_HLG)) {
163 }
else if (CFEqual(cTransfer, kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ)) {
170 format.setColorSpace(colorSpace);
171 format.setColorTransfer(colorTransfer);
bool toCVPixelFormat(QVideoFrameFormat::PixelFormat qtFormat, unsigned &conv)
QVideoFrameFormat::PixelFormat fromCVPixelFormat(unsigned avPixelFormat)
QVideoFrameFormat videoFormatForImageBuffer(CVImageBufferRef buffer, bool openGL=false)
static QVideoFrameFormat::ColorRange colorRangeForPixelFormat(unsigned avPixelFormat)
@ q_kCVPixelFormatType_OneComponent16
GLint GLsizei GLsizei height
GLint GLsizei GLsizei GLenum format