… | |
… | |
875 | |
875 | |
876 | // many kilobytes transfer per colour, but pseudocolor isn't worth |
876 | // many kilobytes transfer per colour, but pseudocolor isn't worth |
877 | // many extra optimisations. |
877 | // many extra optimisations. |
878 | XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); |
878 | XQueryColors (screen->dpy, screen->cmap, colors, cmap_size); |
879 | |
879 | |
|
|
880 | while (cmap_size) |
|
|
881 | { |
880 | int diff = 0x7fffffffUL; |
882 | int diff = 0x7fffffffUL; |
881 | XColor *best = colors; |
883 | XColor *best = colors; |
882 | |
884 | |
883 | for (int i = 0; i < cmap_size; i++) |
885 | for (int i = 0; i < cmap_size; i++) |
884 | { |
|
|
885 | int d = (squared_diff<int> (color.r >> 2, colors [i].red >> 2)) |
|
|
886 | + (squared_diff<int> (color.g >> 2, colors [i].green >> 2)) |
|
|
887 | + (squared_diff<int> (color.b >> 2, colors [i].blue >> 2)); |
|
|
888 | |
|
|
889 | if (d < diff) |
|
|
890 | { |
886 | { |
|
|
887 | int d = (squared_diff<int> (color.r >> 2, colors [i].red >> 2)) |
|
|
888 | + (squared_diff<int> (color.g >> 2, colors [i].green >> 2)) |
|
|
889 | + (squared_diff<int> (color.b >> 2, colors [i].blue >> 2)); |
|
|
890 | |
|
|
891 | if (d < diff) |
|
|
892 | { |
891 | diff = d; |
893 | diff = d; |
892 | best = colors + i; |
894 | best = colors + i; |
|
|
895 | } |
893 | } |
896 | } |
894 | } |
|
|
895 | |
897 | |
896 | //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d)\n", |
898 | //rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d,%d)\n", |
897 | // color.r, color.g, color.b, best->red, best->green, best->blue, diff); |
899 | // color.r, color.g, color.b, best->red, best->green, best->blue, diff, best - colors); |
898 | |
900 | |
899 | got = alloc (screen, rgba (best->red, best->green, best->blue)); |
901 | got = alloc (screen, rgba (best->red, best->green, best->blue)); |
|
|
902 | |
|
|
903 | if (got) |
|
|
904 | break; |
|
|
905 | |
|
|
906 | *best = colors [--cmap_size]; |
|
|
907 | } |
900 | |
908 | |
901 | delete [] colors; |
909 | delete [] colors; |
902 | } |
910 | } |
903 | #endif |
911 | #endif |
904 | |
912 | |