gint color1_r, color1_g, color1_b, color2_r, color2_g, color2_b, min_d, d; gboolean gimp_context_get_background (GimpRGB *background); color1_r = background[1]; color1_g = background[2]; color1_b = background[3]; min_d = 195075; /* Max value possible is R^2 + G^2 + B^2 = ( 255^2 ) * 3 */ for (x = 0; x<16; x++) { color2_r = vicpalette[x*3] color2_g = vicpalette[x*3+1] color2_b = vicpalette[x*3+2] od = d d = (color1_r - color2_r)^2 + (color1_g - color2_g)^2 + (color1_b - color2_b)^2 if d < min_d ( min_d = d color_index = x } } return min_d; }