]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | #define _GNU_SOURCE |
1f0299c1 KB |
2 | #include "../gdk_imlib/gdk_imlib.h" |
3 | #include "../gdk_imlib/gdk_imlib_private.h" | |
c801d85f KB |
4 | |
5 | gint | |
6 | gdk_imlib_get_render_type() | |
7 | { | |
8 | if (id) | |
9 | return id->render_type; | |
10 | else | |
11 | return -1; | |
12 | } | |
13 | ||
14 | void | |
15 | gdk_imlib_set_render_type(gint rend_type) | |
16 | { | |
17 | if (id) | |
18 | { | |
19 | if (id->x.depth > 8) | |
20 | id->render_type = rend_type; | |
21 | else | |
22 | { | |
23 | if ((rend_type == RT_PLAIN_TRUECOL) || | |
24 | (rend_type == RT_DITHER_TRUECOL)) | |
25 | id->render_type = RT_DITHER_PALETTE_FAST; | |
26 | else | |
27 | id->render_type = rend_type; | |
28 | } | |
29 | return; | |
30 | } | |
31 | else | |
32 | return; | |
33 | } | |
34 | ||
35 | static void | |
36 | gdk_imlib_set_fast_render(ImlibData * id, Display * disp) | |
37 | { | |
38 | /* Turn off fastrender if there is an endianess diff between */ | |
39 | /* client and Xserver */ | |
40 | int byt, bit; | |
41 | ||
42 | byt = ImageByteOrder(id->x.disp); /* LSBFirst | MSBFirst */ | |
43 | bit = BitmapBitOrder(id->x.disp); /* LSBFirst | MSBFirst */ | |
44 | /* if little endian && server big */ | |
45 | if (htonl(1) != 1 && byt == MSBFirst) | |
46 | id->fastrend = 0; | |
47 | /* if big endian && server little */ | |
48 | if (htonl(1) == 1 && byt == LSBFirst) | |
49 | id->fastrend = 0; | |
50 | } | |
51 | ||
52 | static int | |
53 | gdk_imlib_set_color_map(ImlibData * id, Display * disp) | |
54 | { | |
55 | XSetWindowAttributes at; | |
56 | unsigned long mask; | |
57 | int newcm = 0; | |
58 | ||
59 | at.border_pixel = 0; | |
60 | at.backing_store = NotUseful; | |
61 | at.background_pixel = 0; | |
62 | at.save_under = False; | |
63 | at.override_redirect = True; | |
64 | mask = CWOverrideRedirect | CWBackPixel | CWBorderPixel | | |
65 | CWBackingStore | CWSaveUnder; | |
66 | newcm = 0; | |
67 | if (id->x.visual != DefaultVisual(disp, id->x.screen)) | |
68 | { | |
69 | Colormap cm; | |
70 | ||
71 | cm = XCreateColormap(id->x.disp, id->x.root, | |
72 | id->x.visual, AllocNone); | |
73 | if (cm) | |
74 | { | |
75 | mask |= CWColormap; | |
76 | id->x.root_cmap = cm; | |
77 | at.colormap = cm; | |
78 | newcm = 1; | |
79 | } | |
80 | } | |
81 | id->x.base_window = XCreateWindow(id->x.disp, id->x.root, | |
82 | -100, -100, 10, 10, 0, | |
83 | id->x.depth, InputOutput, | |
84 | id->x.visual, mask, &at); | |
85 | id->x.gdk_win = gdk_window_foreign_new(id->x.base_window); | |
86 | if (newcm) | |
87 | id->x.gdk_cmap = gdk_colormap_new(gdk_window_get_visual | |
88 | (id->x.gdk_win), FALSE); | |
89 | else | |
90 | id->x.gdk_cmap = gdk_colormap_get_system(); | |
91 | return newcm; | |
92 | } | |
93 | ||
94 | void | |
95 | gdk_imlib_init() | |
96 | { | |
97 | Display *disp; | |
98 | XWindowAttributes xwa; | |
99 | XVisualInfo xvi, *xvir; | |
100 | char *homedir; | |
101 | char s[4096]; | |
102 | char *s1; | |
103 | char *s2; | |
104 | FILE *f; | |
105 | int override = 0; | |
106 | int dither = 0; | |
107 | int remap = 1; | |
108 | int num; | |
109 | int i, max, maxn; | |
110 | int clas; | |
111 | char *palfile = NULL; | |
112 | int loadpal; | |
113 | int vis; | |
114 | int newcm; | |
115 | ||
116 | disp = (Display *) gdk_display; | |
117 | if (!disp) | |
118 | { | |
119 | fprintf(stderr, "gdk_imlib ERROR: gdk has not connected to the display\n"); | |
120 | return; | |
121 | } | |
122 | vis = -1; | |
123 | loadpal = 0; | |
124 | if (id) | |
125 | return; | |
126 | id = (ImlibData *) malloc(sizeof(ImlibData)); | |
127 | if (!id) | |
128 | { | |
129 | fprintf(stderr, "gdk_imlib ERROR: Cannot alloc RAM for Initial data struct\n"); | |
130 | return; | |
131 | } | |
132 | id->palette = NULL; | |
133 | id->palette_orig = NULL; | |
134 | id->fast_rgb = NULL; | |
135 | id->fast_err = NULL; | |
136 | id->fast_erg = NULL; | |
137 | id->fast_erb = NULL; | |
138 | id->x.disp = disp; | |
139 | id->x.screen = DefaultScreen(disp); /* the screen number */ | |
140 | id->x.root = DefaultRootWindow(disp); /* the root window id */ | |
141 | id->x.visual = DefaultVisual(disp, id->x.screen); /* the visual type */ | |
142 | id->x.depth = DefaultDepth(disp, id->x.screen); /* the depth of the screen in bpp */ | |
143 | if (XShmQueryExtension(id->x.disp)) | |
144 | { | |
145 | id->x.shm = 1; | |
146 | id->x.shm_event = XShmGetEventBase(id->x.disp) + ShmCompletion; | |
147 | id->x.last_xim = NULL; | |
148 | id->x.last_sxim = NULL; | |
149 | id->max_shm = 0x7fffffff; | |
150 | if (XShmPixmapFormat(id->x.disp) == ZPixmap) | |
151 | id->x.shmp = 1; | |
152 | } | |
153 | else | |
154 | { | |
155 | id->x.shm = 0; | |
156 | id->x.shmp = 0; | |
157 | } | |
158 | id->cache.on_image = 0; | |
159 | id->cache.size_image = 0; | |
160 | id->cache.num_image = 0; | |
161 | id->cache.used_image = 0; | |
162 | id->cache.image = NULL; | |
163 | id->cache.on_pixmap = 0; | |
164 | id->cache.size_pixmap = 0; | |
165 | id->cache.num_pixmap = 0; | |
166 | id->cache.used_pixmap = 0; | |
167 | id->cache.pixmap = NULL; | |
168 | id->byte_order = 0; | |
169 | id->fastrend = 0; | |
170 | id->hiq = 0; | |
171 | id->fallback = 1; | |
172 | id->mod.gamma = 256; | |
173 | id->mod.brightness = 256; | |
174 | id->mod.contrast = 256; | |
175 | id->rmod.gamma = 256; | |
176 | id->rmod.brightness = 256; | |
177 | id->rmod.contrast = 256; | |
178 | id->gmod.gamma = 256; | |
179 | id->gmod.brightness = 256; | |
180 | id->gmod.contrast = 256; | |
181 | id->bmod.gamma = 256; | |
182 | id->bmod.brightness = 256; | |
183 | id->bmod.contrast = 256; | |
184 | id->ordered_dither = 1; | |
185 | ||
186 | if (XGetWindowAttributes(disp, id->x.root, &xwa)) | |
187 | { | |
188 | if (xwa.colormap) | |
189 | id->x.root_cmap = xwa.colormap; | |
190 | else | |
191 | id->x.root_cmap = 0; | |
192 | } | |
193 | else | |
194 | id->x.root_cmap = 0; | |
195 | ||
196 | id->num_colors = 0; | |
197 | homedir = getenv("HOME"); | |
198 | g_snprintf(s, sizeof(s), "%s/.imrc", homedir); | |
199 | f = fopen(s, "r"); | |
200 | if (!f) | |
201 | f = fopen(SYSTEM_IMRC, "r"); | |
202 | if (f) | |
203 | { | |
204 | while (fgets(s, 4096, f)) | |
205 | { | |
206 | if (s[0] == '#') | |
207 | continue; | |
208 | ||
209 | s1 = strtok(s, " \t\n"); | |
210 | ||
211 | /* Blank line ? */ | |
212 | ||
213 | if (s1 == NULL) | |
214 | continue; | |
215 | ||
216 | s2 = strtok(NULL, " \t\n"); | |
217 | if (s2 == NULL) | |
218 | s2 = ""; /* NULL argument */ | |
219 | ||
220 | if (!strcasecmp("PaletteFile", s1)) | |
221 | { | |
222 | palfile = strdup(s2); | |
223 | } | |
224 | else if (!strcasecmp("PaletteOverride", s1)) | |
225 | { | |
226 | if (!strcasecmp("yes", s2)) | |
227 | override = 1; | |
228 | else | |
229 | override = 0; | |
230 | } | |
231 | else if (!strcasecmp("Dither", s1)) | |
232 | { | |
233 | if (!strcasecmp("yes", s2)) | |
234 | dither = 1; | |
235 | else | |
236 | dither = 0; | |
237 | } | |
238 | else if (!strcasecmp("Remap", s1)) | |
239 | { | |
240 | if (!strcasecmp("fast", s2)) | |
241 | remap = 1; | |
242 | else | |
243 | remap = 0; | |
244 | } | |
245 | else if (!strcasecmp("Mit-Shm", s1)) | |
246 | { | |
247 | if (!strcasecmp("off", s2)) | |
248 | { | |
249 | id->x.shm = 0; | |
250 | id->x.shmp = 0; | |
251 | } | |
252 | } | |
253 | else if (!strcasecmp("SharedPixmaps", s1)) | |
254 | { | |
255 | if (!strcasecmp("off", s2)) | |
256 | id->x.shmp = 0; | |
257 | } | |
258 | else if (!strcasecmp("FastRender", s1)) | |
259 | { | |
260 | if (!strcasecmp("on", s2)) | |
261 | id->fastrend = 1; | |
262 | } | |
263 | else if (!strcasecmp("HighQuality", s1)) | |
264 | { | |
265 | if (!strcasecmp("on", s2)) | |
266 | id->hiq = 1; | |
267 | } | |
268 | else if (!strcasecmp("Shm_Max_Size", s1)) | |
269 | { | |
270 | num = atoi(s2); | |
271 | id->max_shm = num; | |
272 | } | |
273 | else if (!strcasecmp("Image_Cache_Size", s1)) | |
274 | { | |
275 | num = atoi(s2); | |
276 | id->cache.size_image = num; | |
277 | } | |
278 | else if (!strcasecmp("Pixmap_Cache_Size", s1)) | |
279 | { | |
280 | num = atoi(s2); | |
281 | id->cache.size_pixmap = num; | |
282 | } | |
283 | else if (!strcasecmp("Image_Cache", s1)) | |
284 | { | |
285 | if (!strcasecmp("on", s2)) | |
286 | id->cache.on_image = 1; | |
287 | } | |
288 | else if (!strcasecmp("Pixmap_Cache", s1)) | |
289 | { | |
290 | if (!strcasecmp("on", s2)) | |
291 | id->cache.on_pixmap = 1; | |
292 | } | |
293 | else if (!strcasecmp("ForceVisualID", s1)) | |
294 | { | |
295 | sscanf(s, "%1024s %x", s1, &num); | |
296 | vis = num; | |
297 | } | |
298 | else if (!strcasecmp("Fallback", s1)) | |
299 | { | |
300 | if (!strcasecmp("off", s2)) | |
301 | id->fallback = 0; | |
302 | else | |
303 | id->fallback = 1; | |
304 | } | |
305 | else if (!strcasecmp("Gamma", s1)) | |
306 | { | |
307 | id->mod.gamma = (int)(256.0 * atof(s2)); | |
308 | } | |
309 | else if (!strcasecmp("Brightness", s1)) | |
310 | { | |
311 | id->mod.brightness = (int)(256.0 * atof(s2)); | |
312 | } | |
313 | else if (!strcasecmp("Contrast", s1)) | |
314 | { | |
315 | id->mod.contrast = (int)(256.0 * atof(s2)); | |
316 | } | |
317 | else if (!strcasecmp("Red_Gamma", s1)) | |
318 | { | |
319 | id->rmod.gamma = (int)(256.0 * atof(s2)); | |
320 | } | |
321 | else if (!strcasecmp("Red_Brightness", s1)) | |
322 | { | |
323 | id->rmod.brightness = (int)(256.0 * atof(s2)); | |
324 | } | |
325 | else if (!strcasecmp("Red_Contrast", s1)) | |
326 | { | |
327 | id->rmod.contrast = (int)(256.0 * atof(s2)); | |
328 | } | |
329 | else if (!strcasecmp("Green_Gamma", s1)) | |
330 | { | |
331 | id->gmod.gamma = (int)(256.0 * atof(s2)); | |
332 | } | |
333 | else if (!strcasecmp("Green_Brightness", s1)) | |
334 | { | |
335 | id->gmod.brightness = (int)(256.0 * atof(s2)); | |
336 | } | |
337 | else if (!strcasecmp("Green_Contrast", s1)) | |
338 | { | |
339 | id->gmod.contrast = (int)(256.0 * atof(s2)); | |
340 | } | |
341 | else if (!strcasecmp("Blue_Gamma", s1)) | |
342 | { | |
343 | id->bmod.gamma = (int)(256.0 * atof(s2)); | |
344 | } | |
345 | else if (!strcasecmp("Blue_Brightness", s1)) | |
346 | { | |
347 | id->bmod.brightness = (int)(256.0 * atof(s2)); | |
348 | } | |
349 | else if (!strcasecmp("Blue_Contrast", s1)) | |
350 | { | |
351 | id->bmod.contrast = (int)(256.0 * atof(s2)); | |
352 | } | |
353 | else if (!strcasecmp("Ordered_Dither", s1)) | |
354 | { | |
355 | if (!strcasecmp("off", s2)) | |
356 | id->ordered_dither = 0; | |
357 | else | |
358 | id->ordered_dither = 1; | |
359 | } | |
360 | } | |
361 | fclose(f); | |
362 | } | |
363 | /* list all visuals for the default screen */ | |
364 | xvi.screen = id->x.screen; | |
365 | xvir = XGetVisualInfo(disp, VisualScreenMask, &xvi, &num); | |
366 | if (vis >= 0) | |
367 | { | |
368 | /* use the forced visual id */ | |
369 | maxn = 0; | |
370 | for (i = 0; i < num; i++) | |
371 | { | |
372 | if (xvir[i].visualid == (VisualID) vis) | |
373 | maxn = i; | |
374 | } | |
375 | if (maxn >= 0) | |
376 | { | |
377 | unsigned long rmsk, gmsk, bmsk; | |
378 | ||
379 | id->x.depth = xvir[maxn].depth; | |
380 | id->x.visual = xvir[maxn].visual; | |
381 | rmsk = xvir[maxn].red_mask; | |
382 | gmsk = xvir[maxn].green_mask; | |
383 | bmsk = xvir[maxn].blue_mask; | |
384 | ||
385 | if ((rmsk > gmsk) && (gmsk > bmsk)) | |
386 | id->byte_order = BYTE_ORD_24_RGB; | |
387 | else if ((rmsk > bmsk) && (bmsk > gmsk)) | |
388 | id->byte_order = BYTE_ORD_24_RBG; | |
389 | else if ((bmsk > rmsk) && (rmsk > gmsk)) | |
390 | id->byte_order = BYTE_ORD_24_BRG; | |
391 | else if ((bmsk > gmsk) && (gmsk > rmsk)) | |
392 | id->byte_order = BYTE_ORD_24_BGR; | |
393 | else if ((gmsk > rmsk) && (rmsk > bmsk)) | |
394 | id->byte_order = BYTE_ORD_24_GRB; | |
395 | else if ((gmsk > bmsk) && (bmsk > rmsk)) | |
396 | id->byte_order = BYTE_ORD_24_GBR; | |
397 | else | |
398 | id->byte_order = 0; | |
399 | } | |
400 | else | |
401 | fprintf(stderr, "Visual Id no 0x%x specified in the imrc file is invalid on this display.\nUsing Default Visual.\n", vis); | |
402 | } | |
403 | else | |
404 | { | |
405 | if (xvir) | |
406 | { | |
407 | /* find the highest bit-depth supported by visuals */ | |
408 | max = 0; | |
409 | for (i = 0; i < num; i++) | |
410 | { | |
411 | if (xvir[i].depth > max) | |
412 | max = xvir[i].depth; | |
413 | } | |
414 | if (max > 8) | |
415 | { | |
416 | id->x.depth = max; | |
417 | clas = -1; | |
418 | maxn = -1; | |
419 | for (i = 0; i < num; i++) | |
420 | { | |
421 | if (xvir[i].depth == id->x.depth) | |
422 | { | |
423 | if ((xvir[i].class > clas) && (xvir[i].class != DirectColor)) | |
424 | { | |
425 | maxn = i; | |
426 | clas = xvir[i].class; | |
427 | } | |
428 | } | |
429 | } | |
430 | if (maxn >= 0) | |
431 | { | |
432 | unsigned long rmsk, gmsk, bmsk; | |
433 | ||
434 | id->x.visual = xvir[maxn].visual; | |
435 | rmsk = xvir[maxn].red_mask; | |
436 | gmsk = xvir[maxn].green_mask; | |
437 | bmsk = xvir[maxn].blue_mask; | |
438 | ||
439 | if ((rmsk > gmsk) && (gmsk > bmsk)) | |
440 | id->byte_order = BYTE_ORD_24_RGB; | |
441 | else if ((rmsk > bmsk) && (bmsk > gmsk)) | |
442 | id->byte_order = BYTE_ORD_24_RBG; | |
443 | else if ((bmsk > rmsk) && (rmsk > gmsk)) | |
444 | id->byte_order = BYTE_ORD_24_BRG; | |
445 | else if ((bmsk > gmsk) && (gmsk > rmsk)) | |
446 | id->byte_order = BYTE_ORD_24_BGR; | |
447 | else if ((gmsk > rmsk) && (rmsk > bmsk)) | |
448 | id->byte_order = BYTE_ORD_24_GRB; | |
449 | else if ((gmsk > bmsk) && (bmsk > rmsk)) | |
450 | id->byte_order = BYTE_ORD_24_GBR; | |
451 | else | |
452 | id->byte_order = 0; | |
453 | } | |
454 | } | |
455 | } | |
456 | } | |
457 | id->x.render_depth = id->x.depth; | |
458 | XFree(xvir); | |
459 | ||
460 | if (id->x.depth == 16) | |
461 | { | |
462 | xvi.visual = id->x.visual; | |
463 | xvi.visualid = XVisualIDFromVisual(id->x.visual); | |
464 | xvir = XGetVisualInfo(disp, VisualIDMask, &xvi, &num); | |
465 | if (xvir) | |
466 | { | |
467 | if (xvir->red_mask != 0xf800) | |
468 | id->x.render_depth = 15; | |
469 | XFree(xvir); | |
470 | } | |
471 | } | |
472 | if (id->x.depth <= 8 || override == 1) | |
473 | loadpal = 1; | |
474 | ||
475 | if (loadpal) | |
476 | { | |
477 | if (dither == 1) | |
478 | { | |
479 | if (remap == 1) | |
480 | id->render_type = RT_DITHER_PALETTE_FAST; | |
481 | else | |
482 | id->render_type = RT_DITHER_PALETTE; | |
483 | } | |
484 | else | |
485 | { | |
486 | if (remap == 1) | |
487 | id->render_type = RT_PLAIN_PALETTE_FAST; | |
488 | else | |
489 | id->render_type = RT_PLAIN_PALETTE; | |
490 | } | |
491 | /* Should we error this case or default it nicely */ | |
492 | if (palfile != NULL) | |
493 | gdk_imlib_load_colors(palfile); | |
494 | if (id->num_colors == 0) | |
495 | { | |
496 | fprintf(stderr, "gdk_imlib: Cannot Find Palette. A Palette is required for this mode\n"); | |
497 | free(id); | |
498 | id = NULL; | |
499 | if (palfile) | |
500 | free(palfile); | |
501 | return; | |
502 | } | |
503 | } | |
504 | else | |
505 | { | |
506 | if (id->hiq == 1) | |
507 | id->render_type = RT_DITHER_TRUECOL; | |
508 | else | |
509 | id->render_type = RT_PLAIN_TRUECOL; | |
510 | } | |
511 | ||
512 | newcm = gdk_imlib_set_color_map(id, disp); | |
513 | ||
514 | gdk_imlib_set_fast_render(id, disp); | |
515 | ||
516 | if (palfile) | |
517 | free(palfile); | |
518 | } | |
519 | ||
520 | void | |
521 | gdk_imlib_init_params(GdkImlibInitParams * p) | |
522 | { | |
523 | Display *disp; | |
524 | XWindowAttributes xwa; | |
525 | XVisualInfo xvi, *xvir; | |
526 | char *homedir; | |
bd7d06f2 | 527 | /* char file[4096]; */ |
c801d85f KB |
528 | char s[4096], *s1, *s2; |
529 | FILE *f; | |
530 | int override = 0; | |
531 | int dither = 0; | |
532 | int remap = 1; | |
533 | int num; | |
534 | int i, max, maxn; | |
535 | int clas; | |
bd7d06f2 | 536 | char *palfile = NULL; |
c801d85f KB |
537 | int loadpal; |
538 | int vis; | |
539 | int newcm; | |
540 | ||
541 | disp = (Display *) gdk_display; | |
542 | if (!disp) | |
543 | { | |
544 | fprintf(stderr, "gdk_imlib ERROR: gdk has not connected to the display\n"); | |
545 | return; | |
546 | } | |
547 | vis = -1; | |
548 | loadpal = 0; | |
549 | if (id) | |
550 | return; | |
551 | id = (ImlibData *) malloc(sizeof(ImlibData)); | |
552 | if (!id) | |
553 | { | |
554 | fprintf(stderr, "gdk_imlib ERROR: Cannot alloc RAM for Initial data struct\n"); | |
555 | return; | |
556 | } | |
557 | id->palette = NULL; | |
558 | id->palette_orig = NULL; | |
559 | id->fast_rgb = NULL; | |
560 | id->fast_err = NULL; | |
561 | id->fast_erg = NULL; | |
562 | id->fast_erb = NULL; | |
563 | id->x.disp = disp; | |
564 | id->x.screen = DefaultScreen(disp); /* the screen number */ | |
565 | id->x.root = DefaultRootWindow(disp); /* the root window id */ | |
566 | id->x.visual = DefaultVisual(disp, id->x.screen); /* the visual type */ | |
567 | id->x.depth = DefaultDepth(disp, id->x.screen); /* the depth of the screen in bpp */ | |
568 | if (XShmQueryExtension(id->x.disp)) | |
569 | { | |
570 | id->x.shm = 1; | |
571 | id->x.shm_event = XShmGetEventBase(id->x.disp) + ShmCompletion; | |
572 | id->x.last_xim = NULL; | |
573 | id->x.last_sxim = NULL; | |
574 | id->max_shm = 0x7fffffff; | |
575 | if (XShmPixmapFormat(id->x.disp) == ZPixmap) | |
576 | id->x.shmp = 1; | |
577 | } | |
578 | else | |
579 | { | |
580 | id->x.shm = 0; | |
581 | id->x.shmp = 0; | |
582 | } | |
583 | id->cache.on_image = 0; | |
584 | id->cache.size_image = 0; | |
585 | id->cache.num_image = 0; | |
586 | id->cache.used_image = 0; | |
587 | id->cache.image = NULL; | |
588 | id->cache.on_pixmap = 0; | |
589 | id->cache.size_pixmap = 0; | |
590 | id->cache.num_pixmap = 0; | |
591 | id->cache.used_pixmap = 0; | |
592 | id->cache.pixmap = NULL; | |
593 | id->byte_order = 0; | |
594 | id->fastrend = 0; | |
595 | id->hiq = 0; | |
596 | id->fallback = 1; | |
597 | id->mod.gamma = 256; | |
598 | id->mod.brightness = 256; | |
599 | id->mod.contrast = 256; | |
600 | id->rmod.gamma = 256; | |
601 | id->rmod.brightness = 256; | |
602 | id->rmod.contrast = 256; | |
603 | id->gmod.gamma = 256; | |
604 | id->gmod.brightness = 256; | |
605 | id->gmod.contrast = 256; | |
606 | id->bmod.gamma = 256; | |
607 | id->bmod.brightness = 256; | |
608 | id->bmod.contrast = 256; | |
609 | ||
610 | if (XGetWindowAttributes(disp, id->x.root, &xwa)) | |
611 | { | |
612 | if (xwa.colormap) | |
613 | id->x.root_cmap = xwa.colormap; | |
614 | else | |
615 | id->x.root_cmap = 0; | |
616 | } | |
617 | else | |
618 | id->x.root_cmap = 0; | |
619 | id->num_colors = 0; | |
620 | homedir = getenv("HOME"); | |
621 | g_snprintf(s, sizeof(s), "%s/.imrc", homedir); | |
622 | f = fopen(s, "r"); | |
623 | if (!f) | |
624 | f = fopen(SYSTEM_IMRC, "r"); | |
625 | if (f) | |
626 | { | |
627 | while (fgets(s, 4096, f)) | |
628 | { | |
629 | if (s[0] == '#') | |
630 | continue; | |
631 | ||
632 | s1 = strtok(s, " \t\n"); | |
633 | ||
634 | /* Blank line ? */ | |
635 | ||
636 | if (s1 == NULL) | |
637 | continue; | |
638 | ||
639 | s2 = strtok(NULL, " \t\n"); | |
640 | if (s2 == NULL) | |
641 | s2 = ""; /* NULL argument */ | |
642 | ||
643 | if (!strcasecmp("PaletteFile", s1)) | |
644 | { | |
645 | palfile = strdup(s2); | |
646 | } | |
647 | else if (!strcasecmp("PaletteOverride", s1)) | |
648 | { | |
649 | if (!strcasecmp("yes", s2)) | |
650 | override = 1; | |
651 | else | |
652 | override = 0; | |
653 | } | |
654 | else if (!strcasecmp("Dither", s1)) | |
655 | { | |
656 | if (!strcasecmp("yes", s2)) | |
657 | dither = 1; | |
658 | else | |
659 | dither = 0; | |
660 | } | |
661 | else if (!strcasecmp("Remap", s1)) | |
662 | { | |
663 | if (!strcasecmp("fast", s2)) | |
664 | remap = 1; | |
665 | else | |
666 | remap = 0; | |
667 | } | |
668 | else if (!strcasecmp("Mit-Shm", s1)) | |
669 | { | |
670 | if (!strcasecmp("off", s2)) | |
671 | { | |
672 | id->x.shm = 0; | |
673 | id->x.shmp = 0; | |
674 | } | |
675 | } | |
676 | else if (!strcasecmp("SharedPixmaps", s1)) | |
677 | { | |
678 | if (!strcasecmp("off", s2)) | |
679 | id->x.shmp = 0; | |
680 | } | |
681 | else if (!strcasecmp("FastRender", s1)) | |
682 | { | |
683 | if (!strcasecmp("on", s2)) | |
684 | id->fastrend = 1; | |
685 | } | |
686 | else if (!strcasecmp("HighQuality", s1)) | |
687 | { | |
688 | if (!strcasecmp("on", s2)) | |
689 | id->hiq = 1; | |
690 | } | |
691 | else if (!strcasecmp("Shm_Max_Size", s1)) | |
692 | { | |
693 | num = atoi(s2); | |
694 | id->max_shm = num; | |
695 | } | |
696 | if (!strcasecmp("Image_Cache_Size", s1)) | |
697 | { | |
698 | num = atoi(s2); | |
699 | id->cache.size_image = num; | |
700 | } | |
701 | else if (!strcasecmp("Pixmap_Cache_Size", s1)) | |
702 | { | |
703 | num = atoi(s2); | |
704 | id->cache.size_pixmap = num; | |
705 | } | |
706 | else if (!strcasecmp("Image_Cache", s1)) | |
707 | { | |
708 | if (!strcasecmp("on", s2)) | |
709 | id->cache.on_image = 1; | |
710 | } | |
711 | else if (!strcasecmp("Pixmap_Cache", s1)) | |
712 | { | |
713 | if (!strcasecmp("on", s2)) | |
714 | id->cache.on_pixmap = 1; | |
715 | } | |
716 | else if (!strcasecmp("ForceVisualID", s1)) | |
717 | { | |
718 | sscanf(s, "%1024s %x", s1, &num); | |
719 | vis = num; | |
720 | } | |
721 | else if (!strcasecmp("Fallback", s1)) | |
722 | { | |
723 | if (!strcasecmp("off", s2)) | |
724 | id->fallback = 0; | |
725 | else | |
726 | id->fallback = 1; | |
727 | } | |
728 | else if (!strcasecmp("Gamma", s1)) | |
729 | { | |
730 | id->mod.gamma = (int)(256.0 * atof(s2)); | |
731 | } | |
732 | else if (!strcasecmp("Brightness", s1)) | |
733 | { | |
734 | id->mod.brightness = (int)(256.0 * atof(s2)); | |
735 | } | |
736 | else if (!strcasecmp("Contrast", s1)) | |
737 | { | |
738 | id->mod.contrast = (int)(256.0 * atof(s2)); | |
739 | } | |
740 | else if (!strcasecmp("Red_Gamma", s1)) | |
741 | { | |
742 | id->rmod.gamma = (int)(256.0 * atof(s2)); | |
743 | } | |
744 | else if (!strcasecmp("Red_Brightness", s1)) | |
745 | { | |
746 | id->rmod.brightness = (int)(256.0 * atof(s2)); | |
747 | } | |
748 | else if (!strcasecmp("Red_Contrast", s1)) | |
749 | { | |
750 | id->rmod.contrast = (int)(256.0 * atof(s2)); | |
751 | } | |
752 | else if (!strcasecmp("Green_Gamma", s1)) | |
753 | { | |
754 | id->gmod.gamma = (int)(256.0 * atof(s2)); | |
755 | } | |
756 | else if (!strcasecmp("Green_Brightness", s1)) | |
757 | { | |
758 | id->gmod.brightness = (int)(256.0 * atof(s2)); | |
759 | } | |
760 | else if (!strcasecmp("Green_Contrast", s1)) | |
761 | { | |
762 | id->gmod.contrast = (int)(256.0 * atof(s2)); | |
763 | } | |
764 | else if (!strcasecmp("Blue_Gamma", s1)) | |
765 | { | |
766 | id->bmod.gamma = (int)(256.0 * atof(s2)); | |
767 | } | |
768 | else if (!strcasecmp("Blue_Brightness", s1)) | |
769 | { | |
770 | id->bmod.brightness = (int)(256.0 * atof(s2)); | |
771 | } | |
772 | else if (!strcasecmp("Blue_Contrast", s1)) | |
773 | { | |
774 | id->bmod.contrast = (int)(256.0 * atof(s2)); | |
775 | } | |
776 | else if (!strcasecmp("Ordered_Dither", s1)) | |
777 | { | |
778 | if (!strcasecmp("off", s2)) | |
779 | id->ordered_dither = 0; | |
780 | else | |
781 | id->ordered_dither = 1; | |
782 | } | |
783 | } | |
784 | fclose(f); | |
785 | } | |
786 | if (p) | |
787 | { | |
788 | if (p->flags & PARAMS_VISUALID) | |
789 | vis = p->visualid; | |
790 | if (p->flags & PARAMS_PALETTEFILE) | |
791 | palfile = strdup(p->palettefile); | |
792 | if (p->flags & PARAMS_SHAREDMEM) | |
793 | { | |
794 | if (!p->sharedmem) | |
795 | { | |
796 | id->x.shm = 0; | |
797 | id->x.shmp = 0; | |
798 | } | |
799 | else | |
800 | { | |
801 | id->x.shm = 1; | |
802 | id->x.shmp = 0; | |
803 | } | |
804 | } | |
805 | if (p->flags & PARAMS_SHAREDPIXMAPS) | |
806 | { | |
807 | if (id->x.shm) | |
808 | id->x.shmp = p->sharedpixmaps; | |
809 | } | |
810 | if (p->flags & PARAMS_PALETTEOVERRIDE) | |
811 | override = p->paletteoverride; | |
812 | if (p->flags & PARAMS_REMAP) | |
813 | remap = p->remap; | |
814 | if (p->flags & PARAMS_FASTRENDER) | |
815 | id->fastrend = p->fastrender; | |
816 | if (p->flags & PARAMS_HIQUALITY) | |
817 | id->hiq = p->hiquality; | |
818 | if (p->flags & PARAMS_DITHER) | |
819 | dither = p->dither; | |
820 | if (p->flags & PARAMS_IMAGECACHESIZE) | |
821 | id->cache.size_image = p->imagecachesize; | |
822 | if (p->flags & PARAMS_PIXMAPCACHESIZE) | |
823 | id->cache.size_pixmap = p->pixmapcachesize; | |
824 | } | |
825 | /* list all visuals for the default screen */ | |
826 | xvi.screen = id->x.screen; | |
827 | xvir = XGetVisualInfo(disp, VisualScreenMask, &xvi, &num); | |
828 | if (vis >= 0) | |
829 | { | |
830 | /* use the forced visual id */ | |
831 | maxn = 0; | |
832 | for (i = 0; i < num; i++) | |
833 | { | |
834 | if (xvir[i].visualid == (VisualID) vis) | |
835 | maxn = i; | |
836 | } | |
837 | if (maxn >= 0) | |
838 | { | |
839 | unsigned long rmsk, gmsk, bmsk; | |
840 | ||
841 | id->x.depth = xvir[maxn].depth; | |
842 | id->x.visual = xvir[maxn].visual; | |
843 | rmsk = xvir[maxn].red_mask; | |
844 | gmsk = xvir[maxn].green_mask; | |
845 | bmsk = xvir[maxn].blue_mask; | |
846 | ||
847 | if ((rmsk > gmsk) && (gmsk > bmsk)) | |
848 | id->byte_order = BYTE_ORD_24_RGB; | |
849 | else if ((rmsk > bmsk) && (bmsk > gmsk)) | |
850 | id->byte_order = BYTE_ORD_24_RBG; | |
851 | else if ((bmsk > rmsk) && (rmsk > gmsk)) | |
852 | id->byte_order = BYTE_ORD_24_BRG; | |
853 | else if ((bmsk > gmsk) && (gmsk > rmsk)) | |
854 | id->byte_order = BYTE_ORD_24_BGR; | |
855 | else if ((gmsk > rmsk) && (rmsk > bmsk)) | |
856 | id->byte_order = BYTE_ORD_24_GRB; | |
857 | else if ((gmsk > bmsk) && (bmsk > rmsk)) | |
858 | id->byte_order = BYTE_ORD_24_GBR; | |
859 | else | |
860 | id->byte_order = 0; | |
861 | } | |
862 | else | |
863 | fprintf(stderr, "Visual Id no 0x%x specified in the imrc file is invalid on this display.\nUsing Default Visual.\n", vis); | |
864 | } | |
865 | else | |
866 | { | |
867 | if (xvir) | |
868 | { | |
869 | /* find the highest bit-depth supported by visuals */ | |
870 | max = 0; | |
871 | for (i = 0; i < num; i++) | |
872 | { | |
873 | if (xvir[i].depth > max) | |
874 | max = xvir[i].depth; | |
875 | } | |
876 | if (max > 8) | |
877 | { | |
878 | id->x.depth = max; | |
879 | clas = -1; | |
880 | maxn = -1; | |
881 | for (i = 0; i < num; i++) | |
882 | { | |
883 | if (xvir[i].depth == id->x.depth) | |
884 | { | |
885 | if ((xvir[i].class > clas) && (xvir[i].class != DirectColor)) | |
886 | { | |
887 | maxn = i; | |
888 | clas = xvir[i].class; | |
889 | } | |
890 | } | |
891 | } | |
892 | if (maxn >= 0) | |
893 | { | |
894 | unsigned long rmsk, gmsk, bmsk; | |
895 | ||
896 | id->x.visual = xvir[maxn].visual; | |
897 | rmsk = xvir[maxn].red_mask; | |
898 | gmsk = xvir[maxn].green_mask; | |
899 | bmsk = xvir[maxn].blue_mask; | |
900 | ||
901 | if ((rmsk > gmsk) && (gmsk > bmsk)) | |
902 | id->byte_order = BYTE_ORD_24_RGB; | |
903 | else if ((rmsk > bmsk) && (bmsk > gmsk)) | |
904 | id->byte_order = BYTE_ORD_24_RBG; | |
905 | else if ((bmsk > rmsk) && (rmsk > gmsk)) | |
906 | id->byte_order = BYTE_ORD_24_BRG; | |
907 | else if ((bmsk > gmsk) && (gmsk > rmsk)) | |
908 | id->byte_order = BYTE_ORD_24_BGR; | |
909 | else if ((gmsk > rmsk) && (rmsk > bmsk)) | |
910 | id->byte_order = BYTE_ORD_24_GRB; | |
911 | else if ((gmsk > bmsk) && (bmsk > rmsk)) | |
912 | id->byte_order = BYTE_ORD_24_GBR; | |
913 | else | |
914 | id->byte_order = 0; | |
915 | } | |
916 | } | |
917 | } | |
918 | } | |
919 | id->x.render_depth = id->x.depth; | |
920 | XFree(xvir); | |
921 | if (id->x.depth == 16) | |
922 | { | |
923 | xvi.visual = id->x.visual; | |
924 | xvi.visualid = XVisualIDFromVisual(id->x.visual); | |
925 | xvir = XGetVisualInfo(disp, VisualIDMask, &xvi, &num); | |
926 | if (xvir) | |
927 | { | |
928 | if (xvir->red_mask != 0xf800) | |
929 | id->x.render_depth = 15; | |
930 | XFree(xvir); | |
931 | } | |
932 | } | |
933 | if ((id->x.depth <= 8) || (override == 1)) | |
934 | loadpal = 1; | |
935 | if (loadpal) | |
936 | { | |
937 | if (dither == 1) | |
938 | { | |
939 | if (remap == 1) | |
940 | id->render_type = RT_DITHER_PALETTE_FAST; | |
941 | else | |
942 | id->render_type = RT_DITHER_PALETTE; | |
943 | } | |
944 | else | |
945 | { | |
946 | if (remap == 1) | |
947 | id->render_type = RT_PLAIN_PALETTE_FAST; | |
948 | else | |
949 | id->render_type = RT_PLAIN_PALETTE; | |
950 | } | |
951 | gdk_imlib_load_colors(palfile); | |
952 | if (id->num_colors == 0) | |
953 | { | |
954 | fprintf(stderr, "gdk_imlib: Cannot Find Palette. A Palette is required for this mode\n"); | |
955 | free(id); | |
956 | id = NULL; | |
957 | if (palfile) | |
958 | free(palfile); | |
959 | return; | |
960 | } | |
961 | } | |
962 | else | |
963 | { | |
964 | if (id->hiq == 1) | |
965 | id->render_type = RT_DITHER_TRUECOL; | |
966 | else | |
967 | id->render_type = RT_PLAIN_TRUECOL; | |
968 | } | |
969 | ||
970 | newcm = gdk_imlib_set_color_map(id, disp); | |
971 | gdk_imlib_set_fast_render(id, disp); | |
972 | if (palfile) | |
973 | free(palfile); | |
974 | } | |
975 | ||
976 | GdkPixmap * | |
977 | gdk_imlib_copy_image(GdkImlibImage * im) | |
978 | { | |
979 | GdkPixmap *p; | |
980 | GdkGC *gc; | |
981 | ||
982 | if ((!im) || (!im->pixmap)) | |
983 | return NULL; | |
984 | p = gdk_pixmap_new(id->x.gdk_win, im->width, im->height, id->x.depth); | |
985 | gc = gdk_gc_new(p); | |
986 | gdk_draw_pixmap(p, gc, im->pixmap, 0, 0, 0, 0, im->width, im->height); | |
987 | gdk_gc_destroy(gc); | |
988 | return p; | |
989 | } | |
990 | ||
991 | GdkPixmap * | |
992 | gdk_imlib_move_image(GdkImlibImage * im) | |
993 | { | |
994 | GdkPixmap *p; | |
995 | ||
996 | if (!im) | |
997 | return NULL; | |
998 | p = im->pixmap; | |
999 | im->pixmap = NULL; | |
1000 | return p; | |
1001 | } | |
1002 | ||
1003 | GdkBitmap * | |
1004 | gdk_imlib_copy_mask(GdkImlibImage * im) | |
1005 | { | |
1006 | GdkBitmap *p; | |
1007 | GdkGC *gc; | |
1008 | ||
1009 | if ((!im) || (!im->shape_mask)) | |
1010 | return NULL; | |
1011 | p = gdk_pixmap_new(id->x.gdk_win, im->width, im->height, 1); | |
1012 | gc = gdk_gc_new(p); | |
1013 | gdk_draw_pixmap(p, gc, im->shape_mask, 0, 0, 0, 0, im->width, im->height); | |
1014 | gdk_gc_destroy(gc); | |
1015 | return p; | |
1016 | } | |
1017 | ||
1018 | GdkBitmap * | |
1019 | gdk_imlib_move_mask(GdkImlibImage * im) | |
1020 | { | |
1021 | GdkBitmap *p; | |
1022 | ||
1023 | if (!im) | |
1024 | return NULL; | |
1025 | p = im->shape_mask; | |
1026 | im->shape_mask = NULL; | |
1027 | return p; | |
1028 | } | |
1029 | ||
1030 | void | |
1031 | gdk_imlib_destroy_image(GdkImlibImage * im) | |
1032 | { | |
1033 | if (im) | |
1034 | { | |
1035 | if (id->cache.on_image) | |
1036 | { | |
1037 | gfree_image(im); | |
1038 | gclean_caches(); | |
1039 | } | |
1040 | else | |
1041 | gnullify_image(im); | |
1042 | } | |
1043 | } | |
1044 | ||
1045 | void | |
1046 | gdk_imlib_kill_image(GdkImlibImage * im) | |
1047 | { | |
1048 | if (im) | |
1049 | { | |
1050 | if (id->cache.on_image) | |
1051 | { | |
1052 | gfree_image(im); | |
1053 | gflush_image(im); | |
1054 | gclean_caches(); | |
1055 | } | |
1056 | else | |
1057 | gnullify_image(im); | |
1058 | } | |
1059 | } | |
1060 | ||
1061 | void | |
1062 | gdk_imlib_free_pixmap(GdkPixmap * pmap) | |
1063 | { | |
1064 | if (pmap) | |
1065 | { | |
1066 | gfree_pixmappmap(pmap); | |
1067 | gclean_caches(); | |
1068 | } | |
1069 | } | |
1070 | ||
1071 | void | |
1072 | gdk_imlib_free_bitmap(GdkBitmap * pmap) | |
1073 | { | |
1074 | if (pmap) | |
1075 | { | |
1076 | gfree_pixmappmap(pmap); | |
1077 | gclean_caches(); | |
1078 | } | |
1079 | } | |
1080 | ||
1081 | void | |
1082 | gdk_imlib_set_image_border(GdkImlibImage * im, GdkImlibBorder * border) | |
1083 | { | |
1084 | if ((im) && (border)) | |
1085 | { | |
1086 | im->border.left = border->left; | |
1087 | im->border.right = border->right; | |
1088 | im->border.top = border->top; | |
1089 | im->border.bottom = border->bottom; | |
1090 | gdirty_pixmaps(im); | |
1091 | } | |
1092 | } | |
1093 | ||
1094 | void | |
1095 | gdk_imlib_get_image_border(GdkImlibImage * im, GdkImlibBorder * border) | |
1096 | { | |
1097 | if ((im) && (border)) | |
1098 | { | |
1099 | border->left = im->border.left; | |
1100 | border->right = im->border.right; | |
1101 | border->top = im->border.top; | |
1102 | border->bottom = im->border.bottom; | |
1103 | } | |
1104 | } | |
1105 | ||
1106 | void | |
1107 | gdk_imlib_get_image_shape(GdkImlibImage * im, GdkImlibColor * color) | |
1108 | { | |
1109 | if ((!im) || (!color)) | |
1110 | return; | |
1111 | color->r = im->shape_color.r; | |
1112 | color->g = im->shape_color.g; | |
1113 | color->b = im->shape_color.b; | |
1114 | } | |
1115 | ||
1116 | void | |
1117 | gdk_imlib_set_image_shape(GdkImlibImage * im, GdkImlibColor * color) | |
1118 | { | |
1119 | if ((!im) || (!color)) | |
1120 | return; | |
1121 | im->shape_color.r = color->r; | |
1122 | im->shape_color.g = color->g; | |
1123 | im->shape_color.b = color->b; | |
1124 | gdirty_pixmaps(im); | |
1125 | } | |
1126 | ||
1127 | gint | |
1128 | gdk_imlib_get_fallback() | |
1129 | { | |
1130 | if (!id) | |
1131 | return 0; | |
1132 | return id->fallback; | |
1133 | } | |
1134 | ||
1135 | void | |
1136 | gdk_imlib_set_fallback(gint fallback) | |
1137 | { | |
1138 | if (!id) | |
1139 | return; | |
1140 | id->fallback = fallback; | |
1141 | } | |
1142 | ||
1143 | GdkVisual * | |
1144 | gdk_imlib_get_visual() | |
1145 | { | |
1146 | if (!id) | |
1147 | return NULL; | |
1148 | return gdk_window_get_visual(id->x.gdk_win); | |
1149 | } | |
1150 | ||
1151 | GdkColormap * | |
1152 | gdk_imlib_get_colormap() | |
1153 | { | |
1154 | if (!id) | |
1155 | return NULL; | |
1156 | return (id->x.gdk_cmap); | |
1157 | } | |
1158 | ||
1159 | gchar * | |
1160 | gdk_imlib_get_sysconfig() | |
1161 | { | |
1162 | if (!id) | |
1163 | return NULL; | |
1164 | return strdup(SYSTEM_IMRC); | |
1165 | } |