Falling around google and found nothing like what I need. so what is it me ok two things:
Firstly, I am looking for an Algorithm / pseudo-code / white wallpaper to determine the best color for an r, g, b tuple and an array of 256 RGB tuples.
Secondly, I am looking for an algorithm / pseudo-code / documents to repaint the 8-bit image of the palette (using the RGB palette above), either taking into account Hue / Saturation or r, g, b channel modification. It will also be nice if you could add a correction for gamma and artifact pixels in the coloring as well.
does anyone have hints / pointers / hints as to where I can find such a thing (I know that they must exist, otherwise some photoshop functions will not work)
UPDATE: here is the basic RGB Euclidean distance for finding a palette index:
uint_8 __stdcall GFXUTIL_GetNearestPaletteIndex(const uint_8* pPalette, size_t nSize, uint_8 nRed, uint_8 nGreen, uint_8 nBlue)
{
if(pPalette == NULL)
return 0;
int nDistance = -1;
size_t nIndex = 0, nFoundIndex = 0;
while(nIndex < nSize)
{
int nDistRed = pPalette[0] - nRed;
int nDistGreen = pPalette[1] - nGreen;
int nDistBlue = pPalette[2] - nBlue;
int nCurrentDistance = (nDistRed * nDistRed) + (nDistGreen * nDistGreen) + (nDistBlue * nDistBlue);
if(nCurrentDistance < nDistance)
{
nFoundIndex = nIndex;
nDistance = nCurrentDistance;
}
nIndex++;
pPalette += sizeof(uint_32);
}
return nFoundIndex;
}
source
share