comparison src/video/Xext/XmuStdCmap/Distinct.c @ 2185:2032348afed1

This code adds support for DirectColor visuals to SDL 1.3. The support uses part of the Xmu library. To ensure that the library is available and to keep people form having to install yet another library I have added the essential parts of Xmu in src/video/extensions/XmuStdCmap and an include file in src/video/extensions. The support makes use of standard X11 mechanisms to create color maps and make sure that an application uses the same color map for each window/visual combination. This should make it possible for gamma support to be implemented based on a single color map per application. Hurm... it looks like "make indent" modified a few extra files. Those are getting committed too.
author Bob Pendleton <bob@pendleton.com>
date Thu, 12 Jul 2007 20:00:50 +0000
parents
children
comparison
equal deleted inserted replaced
2184:8f8516e79a13 2185:2032348afed1
1 /* $Xorg: Distinct.c,v 1.4 2001/02/09 02:03:52 xorgcvs Exp $ */
2
3 /*
4
5 Copyright 1990, 1998 The Open Group
6
7 Permission to use, copy, modify, distribute, and sell this software and its
8 documentation for any purpose is hereby granted without fee, provided that
9 the above copyright notice appear in all copies and that both that
10 copyright notice and this permission notice appear in supporting
11 documentation.
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23 Except as contained in this notice, the name of The Open Group shall not be
24 used in advertising or otherwise to promote the sale, use or other dealings
25 in this Software without prior written authorization from The Open Group.
26
27 */
28 /* $XFree86: xc/lib/Xmu/Distinct.c,v 3.5 2001/07/25 15:04:50 dawes Exp $ */
29
30 /*
31 * Author: Keith Packard, MIT X Consortium
32 */
33
34 #ifdef HAVE_CONFIG_H
35 #include <config.h>
36 #endif
37 #include <X11/Xlib.h>
38 #include <stdlib.h>
39 #include <X11/Xutil.h>
40 #include "../extensions/StdCmap.h"
41
42 /*
43 * Distinguishable colors routine. Determines if two colors are
44 * distinguishable or not. Somewhat arbitrary meaning.
45 */
46
47 #define MIN_DISTINGUISH 10000.0
48
49 Bool
50 XmuDistinguishableColors(XColor * colors, int count)
51 {
52 double deltaRed, deltaGreen, deltaBlue;
53 double dist;
54 int i, j;
55
56 for (i = 0; i < count - 1; i++)
57 for (j = i + 1; j < count; j++) {
58 deltaRed = (double) colors[i].red - (double) colors[j].red;
59 deltaGreen = (double) colors[i].green - (double) colors[j].green;
60 deltaBlue = (double) colors[i].blue - (double) colors[j].blue;
61 dist = deltaRed * deltaRed +
62 deltaGreen * deltaGreen + deltaBlue * deltaBlue;
63 if (dist <= MIN_DISTINGUISH * MIN_DISTINGUISH)
64 return False;
65 }
66 return True;
67 }
68
69 Bool
70 XmuDistinguishablePixels(Display * dpy, Colormap cmap,
71 unsigned long *pixels, int count)
72 {
73 XColor *defs;
74 int i, j;
75 Bool ret;
76
77 for (i = 0; i < count - 1; i++)
78 for (j = i + 1; j < count; j++)
79 if (pixels[i] == pixels[j])
80 return False;
81 defs = (XColor *) malloc(count * sizeof(XColor));
82 if (!defs)
83 return False;
84 for (i = 0; i < count; i++)
85 defs[i].pixel = pixels[i];
86 XQueryColors(dpy, cmap, defs, count);
87 ret = XmuDistinguishableColors(defs, count);
88 free((char *) defs);
89 return ret;
90 }