MCPcopy Create free account
hub / github.com/NetHack/NetHack / color_distance

Function color_distance

src/coloratt.c:978–994  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

976 **/
977
978int
979color_distance(uint32_t rgb1, uint32_t rgb2)
980{
981 int r1 = (rgb1 >> 16) & 0xFF;
982 int g1 = (rgb1 >> 8) & 0xFF;
983 int b1 = (rgb1) & 0xFF;
984 int r2 = (rgb2 >> 16) & 0xFF;
985 int g2 = (rgb2 >> 8) & 0xFF;
986 int b2 = (rgb2) & 0xFF;
987
988 int rmean = (r1 + r2) / 2;
989 int r = r1 - r2;
990 int g = g1 - g2;
991 int b = b1 - b2;
992 return ((((512 + rmean) * r * r) >> 8) + 4 * g * g
993 + (((767 - rmean) * b * b) >> 8));
994}
995
996boolean
997closest_color(uint32 lcolor, uint32 *closecolor, uint16 *clridx)

Callers 1

closest_colorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected