--- rxvt-unicode/src/rxvttoolkit.C 2006/01/31 00:25:16 1.39 +++ rxvt-unicode/src/rxvttoolkit.C 2006/01/31 18:36:35 1.43 @@ -562,7 +562,7 @@ ///////////////////////////////////////////////////////////////////////////// bool -rxvt_color::alloc (rxvt_screen *screen, rxvt_rgba rgba) +rxvt_color::alloc (rxvt_screen *screen, const rgba &color) { #if XFT XRenderPictFormat *format; @@ -574,15 +574,15 @@ && (format = XRenderFindVisualFormat (screen->xdisp, screen->visual))) { // the fun lies in doing everything manually... - c.color.red = rgba.r; - c.color.green = rgba.g; - c.color.blue = rgba.b; - c.color.alpha = rgba.a; - - c.pixel = ((rgba.r * format->direct.redMask / rxvt_rgba::MAX_CC) << format->direct.red ) - | ((rgba.g * format->direct.greenMask / rxvt_rgba::MAX_CC) << format->direct.green) - | ((rgba.b * format->direct.blueMask / rxvt_rgba::MAX_CC) << format->direct.blue ) - | ((rgba.a * format->direct.alphaMask / rxvt_rgba::MAX_CC) << format->direct.alpha); + c.color.red = color.r; + c.color.green = color.g; + c.color.blue = color.b; + c.color.alpha = color.a; + + c.pixel = ((color.r * format->direct.redMask / rgba::MAX_CC) << format->direct.red ) + | ((color.g * format->direct.greenMask / rgba::MAX_CC) << format->direct.green) + | ((color.b * format->direct.blueMask / rgba::MAX_CC) << format->direct.blue ) + | ((color.a * format->direct.alphaMask / rgba::MAX_CC) << format->direct.alpha); return true; } @@ -590,42 +590,40 @@ { XRenderColor d; - d.red = rgba.r; - d.green = rgba.g; - d.blue = rgba.b; - d.alpha = rgba.a; + d.red = color.r; + d.green = color.g; + d.blue = color.b; + d.alpha = color.a; return XftColorAllocValue (screen->xdisp, screen->visual, screen->cmap, &d, &c); } #else if (screen->visual->c_class == TrueColor || screen->visual->c_class == DirectColor) { - p = (rgba.r * (screen->visual->red_mask >> ctz (screen->visual->red_mask )) - / rxvt_rgba::MAX_CC) << ctz (screen->visual->red_mask ) - | (rgba.g * (screen->visual->green_mask >> ctz (screen->visual->green_mask)) - / rxvt_rgba::MAX_CC) << ctz (screen->visual->green_mask) - | (rgba.b * (screen->visual->blue_mask >> ctz (screen->visual->blue_mask )) - / rxvt_rgba::MAX_CC) << ctz (screen->visual->blue_mask ); + c.red = color.g; + c.green = color.g; + c.blue = color.g; + c.pixel = (color.r * (screen->visual->red_mask >> ctz (screen->visual->red_mask )) + / rgba::MAX_CC) << ctz (screen->visual->red_mask ) + | (color.g * (screen->visual->green_mask >> ctz (screen->visual->green_mask)) + / rgba::MAX_CC) << ctz (screen->visual->green_mask) + | (color.b * (screen->visual->blue_mask >> ctz (screen->visual->blue_mask )) + / rgba::MAX_CC) << ctz (screen->visual->blue_mask ); return true; } else { - XColor xc; + c.red = color.r; + c.green = color.g; + c.blue = color.b; - xc.red = rgba.r; - xc.green = rgba.g; - xc.blue = rgba.b; - - if (XAllocColor (screen->xdisp, screen->cmap, &xc)) - { - p = xc.pixel; - return true; - } + if (XAllocColor (screen->xdisp, screen->cmap, &c)) + return true; else - p = (rgba.r + rgba.g + rgba.b) > 128*3 - ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->xdisp)) - : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->xdisp)); + c.pixel = (color.r + color.g + color.b) > 128*3 + ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->xdisp)) + : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->xdisp)); } #endif @@ -635,24 +633,19 @@ bool rxvt_color::set (rxvt_screen *screen, const char *name) { - rxvt_rgba c; + rgba c; char eos; int skip; - if (1 <= sscanf (name, "[%hx]%n", &c.a, &skip)) + if (1 <= sscanf (name, "[%hd]%n", &c.a, &skip)) { - switch (skip) - { - case 2 + 1: c.a *= rxvt_rgba::MAX_CC / 0x000f; break; - case 2 + 2: c.a *= rxvt_rgba::MAX_CC / 0x00ff; break; - case 2 + 3: c.a *= rxvt_rgba::MAX_CC / 0x0fff; break; - case 2 + 4: c.a *= rxvt_rgba::MAX_CC / 0xffff; break; - } - + printf ("X %d\n", c.a); + c.a = lerp (0, rgba::MAX_CC, c.a); name += skip; + printf ("y %04x\n", c.a); } else - c.a = rxvt_rgba::MAX_CC; + c.a = rgba::MAX_CC; // parse the non-standard rgba format if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%hx/%hx/%hx/%hx%c", &c.r, &c.g, &c.b, &c.a, &eos)) @@ -679,9 +672,9 @@ } bool -rxvt_color::set (rxvt_screen *screen, rxvt_rgba rgba) +rxvt_color::set (rxvt_screen *screen, const rgba &color) { - bool got = alloc (screen, rgba); + bool got = alloc (screen, color); #if !ENABLE_MINIMAL int cmap_size = screen->visual->map_entries; @@ -695,6 +688,8 @@ for (int i = 0; i < cmap_size; i++) colors [i].pixel = i; + // many kilobytes transfer per colour, but pseudocolor isn't worth + // many extra optimisations. XQueryColors (screen->xdisp, screen->cmap, colors, cmap_size); int diff = 0x7fffffffUL; @@ -702,9 +697,9 @@ for (int i = 0; i < cmap_size; i++) { - int d = (squared_diff (rgba.r >> 2, colors [i].red >> 2)) - + (squared_diff (rgba.g >> 2, colors [i].green >> 2)) - + (squared_diff (rgba.b >> 2, colors [i].blue >> 2)); + int d = (squared_diff (color.r >> 2, colors [i].red >> 2)) + + (squared_diff (color.g >> 2, colors [i].green >> 2)) + + (squared_diff (color.b >> 2, colors [i].blue >> 2)); if (d < diff) { @@ -714,9 +709,9 @@ } //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d)\n", - // rgba.r, rgba.g, rgba.b, best->red, best->green, best->blue, diff); + // color.r, color.g, color.b, best->red, best->green, best->blue, diff); - got = alloc (screen, rxvt_rgba (best->red, best->green, best->blue)); + got = alloc (screen, rgba (best->red, best->green, best->blue)); delete colors; } @@ -726,23 +721,18 @@ } void -rxvt_color::get (rxvt_screen *screen, rxvt_rgba &rgba) +rxvt_color::get (rxvt_screen *screen, rgba &color) { #if XFT - rgba.r = c.color.red; - rgba.g = c.color.green; - rgba.b = c.color.blue; - rgba.a = c.color.alpha; + color.r = c.color.red; + color.g = c.color.green; + color.b = c.color.blue; + color.a = c.color.alpha; #else - XColor c; - - c.pixel = p; - XQueryColor (screen->xdisp, screen->cmap, &c); - - rgba.r = c.red; - rgba.g = c.green; - rgba.b = c.blue; - rgba.a = rxvt_rgba::MAX_CC; + color.r = c.red; + color.g = c.green; + color.b = c.blue; + color.a = rgba::MAX_CC; #endif } @@ -752,46 +742,24 @@ #if XFT XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c); #else - XFreeColors (screen->xdisp, screen->cmap, &p, 1, AllPlanes); + XFreeColors (screen->xdisp, screen->cmap, &c.pixel, 1, AllPlanes); #endif } -rxvt_color -rxvt_color::fade (rxvt_screen *screen, int percent) -{ - rxvt_color faded; - - rxvt_rgba c; - get (screen, c); - - c.r = lerp (0, c.r, percent); - c.g = lerp (0, c.g, percent); - c.b = lerp (0, c.b, percent); - - faded.set (screen, c); - - return faded; -} - -rxvt_color -rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &fadeto) +void +rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to) { - rxvt_rgba c, fc; - rxvt_color faded; - + rgba c; get (screen, c); - fadeto.get (screen, fc); - faded.set ( + result.set ( screen, - rxvt_rgba ( - lerp (fc.r, c.r, percent), - lerp (fc.g, c.g, percent), - lerp (fc.b, c.b, percent), - lerp (fc.a, c.a, percent) + rgba ( + lerp (c.r, to.r, percent), + lerp (c.g, to.g, percent), + lerp (c.b, to.b, percent), + lerp (c.a, to.a, percent) ) ); - - return faded; }