Different paletted texture formats

How to create data samples for each of the paletted texture formats supported by Opengl-es?

Thank you.

I googled for any tool to generate the palettized texture, but unfortunately not successful.

So i plan to create the sample data by hand. But my next question is how to decide on the size of each texel.

For Eg: PALETTE4_RGB8_OES, the spec says its 4 bits per texel, but what does RGB8 signify? 8 bits per color component?

Simillarly for other palette formats.


Is creating the texture samples by hand (using random number generation) a good idea?

RGB8 / RGBA8 / R5_G6_B5 etc is the format of the palette data, yes. PALETTE4 and PALETTE8 means the color-indices (or the bitmap) are 4 or 8 bits respectively (= 16 or 256 colors).

I’d reccomend libraries like FreeImage that contains color quantizing functions for generating paletted images.

I would reframe my doubt as below:
For Eg: PALETTE4_RGB8_OES : If each texel in this format is 4 bits, How is R,G,B each of 8 bits represented in each texel.

RGB isn’t represented in a texel in paletted textures. Instead, you reference a color from a palette. So, for PALETTE4_RGB8_OES you have an array of 16 RGB8 colors (24bit packed), and a bitmap of references to that arrays (4 bit packed indices to that first array).

OK, Now i understand the meaning. Thank you.

I would check the “FreeImage” suggested by you.

To experiment,

i have created a packed “unsigned char” array of random numbers to represent PALETTE4_RGB8_0ES format. The array is of size (128 * 128).

For the API:
glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_PALETTE4_RGB8_OES, 256, 256, 0, size, data);

How to calculate “size” for a given width and height? Can i have a single mip-map level “0”?

The data passed to glCompressedTexImage2D for paletted textures consists of two parts: first the palette, followed by either a single mipmap level or the whole mipmap pyramid.

PALETTE4_* formats have 16 palette entries and use 4 bits per pixel.
PALETTE8_* formats have 256 palette entries and use 8 bits per pixel.

*_RGBA8_OES formats use 32 bits per palette entry.
*_RGB8_OES formats use 24 bits per palette entry.
The other formats use 16 bits per palette entry.

So the size of the palette in bytes is the number of palette entries times the bits per palette entry divided by 8. The size of each mipmap level is its width * height * bits per pixel / 8 (rounded up for 1x1 at 4bpp).

So a single mipmap level for a PALETTE4_RGB8 texture of size 128 x 128 is 16 * 24 / 8 + 128 * 128 * 4 / 8 = 8240 bytes.

Thank you very much.

I could display all the palette textures at mip map level 0, by using the equation and hand made array.

But I was not successful for other miplevels, with the same equation, with corresponding level-width and level-height.

You have to sum up the size for the palette and the sizes for each mipmap level. E.g. for a 8x4 texture in PALETTE4_RGB8 format:
Palette: 16 * 24 / 8 = 48
Level 0: 8 * 4 * 4 / 8 = 16
Level 1: 4 * 2 * 4 / 8 = 4
Level 2: 2 * 1 * 4 / 8 = 1
Level 3: 1 * 1 * 4 / 8 = 1 (rounded up)
Total size: 48 + 16 + 4 + 1 + 1 = 70 bytes

In addition, the level parameter to glCompressedTexImage2D needs to be (1 - number of levels) for paletted textures, so for this example it would be:
glCompressedTexImage2D(GL_TEXTURE_2D, -3, GL_PALETTE4_RGB8_OES, 8, 4, 0, 70, data);

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.