1 /* gib_imlib.c
2
3 Copyright (C) 1999,2000 Tom Gilbert.
4
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to
7 deal in the Software without restriction, including without limitation the
8 rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 sell copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies of the Software and its documentation and acknowledgment shall be
14 given in the documentation and software packages that this Software was
15 used.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
21 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
24 */
25
26 #include "gib_imlib.h"
27 #include "gib_utils.h"
28 #include "gib_debug.h"
29
30 int
gib_imlib_load_image(Imlib_Image * im,char * filename)31 gib_imlib_load_image(Imlib_Image * im, char *filename)
32 {
33 Imlib_Load_Error err;
34
35 imlib_context_set_progress_function(NULL);
36 if (!filename)
37 return (0);
38 *im = imlib_load_image_with_error_return(filename, &err);
39 if ((err) || (!im))
40 {
41 /* Check error code */
42 switch (err)
43 {
44 case IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST:
45 gib_weprintf("%s - File does not exist", filename);
46 break;
47 case IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY:
48 gib_weprintf("%s - Directory specified for image filename", filename);
49 break;
50 case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ:
51 gib_weprintf("%s - No read access to directory", filename);
52 break;
53 case IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT:
54 gib_weprintf("%s - No Imlib2 loader for that file format", filename);
55 break;
56 case IMLIB_LOAD_ERROR_PATH_TOO_LONG:
57 gib_weprintf("%s - Path specified is too long", filename);
58 break;
59 case IMLIB_LOAD_ERROR_PATH_COMPONENT_NON_EXISTANT:
60 gib_weprintf("%s - Path component does not exist", filename);
61 break;
62 case IMLIB_LOAD_ERROR_PATH_COMPONENT_NOT_DIRECTORY:
63 gib_weprintf("%s - Path component is not a directory", filename);
64 break;
65 case IMLIB_LOAD_ERROR_PATH_POINTS_OUTSIDE_ADDRESS_SPACE:
66 gib_weprintf("%s - Path points outside address space", filename);
67 break;
68 case IMLIB_LOAD_ERROR_TOO_MANY_SYMBOLIC_LINKS:
69 gib_weprintf("%s - Too many levels of symbolic links", filename);
70 break;
71 case IMLIB_LOAD_ERROR_OUT_OF_MEMORY:
72 gib_eprintf("While loading %s - Out of memory", filename);
73 break;
74 case IMLIB_LOAD_ERROR_OUT_OF_FILE_DESCRIPTORS:
75 gib_eprintf("While loading %s - Out of file descriptors", filename);
76 break;
77 case IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_WRITE:
78 gib_weprintf("%s - Cannot write to directory", filename);
79 break;
80 case IMLIB_LOAD_ERROR_OUT_OF_DISK_SPACE:
81 gib_weprintf("%s - Cannot write - out of disk space", filename);
82 break;
83 case IMLIB_LOAD_ERROR_UNKNOWN:
84 default:
85 gib_weprintf
86 ("While loading %s - Unknown error. Attempting to continue",
87 filename);
88 break;
89 }
90 return (0);
91 }
92 return (1);
93 }
94
95 int
gib_imlib_image_get_width(Imlib_Image im)96 gib_imlib_image_get_width(Imlib_Image im)
97 {
98 imlib_context_set_image(im);
99 return imlib_image_get_width();
100 }
101
102 int
gib_imlib_image_get_height(Imlib_Image im)103 gib_imlib_image_get_height(Imlib_Image im)
104 {
105 imlib_context_set_image(im);
106 return imlib_image_get_height();
107 }
108
109 int
gib_imlib_image_has_alpha(Imlib_Image im)110 gib_imlib_image_has_alpha(Imlib_Image im)
111 {
112 imlib_context_set_image(im);
113 return imlib_image_has_alpha();
114 }
115
116 void
gib_imlib_free_image_and_decache(Imlib_Image im)117 gib_imlib_free_image_and_decache(Imlib_Image im)
118 {
119 imlib_context_set_image(im);
120 imlib_free_image_and_decache();
121 }
122
123 void
gib_imlib_free_image(Imlib_Image im)124 gib_imlib_free_image(Imlib_Image im)
125 {
126 imlib_context_set_image(im);
127 imlib_free_image();
128 }
129
130 const char *
gib_imlib_image_get_filename(Imlib_Image im)131 gib_imlib_image_get_filename(Imlib_Image im)
132 {
133 if (im)
134 {
135 imlib_context_set_image(im);
136 return imlib_image_get_filename();
137 }
138 else
139 return NULL;
140 }
141
142 void
gib_imlib_render_image_on_drawable(Drawable d,Imlib_Image im,int x,int y,char dither,char blend,char alias)143 gib_imlib_render_image_on_drawable(Drawable d, Imlib_Image im, int x, int y,
144 char dither, char blend, char alias)
145 {
146 imlib_context_set_image(im);
147 imlib_context_set_drawable(d);
148 imlib_context_set_anti_alias(alias);
149 imlib_context_set_dither(dither);
150 imlib_context_set_blend(blend);
151 imlib_context_set_angle(0);
152 imlib_render_image_on_drawable(x, y);
153 }
154
155 void
gib_imlib_render_image_on_drawable_with_rotation(Drawable d,Imlib_Image im,int x,int y,double angle,char dither,char blend,char alias)156 gib_imlib_render_image_on_drawable_with_rotation(Drawable d, Imlib_Image im,
157 int x, int y, double angle,
158 char dither, char blend,
159 char alias)
160 {
161 Imlib_Image new_im;
162
163 imlib_context_set_image(im);
164 imlib_context_set_anti_alias(alias);
165 imlib_context_set_dither(dither);
166 imlib_context_set_blend(blend);
167 imlib_context_set_angle(angle);
168 imlib_context_set_drawable(d);
169 new_im = imlib_create_rotated_image(angle);
170 imlib_context_set_image(new_im);
171 imlib_render_image_on_drawable(x, y);
172 imlib_free_image();
173 }
174
175 void
gib_imlib_render_image_on_drawable_at_size(Drawable d,Imlib_Image im,int x,int y,int w,int h,char dither,char blend,char alias)176 gib_imlib_render_image_on_drawable_at_size(Drawable d, Imlib_Image im, int x,
177 int y, int w, int h, char dither,
178 char blend, char alias)
179 {
180 imlib_context_set_image(im);
181 imlib_context_set_drawable(d);
182 imlib_context_set_anti_alias(alias);
183 imlib_context_set_dither(dither);
184 imlib_context_set_blend(blend);
185 imlib_context_set_angle(0);
186 imlib_render_image_on_drawable_at_size(x, y, w, h);
187 }
188
189 void
gib_imlib_render_image_on_drawable_at_size_with_rotation(Drawable d,Imlib_Image im,int x,int y,int w,int h,double angle,char dither,char blend,char alias)190 gib_imlib_render_image_on_drawable_at_size_with_rotation(Drawable d,
191 Imlib_Image im,
192 int x, int y, int w,
193 int h, double angle,
194 char dither,
195 char blend,
196 char alias)
197 {
198 Imlib_Image new_im;
199
200 imlib_context_set_image(im);
201 imlib_context_set_drawable(d);
202 imlib_context_set_anti_alias(alias);
203 imlib_context_set_dither(dither);
204 imlib_context_set_blend(blend);
205 imlib_context_set_angle(angle);
206 new_im = imlib_create_rotated_image(angle);
207 imlib_context_set_image(new_im);
208 imlib_render_image_on_drawable_at_size(x, y, w, h);
209 imlib_free_image_and_decache();
210 }
211
212 void
gib_imlib_render_image_part_on_drawable_at_size(Drawable d,Imlib_Image im,int sx,int sy,int sw,int sh,int dx,int dy,int dw,int dh,char dither,char blend,char alias)213 gib_imlib_render_image_part_on_drawable_at_size(Drawable d, Imlib_Image im,
214 int sx, int sy, int sw,
215 int sh, int dx, int dy,
216 int dw, int dh, char dither,
217 char blend, char alias)
218 {
219 imlib_context_set_image(im);
220 imlib_context_set_drawable(d);
221 imlib_context_set_anti_alias(alias);
222 imlib_context_set_dither(dither);
223 imlib_context_set_blend(blend);
224 imlib_context_set_angle(0);
225 imlib_render_image_part_on_drawable_at_size(sx, sy, sw, sh, dx, dy, dw,
226 dh);
227 }
228
229 void
gib_imlib_render_image_part_on_drawable_at_size_with_rotation(Drawable d,Imlib_Image im,int sx,int sy,int sw,int sh,int dx,int dy,int dw,int dh,double angle,char dither,char blend,char alias)230 gib_imlib_render_image_part_on_drawable_at_size_with_rotation(Drawable d,
231 Imlib_Image im,
232 int sx, int sy,
233 int sw, int sh,
234 int dx, int dy,
235 int dw, int dh,
236 double angle,
237 char dither,
238 char blend,
239 char alias)
240 {
241 Imlib_Image new_im;
242
243 imlib_context_set_image(im);
244 imlib_context_set_drawable(d);
245 imlib_context_set_anti_alias(alias);
246 imlib_context_set_dither(dither);
247 imlib_context_set_angle(angle);
248 imlib_context_set_blend(blend);
249 new_im = imlib_create_rotated_image(angle);
250 imlib_context_set_image(new_im);
251 imlib_render_image_part_on_drawable_at_size(sx, sy, sw, sh, dx, dy, dw,
252 dh);
253 imlib_free_image_and_decache();
254 }
255
256 void
gib_imlib_image_fill_rectangle(Imlib_Image im,int x,int y,int w,int h,int r,int g,int b,int a)257 gib_imlib_image_fill_rectangle(Imlib_Image im, int x, int y, int w, int h,
258 int r, int g, int b, int a)
259 {
260 imlib_context_set_image(im);
261 imlib_context_set_color(r, g, b, a);
262 imlib_image_fill_rectangle(x, y, w, h);
263 }
264
265 void
gib_imlib_image_fill_polygon(Imlib_Image im,ImlibPolygon poly,int r,int g,int b,int a,unsigned char alias,int cx,int cy,int cw,int ch)266 gib_imlib_image_fill_polygon(Imlib_Image im, ImlibPolygon poly, int r, int g,
267 int b, int a, unsigned char alias, int cx,
268 int cy, int cw, int ch)
269 {
270 imlib_context_set_image(im);
271 imlib_context_set_color(r, g, b, a);
272 imlib_context_set_anti_alias(alias);
273 imlib_context_set_cliprect(cx, cy, cw, ch);
274 imlib_image_fill_polygon(poly);
275 imlib_context_set_cliprect(0, 0, 0, 0);
276 }
277
278 void
gib_imlib_image_draw_polygon(Imlib_Image im,ImlibPolygon poly,int r,int g,int b,int a,unsigned char closed,unsigned char alias,int cx,int cy,int cw,int ch)279 gib_imlib_image_draw_polygon(Imlib_Image im, ImlibPolygon poly, int r, int g,
280 int b, int a, unsigned char closed,
281 unsigned char alias, int cx, int cy, int cw,
282 int ch)
283 {
284 imlib_context_set_image(im);
285 imlib_context_set_color(r, g, b, a);
286 imlib_context_set_anti_alias(alias);
287 imlib_context_set_cliprect(cx, cy, cw, ch);
288 imlib_image_draw_polygon(poly, closed);
289 imlib_context_set_cliprect(0, 0, 0, 0);
290 }
291
292
293 void
gib_imlib_image_draw_rectangle(Imlib_Image im,int x,int y,int w,int h,int r,int g,int b,int a)294 gib_imlib_image_draw_rectangle(Imlib_Image im, int x, int y, int w, int h,
295 int r, int g, int b, int a)
296 {
297 imlib_context_set_image(im);
298 imlib_context_set_color(r, g, b, a);
299 imlib_image_draw_rectangle(x, y, w, h);
300 }
301
302
303 void
gib_imlib_text_draw(Imlib_Image im,Imlib_Font fn,gib_style * s,int x,int y,char * text,Imlib_Text_Direction dir,int r,int g,int b,int a)304 gib_imlib_text_draw(Imlib_Image im, Imlib_Font fn, gib_style * s, int x,
305 int y, char *text, Imlib_Text_Direction dir, int r, int g,
306 int b, int a)
307 {
308 imlib_context_set_image(im);
309 imlib_context_set_font(fn);
310 imlib_context_set_direction(dir);
311 if (s)
312 {
313 int min_x = 0, min_y = 0;
314 gib_style_bit *bb;
315 gib_list *l;
316
317 /* here we shift the draw to accomodate bits with negative offsets,
318 * which would be drawn at negative coords otherwise */
319 l = s->bits;
320 while (l)
321 {
322 bb = (gib_style_bit *) l->data;
323 if (bb)
324 {
325 if (bb->x_offset < min_x)
326 min_x = bb->x_offset;
327 if (bb->y_offset < min_y)
328 min_y = bb->y_offset;
329 }
330 l = l->next;
331 }
332 x -= min_x;
333 y -= min_y;
334
335 /* Now draw the bits */
336 l = s->bits;
337 while (l)
338 {
339 bb = (gib_style_bit *) l->data;
340 if (bb)
341 {
342 if ((bb->r + bb->g + bb->b + bb->a) == 0)
343 imlib_context_set_color(r, g, b, a);
344 else
345 imlib_context_set_color(bb->r, bb->g, bb->b, bb->a);
346 imlib_text_draw(x + bb->x_offset, y + bb->y_offset, text);
347 }
348 l = l->next;
349 }
350 }
351 else
352 {
353 imlib_context_set_color(r, g, b, a);
354 imlib_text_draw(x, y, text);
355 }
356 }
357
358 char **
gib_imlib_list_fonts(int * num)359 gib_imlib_list_fonts(int *num)
360 {
361 return imlib_list_fonts(num);
362 }
363
364
365 void
gib_imlib_get_text_size(Imlib_Font fn,char * text,gib_style * s,int * w,int * h,Imlib_Text_Direction dir)366 gib_imlib_get_text_size(Imlib_Font fn, char *text, gib_style * s, int *w,
367 int *h, Imlib_Text_Direction dir)
368 {
369
370 imlib_context_set_font(fn);
371 imlib_context_set_direction(dir);
372 imlib_get_text_size(text, w, h);
373 if (s)
374 {
375 gib_style_bit *b;
376 int max_x_off = 0, min_x_off = 0, max_y_off = 0, min_y_off = 0;
377 gib_list *l;
378
379 l = s->bits;
380 while (l)
381 {
382 b = (gib_style_bit *) l->data;
383 if (b)
384 {
385 if (b->x_offset > max_x_off)
386 max_x_off = b->x_offset;
387 else if (b->x_offset < min_x_off)
388 min_x_off = b->x_offset;
389 if (b->y_offset > max_y_off)
390 max_y_off = b->y_offset;
391 else if (b->y_offset < min_y_off)
392 min_y_off = b->y_offset;
393 }
394 l = l->next;
395 }
396 if (h)
397 {
398 *h += max_y_off;
399 *h -= min_y_off;
400 }
401 if (w)
402 {
403 *w += max_x_off;
404 *w -= min_x_off;
405 }
406 }
407 }
408
gib_imlib_clone_image(Imlib_Image im)409 Imlib_Image gib_imlib_clone_image(Imlib_Image im)
410 {
411 imlib_context_set_image(im);
412 return imlib_clone_image();
413 }
414
415 char *
gib_imlib_image_format(Imlib_Image im)416 gib_imlib_image_format(Imlib_Image im)
417 {
418 imlib_context_set_image(im);
419 return imlib_image_format();
420 }
421
422 void
gib_imlib_blend_image_onto_image(Imlib_Image dest_image,Imlib_Image source_image,char merge_alpha,int sx,int sy,int sw,int sh,int dx,int dy,int dw,int dh,char dither,char blend,char alias)423 gib_imlib_blend_image_onto_image(Imlib_Image dest_image,
424 Imlib_Image source_image, char merge_alpha,
425 int sx, int sy, int sw, int sh, int dx,
426 int dy, int dw, int dh, char dither,
427 char blend, char alias)
428 {
429 imlib_context_set_image(dest_image);
430 imlib_context_set_anti_alias(alias);
431 imlib_context_set_dither(dither);
432 imlib_context_set_blend(blend);
433 imlib_context_set_angle(0);
434 imlib_blend_image_onto_image(source_image, merge_alpha, sx, sy, sw, sh, dx,
435 dy, dw, dh);
436 }
437
438 void
gib_imlib_blend_image_onto_image_with_rotation(Imlib_Image dest_image,Imlib_Image source_image,char merge_alpha,int sx,int sy,int sw,int sh,int dx,int dy,int dw,int dh,double angle,char dither,char blend,char alias)439 gib_imlib_blend_image_onto_image_with_rotation(Imlib_Image dest_image,
440 Imlib_Image source_image,
441 char merge_alpha, int sx,
442 int sy, int sw, int sh, int dx,
443 int dy, int dw, int dh,
444 double angle, char dither,
445 char blend, char alias)
446 {
447 imlib_context_set_image(dest_image);
448 imlib_context_set_anti_alias(alias);
449 imlib_context_set_dither(dither);
450 imlib_context_set_blend(blend);
451 imlib_context_set_angle(angle);
452 imlib_blend_image_onto_image_at_angle(source_image, merge_alpha, sx, sy,
453 sw, sh, dx, dy, (int) angle,
454 (int) angle);
455 return;
456 dw = 0;
457 dh = 0;
458 }
459
gib_imlib_create_cropped_scaled_image(Imlib_Image im,int sx,int sy,int sw,int sh,int dw,int dh,char alias)460 Imlib_Image gib_imlib_create_cropped_scaled_image(Imlib_Image im, int sx,
461 int sy, int sw, int sh,
462 int dw, int dh, char alias)
463 {
464 imlib_context_set_image(im);
465 imlib_context_set_anti_alias(alias);
466 return imlib_create_cropped_scaled_image(sx, sy, sw, sh, dw, dh);
467 }
468
469 void
gib_imlib_apply_color_modifier_to_rectangle(Imlib_Image im,int x,int y,int w,int h,DATA8 * rtab,DATA8 * gtab,DATA8 * btab,DATA8 * atab)470 gib_imlib_apply_color_modifier_to_rectangle(Imlib_Image im, int x, int y,
471 int w, int h, DATA8 * rtab,
472 DATA8 * gtab, DATA8 * btab,
473 DATA8 * atab)
474 {
475 Imlib_Color_Modifier cm;
476
477 imlib_context_set_image(im);
478 cm = imlib_create_color_modifier();
479 imlib_context_set_color_modifier(cm);
480 imlib_set_color_modifier_tables(rtab, gtab, btab, atab);
481 imlib_apply_color_modifier_to_rectangle(x, y, w, h);
482 imlib_free_color_modifier();
483 }
484
485 void
gib_imlib_image_set_has_alpha(Imlib_Image im,int alpha)486 gib_imlib_image_set_has_alpha(Imlib_Image im, int alpha)
487 {
488 imlib_context_set_image(im);
489 imlib_image_set_has_alpha(alpha);
490 }
491
492 void
gib_imlib_save_image(Imlib_Image im,char * file)493 gib_imlib_save_image(Imlib_Image im, char *file)
494 {
495 char *tmp;
496
497 imlib_context_set_image(im);
498 tmp = strrchr(file, '.');
499 if (tmp)
500 {
501 char *p, *pp;
502 p = gib_estrdup(tmp + 1);
503 pp = p;
504 while(*pp) {
505 *pp = tolower(*pp);
506 pp++;
507 }
508 imlib_image_set_format(p);
509 gib_efree(p);
510 }
511 imlib_save_image(file);
512 }
513
514 void
gib_imlib_save_image_with_error_return(Imlib_Image im,char * file,Imlib_Load_Error * error_return)515 gib_imlib_save_image_with_error_return(Imlib_Image im, char *file,
516 Imlib_Load_Error * error_return)
517 {
518 char *tmp;
519
520 imlib_context_set_image(im);
521 tmp = strrchr(file, '.');
522 if (tmp)
523 imlib_image_set_format(tmp + 1);
524 imlib_save_image_with_error_return(file, error_return);
525 }
526
527 void
gib_imlib_free_font(Imlib_Font fn)528 gib_imlib_free_font(Imlib_Font fn)
529 {
530 imlib_context_set_font(fn);
531 imlib_free_font();
532 }
533
534 void
gib_imlib_image_draw_line(Imlib_Image im,int x1,int y1,int x2,int y2,char make_updates,int r,int g,int b,int a)535 gib_imlib_image_draw_line(Imlib_Image im, int x1, int y1, int x2, int y2,
536 char make_updates, int r, int g, int b, int a)
537 {
538 imlib_context_set_image(im);
539 imlib_context_set_color(r, g, b, a);
540 imlib_image_draw_line(x1, y1, x2, y2, make_updates);
541 }
542
gib_imlib_create_rotated_image(Imlib_Image im,double angle)543 Imlib_Image gib_imlib_create_rotated_image(Imlib_Image im, double angle)
544 {
545 imlib_context_set_image(im);
546 return (imlib_create_rotated_image(angle));
547 }
548
549 void
gib_imlib_image_tile(Imlib_Image im)550 gib_imlib_image_tile(Imlib_Image im)
551 {
552 imlib_context_set_image(im);
553 imlib_image_tile();
554 }
555
556 void
gib_imlib_image_blur(Imlib_Image im,int radius)557 gib_imlib_image_blur(Imlib_Image im, int radius)
558 {
559 imlib_context_set_image(im);
560 imlib_image_blur(radius);
561 }
562
563 void
gib_imlib_image_sharpen(Imlib_Image im,int radius)564 gib_imlib_image_sharpen(Imlib_Image im, int radius)
565 {
566 imlib_context_set_image(im);
567 imlib_image_sharpen(radius);
568 }
569
570 void
gib_imlib_line_clip_and_draw(Imlib_Image dest,int x0,int y0,int x1,int y1,int cx,int cy,int cw,int ch,int r,int g,int b,int a)571 gib_imlib_line_clip_and_draw(Imlib_Image dest, int x0, int y0, int x1, int y1,
572 int cx, int cy, int cw, int ch, int r, int g,
573 int b, int a)
574 {
575 imlib_context_set_cliprect(cx, cy, cw, ch);
576 gib_imlib_image_draw_line(dest, x0, y0, x1, y1, 0, r, g, b, a);
577 imlib_context_set_cliprect(0, 0, 0, 0);
578 }
579
580 Imlib_Image
gib_imlib_create_image_from_drawable(Drawable d,Pixmap mask,int x,int y,int width,int height,char need_to_grab_x)581 gib_imlib_create_image_from_drawable(Drawable d, Pixmap mask, int x, int y,
582 int width, int height,
583 char need_to_grab_x)
584 {
585 imlib_context_set_drawable(d);
586 return imlib_create_image_from_drawable(mask, x, y, width, height,
587 need_to_grab_x);
588 }
589
gib_imlib_parse_color(char * col,int * r,int * g,int * b,int * a)590 void gib_imlib_parse_color(char *col, int *r, int *g, int *b, int *a)
591 {
592 gib_list *ll;
593 unsigned long cc, rr, gg, bb, aa;
594 int len;
595
596 if (col[0] == '#')
597 {
598 /* #RRGGBBAA style */
599 /* skip the '#' */
600 col++;
601 len = strlen(col);
602 if (len == 8)
603 {
604 cc = (unsigned long) strtoul(col, NULL, 16);
605 rr = (cc & 0xff000000) >> 24;
606 gg = (cc & 0x00ff0000) >> 16;
607 bb = (cc & 0x0000ff00) >> 8;
608 aa = (cc & 0x000000ff);
609 }
610 else if (len == 6)
611 {
612 cc = (unsigned long) strtoul(col, NULL, 16);
613 rr = (cc & 0xff0000) >> 16;
614 gg = (cc & 0x00ff00) >> 8;
615 bb = (cc & 0x0000ff);
616 aa = 255;
617 }
618 else
619 {
620 gib_weprintf("unable to parse color %s\n", col);
621 return;
622 }
623 }
624 else
625 {
626 /* r,g,b,a style */
627 ll = gib_string_split(col, ",");
628 if (!ll)
629 {
630 gib_weprintf("unable to parse color %s\n", col);
631 return;
632 }
633 len = gib_list_length(ll);
634 if (len == 3)
635 {
636 rr = atoi(ll->data);
637 gg = atoi(ll->next->data);
638 bb = atoi(ll->next->next->data);
639 aa = 255;
640 }
641 else if (len == 4)
642 {
643 rr = atoi(ll->data);
644 gg = atoi(ll->next->data);
645 bb = atoi(ll->next->next->data);
646 aa = atoi(ll->next->next->next->data);
647 }
648 else
649 {
650 gib_weprintf("unable to parse color %s\n", col);
651 return;
652 }
653 }
654 *r = rr;
655 *g = gg;
656 *b = bb;
657 *a = aa;
658 }
659
660 void
gib_imlib_parse_fontpath(char * path)661 gib_imlib_parse_fontpath(char *path)
662 {
663 gib_list *l, *ll;
664
665 if (!path)
666 return;
667
668 l = gib_string_split(path, ":");
669 if (!l)
670 return;
671 ll = l;
672 while (ll)
673 {
674 imlib_add_path_to_font_path((char *) ll->data);
675 ll = ll->next;
676 }
677 gib_list_free_and_data(l);
678 }
679
680 Imlib_Font
gib_imlib_load_font(char * name)681 gib_imlib_load_font(char *name)
682 {
683 Imlib_Font fn;
684
685 if ((fn = imlib_load_font(name)))
686 return fn;
687 gib_weprintf("couldn't load font %s, attempting to fall back to fixed.", name);
688 if ((fn = imlib_load_font("fixed")))
689 return fn;
690 gib_weprintf("failed to even load fixed! Attempting to find any font.");
691 return imlib_load_font("*");
692 }
693
gib_imlib_image_orientate(Imlib_Image im,int orientation)694 void gib_imlib_image_orientate(Imlib_Image im, int orientation)
695 {
696 imlib_context_set_image(im);
697 imlib_image_orientate(orientation);
698 }
699