rem: uint8 red = (color & 0x7c00) >> 7; uint8 green = (color & 0x3e0) >> 2; uint8 blue = (color & 0x1f) << 3; red |= red >> 5; green |= green >> 5; blue |= blue >> 5;  uint8 closestIndex = 0; unsigned closestDistance = UINT_MAX; for (int32 i = 0; i < 256; i++) { const rgb_color &c = map->color_list[i]; unsigned distance = color_distance(red, green, blue, c.red, c.green, c.blue); if (distance < closestDistance) { closestIndex = i; closestDistance = distance; } }
add: rgb_color rgbColor; rgbColor.red = (color & 0x7c00) >> 7; rgbColor.green = (color & 0x3e0) >> 2; rgbColor.blue = (color & 0x1f) << 3; rgbColor.red |= rgbColor.red >> 5; rgbColor.green |= rgbColor.green >> 5; rgbColor.blue |= rgbColor.blue >> 5;  uint8 closestIndex = FindClosestColor(rgbColor, palette);
context: FillColorMap(const rgb_color *palette, color_map *map){	memcpy(map->color_list, palette, sizeof(map->color_list));		// init index map	for (int32 color = 0; color < 32768; color++) {		// get components		uint8 red = (color & 0x7c00) >> 7;		uint8 green = (color & 0x3e0) >> 2;		uint8 blue = (color & 0x1f) << 3;		red |= red >> 5;		green |= green >> 5;		blue |= blue >> 5;		// find closest color		uint8 closestIndex = 0;		unsigned closestDistance = UINT_MAX;		for (int32 i = 0; i < 256; i++) {			const rgb_color &c = map->color_list[i];			unsigned distance = color_distance(red, green, blue,											   c.red, c.green, c.blue);			if (distance < closestDistance) {				closestIndex = i;				closestDistance = distance;			}		}		map->index_map[color] = closestIndex;	}	// TODO: Inversion map}