Paletted / Indexed PNG as Textures, with <= 16 Colors, Fail

Anything about development not directly related to libgdx, e.g. OpenGL, Android APIs etc.

Paletted / Indexed PNG as Textures, with <= 16 Colors, Fail

Postby joecks » Mon Jun 25, 2012 2:06 pm

I described an issue in the bugtracker http://code.google.com/p/libgdx/issues/detail?id=895, where loading a PNG texture with less then 17 indexed colors is failing, 17+ colors works perfectly. Could that be related to the Pixmap Constructor JavaDoc entry, which says that "Paletted formats are not supported":

Code: Select all
/** Creates a new Pixmap instance from the given file. The file must be a Png, Jpeg or Bitmap. Paletted formats are not
    * supported.
    *
    * @param file the {@link FileHandle} */


So could I switch to the alternative constructor, which is taking a different offset, and so fix this issue?

Alternative Constructor:
Code: Select all
/** Creates a new Pixmap instance from the given encoded image data. The image can be encoded as JPEG, PNG or BMP.
    * @param encodedData the encoded image data
    * @param offset the offset
    * @param len the length */
   public Pixmap (byte[] encodedData, int offset, int len) {
      try {
         pixmap = new Gdx2DPixmap(encodedData, offset, len, 0);
      } catch (IOException e) {
         throw new GdxRuntimeException("Couldn't load pixmap from image data", e);
      }
   }
joecks
 
Posts: 5
Joined: Mon Jun 25, 2012 1:23 pm

Re: Paletted / Indexed PNG as Textures, with <= 16 Colors, F

Postby mzechner » Wed Jun 27, 2012 7:08 am

We use stb_image for image loading. That library does not support indexed PNGs and due to that, neither can we. One solution would be to wrap libpng, but i'm afraid i lack the time to do that at the moment :/
mzechner
Site Admin
 
Posts: 4715
Joined: Sat Jul 10, 2010 3:50 pm

Re: Paletted / Indexed PNG as Textures, with <= 16 Colors, F

Postby joecks » Wed Jun 27, 2012 12:29 pm

Interesting. But how does that correspond to my observation with less then 17 Colors. Loading 17+ palatted / indexed PNGs works perfectly, below that number loading crashes! :?:
joecks
 
Posts: 5
Joined: Mon Jun 25, 2012 1:23 pm

Re: Paletted / Indexed PNG as Textures, with <= 16 Colors, F

Postby mzechner » Fri Jun 29, 2012 12:52 pm

Good question, for that we'd have to look into stb_image's PNG decoder. To be frank, i have no idea why it would behave like this, the docs state that paletted PNGs aren't supported, so i'm puzzled that it returns anything for +16 color paletted PNGs.
mzechner
Site Admin
 
Posts: 4715
Joined: Sat Jul 10, 2010 3:50 pm


Return to General Development

Who is online

Users browsing this forum: No registered users and 1 guest