@@ -2272,8 +2272,6 @@ gui_mch_get_color(char_u *name)
22722272 guicolor_T requested ;
22732273 XColor available ;
22742274 Colormap colormap ;
2275- #define COLORSPECBUFSIZE 8 /* space enough to hold "#RRGGBB" */
2276- char spec [COLORSPECBUFSIZE ];
22772275
22782276 /* can't do this when GUI not running */
22792277 if (!gui .in_use || name == NULL || * name == NUL )
@@ -2283,11 +2281,22 @@ gui_mch_get_color(char_u *name)
22832281 if (requested == INVALCOLOR )
22842282 return INVALCOLOR ;
22852283
2286- vim_snprintf ( spec , COLORSPECBUFSIZE , "#%.2x%.2x%.2x" ,
2284+ return gui_mch_get_rgb_color (
22872285 (requested & 0xff0000 ) >> 16 ,
22882286 (requested & 0xff00 ) >> 8 ,
22892287 requested & 0xff );
2290- #undef COLORSPECBUFSIZE
2288+ }
2289+
2290+ /*
2291+ * Return the Pixel value (color) for the given RGB values.
2292+ * Return INVALCOLOR for error.
2293+ */
2294+ guicolor_T
2295+ gui_mch_get_rgb_color (int r , int g , int b )
2296+ {
2297+ char spec [8 ]; /* space enough to hold "#RRGGBB" */
2298+
2299+ vim_snprintf (spec , sizeof (spec ), "#%.2x%.2x%.2x" , r , g , b );
22912300 colormap = DefaultColormap (gui .dpy , DefaultScreen (gui .dpy ));
22922301 if (XParseColor (gui .dpy , colormap , (char * )spec , & available ) != 0
22932302 && XAllocColor (gui .dpy , colormap , & available ) != 0 )
0 commit comments