0

I have a PNG-Image with alpha values and need to reduce the amount of colors. I need to have no more than 256 colors for all the colors in the image and so far everything I tried (from paint shop to leptonica, etc...) strips the image of the alpha channel and makes it unusable. Is there anything out there that does what I want ?

Edit: I do not want to use a 8-bit palette. I just need to reduce the numbers of color so that my own program can process the image.

HardCoder
  • 3,026
  • 6
  • 32
  • 52

3 Answers3

1

Have you tried ImageMagick?

paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • 1
    Yes I have. It seems to be buggy because the output seems to drop the alpha values when I reduce the colors to 256 or less (probably switches to palette) and always creates rather bad results with lots of wrong colored pixels. It may not be visible with normal pictures but my images have many areas with only a few colors and the very bad dithering is really far too obvious. – HardCoder Jan 05 '12 at 12:51
1

8-bit PNGs with alpha transparency will only render alpha on newer webbrowsers.

Here are some tools and website that does the conversion:

free pngquant

Adobe Fireworks

and website: http://www.8bitalpha.com/

Also, see similar question

Community
  • 1
  • 1
Motomotes
  • 4,111
  • 1
  • 25
  • 24
  • Thanks for your reply. I should have been more precise with my question (I edited it) but I don't need the image for displaying it in a browser or anything but to continue processing it with my own program. I checked all your links and unfortunately (unless I missed something) they don't get me any closer to a solution for my problem... – HardCoder Jan 05 '12 at 12:53
  • Why do you need less than 256 colors if your not trying to use the 8-bt palette? – Motomotes Jan 05 '12 at 22:56
  • I want to use the image as a lookup table for a fragment shaders to conserve texture memory. That way I only use 8bit per pixel for high quality transparency instead of 32bits... – HardCoder Jan 06 '12 at 01:43
  • I believe 256 colors would be 8 bits + alpha channel would be 8 bits = 16 bits per pixel. a transparent PNG24 actually occupies 32bits per pixel, 32bpp. And I don't even know if it is possible to define your own palette but I would look into that, because that is what your trying to do. Whatever interprets your color, needs to know that the numbers 0 to 255 correspond to your custom defined palette. – Motomotes Jan 06 '12 at 02:15
1

The problem you describe is inherent in the PNG format. See the entry at Wikipedia and notice there's no entry in the color options table for Indexed & alpha. There's an ability to add an alpha value to each of the 256 colors, but typically only one palette entry will be made fully transparent and the rest will be fully opaque.

Paint Shop Pro has a couple of options for blending or simulating partial transparency in a paletted PNG - I know because I wrote it.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • I only want to reduce the number of colors to a specific number not use a palette format. I can extract the rgba colors from png with my own program I just need the colors to be less and the alpha to be kept intact. Is this somehow possible with Paint Shop Pro ? – HardCoder Jan 05 '12 at 12:12
  • I rechecked it and there most definitely is a way to set an alpha value to each entry in an 8bit table and effectively turn the palette to 256 RGBA colors. – HardCoder Jan 07 '12 at 12:47
  • @HardCoder, I said as much in my answer: "There's an ability to add an alpha value to each of the 256 colors". Since the alpha isn't independent, it really restricts your palette when you do this. IE6 didn't display them properly either, so you don't see it used very often. – Mark Ransom Jan 07 '12 at 18:10