legacy-imlib2/doc/index.html

2269 lines
103 KiB
HTML
Raw Normal View History

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Mozilla/4.72 [en] (X11; U; Linux 2.2.16-3ext3 i686) [Netscape]">
<meta name="Author" content="The Rasterman & Lightman">
<title>Imlib 2 - Documentation.</title>
</head>
<body text="#000000" bgcolor="#FFFFFF" link="#0000EF" vlink="#51188E" alink="#FFFF00">
<center>
<h1>
<img SRC="imlib2.gif" ALT="Imlib2" height=128 width=256></h1></center>
<center><table BORDER=0 CELLSPACING=0 WIDTH="95%" BGCOLOR="#666666" NOSAVE ROWS="5" >
<tr NOSAVE>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
<tr NOSAVE>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td ALIGN=CENTER VALIGN=CENTER NOSAVE><b><font color="#FFFFFF"><font size=+2>What
is it?</font></font></b></td>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
<tr NOSAVE>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
<tr NOSAVE>
<td><img SRC="img/blank.gif" height=1 width=1></td>
<td VALIGN=TOP HEIGHT="100%" BGCOLOR="#6a7a8a" NOSAVE>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.
<p>Imlib 2 does the following:
<ul>
<li>
Load image files from disk in one of many formats</li>
<li>
Save images to disk in one of many formats</li>
<li>
Render image data onto other images</li>
<li>
Render images to an X-Windows drawable</li>
<li>
Produce pixmaps and pixmap masks of Images</li>
<li>
Apply filters to images</li>
<li>
Rotate images</li>
<li>
Accept RGBA Data for images</li>
<li>
Scale images</li>
<li>
Alpha blend Images on other images or drawables</li>
<li>
Apply color correction and modification tables and factors to images</li>
<li>
Render images onto images with color correction and modification tables</li>
<li>
Render truetype anti-aliased text</li>
<li>
Render truetype anti-aliased text at any angle</li>
<li>
Render anti-aliased lines</li>
<li>
Render rectangles</li>
<li>
Render linear multi-colored gradients</li>
<li>
Cache data intelligently for maximum performance</li>
<li>
Allocate colors automatically</li>
<li>
Allow full control over caching and color allocation</li>
<li>
Provide highly optimized MMX assembly for core routines</li>
<li>
Provide plug-in filter interface</li>
<li>
Provide on-the-fly runtime plug-in image loading and saving interface</li>
<li>
Fastest image compositing, rendering and manipulation library for X</li>
</ul>
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.
<p>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.
<p>The interface is simple - once you get used to it, the functions do
exactly what they say they do.</td>
<td><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
<tr NOSAVE>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
</table></center>
<br>
<center><table BORDER=0 CELLSPACING=0 WIDTH="95%" BGCOLOR="#666666" NOSAVE ROWS="5" >
<tr NOSAVE>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
<tr NOSAVE>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td ALIGN=CENTER VALIGN=CENTER NOSAVE><b><font color="#FFFFFF"><font size=+2>A
Simple Example</font></font></b></td>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
<tr NOSAVE>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
<tr NOSAVE>
<td><img SRC="img/blank.gif" height=1 width=1></td>
<td VALIGN=TOP HEIGHT="100%" BGCOLOR="#6a7a8a" NOSAVE>The best way to start
is to show a simple example of an Imlib2 program. This one will load an
image of any format you have a loader installed for (all loaders are dynamic
code objects that Imlib2 will use and update automatically runtime - anyone
is free to write a loader. All that has to be done is for the object to
be dropped into the loaders directory with the others and all Imlib2 programs
will automatically be able to use it - without a restart).
<blockquote>
<pre><tt><font color="#660000">/* standard headers */
#include &lt;X11/Xlib.h&gt;
#include &lt;Imlib2.h&gt;
#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
/* main program */
int main(int argc, char **argv)
{
/* an image handle */
Imlib_Image image;
/* if we provided &lt; 2 arguments after the command - exit */
if (argc != 3) exit(1);
/* load the image */
image = imlib_load_image(argv[1]);
/* if the load was successful */
if (image)
{
char *tmp;
/* set the image we loaded as the current context image to work on */
imlib_context_set_image(image);
/* set the image format to be the format of the extension of our last */
/* argument - i.e. .png = png, .tif = tiff etc. */
tmp = strrchr(argv[2], '.');
if(tmp)
imlib_image_set_format(tmp + 1);
/* save the image */
imlib_save_image(argv[2]);
}
}</font></tt></pre>
Now to compile this
<br>
<tt><font color="#000099">cc imlib2_convert.c -o imlib2_convert `imlib2-config --cflags` `imlib2-config --libs`</font></tt>
<br>
You now have a program that if used as follows:
<br>
<tt><font color="#000099">./imlib2_convert image1.jpg image2.png</font></tt>
<br>
will convert image1.jpg into a png called image2.png. It is that simple.</blockquote>
</td>
<td><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
<tr NOSAVE>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
</table></center>
<br>
<center><table BORDER=0 CELLSPACING=0 WIDTH="95%" BGCOLOR="#666666" NOSAVE ROWS="5" >
<tr NOSAVE>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
<tr NOSAVE>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td ALIGN=CENTER VALIGN=CENTER NOSAVE><b><font color="#FFFFFF"><font size=+2>How
Image Loading Works</font></font></b></td>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
<tr NOSAVE>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
<tr NOSAVE>
<td><img SRC="img/blank.gif" height=1 width=1></td>
<td VALIGN=TOP HEIGHT="100%" BGCOLOR="#6a7a8a" NOSAVE>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.
<br>
<blockquote>
<h3>
Loading using imlib_load_image();</h3>
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.
<p>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 &amp; 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:
<pre><tt><font color="#006600">set cache to some amount (e.g. 4 Mb)
...
rendering loop ...
load image
render image
free image
... continue loop</font></tt></pre>
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.
<p>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 <tt><font color="#660000">imlib_image_set_changes_on_disk();
</font></tt><font color="#000000">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.</font>
<p><font color="#000000">Now what actually happens when we try and load
an image using a filename? First the filename is broken down into 2 parts.
the filename before a colon (:) and the key after the colon. This means
when we have a filename like:</font>
<p><tt><font color="#000099">/path/to/file.jpg</font></tt>
<p><font color="#000000">the filename is:</font>
<p><tt><font color="#000099">/path/to/file.jpg</font></tt>
<p><font color="#000000">and the key is blank. If we have:</font>
<p><tt><font color="#000099">/path/to/file.db:key.value/blah</font></tt>
<p><font color="#000000">the filename is:</font>
<p><tt><font color="#000099">/path/to/file.db</font></tt>
<p><font color="#000000">and the key is:</font>
<p><tt><font color="#000099">key.value/blah</font></tt>
<p><font color="#000000">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.</font>
<p><font color="#000000">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.</font>
<p><font color="#000000">If you desire more detailed information about
why a load failed you can use </font><tt><font color="#000099">imlib_load_image_with_error_return();
</font></tt><font color="#000000">and
it will return a detailed error return code.</font>
<p><font color="#000000">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 </font><tt><font color="#000099">imlib_load_image_immediately();</font></tt>
<p><font color="#000000">If you wish to bypass the cache when loading images
you can using </font><tt><font color="#000099">imlib_load_image_without_cache();
</font></tt><font color="#000000">and
</font><tt><font color="#000099">imlib_load_image_immediately_without_cache();</font></tt><font color="#000000">.</font>
<p><font color="#000000">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 </font><tt><font color="#000099">imlib_context_set_progress_function();</font></tt><font color="#000000">
and </font><tt><font color="#000099">imlib_context_set_progress_granularity();
</font></tt><font color="#000000">to
set this up.</font></blockquote>
</td>
<td><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
<tr NOSAVE>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
</table></center>
<br>
<center><table BORDER=0 CELLSPACING=0 WIDTH="95%" BGCOLOR="#666666" NOSAVE ROWS="5" >
<tr NOSAVE>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
<tr NOSAVE>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td ALIGN=CENTER VALIGN=CENTER NOSAVE><b><font color="#FFFFFF"><font size=+2>A
more advanced Example</font></font></b></td>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
<tr NOSAVE>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
<tr NOSAVE>
<td><img SRC="img/blank.gif" height=1 width=1></td>
<td VALIGN=TOP HEIGHT="100%" BGCOLOR="#6a7a8a" NOSAVE>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.
<blockquote>
<pre><tt><font color="#660000">/* include X11 stuff */
#include &lt;X11/Xlib.h>
/* include Imlib2 stuff */
#include &lt;Imlib2.h>
/* sprintf include */
#include &lt;stdio.h>
/* some globals for our window &amp; X display */
Display *disp;
Window win;
Visual *vis;
Colormap cm;
int depth;
/* the program... */
int main(int argc, char **argv)
{
/* events we get from X */
XEvent ev;
/* areas to update */
Imlib_Updates updates, current_update;
/* our virtual framebuffer image we draw into */
Imlib_Image buffer;
/* a font */
Imlib_Font font;
/* our color range */
Imlib_Color_Range range;
/* our mouse x, y coordinates */
int mouse_x = 0, mouse_y = 0;
/* connect to X */
disp = XOpenDisplay(NULL);
/* get default visual , colormap etc. you could ask imlib2 for what it */
/* thinks is the best, but this example is intended to be simple */
vis = DefaultVisual(disp, DefaultScreen(disp));
depth = DefaultDepth(disp, DefaultScreen(disp));
cm = DefaultColormap(disp, DefaultScreen(disp));
/* create a window 640x480 */
win = XCreateSimpleWindow(disp, DefaultRootWindow(disp),
0, 0, 640, 480, 0, 0, 0);
/* tell X what events we are interested in */
XSelectInput(disp, win, ButtonPressMask | ButtonReleaseMask |
PointerMotionMask | ExposureMask);
/* show the window */
XMapWindow(disp, win);
/* set our cache to 2 Mb so it doesn't have to go hit the disk as long as */
/* the images we use use less than 2Mb of RAM (that is uncompressed) */
imlib_set_cache_size(2048 * 1024);
/* set the font cache to 512Kb - again to avoid re-loading */
imlib_set_font_cache_size(512 * 1024);
/* add the ./ttfonts dir to our font path - you'll want a notepad.ttf */
/* in that dir for the text to display */
imlib_add_path_to_font_path("./ttfonts");
/* set the maximum number of colors to allocate for 8bpp and less to 128 */
imlib_set_color_usage(128);
/* dither for depths &lt; 24bpp */
imlib_context_set_dither(1);
/* set the display , visual, colormap and drawable we are using */
imlib_context_set_display(disp);
imlib_context_set_visual(vis);
imlib_context_set_colormap(cm);
imlib_context_set_drawable(win);
/* infinite event loop */
for (;;)
{
/* image variable */
Imlib_Image image;
/* width and height values */
int w, h, text_w, text_h;
/* init our updates to empty */
updates = imlib_updates_init();
/* while there are events form X - handle them */
do
{
XNextEvent(disp, &amp;ev);
switch (ev.type)
{
case Expose:
/* window rectangle was exposed - add it to the list of */
/* rectangles we need to re-render */
updates = imlib_update_append_rect(updates,
ev.xexpose.x, ev.xexpose.y,
ev.xexpose.width, ev.xexpose.height);
break;
case ButtonPress:
/* if we click anywhere in the window, exit */
exit(0);
break;
case MotionNotify:
/* if the mouse moves - note it */
/* add a rectangle update for the new mouse position */
image = imlib_load_image("./test_images/mush.png");
imlib_context_set_image(image);
w = imlib_image_get_width();
h = imlib_image_get_height();
imlib_context_set_image(image);
imlib_free_image();
/* the old position - so we wipe over where it used to be */
updates = imlib_update_append_rect(updates,
mouse_x - (w / 2), mouse_y - (h / 2),
w, h);
font = imlib_load_font("notepad/30");
if (font)
{
char text[4096];
imlib_context_set_font(font);
sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
imlib_get_text_size(text, &amp;text_w, &amp;text_h);
imlib_free_font();
updates = imlib_update_append_rect(updates,
320 - (text_w / 2), 240 - (text_h / 2),
text_w, text_h);
}
mouse_x = ev.xmotion.x;
mouse_y = ev.xmotion.y;
/* the new one */
updates = imlib_update_append_rect(updates,
mouse_x - (w / 2), mouse_y - (h / 2),
w, h);
font = imlib_load_font("notepad/30");
if (font)
{
char text[4096];
imlib_context_set_font(font);
sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
imlib_get_text_size(text, &amp;text_w, &amp;text_h);
imlib_free_font();
updates = imlib_update_append_rect(updates,
320 - (text_w / 2), 240 - (text_h / 2),
text_w, text_h);
}
default:
/* any other events - do nothing */
break;
}
}
while (XPending(disp));
/* no more events for now ? ok - idle time so lets draw stuff */
/* take all the little rectangles to redraw and merge them into */
/* something sane for rendering */
updates = imlib_updates_merge_for_rendering(updates, 640, 480);
for (current_update = updates;
current_update;
current_update = imlib_updates_get_next(current_update))
{
int up_x, up_y, up_w, up_h;
/* find out where the first update is */
imlib_updates_get_coordinates(current_update,
&amp;up_x, &amp;up_y, &amp;up_w, &amp;up_h);
/* create our buffer image for rendering this update */
buffer = imlib_create_image(up_w, up_h);
/* we can blend stuff now */
imlib_context_set_blend(1);
/* fill the window background */
/* load the background image - you'll need to have some images */
/* in ./test_images lying around for this to actually work */
image = imlib_load_image("./test_images/bg.png");
/* we're working with this image now */
imlib_context_set_image(image);
/* get its size */
w = imlib_image_get_width();
h = imlib_image_get_height();
/* now we want to work with the buffer */
imlib_context_set_image(buffer);
/* if the iimage loaded */
if (image)
{
/* blend image onto the buffer and scale it to 640x480 */
imlib_blend_image_onto_image(image, 0,
0, 0, w, h,
- up_x, - up_y, 640, 480);
/* working with the loaded image */
imlib_context_set_image(image);
/* free it */
imlib_free_image();
}
/* draw an icon centered around the mouse position */
image = imlib_load_image("./test_images/mush.png");
imlib_context_set_image(image);
w = imlib_image_get_width();
h = imlib_image_get_height();
imlib_context_set_image(buffer);
if (image)
{
imlib_blend_image_onto_image(image, 0,
0, 0, w, h,
mouse_x - (w / 2) - up_x, mouse_y - (h / 2) - up_y, w, h);
imlib_context_set_image(image);
imlib_free_image();
}
/* draw a gradient on top of things at the top left of the window */
/* create a range */
range = imlib_create_color_range();
imlib_context_set_color_range(range);
/* add white opaque as the first color */
imlib_context_set_color(255, 255, 255, 255);
imlib_add_color_to_color_range(0);
/* add an orange color, semi-transparent 10 units from the first */
imlib_context_set_color(255, 200, 10, 100);
imlib_add_color_to_color_range(10);
/* add black, fully transparent at the end 20 units away */
imlib_context_set_color(0, 0, 0, 0);
imlib_add_color_to_color_range(20);
/* draw the range */
imlib_context_set_image(buffer);
imlib_image_fill_color_range_rectangle(- up_x, - up_y, 128, 128, -45.0);
/* free it */
imlib_free_color_range();
/* draw text - centered with the current mouse x, y */
font = imlib_load_font("notepad/30");
if (font)
{
char text[4096];
/* set the current font */
imlib_context_set_font(font);
/* set the image */
imlib_context_set_image(buffer);
/* set the color (black) */
imlib_context_set_color(0, 0, 0, 255);
/* print text to display in the buffer */
sprintf(text, "Mouse is at %i, %i", mouse_x, mouse_y);
/* query the size it will be */
imlib_get_text_size(text, &amp;text_w, &amp;text_h);
/* draw it */
imlib_text_draw(320 - (text_w / 2) - up_x, 240 - (text_h / 2) - up_y, text);
/* free the font */
imlib_free_font();
}
/* don't blend the image onto the drawable - slower */
imlib_context_set_blend(0);
/* set the buffer image as our current image */
imlib_context_set_image(buffer);
/* render the image at 0, 0 */
imlib_render_image_on_drawable(up_x, up_y);
/* don't need that temporary buffer image anymore */
imlib_free_image();
}
/* if we had updates - free them */
if (updates)
imlib_updates_free(updates);
/* loop again waiting for events */
}
return 0;
}</font></tt></pre>
</blockquote>
</td>
<td><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
<tr NOSAVE>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
</table></center>
<br>
<center><table BORDER=0 CELLSPACING=0 WIDTH="95%" BGCOLOR="#666666" NOSAVE ROWS="5" >
<tr NOSAVE>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
<tr NOSAVE>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td ALIGN=CENTER VALIGN=CENTER NOSAVE><b><font color="#FFFFFF"><font size=+2>API
Reference</font></font></b></td>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
<tr NOSAVE>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
<td WIDTH="1" NOSAVE><img SRC="img/blank.gif" height=1 width=1></td>
</tr>
<tr NOSAVE>
<td>
<img SRC="img/blank.gif" height=1 width=1>
</td>
<td VALIGN=TOP HEIGHT="100%" BGCOLOR="#6a7a8a" NOSAVE><p>This is a list of
all the Imlib2 API calls and what each of them do. You should familiarize
yourself well with this API so you have a good idea of what can be done.</p>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_display(Display *display);</font></font></tt></b>
<blockquote>Sets the current X display to be used for rendering of images
to drawables. You do not need to set this if you do not intend to render
an image to an X drawable. If you do you will need to set this. If you
change displays just set this to the new display pointer. Do not use a
Display pointer if you have closed that display already - also note that
if you close a display connection and continue to render using Imlib2 without
setting the display pointer to NULL or something new, crashes may occur.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_visual(Visual *visual);</font></font></tt></b>
<blockquote>This sets the current visual to use when rendering images to
drawables or producing pixmaps. You need to set this for anything to render
to a drawable or produce any pixmaps (this can be the default visual).</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_colormap(Colormap colormap);</font></font></tt></b>
<blockquote>Sets the colormap to use when rendering to drawables and allocating
colors. You must set this to the colormap you are using to render any images
or produce any pixmaps (this can be the default colormap).</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_drawable(Drawable drawable);</font></font></tt></b>
<blockquote>This sets the X drawable to which images will be rendered when
you call a render call in Imlib2. This may be either a pixmap or a window.
You must set this to render anything.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_mask(Pixmap mask);</font></font></tt></b>
<blockquote>This sets the 1-bit deep pixmap to be drawn to when rendering
to generate a mask pixmap. This is only useful if the image you are rendering
has alpha. Set this to 0 to not render a pixmap mask.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_dither_mask(char dither_mask);</font></font></tt></b>
<blockquote>Selects if, you are rendering to a mask, or producing pixmap
masks from images, if the mask is to be dithered or not. passing in 1 for
dither_mask means the mask pixmap will be dithered, 0 means it will not
be dithered.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_anti_alias(char anti_alias);</font></font></tt></b>
<blockquote>Toggles "anti-aliased" scaling of images. This isn't quite
correct since it's actually super and sub pixel sampling that it turns
on and off, but anti-aliasing is used for having "smooth" edges to lines
and shapes and this means when images are scaled they will keep their smooth
appearance. Passing in 1 turns this on and 0 turns it off.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_dither(char dither);</font></font></tt></b>
<blockquote>Sets the dithering flag for rendering to a drawable or when
pixmaps are produced. This affects the color image appearance by enabling
dithering. Dithering slows down rendering but produces considerably better
results. this option has no effect foe rendering in 24 bit and up, but
in 16 bit and lower it will dither, producing smooth gradients and much
better quality images. setting dither to 1 enables it and 0 disables it.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_blend(char blend);</font></font></tt></b>
<blockquote>When rendering an image to a drawable, Imlib2 is able to blend
the image directly onto the drawable during rendering. setting this to
1 will enable this. If the image has no alpha channel this has no effect.
Setting it to 0 will disable this.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_color_modifier(Imlib_Color_Modifier color_modifier);</font></font></tt></b>
<blockquote>This sets the current color modifier used for rendering pixmaps
or images to a drawable or images onto other images. Color modifiers are
lookup tables that map the values in the red, green, blue and alpha channels
to other values in the same channel when rendering, allowing for fades,
color correction etc. to be done whilst rendering. pass in NULL as the
color_modifier to disable the color modifier for rendering.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_operation(Imlib_Operation operation);</font></font></tt></b>
<blockquote>When Imlib2 draws an image onto another or an image onto a
drawable it is able to do more than just blend the result on using the
given alpha channel of the image. It is also able to do saturating additive,
subtractive and a combination of the both (called reshade) rendering. The
default mode is IMLIB_OP_COPY. you can also set it to IMLIB_OP_ADD, IMLIB_OP_SUBTRACT
or IMLIB_OP_RESHADE. Use this function to set the rendering operation.
IMLIB_OP_COPY performs basic alpha blending: DST = (SRC * A) + (DST * (1
- A)). IMLIB_OP_ADD does DST = DST + (SRC * A). IMLIB_OP_SUBTRACT does
DST = DST - (SRC * A) and IMLIB_OP_RESHADE does DST = DST + (((SRC - 0.5)
/ 2) * A).</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_font(Imlib_Font font);</font></font></tt></b>
<blockquote>This function sets the current font to use when rendering text.
you should load the font first with imlib_load_font().</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_direction(Imlib_Text_Direction direction);</font></font></tt></b>
<blockquote>This sets the direction in which to draw text in terms of simple
90 degree orientations or an arbitrary angle. The direction can be one
of IMLIB_TEXT_TO_RIGHT, IMLIB_TEXT_TO_LEFT, IMLIB_TEXT_TO_DOWN, IMLIB_TEXT_TO_UP
or IMLIB_TEXT_TO_ANGLE. The default is IMLIB_TEXT_TO_RIGHT. If you use
IMLIB_TEXT_TO_ANGLE, you will also have to set the angle with imlib_context_set_angle().</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_angle(double angle);</font></font></tt></b>
<blockquote>This sets the angle at which text strings will be drawn if
the text direction has been set to IMLIB_TEXT_TO_ANGLE with imlib_context_set_direction().</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_color(int red, int green, int blue, int alpha);</font></font></tt></b>
<blockquote>This sets the color with which text, lines and rectangles are
drawn when being rendered onto an image. Values for red, green, blue and
alpha are between 0 and 255 - any other values have undefined results.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_color_cmya(int cyan, magenta, int yellow, int alpha);</font></font></tt></b>
<blockquote>This sets the color in CMYA space. Values for cyan, magenta,
yellow and alpha are between 0 and 255 - any other values have undefined results.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_color_hsva(float hue, float saturation, float value, int alpha);</font></font></tt></b>
<blockquote>This sets the color in HSVA space. Values for hue are between 0 and 360,
values for saturation and value between 0 and 1, and values for alpha are between 0
and 255 - any other values have undefined results.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_color_hlsa(float hue, float lightness, float saturation, int alpha);</font></font></tt></b>
<blockquote>This sets the color in HLSA space. Values for hue are between 0 and 360,
values for lightness and saturation between 0 and 1, and values for alpha are
between 0 and 255 - any other values have undefined results.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_color_range(Imlib_Color_Range color_range);</font></font></tt></b>
<blockquote>This sets the current color range to use for rendering gradients.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_progress_function(Imlib_Progress_Function progress_function);</font></font></tt></b>
<blockquote>This sets the progress function to be called back whilst loading
images. Set this to the function to be called, or set it to NULL to disable
progress callbacks whilst loading.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_progress_granularity(char progress_granularity);</font></font></tt></b>
<blockquote>This hints as to how often to call the progress callback. 0
means as often as possible. 1 means whenever 15 more of the image has been
decoded, 10 means every 10% of the image decoding, 50 means every 50% and
100 means only call at the end. Values outside of the range 0-100 are undefined.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_image(Imlib_Image image);</font></font></tt></b>
<blockquote>This sets the current image Imlib2 will be using with its function
calls.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_set_filter(Imlib_Filter filter);</font></font></tt></b>
<blockquote>This sets the current filter to be used when applying filters
to images. Set this to NULL to disable filters.</blockquote>
<b><tt><font color="#660000"><font size=+2>Display *imlib_context_get_display(void);</font></font></tt></b>
<blockquote>This returns the current display used for Imlib2's display
context.</blockquote>
<b><tt><font color="#660000"><font size=+2>Visual *imlib_context_get_visual(void);</font></font></tt></b>
<blockquote>Returns the current visual used for Imlib2's context.</blockquote>
<b><tt><font color="#660000"><font size=+2>Colormap imlib_context_get_colormap(void);</font></font></tt></b>
<blockquote>Returns the current Colormap used for Imlib2's context.</blockquote>
<b><tt><font color="#660000"><font size=+2>Drawable imlib_context_get_drawable(void);</font></font></tt></b>
<blockquote>Returns the current Drawable used for Imlib2's context.</blockquote>
<b><tt><font color="#660000"><font size=+2>Pixmap imlib_context_get_mask(void);</font></font></tt></b>
<blockquote>Returns the current pixmap destination to be used to render
a mask into.</blockquote>
<b><tt><font color="#660000"><font size=+2>char imlib_context_get_dither_mask(void);</font></font></tt></b>
<blockquote>Returns the current mode for dithering pixmap masks. 1 means
dithering is enabled and 0 means it is not.</blockquote>
<b><tt><font color="#660000"><font size=+2>char imlib_context_get_anti_alias(void);</font></font></tt></b>
<blockquote>Returns if Imlib2 currently will smoothly scale images. 1 means
it will and 0 means it will not.</blockquote>
<b><tt><font color="#660000"><font size=+2>char imlib_context_get_dither(void);</font></font></tt></b>
<blockquote>Returns if image data is rendered with dithering currently.
1 means yes and 0 means no.</blockquote>
<b><tt><font color="#660000"><font size=+2>char imlib_context_get_blend(void);</font></font></tt></b>
<blockquote>Returns if Imlib2 will blend images onto a drawable whilst
rendering to that drawable. 1 means yes and 0 means no.</blockquote>
<b><tt><font color="#660000"><font size=+2>Imlib_Color_Modifier imlib_context_get_color_modifier(void);</font></font></tt></b>
<blockquote>Returns the current colormodifier being used.</blockquote>
<b><tt><font color="#660000"><font size=+2>Imlib_Operation imlib_context_get_operation(void);</font></font></tt></b>
<blockquote>Returns the current operation mode.</blockquote>
<b><tt><font color="#660000"><font size=+2>Imlib_Font imlib_context_get_font(void);</font></font></tt></b>
<blockquote>Returns the current font.</blockquote>
<b><tt><font color="#660000"><font size=+2>double imlib_context_get_angle(void);</font></font></tt></b>
<blockquote>Returns the current angle used to render text at if the direction
is IMLIB_TEXT_TO_ANGLE.</blockquote>
<b><tt><font color="#660000"><font size=+2>Imlib_Text_Direction imlib_context_get_direction(void);</font></font></tt></b>
<blockquote>Returns the current direction to render text in.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_get_color(int *red, int *green, int *blue, int *alpha);</font></font></tt></b>
<blockquote>Returns the current color for rendering text, rectangles and
lines.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_get_color_cmya(int *cyan, int *magenta, int *yellow, int *alpha);</font></font></tt></b>
<blockquote>Returns the current color for rendering text, rectangles and
lines in CMYA space.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_get_color_hsva(float *hue, float *saturation, float *value, int *alpha);</font></font></tt></b>
<blockquote>Returns the current color for rendering text, rectangles and
lines in HSVA space.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_context_get_color_hlsa(float *hue, float * lightness, float *saturation, int *alpha);</font></font></tt></b>
<blockquote>Returns the current color for rendering text, rectangles and
lines in HLSA space.</blockquote>
<b><tt><font color="#660000"><font size=+2>Imlib_Color *imlib_context_get_imlib_color(void);</font></font></tt></b>
<blockquote>Returns the current color as a color struct. Do NOT free this
pointer.</blockquote>
<b><tt><font color="#660000"><font size=+2>Imlib_Color_Range imlib_context_get_color_range(void);</font></font></tt></b>
<blockquote>Return the current color range being used for gradients.</blockquote>
<b><tt><font color="#660000"><font size=+2>Imlib_Progress_Function imlib_context_get_progress_function(void);</font></font></tt></b>
<blockquote>Return the current progress function being used.</blockquote>
<b><tt><font color="#660000"><font size=+2>char imlib_context_get_progress_granularity(void);</font></font></tt></b>
<blockquote>Get the current progress granularity being used.</blockquote>
<b><tt><font color="#660000"><font size=+2>Imlib_Image imlib_context_get_image(void);</font></font></tt></b>
<blockquote>Return the current context image.</blockquote>
<b><tt><font color="#660000"><font size=+2>Imlib_Filter imlib_context_get_filter(void);</font></font></tt></b>
<blockquote>Get the current context image filter.</blockquote>
<b><tt><font color="#660000"><font size=+2>int imlib_get_cache_size(void);</font></font></tt></b>
<blockquote>Return the current size of the image cache in bytes. The cache
is a unified cache used for image data AND pixmaps.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_set_cache_size(int bytes);</font></font></tt></b>
<blockquote>Set the cache size. The size is in bytes. Setting the cache
size to 0 effectively flushes the cache and keeps the cache size at 0 until
set to another value. Whenever you set the cache size Imlib2 will flush
as many old images and pixmap from the cache as needed until the current
cache usage is less than or equal to the cache size.</blockquote>
<b><tt><font color="#660000"><font size=+2>int imlib_get_color_usage(void);</font></font></tt></b>
<blockquote>Get the number of colors Imlib2 currently at a maximum is allowed
to allocate for rendering. The default is 256.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_set_color_usage(int max);</font></font></tt></b>
<blockquote>Set the maximum number of colors you would like Imlib2 to allocate
for you when rendering. The default ids 256. This has no effect in depths
greater than 8 bit.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_flush_loaders(void);</font></font></tt></b>
<blockquote>If you want Imlib2 to forcibly flush any cached loaders it
has and re-load them from disk (this is useful if the program just installed
a new loader and does not want to wait till Imlib2 deems it an optimal
time to rescan the loaders)</blockquote>
<b><tt><font color="#660000"><font size=+2>int imlib_get_visual_depth(Display *display, Visual *visual);</font></font></tt></b>
<blockquote>Convenience function that returns the depth of a visual for
that display.</blockquote>
<b><tt><font color="#660000"><font size=+2>Visual *imlib_get_best_visual(Display *display, int screen, int *depth_return);</font></font></tt></b>
<blockquote>Returns the visual for that display and screen that Imlib2
thinks will give you the best quality output. depth_return should point
to an int that will be filled with the depth of that visual too.</blockquote>
<b><tt><font color="#660000"><font size=+2>Imlib_Image imlib_load_image(const char *file);</font></font></tt></b>
<blockquote>This function loads an image from disk located at the path
specified by file. Please see the "How image loading works" section for
more detail. Returns an image handle on success or NULL on failure.</blockquote>
<b><tt><font color="#660000"><font size=+2>Imlib_Image imlib_load_image_immediately(const char *file);</font></font></tt></b>
<blockquote>Loads an image from disk located at the path specified by file.
This forces the image data to be decoded at load time too, instead of decoding
being deferred until it is needed. Returns an image handle on success or
NULL on failure.</blockquote>
<b><tt><font color="#660000"><font size=+2>Imlib_Image imlib_load_image_without_cache(const char *file);</font></font></tt></b>
<blockquote>This loads the image without looking in the cache first. Returns
an image handle on success or NULL on failure.</blockquote>
<b><tt><font color="#660000"><font size=+2>Imlib_Image imlib_load_image_immediately_without_cache(const char *file);</font></font></tt></b>
<blockquote>Loads the image without deferred image data decoding (i.e.
it is decoded straight away) and without looking in the cache. Returns
an image handle on success or NULL on failure.</blockquote>
<b><tt><font color="#660000"><font size=+2>Imlib_Image imlib_load_image_with_error_return(const char *file, Imlib_Load_Error *error_return);</font></font></tt></b>
<blockquote>This loads an image at the path file on disk. If it succeeds
it returns a valid image handle, if not NULL is returned and the error_return
pointed to is set to the detail of the error.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_free_image(void);</font></font></tt></b>
<blockquote>This frees the image that is set as the current image in Imlib2's
context.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_free_image_and_decache(void);</font></font></tt></b>
<blockquote>Frees the current image in Imlib2's context AND removes it
from the cache.</blockquote>
<b><tt><font color="#660000"><font size=+2>int imlib_image_get_width(void);</font></font></tt></b>
<blockquote>Returns the width in pixels of the current image in Imlib2's
context.</blockquote>
<b><tt><font color="#660000"><font size=+2>int imlib_image_get_height(void);</font></font></tt></b>
<blockquote>Returns the height in pixels of the current image in Imlib2's
context.</blockquote>
<b><tt><font color="#660000"><font size=+2>const char *imlib_image_get_filename(void);</font></font></tt></b>
<blockquote>This returns the filename for the file that is set as the current
context. The pointer returned is only valid as long as no operations cause
the filename of the image to change. Saving the file with a different name
would cause this. It is suggested you duplicate the string if you wish
to continue to use the string for later processing. Do not free the string
pointer returned by this function.</blockquote>
<b><tt><font color="#660000"><font size=+2>DATA32 *imlib_image_get_data(void);</font></font></tt></b>
<blockquote>This returns a pointer to the image data in the image set as
the image for the current context. When you get this pointer it is assumed
you are planning on writing to the data, thus once you do this the image
can no longer be used for caching - in fact all images cached from this
one will also be affected when you put the data back. If this matters it
is suggested you clone the image first before playing with the image data.
The image data is returned in the format of a DATA32 (32 bits) per pixel
in a linear array ordered from the top left of the image to the bottom
right going from left to right each line. Each pixel has the upper 8 bits
as the alpha channel and the lower 8 bits are the blue channel - so a pixel's
bits are ARGB (from most to least significant, 8 bits per channel). You
must put the data back at some point.</blockquote>
<b><tt><font color="#660000"><font size=+2>DATA32 *imlib_image_get_data_for_reading_only(void);</font></font></tt></b>
<blockquote>This functions the same way as imlib_image_get_data(), but
returns a pointer expecting the program to NOT write to the data returned
(it is for inspection purposes only). Writing to this data has undefined
results. The data does not need to be put back.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_image_put_back_data(DATA32 *data);</font></font></tt></b>
<blockquote>This will put back data when it was obtained by imlib_image_get_data().
The data must be the same pointer returned by imlib_image_get_data(). This
operated on the current context image.</blockquote>
<b><tt><font color="#660000"><font size=+2>char imlib_image_has_alpha(void);</font></font></tt></b>
<blockquote>Returns 1 if the current context image has an alpha channel,
or 0 if it does not (the alpha data space is still there and available
- just "unused").</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_image_set_changes_on_disk(void);</font></font></tt></b>
<blockquote>By default Imlib2 will not check the timestamp of an image
on disk and compare it with the image in its cache - this is to minimize
disk activity when using the cache. Call this function and it will flag
the current context image as being liable to change on disk and Imlib2
will check the timestamp of the image file on disk and compare it with
the cached image when it next needs to use this image in the cache.</blockquote>
<b><tt><font color="#660000"><font size=+2>void imlib_image_get_border(Imlib_Border *border);</font></font></tt></b>
<blockquote>This function fills the Imlib_Border structure to which border
points to with the values of the border of the current context image. The
border is the area at the edge of the image that does not scale with the