一直在谷歌周围闲逛,并没有找到任何像我所追求的东西。那我在追求什么?有两件事:
首先,我正在寻找一种算法/伪代码/白皮书来确定给定 r、g、b 元组和 256 个 RGB 元组数组的最合适的颜色。
其次,我正在寻找一种算法/伪代码/白皮书来将 8 位调色板图像(使用上面的 RGB 调色板)重新着色为给定的色相/饱和度或通过 r、g、b 通道修改。如果可以在着色中添加伽玛和伪影像素的修复,那也很好。
任何人都得到了关于我在哪里可以找到这样的东西的任何提示/指针/提示(我知道它们必须存在,否则一些 Photoshop 功能不会)
更新:这是一个基本的欧几里德距离 RGB 到调色板索引查找器:
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;
}