one fing leads . . .

Auto Pixel Colour
There are two modes, the first is to limit the colour palette to the colours that are specified, the system chooses what is the closest match to each pixel by comparing the specified criterion: hue, RGB, brightness or weighted RGB which is the RGB triad multiplied by the factors that give a brightness calculation (see Formulas for Calculating Pixel Brightness). Comparison on the two RGB options are in flat total difference between the Rs, the Gs and the Bs.
In the second mode each of the 1677216 colours (256 × 256 × 256) is used just once. If there are more than 1677216 pixels in the pic, the remainder are left transparent, if there are fewer than 16777216, then they’re all filled but not all those possible colours are used.
Colours are chosen first based upon RGB values of each pixel, if that colour is already used the nearest colour in numeric terms is found; because of the way that RGB is organised as a number ( × 65536 + green × 256 + blue). this means looking through the blues first, then the greens, then the reds. To counteract the effect of this rows on the output file can be specified as being written in alternately, or in any number of passes up to 7.
This page requires a HTML5 browser and Javascript switched on.
selected colours auto: full colour range
number of colours
COLOURS : (use colour picker to change checked colour)
Match by:
Hue RGB Brightness Weighted RGB
. . . .
Brightness calculation formula:

more experiments for the sake of my dreams