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.147 by root, Wed Dec 17 13:16:18 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>
787 d.red = color.r; 789 d.red = color.r;
788 d.green = color.g; 790 d.green = color.g;
789 d.blue = color.b; 791 d.blue = color.b;
790 d.alpha = alpha; 792 d.alpha = alpha;
791 793
794 // XftColorAlloc always returns 100% transparent pixels(!)
792 if (XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c)) 795 if (XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c))
793 return true; 796 return true;
794 } 797 }
795#else 798#else
796 c.red = color.r; 799 c.red = color.r;
807 } 810 }
808 else if (XAllocColor (screen->dpy, screen->cmap, &c)) 811 else if (XAllocColor (screen->dpy, screen->cmap, &c))
809 return true; 812 return true;
810#endif 813#endif
811 814
815 //TODO: set c.color* or c.*
812 c.pixel = (color.r + color.g + color.b) > 128*3 816 c.pixel = (color.r * 2 + color.g * 3 + color.b) >= 0x8000 * 6
813 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) 817 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy))
814 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); 818 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy));
815 819
816 return false; 820 return false;
817} 821}
877 // many extra optimisations. 881 // many extra optimisations.
878 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); 882 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size);
879 883
880 while (cmap_size) 884 while (cmap_size)
881 { 885 {
882 int diff = 0x7fffffffUL; 886 int diff = 0x7fffffffL;
883 XColor *best = colors; 887 XColor *best = colors;
884 888
885 for (int i = 0; i < cmap_size; i++) 889 for (int i = 0; i < cmap_size; i++)
886 { 890 {
891 // simple weighted rgb distance sucks, but keeps it simple
887 int d = (squared_diff<int> (color.r >> 2, colors [i].red >> 2)) 892 int d = abs (color.r - colors [i].red ) * 2
888 + (squared_diff<int> (color.g >> 2, colors [i].green >> 2)) 893 + abs (color.g - colors [i].green) * 3
889 + (squared_diff<int> (color.b >> 2, colors [i].blue >> 2)); 894 + abs (color.b - colors [i].blue );
890 895
891 if (d < diff) 896 if (d < diff)
892 { 897 {
893 diff = d; 898 diff = d;
894 best = colors + i; 899 best = colors + i;
915 920
916void 921void
917rxvt_color::get (rgba &color) const 922rxvt_color::get (rgba &color) const
918{ 923{
919#if XFT 924#if XFT
925 //TODO premultiplied alpha??
920 color.r = c.color.red; 926 color.r = c.color.red;
921 color.g = c.color.green; 927 color.g = c.color.green;
922 color.b = c.color.blue; 928 color.b = c.color.blue;
923 color.a = c.color.alpha; 929 color.a = c.color.alpha;
924#else 930#else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines