Skip to content

Instantly share code, notes, and snippets.

@albertz
Created January 2, 2012 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albertz/1551404 to your computer and use it in GitHub Desktop.
Save albertz/1551404 to your computer and use it in GitHub Desktop.
SDL_image ImageIO color space fix
diff -r 5e26e77b30bf IMG_ImageIO.m
--- a/IMG_ImageIO.m Sat Dec 31 13:34:24 2011 -0500
+++ b/IMG_ImageIO.m Mon Jan 02 18:10:20 2012 +0100
@@ -212,8 +212,25 @@
CGContextRef bitmap_context;
CGBitmapInfo bitmap_info;
- CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
-
+
+ /* This sets up a color space that results in identical values
+ * as the image data itself, which is the same as the standalone
+ * libpng loader.
+ * Thanks to Allegro. :)
+ */
+ CGFloat whitePoint[3] = { 1, 1, 1 };
+ CGFloat blackPoint[3] = { 0, 0, 0 };
+ CGFloat gamma[3] = { 2.2, 2.2, 2.2 };
+ CGFloat matrix[9] = {
+ 1, 1, 1,
+ 1, 1, 1,
+ 1, 1, 1
+ };
+ CGColorSpaceRef color_space =
+ CGColorSpaceCreateCalibratedRGB(
+ whitePoint, blackPoint, gamma, matrix
+ );
+
if (alpha == kCGImageAlphaNone ||
alpha == kCGImageAlphaNoneSkipFirst ||
alpha == kCGImageAlphaNoneSkipLast) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment