I'm trying to convert an NSImage to have a a gamma of 1.8 and I'm not having much luck. I've found some code but nothing that's working. I've got a method that returns an NSBitmapImageRep on an NSImage category.
First I tried changing the color space with a CGColorSpaceCreateCalibratedRGB function I found online, but this had no effect:
- (NSBitmapImageRep *)OnePointEightBitmapImageRep{
CGColorSpaceRef colorSpace = CGColorSpaceCreateCalibratedRGB(
(CGFloat[3]){0.9505, 1.0000, 1.0891},//white point
(CGFloat[3]){0.0000, 0.0000, 0.0000},//black point
(CGFloat[3]){1.8010, 1.8010, 1.8010},//gamma rgb
(CGFloat[9]){0.4543, 0.2426, 0.0148, 0.3533, 0.6744, 0.0904, 0.1566, 0.0834, 0.7195} //rgb tristimulus
);
CGImageRef imageRef = CGImageCreateCopyWithColorSpace([self CGImage], colorSpace);
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithCGImage:imageRef];
CGColorSpaceRelease(colorSpace);
CGImageRelease(imageRef);
return bitmap;
}
- (CGImageRef)CGImage{
return [self CGImageForProposedRect:nil context:nil hints:nil];
}
Next I tried setting the gamma on the bitmap image properties:
- (NSBitmapImageRep *)OnePointEightBitmapImageRep{
NSBitmapImageRep *bitmap = [[NSBitmapImageRep alloc] initWithCGImage:[self CGImage]];
NSLog(@"gamma: %@", [bitmap valueForProperty:NSImageGamma]);
[bitmap setProperty:NSImageGamma withValue:[NSNumber numberWithDouble:1.8f]];
NSLog(@"gamma: %@", [bitmap valueForProperty:NSImageGamma]);
return bitmap;
}
This set the property but had no effect on the output image.
Is there a way to do this?