Mercurial > hg > xemacs-beta
comparison src/objects-x.c @ 424:11054d720c21 r21-2-20
Import from CVS: tag r21-2-20
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:26:11 +0200 |
parents | 697ef44129c6 |
children |
comparison
equal
deleted
inserted
replaced
423:28d9c139be4c | 424:11054d720c21 |
---|---|
26 | 26 |
27 /* Authors: Jamie Zawinski, Chuck Thompson, Ben Wing */ | 27 /* Authors: Jamie Zawinski, Chuck Thompson, Ben Wing */ |
28 | 28 |
29 #include <config.h> | 29 #include <config.h> |
30 #include "lisp.h" | 30 #include "lisp.h" |
31 #include <limits.h> | |
31 | 32 |
32 #include "console-x.h" | 33 #include "console-x.h" |
33 #include "objects-x.h" | 34 #include "objects-x.h" |
34 | 35 |
35 #include "buffer.h" | 36 #include "buffer.h" |
43 /* color instances */ | 44 /* color instances */ |
44 /************************************************************************/ | 45 /************************************************************************/ |
45 | 46 |
46 /* Replacement for XAllocColor() that tries to return the nearest | 47 /* Replacement for XAllocColor() that tries to return the nearest |
47 available color if the colormap is full. Original was from FSFmacs, | 48 available color if the colormap is full. Original was from FSFmacs, |
48 but rewritten by Jareth Hein <jareth@camelot-soft.com> 97/11/25 */ | 49 but rewritten by Jareth Hein <jareth@camelot-soft.com> 97/11/25 |
49 | 50 Modified by Lee Kindness <lkindness@csl.co.uk> 31/08/99 to handle previous |
50 /* Return value is 1 for normal success, 2 for nearest color success, | 51 total failure which was due to a read/write colorcell being the nearest |
51 3 for Non-deallocable sucess, and 0 for absolute failure (shouldn't | 52 match - tries the next nearest... |
52 happen?) */ | 53 |
54 Return value is 1 for normal success, 2 for nearest color success, | |
55 3 for Non-deallocable sucess. */ | |
53 int | 56 int |
54 allocate_nearest_color (Display *display, Colormap colormap, Visual *visual, | 57 allocate_nearest_color (Display *display, Colormap colormap, Visual *visual, |
55 XColor *color_def) | 58 XColor *color_def) |
56 { | 59 { |
57 int status; | 60 int status; |
138 } | 141 } |
139 } | 142 } |
140 } | 143 } |
141 else | 144 else |
142 { | 145 { |
146 XColor *cells = NULL; | |
147 /* JH: I can't believe there's no way to go backwards from a | |
148 colormap ID and get its visual and number of entries, but X | |
149 apparently isn't built that way... */ | |
150 int no_cells = visual->map_entries; | |
151 status = 0; | |
152 | |
143 if (XAllocColor (display, colormap, color_def) != 0) | 153 if (XAllocColor (display, colormap, color_def) != 0) |
144 status = 1; | 154 status = 1; |
145 else | 155 else while( status != 2 ) |
146 { | 156 { |
147 /* If we got to this point, the colormap is full, so we're | 157 /* If we got to this point, the colormap is full, so we're |
148 going to try and get the next closest color. The algorithm used | 158 going to try and get the next closest color. The algorithm used |
149 is a least-squares matching, which is what X uses for closest | 159 is a least-squares matching, which is what X uses for closest |
150 color matching with StaticColor visuals. */ | 160 color matching with StaticColor visuals. */ |
151 XColor *cells; | |
152 /* JH: I can't believe there's no way to go backwards from a | |
153 colormap ID and get its visual and number of entries, but X | |
154 apparently isn't built that way... */ | |
155 int no_cells = visual->map_entries; | |
156 int nearest; | 161 int nearest; |
157 long nearest_delta, trial_delta; | 162 long nearest_delta, trial_delta; |
158 int x; | 163 int x; |
159 | 164 |
160 cells = alloca_array (XColor, no_cells); | 165 if( cells == NULL ) |
161 | 166 { |
162 for (x = 0; x < no_cells; x++) | 167 cells = alloca_array (XColor, no_cells); |
163 cells[x].pixel = x; | 168 for (x = 0; x < no_cells; x++) |
164 | 169 cells[x].pixel = x; |
165 /* read the current colormap */ | 170 |
166 XQueryColors (display, colormap, cells, no_cells); | 171 /* read the current colormap */ |
172 XQueryColors (display, colormap, cells, no_cells); | |
173 } | |
174 | |
167 nearest = 0; | 175 nearest = 0; |
168 /* I'm assuming CSE so I'm not going to condense this. */ | 176 /* I'm assuming CSE so I'm not going to condense this. */ |
169 nearest_delta = ((((color_def->red >> 8) - (cells[0].red >> 8)) | 177 nearest_delta = ((((color_def->red >> 8) - (cells[0].red >> 8)) |
170 * ((color_def->red >> 8) - (cells[0].red >> 8))) | 178 * ((color_def->red >> 8) - (cells[0].red >> 8))) |
171 + | 179 + |
182 (((color_def->green >> 8) - (cells[x].green >> 8)) | 190 (((color_def->green >> 8) - (cells[x].green >> 8)) |
183 * ((color_def->green >> 8) - (cells[x].green >> 8))) | 191 * ((color_def->green >> 8) - (cells[x].green >> 8))) |
184 + | 192 + |
185 (((color_def->blue >> 8) - (cells[x].blue >> 8)) | 193 (((color_def->blue >> 8) - (cells[x].blue >> 8)) |
186 * ((color_def->blue >> 8) - (cells[x].blue >> 8)))); | 194 * ((color_def->blue >> 8) - (cells[x].blue >> 8)))); |
187 if (trial_delta < nearest_delta) | 195 |
196 /* less? Ignore cells marked as previously failing */ | |
197 if( (trial_delta < nearest_delta) && | |
198 (cells[x].pixel != ULONG_MAX) ) | |
188 { | 199 { |
189 nearest = x; | 200 nearest = x; |
190 nearest_delta = trial_delta; | 201 nearest_delta = trial_delta; |
191 } | 202 } |
192 } | 203 } |
193 color_def->red = cells[nearest].red; | 204 color_def->red = cells[nearest].red; |
194 color_def->green = cells[nearest].green; | 205 color_def->green = cells[nearest].green; |
195 color_def->blue = cells[nearest].blue; | 206 color_def->blue = cells[nearest].blue; |
196 if (XAllocColor (display, colormap, color_def) != 0) { | 207 if (XAllocColor (display, colormap, color_def) != 0) |
197 status = 2; | 208 status = 2; |
198 } else { | 209 else |
199 status = 0; /* JH: how does this happen??? DOES this happen??? */ | 210 /* LSK: Either the colour map has changed since |
200 fprintf(stderr,"allocate_nearest_color returned 0!!!\n"); | 211 * we read it, or the colour is allocated |
201 } | 212 * read/write... Mark this cmap entry so it's |
213 * ignored in the next iteration. | |
214 */ | |
215 cells[nearest].pixel = ULONG_MAX; | |
202 } | 216 } |
203 } | 217 } |
204 return status; | 218 return status; |
205 } | 219 } |
206 | 220 |
207 int | 221 int |
208 x_parse_nearest_color (struct device *d, XColor *color, Bufbyte *name, | 222 x_parse_nearest_color (struct device *d, XColor *color, Bufbyte *name, |
209 Bytecount len, Error_behavior errb) | 223 Bytecount len, Error_behavior errb) |
210 { | 224 { |
211 Display *dpy; | 225 Display *dpy = DEVICE_X_DISPLAY (d); |
212 Colormap cmap; | 226 Colormap cmap = DEVICE_X_COLORMAP (d); |
213 Visual *visual; | 227 Visual *visual = DEVICE_X_VISUAL (d); |
214 int result; | 228 int result; |
215 | |
216 dpy = DEVICE_X_DISPLAY (d); | |
217 cmap = DEVICE_X_COLORMAP(d); | |
218 visual = DEVICE_X_VISUAL (d); | |
219 | 229 |
220 xzero (*color); | 230 xzero (*color); |
221 { | 231 { |
222 CONST Extbyte *extname; | 232 CONST Extbyte *extname; |
223 Extcount extnamelen; | 233 Extcount extnamelen; |
445 | 455 |
446 return 1; | 456 return 1; |
447 } | 457 } |
448 | 458 |
449 static void | 459 static void |
450 x_mark_font_instance (struct Lisp_Font_Instance *f, | 460 x_mark_font_instance (struct Lisp_Font_Instance *f) |
451 void (*markobj) (Lisp_Object)) | 461 { |
452 { | 462 mark_object (FONT_INSTANCE_X_TRUENAME (f)); |
453 markobj (FONT_INSTANCE_X_TRUENAME (f)); | |
454 } | 463 } |
455 | 464 |
456 static void | 465 static void |
457 x_print_font_instance (struct Lisp_Font_Instance *f, | 466 x_print_font_instance (struct Lisp_Font_Instance *f, |
458 Lisp_Object printcharfun, | 467 Lisp_Object printcharfun, |