static gint8 get_bgcol(gint line, guint8 type) { gint color1_r, color1_g, color1_b, color2_r, color2_g, color2_b, min_d, d, color_index; GimpRGB bgcolor; if (!gimp_context_get_background(&bgcolor) { return 0; } color1_r = bgcolor.r color1_g = bgcolor.g color1_b = bgcolor.b 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] d = pow( (color1_r - color2_r), 2) ) + pow( (color1_g - color2_g) , 2 ) + pow ( (color1_b - color2_b), 2) if (d < min_d) ( min_d = d color_index = x } } return min_d; }