Typo.
[adesklets.git] / doc / imlib2 / imlib2.c
blob3fe294173c0e60f2073427992793de61f772ce17
1 /**
2 @file
3 @brief Imlib2 library
5 Brief of imlib2 library
6 */
7 /**
9 @mainpage Imlib2 Library Documentation
10 @version 1.1.1
11 @author Carsten Haitzler <raster@rasterman.com>
12 @date 1999-2004
14 @section about About This Documentation
15 This is a copy of Imlib2 doxygen documentation adesklets maintainer
16 included here for the sake of having it around. It was produced out
17 of enlightenment CVS content (http://sourceforge.net/projects/enlightenment/) on
18 Sunday, March the 20th, 02:30:15 UTC 2005. This notice aside, original content
19 by Carsten Haitzler was preserved untouched.
21 @section intro What is Imlib2 ?
23 Imlib 2 is the successor to Imlib. It is NOT a newer version - it is a completely new library. Imlib 2 can be installed alongside Imlib 1.x without any problems since they are effectively different libraries - BUT they Have very similar functionality.
25 Imlib 2 does the following:
27 \li Load image files from disk in one of many formats
28 \li Save images to disk in one of many formats
29 \li Render image data onto other images
30 \li Render images to an X-Windows drawable
31 \li Produce pixmaps and pixmap masks of Images
32 \li Apply filters to images
33 \li Rotate images
34 \li Accept RGBA Data for images
35 \li Scale images
36 \li Alpha blend Images on other images or drawables
37 \li Apply color correction and modification tables and factors to images
38 \li Render images onto images with color correction and modification tables
39 \li Render truetype anti-aliased text
40 \li Render truetype anti-aliased text at any angle
41 \li Render anti-aliased lines
42 \li Render rectangles
43 \li Render linear multi-colored gradients
44 \li Cache data intelligently for maximum performance
45 \li Allocate colors automatically
46 \li Allow full control over caching and color allocation
47 \li Provide highly optimized MMX assembly for core routines
48 \li Provide plug-in filter interface
49 \li Provide on-the-fly runtime plug-in image loading and saving interface
50 \li Fastest image compositing, rendering and manipulation library for X
52 If what you want isn't in the list above somewhere then likely Imlib 2 does not do it. If it does it it likely does it faster than any other library you can find (this includes gdk-pixbuf, gdkrgb, etc.) primarily because of highly optimized code and a smart subsystem that does the dirty work for you and picks up the pieces for you so you can be lazy and let all the optimizations for FOR you.
54 Imlib 2 can run without a display, so it can be easily used for background image processing for web sites or servers - it only requires the X libraries to be installed - that is all - it does not require an XServer to run unless you wish to display images.
56 The interface is simple - once you get used to it, the functions do exactly what they say they do.
58 @section first_ex A Simple Example
60 The best way to start is to show a simple example of an Imlib2
61 program. This one will load an image of any format you have a loader
62 installed for (all loaders are dynamic code objects that Imlib2 will
63 use and update automatically runtime - anyone is free to write a
64 loader. All that has to be done is for the object to be dropped into
65 the loaders directory with the others and all Imlib2 programs will
66 automatically be able to use it - without a restart).
68 @code
69 /* main program */
70 int main(int argc, char **argv)
72 /* an image handle */
73 Imlib_Image image;
75 /* if we provided < 2 arguments after the command - exit */
76 if (argc != 3) exit(1);
77 /* load the image */
78 image = imlib_load_image(argv[1]);
79 /* if the load was successful */
80 if (image)
82 char *tmp;
83 /* set the image we loaded as the current context image to work on */
84 imlib_context_set_image(image);
85 /* set the image format to be the format of the extension of our last */
86 /* argument - i.e. .png = png, .tif = tiff etc. */
87 tmp = strrchr(argv[2], '.');
88 if(tmp)
89 imlib_image_set_format(tmp + 1);
90 /* save the image */
91 imlib_save_image(argv[2]);
94 @endcode
96 Now to compile this
98 @verbatim
99 cc imlib2_convert.c -o imlib2_convert `imlib2-config --cflags` `imlib2-config --libs`
100 @endverbatim
102 You now have a program that if used as follows:
104 @verbatim
105 cc imlib2_con
106 ./imlib2_convert image1.jpg image2.png
107 @endverbatim
109 will convert image1.jpg into a png called image2.png. It is that simple.
111 @section loading How Image Loading Works
113 It is probably a good idea to discuss how Imlib2 actually loads an Image so the programmer knows what is going on, how to take advantage of the optimizations already there and to explain why things work as they do.
115 @subsection load_func Loading using imlib_load_image();
117 This is likely to be by far the most common way to load an image - when you don't really care about the details of the loading process or why it failed - all you care about is if you got a valid image handle.
119 When you call this function Imlib2 attempts to find the file specified as the parameter. This will involve Imlib2 first checking to see if that file path already has been loaded and is in Imlib2's cache (a cache of already decoded images in memory to save having to load and decode from disk all the time). If there already is a copy in the cache (either already active or speculatively cached from a previous load & free) this copy will have its handle returned instead of Imlib2 checking on disk (in some circumstances this is not true - see later in this section to find out). This means if your program blindly loads an Image, renders it, then frees it - then soon afterwards loads the same image again, it will not be loaded from disk at all, instead it will simply be re-referenced from the cache - meaning the load will be almost instant. A great way to take full advantage of this is to set the cache to some size you are happy with for the image data being used by your application and then all rendering o an image follows the pseudo code:
121 @verbatim
122 set cache to some amount (e.g. 4 Mb)
124 rendering loop ...
125 load image
126 render image
127 free image
128 ... continue loop
129 @endverbatim
131 This may normally sound silly - load image, render then free - EVERY time we want to use it, BUT - it is actually the smartest way to use Imlib2 - since the caching will find the image for you in the cache - you do not need to manage your own cache, or worry about filling up memory with image data - only as much memory as you have set for the cache size will actually ever be used to store image data - if you have lots of image data to work with then increase the cache size for better performance, but this is the only thing you need to worry about. you won't have problems of accidentally forgetting to free images later since you free them immediately after use.
133 Now what happens if the file changes on disk while it's in cache? By default nothing. The file is ignored. This is an optimization (to avoid hitting the disk to check if the file changed for every load if it's cached). You can inform Imlib2 that you care about this by using the imlib_image_set_changes_on_disk(); call. Do this whenever you load an Image that you expect will change on disk, and the fact that it changes really matters. Remember this will marginally reduce the caching performance.
135 Now what actually happens when we try and load an image using a
136 filename? First the filename is broken down into 2 parts. the filename
137 before a colon (:) and the key after the colon. This means when we
138 have a filename like:
140 @verbatim
141 /path/to/file.jpg
142 @endverbatim
144 the filename is:
146 @verbatim
147 /path/to/file.jpg
148 @endverbatim
150 and the key is blank. If we have:
152 @verbatim
153 /path/to/file.db:key.value/blah
154 @endverbatim
156 the filename is:
158 @verbatim
159 /path/to/file.db
160 @endverbatim
162 and the key is:
164 @verbatim
165 key.value/blah
166 @endverbatim
168 You may ask what is this thing with keys and filenames? Well Imlib2 has loaders that are able to load data that is WITHIN a file (the loader capable of this right now is the database loader that is able to load image data stored with a key in a Berkeley-db database file). The colon is used to delimit where the filename ends and the key begins. Fro the majority of files you load you won't have to worry, but there is a limit in this case that filenames cannot contain a color character.
170 First Imlib2 checks to see if the file exists and that you have permission to read it. If this fails it will abort the load. Now that it has checked that this is the case it evaluates that it's list of dynamically loaded loader modules it up to date then it runs through the loader modules until one of them claims it can load this file. If this is the case that loader is now used to decode the image and return an Image handle to the calling program. If the loader is written correctly and the file format sanely supports this, the loader will NOT decode any image data at this point. It will ONLY read the header of the image to figure out its size, if it has an alpha channel, format and any other header information. The loader is remembered and it will be re-used to load the image data itself later if and ONLY if the actual image data itself is needed. This means you can scan vast directories of files figuring their format and size and other such information just by loading and freeing - and it will be fast because no image data is decoded. You can take advantage of this by loading the image and checking its size to calculate the size of an output area before you ever load the data. This means geometry calculations can be done fast ahead of time.
172 If you desire more detailed information about why a load failed you can use imlib_load_image_with_error_return(); and it will return a detailed error return code.
174 If you do not wish to have the image data loaded later using the optimized "deferred" method of loading, you can force the data to be decoded immediately with imlib_load_image_immediately();
176 If you wish to bypass the cache when loading images you can using imlib_load_image_without_cache(); and imlib_load_image_immediately_without_cache();.
178 Sometimes loading images can take a while. Often it is a good idea to provide feedback to the user whilst this is happening. This is when you set the progress function callback. Setting this to NULL will mean no progress function is called during load - this is the default. When it is set you set it to a function that will get called every so often (depending on the progress granularity) during load. Use imlib_context_set_progress_function(); and imlib_context_set_progress_granularity(); to set this up.
180 @section second_ex A more advanced Example
182 This is a more comprehensive example that should show off a fair number of features of imlib2. The code this was based off can be found in Imlib2's test directory. This covers a lot of the core of Imlib2's API so you should have a pretty good idea on how it works if you understand this code snippet.
184 @code
185 /* include X11 stuff */
186 #include <X11/Xlib.h>
187 /* include Imlib2 stuff */
188 #include <Imlib2.h>
189 /* sprintf include */
190 #include <stdio.h>
192 /* some globals for our window & X display */
193 Display *disp;
194 Window win;
195 Visual *vis;
196 Colormap cm;
197 int depth;
199 /* the program... */
200 int main(int argc, char **argv)
202 /* events we get from X */
203 XEvent ev;
204 /* areas to update */
205 Imlib_Updates updates, current_update;
206 /* our virtual framebuffer image we draw into */
207 Imlib_Image buffer;
208 /* a font */
209 Imlib_Font font;
210 /* our color range */
211 Imlib_Color_Range range;
212 /* our mouse x, y coordinates */
213 int mouse_x = 0, mouse_y = 0;
215 /* connect to X */
216 disp = XOpenDisplay(NULL);
217 /* get default visual , colormap etc. you could ask imlib2 for what it */
218 /* thinks is the best, but this example is intended to be simple */
219 vis = DefaultVisual(disp, DefaultScreen(disp));
220 depth = DefaultDepth(disp, DefaultScreen(disp));
221 cm = DefaultColormap(disp, DefaultScreen(disp));
222 /* create a window 640x480 */
223 win = XCreateSimpleWindow(disp, DefaultRootWindow(disp),
224 0, 0, 640, 480, 0, 0, 0);
225 /* tell X what events we are interested in */
226 XSelectInput(disp, win, ButtonPressMask | ButtonReleaseMask |
227 PointerMotionMask | ExposureMask);
228 /* show the window */
229 XMapWindow(disp, win);
230 /* set our cache to 2 Mb so it doesn't have to go hit the disk as long as */
231 /* the images we use use less than 2Mb of RAM (that is uncompressed) */
232 imlib_set_cache_size(2048 * 1024);
233 /* set the font cache to 512Kb - again to avoid re-loading */
234 imlib_set_font_cache_size(512 * 1024);
235 /* add the ./ttfonts dir to our font path - you'll want a notepad.ttf */
236 /* in that dir for the text to display */
237 imlib_add_path_to_font_path("./ttfonts");
238 /* set the maximum number of colors to allocate for 8bpp and less to 128 */
239 imlib_set_color_usage(128);
240 /* dither for depths < 24bpp */
241 imlib_context_set_dither(1);
242 /* set the display , visual, colormap and drawable we are using */
243 imlib_context_set_display(disp);
244 imlib_context_set_visual(vis);
245 imlib_context_set_colormap(cm);
246 imlib_context_set_drawable(win);
247 /* infinite event loop */
248 for (;;)
250 /* image variable */
251 Imlib_Image image;
252 /* width and height values */
253 int w, h, text_w, text_h;
255 /* init our updates to empty */
256 updates = imlib_updates_init();
257 /* while there are events form X - handle them */
260 XNextEvent(disp, &ev);
261 switch (ev.type)
263 case Expose:
264 /* window rectangle was exposed - add it to the list of */
265 /* rectangles we need to re-render */
266 updates = imlib_update_append_rect(updates,
267 ev.xexpose.x, ev.xexpose.y,
268 ev.xexpose.width, ev.xexpose.height);
269 break;
270 case ButtonPress:
271 /* if we click anywhere in the window, exit */
272 exit(0);
273 break;
274 case MotionNotify:
275 /* if the mouse moves - note it */
276 /* add a rectangle update for the new mouse position */
277 image = imlib_load_image("./test_images/mush.png");
278 imlib_context_set_image(image);
279 w = imlib_image_get_width();
280 h = imlib_image_get_height();
281 imlib_context_set_image(image);
282 imlib_free_image();
283 /* the old position - so we wipe over where it used to be */
284 updates = imlib_update_append_rect(updates,
285 mouse_x - (w / 2), mouse_y - (h / 2),
286 w, h);
287 font = imlib_load_font("notepad/30");
288 if (font)
290 char text[4096];
292 imlib_context_set_font(font);
293 sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
294 imlib_get_text_size(text, &text_w, &text_h);
295 imlib_free_font();
296 updates = imlib_update_append_rect(updates,
297 320 - (text_w / 2), 240 - (text_h / 2),
298 text_w, text_h);
301 mouse_x = ev.xmotion.x;
302 mouse_y = ev.xmotion.y;
303 /* the new one */
304 updates = imlib_update_append_rect(updates,
305 mouse_x - (w / 2), mouse_y - (h / 2),
306 w, h);
307 font = imlib_load_font("notepad/30");
308 if (font)
310 char text[4096];
312 imlib_context_set_font(font);
313 sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
314 imlib_get_text_size(text, &text_w, &text_h);
315 imlib_free_font();
316 updates = imlib_update_append_rect(updates,
317 320 - (text_w / 2), 240 - (text_h / 2),
318 text_w, text_h);
320 default:
321 /* any other events - do nothing */
322 break;
325 while (XPending(disp));
327 /* no more events for now ? ok - idle time so lets draw stuff */
329 /* take all the little rectangles to redraw and merge them into */
330 /* something sane for rendering */
331 updates = imlib_updates_merge_for_rendering(updates, 640, 480);
332 for (current_update = updates;
333 current_update;
334 current_update = imlib_updates_get_next(current_update))
336 int up_x, up_y, up_w, up_h;
338 /* find out where the first update is */
339 imlib_updates_get_coordinates(current_update,
340 &up_x, &up_y, &up_w, &up_h);
342 /* create our buffer image for rendering this update */
343 buffer = imlib_create_image(up_w, up_h);
345 /* we can blend stuff now */
346 imlib_context_set_blend(1);
348 /* fill the window background */
349 /* load the background image - you'll need to have some images */
350 /* in ./test_images lying around for this to actually work */
351 image = imlib_load_image("./test_images/bg.png");
352 /* we're working with this image now */
353 imlib_context_set_image(image);
354 /* get its size */
355 w = imlib_image_get_width();
356 h = imlib_image_get_height();
357 /* now we want to work with the buffer */
358 imlib_context_set_image(buffer);
359 /* if the iimage loaded */
360 if (image)
362 /* blend image onto the buffer and scale it to 640x480 */
363 imlib_blend_image_onto_image(image, 0,
364 0, 0, w, h,
365 - up_x, - up_y, 640, 480);
366 /* working with the loaded image */
367 imlib_context_set_image(image);
368 /* free it */
369 imlib_free_image();
372 /* draw an icon centered around the mouse position */
373 image = imlib_load_image("./test_images/mush.png");
374 imlib_context_set_image(image);
375 w = imlib_image_get_width();
376 h = imlib_image_get_height();
377 imlib_context_set_image(buffer);
378 if (image)
380 imlib_blend_image_onto_image(image, 0,
381 0, 0, w, h,
382 mouse_x - (w / 2) - up_x, mouse_y - (h / 2) - up_y, w, h);
383 imlib_context_set_image(image);
384 imlib_free_image();
387 /* draw a gradient on top of things at the top left of the window */
388 /* create a range */
389 range = imlib_create_color_range();
390 imlib_context_set_color_range(range);
391 /* add white opaque as the first color */
392 imlib_context_set_color(255, 255, 255, 255);
393 imlib_add_color_to_color_range(0);
394 /* add an orange color, semi-transparent 10 units from the first */
395 imlib_context_set_color(255, 200, 10, 100);
396 imlib_add_color_to_color_range(10);
397 /* add black, fully transparent at the end 20 units away */
398 imlib_context_set_color(0, 0, 0, 0);
399 imlib_add_color_to_color_range(20);
400 /* draw the range */
401 imlib_context_set_image(buffer);
402 imlib_image_fill_color_range_rectangle(- up_x, - up_y, 128, 128, -45.0);
403 /* free it */
404 imlib_free_color_range();
406 /* draw text - centered with the current mouse x, y */
407 font = imlib_load_font("notepad/30");
408 if (font)
410 char text[4096];
412 /* set the current font */
413 imlib_context_set_font(font);
414 /* set the image */
415 imlib_context_set_image(buffer);
416 /* set the color (black) */
417 imlib_context_set_color(0, 0, 0, 255);
418 /* print text to display in the buffer */
419 sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
420 /* query the size it will be */
421 imlib_get_text_size(text, &text_w, &text_h);
422 /* draw it */
423 imlib_text_draw(320 - (text_w / 2) - up_x, 240 - (text_h / 2) - up_y, text);
424 /* free the font */
425 imlib_free_font();
428 /* don't blend the image onto the drawable - slower */
429 imlib_context_set_blend(0);
430 /* set the buffer image as our current image */
431 imlib_context_set_image(buffer);
432 /* render the image at 0, 0 */
433 imlib_render_image_on_drawable(up_x, up_y);
434 /* don't need that temporary buffer image anymore */
435 imlib_free_image();
437 /* if we had updates - free them */
438 if (updates)
439 imlib_updates_free(updates);
440 /* loop again waiting for events */
442 return 0;
444 @endcode
446 @section filters Imlib2 filters
448 @subsection dyn_filter Imlib 2 Dynamic Filters
450 Imlib2 has built in features allowing filters and effects to be applied at run time through a very small scripting language, this is similar to that of script-fu found in the GIMP (http://www.gimp.org). There are two parts to the system, the client library call ``imlib_apply_filter'' and the library side filters. The library side filters are synonymous with image loaders.
452 To run a script on an image you need to set the context image then call:
454 @verbatim
455 imlib_apply_filter( script_string, ... );
456 @endverbatim
458 The script_string variable is made up of the script language, which is very simple and made up of only function calls. Functions calls look like this:
460 @verbatim
461 filter name( key=value [, ...] );
462 @endverbatim
464 Where,
466 \li <b>filter name</b> is the name of the filter you wish to apply
467 \li \b key is an expected value
468 \li \b value is a ``string'', a number, or an actual variable in
470 the program, or the result of another filter.
474 @verbatim
475 bump_map( map=tint(red=50,tint=200), blue=10 );
476 @endverbatim
478 This example would bump map using a a map generated from the tint filter.
480 It is also possible to pass application information to the filters via the usage of the [] operator. When the script is being compiled the script engine looks on the parameters passed to it and picks up a pointer for every [] found.
482 eg2.
484 @verbatim
485 imlib_apply_filter( "tint( x=[], y=[], red=255, alpha=55 );", &myxint, &myyint );
486 @endverbatim
488 This will cause a tint to the current image at (myxint,myyint) to be done. This is very useful for when you want the filters to dynamically change according to program variables. The system is very quick as the code is pseudo-compiled and then run. The advantage of having the scripting system allows customization of the image manipulations, this is particularly useful in applications that allow modifications to be done (eg. image viewers).
490 */#include "config.h"
491 #ifdef BUILD_X11
492 #include <X11/Xlib.h>
493 #include <X11/Xutil.h>
494 #include <X11/extensions/shape.h>
495 #else
496 # define X_DISPLAY_MISSING
497 #endif
498 #include <string.h>
499 #include <stdarg.h>
500 #include "common.h"
501 #include "colormod.h"
502 #include "image.h"
503 #include "scale.h"
504 #include "blend.h"
505 #include "span.h"
506 #ifdef BUILD_X11
507 #include "context.h"
508 #include "color.h"
509 #include "grab.h"
510 #include "rend.h"
511 #include "rgba.h"
512 #include "ximage.h"
513 #include "draw.h"
514 #endif
515 #include "file.h"
516 #include "updates.h"
517 #include "rgbadraw.h"
518 #include "Imlib2.h"
519 #include <ft2build.h>
520 #include FT_FREETYPE_H
521 /*#ifdef HAVE_FREETYPE1_FREETYPE_FREETYPE_H
522 #include <freetype1/freetype/freetype.h>
523 #elif defined(HAVE_FREETYPE_FREETYPE_H)
524 #include <freetype/freetype.h>
525 #else
526 #include <freetype.h>
527 #endif
529 #include "font.h"
530 #include "grad.h"
531 #include "rotate.h"
532 #include "filter.h"
533 #include "dynamic_filters.h"
534 #include "script.h"
535 #include <math.h>
536 #include "color_helpers.h"
538 /* convenience macros */
539 #define CAST_IMAGE(im, image) (im) = (ImlibImage *)(image)
540 #define CHECK_PARAM_POINTER_RETURN(func, sparam, param, ret) \
541 if (!(param)) \
543 fprintf(stderr, "***** Imlib2 Developer Warning ***** :\n" \
544 "\tThis program is calling the Imlib call:\n\n" \
545 "\t%s();\n\n" \
546 "\tWith the parameter:\n\n" \
547 "\t%s\n\n" \
548 "\tbeing NULL. Please fix your program.\n", func, sparam); \
549 return ret; \
552 #define CHECK_PARAM_POINTER(func, sparam, param) \
553 if (!(param)) \
555 fprintf(stderr, "***** Imlib2 Developer Warning ***** :\n" \
556 "\tThis program is calling the Imlib call:\n\n" \
557 "\t%s();\n\n" \
558 "\tWith the parameter:\n\n" \
559 "\t%s\n\n" \
560 "\tbeing NULL. Please fix your program.\n", func, sparam); \
561 return; \
564 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
565 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
567 /* internal typedefs for function pointers */
568 typedef void (*Imlib_Internal_Progress_Function) (void *, char, int, int,
569 int, int);
570 typedef void (*Imlib_Internal_Data_Destructor_Function) (void *, void *);
572 struct _imlibcontext;
573 typedef struct _imlibcontext ImlibContext;
575 struct _imlibcontext {
576 #ifdef BUILD_X11
577 Display *display;
578 Visual *visual;
579 Colormap colormap;
580 int depth;
581 Drawable drawable;
582 Pixmap mask;
583 #endif
584 char anti_alias;
585 char dither;
586 char blend;
587 Imlib_Color_Modifier color_modifier;
588 Imlib_Operation operation;
589 Imlib_Font font;
590 Imlib_Text_Direction direction;
591 double angle;
592 Imlib_Color color;
593 Imlib_Color_Range color_range;
594 Imlib_Image image;
595 Imlib_Progress_Function progress_func;
596 char progress_granularity;
597 char dither_mask;
598 Imlib_Filter filter;
599 Imlib_Rectangle cliprect;
600 Imlib_TTF_Encoding encoding;
602 int references;
603 char dirty;
606 struct _imlibcontextitem;
607 typedef struct _imlibcontextitem ImlibContextItem;
608 struct _imlibcontextitem {
609 ImlibContext *context;
610 ImlibContextItem *below;
613 /* a stack of contexts -- only used by context-handling functions. */
614 static ImlibContextItem *contexts = NULL; /* (ImlibContext*) imlib_context_new(); */
616 /* this is the context all functions use rely on */
617 static ImlibContext *ctx = NULL; /* contexts->context; */
619 /* frees the given context including all its members */
620 void
621 __imlib_free_context(ImlibContext * context)
623 ImlibContextItem *next = contexts;
625 if (ctx == context)
627 next = contexts->below;
628 free(contexts);
629 contexts = next;
632 ctx = context;
634 if (ctx->image)
636 imlib_free_image();
637 ctx->image = NULL;
639 if (ctx->font)
641 imlib_free_font();
642 ctx->font = NULL;
644 if (ctx->color_modifier)
646 imlib_free_color_modifier();
647 ctx->color_modifier = NULL;
649 if (ctx->filter)
651 imlib_free_filter();
652 ctx->filter = NULL;
655 free(ctx);
656 ctx = next->context;
659 Imlib_Context
660 imlib_context_new(void)
662 ImlibContext *context = malloc(sizeof(ImlibContext));
664 #ifdef BUILD_X11
665 context->display = NULL;
666 context->visual = NULL;
667 context->colormap = 0;
668 context->depth = 0;
669 context->drawable = 0;
670 context->mask = 0;
671 #endif
672 context->anti_alias = 1;
673 context->dither = 0;
674 context->blend = 1;
675 context->color_modifier = NULL;
676 context->operation = IMLIB_OP_COPY;
677 context->font = NULL;
678 context->direction = IMLIB_TEXT_TO_RIGHT;
679 context->angle = 0.0;
680 context->color.alpha = 255;
681 context->color.red = 255;
682 context->color.green = 255;
683 context->color.blue = 255;
684 context->color_range = NULL;
685 context->image = NULL;
686 context->progress_func = NULL;
687 context->progress_granularity = 0;
688 context->dither_mask = 0;
689 context->filter = NULL;
690 context->cliprect.x = 0;
691 context->cliprect.y = 0;
692 context->cliprect.w = 0;
693 context->cliprect.h = 0;
694 context->encoding = IMLIB_TTF_ENCODING_ISO_8859_1;
696 context->references = 0;
697 context->dirty = 0;
699 return (Imlib_Context) context;
702 /* frees the given context if it doesn't have any reference anymore. The
703 last (default) context can never be freed.
704 If context is the current context, the context below will be made the
705 current context.
707 void
708 imlib_context_free(Imlib_Context context)
710 ImlibContext *c = (ImlibContext *) context;
712 CHECK_PARAM_POINTER("imlib_context_free", "context", context);
713 if (c == ctx && !contexts->below)
714 return;
716 if (c->references == 0)
717 __imlib_free_context(c);
718 else
719 c->dirty = 1;
722 void
723 imlib_context_push(Imlib_Context context)
725 ImlibContextItem *item;
727 CHECK_PARAM_POINTER("imlib_context_push", "context", context);
728 ctx = (ImlibContext *) context;
730 item = malloc(sizeof(ImlibContextItem));
731 item->context = ctx;
732 item->below = contexts;
733 contexts = item;
735 ctx->references++;
738 void
739 imlib_context_pop(void)
741 ImlibContextItem *item = contexts;
742 ImlibContext *current_ctx = item->context;
744 if (!item->below)
745 return;
747 contexts = item->below;
748 ctx = contexts->context;
749 current_ctx->references--;
750 if (current_ctx->dirty && current_ctx->references <= 0)
751 __imlib_free_context(current_ctx);
753 free(item);
756 Imlib_Context
757 imlib_context_get(void)
759 return (Imlib_Context) ctx;
762 /* context setting/getting functions */
765 * @param x The top left x coordinate of the rectangle.
766 * @param y The top left y coordinate of the rectangle.
767 * @param w The width of the rectangle.
768 * @param h The height of the rectangle.
770 * Sets the rectangle of the current context.
772 void
773 imlib_context_set_cliprect(int x, int y, int w, int h)
775 if (!ctx)
776 ctx = imlib_context_new();
777 ctx->cliprect.x = x;
778 ctx->cliprect.y = y;
779 ctx->cliprect.w = w;
780 ctx->cliprect.h = h;
783 void
784 imlib_context_get_cliprect(int *x, int *y, int *w, int *h)
786 if (!ctx)
787 ctx = imlib_context_new();
788 *x = ctx->cliprect.x;
789 *y = ctx->cliprect.y;
790 *w = ctx->cliprect.w;
791 *h = ctx->cliprect.h;
794 #ifdef BUILD_X11
795 /**
796 * @param display Current display to bu used.
798 * Sets the current X display to be used for rendering of images to
799 * drawables. You do not need to set this if you do not intend to
800 * render an image to an X drawable. If you do you will need to set
801 * this. If you change displays just set this to the new display
802 * pointer. Do not use a Display pointer if you have closed that
803 * display already - also note that if you close a display connection
804 * and continue to render using Imlib2 without setting the display
805 * pointer to NULL or something new, crashes may occur.
807 void
808 imlib_context_set_display(Display * display)
810 if (!ctx)
811 ctx = imlib_context_new();
812 ctx->display = display;
815 /**
816 * @return The current display.
818 * Returns the current display used for Imlib2's display context.
820 Display *
821 imlib_context_get_display(void)
823 if (!ctx)
824 ctx = imlib_context_new();
825 return ctx->display;
829 * @param visual Current visual to use.
831 * Sets the current visual to use when rendering images to
832 * drawables or producing pixmaps. You need to set this for anything to
833 * render to a drawable or produce any pixmaps (this can be the default
834 * visual).
836 void
837 imlib_context_set_visual(Visual * visual)
839 if (!ctx)
840 ctx = imlib_context_new();
841 ctx->visual = visual;
842 ctx->depth = imlib_get_visual_depth(ctx->display, ctx->visual);
845 /**
846 * @return The current visual.
848 * Returns the current visual used for Imlib2's context.
850 Visual *
851 imlib_context_get_visual(void)
853 if (!ctx)
854 ctx = imlib_context_new();
855 return ctx->visual;
859 * @param colormap Colormap to use.
861 * Sets the colormap to use when rendering to drawables and allocating
862 * colors. You must set this to the colormap you are using to render any
863 * images or produce any pixmaps (this can be the default colormap).
865 void
866 imlib_context_set_colormap(Colormap colormap)
868 if (!ctx)
869 ctx = imlib_context_new();
870 ctx->colormap = colormap;
873 /**
874 * @return The current colormap.
876 * Returns the current Colormap used for Imlib2's context.
878 Colormap
879 imlib_context_get_colormap(void)
881 if (!ctx)
882 ctx = imlib_context_new();
883 return ctx->colormap;
887 * @param drawable An X drawable.
889 * Sets the X drawable to which images will be rendered when you call
890 * a render call in Imlib2. This may be either a pixmap or a
891 * window. You must set this to render anything.
893 void
894 imlib_context_set_drawable(Drawable drawable)
896 if (!ctx)
897 ctx = imlib_context_new();
898 ctx->drawable = drawable;
901 /**
902 * @return The current drawable.
904 * Returns the current Drawable used for Imlib2's context.
906 Drawable
907 imlib_context_get_drawable(void)
909 if (!ctx)
910 ctx = imlib_context_new();
911 return ctx->drawable;
915 * @param mask An 1-bit deep pixmap.
917 * Sets the 1-bit deep pixmap to be drawn to when rendering to generate
918 * a mask pixmap. This is only useful if the image you are rendering
919 * has alpha. Set this to 0 to not render a pixmap mask.
921 void
922 imlib_context_set_mask(Pixmap mask)
924 if (!ctx)
925 ctx = imlib_context_new();
926 ctx->mask = mask;
929 /**
930 * @return The current pixmap.
932 * Returns the current pixmap destination to be used to render a mask into.
934 Pixmap
935 imlib_context_get_mask(void)
937 if (!ctx)
938 ctx = imlib_context_new();
939 return ctx->mask;
941 #endif
944 * @param dither_mask The dither mask flag.
946 * Selects if, you are rendering to a mask, or producing pixmap masks
947 * from images, if the mask is to be dithered or not. passing in 1 for
948 * dither_mask means the mask pixmap will be dithered, 0 means it will
949 * not be dithered.
951 void
952 imlib_context_set_dither_mask(char dither_mask)
954 if (!ctx)
955 ctx = imlib_context_new();
956 ctx->dither_mask = dither_mask;
959 /**
960 * @return The current dither mask flag.
962 * Returns the current mode for dithering pixmap masks. 1 means
963 * dithering is enabled and 0 means it is not.
965 char
966 imlib_context_get_dither_mask(void)
968 if (!ctx)
969 ctx = imlib_context_new();
970 return ctx->dither_mask;
974 * @param anti_alias The anti alias flag.
976 * Toggles "anti-aliased" scaling of images. This
977 * isn't quite correct since it's actually super and sub pixel
978 * sampling that it turns on and off, but anti-aliasing is used for
979 * having "smooth" edges to lines and shapes and this means when
980 * images are scaled they will keep their smooth appearance. Passing
981 * in 1 turns this on and 0 turns it off.
983 void
984 imlib_context_set_anti_alias(char anti_alias)
986 if (!ctx)
987 ctx = imlib_context_new();
988 ctx->anti_alias = anti_alias;
991 /**
992 * @return The current anti alias flag.
994 * Returns if Imlib2 currently will smoothly scale images. 1 means it
995 * will and 0 means it will not.
997 char
998 imlib_context_get_anti_alias(void)
1000 if (!ctx)
1001 ctx = imlib_context_new();
1002 return ctx->anti_alias;
1006 * @param dither The dithering flag.
1008 * Sets the dithering flag for rendering to a drawable or when pixmaps
1009 * are produced. This affects the color image appearance by enabling
1010 * dithering. Dithering slows down rendering but produces considerably
1011 * better results. this option has no effect foe rendering in 24 bit
1012 * and up, but in 16 bit and lower it will dither, producing smooth
1013 * gradients and much better quality images. setting dither to 1
1014 * enables it and 0 disables it.
1016 void
1017 imlib_context_set_dither(char dither)
1019 if (!ctx)
1020 ctx = imlib_context_new();
1021 ctx->dither = dither;
1024 /**
1025 * @return The current dithering flag.
1027 * Returns if image data is rendered with dithering currently. 1 means
1028 * yes and 0 means no.
1030 char
1031 imlib_context_get_dither(void)
1033 if (!ctx)
1034 ctx = imlib_context_new();
1035 return ctx->dither;
1039 * @param blend The blending flag.
1041 * When rendering an image to a drawable, Imlib2 is able to blend the
1042 * image directly onto the drawable during rendering. Setting this to 1
1043 * will enable this. If the image has no alpha channel this has no
1044 * effect. Setting it to 0 will disable this.
1046 void
1047 imlib_context_set_blend(char blend)
1049 if (!ctx)
1050 ctx = imlib_context_new();
1051 ctx->blend = blend;
1054 /**
1055 * @return The current blending flag.
1057 * Returns if Imlib2 will blend images onto a drawable whilst
1058 * rendering to that drawable. 1 means yes and 0 means no.
1060 char
1061 imlib_context_get_blend(void)
1063 if (!ctx)
1064 ctx = imlib_context_new();
1065 return ctx->blend;
1069 * @param color_modifier Current color modifier.
1071 * Sets the current color modifier used for rendering pixmaps or
1072 * images to a drawable or images onto other images. Color modifiers
1073 * are lookup tables that map the values in the red, green, blue and
1074 * alpha channels to other values in the same channel when rendering,
1075 * allowing for fades, color correction etc. to be done whilst
1076 * rendering. pass in NULL as the color_modifier to disable the color
1077 * modifier for rendering.
1079 void
1080 imlib_context_set_color_modifier(Imlib_Color_Modifier color_modifier)
1082 if (!ctx)
1083 ctx = imlib_context_new();
1084 ctx->color_modifier = color_modifier;
1087 /**
1088 * @return The current color modifier.
1090 * Returns the current color modifier being used.
1092 Imlib_Color_Modifier
1093 imlib_context_get_color_modifier(void)
1095 if (!ctx)
1096 ctx = imlib_context_new();
1097 return ctx->color_modifier;
1101 * @param operation
1103 * When Imlib2 draws an image onto another or an image onto a drawable
1104 * it is able to do more than just blend the result on using the given
1105 * alpha channel of the image. It is also able to do saturating
1106 * additive, subtractive and a combination of the both (called reshade)
1107 * rendering. The default mode is IMLIB_OP_COPY. you can also set it to
1108 * IMLIB_OP_ADD, IMLIB_OP_SUBTRACT or IMLIB_OP_RESHADE. Use this
1109 * function to set the rendering operation. IMLIB_OP_COPY performs
1110 * basic alpha blending: DST = (SRC * A) + (DST * (1 -
1111 * A)). IMLIB_OP_ADD does DST = DST + (SRC * A). IMLIB_OP_SUBTRACT does
1112 * DST = DST - (SRC * A) and IMLIB_OP_RESHADE does DST = DST + (((SRC -
1113 * 0.5) / 2) * A).
1115 void
1116 imlib_context_set_operation(Imlib_Operation operation)
1118 if (!ctx)
1119 ctx = imlib_context_new();
1120 ctx->operation = operation;
1123 /**
1124 * @return The current operation mode.
1126 * Returns the current operation mode.
1128 Imlib_Operation
1129 imlib_context_get_operation(void)
1131 if (!ctx)
1132 ctx = imlib_context_new();
1133 return ctx->operation;
1137 * @param font Current font.
1139 * Sets the current font to use when rendering text. you should load
1140 * the font first with imlib_load_font().
1142 void
1143 imlib_context_set_font(Imlib_Font font)
1145 if (!ctx)
1146 ctx = imlib_context_new();
1147 ctx->font = font;
1150 /**
1151 * @return The current font.
1153 * Returns the current font.
1155 Imlib_Font
1156 imlib_context_get_font(void)
1158 if (!ctx)
1159 ctx = imlib_context_new();
1160 return ctx->font;
1164 * @param direction Text direction.
1166 * Sets the direction in which to draw text in terms of simple 90
1167 * degree orientations or an arbitrary angle. The direction can be one
1168 * of IMLIB_TEXT_TO_RIGHT, IMLIB_TEXT_TO_LEFT, IMLIB_TEXT_TO_DOWN,
1169 * IMLIB_TEXT_TO_UP or IMLIB_TEXT_TO_ANGLE. The default is
1170 * IMLIB_TEXT_TO_RIGHT. If you use IMLIB_TEXT_TO_ANGLE, you will also
1171 * have to set the angle with imlib_context_set_angle().
1173 void
1174 imlib_context_set_direction(Imlib_Text_Direction direction)
1176 if (!ctx)
1177 ctx = imlib_context_new();
1178 ctx->direction = direction;
1182 * @param angle Angle of the text strings.
1184 * Sets the angle at which text strings will be drawn if the text
1185 * direction has been set to IMLIB_TEXT_TO_ANGLE with
1186 * imlib_context_set_direction().
1188 void
1189 imlib_context_set_angle(double angle)
1191 if (!ctx)
1192 ctx = imlib_context_new();
1193 ctx->angle = angle;
1196 /**
1197 * @return The current angle of the text strings.
1199 * Returns the current angle used to render text at if the direction
1200 * is IMLIB_TEXT_TO_ANGLE.
1202 double
1203 imlib_context_get_angle(void)
1205 if (!ctx)
1206 ctx = imlib_context_new();
1207 return ctx->angle;
1210 /**
1211 * @return The current direction of the text.
1213 * Returns the current direction to render text in.
1215 Imlib_Text_Direction
1216 imlib_context_get_direction(void)
1218 if (!ctx)
1219 ctx = imlib_context_new();
1220 return ctx->direction;
1224 * @param red Red channel of the current color.
1225 * @param green Green channel of the current color.
1226 * @param blue Blue channel of the current color.
1227 * @param alpha Alpha channel of the current color.
1229 * Sets the color with which text, lines and rectangles are drawn when
1230 * being rendered onto an image. Values for @p red, @p green, @p blue
1231 * and @p alpha are between 0 and 255 - any other values have
1232 * undefined results.
1234 void
1235 imlib_context_set_color(int red, int green, int blue, int alpha)
1237 if (!ctx)
1238 ctx = imlib_context_new();
1239 ctx->color.red = red;
1240 ctx->color.green = green;
1241 ctx->color.blue = blue;
1242 ctx->color.alpha = alpha;
1246 * @param red Red channel of the current color.
1247 * @param green Green channel of the current color.
1248 * @param blue Blue channel of the current color.
1249 * @param alpha Alpha channel of the current color.
1251 * Returns the current color for rendering text, rectangles and lines.
1253 void
1254 imlib_context_get_color(int *red, int *green, int *blue, int *alpha)
1256 if (!ctx)
1257 ctx = imlib_context_new();
1258 *red = ctx->color.red;
1259 *green = ctx->color.green;
1260 *blue = ctx->color.blue;
1261 *alpha = ctx->color.alpha;
1264 /**
1265 * @return The current color.
1267 * Returns the current color as a color struct. Do NOT free this
1268 * pointer.
1270 Imlib_Color *
1271 imlib_context_get_imlib_color(void)
1273 if (!ctx)
1274 ctx = imlib_context_new();
1275 return &ctx->color;
1279 * @param hue Hue channel of the current color.
1280 * @param saturation Saturation channel of the current color.
1281 * @param value Value channel of the current color.
1282 * @param alpha Alpha channel of the current color.
1284 * Sets the color in HSVA space. Values for @p hue are between 0 and 360,
1285 * values for @p saturation and @p value between 0 and 1, and values for
1286 * @p alpha are between 0 and 255 - any other values have undefined
1287 * results.
1289 void
1290 imlib_context_set_color_hsva(float hue, float saturation, float value,
1291 int alpha)
1293 int r, g, b;
1295 __imlib_hsv_to_rgb(hue, saturation, value, &r, &g, &b);
1296 imlib_context_set_color(r, g, b, alpha);
1300 * @param hue Hue channel of the current color.
1301 * @param saturation Saturation channel of the current color.
1302 * @param value Value channel of the current color.
1303 * @param alpha Alpha channel of the current color.
1305 * Returns the current color for rendering text, rectangles and lines
1306 * in HSVA space.
1308 void
1309 imlib_context_get_color_hsva(float *hue, float *saturation, float *value,
1310 int *alpha)
1312 int r, g, b;
1314 imlib_context_get_color(&r, &g, &b, alpha);
1315 __imlib_rgb_to_hsv(r, g, b, hue, saturation, value);
1319 * @param hue Hue channel of the current color.
1320 * @param lightness Lightness channel of the current color.
1321 * @param saturation Saturation channel of the current color.
1322 * @param alpha Alpha channel of the current color.
1324 * Sets the color in HLSA space. Values for @p hue are between 0 and 360,
1325 * values for @p lightness and @p saturation between 0 and 1, and values for
1326 * @p alpha are between 0 and 255 - any other values have undefined
1327 * results.
1329 void
1330 imlib_context_set_color_hlsa(float hue, float lightness, float saturation,
1331 int alpha)
1333 int r, g, b;
1335 __imlib_hls_to_rgb(hue, lightness, saturation, &r, &g, &b);
1336 imlib_context_set_color(r, g, b, alpha);
1340 * @param hue Hue channel of the current color.
1341 * @param lightness Lightness channel of the current color.
1342 * @param saturation Saturation channel of the current color.
1343 * @param alpha Alpha channel of the current color.
1345 * Returns the current color for rendering text, rectangles and lines
1346 * in HLSA space.
1348 void
1349 imlib_context_get_color_hlsa(float *hue, float *lightness, float *saturation,
1350 int *alpha)
1352 int r, g, b;
1354 imlib_context_get_color(&r, &g, &b, alpha);
1355 __imlib_rgb_to_hls(r, g, b, hue, lightness, saturation);
1359 * @param cyan Cyan channel of the current color.
1360 * @param magenta Magenta channel of the current color.
1361 * @param yellow Yellow channel of the current color.
1362 * @param alpha Alpha channel of the current color.
1364 * Sets the color in CMYA space. Values for @p cyan, @p magenta, @p yellow and
1365 * @p alpha are between 0 and 255 - any other values have undefined
1366 * results.
1368 void
1369 imlib_context_set_color_cmya(int cyan, int magenta, int yellow, int alpha)
1371 if (!ctx)
1372 ctx = imlib_context_new();
1373 ctx->color.red = 255 - cyan;
1374 ctx->color.green = 255 - magenta;
1375 ctx->color.blue = 255 - yellow;
1376 ctx->color.alpha = alpha;
1380 * @param cyan Cyan channel of the current color.
1381 * @param magenta Magenta channel of the current color.
1382 * @param yellow Yellow channel of the current color.
1383 * @param alpha Alpha channel of the current color.
1385 * Returns the current color for rendering text, rectangles and lines
1386 * in CMYA space.
1388 void
1389 imlib_context_get_color_cmya(int *cyan, int *magenta, int *yellow, int *alpha)
1391 if (!ctx)
1392 ctx = imlib_context_new();
1393 *cyan = 255 - ctx->color.red;
1394 *magenta = 255 - ctx->color.green;
1395 *yellow = 255 - ctx->color.blue;
1396 *alpha = ctx->color.alpha;
1400 * @param color_range Color range.
1402 * Sets the current color range to use for rendering gradients.
1404 void
1405 imlib_context_set_color_range(Imlib_Color_Range color_range)
1407 if (!ctx)
1408 ctx = imlib_context_new();
1409 ctx->color_range = color_range;
1413 * @return The current color range.
1415 * Returns the current color range being used for gradients.
1417 Imlib_Color_Range
1418 imlib_context_get_color_range(void)
1420 if (!ctx)
1421 ctx = imlib_context_new();
1422 return ctx->color_range;
1426 * @param progress_function A progress function.
1428 * Sets the progress function to be called back whilst loading
1429 * images. Set this to the function to be called, or set it to NULL to
1430 * disable progress callbacks whilst loading.
1432 void
1433 imlib_context_set_progress_function(Imlib_Progress_Function progress_function)
1435 if (!ctx)
1436 ctx = imlib_context_new();
1437 ctx->progress_func = progress_function;
1441 * @return The current progress function.
1443 * Returns the current progress function being used.
1445 Imlib_Progress_Function
1446 imlib_context_get_progress_function(void)
1448 if (!ctx)
1449 ctx = imlib_context_new();
1450 return ctx->progress_func;
1454 * @param progress_granularity A char.
1456 * This hints as to how often to call the progress callback. 0 means
1457 * as often as possible. 1 means whenever 15 more of the image has been
1458 * decoded, 10 means every 10% of the image decoding, 50 means every
1459 * 50% and 100 means only call at the end. Values outside of the range
1460 * 0-100 are undefined.
1462 void
1463 imlib_context_set_progress_granularity(char progress_granularity)
1465 if (!ctx)
1466 ctx = imlib_context_new();
1467 ctx->progress_granularity = progress_granularity;
1471 * @return The current progress granularity
1473 * Returns the current progress granularity being used.
1475 char
1476 imlib_context_get_progress_granularity(void)
1478 if (!ctx)
1479 ctx = imlib_context_new();
1480 return ctx->progress_granularity;
1484 * @param image Current image.
1486 * Sets the current image Imlib2 will be using with its function calls.
1488 void
1489 imlib_context_set_image(Imlib_Image image)
1491 if (!ctx)
1492 ctx = imlib_context_new();
1493 ctx->image = image;
1497 * @return The current image.
1499 * Returns the current context image.
1501 Imlib_Image
1502 imlib_context_get_image(void)
1504 if (!ctx)
1505 ctx = imlib_context_new();
1506 return ctx->image;
1509 void
1510 imlib_context_set_TTF_encoding(Imlib_TTF_Encoding encoding)
1512 if (!ctx)
1513 ctx = imlib_context_new();
1514 ctx->encoding = encoding;
1517 Imlib_TTF_Encoding
1518 imlib_context_get_TTF_encoding(void)
1520 if (!ctx)
1521 ctx = imlib_context_new();
1522 return ctx->encoding;
1525 /* imlib api */
1528 * @return The current image size.
1530 * Returns the current size of the image cache in bytes. The cache is
1531 * a unified cache used for image data AND pixmaps.
1534 imlib_get_cache_size(void)
1536 if (!ctx)
1537 ctx = imlib_context_new();
1538 return __imlib_GetCacheSize();
1542 * @param bytes Cache size.
1544 * Sets the cache size. The size is in bytes. Setting the cache size to
1545 * 0 effectively flushes the cache and keeps the cache size at 0 until
1546 * set to another value. Whenever you set the cache size Imlib2 will
1547 * flush as many old images and pixmap from the cache as needed until
1548 * the current cache usage is less than or equal to the cache size.
1550 void
1551 imlib_set_cache_size(int bytes)
1553 if (!ctx)
1554 ctx = imlib_context_new();
1555 __imlib_SetCacheSize(bytes);
1559 * @return The current number of colors.
1561 * Gets the number of colors Imlib2 currently at a maximum is allowed
1562 * to allocate for rendering. The default is 256.
1565 imlib_get_color_usage(void)
1567 if (!ctx)
1568 ctx = imlib_context_new();
1569 #ifdef BUILD_X11
1570 return (int)_max_colors;
1571 #else
1572 return 256;
1573 #endif
1577 * @param max Maximum number of colors.
1579 * Sets the maximum number of colors you would like Imlib2 to allocate
1580 * for you when rendering. The default is 256. This has no effect in
1581 * depths greater than 8 bit.
1583 void
1584 imlib_set_color_usage(int max)
1586 if (!ctx)
1587 ctx = imlib_context_new();
1588 #ifdef BUILD_X11
1589 if (max < 2)
1590 max = 2;
1591 else if (max > 256)
1592 max = 256;
1593 _max_colors = max;
1594 #endif
1598 * If you want Imlib2 to forcibly flush any cached loaders it has and
1599 * re-load them from disk (this is useful if the program just
1600 * installed a new loader and does not want to wait till Imlib2 deems
1601 * it an optimal time to rescan the loaders)
1603 void
1604 imlib_flush_loaders(void)
1606 if (!ctx)
1607 ctx = imlib_context_new();
1608 __imlib_RemoveAllLoaders();
1611 #ifdef BUILD_X11
1613 * @param display The current display
1614 * @param visual The current visual
1615 * @return
1617 * Convenience function that returns the depth of a visual for that
1618 * display.
1621 imlib_get_visual_depth(Display * display, Visual * visual)
1623 if (!ctx)
1624 ctx = imlib_context_new();
1625 CHECK_PARAM_POINTER_RETURN("imlib_get_visual_depth", "display", display, 0);
1626 CHECK_PARAM_POINTER_RETURN("imlib_get_visual_depth", "visual", visual, 0);
1627 return __imlib_XActualDepth(display, visual);
1631 * @param display The current display
1632 * @param screen The screen
1633 * @param depth_return The depth of the returned visual.
1634 * @return The best visual.
1636 * Returns the visual for the display @p display and the screen @p
1637 * screen that Imlib2 thinks
1638 * will give you the best quality output. @p depth_return should point to
1639 * an int that will be filled with the depth of that visual too.
1641 Visual *
1642 imlib_get_best_visual(Display * display, int screen, int *depth_return)
1644 if (!ctx)
1645 ctx = imlib_context_new();
1646 CHECK_PARAM_POINTER_RETURN("imlib_get_best_visual", "display", display,
1647 NULL);
1648 CHECK_PARAM_POINTER_RETURN("imlib_get_best_visual", "depth_return",
1649 depth_return, NULL);
1650 return __imlib_BestVisual(display, screen, depth_return);
1652 #endif
1655 * @param file Image file.
1656 * @return An image handle.
1658 * Loads an image from disk located at the path specified by
1659 * @p file. Please see the section \ref loading for more
1660 * detail. Returns an image handle on success or NULL on failure.
1662 Imlib_Image
1663 imlib_load_image(const char *file)
1665 Imlib_Image im = NULL;
1666 Imlib_Image prev_ctxt_image;
1668 if (!ctx)
1669 ctx = imlib_context_new();
1670 CHECK_PARAM_POINTER_RETURN("imlib_load_image", "file", file, NULL);
1671 prev_ctxt_image = ctx->image;
1672 im = __imlib_LoadImage(file, (ImlibProgressFunction) ctx->progress_func,
1673 ctx->progress_granularity, 0, 0, NULL);
1674 ctx->image = prev_ctxt_image;
1675 return (Imlib_Image) im;
1679 * @param file Image file.
1680 * @return An image handle.
1682 * Loads an image from disk located at the path specified by
1683 * @p file. This forces the image data to be decoded at load time too,
1684 * instead of decoding being deferred until it is needed. Returns an
1685 * image handle on success or NULL on failure.
1687 Imlib_Image
1688 imlib_load_image_immediately(const char *file)
1690 Imlib_Image im = NULL;
1691 Imlib_Image prev_ctxt_image;
1693 if (!ctx)
1694 ctx = imlib_context_new();
1695 CHECK_PARAM_POINTER_RETURN("imlib_load_image_immediately", "file", file,
1696 NULL);
1697 prev_ctxt_image = ctx->image;
1698 im = __imlib_LoadImage(file, (ImlibProgressFunction) ctx->progress_func,
1699 ctx->progress_granularity, 1, 0, NULL);
1700 ctx->image = prev_ctxt_image;
1701 return (Imlib_Image) im;
1705 * @param file Image file.
1706 * @return An image handle.
1708 * Loads the image without looking in the cache first. Returns an
1709 * image handle on success or NULL on failure.
1711 Imlib_Image
1712 imlib_load_image_without_cache(const char *file)
1714 Imlib_Image im = NULL;
1715 Imlib_Image prev_ctxt_image;
1717 if (!ctx)
1718 ctx = imlib_context_new();
1719 CHECK_PARAM_POINTER_RETURN("imlib_load_image_without_cache", "file",
1720 file, NULL);
1721 prev_ctxt_image = ctx->image;
1722 im = __imlib_LoadImage(file, (ImlibProgressFunction) ctx->progress_func,
1723 ctx->progress_granularity, 0, 1, NULL);
1724 ctx->image = prev_ctxt_image;
1725 return (Imlib_Image) im;
1729 * @param file Image file.
1730 * @return An image handle.
1732 * Loads the image without deferred image data decoding (i.e. it is
1733 * decoded straight away) and without looking in the cache. Returns an
1734 * image handle on success or NULL on failure.
1736 Imlib_Image
1737 imlib_load_image_immediately_without_cache(const char *file)
1739 Imlib_Image im = NULL;
1740 Imlib_Image prev_ctxt_image;
1742 if (!ctx)
1743 ctx = imlib_context_new();
1744 CHECK_PARAM_POINTER_RETURN("imlib_load_image_immediately_without_cache",
1745 "file", file, NULL);
1746 prev_ctxt_image = ctx->image;
1747 im = __imlib_LoadImage(file, (ImlibProgressFunction) ctx->progress_func,
1748 ctx->progress_granularity, 1, 1, NULL);
1749 ctx->image = prev_ctxt_image;
1750 return (Imlib_Image) im;
1754 * @param file Image file.
1755 * @param error_return The returned error.
1756 * @return An image handle.
1758 * Loads an image at the path @p file on disk. If it succeeds it returns
1759 * a valid image handle, if not NULL is returned and @p error_return
1760 * is set to the detail of the error.
1762 Imlib_Image
1763 imlib_load_image_with_error_return(const char *file,
1764 Imlib_Load_Error * error_return)
1766 Imlib_Image im = NULL;
1767 ImlibLoadError er;
1768 Imlib_Image prev_ctxt_image;
1770 if (!ctx)
1771 ctx = imlib_context_new();
1772 CHECK_PARAM_POINTER_RETURN("imlib_load_image_with_error_return", "file",
1773 file, NULL);
1774 if (!__imlib_FileExists(file))
1776 *error_return = IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST;
1777 return NULL;
1779 if (__imlib_FileIsDir(file))
1781 *error_return = IMLIB_LOAD_ERROR_FILE_IS_DIRECTORY;
1782 return NULL;
1784 if (!__imlib_FileCanRead(file))
1786 *error_return = IMLIB_LOAD_ERROR_PERMISSION_DENIED_TO_READ;
1787 return NULL;
1789 prev_ctxt_image = ctx->image;
1790 im = (Imlib_Image) __imlib_LoadImage(file,
1791 (ImlibProgressFunction)
1792 ctx->progress_func,
1793 ctx->progress_granularity, 1, 0, &er);
1794 ctx->image = prev_ctxt_image;
1795 if (im)
1796 *error_return = IMLIB_LOAD_ERROR_NONE;
1797 else
1799 if (er == IMLIB_LOAD_ERROR_NONE)
1800 *error_return = IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT;
1801 else
1802 *error_return = (Imlib_Load_Error) er;
1804 return im;
1808 * Frees the image that is set as the current image in Imlib2's context.
1810 void
1811 imlib_free_image(void)
1813 if (!ctx)
1814 ctx = imlib_context_new();
1815 CHECK_PARAM_POINTER("imlib_free_image", "image", ctx->image);
1816 __imlib_FreeImage(ctx->image);
1817 ctx->image = NULL;
1821 * Frees the current image in Imlib2's context AND removes it from the
1822 * cache.
1824 void
1825 imlib_free_image_and_decache(void)
1827 ImlibImage *im;
1829 if (!ctx)
1830 ctx = imlib_context_new();
1831 CHECK_PARAM_POINTER("imlib_free_image_and_decache", "image", ctx->image);
1832 CAST_IMAGE(im, ctx->image);
1833 SET_FLAG(im->flags, F_INVALID);
1834 __imlib_FreeImage(im);
1835 ctx->image = NULL;
1839 * Returns the width in pixels of the current image in Imlib2's context.
1842 imlib_image_get_width(void)
1844 ImlibImage *im;
1846 if (!ctx)
1847 ctx = imlib_context_new();
1848 CHECK_PARAM_POINTER_RETURN("imlib_image_get_width", "image", ctx->image, 0);
1849 CAST_IMAGE(im, ctx->image);
1850 return im->w;
1854 * Returns the height in pixels of the current image in Imlib2's context.
1857 imlib_image_get_height(void)
1859 ImlibImage *im;
1861 if (!ctx)
1862 ctx = imlib_context_new();
1863 CHECK_PARAM_POINTER_RETURN("imlib_image_get_height", "image", ctx->image, 0);
1864 CAST_IMAGE(im, ctx->image);
1865 return im->h;
1869 * @return The current filename.
1871 * Returns the filename for the file that is set as the current
1872 * context. The pointer returned is only valid as long as no operations
1873 * cause the filename of the image to change. Saving the file with a
1874 * different name would cause this. It is suggested you duplicate the
1875 * string if you wish to continue to use the string for later
1876 * processing. Do not free the string pointer returned by this
1877 * function.
1879 const char *
1880 imlib_image_get_filename(void)
1882 ImlibImage *im;
1884 if (!ctx)
1885 ctx = imlib_context_new();
1886 CHECK_PARAM_POINTER_RETURN("imlib_image_get_filename", "image", ctx->image,
1888 CAST_IMAGE(im, ctx->image);
1889 /* strdup() the returned value if you want to alter it! */
1890 return (const char *)(im->file);
1894 * @return A pointer to the image data.
1896 * Returns a pointer to the image data in the image set as the image
1897 * for the current context. When you get this pointer it is assumed you
1898 * are planning on writing to the data, thus once you do this the image
1899 * can no longer be used for caching - in fact all images cached from
1900 * this one will also be affected when you put the data back. If this
1901 * matters it is suggested you clone the image first before playing
1902 * with the image data. The image data is returned in the format of a
1903 * DATA32 (32 bits) per pixel in a linear array ordered from the top
1904 * left of the image to the bottom right going from left to right each
1905 * line. Each pixel has the upper 8 bits as the alpha channel and the
1906 * lower 8 bits are the blue channel - so a pixel's bits are ARGB (from
1907 * most to least significant, 8 bits per channel). You must put the
1908 * data back at some point.
1910 DATA32 *
1911 imlib_image_get_data(void)
1913 ImlibImage *im;
1915 if (!ctx)
1916 ctx = imlib_context_new();
1917 CHECK_PARAM_POINTER_RETURN("imlib_image_get_data", "image", ctx->image,
1918 NULL);
1919 CAST_IMAGE(im, ctx->image);
1920 if ((!(im->data)) && (im->loader) && (im->loader->load))
1921 im->loader->load(im, NULL, 0, 1);
1922 if (!im->data)
1923 return NULL;
1924 __imlib_DirtyImage(im);
1925 return im->data;
1929 * @return A pointer to the image data.
1931 * Functions the same way as imlib_image_get_data(), but returns a
1932 * pointer expecting the program to NOT write to the data returned (it
1933 * is for inspection purposes only). Writing to this data has undefined
1934 * results. The data does not need to be put back.
1936 DATA32 *
1937 imlib_image_get_data_for_reading_only(void)
1939 ImlibImage *im;
1941 if (!ctx)
1942 ctx = imlib_context_new();
1943 CHECK_PARAM_POINTER_RETURN("imlib_image_get_data_for_reading_only",
1944 "image", ctx->image, NULL);
1945 CAST_IMAGE(im, ctx->image);
1946 if ((!(im->data)) && (im->loader) && (im->loader->load))
1947 im->loader->load(im, NULL, 0, 1);
1948 if (!im->data)
1949 return NULL;
1950 return im->data;
1954 * @param data The pointer to the image data.
1956 * Puts back @p data when it was obtained by
1957 * imlib_image_get_data(). @p data must be the same pointer returned
1958 * by imlib_image_get_data(). This operated on the current context
1959 * image.
1961 void
1962 imlib_image_put_back_data(DATA32 * data)
1964 ImlibImage *im;
1966 if (!ctx)
1967 ctx = imlib_context_new();
1968 CHECK_PARAM_POINTER("imlib_image_put_back_data", "image", ctx->image);
1969 CHECK_PARAM_POINTER("imlib_image_put_back_data", "data", data);
1970 CAST_IMAGE(im, ctx->image);
1971 __imlib_DirtyImage(im);
1972 data = NULL;
1976 * @return Current alpha channel flag.
1978 * Returns 1 if the current context image has an alpha channel, or 0
1979 * if it does not (the alpha data space is still there and available -
1980 * just "unused").
1982 char
1983 imlib_image_has_alpha(void)
1985 ImlibImage *im;
1987 if (!ctx)
1988 ctx = imlib_context_new();
1989 CHECK_PARAM_POINTER_RETURN("imlib_image_has_alpha", "image", ctx->image, 0);
1990 CAST_IMAGE(im, ctx->image);
1991 if (IMAGE_HAS_ALPHA(im))
1992 return 1;
1993 return 0;
1997 * By default Imlib2 will not check the timestamp of an image on disk
1998 * and compare it with the image in its cache - this is to minimize
1999 * disk activity when using the cache. Call this function and it will
2000 * flag the current context image as being liable to change on disk
2001 * and Imlib2 will check the timestamp of the image file on disk and
2002 * compare it with the cached image when it next needs to use this
2003 * image in the cache.
2005 void
2006 imlib_image_set_changes_on_disk(void)
2008 ImlibImage *im;
2010 if (!ctx)
2011 ctx = imlib_context_new();
2012 CHECK_PARAM_POINTER("imlib_image_set_never_changes_on_disk", "image",
2013 ctx->image);
2014 CAST_IMAGE(im, ctx->image);
2015 SET_FLAG(im->flags, F_ALWAYS_CHECK_DISK);
2019 * @param border The border of the image.
2021 * Fills the Imlib_Border structure to which @p border points to with the
2022 * values of the border of the current context image. The border is the
2023 * area at the edge of the image that does not scale with the rest of
2024 * the image when resized - the borders remain constant in size. This
2025 * is useful for scaling bevels at the edge of images differently to
2026 * the image center.
2028 void
2029 imlib_image_get_border(Imlib_Border * border)
2031 ImlibImage *im;
2033 if (!ctx)
2034 ctx = imlib_context_new();
2035 CHECK_PARAM_POINTER("imlib_image_get_border", "image", ctx->image);
2036 CHECK_PARAM_POINTER("imlib_image_get_border", "border", border);
2037 CAST_IMAGE(im, ctx->image);
2038 border->left = im->border.left;
2039 border->right = im->border.right;
2040 border->top = im->border.top;
2041 border->bottom = im->border.bottom;
2045 * @param border The border of the image.
2047 * Sets the border of the current context image to the values contained
2048 * in the Imlib_Border structure @p border points to.
2050 void
2051 imlib_image_set_border(Imlib_Border * border)
2053 ImlibImage *im;
2055 if (!ctx)
2056 ctx = imlib_context_new();
2057 CHECK_PARAM_POINTER("imlib_image_set_border", "image", ctx->image);
2058 CHECK_PARAM_POINTER("imlib_image_set_border", "border", border);
2059 CAST_IMAGE(im, ctx->image);
2060 if ((im->border.left == border->left)
2061 && (im->border.right == border->right)
2062 && (im->border.top == border->top)
2063 && (im->border.bottom == border->bottom))
2064 return;
2065 im->border.left = border->left;
2066 im->border.right = border->right;
2067 im->border.top = border->top;
2068 im->border.bottom = border->bottom;
2069 __imlib_DirtyPixmapsForImage(im);
2073 * @param format Format of the image.
2075 * Sets the format of the current image. This is used for when you
2076 * wish to save an image in a different format that it was loaded in,
2077 * or if the image currently has no file format associated with it.
2079 void
2080 imlib_image_set_format(const char *format)
2082 ImlibImage *im;
2084 if (!ctx)
2085 ctx = imlib_context_new();
2086 CHECK_PARAM_POINTER("imlib_image_set_format", "image", ctx->image);
2087 CHECK_PARAM_POINTER("imlib_image_set_format", "format", format);
2088 CAST_IMAGE(im, ctx->image);
2089 if (im->format)
2090 free(im->format);
2091 if (format)
2092 im->format = strdup(format);
2093 else
2094 im->format = NULL;
2095 if (!(im->flags & F_FORMAT_IRRELEVANT))
2097 __imlib_DirtyImage(im);
2102 * @param irrelevant Irrelevant format flag.
2104 * Sets if the format value of the current image is irrelevant for
2105 * caching purposes - by default it is. pass irrelevant as 1 to make it
2106 * irrelevant and 0 to make it relevant for caching.
2108 void
2109 imlib_image_set_irrelevant_format(char irrelevant)
2111 ImlibImage *im;
2113 if (!ctx)
2114 ctx = imlib_context_new();
2115 CHECK_PARAM_POINTER("imlib_image_set_irrelevant_format", "image",
2116 ctx->image);
2117 CAST_IMAGE(im, ctx->image);
2118 if (irrelevant)
2120 SET_FLAG(im->flags, F_FORMAT_IRRELEVANT);
2122 else
2124 UNSET_FLAG(im->flags, F_FORMAT_IRRELEVANT);
2129 * @param irrelevant Irrelevant border flag.
2131 * Sets if the border of the current image is irrelevant for caching
2132 * purposes. By default it is. Set irrelevant to 1 to make it
2133 * irrelevant, and 0 to make it relevant.
2135 void
2136 imlib_image_set_irrelevant_border(char irrelevant)
2138 ImlibImage *im;
2140 if (!ctx)
2141 ctx = imlib_context_new();
2142 CHECK_PARAM_POINTER("imlib_image_set_irrelevant_border", "image",
2143 ctx->image);
2144 CAST_IMAGE(im, ctx->image);
2145 if (irrelevant)
2147 SET_FLAG(im->flags, F_BORDER_IRRELEVANT);
2149 else
2151 UNSET_FLAG(im->flags, F_BORDER_IRRELEVANT);
2156 * @param irrelevant Irrelevant alpha flag.
2158 * Sets if the alpha channel status of the current image (i.e. if
2159 * there is or is not one) is important for caching purposes. By
2160 * default it is not. Set irrelevant to 1 to make it irrelevant and 0
2161 * to make it relevant.
2163 void
2164 imlib_image_set_irrelevant_alpha(char irrelevant)
2166 ImlibImage *im;
2168 if (!ctx)
2169 ctx = imlib_context_new();
2170 CHECK_PARAM_POINTER("imlib_image_set_irrelevant_alpha", "image", ctx->image);
2171 CAST_IMAGE(im, ctx->image);
2172 if (irrelevant)
2174 SET_FLAG(im->flags, F_ALPHA_IRRELEVANT);
2176 else
2178 UNSET_FLAG(im->flags, F_ALPHA_IRRELEVANT);
2183 * @return Current image format.
2185 * Returns the current image's format. Do not free this
2186 * string. Duplicate it if you need it for later use.
2188 char *
2189 imlib_image_format(void)
2191 ImlibImage *im;
2193 if (!ctx)
2194 ctx = imlib_context_new();
2195 CHECK_PARAM_POINTER_RETURN("imlib_image_format", "image", ctx->image, NULL);
2196 CAST_IMAGE(im, ctx->image);
2197 return im->format;
2201 * @param has_alpha Alpha flag.
2203 * Sets the alpha flag for the current image. Set @p has_alpha to 1 to
2204 * enable the alpha channel in the current image, or 0 to disable it.
2206 void
2207 imlib_image_set_has_alpha(char has_alpha)
2209 ImlibImage *im;
2211 if (!ctx)
2212 ctx = imlib_context_new();
2213 CHECK_PARAM_POINTER("imlib_image_set_has_alpha", "image", ctx->image);
2214 CAST_IMAGE(im, ctx->image);
2215 if (has_alpha)
2216 SET_FLAG(im->flags, F_HAS_ALPHA);
2217 else
2218 UNSET_FLAG(im->flags, F_HAS_ALPHA);
2221 #ifdef BUILD_X11
2223 * @param pixmap_return The returned pixmap.
2224 * @param mask_return The returned mask.
2226 * Creates a pixmap of the current image (and a mask if the image has
2227 * an alpha value) and return the id's of the pixmap and mask to
2228 * @p pixmap_return and @p mask_return pixmap id's. You must free these
2229 * pixmaps using Imlib2's free function imlib_free_pixmap_and_mask();.
2231 void
2232 imlib_render_pixmaps_for_whole_image(Pixmap * pixmap_return,
2233 Pixmap * mask_return)
2235 ImlibImage *im;
2237 if (!ctx)
2238 ctx = imlib_context_new();
2239 CHECK_PARAM_POINTER("imlib_render_pixmaps_for_whole_image", "image",
2240 ctx->image);
2241 CHECK_PARAM_POINTER("imlib_render_pixmaps_for_whole_image",
2242 "pixmap_return", pixmap_return);
2243 CHECK_PARAM_POINTER("imlib_render_pixmaps_for_whole_image", "mask_return",
2244 mask_return);
2245 CAST_IMAGE(im, ctx->image);
2246 if ((!(im->data)) && (im->loader) && (im->loader->load))
2247 im->loader->load(im, NULL, 0, 1);
2248 if (!(im->data))
2249 return;
2250 __imlib_CreatePixmapsForImage(ctx->display, ctx->drawable, ctx->visual,
2251 ctx->depth, ctx->colormap, im, pixmap_return,
2252 mask_return, 0, 0, im->w, im->h, im->w,
2253 im->h, 0, ctx->dither, ctx->dither_mask,
2254 ctx->color_modifier);
2258 * @param pixmap_return The returned pixmap.
2259 * @param mask_return The returned mask.
2260 * @param width Width of the pixmap.
2261 * @param height Height of the pixmap.
2263 * Works just like imlib_render_pixmaps_for_whole_image(), but will
2264 * scale the output result to the width @p width and height @p height
2265 * specified. Scaling
2266 * is done before depth conversion so pixels used for dithering don't
2267 * grow large.
2269 void
2270 imlib_render_pixmaps_for_whole_image_at_size(Pixmap * pixmap_return,
2271 Pixmap * mask_return, int width,
2272 int height)
2274 ImlibImage *im;
2276 if (!ctx)
2277 ctx = imlib_context_new();
2278 CHECK_PARAM_POINTER("imlib_render_pixmaps_for_whole_image_at_size",
2279 "image", ctx->image);
2280 CHECK_PARAM_POINTER("imlib_render_pixmaps_for_whole_image_at_size",
2281 "pixmap_return", pixmap_return);
2282 CHECK_PARAM_POINTER("imlib_render_pixmaps_for_whole_image_at_size",
2283 "mask_return", mask_return);
2284 CAST_IMAGE(im, ctx->image);
2285 if ((!(im->data)) && (im->loader) && (im->loader->load))
2286 im->loader->load(im, NULL, 0, 1);
2288 if (!(im->data))
2289 return;
2290 __imlib_CreatePixmapsForImage(ctx->display, ctx->drawable, ctx->visual,
2291 ctx->depth, ctx->colormap, im, pixmap_return,
2292 mask_return, 0, 0, im->w, im->h, width,
2293 height, ctx->anti_alias, ctx->dither,
2294 ctx->dither_mask, ctx->color_modifier);
2298 * @param pixmap The pixmap.
2300 * Frees @p pixmap (and any mask generated in association with that
2301 * pixmap). The pixmap will remain cached until the image the pixmap
2302 * was generated from is dirtied or decached, or the cache is flushed.
2304 void
2305 imlib_free_pixmap_and_mask(Pixmap pixmap)
2307 if (!ctx)
2308 ctx = imlib_context_new();
2309 __imlib_FreePixmap(ctx->display, pixmap);
2313 * @param x X coordinate of the pixel.
2314 * @param y Y coordinate of the pixel.
2316 * Renders the current image onto the current drawable at the (@p x, @p y)
2317 * pixel location specified without scaling.
2319 void
2320 imlib_render_image_on_drawable(int x, int y)
2322 ImlibImage *im;
2324 if (!ctx)
2325 ctx = imlib_context_new();
2326 CHECK_PARAM_POINTER("imlib_render_image_on_drawable", "image", ctx->image);
2327 CAST_IMAGE(im, ctx->image);
2328 if ((!(im->data)) && (im->loader) && (im->loader->load))
2329 im->loader->load(im, NULL, 0, 1);
2330 if (!(im->data))
2331 return;
2332 __imlib_RenderImage(ctx->display, im, ctx->drawable, ctx->mask,
2333 ctx->visual, ctx->colormap, ctx->depth, 0, 0, im->w,
2334 im->h, x, y, im->w, im->h, 0, ctx->dither, ctx->blend,
2335 ctx->dither_mask, ctx->color_modifier, ctx->operation);
2339 * @param x X coordinate of the pixel.
2340 * @param y Y coordinate of the pixel.
2341 * @param width Width of the rendered image.
2342 * @param height Height of the rendered image.
2344 * Renders the current image onto the current drawable at the (@p x, @p y)
2345 * location specified AND scale the image to the width @p width and height
2346 * @p height.
2348 void
2349 imlib_render_image_on_drawable_at_size(int x, int y, int width, int height)
2351 ImlibImage *im;
2353 if (!ctx)
2354 ctx = imlib_context_new();
2355 CHECK_PARAM_POINTER("imlib_render_image_on_drawable_at_size", "image",
2356 ctx->image);
2357 CAST_IMAGE(im, ctx->image);
2358 if ((!(im->data)) && (im->loader) && (im->loader->load))
2359 im->loader->load(im, NULL, 0, 1);
2360 if (!(im->data))
2361 return;
2362 __imlib_RenderImage(ctx->display, im, ctx->drawable, ctx->mask,
2363 ctx->visual, ctx->colormap, ctx->depth, 0, 0, im->w,
2364 im->h, x, y, width, height, ctx->anti_alias,
2365 ctx->dither, ctx->blend, ctx->dither_mask,
2366 ctx->color_modifier, ctx->operation);
2370 * @param source_x X coordinate of the source image.
2371 * @param source_y Y coordinate of the source image.
2372 * @param source_width Width of the source image.
2373 * @param source_height Height of the source image.
2374 * @param x X coordinate of the destination image.
2375 * @param y Y coordinate of the destination image.
2376 * @param width Width of the destination image.
2377 * @param height Height of the destination image.
2379 * Renders the source (@p source_x, @p source_y, @p source_width, @p source_height) pixel
2380 * rectangle from the
2381 * current image onto the current drawable at the (@p x, @p y) location scaled
2382 * to the width @p width and height @p height.
2384 void
2385 imlib_render_image_part_on_drawable_at_size(int source_x, int source_y,
2386 int source_width,
2387 int source_height, int x, int y,
2388 int width, int height)
2390 ImlibImage *im;
2392 if (!ctx)
2393 ctx = imlib_context_new();
2394 CHECK_PARAM_POINTER("imlib_render_image_part_on_drawable_at_size", "image",
2395 ctx->image);
2396 CAST_IMAGE(im, ctx->image);
2397 if ((!(im->data)) && (im->loader) && (im->loader->load))
2398 im->loader->load(im, NULL, 0, 1);
2399 if (!(im->data))
2400 return;
2401 __imlib_RenderImage(ctx->display, im, ctx->drawable, 0, ctx->visual,
2402 ctx->colormap, ctx->depth, source_x, source_y,
2403 source_width, source_height, x, y, width, height,
2404 ctx->anti_alias, ctx->dither, ctx->blend, 0,
2405 ctx->color_modifier, ctx->operation);
2408 DATA32
2409 imlib_render_get_pixel_color(void)
2411 if (!ctx)
2412 ctx = imlib_context_new();
2413 return __imlib_RenderGetPixel(ctx->display, ctx->drawable, ctx->visual,
2414 ctx->colormap, ctx->depth,
2415 (DATA8) ctx->color.red,
2416 (DATA8) ctx->color.green,
2417 (DATA8) ctx->color.blue);
2420 #endif
2423 * @param source_image The source image.
2424 * @param merge_alpha Alpha flag.
2425 * @param source_x X coordinate of the source image.
2426 * @param source_y Y coordinate of the source image.
2427 * @param source_width Width of the source image.
2428 * @param source_height Height of the source image.
2429 * @param destination_x X coordinate of the destination image.
2430 * @param destination_y Y coordinate of the destination image.
2431 * @param destination_width Width of the destination image.
2432 * @param destination_height Height of the destination image.
2434 * Blends the source rectangle (@p source_x, @p source_y, @p
2435 * source_width, @p source_height) from
2436 * @p source_image onto the current image at the destination (@p
2437 * destination_x, @p destination_y) location
2438 * scaled to the width @p destination_width and height @p
2439 * destination_height. If @p merge_alpha is set to 1
2440 * it will also modify the destination image alpha channel, otherwise
2441 * the destination alpha channel is left untouched.
2443 void
2444 imlib_blend_image_onto_image(Imlib_Image source_image, char merge_alpha,
2445 int source_x, int source_y, int source_width,
2446 int source_height, int destination_x,
2447 int destination_y, int destination_width,
2448 int destination_height)
2450 ImlibImage *im_src, *im_dst;
2451 int aa;
2453 if (!ctx)
2454 ctx = imlib_context_new();
2455 CHECK_PARAM_POINTER("imlib_blend_image_onto_image", "source_image",
2456 source_image);
2457 CHECK_PARAM_POINTER("imlib_blend_image_onto_image", "image", ctx->image);
2458 CAST_IMAGE(im_src, source_image);
2459 CAST_IMAGE(im_dst, ctx->image);
2460 if ((!(im_src->data)) && (im_src->loader) && (im_src->loader->load))
2461 im_src->loader->load(im_src, NULL, 0, 1);
2462 if (!(im_src->data))
2463 return;
2464 if ((!(im_dst->data)) && (im_dst->loader) && (im_dst->loader->load))
2465 im_dst->loader->load(im_dst, NULL, 0, 1);
2466 if (!(im_dst->data))
2467 return;
2468 __imlib_DirtyImage(im_dst);
2469 /* FIXME: hack to get around infinite loops for scaling down too far */
2470 aa = ctx->anti_alias;
2471 if ((abs(destination_width) < (source_width >> 7))
2472 || (abs(destination_height) < (source_height >> 7)))
2473 aa = 0;
2474 __imlib_BlendImageToImage(im_src, im_dst, aa, ctx->blend,
2475 merge_alpha, source_x, source_y, source_width,
2476 source_height, destination_x, destination_y,
2477 destination_width, destination_height,
2478 ctx->color_modifier, ctx->operation,
2479 ctx->cliprect.x, ctx->cliprect.y,
2480 ctx->cliprect.w, ctx->cliprect.h);
2484 * @param width The width of the image.
2485 * @param height The height of the image.
2486 * @return A new blank image.
2488 * Creates a new blank image of size @p width and @p height. The contents of
2489 * this image at creation time are undefined (they could be garbage
2490 * memory). You are free to do whatever you like with this image. It
2491 * is not cached. On success an image handle is returned - on failure
2492 * NULL is returned.
2494 Imlib_Image
2495 imlib_create_image(int width, int height)
2497 DATA32 *data;
2499 if (!ctx)
2500 ctx = imlib_context_new();
2501 if ((width <= 0) || (height <= 0))
2502 return NULL;
2503 data = malloc(width * height * sizeof(DATA32));
2504 if (data)
2505 return (Imlib_Image) __imlib_CreateImage(width, height, data);
2506 return NULL;
2510 * @param width The width of the image.
2511 * @param height The height of the image.
2512 * @param data The data.
2513 * @return A valid image, otherwise NULL.
2515 * Creates an image from the image data specified with the width @p width and
2516 * the height @p height specified. The image data @p data must be in the same format as
2517 * imlib_image_get_data() would return. You are responsible for
2518 * freeing this image data once the image is freed - Imlib2 will not
2519 * do that for you. This is useful for when you already have static
2520 * buffers of the same format Imlib2 uses (many video grabbing devices
2521 * use such a format) and wish to use Imlib2 to render the results
2522 * onto another image, or X drawable. You should free the image when
2523 * you are done with it. Imlib2 returns a valid image handle on
2524 * success or NULL on failure
2527 Imlib_Image
2528 imlib_create_image_using_data(int width, int height, DATA32 * data)
2530 ImlibImage *im;
2532 if (!ctx)
2533 ctx = imlib_context_new();
2534 CHECK_PARAM_POINTER_RETURN("imlib_create_image_using_data", "data", data,
2535 NULL);
2536 if ((width <= 0) || (height <= 0))
2537 return NULL;
2538 im = __imlib_CreateImage(width, height, data);
2539 if (im)
2540 SET_FLAG(im->flags, F_DONT_FREE_DATA);
2541 return (Imlib_Image) im;
2545 * @param width The width of the image.
2546 * @param height The height of the image.
2547 * @param data The data.
2548 * @return A valid image, otherwise NULL.
2550 * Works the same way as imlib_create_image_using_data() but Imlib2
2551 * copies the image data to the image structure. You may now do
2552 * whatever you wish with the original data as it will not be needed
2553 * anymore. Imlib2 returns a valid image handle on success or NULL on
2554 * failure.
2557 Imlib_Image
2558 imlib_create_image_using_copied_data(int width, int height, DATA32 * data)
2560 ImlibImage *im;
2562 if (!ctx)
2563 ctx = imlib_context_new();
2564 CHECK_PARAM_POINTER_RETURN("imlib_create_image_using_copied_data", "data",
2565 data, NULL);
2566 if ((width <= 0) || (height <= 0))
2567 return NULL;
2568 im = __imlib_CreateImage(width, height, NULL);
2569 if (!im)
2570 return NULL;
2571 im->data = malloc(width * height * sizeof(DATA32));
2572 if (data)
2574 memcpy(im->data, data, width * height * sizeof(DATA32));
2575 return (Imlib_Image) im;
2577 else
2578 __imlib_FreeImage(im);
2579 return NULL;
2582 #ifdef BUILD_X11
2584 * @param mask A mask.
2585 * @param x The top left x coordinate of the rectangle.
2586 * @param y The top left y coordinate of the rectangle.
2587 * @param width The width of the rectangle.
2588 * @param height The height of the rectangle.
2589 * @param need_to_grab_x Grab flag.
2590 * @return a valid image, otherwise NULL.
2592 * Return an image (using the mask @p mask to determine the alpha channel)
2593 * from the current drawable. If the mask is 0 it will not create a
2594 * useful alpha channel in the image. It will create an image from the
2595 * (@p x, @p y, @p width , @p height) rectangle in the drawable. If @p
2596 * need_to_grab_x
2597 * is 1 it will also grab the X Server to avoid possible race
2598 * conditions in grabbing. If you have not already grabbed the server
2599 * you MUST set this to 1. Imlib2 returns a valid image handle on
2600 * success or NULL on failure.
2603 Imlib_Image
2604 imlib_create_image_from_drawable(Pixmap mask, int x, int y, int width,
2605 int height, char need_to_grab_x)
2607 ImlibImage *im;
2608 char domask = 0;
2610 if (!ctx)
2611 ctx = imlib_context_new();
2612 if (mask)
2613 domask = 1;
2614 im = __imlib_CreateImage(width, height, NULL);
2615 im->data = malloc(width * height * sizeof(DATA32));
2616 __imlib_GrabDrawableToRGBA(im->data, 0, 0, width, height, ctx->display,
2617 ctx->drawable, mask, ctx->visual, ctx->colormap,
2618 ctx->depth, x, y, width, height, domask,
2619 need_to_grab_x);
2620 return (Imlib_Image) im;
2624 * @param image An image.
2625 * @param mask A mask.
2626 * @param x The top left x coordinate of the rectangle.
2627 * @param y The top left y coordinate of the rectangle.
2628 * @param width The width of the rectangle.
2629 * @param height The height of the rectangle.
2630 * @param need_to_grab_x Grab flag.
2631 * @return a valid image, otherwise NULL.
2635 Imlib_Image
2636 imlib_create_image_from_ximage(XImage * image, XImage * mask, int x, int y,
2637 int width, int height, char need_to_grab_x)
2639 ImlibImage *im;
2640 char domask = 0;
2642 if (!ctx)
2643 ctx = imlib_context_new();
2644 if (mask)
2645 domask = 1;
2646 im = __imlib_CreateImage(width, height, NULL);
2647 im->data = malloc(width * height * sizeof(DATA32));
2648 __imlib_GrabXImageToRGBA(im->data, 0, 0, width, height,
2649 ctx->display, image, mask, ctx->visual,
2650 ctx->depth, x, y, width, height, need_to_grab_x);
2651 return (Imlib_Image) im;
2655 * @param mask A mask.
2656 * @param source_x The top left x coordinate of the rectangle.
2657 * @param source_y The top left y coordinate of the rectangle.
2658 * @param source_width The width of the rectangle.
2659 * @param source_height The height of the rectangle.
2660 * @param destination_width The width of the returned image.
2661 * @param destination_height The height of the returned image.
2662 * @param need_to_grab_x Grab flag.
2663 * @param get_mask_from_shape A char.
2664 * @return A valid image, otherwise NULL.
2666 * Creates an image from the current drawable (optionally using the
2667 * @p mask pixmap specified to determine alpha transparency) and scale
2668 * the grabbed data first before converting to an actual image (to
2669 * minimize reads from the frame buffer which can be slow). The source
2670 * (@p source_x, @p source_y, @p source_width, @p source_height) rectangle will be grabbed, scaled to the
2671 * destination @p destination_width and @p destination_height, then converted to an image. If
2672 * @p need_to_grab_x is set to 1, X is grabbed (set this to 1 unless you
2673 * have already grabbed the server) and if @p get_mask_from_shape and the
2674 * current drawable is a window its shape is used for determining the
2675 * alpha channel. If successful this function will return a valid
2676 * image handle, otherwise NULL is returned.
2679 Imlib_Image
2680 imlib_create_scaled_image_from_drawable(Pixmap mask, int source_x,
2681 int source_y, int source_width,
2682 int source_height,
2683 int destination_width,
2684 int destination_height,
2685 char need_to_grab_x,
2686 char get_mask_from_shape)
2688 ImlibImage *im;
2689 char domask = 0, tmpmask = 0;
2690 int x, xx;
2691 XGCValues gcv;
2692 GC gc = 0, mgc = 0;
2693 Pixmap p, m;
2695 if (!ctx)
2696 ctx = imlib_context_new();
2697 if ((mask) || (get_mask_from_shape))
2698 domask = 1;
2699 p = XCreatePixmap(ctx->display, ctx->drawable, destination_width,
2700 source_height, ctx->depth);
2701 gcv.foreground = 0;
2702 gcv.subwindow_mode = IncludeInferiors;
2703 if (domask)
2705 m = XCreatePixmap(ctx->display, ctx->drawable, destination_width,
2706 source_height, 1);
2707 mgc = XCreateGC(ctx->display, m, GCForeground, &gcv);
2709 else
2710 m = None;
2711 gc = XCreateGC(ctx->display, ctx->drawable, GCSubwindowMode, &gcv);
2712 if ((domask) && (!mask))
2714 XRectangle *rect;
2715 int rect_num, rect_ord;
2717 tmpmask = 1;
2718 mask =
2719 XCreatePixmap(ctx->display, ctx->drawable, source_width,
2720 source_height, 1);
2721 rect =
2722 XShapeGetRectangles(ctx->display, ctx->drawable, ShapeBounding,
2723 &rect_num, &rect_ord);
2724 XFillRectangle(ctx->display, mask, mgc, 0, 0, source_width,
2725 source_height);
2726 if (rect)
2728 XSetForeground(ctx->display, mgc, 1);
2729 for (x = 0; x < rect_num; x++)
2730 XFillRectangle(ctx->display, mask, mgc, rect[x].x, rect[x].y,
2731 rect[x].width, rect[x].height);
2732 XFree(rect);
2734 /* build mask from window shape rects */
2736 for (x = 0; x < destination_width; x++)
2738 xx = (source_width * x) / destination_width;
2739 XCopyArea(ctx->display, ctx->drawable, p, gc, source_x + xx, source_y,
2740 1, source_height, x, 0);
2741 if (m != None)
2742 XCopyArea(ctx->display, mask, m, mgc, xx, 0, 1, source_height, x,
2745 for (x = 0; x < destination_height; x++)
2747 xx = (source_height * x) / destination_height;
2748 XCopyArea(ctx->display, p, p, gc, 0, xx, destination_width, 1, 0, x);
2749 if (m != None)
2750 XCopyArea(ctx->display, m, m, mgc, 0, xx, destination_width, 1, 0, x);
2752 im = __imlib_CreateImage(destination_width, destination_height, NULL);
2753 im->data = malloc(destination_width * destination_height * sizeof(DATA32));
2754 __imlib_GrabDrawableToRGBA(im->data, 0, 0, destination_width,
2755 source_height, ctx->display, p, m,
2756 ctx->visual, ctx->colormap, ctx->depth, 0, 0,
2757 destination_width, destination_height, domask,
2758 need_to_grab_x);
2759 XFreePixmap(ctx->display, p);
2760 if (m != None)
2762 XFreeGC(ctx->display, mgc);
2763 XFreePixmap(ctx->display, m);
2764 if (tmpmask)
2765 XFreePixmap(ctx->display, mask);
2767 XFreeGC(ctx->display, gc);
2768 return (Imlib_Image) im;
2772 * @param mask A mask.
2773 * @param x The top left x coordinate of the rectangle.
2774 * @param y The top left y coordinate of the rectangle.
2775 * @param width The width of the rectangle.
2776 * @param height The height of the rectangle.
2777 * @param destination_x The x coordinate of the new location.
2778 * @param destination_y The x coordinate of the new location.
2779 * @param need_to_grab_x Grab flag.
2780 * @return A char.
2782 * Grabs a section of the current drawable (optionally using the
2783 * pixmap @p mask
2784 * provided as a corresponding mask for that drawable - if @p mask is 0
2785 * this is not used). It grabs the (@p x, @p y, @p width, @p height) rectangle and
2786 * places it at the destination (@p destination_x, @p destination_y) location in the current image. If
2787 * @p need_to_grab_x is 1 it will grab and ungrab the server whilst doing
2788 * this - you need to do this if you have not already grabbed the
2789 * server.
2792 char
2793 imlib_copy_drawable_to_image(Pixmap mask, int x, int y, int width, int height,
2794 int destination_x, int destination_y,
2795 char need_to_grab_x)
2797 ImlibImage *im;
2798 char domask = 0;
2799 int pre_adj;
2801 if (!ctx)
2802 ctx = imlib_context_new();
2803 CHECK_PARAM_POINTER_RETURN("imlib_copy_drawable_to_image", "image",
2804 ctx->image, 0);
2805 if (mask)
2806 domask = 1;
2807 CAST_IMAGE(im, ctx->image);
2809 if ((!(im->data)) && (im->loader) && (im->loader->load))
2810 im->loader->load(im, NULL, 0, 1);
2811 if (!(im->data))
2812 return 0;
2814 pre_adj = 0;
2815 if (x < 0)
2817 width += x;
2818 pre_adj = x;
2819 x = 0;
2821 if (width < 0)
2822 width = 0;
2823 if (destination_x < 0)
2825 width += destination_x;
2826 x -= destination_x - pre_adj;
2827 destination_x = 0;
2829 if ((destination_x + width) >= im->w)
2830 width = im->w - destination_x;
2832 pre_adj = 0;
2833 if (y < 0)
2835 height += y;
2836 pre_adj = y;
2837 y = 0;
2839 if (height < 0)
2840 height = 0;
2841 if (destination_y < 0)
2843 height += destination_y;
2844 y -= destination_y - pre_adj;
2845 destination_y = 0;
2847 if ((destination_y + height) >= im->h)
2848 height = im->h - destination_y;
2850 if ((width <= 0) || (height <= 0))
2851 return 0;
2852 __imlib_DirtyImage(im);
2853 return __imlib_GrabDrawableToRGBA(im->data, destination_x, destination_y,
2854 im->w, im->h, ctx->display,
2855 ctx->drawable, mask, ctx->visual,
2856 ctx->colormap, ctx->depth, x, y, width,
2857 height, domask, need_to_grab_x);
2859 #endif
2862 * @return A valid image, otherwise NULL.
2864 * Creates an exact duplicate of the current image and returns a valid
2865 * image handle on success, or NULL on failure.
2868 Imlib_Image
2869 imlib_clone_image(void)
2871 ImlibImage *im, *im_old;
2873 if (!ctx)
2874 ctx = imlib_context_new();
2875 CHECK_PARAM_POINTER_RETURN("imlib_clone_image", "image", ctx->image, NULL);
2876 CAST_IMAGE(im_old, ctx->image);
2877 if ((!(im_old->data)) && (im_old->loader) && (im_old->loader->load))
2878 im_old->loader->load(im_old, NULL, 0, 1);
2879 if (!(im_old->data))
2880 return NULL;
2881 im = __imlib_CreateImage(im_old->w, im_old->h, NULL);
2882 if (!(im))
2883 return NULL;
2884 im->data = malloc(im->w * im->h * sizeof(DATA32));
2885 if (!(im->data))
2887 __imlib_FreeImage(im);
2888 return NULL;
2890 memcpy(im->data, im_old->data, im->w * im->h * sizeof(DATA32));
2891 im->flags = im_old->flags;
2892 SET_FLAG(im->flags, F_UNCACHEABLE);
2893 im->moddate = im_old->moddate;
2894 im->border = im_old->border;
2895 im->loader = im_old->loader;
2896 if (im_old->format)
2898 im->format = malloc(strlen(im_old->format) + 1);
2899 strcpy(im->format, im_old->format);
2901 if (im_old->file)
2903 im->file = malloc(strlen(im_old->file) + 1);
2904 strcpy(im->file, im_old->file);
2906 return (Imlib_Image) im;
2910 * @param x The top left x coordinate of the rectangle.
2911 * @param y The top left y coordinate of the rectangle.
2912 * @param width The width of the rectangle.
2913 * @param height The height of the rectangle.
2914 * @return A valid image, otherwise NULL.
2916 * Creates a duplicate of a (@p x, @p y, @p width, @p height) rectangle in the
2917 * current image and returns a valid image handle on success, or NULL
2918 * on failure.
2921 Imlib_Image
2922 imlib_create_cropped_image(int x, int y, int width, int height)
2924 ImlibImage *im, *im_old;
2926 if (!ctx)
2927 ctx = imlib_context_new();
2928 CHECK_PARAM_POINTER_RETURN("imlib_create_cropped_image", "image",
2929 ctx->image, NULL);
2930 CAST_IMAGE(im_old, ctx->image);
2931 if ((!(im_old->data)) && (im_old->loader) && (im_old->loader->load))
2932 im_old->loader->load(im_old, NULL, 0, 1);
2933 if (!(im_old->data))
2934 return NULL;
2935 im = __imlib_CreateImage(abs(width), abs(height), NULL);
2936 im->data = malloc(abs(width * height) * sizeof(DATA32));
2937 if (!(im->data))
2939 __imlib_FreeImage(im);
2940 return NULL;
2942 if (IMAGE_HAS_ALPHA(im_old))
2944 SET_FLAG(im->flags, F_HAS_ALPHA);
2945 __imlib_BlendImageToImage(im_old, im, 0, 0, 1, x, y, abs(width),
2946 abs(height), 0, 0, width, height, NULL,
2947 IMLIB_OP_COPY,
2948 ctx->cliprect.x, ctx->cliprect.y,
2949 ctx->cliprect.w, ctx->cliprect.h);
2951 else
2953 __imlib_BlendImageToImage(im_old, im, 0, 0, 0, x, y, abs(width),
2954 abs(height), 0, 0, width, height, NULL,
2955 IMLIB_OP_COPY,
2956 ctx->cliprect.x, ctx->cliprect.y,
2957 ctx->cliprect.w, ctx->cliprect.h);
2959 return (Imlib_Image) im;
2963 * @param source_x The top left x coordinate of the source rectangle.
2964 * @param source_y The top left y coordinate of the source rectangle.
2965 * @param source_width The width of the source rectangle.
2966 * @param source_height The height of the source rectangle.
2967 * @param destination_width The width of the destination image.
2968 * @param destination_height The height of the destination image.
2969 * @return A valid image, otherwise NULL.
2971 * Works the same as imlib_create_cropped_image() but will scale the
2972 * new image to the new destination @p destination_width and
2973 * @p destination_height whilst cropping.
2976 Imlib_Image
2977 imlib_create_cropped_scaled_image(int source_x, int source_y,
2978 int source_width, int source_height,
2979 int destination_width, int destination_height)
2981 ImlibImage *im, *im_old;
2983 if (!ctx)
2984 ctx = imlib_context_new();
2985 CHECK_PARAM_POINTER_RETURN("imlib_create_cropped_scaled_image", "image",
2986 ctx->image, NULL);
2987 CAST_IMAGE(im_old, ctx->image);
2988 if ((!(im_old->data)) && (im_old->loader) && (im_old->loader->load))
2989 im_old->loader->load(im_old, NULL, 0, 1);
2990 if (!(im_old->data))
2991 return NULL;
2992 im = __imlib_CreateImage(abs(destination_width), abs(destination_height),
2993 NULL);
2994 im->data =
2995 malloc(abs(destination_width * destination_height) * sizeof(DATA32));
2996 if (!(im->data))
2998 __imlib_FreeImage(im);
2999 return NULL;
3001 if (IMAGE_HAS_ALPHA(im_old))
3003 SET_FLAG(im->flags, F_HAS_ALPHA);
3004 __imlib_BlendImageToImage(im_old, im, ctx->anti_alias, 0, 1, source_x,
3005 source_y, source_width, source_height, 0, 0,
3006 destination_width, destination_height, NULL,
3007 IMLIB_OP_COPY,
3008 ctx->cliprect.x, ctx->cliprect.y,
3009 ctx->cliprect.w, ctx->cliprect.h);
3011 else
3013 __imlib_BlendImageToImage(im_old, im, ctx->anti_alias, 0, 0, source_x,
3014 source_y, source_width, source_height, 0, 0,
3015 destination_width, destination_height, NULL,
3016 IMLIB_OP_COPY,
3017 ctx->cliprect.x, ctx->cliprect.y,
3018 ctx->cliprect.w, ctx->cliprect.h);
3020 return (Imlib_Image) im;
3024 * @param updates An updates list.
3025 * @return Duplicate of @p updates.
3027 * Creates a duplicate of the updates list passed into the function.
3029 Imlib_Updates
3030 imlib_updates_clone(Imlib_Updates updates)
3032 ImlibUpdate *u;
3034 if (!ctx)
3035 ctx = imlib_context_new();
3036 u = (ImlibUpdate *) updates;
3037 return (Imlib_Updates) __imlib_DupUpdates(u);
3041 * @param updates An updates list.
3042 * @param x The top left x coordinate of the rectangle.
3043 * @param y The top left y coordinate of the rectangle.
3044 * @param w The width of the rectangle.
3045 * @param h The height of the rectangle.
3046 * @return The updates handle.
3048 * Appends an update rectangle to the updates list passed in (if the
3049 * updates is NULL it will create a new updates list) and returns a
3050 * handle to the modified updates list (the handle may be modified so
3051 * only use the new updates handle returned).
3053 Imlib_Updates
3054 imlib_update_append_rect(Imlib_Updates updates, int x, int y, int w, int h)
3056 ImlibUpdate *u;
3058 if (!ctx)
3059 ctx = imlib_context_new();
3060 u = (ImlibUpdate *) updates;
3061 return (Imlib_Updates) __imlib_AddUpdate(u, x, y, w, h);
3065 * @param updates An updates list.
3066 * @param w The width of the rectangle.
3067 * @param h The height of the rectangle.
3068 * @return The updates handle.
3070 * Takes an updates list, and modifies it by merging overlapped
3071 * rectangles and lots of tiny rectangles into larger rectangles to
3072 * minimize the number of rectangles in the list for optimized
3073 * redrawing. The new updates handle is now valid and the old one
3074 * passed in is not.
3076 Imlib_Updates
3077 imlib_updates_merge(Imlib_Updates updates, int w, int h)
3079 ImlibUpdate *u;
3081 if (!ctx)
3082 ctx = imlib_context_new();
3083 u = (ImlibUpdate *) updates;
3084 return (Imlib_Updates) __imlib_MergeUpdate(u, w, h, 0);
3088 * @param updates An updates list.
3089 * @param w The width of the rectangle.
3090 * @param h The height of the rectangle.
3091 * @return The updates handle.
3093 * Works almost exactly as imlib_updates_merge() but is more lenient
3094 * on the spacing between update rectangles - if they are very close it
3095 * amalgamates 2 smaller rectangles into 1 larger one.
3097 Imlib_Updates
3098 imlib_updates_merge_for_rendering(Imlib_Updates updates, int w, int h)
3100 ImlibUpdate *u;
3102 if (!ctx)
3103 ctx = imlib_context_new();
3104 u = (ImlibUpdate *) updates;
3105 return (Imlib_Updates) __imlib_MergeUpdate(u, w, h, 3);
3109 * @param updates An updates list.
3111 * Frees an updates list.
3113 void
3114 imlib_updates_free(Imlib_Updates updates)
3116 ImlibUpdate *u;
3118 if (!ctx)
3119 ctx = imlib_context_new();
3120 u = (ImlibUpdate *) updates;
3121 __imlib_FreeUpdates(u);
3125 * @param updates An updates list.
3126 * @return The next updates.
3128 * Gets the next update in the updates list relative to the one passed
3129 * in.
3131 Imlib_Updates
3132 imlib_updates_get_next(Imlib_Updates updates)
3134 ImlibUpdate *u;
3136 if (!ctx)
3137 ctx = imlib_context_new();
3138 u = (ImlibUpdate *) updates;
3139 return (Imlib_Updates) (u->next);
3143 * @param updates An updates list.
3144 * @param x_return The top left x coordinate of the update.
3145 * @param y_return The top left y coordinate of the update.
3146 * @param width_return The width of the update.
3147 * @param height_return The height of the update.
3149 * Returns the coordinates of an update.
3151 void
3152 imlib_updates_get_coordinates(Imlib_Updates updates, int *x_return,
3153 int *y_return, int *width_return,
3154 int *height_return)
3156 ImlibUpdate *u;
3158 if (!ctx)
3159 ctx = imlib_context_new();
3160 CHECK_PARAM_POINTER("imlib_updates_get_coordinates", "updates", updates);
3161 u = (ImlibUpdate *) updates;
3162 if (x_return)
3163 *x_return = u->x;
3164 if (y_return)
3165 *y_return = u->y;
3166 if (width_return)
3167 *width_return = u->w;
3168 if (height_return)
3169 *height_return = u->h;
3173 * @param updates An updates list.
3174 * @param x The top left x coordinate of the update.
3175 * @param y The top left y coordinate of the update.
3176 * @param width The width of the update.
3177 * @param height The height of the update.
3179 * Modifies the coordinates of an update in @p update.
3181 void
3182 imlib_updates_set_coordinates(Imlib_Updates updates, int x, int y, int width,
3183 int height)
3185 ImlibUpdate *u;
3187 if (!ctx)
3188 ctx = imlib_context_new();
3189 CHECK_PARAM_POINTER("imlib_updates_set_coordinates", "updates", updates);
3190 u = (ImlibUpdate *) updates;
3191 u->x = x;
3192 u->y = y;
3193 u->w = width;
3194 u->h = height;
3197 #ifdef BUILD_X11
3199 * @param updates An updates list.
3200 * @param x The top left x coordinate of the update.
3201 * @param y The top left y coordinate of the update.
3203 * Given an updates list (preferable already merged for rendering)
3204 * this will render the corresponding parts of the image to the current
3205 * drawable at an offset of @p x, @p y in the drawable.
3207 void
3208 imlib_render_image_updates_on_drawable(Imlib_Updates updates, int x, int y)
3210 ImlibUpdate *u;
3211 ImlibImage *im;
3213 if (!ctx)
3214 ctx = imlib_context_new();
3215 CHECK_PARAM_POINTER("imlib_render_image_updates_on_drawable", "image",
3216 ctx->image);
3217 CAST_IMAGE(im, ctx->image);
3218 u = (ImlibUpdate *) updates;
3219 if (!updates)
3220 return;
3221 if ((!(im->data)) && (im->loader) && (im->loader->load))
3222 im->loader->load(im, NULL, 0, 1);
3223 if (!(im->data))
3224 return;
3225 __imlib_SetMaxXImageCount(ctx->display, 10);
3226 for (; u; u = u->next)
3228 __imlib_RenderImage(ctx->display, im, ctx->drawable, 0, ctx->visual,
3229 ctx->colormap, ctx->depth, u->x, u->y, u->w, u->h,
3230 x + u->x, y + u->y, u->w, u->h, 0, ctx->dither, 0,
3231 0, ctx->color_modifier, OP_COPY);
3233 __imlib_SetMaxXImageCount(ctx->display, 0);
3235 #endif
3238 * @return The initialized updates list.
3240 * Initializes an updates list before you add any updates to it or
3241 * merge it for rendering etc.
3243 Imlib_Updates
3244 imlib_updates_init(void)
3246 if (!ctx)
3247 ctx = imlib_context_new();
3248 return (Imlib_Updates) NULL;
3252 * @param updates An updates list.
3253 * @param appended_updates The updates list to append.
3254 * @return The new updates list.
3256 * Appends @p appended_updates to the updates list @p updates and
3257 * returns the new list.
3259 Imlib_Updates
3260 imlib_updates_append_updates(Imlib_Updates updates,
3261 Imlib_Updates appended_updates)
3263 ImlibUpdate *u, *uu;
3265 if (!ctx)
3266 ctx = imlib_context_new();
3267 u = (ImlibUpdate *) updates;
3268 uu = (ImlibUpdate *) appended_updates;
3269 if (!uu)
3270 return (Imlib_Updates) u;
3271 if (!u)
3272 return (Imlib_Updates) uu;
3273 while (u)
3275 if (!(u->next))
3277 u->next = uu;
3278 return updates;
3280 u = u->next;
3282 return (Imlib_Updates) u;
3286 * Flips/mirrors the current image horizontally.
3288 void
3289 imlib_image_flip_horizontal(void)
3291 ImlibImage *im;
3293 if (!ctx)
3294 ctx = imlib_context_new();
3295 CHECK_PARAM_POINTER("imlib_image_flip_horizontal", "image", ctx->image);
3296 CAST_IMAGE(im, ctx->image);
3297 if ((!(im->data)) && (im->loader) && (im->loader->load))
3298 im->loader->load(im, NULL, 0, 1);
3299 if (!(im->data))
3300 return;
3301 __imlib_DirtyImage(im);
3302 __imlib_FlipImageHoriz(im);
3306 * Flips/mirrors the current image vertically.
3308 void
3309 imlib_image_flip_vertical(void)
3311 ImlibImage *im;
3313 if (!ctx)
3314 ctx = imlib_context_new();
3315 CHECK_PARAM_POINTER("imlib_image_flip_vertical", "image", ctx->image);
3316 CAST_IMAGE(im, ctx->image);
3317 if ((!(im->data)) && (im->loader) && (im->loader->load))
3318 im->loader->load(im, NULL, 0, 1);
3319 if (!(im->data))
3320 return;
3321 __imlib_DirtyImage(im);
3322 __imlib_FlipImageVert(im);
3326 * Flips/mirrors the current image diagonally (good for quick and dirty
3327 * 90 degree rotations if used before to after a horizontal or vertical
3328 * flip).
3330 void
3331 imlib_image_flip_diagonal(void)
3333 ImlibImage *im;
3335 if (!ctx)
3336 ctx = imlib_context_new();
3337 CHECK_PARAM_POINTER("imlib_image_flip_diagonal", "image", ctx->image);
3338 CAST_IMAGE(im, ctx->image);
3339 if ((!(im->data)) && (im->loader) && (im->loader->load))
3340 im->loader->load(im, NULL, 0, 1);
3341 if (!(im->data))
3342 return;
3343 __imlib_DirtyImage(im);
3344 __imlib_FlipImageDiagonal(im, 0);
3348 * @param orientation The orientation.
3350 * Performs 90 degree rotations on the current image. Passing in
3351 * @p orientation does not rotate, 1 rotates clockwise by 90 degree, 2,
3352 * rotates clockwise by 180 degrees, 3 rotates clockwise by 270
3353 * degrees.
3355 void
3356 imlib_image_orientate(int orientation)
3358 ImlibImage *im;
3360 if (!ctx)
3361 ctx = imlib_context_new();
3362 CHECK_PARAM_POINTER("imlib_image_orientate", "image", ctx->image);
3363 CAST_IMAGE(im, ctx->image);
3364 if ((!(im->data)) && (im->loader) && (im->loader->load))
3365 im->loader->load(im, NULL, 0, 1);
3366 if (!(im->data))
3367 return;
3368 __imlib_DirtyImage(im);
3369 switch (orientation)
3371 default:
3372 case 0:
3373 break;
3374 case 1:
3375 __imlib_FlipImageDiagonal(im, 1);
3376 break;
3377 case 2:
3378 __imlib_FlipImageBoth(im);
3379 break;
3380 case 3:
3381 __imlib_FlipImageDiagonal(im, 2);
3382 break;
3383 case 4:
3384 __imlib_FlipImageHoriz(im);
3385 break;
3386 case 5:
3387 __imlib_FlipImageDiagonal(im, 3);
3388 break;
3389 case 6:
3390 __imlib_FlipImageVert(im);
3391 break;
3392 case 7:
3393 __imlib_FlipImageDiagonal(im, 0);
3394 break;
3399 * @param radius The radius.
3401 * Blurs the current image. A @p radius value of 0 has no effect, 1 and above
3402 * determine the blur matrix radius that determine how much to blur the
3403 * image.
3405 void
3406 imlib_image_blur(int radius)
3408 ImlibImage *im;
3410 if (!ctx)
3411 ctx = imlib_context_new();
3412 CHECK_PARAM_POINTER("imlib_image_blur", "image", ctx->image);
3413 CAST_IMAGE(im, ctx->image);
3414 if ((!(im->data)) && (im->loader) && (im->loader->load))
3415 im->loader->load(im, NULL, 0, 1);
3416 if (!(im->data))
3417 return;
3418 __imlib_DirtyImage(im);
3419 __imlib_BlurImage(im, radius);
3423 * @param radius The radius.
3425 * Sharpens the current image. The @p radius value affects how much to sharpen
3426 * by.
3428 void
3429 imlib_image_sharpen(int radius)
3431 ImlibImage *im;
3433 if (!ctx)
3434 ctx = imlib_context_new();
3435 CAST_IMAGE(im, ctx->image);
3436 CHECK_PARAM_POINTER("imlib_image_sharpen", "image", ctx->image);
3437 if ((!(im->data)) && (im->loader) && (im->loader->load))
3438 im->loader->load(im, NULL, 0, 1);
3439 if (!(im->data))
3440 return;
3441 __imlib_DirtyImage(im);
3442 __imlib_SharpenImage(im, radius);
3446 * Modifies an image so it will tile seamlessly horizontally if used
3447 * as a tile (i.e. drawn multiple times horizontally).
3449 void
3450 imlib_image_tile_horizontal(void)
3452 ImlibImage *im;
3454 if (!ctx)
3455 ctx = imlib_context_new();
3456 CHECK_PARAM_POINTER("imlib_image_tile_horizontal", "image", ctx->image);
3457 CAST_IMAGE(im, ctx->image);
3458 if ((!(im->data)) && (im->loader) && (im->loader->load))
3459 im->loader->load(im, NULL, 0, 1);
3460 if (!(im->data))
3461 return;
3462 __imlib_DirtyImage(im);
3463 __imlib_TileImageHoriz(im);
3467 * Modifies an image so it will tile seamlessly vertically if used as
3468 * a tile (i.e. drawn multiple times vertically).
3470 void
3471 imlib_image_tile_vertical(void)
3473 ImlibImage *im;
3475 if (!ctx)
3476 ctx = imlib_context_new();
3477 CHECK_PARAM_POINTER("imlib_image_tile_vertical", "image", ctx->image);
3478 CAST_IMAGE(im, ctx->image);
3479 if ((!(im->data)) && (im->loader) && (im->loader->load))
3480 im->loader->load(im, NULL, 0, 1);
3481 if (!(im->data))
3482 return;
3483 __imlib_DirtyImage(im);
3484 __imlib_TileImageVert(im);
3488 * Modifies an image so it will tile seamlessly horizontally and
3489 * vertically if used as a tile (i.e. drawn multiple times horizontally
3490 * and vertically).
3492 void
3493 imlib_image_tile(void)
3495 ImlibImage *im;
3497 if (!ctx)
3498 ctx = imlib_context_new();
3499 CHECK_PARAM_POINTER("imlib_image_tile", "image", ctx->image);
3500 CAST_IMAGE(im, ctx->image);
3501 if ((!(im->data)) && (im->loader) && (im->loader->load))
3502 im->loader->load(im, NULL, 0, 1);
3503 if (!(im->data))
3504 return;
3505 __imlib_DirtyImage(im);
3506 __imlib_TileImageHoriz(im);
3507 __imlib_TileImageVert(im);
3511 * @param font_name The font name with the size.
3512 * @return NULL if no font found.
3514 * Loads a truetype font from the first directory in the font path that
3515 * contains that font. The font name @p font_name format is "font_name/size". For
3516 * example. If there is a font file called blum.ttf somewhere in the
3517 * font path you might use "blum/20" to load a 20 pixel sized font of
3518 * blum. If the font cannot be found NULL is returned.
3521 Imlib_Font
3522 imlib_load_font(const char *font_name)
3524 return imlib_font_load_joined(font_name);
3528 * Frees the current font.
3530 void
3531 imlib_free_font(void)
3533 if (!ctx)
3534 ctx = imlib_context_new();
3535 CHECK_PARAM_POINTER("imlib_free_font", "font", ctx->font);
3536 imlib_font_free(ctx->font);
3537 ctx->font = NULL;
3541 * @param x The x coordinate of the top left corner.
3542 * @param y The y coordinate of the top left corner.
3543 * @param text A null-byte terminated string.
3545 * Draws the null-byte terminated string @p text using the current font on
3546 * the current image at the (@p x, @p y) location (@p x, @p y denoting the top left
3547 * corner of the font string)
3549 void
3550 imlib_text_draw(int x, int y, const char *text)
3552 if (!ctx)
3553 ctx = imlib_context_new();
3554 imlib_text_draw_with_return_metrics(x, y, text, NULL, NULL, NULL, NULL);
3558 * @param x The x coordinate of the top left corner.
3559 * @param y The y coordinate of the top left corner.
3560 * @param text A null-byte terminated string.
3561 * @param width_return The width of the string.
3562 * @param height_return The height of the string.
3563 * @param horizontal_advance_return Horizontal offset.
3564 * @param vertical_advance_return Vertical offset.
3566 * Works just like imlib_text_draw() but also returns the width and
3567 * height of the string drawn, and @p horizontal_advance_return returns
3568 * the number of pixels you should advance horizontally to draw another
3569 * string (useful if you are drawing a line of text word by word) and
3570 * @p vertical_advance_return does the same for the vertical direction
3571 * (i.e. drawing text line by line).
3573 void
3574 imlib_text_draw_with_return_metrics(int x, int y, const char *text,
3575 int *width_return, int *height_return,
3576 int *horizontal_advance_return,
3577 int *vertical_advance_return)
3579 ImlibImage *im;
3580 ImlibFont *fn;
3581 int dir;
3583 if (!ctx)
3584 ctx = imlib_context_new();
3585 CHECK_PARAM_POINTER("imlib_text_draw_with_return_metrics", "font",
3586 ctx->font);
3587 CHECK_PARAM_POINTER("imlib_text_draw_with_return_metrics", "image",
3588 ctx->image);
3589 CHECK_PARAM_POINTER("imlib_text_draw_with_return_metrics", "text", text);
3590 CAST_IMAGE(im, ctx->image);
3591 if ((!(im->data)) && (im->loader) && (im->loader->load))
3592 im->loader->load(im, NULL, 0, 1);
3593 if (!(im->data))
3594 return;
3595 fn = (ImlibFont *) ctx->font;
3596 __imlib_DirtyImage(im);
3598 dir = ctx->direction;
3599 if (ctx->direction == IMLIB_TEXT_TO_ANGLE && ctx->angle == 0.0)
3600 dir = IMLIB_TEXT_TO_RIGHT;
3602 imlib_render_str(im, fn, x, y, text, (DATA8) ctx->color.red,
3603 (DATA8) ctx->color.green, (DATA8) ctx->color.blue,
3604 (DATA8) ctx->color.alpha, (char)dir,
3605 ctx->angle, width_return, height_return, 0,
3606 horizontal_advance_return, vertical_advance_return,
3607 ctx->operation,
3608 ctx->cliprect.x, ctx->cliprect.y,
3609 ctx->cliprect.w, ctx->cliprect.h);
3613 * @param text A string.
3614 * @param width_return The width of the text.
3615 * @param height_return The height of the text.
3617 * Gets the width and height in pixels the @p text string would use up
3618 * if drawn with the current font.
3620 void
3621 imlib_get_text_size(const char *text, int *width_return, int *height_return)
3623 ImlibFont *fn;
3624 int w, h;
3625 int dir;
3627 if (!ctx)
3628 ctx = imlib_context_new();
3629 CHECK_PARAM_POINTER("imlib_get_text_size", "font", ctx->font);
3630 CHECK_PARAM_POINTER("imlib_get_text_size", "text", text);
3631 fn = (ImlibFont *) ctx->font;
3633 dir = ctx->direction;
3634 if (ctx->direction == IMLIB_TEXT_TO_ANGLE && ctx->angle == 0.0)
3635 dir = IMLIB_TEXT_TO_RIGHT;
3637 imlib_font_query_size(fn, text, &w, &h);
3639 switch (dir)
3641 case IMLIB_TEXT_TO_RIGHT:
3642 case IMLIB_TEXT_TO_LEFT:
3643 if (width_return)
3644 *width_return = w;
3645 if (height_return)
3646 *height_return = h;
3647 break;
3648 case IMLIB_TEXT_TO_DOWN:
3649 case IMLIB_TEXT_TO_UP:
3650 if (width_return)
3651 *width_return = h;
3652 if (height_return)
3653 *height_return = w;
3654 break;
3655 case IMLIB_TEXT_TO_ANGLE:
3656 if (width_return || height_return)
3658 double sa, ca;
3660 sa = sin(ctx->angle);
3661 ca = cos(ctx->angle);
3663 if (width_return)
3665 double x1, x2, xt;
3667 x1 = x2 = 0.0;
3668 xt = ca * w;
3669 if (xt < x1)
3670 x1 = xt;
3671 if (xt > x2)
3672 x2 = xt;
3673 xt = -(sa * h);
3674 if (xt < x1)
3675 x1 = xt;
3676 if (xt > x2)
3677 x2 = xt;
3678 xt = ca * w - sa * h;
3679 if (xt < x1)
3680 x1 = xt;
3681 if (xt > x2)
3682 x2 = xt;
3683 *width_return = (int)(x2 - x1);
3685 if (height_return)
3687 double y1, y2, yt;
3689 y1 = y2 = 0.0;
3690 yt = sa * w;
3691 if (yt < y1)
3692 y1 = yt;
3693 if (yt > y2)
3694 y2 = yt;
3695 yt = ca * h;
3696 if (yt < y1)
3697 y1 = yt;
3698 if (yt > y2)
3699 y2 = yt;
3700 yt = sa * w + ca * h;
3701 if (yt < y1)
3702 y1 = yt;
3703 if (yt > y2)
3704 y2 = yt;
3705 *height_return = (int)(y2 - y1);
3708 break;
3709 default:
3710 break;
3715 * @param text A string.
3716 * @param horizontal_advance_return Horizontal offset.
3717 * @param vertical_advance_return Vertical offset.
3719 * Gets the advance horizontally and vertically in pixels the next
3720 * text string would need to be placed at for the current font. The
3721 * advances are not adjusted for rotation so you will have to translate
3722 * the advances (which are calculated as if the text was drawn
3723 * horizontally from left to right) depending on the text orientation.
3725 void
3726 imlib_get_text_advance(const char *text, int *horizontal_advance_return,
3727 int *vertical_advance_return)
3729 ImlibFont *fn;
3730 int w, h;
3732 if (!ctx)
3733 ctx = imlib_context_new();
3734 CHECK_PARAM_POINTER("imlib_get_text_advance", "font", ctx->font);
3735 CHECK_PARAM_POINTER("imlib_get_text_advance", "text", text);
3736 fn = (ImlibFont *) ctx->font;
3737 imlib_font_query_advance(fn, text, &w, &h);
3738 if (horizontal_advance_return)
3739 *horizontal_advance_return = w;
3740 if (vertical_advance_return)
3741 *vertical_advance_return = h;
3745 * @param text A string.
3746 * @return The inset value of @text.
3748 * Returns the inset of the first character of @p text
3749 * in using the current font and returns that value in pixels.
3753 imlib_get_text_inset(const char *text)
3755 ImlibFont *fn;
3757 if (!ctx)
3758 ctx = imlib_context_new();
3759 CHECK_PARAM_POINTER_RETURN("imlib_get_text_advance", "font", ctx->font, 0);
3760 CHECK_PARAM_POINTER_RETURN("imlib_get_text_advance", "text", text, 0);
3761 fn = (ImlibFont *) ctx->font;
3762 return imlib_font_query_inset(fn, text);
3766 * @param path A directory path.
3768 * Adds the directory @p path to the end of the current list of
3769 * directories to scan for fonts.
3771 void
3772 imlib_add_path_to_font_path(const char *path)
3774 if (!ctx)
3775 ctx = imlib_context_new();
3776 CHECK_PARAM_POINTER("imlib_add_path_to_font_path", "path", path);
3777 if (!imlib_font_path_exists(path))
3778 imlib_font_add_font_path(path);
3782 * @param path A directory path.
3784 * Removes all directories in the font path that match @p path.
3786 void
3787 imlib_remove_path_from_font_path(const char *path)
3789 if (!ctx)
3790 ctx = imlib_context_new();
3791 CHECK_PARAM_POINTER("imlib_remove_path_from_font_path", "path", path);
3792 imlib_font_del_font_path(path);
3796 * @param number_return Number of paths in the list.
3797 * @return A list of strings.
3799 * Returns a list of strings that are the directories in the font
3800 * path. Do not free this list or change it in any way. If you add or
3801 * delete members of the font path this list will be invalid. If you
3802 * intend to use this list later duplicate it for your own use. The
3803 * number of elements in the array of strings is put into
3804 * @p number_return.
3807 char **
3808 imlib_list_font_path(int *number_return)
3810 if (!ctx)
3811 ctx = imlib_context_new();
3812 CHECK_PARAM_POINTER_RETURN("imlib_list_font_path", "number_return",
3813 number_return, NULL);
3814 return imlib_font_list_font_path(number_return);
3818 * @param text A string.
3819 * @param x The x offset.
3820 * @param y The y offset.
3821 * @param char_x_return The x coordinate of the character.
3822 * @param char_y_return The x coordinate of the character.
3823 * @param char_width_return The width of the character.
3824 * @param char_height_return The height of the character.
3825 * @return -1 if no character found.
3827 * Returns the character number in the string @p text using the current
3828 * font at the (@p x, @p y) pixel location which is an offset relative to the
3829 * top left of that string. -1 is returned if there is no character
3830 * there. If there is a character, @p char_x_return, @p char_y_return,
3831 * @p char_width_return and @p char_height_return (respectively the
3832 * character x, y, width and height) are also filled in.
3836 imlib_text_get_index_and_location(const char *text, int x, int y,
3837 int *char_x_return, int *char_y_return,
3838 int *char_width_return,
3839 int *char_height_return)
3841 ImlibFont *fn;
3842 int w, h, cx, cy, cw, ch, cp, xx, yy;
3843 int dir;
3845 if (!ctx)
3846 ctx = imlib_context_new();
3847 CHECK_PARAM_POINTER_RETURN("imlib_text_get_index_and_location", "font",
3848 ctx->font, -1);
3849 CHECK_PARAM_POINTER_RETURN("imlib_text_get_index_and_location", "text",
3850 text, -1);
3851 fn = (ImlibFont *) ctx->font;
3853 dir = ctx->direction;
3854 if (ctx->direction == IMLIB_TEXT_TO_ANGLE && ctx->angle == 0.0)
3855 dir = IMLIB_TEXT_TO_RIGHT;
3857 imlib_get_text_size(text, &w, &h);
3859 switch (dir)
3861 case IMLIB_TEXT_TO_RIGHT:
3862 xx = x;
3863 yy = y;
3864 break;
3865 case IMLIB_TEXT_TO_LEFT:
3866 xx = w - x;
3867 yy = h - y;
3868 break;
3869 case IMLIB_TEXT_TO_DOWN:
3870 xx = y;
3871 yy = w - x;
3872 break;
3873 case IMLIB_TEXT_TO_UP:
3874 xx = h - y;
3875 yy = x;
3876 break;
3877 default:
3878 return -1;
3881 cp = imlib_font_query_text_at_pos(fn, text, xx, yy, &cx, &cy, &cw, &ch);
3883 switch (dir)
3885 case IMLIB_TEXT_TO_RIGHT:
3886 if (char_x_return)
3887 *char_x_return = cx;
3888 if (char_y_return)
3889 *char_y_return = cy;
3890 if (char_width_return)
3891 *char_width_return = cw;
3892 if (char_height_return)
3893 *char_height_return = ch;
3894 return cp;
3895 break;
3896 case IMLIB_TEXT_TO_LEFT:
3897 cx = 1 + w - cx - cw;
3898 if (char_x_return)
3899 *char_x_return = cx;
3900 if (char_y_return)
3901 *char_y_return = cy;
3902 if (char_width_return)
3903 *char_width_return = cw;
3904 if (char_height_return)
3905 *char_height_return = ch;
3906 return cp;
3907 break;
3908 case IMLIB_TEXT_TO_DOWN:
3909 if (char_x_return)
3910 *char_x_return = cy;
3911 if (char_y_return)
3912 *char_y_return = cx;
3913 if (char_width_return)
3914 *char_width_return = ch;
3915 if (char_height_return)
3916 *char_height_return = cw;
3917 return cp;
3918 break;
3919 case IMLIB_TEXT_TO_UP:
3920 cy = 1 + h - cy - ch;
3921 if (char_x_return)
3922 *char_x_return = cy;
3923 if (char_y_return)
3924 *char_y_return = cx;
3925 if (char_width_return)
3926 *char_width_return = ch;
3927 if (char_height_return)
3928 *char_height_return = cw;
3929 return cp;
3930 break;
3931 default:
3932 return -1;
3933 break;
3935 return -1;
3939 * @param text A string.
3940 * @param index The index of @text.
3941 * @param char_x_return The x coordinate of the character.
3942 * @param char_y_return The y coordinate of the character.
3943 * @param char_width_return The width of the character.
3944 * @param char_height_return The height of the character.
3946 * Gets the geometry of the character at index @p index in the @p text
3947 * string using the current font.
3949 void
3950 imlib_text_get_location_at_index(const char *text, int index,
3951 int *char_x_return, int *char_y_return,
3952 int *char_width_return,
3953 int *char_height_return)
3955 ImlibFont *fn;
3956 int cx, cy, cw, ch, w, h;
3958 if (!ctx)
3959 ctx = imlib_context_new();
3960 CHECK_PARAM_POINTER("imlib_text_get_index_and_location", "font", ctx->font);
3961 CHECK_PARAM_POINTER("imlib_text_get_index_and_location", "text", text);
3962 fn = (ImlibFont *) ctx->font;
3964 imlib_font_query_char_coords(fn, text, index, &cx, &cy, &cw, &ch);
3966 imlib_get_text_size(text, &w, &h);
3968 switch (ctx->direction)
3970 case IMLIB_TEXT_TO_RIGHT:
3971 if (char_x_return)
3972 *char_x_return = cx;
3973 if (char_y_return)
3974 *char_y_return = cy;
3975 if (char_width_return)
3976 *char_width_return = cw;
3977 if (char_height_return)
3978 *char_height_return = ch;
3979 return;
3980 break;
3981 case IMLIB_TEXT_TO_LEFT:
3982 cx = 1 + w - cx - cw;
3983 if (char_x_return)
3984 *char_x_return = cx;
3985 if (char_y_return)
3986 *char_y_return = cy;
3987 if (char_width_return)
3988 *char_width_return = cw;
3989 if (char_height_return)
3990 *char_height_return = ch;
3991 return;
3992 break;
3993 case IMLIB_TEXT_TO_DOWN:
3994 if (char_x_return)
3995 *char_x_return = cy;
3996 if (char_y_return)
3997 *char_y_return = cx;
3998 if (char_width_return)
3999 *char_width_return = ch;
4000 if (char_height_return)
4001 *char_height_return = cw;
4002 return;
4003 break;
4004 case IMLIB_TEXT_TO_UP:
4005 cy = 1 + h - cy - ch;
4006 if (char_x_return)
4007 *char_x_return = cy;
4008 if (char_y_return)
4009 *char_y_return = cx;
4010 if (char_width_return)
4011 *char_width_return = ch;
4012 if (char_height_return)
4013 *char_height_return = cw;
4014 return;
4015 break;
4016 default:
4017 return;
4018 break;
4023 * @param number_return Number of fonts in the list.
4024 * @return A list of fonts.
4026 * Returns a list of fonts imlib2 can find in its font path.
4029 char **
4030 imlib_list_fonts(int *number_return)
4032 if (!ctx)
4033 ctx = imlib_context_new();
4034 CHECK_PARAM_POINTER_RETURN("imlib_list_fonts", "number_return",
4035 number_return, NULL);
4036 return imlib_font_list_fonts(number_return);
4040 * @param font_list The font list.
4041 * @param number Number of fonts in the list.
4043 * Frees the font list returned by imlib_list_fonts().
4046 void
4047 imlib_free_font_list(char **font_list, int number)
4049 __imlib_FileFreeDirList(font_list, number);
4053 * @return The font cache size.
4055 * Returns the font cache size in bytes.
4059 imlib_get_font_cache_size(void)
4061 if (!ctx)
4062 ctx = imlib_context_new();
4063 return imlib_font_cache_get();
4067 * @param bytes The font cache size.
4069 * Sets the font cache in bytes. Whenever you set the font cache size
4070 * Imlib2 will flush fonts from the cache until the memory used by
4071 * fonts is less than or equal to the font cache size. Setting the size
4072 * to 0 effectively frees all speculatively cached fonts.
4074 void
4075 imlib_set_font_cache_size(int bytes)
4077 if (!ctx)
4078 ctx = imlib_context_new();
4079 imlib_font_cache_set(bytes);
4083 * Causes a flush of all speculatively cached fonts from the font
4084 * cache.
4086 void
4087 imlib_flush_font_cache(void)
4089 if (!ctx)
4090 ctx = imlib_context_new();
4091 imlib_font_flush();
4095 * @return The font's ascent.
4097 * Returns the current font's ascent value in pixels.
4101 imlib_get_font_ascent(void)
4103 if (!ctx)
4104 ctx = imlib_context_new();
4105 CHECK_PARAM_POINTER_RETURN("imlib_get_font_ascent", "font", ctx->font, 0);
4106 return imlib_font_ascent_get(ctx->font);
4110 * @return The font's descent.
4112 * Returns the current font's descent value in pixels.
4116 imlib_get_font_descent(void)
4118 if (!ctx)
4119 ctx = imlib_context_new();
4120 CHECK_PARAM_POINTER_RETURN("imlib_get_font_ascent", "font", ctx->font, 0);
4121 return imlib_font_descent_get(ctx->font);
4125 * @return The font's maximum ascent.
4127 * Returns the current font's maximum ascent extent.
4131 imlib_get_maximum_font_ascent(void)
4133 if (!ctx)
4134 ctx = imlib_context_new();
4135 CHECK_PARAM_POINTER_RETURN("imlib_get_font_ascent", "font", ctx->font, 0);
4136 return imlib_font_max_ascent_get(ctx->font);
4140 * @return The font's maximum descent.
4142 * Returns the current font's maximum descent extent.
4146 imlib_get_maximum_font_descent(void)
4148 if (!ctx)
4149 ctx = imlib_context_new();
4150 CHECK_PARAM_POINTER_RETURN("imlib_get_font_ascent", "font", ctx->font, 0);
4151 return imlib_font_max_descent_get(ctx->font);
4155 * @return Valid handle.
4157 * Creates a new empty color modifier and returns a
4158 * valid handle on success. NULL is returned on failure.
4161 Imlib_Color_Modifier
4162 imlib_create_color_modifier(void)
4164 if (!ctx)
4165 ctx = imlib_context_new();
4166 return (Imlib_Color_Modifier) __imlib_CreateCmod();
4170 * Frees the current color modifier.
4172 void
4173 imlib_free_color_modifier(void)
4175 if (!ctx)
4176 ctx = imlib_context_new();
4177 CHECK_PARAM_POINTER("imlib_free_color_modifier", "color_modifier",
4178 ctx->color_modifier);
4179 __imlib_FreeCmod((ImlibColorModifier *) ctx->color_modifier);
4180 ctx->color_modifier = NULL;
4184 * @param gamma_value Value of gamma.
4186 * Modifies the current color modifier by adjusting the gamma by the
4187 * value specified @p gamma_value. The color modifier is modified not set, so calling
4188 * this repeatedly has cumulative effects. A gamma of 1.0 is normal
4189 * linear, 2.0 brightens and 0.5 darkens etc. Negative values are not
4190 * allowed.
4192 void
4193 imlib_modify_color_modifier_gamma(double gamma_value)
4195 if (!ctx)
4196 ctx = imlib_context_new();
4197 CHECK_PARAM_POINTER("imlib_modify_color_modifier_gamma", "color_modifier",
4198 ctx->color_modifier);
4199 __imlib_CmodModGamma((ImlibColorModifier *) ctx->color_modifier,
4200 gamma_value);
4204 * @param brightness_value Value of brightness.
4206 * Modifies the current color modifier by adjusting the brightness by
4207 * the value @p brightness_value. The color modifier is modified not set, so
4208 * calling this repeatedly has cumulative effects. brightness values
4209 * of 0 do not affect anything. -1.0 will make things completely black
4210 * and 1.0 will make things all white. Values in-between vary
4211 * brightness linearly.
4213 void
4214 imlib_modify_color_modifier_brightness(double brightness_value)
4216 if (!ctx)
4217 ctx = imlib_context_new();
4218 CHECK_PARAM_POINTER("imlib_modify_color_modifier_brightness",
4219 "color_modifier", ctx->color_modifier);
4220 __imlib_CmodModBrightness((ImlibColorModifier *) ctx->color_modifier,
4221 brightness_value);
4225 * @param contrast_value Value of contrast.
4227 * Modifies the current color modifier by adjusting the contrast by
4228 * the value @p contrast_value. The color modifier is modified not set, so
4229 * calling this repeatedly has cumulative effects. Contrast of 1.0 does
4230 * nothing. 0.0 will merge to gray, 2.0 will double contrast etc.
4232 void
4233 imlib_modify_color_modifier_contrast(double contrast_value)
4235 if (!ctx)
4236 ctx = imlib_context_new();
4237 CHECK_PARAM_POINTER("imlib_modify_color_modifier_contrast",
4238 "color_modifier", ctx->color_modifier);
4239 __imlib_CmodModContrast((ImlibColorModifier *) ctx->color_modifier,
4240 contrast_value);
4244 * @param red_table An array of #DATA8.
4245 * @param green_table An array of #DATA8.
4246 * @param blue_table An array of #DATA8.
4247 * @param alpha_table An array of #DATA8.
4249 * Explicitly copies the mapping tables from the table pointers passed
4250 * into this function into those of the current color modifier. Tables
4251 * are 256 entry arrays of DATA8 which are a mapping of that channel
4252 * value to a new channel value. A normal mapping would be linear (v[0]
4253 * = 0, v[10] = 10, v[50] = 50, v[200] = 200, v[255] = 255).
4255 void
4256 imlib_set_color_modifier_tables(DATA8 * red_table, DATA8 * green_table,
4257 DATA8 * blue_table, DATA8 * alpha_table)
4259 if (!ctx)
4260 ctx = imlib_context_new();
4261 CHECK_PARAM_POINTER("imlib_set_color_modifier_tables", "color_modifier",
4262 ctx->color_modifier);
4263 __imlib_CmodSetTables((ImlibColorModifier *) ctx->color_modifier,
4264 red_table, green_table, blue_table, alpha_table);
4268 * @param red_table: an array of #DATA8.
4269 * @param green_table: an array of #DATA8.
4270 * @param blue_table: an array of #DATA8.
4271 * @param alpha_table: an array of #DATA8.
4273 * Copies the table values from the current color modifier into the
4274 * pointers to mapping tables specified. They must have 256 entries and
4275 * be DATA8 format.
4277 void
4278 imlib_get_color_modifier_tables(DATA8 * red_table, DATA8 * green_table,
4279 DATA8 * blue_table, DATA8 * alpha_table)
4281 if (!ctx)
4282 ctx = imlib_context_new();
4283 CHECK_PARAM_POINTER("imlib_get_color_modifier_tables", "color_modifier",
4284 ctx->color_modifier);
4285 __imlib_CmodGetTables((ImlibColorModifier *) ctx->color_modifier,
4286 red_table, green_table, blue_table, alpha_table);
4290 * Resets the current color modifier to have linear mapping tables.
4292 void
4293 imlib_reset_color_modifier(void)
4295 if (!ctx)
4296 ctx = imlib_context_new();
4297 CHECK_PARAM_POINTER("imlib_rset_color_modifier", "color_modifier",
4298 ctx->color_modifier);
4299 __imlib_CmodReset((ImlibColorModifier *) ctx->color_modifier);
4303 * Uses the current color modifier and modifies the current image using
4304 * the mapping tables in the current color modifier.
4306 void
4307 imlib_apply_color_modifier(void)
4309 ImlibImage *im;
4311 if (!ctx)
4312 ctx = imlib_context_new();
4313 CHECK_PARAM_POINTER("imlib_apply_color_modifier", "image", ctx->image);
4314 CHECK_PARAM_POINTER("imlib_apply_color_modifier", "color_modifier",
4315 ctx->color_modifier);
4316 CAST_IMAGE(im, ctx->image);
4317 if ((!(im->data)) && (im->loader) && (im->loader->load))
4318 im->loader->load(im, NULL, 0, 1);
4319 if (!(im->data))
4320 return;
4321 __imlib_DirtyImage(im);
4322 __imlib_DataCmodApply(im->data, im->w, im->h, 0, &(im->flags),
4323 (ImlibColorModifier *) ctx->color_modifier);
4327 * @param x The x coordinate of the left edge of the rectangle.
4328 * @param y The y coordinate of the top edge of the rectangle.
4329 * @param width The width of the rectangle.
4330 * @param height The height of the rectangle.
4332 * Works the same way as imlib_apply_color_modifier() but only modifies
4333 * a selected rectangle in the current image.
4335 void
4336 imlib_apply_color_modifier_to_rectangle(int x, int y, int width, int height)
4338 ImlibImage *im;
4340 if (!ctx)
4341 ctx = imlib_context_new();
4342 CHECK_PARAM_POINTER("imlib_apply_color_modifier_to_rectangle", "image",
4343 ctx->image);
4344 CHECK_PARAM_POINTER("imlib_apply_color_modifier_to_rectangle",
4345 "color_modifier", ctx->color_modifier);
4346 CAST_IMAGE(im, ctx->image);
4347 if (x < 0)
4349 width += x;
4350 x = 0;
4352 if (width <= 0)
4353 return;
4354 if ((x + width) > im->w)
4355 width = (im->w - x);
4356 if (width <= 0)
4357 return;
4358 if (y < 0)
4360 height += y;
4361 y = 0;
4363 if (height <= 0)
4364 return;
4365 if ((y + height) > im->h)
4366 height = (im->h - y);
4367 if (height <= 0)
4368 return;
4369 if ((!(im->data)) && (im->loader) && (im->loader->load))
4370 im->loader->load(im, NULL, 0, 1);
4371 if (!(im->data))
4372 return;
4373 __imlib_DirtyImage(im);
4374 __imlib_DataCmodApply(im->data + (y * im->w) + x, width, height,
4375 im->w - width, &(im->flags),
4376 (ImlibColorModifier *) ctx->color_modifier);
4379 Imlib_Updates
4380 imlib_image_draw_pixel(int x, int y, char make_updates)
4382 ImlibImage *im;
4383 DATA32 color;
4385 if (!ctx)
4386 ctx = imlib_context_new();
4387 CHECK_PARAM_POINTER_RETURN("imlib_image_draw_pixel", "image", ctx->image,
4388 NULL);
4389 CAST_IMAGE(im, ctx->image);
4390 if ((!(im->data)) && (im->loader) && (im->loader->load))
4391 im->loader->load(im, NULL, 0, 1);
4392 if (!(im->data))
4393 return NULL;
4394 __imlib_DirtyImage(im);
4395 A_VAL(&color) = (DATA8) ctx->color.alpha;
4396 R_VAL(&color) = (DATA8) ctx->color.red;
4397 G_VAL(&color) = (DATA8) ctx->color.green;
4398 B_VAL(&color) = (DATA8) ctx->color.blue;
4399 return (Imlib_Updates) __imlib_Point_DrawToImage(x, y, color, im,
4400 ctx->cliprect.x, ctx->cliprect.y,
4401 ctx->cliprect.w, ctx->cliprect.h,
4402 ctx->operation, ctx->blend,
4403 make_updates);
4407 * @param x1 The x coordinate of the first point.
4408 * @param y1 The y coordinate of the first point.
4409 * @param x2 The x coordinate of the second point.
4410 * @param y2 The y coordinate of the second point.
4411 * @param make_updates: a char.
4412 * @return An updates list.
4414 * Draws a line using the current color on the current image from
4415 * coordinates (@p x1, @p y1) to (@p x2, @p y2). If @p make_updates is 1 it will also
4416 * return an update you can use for an updates list, otherwise it
4417 * returns NULL.
4420 Imlib_Updates
4421 imlib_image_draw_line(int x1, int y1, int x2, int y2, char make_updates)
4423 ImlibImage *im;
4424 DATA32 color;
4426 if (!ctx)
4427 ctx = imlib_context_new();
4428 CHECK_PARAM_POINTER_RETURN("imlib_image_draw_line", "image", ctx->image,
4429 NULL);
4430 CAST_IMAGE(im, ctx->image);
4431 if ((!(im->data)) && (im->loader) && (im->loader->load))
4432 im->loader->load(im, NULL, 0, 1);
4433 if (!(im->data))
4434 return NULL;
4435 __imlib_DirtyImage(im);
4436 A_VAL(&color) = (DATA8) ctx->color.alpha;
4437 R_VAL(&color) = (DATA8) ctx->color.red;
4438 G_VAL(&color) = (DATA8) ctx->color.green;
4439 B_VAL(&color) = (DATA8) ctx->color.blue;
4440 return (Imlib_Updates) __imlib_Line_DrawToImage(x1, y1, x2, y2, color, im,
4441 ctx->cliprect.x, ctx->cliprect.y,
4442 ctx->cliprect.w, ctx->cliprect.h,
4443 ctx->operation, ctx->blend,
4444 ctx->anti_alias, make_updates);
4448 * @param x The top left x coordinate of the rectangle.
4449 * @param y The top left y coordinate of the rectangle.
4450 * @param width The width of the rectangle.
4451 * @param height The height of the rectangle.
4453 * Draws the outline of a rectangle on the current image at the (@p x,
4454 * @p y)
4455 * coordinates with a size of @p width and @p height pixels, using the
4456 * current color.
4458 void
4459 imlib_image_draw_rectangle(int x, int y, int width, int height)
4461 ImlibImage *im;
4462 DATA32 color;
4464 if (!ctx)
4465 ctx = imlib_context_new();
4466 CHECK_PARAM_POINTER("imlib_image_draw_rectangle", "image", ctx->image);
4467 CAST_IMAGE(im, ctx->image);
4468 if ((!(im->data)) && (im->loader) && (im->loader->load))
4469 im->loader->load(im, NULL, 0, 1);
4470 if (!(im->data))
4471 return;
4472 __imlib_DirtyImage(im);
4473 A_VAL(&color) = (DATA8) ctx->color.alpha;
4474 R_VAL(&color) = (DATA8) ctx->color.red;
4475 G_VAL(&color) = (DATA8) ctx->color.green;
4476 B_VAL(&color) = (DATA8) ctx->color.blue;
4477 __imlib_Rectangle_DrawToImage(x, y, width, height, color,
4478 im, ctx->cliprect.x, ctx->cliprect.y,
4479 ctx->cliprect.w, ctx->cliprect.h,
4480 ctx->operation, ctx->blend);
4484 * @param x The top left x coordinate of the rectangle.
4485 * @param y The top left y coordinate of the rectangle.
4486 * @param width The width of the rectangle.
4487 * @param height The height of the rectangle.
4489 * Draws a filled rectangle on the current image at the (@p x, @p y)
4490 * coordinates with a size of @p width and @p height pixels, using the
4491 * current color.
4493 void
4494 imlib_image_fill_rectangle(int x, int y, int width, int height)
4496 ImlibImage *im;
4497 DATA32 color;
4499 if (!ctx)
4500 ctx = imlib_context_new();
4501 CHECK_PARAM_POINTER("imlib_image_fill_rectangle", "image", ctx->image);
4502 CAST_IMAGE(im, ctx->image);
4503 if ((!(im->data)) && (im->loader) && (im->loader->load))
4504 im->loader->load(im, NULL, 0, 1);
4505 if (!(im->data))
4506 return;
4507 __imlib_DirtyImage(im);
4508 A_VAL(&color) = (DATA8) ctx->color.alpha;
4509 R_VAL(&color) = (DATA8) ctx->color.red;
4510 G_VAL(&color) = (DATA8) ctx->color.green;
4511 B_VAL(&color) = (DATA8) ctx->color.blue;
4512 __imlib_Rectangle_FillToImage(x, y, width, height, color,
4513 im, ctx->cliprect.x, ctx->cliprect.y,
4514 ctx->cliprect.w, ctx->cliprect.h,
4515 ctx->operation, ctx->blend);
4519 * @param image_source An image.
4520 * @param x The x coordinate.
4521 * @param y The y coordinate.
4523 * Copies the alpha channel of the source image @p image_source to the
4524 * (@p x, @p y) coordinates
4525 * of the current image, replacing the alpha channel there.
4527 void
4528 imlib_image_copy_alpha_to_image(Imlib_Image image_source, int x, int y)
4530 ImlibImage *im, *im2;
4532 if (!ctx)
4533 ctx = imlib_context_new();
4534 CHECK_PARAM_POINTER("imlib_image_copy_alpha_to_image", "image_source",
4535 image_source);
4536 CHECK_PARAM_POINTER("imlib_image_copy_alpha_to_image", "image_destination",
4537 ctx->image);
4538 CAST_IMAGE(im, image_source);
4539 CAST_IMAGE(im2, ctx->image);
4540 if ((!(im->data)) && (im->loader) && (im->loader->load))
4541 im->loader->load(im, NULL, 0, 1);
4542 if ((!(im2->data)) && (im2->loader) && (im2->loader->load))
4543 im2->loader->load(im, NULL, 0, 1);
4544 if (!(im->data))
4545 return;
4546 if (!(im2->data))
4547 return;
4548 __imlib_DirtyImage(im);
4549 __imlib_copy_alpha_data(im, im2, 0, 0, im->w, im->h, x, y);
4553 * @param image_source An image.
4554 * @param x The top left x coordinate of the rectangle.
4555 * @param y The top left y coordinate of the rectangle.
4556 * @param width The width of the rectangle.
4557 * @param height The height of the rectangle.
4558 * @param destination_x The top left x coordinate of the destination rectangle.
4559 * @param destination_y The top left x coordinate of the destination rectangle.
4561 * Copies the source (@p x, @p y, @p width, @p height) rectangle alpha channel from
4562 * the source image @p image_source and replaces the alpha channel on the destination
4563 * image at the (@p destination_x, @p destination_y) coordinates.
4565 void
4566 imlib_image_copy_alpha_rectangle_to_image(Imlib_Image image_source, int x,
4567 int y, int width, int height,
4568 int destination_x, int destination_y)
4570 ImlibImage *im, *im2;
4572 if (!ctx)
4573 ctx = imlib_context_new();
4574 CHECK_PARAM_POINTER("imlib_image_copy_alpha_rectangle_to_image",
4575 "image_source", image_source);
4576 CHECK_PARAM_POINTER("imlib_image_copy_alpha_rectangle_to_image",
4577 "image_destination", ctx->image);
4578 CAST_IMAGE(im, image_source);
4579 CAST_IMAGE(im2, ctx->image);
4580 if ((!(im->data)) && (im->loader) && (im->loader->load))
4581 im->loader->load(im, NULL, 0, 1);
4582 if ((!(im2->data)) && (im2->loader) && (im2->loader->load))
4583 im2->loader->load(im2, NULL, 0, 1);
4584 if (!(im->data))
4585 return;
4586 if (!(im2->data))
4587 return;
4588 __imlib_DirtyImage(im);
4589 __imlib_copy_alpha_data(im, im2, x, y, width, height, destination_x,
4590 destination_y);
4594 * @param x The top left x coordinate of the rectangle.
4595 * @param y The top left y coordinate of the rectangle.
4596 * @param width The width of the rectangle.
4597 * @param height The height of the rectangle.
4598 * @param delta_x Distance along the x coordinates.
4599 * @param delta_y Distance along the y coordinates.
4601 * Scrolls a rectangle of size @p width, @p height at the (@p x, @p y)
4602 * location within the current image
4603 * by the @p delta_x, @p delta_y distance (in pixels).
4605 void
4606 imlib_image_scroll_rect(int x, int y, int width, int height, int delta_x,
4607 int delta_y)
4609 ImlibImage *im;
4610 int xx, yy, w, h, nx, ny;
4612 if (!ctx)
4613 ctx = imlib_context_new();
4614 CHECK_PARAM_POINTER("imlib_image_scroll_rect", "image", ctx->image);
4615 CAST_IMAGE(im, ctx->image);
4616 if ((!(im->data)) && (im->loader) && (im->loader->load))
4617 im->loader->load(im, NULL, 0, 1);
4618 if (!(im->data))
4619 return;
4620 if (delta_x > 0)
4622 xx = x;
4623 nx = x + delta_x;
4624 w = width - delta_x;
4626 else
4628 xx = x - delta_x;
4629 nx = x;
4630 w = width + delta_x;
4632 if (delta_y > 0)
4634 yy = y;
4635 ny = y + delta_y;
4636 h = height - delta_y;
4638 else
4640 yy = y - delta_y;
4641 ny = y;
4642 h = height + delta_y;
4644 __imlib_DirtyImage(im);
4645 __imlib_copy_image_data(im, xx, yy, w, h, nx, ny);
4649 * @param x The top left x coordinate of the rectangle.
4650 * @param y The top left y coordinate of the rectangle.
4651 * @param width The width of the rectangle.
4652 * @param height The height of the rectangle.
4653 * @param new_x The top left x coordinate of the new location.
4654 * @param new_y The top left y coordinate of the new location.
4656 * Copies a rectangle of size @p width, @p height at the (@p x, @p y) location
4657 * specified in the current image to a new location (@p new_x, @p new_y) in the same
4658 * image.
4660 void
4661 imlib_image_copy_rect(int x, int y, int width, int height, int new_x, int new_y)
4663 ImlibImage *im;
4665 if (!ctx)
4666 ctx = imlib_context_new();
4667 CHECK_PARAM_POINTER("imlib_image_copy_rect", "image", ctx->image);
4668 CAST_IMAGE(im, ctx->image);
4669 if ((!(im->data)) && (im->loader) && (im->loader->load))
4670 im->loader->load(im, NULL, 0, 1);
4671 if (!(im->data))
4672 return;
4673 __imlib_DirtyImage(im);
4674 __imlib_copy_image_data(im, x, y, width, height, new_x, new_y);
4678 * @return valid handle.
4680 * Creates a new empty color range and returns a valid handle to that
4681 * color range.
4683 Imlib_Color_Range
4684 imlib_create_color_range(void)
4686 if (!ctx)
4687 ctx = imlib_context_new();
4688 return (Imlib_Color_Range) __imlib_CreateRange();
4692 * Frees the current color range.
4694 void
4695 imlib_free_color_range(void)
4697 if (!ctx)
4698 ctx = imlib_context_new();
4699 CHECK_PARAM_POINTER("imlib_free_color_range", "color_range",
4700 ctx->color_range);
4701 __imlib_FreeRange((ImlibRange *) ctx->color_range);
4702 ctx->color_range = NULL;
4706 * @param distance_away Distance from the previous color.
4708 * Adds the current color to the current color range at a @p distance_away
4709 * distance from the previous color in the range (if it's the first
4710 * color in the range this is irrelevant).
4712 void
4713 imlib_add_color_to_color_range(int distance_away)
4715 if (!ctx)
4716 ctx = imlib_context_new();
4717 CHECK_PARAM_POINTER("imlib_add_color_to_color_range", "color_range",
4718 ctx->color_range);
4719 __imlib_AddRangeColor((ImlibRange *) ctx->color_range, ctx->color.red,
4720 ctx->color.green, ctx->color.blue, ctx->color.alpha,
4721 distance_away);
4725 * @param x The x coordinate of the left edge of the rectangle.
4726 * @param y The y coordinate of the top edge of the rectangle.
4727 * @param width The width of the rectangle.
4728 * @param height The height of the rectangle.
4729 * @param angle Angle of gradient.
4731 * Fills a rectangle of width @p width and height @p height at the (@p x, @p y) location
4732 * specified in the current image with a linear gradient of the
4733 * current color range at an angle of @p angle degrees with 0 degrees
4734 * being vertical from top to bottom going clockwise from there.
4736 void
4737 imlib_image_fill_color_range_rectangle(int x, int y, int width, int height,
4738 double angle)
4740 ImlibImage *im;
4742 if (!ctx)
4743 ctx = imlib_context_new();
4744 CHECK_PARAM_POINTER("imlib_image_fill_color_range_rectangle", "image",
4745 ctx->image);
4746 CHECK_PARAM_POINTER("imlib_image_fill_color_range_rectangle",
4747 "color_range", ctx->color_range);
4748 CAST_IMAGE(im, ctx->image);
4749 if ((!(im->data)) && (im->loader) && (im->loader->load))
4750 im->loader->load(im, NULL, 0, 1);
4751 if (!(im->data))
4752 return;
4753 __imlib_DirtyImage(im);
4754 __imlib_DrawGradient(im, x, y, width, height,
4755 (ImlibRange *) ctx->color_range, angle,
4756 ctx->operation,
4757 ctx->cliprect.x, ctx->cliprect.y,
4758 ctx->cliprect.w, ctx->cliprect.h);
4762 * @param x The x coordinate of the left edge of the rectangle.
4763 * @param y The y coordinate of the top edge of the rectangle.
4764 * @param width The width of the rectangle.
4765 * @param height The height of the rectangle.
4766 * @param angle Angle of gradient.
4768 * Fills a rectangle of width @p width and height @p height at the (@p
4769 * x, @p y) location
4770 * specified in the current image with a linear gradient in HSVA color
4771 * space of the current color range at an angle of @p angle degrees with
4772 * 0 degrees being vertical from top to bottom going clockwise from
4773 * there.
4775 void
4776 imlib_image_fill_hsva_color_range_rectangle(int x, int y, int width, int height,
4777 double angle)
4779 ImlibImage *im;
4781 if (!ctx)
4782 ctx = imlib_context_new();
4783 CHECK_PARAM_POINTER("imlib_image_fill_color_range_rectangle", "image",
4784 ctx->image);
4785 CHECK_PARAM_POINTER("imlib_image_fill_color_range_rectangle",
4786 "color_range", ctx->color_range);
4787 CAST_IMAGE(im, ctx->image);
4788 if ((!(im->data)) && (im->loader) && (im->loader->load))
4789 im->loader->load(im, NULL, 0, 1);
4790 if (!(im->data))
4791 return;
4792 __imlib_DirtyImage(im);
4793 __imlib_DrawHsvaGradient(im, x, y, width, height,
4794 (ImlibRange *) ctx->color_range, angle,
4795 ctx->operation,
4796 ctx->cliprect.x, ctx->cliprect.y,
4797 ctx->cliprect.w, ctx->cliprect.h);
4801 * @param x The x coordinate of the pixel.
4802 * @param y The y coordinate of the pixel.
4803 * @param color_return The returned color.
4805 * Fills the @p color_return color structure with the color of the pixel
4806 * in the current image that is at the (@p x, @p y) location specified.
4808 void
4809 imlib_image_query_pixel(int x, int y, Imlib_Color * color_return)
4811 ImlibImage *im;
4812 DATA32 *p;
4814 if (!ctx)
4815 ctx = imlib_context_new();
4816 CHECK_PARAM_POINTER("imlib_image_query_pixel", "image", ctx->image);
4817 CHECK_PARAM_POINTER("imlib_image_query_pixel", "color_return", color_return);
4818 CAST_IMAGE(im, ctx->image);
4819 if ((!(im->data)) && (im->loader) && (im->loader->load))
4820 im->loader->load(im, NULL, 0, 1);
4821 if (!(im->data))
4822 return;
4823 if ((x < 0) || (x >= im->w) || (y < 0) || (y >= im->h))
4825 color_return->red = 0;
4826 color_return->green = 0;
4827 color_return->blue = 0;
4828 color_return->alpha = 0;
4829 return;
4831 p = im->data + (im->w * y) + x;
4832 color_return->red = ((*p) >> 16) & 0xff;
4833 color_return->green = ((*p) >> 8) & 0xff;
4834 color_return->blue = (*p) & 0xff;
4835 color_return->alpha = ((*p) >> 24) & 0xff;
4839 * @param x The x coordinate of the pixel.
4840 * @param y The y coordinate of the pixel.
4841 * @param hue The returned hue channel.
4842 * @param saturation The returned saturation channel.
4843 * @param value The returned value channel.
4844 * @param alpha The returned alpha channel.
4846 * Gets the HSVA color of the pixel from the current image that is at
4847 * the (@p x, @p y) location specified.
4849 void
4850 imlib_image_query_pixel_hsva(int x, int y, float *hue, float *saturation,
4851 float *value, int *alpha)
4853 ImlibImage *im;
4854 DATA32 *p;
4855 int r, g, b;
4857 if (!ctx)
4858 ctx = imlib_context_new();
4859 CHECK_PARAM_POINTER("imlib_image_query_pixel", "image", ctx->image);
4860 CAST_IMAGE(im, ctx->image);
4861 if ((!(im->data)) && (im->loader) && (im->loader->load))
4862 im->loader->load(im, NULL, 0, 1);
4863 if (!(im->data))
4864 return;
4865 if ((x < 0) || (x >= im->w) || (y < 0) || (y >= im->h))
4867 *hue = 0;
4868 *saturation = 0;
4869 *value = 0;
4870 *alpha = 0;
4871 return;
4873 p = im->data + (im->w * y) + x;
4874 r = ((*p) >> 16) & 0xff;
4875 g = ((*p) >> 8) & 0xff;
4876 b = (*p) & 0xff;
4877 *alpha = ((*p) >> 24) & 0xff;
4879 __imlib_rgb_to_hsv(r, g, b, hue, saturation, value);
4883 * @param x The x coordinate of the pixel.
4884 * @param y The y coordinate of the pixel.
4885 * @param hue The returned hue channel.
4886 * @param lightness The returned lightness channel.
4887 * @param saturation The returned saturation channel.
4888 * @param alpha The returned alpha channel.
4890 * Gets the HLSA color of the pixel from the current image that is at
4891 * the (@p x, @p y) location specified.
4893 void
4894 imlib_image_query_pixel_hlsa(int x, int y, float *hue, float *lightness,
4895 float *saturation, int *alpha)
4897 ImlibImage *im;
4898 DATA32 *p;
4899 int r, g, b;
4901 if (!ctx)
4902 ctx = imlib_context_new();
4903 CHECK_PARAM_POINTER("imlib_image_query_pixel", "image", ctx->image);
4904 CAST_IMAGE(im, ctx->image);
4905 if ((!(im->data)) && (im->loader) && (im->loader->load))
4906 im->loader->load(im, NULL, 0, 1);
4907 if (!(im->data))
4908 return;
4909 if ((x < 0) || (x >= im->w) || (y < 0) || (y >= im->h))
4911 *hue = 0;
4912 *lightness = 0;
4913 *saturation = 0;
4914 *alpha = 0;
4915 return;
4917 p = im->data + (im->w * y) + x;
4918 r = ((*p) >> 16) & 0xff;
4919 g = ((*p) >> 8) & 0xff;
4920 b = (*p) & 0xff;
4921 *alpha = ((*p) >> 24) & 0xff;
4923 __imlib_rgb_to_hls(r, g, b, hue, lightness, saturation);
4927 * @param x Tthe x coordinate of the pixel.
4928 * @param y The y coordinate of the pixel.
4929 * @param cyan The returned cyan channel.
4930 * @param magenta The returned magenta channel.
4931 * @param yellow The returned yellow channel.
4932 * @param alpha The returned alpha channel.
4934 * Gets the CMYA color of the pixel from the current image that is at
4935 * the (@p x, @p y) location specified.
4938 void
4939 imlib_image_query_pixel_cmya(int x, int y, int *cyan, int *magenta, int *yellow,
4940 int *alpha)
4942 ImlibImage *im;
4943 DATA32 *p;
4945 if (!ctx)
4946 ctx = imlib_context_new();
4947 CHECK_PARAM_POINTER("imlib_image_query_pixel", "image", ctx->image);
4948 CAST_IMAGE(im, ctx->image);
4949 if ((!(im->data)) && (im->loader) && (im->loader->load))
4950 im->loader->load(im, NULL, 0, 1);
4951 if (!(im->data))
4952 return;
4953 if ((x < 0) || (x >= im->w) || (y < 0) || (y >= im->h))
4955 *cyan = 0;
4956 *magenta = 0;
4957 *yellow = 0;
4958 *alpha = 0;
4959 return;
4961 p = im->data + (im->w * y) + x;
4962 *cyan = 255 - (((*p) >> 16) & 0xff);
4963 *magenta = 255 - (((*p) >> 8) & 0xff);
4964 *yellow = 255 - ((*p) & 0xff);
4965 *alpha = ((*p) >> 24) & 0xff;
4969 * @param key A string.
4970 * @param data A pointer.
4971 * @param value A value.
4972 * @param destructor_function An Imlib internal function.
4974 * Attaches data to the current image with the string key of @p key, and
4975 * the data of @p data and an integer of @p value. The
4976 * @p destructor_function function, if not NULL is called when this
4977 * image is freed so the destructor can free @p data, if this is needed.
4979 void
4980 imlib_image_attach_data_value(const char *key, void *data, int value,
4981 Imlib_Internal_Data_Destructor_Function
4982 destructor_function)
4984 ImlibImage *im;
4986 if (!ctx)
4987 ctx = imlib_context_new();
4988 CHECK_PARAM_POINTER("imlib_image_attach_data_value", "image", ctx->image);
4989 CHECK_PARAM_POINTER("imlib_image_attach_data_value", "key", key);
4990 CAST_IMAGE(im, ctx->image);
4991 __imlib_AttachTag(im, key, value, data,
4992 (ImlibDataDestructorFunction) destructor_function);
4996 * @param key A string.
4997 * @return The attached data as a pointer, or NULL if none.
4999 * Gets the data attached to the current image with the key @p key
5000 * specified. NULL is returned if no data could be found with that key
5001 * on the current image.
5004 void *
5005 imlib_image_get_attached_data(const char *key)
5007 ImlibImageTag *t;
5008 ImlibImage *im;
5010 if (!ctx)
5011 ctx = imlib_context_new();
5012 CHECK_PARAM_POINTER_RETURN("imlib_image_get_attached_data", "image",
5013 ctx->image, NULL);
5014 CHECK_PARAM_POINTER_RETURN("imlib_image_get_attached_data", "key", key,
5015 NULL);
5016 CAST_IMAGE(im, ctx->image);
5017 t = __imlib_GetTag(im, key);
5018 if (t)
5019 return t->data;
5020 return NULL;
5024 * @param key A string.
5025 * @return The attached value as an integer, or 0 if none.
5027 * Returns the value attached to the current image with the specified
5028 * key @p key. If none could be found 0 is returned.
5032 imlib_image_get_attached_value(const char *key)
5034 ImlibImageTag *t;
5035 ImlibImage *im;
5037 if (!ctx)
5038 ctx = imlib_context_new();
5039 CHECK_PARAM_POINTER_RETURN("imlib_image_get_attached_value", "image",
5040 ctx->image, 0);
5041 CHECK_PARAM_POINTER_RETURN("imlib_image_get_attached_value", "key", key, 0);
5042 CAST_IMAGE(im, ctx->image);
5043 t = __imlib_GetTag(im, key);
5044 if (t)
5045 return t->val;
5046 return 0;
5050 * @param key A string.
5052 * Detaches the data & value attached with the specified key @p key from the
5053 * current image.
5055 void
5056 imlib_image_remove_attached_data_value(const char *key)
5058 ImlibImage *im;
5060 if (!ctx)
5061 ctx = imlib_context_new();
5062 CHECK_PARAM_POINTER("imlib_image_remove_attached_data_value", "image",
5063 ctx->image);
5064 CHECK_PARAM_POINTER("imlib_image_remove_attached_data_value", "key", key);
5065 CAST_IMAGE(im, ctx->image);
5066 __imlib_RemoveTag(im, key);
5070 * @param key A string.
5072 * Removes the data and value attached to the current image with the
5073 * specified key @p key and also calls the destructor function that was
5074 * supplied when attaching it (see imlib_image_attach_data_value()).
5076 void
5077 imlib_image_remove_and_free_attached_data_value(const char *key)
5079 ImlibImageTag *t;
5080 ImlibImage *im;
5082 if (!ctx)
5083 ctx = imlib_context_new();
5084 CHECK_PARAM_POINTER("imlib_image_remove_and_free_attached_data_value",
5085 "image", ctx->image);
5086 CHECK_PARAM_POINTER("imlib_image_remove_and_free_attached_data_value",
5087 "key", key);
5088 CAST_IMAGE(im, ctx->image);
5089 t = __imlib_RemoveTag(im, key);
5090 __imlib_FreeTag(im, t);
5094 * @param filename The file name.
5096 * Saves the current image in the format specified by the current
5097 * image's format settings to the filename @p filename.
5099 void
5100 imlib_save_image(const char *filename)
5102 ImlibImage *im;
5103 Imlib_Image prev_ctxt_image;
5105 if (!ctx)
5106 ctx = imlib_context_new();
5107 CHECK_PARAM_POINTER("imlib_save_image", "image", ctx->image);
5108 CHECK_PARAM_POINTER("imlib_save_image", "filename", filename);
5109 CAST_IMAGE(im, ctx->image);
5110 if ((!(im->data)) && (im->loader) && (im->loader->load))
5111 im->loader->load(im, NULL, 0, 1);
5112 if (!im->data)
5113 return;
5114 prev_ctxt_image = ctx->image;
5115 __imlib_SaveImage(im, filename, (ImlibProgressFunction) ctx->progress_func,
5116 ctx->progress_granularity, NULL);
5117 ctx->image = prev_ctxt_image;
5121 * @param filename The file name.
5122 * @param error_return The returned error.
5124 * Works the same way imlib_save_image() works, but will set the
5125 * @p error_return to an error value if the save fails.
5127 void
5128 imlib_save_image_with_error_return(const char *filename,
5129 Imlib_Load_Error * error_return)
5131 ImlibImage *im;
5132 Imlib_Image prev_ctxt_image;
5134 if (!ctx)
5135 ctx = imlib_context_new();
5136 CHECK_PARAM_POINTER("imlib_save_image_with_error_return", "image",
5137 ctx->image);
5138 CHECK_PARAM_POINTER("imlib_save_image_with_error_return", "filename",
5139 filename);
5140 CHECK_PARAM_POINTER("imlib_save_image_with_error_return", "error_return",
5141 error_return);
5142 CAST_IMAGE(im, ctx->image);
5143 if ((!(im->data)) && (im->loader) && (im->loader->load))
5144 im->loader->load(im, NULL, 0, 1);
5145 if (!im->data)
5146 return;
5147 prev_ctxt_image = ctx->image;
5148 __imlib_SaveImage(im, filename, (ImlibProgressFunction) ctx->progress_func,
5149 ctx->progress_granularity, error_return);
5150 ctx->image = prev_ctxt_image;
5154 * @param angle An angle in radians.
5155 * @return A new image, or NULL.
5157 * Creates an new copy of the current image, but rotated by @p angle
5158 * radians. On success it returns a valid image handle, otherwise
5159 * NULL.
5161 Imlib_Image
5162 imlib_create_rotated_image(double angle)
5164 ImlibImage *im, *im_old;
5165 int x, y, dx, dy, sz;
5166 double x1, y1, d;
5168 if (!ctx)
5169 ctx = imlib_context_new();
5170 CHECK_PARAM_POINTER_RETURN("imlib_create_rotated_image", "image",
5171 ctx->image, NULL);
5172 CAST_IMAGE(im_old, ctx->image);
5173 if ((!(im_old->data)) && (im_old->loader) && (im_old->loader->load))
5174 im_old->loader->load(im_old, NULL, 0, 1);
5175 if (!(im_old->data))
5176 return NULL;
5178 d = hypot((double)(im_old->w + 4), (double)(im_old->h + 4)) / sqrt(2.0);
5180 x1 = (double)(im_old->w) / 2.0 - sin(angle + atan(1.0)) * d;
5181 y1 = (double)(im_old->h) / 2.0 - cos(angle + atan(1.0)) * d;
5183 sz = (int)(d * sqrt(2.0));
5184 x = (int)(x1 * _ROTATE_PREC_MAX);
5185 y = (int)(y1 * _ROTATE_PREC_MAX);
5186 dx = (int)(cos(angle) * _ROTATE_PREC_MAX);
5187 dy = -(int)(sin(angle) * _ROTATE_PREC_MAX);
5189 im = __imlib_CreateImage(sz, sz, NULL);
5190 im->data = calloc(sz * sz, sizeof(DATA32));
5191 if (!(im->data))
5193 __imlib_FreeImage(im);
5194 return NULL;
5197 if (ctx->anti_alias)
5199 #ifdef DO_MMX_ASM
5200 if (__imlib_get_cpuid() & CPUID_MMX)
5201 __imlib_mmx_RotateAA(im_old->data, im->data, im_old->w, im_old->w,
5202 im_old->h, im->w, sz, sz, x, y, dx, dy, -dy,
5203 dx);
5204 else
5205 #endif
5206 __imlib_RotateAA(im_old->data, im->data, im_old->w, im_old->w,
5207 im_old->h, im->w, sz, sz, x, y, dx, dy, -dy, dx);
5209 else
5211 __imlib_RotateSample(im_old->data, im->data, im_old->w, im_old->w,
5212 im_old->h, im->w, sz, sz, x, y, dx, dy, -dy, dx);
5214 SET_FLAG(im->flags, F_HAS_ALPHA);
5216 return (Imlib_Image) im;
5219 void imlib_rotate_image_from_buffer(double angle,
5220 Imlib_Image source_image)
5222 ImlibImage *im, *im_old;
5223 int x, y, dx, dy, sz;
5224 double x1, y1, d;
5226 if (!ctx)
5227 ctx = imlib_context_new();
5228 // source image (to rotate)
5229 CHECK_PARAM_POINTER("imlib_rotate_image_from_buffer", "source_image",
5230 source_image);
5231 CAST_IMAGE(im_old, source_image);
5233 // current context image
5234 CHECK_PARAM_POINTER("imlib_rotate_image_from_buffer", "image",
5235 ctx->image);
5236 CAST_IMAGE(im, ctx->image);
5238 if ((!(im_old->data)) && (im_old->loader) && (im_old->loader->load))
5239 im_old->loader->load(im_old, NULL, 0, 1);
5241 if (!(im_old->data)) return;
5243 d = hypot((double)(im_old->w + 4), (double)(im_old->h + 4)) / sqrt(2.0);
5245 x1 = (double)(im_old->w) / 2.0 - sin(angle + atan(1.0)) * d;
5246 y1 = (double)(im_old->h) / 2.0 - cos(angle + atan(1.0)) * d;
5248 sz = (int)(d * sqrt(2.0));
5249 x = (int)(x1 * _ROTATE_PREC_MAX);
5250 y = (int)(y1 * _ROTATE_PREC_MAX);
5251 dx = (int)(cos(angle) * _ROTATE_PREC_MAX);
5252 dy = -(int)(sin(angle) * _ROTATE_PREC_MAX);
5254 if ( (im->w != im->h) || ((im->w < sz) && (im->h < sz)))
5255 return; // If size is wrong
5256 else sz = im->w; // update sz with real width
5258 /* Not neccesary 'cause destination is context
5259 im = __imlib_CreateImage(sz, sz, NULL);
5260 im->data = calloc(sz * sz, sizeof(DATA32));
5261 if (!(im->data))
5263 __imlib_FreeImage(im);
5264 return;
5267 if (ctx->anti_alias)
5269 #ifdef DO_MMX_ASM
5270 if (__imlib_get_cpuid() & CPUID_MMX)
5271 __imlib_mmx_RotateAA(im_old->data, im->data, im_old->w, im_old->w,
5272 im_old->h, im->w, sz, sz, x, y, dx, dy, -dy,
5273 dx);
5274 else
5275 #endif
5276 __imlib_RotateAA(im_old->data, im->data, im_old->w, im_old->w,
5277 im_old->h, im->w, sz, sz, x, y, dx, dy, -dy, dx);
5279 else
5281 __imlib_RotateSample(im_old->data, im->data, im_old->w, im_old->w,
5282 im_old->h, im->w, sz, sz, x, y, dx, dy, -dy, dx);
5284 SET_FLAG(im->flags, F_HAS_ALPHA);
5287 return;
5291 * @param source_image The image source.
5292 * @param merge_alpha A char.
5293 * @param source_x The source x coordinate.
5294 * @param source_y The source y coordinate.
5295 * @param source_width The source width.
5296 * @param source_height The source height.
5297 * @param destination_x The destination x coordinate.
5298 * @param destination_y The destination y coordinate.
5299 * @param angle_x An angle.
5300 * @param angle_y An angle.
5302 * Works just like imlib_blend_image_onto_image_skewed() except you
5303 * cannot skew an image (@p v_angle_x and @p v_angle_y are 0).
5305 void
5306 imlib_blend_image_onto_image_at_angle(Imlib_Image source_image,
5307 char merge_alpha, int source_x,
5308 int source_y, int source_width,
5309 int source_height, int destination_x,
5310 int destination_y, int angle_x,
5311 int angle_y)
5313 ImlibImage *im_src, *im_dst;
5315 if (!ctx)
5316 ctx = imlib_context_new();
5317 CHECK_PARAM_POINTER("imlib_blend_image_onto_image_at_angle",
5318 "source_image", source_image);
5319 CHECK_PARAM_POINTER("imlib_blend_image_onto_image_at_angle", "image",
5320 ctx->image);
5321 CAST_IMAGE(im_src, source_image);
5322 CAST_IMAGE(im_dst, ctx->image);
5323 if ((!(im_src->data)) && (im_src->loader) && (im_src->loader->load))
5324 im_src->loader->load(im_src, NULL, 0, 1);
5325 if (!(im_src->data))
5326 return;
5327 if ((!(im_dst->data)) && (im_dst->loader) && (im_dst->loader->load))
5328 im_dst->loader->load(im_dst, NULL, 0, 1);
5329 if (!(im_dst->data))
5330 return;
5331 __imlib_DirtyImage(im_dst);
5332 __imlib_BlendImageToImageSkewed(im_src, im_dst, ctx->anti_alias,
5333 ctx->blend, merge_alpha, source_x,
5334 source_y, source_width, source_height,
5335 destination_x, destination_y, angle_x,
5336 angle_y, 0, 0, ctx->color_modifier,
5337 ctx->operation,
5338 ctx->cliprect.x, ctx->cliprect.y,
5339 ctx->cliprect.w, ctx->cliprect.h);
5343 * @param source_image The source image.
5344 * @param merge_alpha A char
5345 * @param source_x The source x coordinate.
5346 * @param source_y The source y coordinate.
5347 * @param source_width The source width.
5348 * @param source_height The source height.
5349 * @param destination_x The destination x coordinate.
5350 * @param destination_y The destination y coordinate.
5351 * @param h_angle_x An angle.
5352 * @param h_angle_y An angle.
5353 * @param v_angle_x An angle.
5354 * @param v_angle_y An angle.
5356 * Blends the source rectangle (@p source_x, @p source_y, @p source_width,
5357 * @p source_height) from the
5358 * @p source_image onto the current image at the destination
5359 * (@p destination_x, @p destination_y)
5360 * location. It will be rotated and scaled so that the upper right
5361 * corner will be positioned @p h_angle_x pixels to the right (or left,
5362 * if negative) and @p h_angle_y pixels down (from (@p destination_x,
5363 * @p destination_y). If
5364 * @p v_angle_x and @p v_angle_y are not 0, the image will also be skewed so
5365 * that the lower left corner will be positioned @p v_angle_x pixels to
5366 * the right and @p v_angle_y pixels down. The at_angle versions simply
5367 * have the @p v_angle_x and @p v_angle_y set to 0 so the rotation doesn't
5368 * get skewed, and the render_..._on_drawable ones seem obvious
5369 * enough; they do the same on a drawable.
5371 * Example:
5372 * @code
5373 * imlib_blend_image_onto_image_skewed(..., 0, 0, 100, 0, 0, 100);
5374 * @endcode
5375 * will simply scale the image to be 100x100.
5376 * @code
5377 * imlib_blend_image_onto_image_skewed(..., 0, 0, 0, 100, 100, 0);
5378 * @endcode
5379 * will scale the image to be 100x100, and flip it diagonally.
5380 * @code
5381 * imlib_blend_image_onto_image_skewed(..., 100, 0, 0, 100, -100, 0);
5382 * @endcode
5383 * will scale the image and rotate it 90 degrees clockwise.
5384 * @code
5385 * imlib_blend_image_onto_image_skewed(..., 50, 0, 50, 50, -50, 50);
5386 * @endcode
5387 * will rotate the image 45 degrees clockwise, and will scale it so
5388 * its corners are at (50,0)-(100,50)-(50,100)-(0,50) i.e. it fits
5389 * into the 100x100 square, so it's scaled down to 70.7% (sqrt(2)/2).
5390 * @code
5391 * imlib_blend_image_onto_image_skewed(..., 50, 50, 100 * cos(a), 100 * sin(a), 0);
5392 * @endcode
5393 * will rotate the image `a' degrees, with its upper left corner at (50,50).
5395 void
5396 imlib_blend_image_onto_image_skewed(Imlib_Image source_image,
5397 char merge_alpha, int source_x,
5398 int source_y, int source_width,
5399 int source_height, int destination_x,
5400 int destination_y, int h_angle_x,
5401 int h_angle_y, int v_angle_x, int v_angle_y)
5403 ImlibImage *im_src, *im_dst;
5405 if (!ctx)
5406 ctx = imlib_context_new();
5407 CHECK_PARAM_POINTER("imlib_blend_image_onto_image_skewed", "source_image",
5408 source_image);
5409 CHECK_PARAM_POINTER("imlib_blend_image_onto_image_skewed", "image",
5410 ctx->image);
5411 CAST_IMAGE(im_src, source_image);
5412 CAST_IMAGE(im_dst, ctx->image);
5413 if ((!(im_src->data)) && (im_src->loader) && (im_src->loader->load))
5414 im_src->loader->load(im_src, NULL, 0, 1);
5415 if (!(im_src->data))
5416 return;
5417 if ((!(im_dst->data)) && (im_dst->loader) && (im_dst->loader->load))
5418 im_dst->loader->load(im_dst, NULL, 0, 1);
5419 if (!(im_dst->data))
5420 return;
5421 __imlib_DirtyImage(im_dst);
5422 __imlib_BlendImageToImageSkewed(im_src, im_dst, ctx->anti_alias,
5423 ctx->blend, merge_alpha, source_x,
5424 source_y, source_width, source_height,
5425 destination_x, destination_y, h_angle_x,
5426 h_angle_y, v_angle_x, v_angle_y,
5427 ctx->color_modifier, ctx->operation,
5428 ctx->cliprect.x, ctx->cliprect.y,
5429 ctx->cliprect.w, ctx->cliprect.h);
5432 #ifdef BUILD_X11
5434 * @param source_x The source x coordinate.
5435 * @param source_y The source y coordinate.
5436 * @param source_width The source width.
5437 * @param source_height The source height.
5438 * @param destination_x The destination x coordinate.
5439 * @param destination_y The destination y coordinate.
5440 * @param h_angle_x An angle.
5441 * @param h_angle_y An angle.
5442 * @param v_angle_x An angle.
5443 * @param v_angle_y An angle.
5446 * Works just like imlib_blend_image_onto_image_skewed(), except it
5447 * blends the image onto the current drawable instead of the current
5448 * image.
5450 void
5451 imlib_render_image_on_drawable_skewed(int source_x, int source_y,
5452 int source_width, int source_height,
5453 int destination_x, int destination_y,
5454 int h_angle_x, int h_angle_y,
5455 int v_angle_x, int v_angle_y)
5457 ImlibImage *im;
5459 if (!ctx)
5460 ctx = imlib_context_new();
5461 CHECK_PARAM_POINTER("imlib_render_image_on_drawable_skewed", "image",
5462 ctx->image);
5463 CAST_IMAGE(im, ctx->image);
5464 if ((!(im->data)) && (im->loader) && (im->loader->load))
5465 im->loader->load(im, NULL, 0, 1);
5466 if (!(im->data))
5467 return;
5468 CAST_IMAGE(im, ctx->image);
5469 __imlib_RenderImageSkewed(ctx->display, im, ctx->drawable, ctx->mask,
5470 ctx->visual, ctx->colormap, ctx->depth, source_x,
5471 source_y, source_width, source_height,
5472 destination_x, destination_y, h_angle_x,
5473 h_angle_y, v_angle_x, v_angle_y, ctx->anti_alias,
5474 ctx->dither, ctx->blend, ctx->dither_mask,
5475 ctx->color_modifier, ctx->operation);
5479 * @param source_x The source x coordinate.
5480 * @param source_y The source y coordinate.
5481 * @param source_width The source width.
5482 * @param source_height The source height.
5483 * @param destination_x The destination x coordinate.
5484 * @param destination_y The destination y coordinate.
5485 * @param angle_x An angle.
5486 * @param angle_y An angle.
5489 * Works just like imlib_render_image_on_drawable_skewed() except you
5490 * cannot skew an image (@p v_angle_x and @p v_angle_y are 0).
5492 void
5493 imlib_render_image_on_drawable_at_angle(int source_x, int source_y,
5494 int source_width, int source_height,
5495 int destination_x, int destination_y,
5496 int angle_x, int angle_y)
5498 ImlibImage *im;
5500 if (!ctx)
5501 ctx = imlib_context_new();
5502 CHECK_PARAM_POINTER("imlib_render_image_on_drawable_at_angle", "image",
5503 ctx->image);
5504 CAST_IMAGE(im, ctx->image);
5505 if ((!(im->data)) && (im->loader) && (im->loader->load))
5506 im->loader->load(im, NULL, 0, 1);
5507 if (!(im->data))
5508 return;
5509 CAST_IMAGE(im, ctx->image);
5510 __imlib_RenderImageSkewed(ctx->display, im, ctx->drawable, ctx->mask,
5511 ctx->visual, ctx->colormap, ctx->depth, source_x,
5512 source_y, source_width, source_height,
5513 destination_x, destination_y, angle_x, angle_y,
5514 0, 0, ctx->anti_alias, ctx->dither, ctx->blend,
5515 ctx->dither_mask, ctx->color_modifier,
5516 ctx->operation);
5518 #endif
5520 void
5521 imlib_image_filter(void)
5523 ImlibImage *im;
5525 if (!ctx)
5526 ctx = imlib_context_new();
5527 CHECK_PARAM_POINTER("imlib_image_filter", "image", ctx->image);
5528 CHECK_PARAM_POINTER("imlib_image_filter", "filter", ctx->filter);
5529 CAST_IMAGE(im, ctx->image);
5530 if ((!(im->data)) && (im->loader) && (im->loader->load))
5531 im->loader->load(im, NULL, 0, 1);
5532 if (!(im->data))
5533 return;
5534 __imlib_DirtyImage(im);
5535 __imlib_FilterImage(im, (ImlibFilter *) ctx->filter);
5538 Imlib_Filter
5539 imlib_create_filter(int initsize)
5541 if (!ctx)
5542 ctx = imlib_context_new();
5543 return (Imlib_Filter) __imlib_CreateFilter(initsize);
5546 void
5547 imlib_free_filter(void)
5549 if (!ctx)
5550 ctx = imlib_context_new();
5551 CHECK_PARAM_POINTER("imlib_free_filter", "filter", ctx->filter);
5552 __imlib_FreeFilter((ImlibFilter *) ctx->filter);
5553 ctx->filter = NULL;
5556 /**
5557 * @param filter Current filter.
5559 * Sets the current filter to be used when applying filters to
5560 * images. Set this to NULL to disable filters.
5562 void
5563 imlib_context_set_filter(Imlib_Filter filter)
5565 if (!ctx)
5566 ctx = imlib_context_new();
5567 ctx->filter = filter;
5570 /**
5571 * @return
5573 * Gets the current context image filter.
5575 Imlib_Filter
5576 imlib_context_get_filter(void)
5578 if (!ctx)
5579 ctx = imlib_context_new();
5580 return ctx->filter;
5583 void
5584 imlib_filter_set(int xoff, int yoff, int a, int r, int g, int b)
5586 ImlibFilter *fil;
5588 if (!ctx)
5589 ctx = imlib_context_new();
5590 CHECK_PARAM_POINTER("imlib_filter_set", "filter", ctx->filter);
5591 fil = (ImlibFilter *) ctx->filter;
5592 __imlib_FilterSetColor(&fil->alpha, xoff, yoff, a, 0, 0, 0);
5593 __imlib_FilterSetColor(&fil->red, xoff, yoff, 0, r, 0, 0);
5594 __imlib_FilterSetColor(&fil->green, xoff, yoff, 0, 0, g, 0);
5595 __imlib_FilterSetColor(&fil->blue, xoff, yoff, 0, 0, 0, b);
5598 void
5599 imlib_filter_set_alpha(int xoff, int yoff, int a, int r, int g, int b)
5601 ImlibFilter *fil;
5603 if (!ctx)
5604 ctx = imlib_context_new();
5605 CHECK_PARAM_POINTER("imlib_filter_set_alpha", "filter", ctx->filter);
5606 fil = (ImlibFilter *) ctx->filter;
5607 __imlib_FilterSetColor(&fil->alpha, xoff, yoff, a, r, g, b);
5610 void
5611 imlib_filter_set_red(int xoff, int yoff, int a, int r, int g, int b)
5613 ImlibFilter *fil;
5615 if (!ctx)
5616 ctx = imlib_context_new();
5617 CHECK_PARAM_POINTER("imlib_filter_set_red", "filter", ctx->filter);
5618 fil = (ImlibFilter *) ctx->filter;
5619 __imlib_FilterSetColor(&fil->red, xoff, yoff, a, r, g, b);
5622 void
5623 imlib_filter_set_green(int xoff, int yoff, int a, int r, int g, int b)
5625 ImlibFilter *fil;
5627 if (!ctx)
5628 ctx = imlib_context_new();
5629 CHECK_PARAM_POINTER("imlib_filter_set_green", "filter", ctx->filter);
5630 fil = (ImlibFilter *) ctx->filter;
5631 __imlib_FilterSetColor(&fil->green, xoff, yoff, a, r, g, b);
5634 void
5635 imlib_filter_set_blue(int xoff, int yoff, int a, int r, int g, int b)
5637 ImlibFilter *fil;
5639 if (!ctx)
5640 ctx = imlib_context_new();
5641 CHECK_PARAM_POINTER("imlib_filter_set_blue", "filter", ctx->filter);
5642 fil = (ImlibFilter *) ctx->filter;
5643 __imlib_FilterSetColor(&fil->blue, xoff, yoff, a, r, g, b);
5646 void
5647 imlib_filter_constants(int a, int r, int g, int b)
5649 if (!ctx)
5650 ctx = imlib_context_new();
5651 CHECK_PARAM_POINTER("imlib_filter_constants", "filter", ctx->filter);
5652 __imlib_FilterConstants((ImlibFilter *) ctx->filter, a, r, g, b);
5655 void
5656 imlib_filter_divisors(int a, int r, int g, int b)
5658 if (!ctx)
5659 ctx = imlib_context_new();
5660 CHECK_PARAM_POINTER("imlib_filter_divisors", "filter", ctx->filter);
5661 __imlib_FilterDivisors((ImlibFilter *) ctx->filter, a, r, g, b);
5664 void
5665 imlib_apply_filter(char *script, ...)
5667 va_list param_list;
5668 ImlibImage *im;
5670 if (!ctx)
5671 ctx = imlib_context_new();
5672 __imlib_dynamic_filters_init();
5673 CAST_IMAGE(im, ctx->image);
5674 if ((!(im->data)) && (im->loader) && (im->loader->load))
5675 im->loader->load(im, NULL, 0, 1);
5676 if (!(im->data))
5677 return;
5678 __imlib_DirtyImage(im);
5679 va_start(param_list, script);
5680 __imlib_script_parse(im, script, param_list);
5681 va_end(param_list);
5685 * Returns a new polygon object with no points set.
5687 ImlibPolygon
5688 imlib_polygon_new(void)
5690 if (!ctx)
5691 ctx = imlib_context_new();
5692 return (ImlibPolygon) __imlib_polygon_new();
5696 * @param poly A polygon
5697 * @param x The X coordinate.
5698 * @param y The Y coordinate.
5700 * Adds the point (@p x, @p y) to the polygon @p poly. The point will be added
5701 * to the end of the polygon's internal point list. The points are
5702 * drawn in order, from the first to the last.
5704 void
5705 imlib_polygon_add_point(ImlibPolygon poly, int x, int y)
5707 if (!ctx)
5708 ctx = imlib_context_new();
5709 CHECK_PARAM_POINTER("imlib_polygon_add_point", "polygon", poly);
5710 __imlib_polygon_add_point((ImlibPoly) poly, x, y);
5714 * @param poly A polygon.
5716 * Frees a polygon object.
5718 void
5719 imlib_polygon_free(ImlibPolygon poly)
5721 if (!ctx)
5722 ctx = imlib_context_new();
5723 CHECK_PARAM_POINTER("imlib_polygon_free", "polygon", poly);
5724 __imlib_polygon_free((ImlibPoly) poly);
5728 * @param poly A polygon.
5729 * @param closed Closed polygon flag.
5731 * Draws the polygon @p poly onto the current context image. Points which have
5732 * been added to the polygon are drawn in sequence, first to last. The
5733 * final point will be joined with the first point if @p closed is
5734 * non-zero.
5736 void
5737 imlib_image_draw_polygon(ImlibPolygon poly, unsigned char closed)
5739 ImlibImage *im;
5740 DATA32 color;
5742 if (!ctx)
5743 ctx = imlib_context_new();
5744 CHECK_PARAM_POINTER("imlib_image_draw_polygon", "image", ctx->image);
5745 CAST_IMAGE(im, ctx->image);
5746 if ((!(im->data)) && (im->loader) && (im->loader->load))
5747 im->loader->load(im, NULL, 0, 1);
5748 if (!(im->data))
5749 return;
5750 __imlib_DirtyImage(im);
5751 A_VAL(&color) = (DATA8) ctx->color.alpha;
5752 R_VAL(&color) = (DATA8) ctx->color.red;
5753 G_VAL(&color) = (DATA8) ctx->color.green;
5754 B_VAL(&color) = (DATA8) ctx->color.blue;
5755 __imlib_Polygon_DrawToImage((ImlibPoly) poly, closed, color,
5756 im, ctx->cliprect.x, ctx->cliprect.y,
5757 ctx->cliprect.w, ctx->cliprect.h,
5758 ctx->operation, ctx->blend, ctx->anti_alias);
5762 * @param poly A polygon.
5764 * Fills the area defined by the polygon @p polyon the current context image
5765 * with the current context color.
5767 void
5768 imlib_image_fill_polygon(ImlibPolygon poly)
5770 ImlibImage *im;
5771 DATA32 color;
5773 if (!ctx)
5774 ctx = imlib_context_new();
5775 CHECK_PARAM_POINTER("imlib_image_fill_polygon", "image", ctx->image);
5776 CAST_IMAGE(im, ctx->image);
5777 if ((!(im->data)) && (im->loader) && (im->loader->load))
5778 im->loader->load(im, NULL, 0, 1);
5779 if (!(im->data))
5780 return;
5781 __imlib_DirtyImage(im);
5782 A_VAL(&color) = (DATA8) ctx->color.alpha;
5783 R_VAL(&color) = (DATA8) ctx->color.red;
5784 G_VAL(&color) = (DATA8) ctx->color.green;
5785 B_VAL(&color) = (DATA8) ctx->color.blue;
5786 __imlib_Polygon_FillToImage((ImlibPoly) poly, color,
5787 im, ctx->cliprect.x, ctx->cliprect.y,
5788 ctx->cliprect.w, ctx->cliprect.h,
5789 ctx->operation, ctx->blend, ctx->anti_alias);
5793 * @param poly A polygon.
5794 * @param px1 X coordinate of the upper left corner.
5795 * @param py1 Y coordinate of the upper left corner.
5796 * @param px2 X coordinate of the lower right corner.
5797 * @param py2 Y coordinate of the lower right corner.
5799 * Calculates the bounding area of the polygon @p poly. (@p px1, @p py1) defines the
5800 * upper left corner of the bounding box and (@p px2, @p py2) defines it's
5801 * lower right corner.
5803 void
5804 imlib_polygon_get_bounds(ImlibPolygon poly, int *px1, int *py1, int *px2,
5805 int *py2)
5807 if (!ctx)
5808 ctx = imlib_context_new();
5809 CHECK_PARAM_POINTER("imlib_polygon_get_bounds", "polygon", poly);
5810 __imlib_polygon_get_bounds((ImlibPoly) poly, px1, py1, px2, py2);
5814 * @param xc X coordinate of the center of the ellipse.
5815 * @param yc Y coordinate of the center of the ellipse.
5816 * @param a The horizontal amplitude of the ellipse.
5817 * @param b The vertical amplitude of the ellipse.
5819 * Draws an ellipse on the current context image. The ellipse is
5820 * defined as (@p x-@p xc)^2/@p a^2 + (@p y-@p yc)^2/@p b^2 = 1. This means that the
5821 * point (@p xc, @p yc) marks the center of the ellipse, @p a defines the
5822 * horizontal amplitude of the ellipse, and @p b defines the vertical
5823 * amplitude.
5825 void
5826 imlib_image_draw_ellipse(int xc, int yc, int a, int b)
5828 ImlibImage *im;
5829 DATA32 color;
5831 if (!ctx)
5832 ctx = imlib_context_new();
5833 CHECK_PARAM_POINTER("imlib_draw_ellipse", "image", ctx->image);
5834 CAST_IMAGE(im, ctx->image);
5835 if ((!(im->data)) && (im->loader) && (im->loader->load))
5836 im->loader->load(im, NULL, 0, 1);
5837 if (!(im->data))
5838 return;
5839 __imlib_DirtyImage(im);
5840 A_VAL(&color) = (DATA8) ctx->color.alpha;
5841 R_VAL(&color) = (DATA8) ctx->color.red;
5842 G_VAL(&color) = (DATA8) ctx->color.green;
5843 B_VAL(&color) = (DATA8) ctx->color.blue;
5844 __imlib_Ellipse_DrawToImage(xc, yc, a, b, color,
5845 im, ctx->cliprect.x, ctx->cliprect.y,
5846 ctx->cliprect.w, ctx->cliprect.h,
5847 ctx->operation, ctx->blend, ctx->anti_alias);
5851 * @param xc X coordinate of the center of the ellipse.
5852 * @param yc Y coordinate of the center of the ellipse.
5853 * @param a The horizontal amplitude of the ellipse.
5854 * @param b The vertical amplitude of the ellipse.
5856 * Fills an ellipse on the current context image using the current
5857 * context color. The ellipse is
5858 * defined as (@p x-@p xc)^2/@p a^2 + (@p y-@p yc)^2/@p b^2 = 1. This means that the
5859 * point (@p xc, @p yc) marks the center of the ellipse, @p a defines the
5860 * horizontal amplitude of the ellipse, and @p b defines the vertical
5861 * amplitude.
5863 void
5864 imlib_image_fill_ellipse(int xc, int yc, int a, int b)
5866 ImlibImage *im;
5867 DATA32 color;
5869 if (!ctx)
5870 ctx = imlib_context_new();
5871 CHECK_PARAM_POINTER("imlib_fill_ellipse", "image", ctx->image);
5872 CAST_IMAGE(im, ctx->image);
5873 if ((!(im->data)) && (im->loader) && (im->loader->load))
5874 im->loader->load(im, NULL, 0, 1);
5875 if (!(im->data))
5876 return;
5877 __imlib_DirtyImage(im);
5878 A_VAL(&color) = (DATA8) ctx->color.alpha;
5879 R_VAL(&color) = (DATA8) ctx->color.red;
5880 G_VAL(&color) = (DATA8) ctx->color.green;
5881 B_VAL(&color) = (DATA8) ctx->color.blue;
5882 __imlib_Ellipse_FillToImage(xc, yc, a, b, color,
5883 im, ctx->cliprect.x, ctx->cliprect.y,
5884 ctx->cliprect.w, ctx->cliprect.h,
5885 ctx->operation, ctx->blend, ctx->anti_alias);
5889 * @param poly A polygon
5890 * @param x The X coordinate.
5891 * @param y The Y coordinate.
5893 * Returns non-zero if the point (@p x, @p y) is within the area defined by
5894 * the polygon @p poly.
5896 unsigned char
5897 imlib_polygon_contains_point(ImlibPolygon poly, int x, int y)
5899 if (!ctx)
5900 ctx = imlib_context_new();
5901 CHECK_PARAM_POINTER_RETURN("imlib_polygon_contains_point", "polygon", poly, 0);
5902 return __imlib_polygon_contains_point((ImlibPoly) poly, x, y);
5905 void
5906 imlib_image_clear(void)
5908 ImlibImage *im;
5910 if (!ctx)
5911 ctx = imlib_context_new();
5912 CHECK_PARAM_POINTER("imlib_image_clear", "image", ctx->image);
5913 CAST_IMAGE(im, ctx->image);
5914 if ((!(im->data)) && (im->loader) && (im->loader->load))
5915 im->loader->load(im, NULL, 0, 1);
5916 if (!(im->data))
5917 return;
5918 __imlib_DirtyImage(im);
5919 memset(im->data, 0, im->w * im->h * sizeof(DATA32));
5922 void
5923 imlib_image_clear_color(int r, int g, int b, int a)
5925 ImlibImage *im;
5926 int i, max;
5927 DATA32 col;
5929 if (!ctx)
5930 ctx = imlib_context_new();
5931 CHECK_PARAM_POINTER("imlib_image_clear_color", "image", ctx->image);
5932 CAST_IMAGE(im, ctx->image);
5933 if ((!(im->data)) && (im->loader) && (im->loader->load))
5934 im->loader->load(im, NULL, 0, 1);
5935 if (!(im->data))
5936 return;
5937 __imlib_DirtyImage(im);
5938 max = im->w * im->h;
5939 WRITE_RGBA(&col, r, g, b, a);
5940 for (i = 0; i < max; i++)
5941 im->data[i] = col;