We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 1413

Summary: Cannot load images with ImageIO enabled on Mac OS X
Product: SDL_image Reporter: toukoaozaki
Component: miscAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: gabomdq, sdl
Version: unspecified   
Hardware: x86   
OS: Mac OS X 10.5 (Intel)   
Attachments: Test source/script, input image file and my result
Screenshot of SDLInvaders showing image corruption towards bottom of sprites.
Fix that can apply to changeset 292 and later.

Description toukoaozaki 2012-02-06 19:38:31 UTC
I was writing a simple image viewer with SDL. Everything was fine, until I switched to SDL_Image for image loading. The surface I was getting was of correct size, but all pixels were simply black (0,0,0,255).

I tried to compile from source, still no joy. showimage utility wasn't working either.

I started to debug with gdb. When I stepped into SDL_Image routines, I found it uses whatever ImageIO gives back: with that black SDL_Surface.

Since ImageIO routines were suspicious, I just configured with '--enable-imageio=no' to use default SDL backend.
Finally it works. I'm not sure which one is faulty, though. I'm filing this because someone might encounter this as well, unless it's something wrong only on my mac.
Comment 1 toukoaozaki 2012-02-06 19:39:39 UTC
ADDED: SDL_image version is 1.2.12.
Comment 2 toukoaozaki 2012-02-06 19:40:23 UTC
(In reply to comment #1)
Sorry for confusion. The version is actually 1.2.15.
Comment 3 Sam Lantinga 2012-02-07 16:06:32 UTC
I built SDL_image with ImageIO and tested it on all the images I have here and didn't have any problems.
Can you post a link to an image that doesn't work?

Thanks!
Comment 4 toukoaozaki 2012-02-07 18:17:06 UTC
Created attachment 817 [details]
Test source/script, input image file and my result

I'm attaching a test program and script with input image file.
I have MacPorts version (with ImageIO) in /opt/local/lib, and source-compiled version without ImageIO in /usr/local/lib.
wo_imageio.txt is the result when linked against the library in /usr/local/lib, and w_imageio.txt is the result when linked against the library in /opt/local/lib. The result was the same for the source compiled version before I manually disabled ImageIO through configure.

This is weird, if this is happening only to me. What would be a possible cause?
Comment 5 Gabriel Jacobo 2012-02-27 08:24:48 UTC
I tested image loading with ImageIO last week with the latest SDL_image and OS X 10.7, it worked fine for PNG files at least.
Comment 6 Mark Scott 2012-12-31 06:19:11 UTC
I can confirm this bug exists - MacOSX 10.5.8; XCode 3.1.4;

All SDL based games I've tried are impacted (widelands, SDLInvaders). I've seen both black images and image corruption. For example, the splash screen of SDLInvaders is black, and in-game it has corrupt graphics (see attachment)

I have traced the problem to be starting when changeset 292 was applied to the SDL_image library (changeset 289 works; 290 & 291 are not code updates) - so this is first seen with SDL_image 1.2.11. SDL_image 1.2.12 is also affected.

http://hg.libsdl.org/SDL_image/rev/5953114c0d27

I have a MacPorts issue open for downstream visibility: https://trac.macports.org/ticket/37453


Workaround: compile SDL_image with --disable-imageio.


Let me know if there's anything I can help check, though ImageIO is not an area I'm familiar with.
Comment 7 Mark Scott 2012-12-31 06:20:13 UTC
Created attachment 1003 [details]
Screenshot of SDLInvaders showing image corruption towards bottom of sprites.
Comment 8 Mark Scott 2012-12-31 14:54:27 UTC
Created attachment 1005 [details]
Fix that can apply to changeset 292 and later.

The attached diff fixes the library so ImageIO can be used and images are displayed again without corruption and black screens.

(Based on http://pastebin.com/T3s15UXF and http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html)

I suspect the matrix passed to CGColorSpaceCreateCalibratedRGB() as implemented in r292 is invalid and the CoreGraphics framework on 10.5 doesn't reject it, but later ones do. Unfortunately all the documentation I can find doesn't actually specify what the valid range of values of the arguments is.
Comment 9 Sam Lantinga 2013-01-01 11:41:33 UTC
Fixed, thanks!
http://hg.libsdl.org/SDL_image/rev/3999783ed889
Comment 10 Sam Lantinga 2013-01-01 11:41:37 UTC
Fixed, thanks!
http://hg.libsdl.org/SDL_image/rev/3999783ed889