GetNearestPaletteIndex is very slow, are there any algorithms that i could implement in order to optimize these actions and get the same results as with GetNearestPaletteIndex?