New SDL_image on MacOSX loads PNG different than earlier

This is the png:

The code for checking is basically:

Code:

void DumpPixelFormat(const SDL_PixelFormat* format) {
std::ostringstream str;
str << “PixelFormat:” << std::endl
<< " BitsPerPixel: " << (int)format->BitsPerPixel << “,”
<< " BytesPerPixel: " << (int)format->BytesPerPixel << std::endl
<< " R/G/B/A mask: " << std::hex
<< (uint)format->Rmask << “/”
<< (uint)format->Gmask << “/”
<< (uint)format->Bmask << “/”
<< (uint)format->Amask << std::endl
<< " R/G/B/A loss: "
<< (uint)format->Rloss << “/”
<< (uint)format->Gloss << “/”
<< (uint)format->Bloss << “/”
<< (uint)format->Aloss << std::endl
<< " Colorkey: " << std::hex << (uint)format->colorkey << “,”
<< " Alpha: " << std::dec << (int)format->alpha;
cout << str.str() << endl;
}

void DumpSurface(SDL_Surface* s) {
DumpPixelFormat(s->format);
for(int y = 0; y < MIN(10, s->h); ++y) {
for(int x = 0; x < MIN(10, s->w); ++x)
printf(" %.8X", GetPixel(s, x, y));
printf("\n");
}
}

void load() {
SDL_Surface* img= IMG_Load(“font.png”);
DumpSurface(img);
}

And this is the output:

Code:

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
00000000 00000000 00000000 00000000 FF1514F4 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 18000000 ED000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 18000000 ED000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 18000000 ED000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 18000000 ED000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 18000000 ED000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 00000000 00000000 00000000 00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 00000000 00000000 00000000 00000000 00000000

Earlier, the value FF1514F4 has been FF0000FF. Gimp also shows FF0000FF at this place. Seashore and other applications show FF1514F4. When I load the image via libgd, I also get FF0000FF.

This might be an issue in ImageIO. Or maybe some color profile thingie.

Any idea?

This has been discussed before on the list. Check the archives,
specifically for a thread called “Pixel bug in Mac OS X”. I posted
some code I wanted people to test at the end of the thread, but nobody
ever got back to me with results.

-Eric–
Beginning iPhone Games Development
http://playcontrol.net/iphonegamebook/

On 12/26/11, albert wrote:

This is the png:
https://github.com/albertz/openlierox/raw/0.59/share/gamedir/data/gfx/font.png

The code for checking is basically:

Code:

void DumpPixelFormat(const SDL_PixelFormat* format) {
std::ostringstream str;
str << “PixelFormat:” << std::endl
<< " BitsPerPixel: " << (int)format->BitsPerPixel << “,”
<< " BytesPerPixel: " << (int)format->BytesPerPixel << std::endl
<< " R/G/B/A mask: " << std::hex
<< (uint)format->Rmask << “/”
<< (uint)format->Gmask << “/”
<< (uint)format->Bmask << “/”
<< (uint)format->Amask << std::endl
<< " R/G/B/A loss: "
<< (uint)format->Rloss << “/”
<< (uint)format->Gloss << “/”
<< (uint)format->Bloss << “/”
<< (uint)format->Aloss << std::endl
<< " Colorkey: " << std::hex << (uint)format->colorkey << “,”
<< " Alpha: " << std::dec << (int)format->alpha;
cout << str.str() << endl;
}

void DumpSurface(SDL_Surface* s) {
DumpPixelFormat(s->format);
for(int y = 0; y < MIN(10, s->h); ++y) {
for(int x = 0; x < MIN(10, s->w); ++x)
printf(" %.8X", GetPixel(s, x, y));
printf("\n");
}
}

void load() {
SDL_Surface* img= IMG_Load(“font.png”);
DumpSurface(img);
}

And this is the output:

Code:

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
00000000 00000000 00000000 00000000 FF1514F4 00000000 00000000 00000000
00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 00000000 00000000 00000000
00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 00000000 00000000 00000000
00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 18000000 ED000000 00000000
00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 18000000 ED000000 00000000
00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 18000000 ED000000 00000000
00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 18000000 ED000000 00000000
00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 18000000 ED000000 00000000
00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 00000000 00000000 00000000
00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 00000000 00000000 00000000
00000000 00000000

Earlier, the value FF1514F4 has been FF0000FF. Gimp also shows FF0000FF at
this place. Seashore and other applications show FF1514F4. When I load the
image via libgd, I also get FF0000FF.

This might be an issue in ImageIO. Or maybe some color profile thingie.

Any idea?

IIRC, this is because using imageio requires to have the alpha channel
premultiplied.
The fix proposed did this, but negleted byte precision information: see
http://bugzilla.libsdl.org/show_bug.cgi?id=868
If you ever try out Eric’s changes do let us know :slight_smile:
VittorioOn Mon, Dec 26, 2011 at 12:37 PM, albert wrote:

**
This is the png:

https://github.com/albertz/openlierox/raw/0.59/share/gamedir/data/gfx/font.png

The code for checking is basically:

Code:

void DumpPixelFormat(const SDL_PixelFormat* format) {
std::ostringstream str;
str << “PixelFormat:” << std::endl
<< " BitsPerPixel: " << (int)format->BitsPerPixel << “,”
<< " BytesPerPixel: " << (int)format->BytesPerPixel << std::endl
<< " R/G/B/A mask: " << std::hex
<< (uint)format->Rmask << “/”
<< (uint)format->Gmask << “/”
<< (uint)format->Bmask << “/”
<< (uint)format->Amask << std::endl
<< " R/G/B/A loss: "
<< (uint)format->Rloss << “/”
<< (uint)format->Gloss << “/”
<< (uint)format->Bloss << “/”
<< (uint)format->Aloss << std::endl
<< " Colorkey: " << std::hex << (uint)format->colorkey << “,”
<< " Alpha: " << std::dec << (int)format->alpha;
cout << str.str() << endl;
}

void DumpSurface(SDL_Surface* s) {
DumpPixelFormat(s->format);
for(int y = 0; y < MIN(10, s->h); ++y) {
for(int x = 0; x < MIN(10, s->w); ++x)
printf(" %.8X", GetPixel(s, x, y));
printf("\n");
}
}

void load() {
SDL_Surface* img= IMG_Load(“font.png”);
DumpSurface(img);
}

And this is the output:

Code:

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
00000000 00000000 00000000 00000000 FF1514F4 00000000 00000000 00000000
00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 00000000 00000000 00000000
00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 00000000 00000000 00000000
00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 18000000 ED000000 00000000
00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 18000000 ED000000 00000000
00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 18000000 ED000000 00000000
00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 18000000 ED000000 00000000
00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 18000000 ED000000 00000000
00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 00000000 00000000 00000000
00000000 00000000
00000000 00000000 00000000 00000000 FF1514F4 00000000 00000000 00000000
00000000 00000000

Earlier, the value FF1514F4 has been FF0000FF. Gimp also shows FF0000FF at
this place. Seashore and other applications show FF1514F4. When I load the
image via libgd, I also get FF0000FF.

This might be an issue in ImageIO. Or maybe some color profile thingie.

Any idea?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Vittorio Giovara wrote:

IIRC, this is because using imageio requires to have the alpha channel premultiplied.
The fix proposed did this, but negleted byte precision information: see http://bugzilla.libsdl.org/show_bug.cgi?id=868 (http://bugzilla.libsdl.org/show_bug.cgi?id=868)
If you ever try out Eric’s changes do let us know :slight_smile:
Vittorio

This is not premultiplied alpha as you can see from the output. The alpha channel is always 0xff.

This is because the color space/profile is device dependent. That is always with CGColorSpaceCreateDeviceRGB. See here: http://developer.apple.com/library/mac/documentation/graphicsimaging/reference/CGColorSpace/Reference/reference.html#//apple_ref/c/func/CGColorSpaceCreateDeviceRGB

And my patch makes the color space device independent so that it doesn’t change it.

Ops, my mistake, hadn’t realized alpha was always 0xff
Which patch are you talking about thought?

VittorioOn Wed, Jan 4, 2012 at 12:51 AM, albert wrote:

**

Vittorio Giovara wrote:

IIRC, this is because using imageio requires to have the alpha channel
premultiplied.
The fix proposed did this, but negleted byte precision information: see
http://bugzilla.libsdl.org/show_bug.cgi?id=868
If you ever try out Eric’s changes do let us know [image: Smile]
Vittorio

This is not premultiplied alpha as you can see from the output. The alpha
channel is always 0xff.

This is because the color space/profile is device dependent. That is
always with CGColorSpaceCreateDeviceRGB. See here:
http://developer.apple.com/library/mac/documentation/graphicsimaging/reference/CGColorSpace/Reference/reference.html#//apple_ref/c/func/CGColorSpaceCreateDeviceRGB

And my patch makes the color space device independent so that it doesn’t
change it.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Vittorio Giovara wrote:

Ops, my mistake, hadn’t realized alpha was always 0xff
Which patch are you talking about thought?

This one: https://gist.github.com/1551404

From here (with some more details):
http://forums.libsdl.org/viewtopic.php?p=31258#31258

Fixed, thanks! :slight_smile:

I appreciate you finding that, people have been asking about that for a
while.On Tue, Jan 3, 2012 at 7:50 PM, albert wrote:

**

Vittorio Giovara wrote:

Ops, my mistake, hadn’t realized alpha was always 0xff
Which patch are you talking about thought?

This one: https://gist.github.com/1551404

From here (with some more details):
http://forums.libsdl.org/viewtopic.php?p=31258#31258


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org