# Indexed color memory size vs raw image

It says this:

Indexed color images with palette sizes beyond 256 entries are rare. The practical limit is around 12-bit per pixel, 4,096 different indices. To use indexed 16 bpp or more does not provide the benefits of the indexed color images' nature, due to the color palette size in bytes being greater than the raw image data itself. Also, useful direct RGB Highcolor modes can be used from 15 bpp and up.

I don't undestand why the indexed 16 bpp or more is inefficient in terms of memory

Indexed color saves a lot of memory, storage space, and transmission time: using truecolor, each pixel needs 24 bits, or 3 bytes. A typical 640×480 VGA resolution truecolor uncompressed image needs 640×480×3 = 921,600 bytes (900 KiB). Limiting the image colors to 256, every pixel needs only 8 bits, or 1 byte each, so the example image now needs only 640×480×1 = 307,200 bytes (300 KiB), plus 256×3 = 768 additional bytes to store the palette map in itself (assuming RGB), approximately one third of the original size. Smaller palettes (4-bit 16 colors, 2-bit 4 colors) can pack the pixels even more (to one sixth or one twelfth), obviously at cost of color accuracy.

If i have 640x480 resolution and if i want to use 16-bit palette: 640x480x2(16 bits == 2 bytes) + 65536(2^16)*3(rgb) 614400 + 196608 = 811008 bytes

Raw image memory size: 640x480x3(rgb) 921600 bytes

So 811008 < 921600

And if i have 1920x1080 reolution:

Raw image: 1920x1080x3 = 6 220 800

Indexed color:

1920x1080x2 + palette size(2**16 * 3)

4147200 + 196608

4343808 bytes On

It really depends upon the size of the image. As you said, if b is the number of bytes per pixel and p is the number of pixels, then the image data size i is:

i = p * b

And the color table size t is:

t = 2^(b * 8) * 3

So the point where a raw image would take the same space as an indexed image is:

p * 3 = p * b + 2^(b * 8) * 3

Which I'll now solve for p:

p * 3 - p * b = 2^(b * 8) * 3

p * (3 - b) = 2^(b * 8) * 3

p = (2^(b * 8) * 3) / (3 - b)

So for various bytepp, the minimum image size that will make using indexed images break even:

``````1 bytepp (8 bit) - 384 pixels (like an image of 24 x 16)
1.5 bytepp (12 bit) - 8192 pixels (like an image of 128 x 64)
2 bytepp (16 bit) - 196,604 pixels (like an image of 512 x 384)
2.5 bytepp (20 bit) - 6,291,456 pixels (like an image of 3072 x 2048)
2.875 bytepp (23 bit) - 201,326,592 (like an image of 16,384 x 12,288)
``````

If you are using an image smaller than 512 x 384, 16 bit per pixel indexed color would take up more space than raw 24 bit image data.