summaryrefslogtreecommitdiffstats
path: root/macosx
diff options
context:
space:
mode:
authorDamiano Galassi <[email protected]>2016-11-10 20:57:11 +0100
committerDamiano Galassi <[email protected]>2016-11-10 20:57:11 +0100
commitc472f5617f15c890c3f84e90866bca99503b6e50 (patch)
tree922bc3f3f1155a760e1effabf85febc05d4c29c5 /macosx
parent9c77f245dcb44f68ac5d7a7a632ec042d995c117 (diff)
MacGui: set the appropriate colorspace for preview images, and use a gamma value of ~1.96, same as Apple media frameworks.
Diffstat (limited to 'macosx')
-rw-r--r--macosx/HBCore.m44
1 files changed, 41 insertions, 3 deletions
diff --git a/macosx/HBCore.m b/macosx/HBCore.m
index eae767060..a0f3e5811 100644
--- a/macosx/HBCore.m
+++ b/macosx/HBCore.m
@@ -284,7 +284,7 @@ static void hb_error_handler(const char *errmsg)
CGAffineTransform transform = CGAffineTransformMakeRotation(angleInRadians);
CGRect rotatedRect = CGRectApplyAffineTransform(imgRect, transform);
- CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+ CGColorSpaceRef colorSpace = CGImageGetColorSpace(imgRef);
CGContextRef bmContext = CGBitmapContextCreate(NULL,
(size_t)rotatedRect.size.width,
(size_t)rotatedRect.size.height,
@@ -294,7 +294,6 @@ static void hb_error_handler(const char *errmsg)
kCGImageAlphaPremultipliedFirst);
CGContextSetAllowsAntialiasing(bmContext, FALSE);
CGContextSetInterpolationQuality(bmContext, kCGInterpolationNone);
- CGColorSpaceRelease(colorSpace);
// Rotate
CGContextTranslateCTM(bmContext,
@@ -325,6 +324,44 @@ static void hb_error_handler(const char *errmsg)
return rotatedImage;
}
+- (CGColorSpaceRef)copyColorSpaceWithColorPrimaries:(int)colorPrimaries
+{
+ const CGFloat whitePoint[] = {0.95047, 1.0, 1.08883};
+ const CGFloat blackPoint[] = {0, 0, 0};
+
+ // See https://developer.apple.com/library/content/technotes/tn2257/_index.html
+ const CGFloat gamma[] = {1.961, 1.961, 1.961};
+
+ // RGB/XYZ Matrices (D65 white point)
+ switch (colorPrimaries) {
+ case HB_COLR_PRI_EBUTECH:
+ {
+ // Rec. 601, 625 line
+ const CGFloat matrix[] = {0.4305538, 0.2220043, 0.0201822,
+ 0.3415498, 0.7066548, 0.1295534,
+ 0.1783523, 0.0713409, 0.9393222};
+ return CGColorSpaceCreateCalibratedRGB(whitePoint, blackPoint, gamma, matrix);
+ }
+ case HB_COLR_PRI_SMPTEC:
+ {
+ // Rec. 601, 525 line
+ const CGFloat matrix[] = {0.3935209, 0.2123764, 0.0187391,
+ 0.3652581, 0.7010599, 0.1119339,
+ 0.1916769, 0.0865638, 0.9583847};
+ return CGColorSpaceCreateCalibratedRGB(whitePoint, blackPoint, gamma, matrix);
+ }
+ case HB_COLR_PRI_BT709:
+ default:
+ {
+ // Rec. 709
+ const CGFloat matrix[] = {0.4124564, 0.2126729, 0.0193339,
+ 0.3575761, 0.7151522, 0.1191920,
+ 0.1804375, 0.0721750, 0.9503041};
+ return CGColorSpaceCreateCalibratedRGB(whitePoint, blackPoint, gamma, matrix);
+ }
+ }
+}
+
- (CGImageRef)copyImageAtIndex:(NSUInteger)index
forTitle:(HBTitle *)title
pictureFrame:(HBPicture *)frame
@@ -354,7 +391,8 @@ static void hb_error_handler(const char *errmsg)
CGBitmapInfo bitmapInfo = kCGBitmapByteOrderDefault | kCGImageAlphaNone;
CFMutableDataRef imgData = CFDataCreateMutable(kCFAllocatorDefault, 3 * image->width * image->height);
CGDataProviderRef provider = CGDataProviderCreateWithCFData(imgData);
- CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+ CGColorSpaceRef colorSpace = [self copyColorSpaceWithColorPrimaries:title.hb_title->color_prim];
+
img = CGImageCreate(image->width,
image->height,
8,