diff options
author | Damiano Galassi <[email protected]> | 2017-06-12 17:04:04 +0200 |
---|---|---|
committer | Damiano Galassi <[email protected]> | 2017-06-12 17:04:04 +0200 |
commit | c894ec059b4b9db3f188aff86c92f44954a2eb3c (patch) | |
tree | e8d69d887ed282299ec93ad90dda43a4acc61935 | |
parent | 74b10b23b0dd902ba718e8848662c9ac4241412c (diff) |
MacGui: call CVImageBufferCreateColorSpaceFromAttachments() to create the preview image color spaces on 10.11 and newer.
-rw-r--r-- | macosx/HBCore.m | 81 |
1 files changed, 79 insertions, 2 deletions
diff --git a/macosx/HBCore.m b/macosx/HBCore.m index 7e9024b47..39e6be5ac 100644 --- a/macosx/HBCore.m +++ b/macosx/HBCore.m @@ -28,7 +28,7 @@ static void hb_error_handler(const char *errmsg) } } -typedef void (^HBCoreCleanupHandler)(); +typedef void (^HBCoreCleanupHandler)(void); /** * Private methods of HBCore. @@ -411,6 +411,81 @@ typedef void (^HBCoreCleanupHandler)(); } } +- (CGColorSpaceRef)copyColorSpaceWithPrimaries:(int)primaries transfer:(int)transfer matrix:(int)matrix +{ + if (NSAppKitVersionNumber < NSAppKitVersionNumber10_11) + { + return [self copyColorSpaceWithColorPrimaries:primaries]; + } + + CFStringRef primariesKey = NULL; + switch (primaries) + { + case HB_COLR_PRI_EBUTECH: + primariesKey = kCVImageBufferColorPrimaries_EBU_3213; + break; + + case HB_COLR_PRI_SMPTEC: + primariesKey = kCVImageBufferColorPrimaries_SMPTE_C; + break; + + case HB_COLR_PRI_BT2020: + primariesKey = kCVImageBufferColorPrimaries_ITU_R_2020; + break; + + case HB_COLR_PRI_BT709: + default: + primariesKey = kCVImageBufferColorPrimaries_ITU_R_709_2; + } + + CFStringRef transferKey = NULL; + switch (transfer) + { + case HB_COLR_TRA_SMPTE240M: + transferKey = kCVImageBufferTransferFunction_SMPTE_240M_1995; + break; + + case HB_COLR_TRA_BT2020_10: + case HB_COLR_TRA_BT2020_12: + transferKey = kCVImageBufferTransferFunction_ITU_R_2020; + break; + + case HB_COLR_TRA_BT709: + default: + transferKey = kCVImageBufferTransferFunction_ITU_R_709_2; + } + + CFStringRef matrixKey = NULL; + + switch (matrix) + { + case HB_COLR_MAT_SMPTE170M: + matrixKey = kCVImageBufferYCbCrMatrix_ITU_R_601_4; + break; + + case HB_COLR_MAT_SMPTE240M: + matrixKey = kCVImageBufferYCbCrMatrix_SMPTE_240M_1995; + break; + + case HB_COLR_MAT_BT2020_NCL: + case HB_COLR_MAT_BT2020_CL: + matrixKey = kCVImageBufferYCbCrMatrix_ITU_R_2020; + break; + + case HB_COLR_MAT_BT709: + default: + matrixKey = kCVImageBufferYCbCrMatrix_ITU_R_709_2;; + } + + const void *keys[3] = { kCVImageBufferColorPrimariesKey, kCVImageBufferTransferFunctionKey, kCVImageBufferYCbCrMatrixKey }; + const void *values[3] = { primariesKey, transferKey, matrixKey}; + CFDictionaryRef attachments = CFDictionaryCreate(NULL, keys, values, 3, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + + CGColorSpaceRef colorSpace = CVImageBufferCreateColorSpaceFromAttachments(attachments); + + return colorSpace; +} + - (CGImageRef)copyImageAtIndex:(NSUInteger)index forTitle:(HBTitle *)title pictureFrame:(HBPicture *)frame @@ -440,7 +515,9 @@ typedef void (^HBCoreCleanupHandler)(); CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault | kCGImageAlphaNone; CFMutableDataRef imgData = CFDataCreateMutable(kCFAllocatorDefault, 3 * image->width * image->height); CGDataProviderRef provider = CGDataProviderCreateWithCFData(imgData); - CGColorSpaceRef colorSpace = [self copyColorSpaceWithColorPrimaries:title.hb_title->color_prim]; + CGColorSpaceRef colorSpace = [self copyColorSpaceWithPrimaries:title.hb_title->color_prim + transfer:title.hb_title->color_transfer + matrix:title.hb_title->color_matrix]; img = CGImageCreate(image->width, image->height, |