That works great, thanks. Now, the last thing - if it could be possible: the system with switching from RGB back to Indexed does produce the colors used, placing them on positions 1,2,3... in the palette. This just crossed my mind, I think it's very complicated, but maybe you could know: is it possible to do the similar, however in a way that it would produce the new palette retaining the positions of the used colors, while switching every unused palette color with some other. Example: a picture contains red, blue, green colors. Their positions in the palette, which is full of other unusedcolors, are (1,3), (3,2), (5,5). Is it possible to automatically alter the palette so that red, blue, green colors retain their positions in the palette, but all other colors are replaced with some other, like white?
Thank you very much for your answers so far