ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvttoolkit.C
(Generate patch)

Comparing rxvt-unicode/src/rxvttoolkit.C (file contents):
Revision 1.145 by root, Sat Dec 13 10:47:32 2014 UTC vs.
Revision 1.146 by root, Sun Dec 14 04:52:10 2014 UTC

23 23
24#include "../config.h" 24#include "../config.h"
25#include <rxvt.h> 25#include <rxvt.h>
26#include <rxvttoolkit.h> 26#include <rxvttoolkit.h>
27 27
28#include <stdlib.h>
29
28#include <unistd.h> 30#include <unistd.h>
29#include <fcntl.h> 31#include <fcntl.h>
30 32
31#include <sys/utsname.h> 33#include <sys/utsname.h>
32#include <sys/socket.h> 34#include <sys/socket.h>
807 } 809 }
808 else if (XAllocColor (screen->dpy, screen->cmap, &c)) 810 else if (XAllocColor (screen->dpy, screen->cmap, &c))
809 return true; 811 return true;
810#endif 812#endif
811 813
814 //TODO: set c.color* or c.*
812 c.pixel = (color.r + color.g + color.b) > 128*3 815 c.pixel = (color.r * 2 + color.g * 3 + color.b) >= 0x8000 * 6
813 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) 816 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy))
814 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); 817 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy));
815 818
816 return false; 819 return false;
817} 820}
877 // many extra optimisations. 880 // many extra optimisations.
878 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); 881 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size);
879 882
880 while (cmap_size) 883 while (cmap_size)
881 { 884 {
882 int diff = 0x7fffffffUL; 885 int diff = 0x7fffffffL;
883 XColor *best = colors; 886 XColor *best = colors;
884 887
885 for (int i = 0; i < cmap_size; i++) 888 for (int i = 0; i < cmap_size; i++)
886 { 889 {
890 // simple weighted rgb distance sucks, but keeps it simple
887 int d = (squared_diff<int> (color.r >> 2, colors [i].red >> 2)) 891 int d = abs (color.r - colors [i].red ) * 2
888 + (squared_diff<int> (color.g >> 2, colors [i].green >> 2)) 892 + abs (color.g - colors [i].green) * 3
889 + (squared_diff<int> (color.b >> 2, colors [i].blue >> 2)); 893 + abs (color.b - colors [i].blue );
890 894
891 if (d < diff) 895 if (d < diff)
892 { 896 {
893 diff = d; 897 diff = d;
894 best = colors + i; 898 best = colors + i;
915 919
916void 920void
917rxvt_color::get (rgba &color) const 921rxvt_color::get (rgba &color) const
918{ 922{
919#if XFT 923#if XFT
924 //TODO premultiplied alpha??
920 color.r = c.color.red; 925 color.r = c.color.red;
921 color.g = c.color.green; 926 color.g = c.color.green;
922 color.b = c.color.blue; 927 color.b = c.color.blue;
923 color.a = c.color.alpha; 928 color.a = c.color.alpha;
924#else 929#else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines