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.143 by sf-exg, Sat Nov 1 10:17:55 2014 UTC vs.
Revision 1.149 by root, Wed Dec 17 16:03:51 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>
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))
758 unsigned int alpha = color.a >= 0xff00 ? 0xffff : color.a; 755 unsigned int alpha = color.a >= 0xff00 ? 0xffff : color.a;
759 756
760#if XFT 757#if XFT
761 XRenderPictFormat *format; 758 XRenderPictFormat *format;
762 759
760 // not needed by XftColorAlloc, but by the other paths (ours
761 // and fallback), so just set all components here.
762 c.color.red = color.r;
763 c.color.green = color.g;
764 c.color.blue = color.b;
765 c.color.alpha = alpha;
766
763 // FUCKING Xft gets it wrong, of course, so work around it. 767 // FUCKING Xft gets it wrong, of course, so work around it.
764 // Transparency users should eat shit and die, and then 768 // Transparency users should eat shit and die, and then
765 // XRenderQueryPictIndexValues themselves plenty. 769 // XRenderQueryPictIndexValues themselves plenty.
766 if ((screen->visual->c_class == TrueColor) 770 if ((screen->visual->c_class == TrueColor)
767 && (format = XRenderFindVisualFormat (screen->dpy, screen->visual))) 771 && (format = XRenderFindVisualFormat (screen->dpy, screen->visual)))
768 { 772 {
769 // the fun lies in doing everything manually... 773 // the fun lies in doing everything manually...
770 c.color.red = color.r;
771 c.color.green = color.g;
772 c.color.blue = color.b;
773 c.color.alpha = alpha;
774 774
775 // Xft wants premultiplied alpha, but abuses the alpha channel 775 // Xft wants premultiplied alpha, but abuses the alpha channel
776 // as blend factor, and doesn't allow us to set the alpha channel 776 // as blend factor, and doesn't allow us to set the alpha channel
777 c.color.red = c.color.red * alpha / 0xffff; 777 c.color.red = c.color.red * alpha / 0xffff;
778 c.color.green = c.color.green * alpha / 0xffff; 778 c.color.green = c.color.green * alpha / 0xffff;
792 d.red = color.r; 792 d.red = color.r;
793 d.green = color.g; 793 d.green = color.g;
794 d.blue = color.b; 794 d.blue = color.b;
795 d.alpha = alpha; 795 d.alpha = alpha;
796 796
797 // XftColorAlloc always returns 100% transparent pixels(!)
797 if (XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c)) 798 if (XftColorAllocValue (screen->dpy, screen->visual, screen->cmap, &d, &c))
798 return true; 799 return true;
799 } 800 }
800#else 801#else
801 c.red = color.r; 802 c.red = color.r;
812 } 813 }
813 else if (XAllocColor (screen->dpy, screen->cmap, &c)) 814 else if (XAllocColor (screen->dpy, screen->cmap, &c))
814 return true; 815 return true;
815#endif 816#endif
816 817
817 c.pixel = (color.r + color.g + color.b) > 128*3 818 c.pixel = (color.r * 2 + color.g * 3 + color.b) >= 0x8000 * 6
818 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy)) 819 ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->dpy))
819 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy)); 820 : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->dpy));
820 821
821 return false; 822 return false;
822} 823}
880 881
881 // many kilobytes transfer per colour, but pseudocolor isn't worth 882 // many kilobytes transfer per colour, but pseudocolor isn't worth
882 // many extra optimisations. 883 // many extra optimisations.
883 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); 884 XQueryColors (screen->dpy, screen->cmap, colors, cmap_size);
884 885
886 while (cmap_size)
887 {
885 int diff = 0x7fffffffUL; 888 int diff = 0x7fffffffL;
886 XColor *best = colors; 889 XColor *best = colors;
887 890
888 for (int i = 0; i < cmap_size; i++) 891 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 { 892 {
893 // simple weighted rgb distance sucks, but keeps it simple
894 int d = abs (color.r - colors [i].red ) * 2
895 + abs (color.g - colors [i].green) * 3
896 + abs (color.b - colors [i].blue );
897
898 if (d < diff)
899 {
896 diff = d; 900 diff = d;
897 best = colors + i; 901 best = colors + i;
902 }
898 } 903 }
899 }
900 904
901 //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d)\n", 905 //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); 906 // color.r, color.g, color.b, best->red, best->green, best->blue, diff, best - colors);
903 907
904 got = alloc (screen, rgba (best->red, best->green, best->blue)); 908 got = alloc (screen, rgba (best->red, best->green, best->blue));
909
910 if (got)
911 break;
912
913 *best = colors [--cmap_size];
914 }
905 915
906 delete [] colors; 916 delete [] colors;
907 } 917 }
908#endif 918#endif
909 919
912 922
913void 923void
914rxvt_color::get (rgba &color) const 924rxvt_color::get (rgba &color) const
915{ 925{
916#if XFT 926#if XFT
927
917 color.r = c.color.red; 928 color.r = c.color.red;
918 color.g = c.color.green; 929 color.g = c.color.green;
919 color.b = c.color.blue; 930 color.b = c.color.blue;
920 color.a = c.color.alpha; 931 color.a = c.color.alpha;
932
933 if (IN_RANGE_INC (color.a, 0x0001, 0xfffe))
934 {
935 color.r = color.r * 0xffff / color.a;
936 color.g = color.g * 0xffff / color.a;
937 color.b = color.b * 0xffff / color.a;
938 }
939
921#else 940#else
941
922 color.r = c.red; 942 color.r = c.red;
923 color.g = c.green; 943 color.g = c.green;
924 color.b = c.blue; 944 color.b = c.blue;
925 color.a = rgba::MAX_CC; 945 color.a = rgba::MAX_CC;
946
926#endif 947#endif
927} 948}
928 949
929void 950void
930rxvt_color::get (XColor &color) const 951rxvt_color::get (XColor &color) const

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines