rem: return IndexForColor(color.red, color.green, color.blue);
add: if (fTransparentMode > NO_TRANSPARENCY && alpha < 128) return fTransparentIndex;  uint8 index = 0;  if (fMode == GREYSCALE_PALETTE) { index = (308 * red + 600 * green + 116 * blue) / 1024;  if (fTransparentMode == AUTO_TRANSPARENCY && index == 1 && fTransparentIndex == 1) index = 0; } else { int closestDistance = 255 * 255 * 3;  if (fTransparentMode == AUTO_TRANSPARENCY) { for (int i = 0; i < fTransparentIndex && closestDistance != 0; i++) { int rd = (int)red - (int)pal[i].red; int gd = (int)green - (int)pal[i].green; int bd = (int)blue - (int)pal[i].blue; int distanceAtIndex = rd * rd + gd * gd + bd * bd; if (distanceAtIndex < closestDistance) { closestDistance = distanceAtIndex; index = i; } } for (int i = fTransparentIndex + 1; i < fSize && closestDistance != 0; i++) { int rd = (int)red - (int)pal[i].red; int gd = (int)green - (int)pal[i].green; int bd = (int)blue - (int)pal[i].blue; int distanceAtIndex = rd * rd + gd * gd + bd * bd; if (distanceAtIndex < closestDistance) { closestDistance = distanceAtIndex; index = i; } } } else { for (int i = 0; i < fSize && closestDistance != 0; i++) { int rd = (int)red - (int)pal[i].red; int gd = (int)green - (int)pal[i].green; int bd = (int)blue - (int)pal[i].blue; int distanceAtIndex = rd * rd + gd * gd + bd * bd; if (distanceAtIndex < closestDistance) { closestDistance = distanceAtIndex; index = i; } } } } return index;
context: SavePalette::IndexForColor(const rgb_color& color){	return IndexForColor(color.red, color.green, color.blue);}