Okay, that clarifies things a little.
I have to ask though, how do you expect to use these palettes on ZX Spectrum, etc, given that most of the colors in them are not available on that display hardware?
The images are quantized only to colors possible to display.
Also the saving format in any picture is binary. So there is no clear way of storing 10-color picture while taking less space than 16-color one. You need things like storing 3 pixels in 10 bits. Here are the sizes of raw pictures the size of 320*200 with various palette storage systems (excluding size and indexed color info, KB is 1000 B, KiB is 1024 B):
2 color:
8 KB, 7.8125 KiB
3 color (5 pixels in 8 bits):
12.8 KB, 12.5 KiB
4 color:
16 KB, 15.625 KiB
5 color (3 pixels in 7 bits):
18.66725 KB, 18.229736328125 KiB (64000 pixels are not divisible by 3, so it's a bit more than 18.66666... KB)
6 color (5 pixels in 13 bits):
20.8 KB, 20.3125 KiB
8 color:
24 KB, 23.4375 KiB
However for older machines/video cards like ZX Spectrum, GameBoy or CGA, tricks like storing 5 pixels in a byte for 3 colors are either slow (using mod operations) or consume system memory (if you define what each byte means, for example 7F byte may be defined as black, yellow, yellow, cyan, black). That's why it's better to use powers of 2 for number of colors in storage. Go to newer machines/video cards and you'll find out that you have 16777216 colors already. 320x200, 640x200 (with tall 1x2 pixels that can resemble 640x400 by using stretched 8x8 fonts in place of 8x16), 640x400, 1280x800, ... are the resolutions that provide maximum size with binary video memory sizes and palettes with 2^(2^n) colors (2, 4, 16, 256, 65536, 4294967296, ...) while 320x256, 640x256, 640x512, 1280x1024, ... merit palettes with 2^(3*(2^n)) colors instead (8, 64, 4096, 16777216, ...). 640x480 and 1024x768 don't have this property.