The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
new SDL_image on MacOSX loads PNG different than earlier
albert


Joined: 22 Oct 2009
Posts: 29
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?
new SDL_image on MacOSX loads PNG different than earlier
Eric Wing
Guest

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:
Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
albert


Joined: 22 Oct 2009
Posts: 29
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

@Sam: Can you apply this?
new SDL_image on MacOSX loads PNG different than earlier
Vittorio Giovara
Guest

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 Smile
Vittorio

On Mon, Dec 26, 2011 at 12:37 PM, albert wrote:
Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: new SDL_image on MacOSX loads PNG different than earlier
albert


Joined: 22 Oct 2009
Posts: 29
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 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.
new SDL_image on MacOSX loads PNG different than earlier
Vittorio Giovara
Guest

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

Vittorio

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



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 [img][/img]
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: new SDL_image on MacOSX loads PNG different than earlier
albert


Joined: 22 Oct 2009
Posts: 29
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
new SDL_image on MacOSX loads PNG different than earlier
Sam Lantinga


Joined: 10 Sep 2009
Posts: 1765
Fixed, thanks! Smilehttp://hg.libsdl.org/SDL_image/rev/5953114c0d27


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:
Quote:



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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org