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.142 by root, Thu May 22 18:54:33 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>
279 XFree (vi); 281 XFree (vi);
280 282
281 cmap = XCreateColormap (dpy, display->root, visual, AllocNone); 283 cmap = XCreateColormap (dpy, display->root, visual, AllocNone);
282 } 284 }
283 else 285 else
284 rxvt_warn ("cannot requested visual id 0x%02x, using default visual.\n", id); 286 rxvt_warn ("no visual found for requested id 0x%02x, using default visual.\n", id);
285} 287}
286 288
287void 289void
288rxvt_screen::select_depth (int bitdepth) 290rxvt_screen::select_depth (int bitdepth)
289{ 291{
490 492
491 flags = 0; 493 flags = 0;
492#if XRENDER 494#if XRENDER
493 int major, minor; 495 int major, minor;
494 if (XRenderQueryVersion (dpy, &major, &minor)) 496 if (XRenderQueryVersion (dpy, &major, &minor))
495 if (major > 0 || (major == 0 && minor >= 10)) 497 if (major > 0 || (major == 0 && minor >= 11))
496 { 498 {
497 flags |= DISPLAY_HAS_RENDER; 499 flags |= DISPLAY_HAS_RENDER;
498
499#if 0
500 if (major > 0 || (major == 0 && minor >= 11))
501 flags |= DISPLAY_HAS_RENDER_MUL;
502#endif
503 500
504 if (XFilters *filters = XRenderQueryFilters (dpy, root)) 501 if (XFilters *filters = XRenderQueryFilters (dpy, root))
505 { 502 {
506 for (int i = 0; i < filters->nfilter; i++) 503 for (int i = 0; i < filters->nfilter; i++)
507 if (!strcmp (filters->filter [i], FilterConvolution)) 504 if (!strcmp (filters->filter [i], FilterConvolution))
812 } 809 }
813 else if (XAllocColor (screen->dpy, screen->cmap, &c)) 810 else if (XAllocColor (screen->dpy, screen->cmap, &c))
814 return true; 811 return true;
815#endif 812#endif
816 813
814 //TODO: set c.color* or c.*
817 c.pixel = (color.r + color.g + color.b) > 128*3 815 c.pixel = (color.r * 2 + color.g * 3 + color.b) >= 0x8000 * 6
818 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) 816 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy))
819 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); 817 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy));
820 818
821 return false; 819 return false;
822} 820}
880 878
881 // many kilobytes transfer per colour, but pseudocolor isn't worth 879 // many kilobytes transfer per colour, but pseudocolor isn't worth
882 // many extra optimisations. 880 // many extra optimisations.
883 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); 881 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size);
884 882
883 while (cmap_size)
884 {
885 int diff = 0x7fffffffUL; 885 int diff = 0x7fffffffL;
886 XColor *best = colors; 886 XColor *best = colors;
887 887
888 for (int i = 0; i < cmap_size; i++) 888 for (int i = 0; i < cmap_size; i++)
889 {
890 int d = (squared_diff<int> (color.r >> 2, colors [i].red >> 2))
891 + (squared_diff<int> (color.g >> 2, colors [i].green >> 2))
892 + (squared_diff<int> (color.b >> 2, colors [i].blue >> 2));
893
894 if (d < diff)
895 { 889 {
890 // simple weighted rgb distance sucks, but keeps it simple
891 int d = abs (color.r - colors [i].red ) * 2
892 + abs (color.g - colors [i].green) * 3
893 + abs (color.b - colors [i].blue );
894
895 if (d < diff)
896 {
896 diff = d; 897 diff = d;
897 best = colors + i; 898 best = colors + i;
899 }
898 } 900 }
899 }
900 901
901 //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d)\n", 902 //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d,%d)\n",
902 // color.r, color.g, color.b, best->red, best->green, best->blue, diff); 903 // color.r, color.g, color.b, best->red, best->green, best->blue, diff, best - colors);
903 904
904 got = alloc (screen, rgba (best->red, best->green, best->blue)); 905 got = alloc (screen, rgba (best->red, best->green, best->blue));
906
907 if (got)
908 break;
909
910 *best = colors [--cmap_size];
911 }
905 912
906 delete [] colors; 913 delete [] colors;
907 } 914 }
908#endif 915#endif
909 916
912 919
913void 920void
914rxvt_color::get (rgba &color) const 921rxvt_color::get (rgba &color) const
915{ 922{
916#if XFT 923#if XFT
924 //TODO premultiplied alpha??
917 color.r = c.color.red; 925 color.r = c.color.red;
918 color.g = c.color.green; 926 color.g = c.color.green;
919 color.b = c.color.blue; 927 color.b = c.color.blue;
920 color.a = c.color.alpha; 928 color.a = c.color.alpha;
921#else 929#else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines