#help me understand the MapPalette
1 messages · Page 1 of 1 (latest)
I assume it is not done in this function, because it is done over there, in the first line:
public static byte matchColor(@NotNull Color color) {
if (color.getAlpha() < 128) return 0;
if (mapColorCache != null && mapColorCache.isCached()) {
return mapColorCache.matchColor(color);
}
int index = 0;
double best = -1;
for (int i = 4; i < colors.length; i++) {
double distance = getDistance(color, colors[i]);
if (distance < best || best == -1) {
best = distance;
index = i;
}
}
// Minecraft has 143 colors, some of which have negative byte representations
return (byte) (index < 128 ? index : -129 + (index - 127));
}```
`if (color.getAlpha() < 128) return 0;` makes sense because the minecraft's palette colors are all opaque (a=255) except one color of index 0 which is the transparent color (a=0)
But isn't that approximation a bit brutal? Wouldn't there be a better to actually calculate the distance of the 2 colors more accurately according to all 4 parameters r,g,b and a? If you have no clue i'm still interested about ur opinion. If you have experience with those (in data science class e.g, personal projeccts or whatever) could you tell me whether this was done "by feeling of it" or based on some already made and proved algorithms?