Skip to content

Commit 97e7217

Browse files
committed
Fixed colorspace for ImageIO loading
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
1 parent d98a4dc commit 97e7217

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

IMG_ImageIO.m

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,25 @@ static CFDictionaryRef CreateHintDictionary(CFStringRef uti_string_hint)
212212

213213
CGContextRef bitmap_context;
214214
CGBitmapInfo bitmap_info;
215-
CGColorSpaceRef color_space = CGColorSpaceCreateDeviceRGB();
216-
215+
216+
/* This sets up a color space that results in identical values
217+
* as the image data itself, which is the same as the standalone
218+
* libpng loader.
219+
* Thanks to Allegro. :)
220+
*/
221+
CGFloat whitePoint[3] = { 1, 1, 1 };
222+
CGFloat blackPoint[3] = { 0, 0, 0 };
223+
CGFloat gamma[3] = { 2.2, 2.2, 2.2 };
224+
CGFloat matrix[9] = {
225+
1, 1, 1,
226+
1, 1, 1,
227+
1, 1, 1
228+
};
229+
CGColorSpaceRef color_space =
230+
CGColorSpaceCreateCalibratedRGB(
231+
whitePoint, blackPoint, gamma, matrix
232+
);
233+
217234
if (alpha == kCGImageAlphaNone ||
218235
alpha == kCGImageAlphaNoneSkipFirst ||
219236
alpha == kCGImageAlphaNoneSkipLast) {

0 commit comments

Comments
 (0)