diff options
author | Damiano Galassi <[email protected]> | 2020-10-02 10:03:14 +0200 |
---|---|---|
committer | Damiano Galassi <[email protected]> | 2020-10-02 10:03:14 +0200 |
commit | 7efa7b80a2bd91ce4a64ac68ce8a8c40c6d2d4d5 (patch) | |
tree | dbdea7615f65196d3ba0e67c54e9dabfe739e82e /macosx | |
parent | 8ab3a7da2004643da5a3204b0f947d467e65b067 (diff) |
MacGui: map more transfer functions to CGColorSpaceRef, simplify copyImageAtIndex: method.
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/HBCore.h | 4 | ||||
-rw-r--r-- | macosx/HBCore.m | 8 | ||||
-rw-r--r-- | macosx/HBImageUtilities.m | 67 | ||||
-rw-r--r-- | macosx/HBPreviewGenerator.m | 8 |
4 files changed, 54 insertions, 33 deletions
diff --git a/macosx/HBCore.h b/macosx/HBCore.h index 3d1160161..5d27a20a1 100644 --- a/macosx/HBCore.h +++ b/macosx/HBCore.h @@ -186,9 +186,7 @@ typedef void (^HBCoreCompletionHandler)(HBCoreResult result); - (nullable CGImageRef)copyImageAtIndex:(NSUInteger)index forTitle:(HBTitle *)title pictureFrame:(HBPicture *)frame - deinterlace:(BOOL)deinterlace - rotate:(int)angle - flipped:(BOOL)flipped CF_RETURNS_RETAINED; + deinterlace:(BOOL)deinterlace CF_RETURNS_RETAINED; /** * Returns the counts of the available previews images. diff --git a/macosx/HBCore.m b/macosx/HBCore.m index 49b73ebe7..5f41289ef 100644 --- a/macosx/HBCore.m +++ b/macosx/HBCore.m @@ -334,9 +334,7 @@ typedef void (^HBCoreCleanupHandler)(void); - (CGImageRef)copyImageAtIndex:(NSUInteger)index forTitle:(HBTitle *)title pictureFrame:(HBPicture *)frame - deinterlace:(BOOL)deinterlace - rotate:(int)angle - flipped:(BOOL)flipped CF_RETURNS_RETAINED + deinterlace:(BOOL)deinterlace CF_RETURNS_RETAINED { CGImageRef img = NULL; @@ -401,9 +399,9 @@ typedef void (^HBCoreCleanupHandler)(void); hb_image_close(&image); } - if (img && (angle || flipped)) + if (img && (frame.rotate || frame.flip)) { - CGImageRef rotatedImg = CGImageRotated(img, angle, flipped); + CGImageRef rotatedImg = CGImageRotated(img, frame.rotate, frame.flip); CGImageRelease(img); return rotatedImg; } diff --git a/macosx/HBImageUtilities.m b/macosx/HBImageUtilities.m index 0d3d580c4..da9a044d3 100644 --- a/macosx/HBImageUtilities.m +++ b/macosx/HBImageUtilities.m @@ -113,79 +113,108 @@ CGImageRef CGImageRotated(CGImageRef imgRef, CGFloat angle, BOOL flipped) CF_RET CGColorSpaceRef copyColorSpace(int primaries, int transfer, int matrix) { - CFStringRef primariesKey = NULL; + CFStringRef primariesValue = NULL; switch (primaries) { case HB_COLR_PRI_EBUTECH: - primariesKey = kCVImageBufferColorPrimaries_EBU_3213; + primariesValue = kCVImageBufferColorPrimaries_EBU_3213; break; case HB_COLR_PRI_SMPTEC: - primariesKey = kCVImageBufferColorPrimaries_SMPTE_C; + primariesValue = kCVImageBufferColorPrimaries_SMPTE_C; break; case HB_COLR_PRI_BT2020: - primariesKey = kCVImageBufferColorPrimaries_ITU_R_2020; + primariesValue = kCVImageBufferColorPrimaries_ITU_R_2020; break; case HB_COLR_PRI_BT709: default: - primariesKey = kCVImageBufferColorPrimaries_ITU_R_709_2; + primariesValue = kCVImageBufferColorPrimaries_ITU_R_709_2; } - CFStringRef transferKey = NULL; + CFStringRef transferValue = NULL; + CFNumberRef gammaValue = NULL; switch (transfer) { + case HB_COLR_TRA_GAMMA22: + { + transferValue = kCVImageBufferTransferFunction_UseGamma; + Float32 gamma = 2.2; + gammaValue = CFNumberCreate(NULL, kCFNumberFloat32Type, &gamma); + break; + } + + case HB_COLR_TRA_GAMMA28: + { + transferValue = kCVImageBufferTransferFunction_UseGamma; + Float32 gamma = 2.8; + gammaValue = CFNumberCreate(NULL, kCFNumberFloat32Type, &gamma); + break; + } + case HB_COLR_TRA_SMPTE240M: - transferKey = kCVImageBufferTransferFunction_SMPTE_240M_1995; + transferValue = kCVImageBufferTransferFunction_SMPTE_240M_1995; + break; + + case HB_COLR_TRA_LINEAR: + if (@available(macOS 10.14, *)) { + transferValue = kCVImageBufferTransferFunction_Linear; break; + } case HB_COLR_TRA_BT2020_10: case HB_COLR_TRA_BT2020_12: - transferKey = kCVImageBufferTransferFunction_ITU_R_2020; + transferValue = kCVImageBufferTransferFunction_ITU_R_2020; break; case HB_COLR_TRA_SMPTEST2084: if (@available(macOS 10.13, *)) { - transferKey = kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ; + transferValue = kCVImageBufferTransferFunction_SMPTE_ST_2084_PQ; break; } case HB_COLR_TRA_ARIB_STD_B67: if (@available(macOS 10.13, *)) { - transferKey = kCVImageBufferTransferFunction_ITU_R_2100_HLG; + transferValue = kCVImageBufferTransferFunction_ITU_R_2100_HLG; + break; + } + + case HB_COLR_TRA_SMPTE428: + if (@available(macOS 10.12, *)) { + transferValue = kCVImageBufferTransferFunction_SMPTE_ST_428_1; break; } case HB_COLR_TRA_BT709: default: - transferKey = kCVImageBufferTransferFunction_ITU_R_709_2; + transferValue = kCVImageBufferTransferFunction_ITU_R_709_2; } - CFStringRef matrixKey = NULL; + CFStringRef matrixValue = NULL; switch (matrix) { case HB_COLR_MAT_SMPTE170M: - matrixKey = kCVImageBufferYCbCrMatrix_ITU_R_601_4; + matrixValue = kCVImageBufferYCbCrMatrix_ITU_R_601_4; break; case HB_COLR_MAT_SMPTE240M: - matrixKey = kCVImageBufferYCbCrMatrix_SMPTE_240M_1995; + matrixValue = kCVImageBufferYCbCrMatrix_SMPTE_240M_1995; break; case HB_COLR_MAT_BT2020_NCL: case HB_COLR_MAT_BT2020_CL: - matrixKey = kCVImageBufferYCbCrMatrix_ITU_R_2020; + matrixValue = kCVImageBufferYCbCrMatrix_ITU_R_2020; break; case HB_COLR_MAT_BT709: default: - matrixKey = kCVImageBufferYCbCrMatrix_ITU_R_709_2;; + matrixValue = 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); + const void *keys[4] = { kCVImageBufferColorPrimariesKey, kCVImageBufferTransferFunctionKey, kCVImageBufferYCbCrMatrixKey, kCVImageBufferGammaLevelKey }; + const void *values[4] = { primariesValue, transferValue, matrixValue, gammaValue}; + CFDictionaryRef attachments = CFDictionaryCreate(NULL, keys, values, 4, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); CGColorSpaceRef colorSpace = CVImageBufferCreateColorSpaceFromAttachments(attachments); CFRelease(attachments); diff --git a/macosx/HBPreviewGenerator.m b/macosx/HBPreviewGenerator.m index 35620ea49..0e5b2b0e9 100644 --- a/macosx/HBPreviewGenerator.m +++ b/macosx/HBPreviewGenerator.m @@ -98,9 +98,7 @@ theImage = (CGImageRef)[self.scanCore copyImageAtIndex:index forTitle:self.job.title pictureFrame:self.job.picture - deinterlace:deinterlace - rotate:self.job.picture.rotate - flipped:self.job.picture.flip]; + deinterlace:deinterlace]; if (cache && theImage) { // The cost is the number of pixels of the image @@ -193,9 +191,7 @@ image = (CGImageRef)[self.scanCore copyImageAtIndex:index forTitle:self.job.title pictureFrame:self.job.picture - deinterlace:NO - rotate:self.job.picture.rotate - flipped:self.job.picture.flip]; + deinterlace:NO]; CFAutorelease(image); } |