Skip to content

Commit

Permalink
Fixed colorspace for ImageIO loading
Browse files Browse the repository at this point in the history
albert

Test case: https://gist.github.com/1551241

It should output:

Code:
$ ./sdlimagetest
PixelFormat:  BitsPerPixel: 32,  BytesPerPixel: 4
  R/G/B/A mask: ff0000/ff00/ff/ff000000
  R/G/B/A loss: 0/0/0/0
  Colorkey: 0,  Alpha: 255
 FF0000FF
 FF0000FF
 FF0000FF
 FF0000FF
 FF0000FF
 FF0000FF
 FF0000FF
 FF0000FF
 FF0000FF
 FF0000FF


Output with bad SDL_image:

Code:

$ ./sdlimagetest
PixelFormat:
  BitsPerPixel: 32,  BytesPerPixel: 4
  R/G/B/A mask: ff0000/ff00/ff/ff000000
  R/G/B/A loss: 0/0/0/0
  Colorkey: 0,  Alpha: 255
 FF1514F4
 FF1514F4
 FF1514F4
 FF1514F4
 FF1514F4
 FF1514F4
 FF1514F4
 FF1514F4
 FF1514F4
 FF1514F4


And I searched a bit around and I found a fix in the Allegro code (http://codesearch.google.com/#w3aXj_apqFs/allegro/tags/5.0.0/addons/image/macosx.m&ct=rc&cd=3&q=CGColorSpaceCreateCalibratedRGB).

So I wrote a patch for SDL_image: https://gist.github.com/1551404
  • Loading branch information
slouken committed Jan 4, 2012
1 parent d98a4dc commit 97e7217
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions IMG_ImageIO.m
Expand Up @@ -212,8 +212,25 @@ static CFDictionaryRef CreateHintDictionary(CFStringRef uti_string_hint)

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) {
Expand Down

0 comments on commit 97e7217

Please sign in to comment.