I'm trying to blend two images with alpha using Imlib library (this code is changing wallpaper). So far I got this:
#include <stdio.h>
#include <X11/Xlib.h>
#include <Imlib2.h>
int main( int argc, char **argv )
{
Display *display;
Pixmap pixmap;
Window root;
Screen *screen;
int width,
height,
w1,
w2,
h1,
h2;
Imlib_Image img,
img2;
// loading images
img = imlib_load_image( "/usr/share/wallpapers/wallpaper1.jpg" );
img2 = imlib_load_image( "/usr/share/wallpapers/wallpaper2.jpg" );
if( !img || !img2 ) {
printf( "Unable to load image.\n" );
return 1;
}
// open display, get screen and root window
display = XOpenDisplay(NULL);
screen = DefaultScreenOfDisplay( display );
root = DefaultRootWindow( display );
width = screen->width;
height = screen->height;
// create pixmap
pixmap = XCreatePixmap( display, root, width, height, DefaultDepthOfScreen(screen) );
// #S == BLENDING 1 =========================
imlib_context_set_image( img );
w1 = imlib_image_get_width();
h1 = imlib_image_get_height();
imlib_context_set_image( img2 );
w2 = imlib_image_get_width();
h2 = imlib_image_get_height();
imlib_context_set_image( img );
imlib_blend_image_onto_image( img2, 0, 0, 0, width, height, 0, 0, width, height );
//imlib_blend_image_onto_image( img2, 0, 0, 0, w2, h2, 0, 0, w1, h1 );
// #E == BLENDING 1 =========================
// setting context
imlib_context_set_image( img );
imlib_context_set_display( display );
imlib_context_set_visual( DefaultVisualOfScreen(screen) );
imlib_context_set_colormap( DefaultColormapOfScreen(screen) );
imlib_context_set_drawable( pixmap );
// render image into pixmap
imlib_render_image_on_drawable_at_size( 0, 0, width, height );
// set pixmap as background
XSetWindowBackgroundPixmap( display, root, pixmap );
// clear window
XClearWindow( display, root );
XFlush( display );
// free...
XFreePixmap( display, pixmap );
imlib_context_set_image( img );
imlib_free_image();
imlib_context_set_image( img2 );
imlib_free_image();
// close display
XCloseDisplay( display );
return 0;
}
It's changing wallpaper, but I want to blend this two images with custom alpha, I mean, something like this: How to blend two image
So, how to set image transparency for blending operation in Imlib?
Compile with: gcc main.c -lX11 -lImlib2