]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/xpm/rgb.c
2 * Copyright (C) 1989-95 GROUPE BULL
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to
6 * deal in the Software without restriction, including without limitation the
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * GROUPE BULL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 * Except as contained in this notice, the name of GROUPE BULL shall not be
22 * used in advertising or otherwise to promote the sale, use or other dealings
23 * in this Software without prior written authorization from GROUPE BULL.
26 /*****************************************************************************\
30 * Rgb file utilities *
32 * Developed by Arnaud Le Hors *
33 \*****************************************************************************/
36 * The code related to FOR_MSW has been added by
37 * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
41 * Part of this code has been taken from the ppmtoxpm.c file written by Mark
42 * W. Snitily but has been modified for my special need
48 #include "rgbtab.h" /* hard coded rgb.txt table */
51 xpmReadRgbNames(rgb_fname
, rgbn
)
56 * check for consistency???
57 * table has to be sorted for calls on strcasecmp
59 return (numTheRGBRecords
);
63 * MSW rgb values are made from 3 BYTEs, this is different from X XColor.red,
64 * which has something like #0303 for one color
67 /* portable rgb values have 16 bit unsigned value range for each color these are promoted from the table */
70 xpmGetRgbName(rgbn
, rgbn_max
, red
, green
, blue
)
71 xpmRgbName rgbn
[]; /* rgb mnemonics from rgb text file
73 int rgbn_max
; /* not used */
74 int red
, green
, blue
; /* rgb values */
81 while (i
< numTheRGBRecords
) {
82 rgbVal
= theRGBRecords
[i
].rgb
;
83 if (GetRValue(rgbVal
) == red
&&
84 GetGValue(rgbVal
) == green
&&
85 GetBValue(rgbVal
) == blue
)
86 return (theRGBRecords
[i
].name
);
92 /* used in XParseColor in simx.c */
94 xpmGetRGBfromName(inname
, r
, g
, b
)
98 int left
, right
, middle
;
100 unsigned long rgbVal
;
104 name
= xpmstrdup(inname
);
107 * the table in rgbtab.c has no names with spaces, and no grey, but a
110 /* so first extract ' ' */
111 while ((p
= strchr(name
, ' '))!=NULL
) {
112 while (*(p
)) { /* till eof of string */
113 *p
= *(p
+ 1); /* copy to the left */
117 /* fold to lower case */
125 * substitute Grey with Gray, else rgbtab.h would have more than 100
126 * 'duplicate' entries
128 if ((grey
= strstr(name
, "grey"))!=NULL
)
133 right
= numTheRGBRecords
- 1;
135 middle
= (left
+ right
) / 2;
136 cmp
= xpmstrcasecmp(name
, theRGBRecords
[middle
].name
);
138 rgbVal
= theRGBRecords
[middle
].rgb
;
139 *r
= GetRValue(rgbVal
);
140 *g
= GetGValue(rgbVal
);
141 *b
= GetBValue(rgbVal
);
144 } else if (cmp
< 0) {
149 } while (left
<= right
);
152 * I don't like to run in a ColorInvalid error and to see no pixmap at
153 * all, so simply return a red pixel. Should be wrapped in an #ifdef
160 *b
= 0; /* red error pixel */
164 *b
= 0; /* red error pixel */
171 xpmFreeRgbNames(rgbn
, rgbn_max
)