PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Creation of paletted mipmaps

Not sure if this is the right forum for this question, but I'll try:

Is there a good library out there that can automatically create mipmaps for a *palette-based* representation? And that maybe even creates the palettes?

Background is as follows: OpenGL ES defines palettized mipmap textures, i.e you have a given color palette with 16 or 256 color entries, and then an array of textures that together form a mipmap, each of them being an array of indices into this palette. So each pixel requires 1/2 or 1 byte.

What I am looking for is a function/algorithm/library that would take a given texture image and derive both the palette as well as all the mipmap levels, and do a good job at it. The rationale is that especially on mobile devices such a format would significantly reduce the amount of data to be transfered during rasterization.

I'd like to add direct support for this type of textures to Vincent ( http://ogl-es.sourceforge.net ), but only if there are effective tools available that would help a game developer to ceate the texture images in this specific format.

Anyone any thoughts?

Thanks,
HM
(I think) What you're after is "colour quantisation"/"color quantization".

I googled <a href="http://www.cubic.org/~submissive/sourcerer/octree.htm">this</a> (Nils Pipenbrinck has posted on this site before and will probably appear now I've said his name ;)), which points at <a href="http://members.ozemail.com.au/~dekker/NEUQUANT.HTML">this</a>. Code is available, so you could hack it to produce your mip-maps.
An easy way for doing this is ceating a histogram and select the top 256/16 entries as your color palette. Then you create the bitmap by selecting the color index based on the minimal distance (N2 Norm).
Its not as sophisticated as "real" quantization, where you minimize the overall mean error, but its certainly faster and results are resonable good.


ps. When i think about it, this may not work well for images with "too many" different colors.
refractor wrote:(I think) What you're after is "colour quantisation"/"color quantization".

I googled <a href="http://www.cubic.org/~submissive/sourcerer/octree.htm">this</a> (Nils Pipenbrinck has posted on this site before and will probably appear now I've said his name ;)), which points at <a href="http://members.ozemail.com.au/~dekker/NEUQUANT.HTML">this</a>. Code is available, so you could hack it to produce your mip-maps.


The octree approach looks indeed quite feasible, thanks for the links.

- HM
refractor wrote:(I think) What you're after is "colour quantisation"/"color quantization".

I googled <a href="http://www.cubic.org/~submissive/sourcerer/octree.htm">this</a> (Nils Pipenbrinck has posted on this site before and will probably appear now I've said his name ;)), which points at <a href="http://members.ozemail.com.au/~dekker/NEUQUANT.HTML">this</a>. Code is available, so you could hack it to produce your mip-maps.


Here I am...

Is this issue already resolved?
torus":617r3sdx]
Hi there...

I haven't gotten to actually implement any of the two approaches, but plan to get there soon. How significant is the difference between the Kohonen network & the oct-tree approach? The latter appeared to be pretty straight-forward, which is why I was contemplating with using that algorithm first.

Gruessle,
HM
well,

the Kohonen network source is *very* easy to hack and apply to your own application. It has several merits. Especially gradients betweeen two colors look very good, but it has problems when a small amount of pixels make a big difference in a picture (e.g. white eyes on a face against a skin-coloured background usually gets lost). Kohonen network does not perserve "extremes" but rather aim for a least square fit.. That works well for certain types of textures like natural images..

The octree approach likes to perserve the extreme values and compresses more on the gradients.. As said human faces look a hell lot better with it.


Recently I've found the "bright" utility from the unreal tool chain.. This algorithm beats booth Kohonen and Octree by a magnitude.. It's results are simply stunning. I've never thought it would be possible to generate *such* a good palette for images. (One day I'd like to meet the guy who coded it and buy him a beer... he did an outstanding job in color reduction)


If you can live with the license and the fact that you have to call it to get the palette use it!

http://dl.fileplanet.com/dl/dl.asp?/pol ... ght183.zip


Regards,
Nils Pipenbrinck
torus wrote:
If you can live with the license and the fact that you have to call it to get the palette use it!

http://dl.fileplanet.com/dl/dl.asp?/pol ... ght183.zip

That's perfect for what I've been looking for. Given there is a ready made tool out there, it makes perfectly sense to add support for that in the rasterizer.

- HM
Good to hear that you like it.

Btw, there's also a rather hacked version that quantizes with alpha channels. As usual outstanding results.

You'll find it you search for "alphapal.zip". Good luck.