/* Anchor of the chain of MDisplayInfo objects. */
static MPlist *display_info_list;
+typedef struct
+{
+ unsigned short r, g, b;
+ GC gc;
+} MColorGC;
+
struct MWDevice
{
/* Common header for the m17n object. */
/** List of pointers to realized fontsets on the frame. */
MPlist *realized_fontset_list;
+ /** List of XColors vs GCs on the frame. */
+ MPlist *gc_list;
};
static MPlist *device_list;
} while (0)
+static GC
+get_gc (MWDevice *device, XColor *color)
+{
+ MPlist *plist;
+ unsigned long valuemask = GCForeground;
+ XGCValues values;
+ GC gc;
+ MColorGC *color_gc;
+
+ MPLIST_DO (plist, device->gc_list)
+ {
+ color_gc = MPLIST_VAL (plist);
+
+ if (color->red == color_gc->r
+ && color->green == color_gc->g
+ && color->blue == color_gc->b)
+ return color_gc->gc;
+ }
+ if (! XAllocColor (device->display_info->display, device->cmap, color))
+ return DefaultGC (device->display_info->display, device->screen_num);
+ values.foreground = color->pixel;
+ gc = XCreateGC (device->display_info->display, device->drawable,
+ valuemask, &values);
+ color_gc = malloc (sizeof (MColorGC));
+ color_gc->r = color->red;
+ color_gc->g = color->green;
+ color_gc->b = color->blue;
+ color_gc->gc = gc;
+ mplist_push (plist, Mt, color_gc);
+ return gc;
+}
+
+
void
mwin__realize_face (MRealizedFace *rface)
{
for (j = 0; j < width; j++)
if (pmp[j])
{
- float ratio = (float) (pmp[j] >> 5) / 32;
+ int fore_ratio = pmp[j] >> 5, back_ratio = 7 - fore_ratio;
color = fore_color;
- color.red = fore_color.red * ratio + back_color.red * (1 - ratio);
- color.green = fore_color.green * ratio + back_color.green * (1 - ratio);
- color.blue = fore_color.blue * ratio + back_color.blue * (1 - ratio);
+ color.red = ((fore_color.red * fore_ratio) + (back_color.red * back_ratio)) / 7;
+ color.green = ((fore_color.green * fore_ratio) + (back_color.green * back_ratio)) / 7;
+ color.blue = ((fore_color.blue * fore_ratio) + (back_color.blue * back_ratio)) / 7;
if (XAllocColor (FRAME_DISPLAY (frame), frame->device->cmap, &color)
&& fore_color.pixel != color.pixel)
{