2

I have terrain data stored as 16-bit png files. I would like to apply a color table that maps the height to a color to be drawn on the map. (Yes, I realize that the table would have 65536 entries).

Is there support for this in Android, or am I going to have to convert the data to RGB when it's loaded? Or find a version of libpng for Android? Or build my own?

Edit: Correct; there's no color table in the png files; I'm generating it in software when I load the images.

I guess a better way to phrase my question is this: Is there any way to map a bitmap of 16-bit integers through a lookup table in order to generate a new RGB bitmap? Or do I need to roll my own?

Edward Falk
  • 9,991
  • 11
  • 77
  • 112
  • FWIW, I did find https://github.com/julienr/libpng-android – Edward Falk Oct 17 '12 at 19:08
  • 1
    Does [this answer](http://stackoverflow.com/a/10673220/752320) work for you? You can extract the value from the unpacked pixel color by bit-shifting. – Geobits Oct 17 '12 at 19:18
  • 1
    As far as I know there's no such thing as 16-bit indexed png, an indexed png is max 8-bit (256 colors). I guess you mean 16-bit grayscale (1 channel) png, but it has no colormap, so you have to convert the image anyway. – pmoleri Oct 17 '12 at 19:44
  • Geobits -- yes, that answer was the first thing I found when I searched for it. I was hoping for something faster than rolling my own loops. – Edward Falk Oct 17 '12 at 22:18

1 Answers1

1

There is no 16-bit indexed PNG format, hence I guess that what you are trying to do is to load a 16-bit grayscale PNG and display it in pseudocolor with a 64Kb color table. This practically means that you need to do a 16-bit-gray to 24bit RGB conversion (or perhaps RGB_565) . That has little to do with PNG specifically, so "find a version of libpng for Android" would not help much, you still need to do the conversion yourself (after PNG decoding). If your concern is to do the conversion wasting less memory, I suggest you take a look at my PNGJ library.

leonbloy
  • 73,180
  • 20
  • 142
  • 190
  • Ahhh, you're probably right. For some reason, I thought libpng had a way to apply a color table to 16-bit data. – Edward Falk Oct 17 '12 at 22:16
  • p.s. I just looked at your code; nice work. I'm more interested in performance issues than space, but I might be able to make use of it. – Edward Falk Oct 17 '12 at 22:21