On Wed, Nov 30, 2005 at 09:20:50AM -0600, Nathan Ingersoll said: > If you draw a white rect on the destination image before copying the source > image, does it still have the same effect?
No. With this snippet
imlib_context_set_image(image);
// imlib_image_set_has_alpha(0);
int w = imlib_image_get_width();
int h = imlib_image_get_height();
Imlib_Image buffer = imlib_create_image(w, h);
imlib_context_set_color(255, 255, 255, 255);
imlib_context_set_image(buffer);
imlib_image_fill_rectangle(0, 0, w, h);
imlib_blend_image_onto_image(image, 0, 0, 0, w, h, 0, 0, w, h);
imlib_context_set_image(image);
imlib_free_image();
imlib_context_set_image(buffer);
I get the attached image :/
I'm convinced I'm doing something wrong but for the life of me I can't
spot it.
I've attached my sample program as well just in case anybody else can
see what horrendous errors I'm perpetrating. Apologies for the C++-isms.
Simon
<<attachment: alpha_white.jpg>>
/* standard headers */
#include <X11/Xlib.h>
#include <Imlib2.h>
#include <stdio.h>
#include <string.h>
/* main program */
int main(int argc, char **argv)
{
/* an image handle */
Imlib_Image image;
/* if we provided < 2 arguments after the command - exit */
if (argc != 3) {
fprintf(stderr,"Usage: imlib2convert <input image> <output image>\n");
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);
/* imlib_image_set_has_alpha(0); */
int w = imlib_image_get_width();
int h = imlib_image_get_height();
Imlib_Image buffer = imlib_create_image(w, h);
imlib_context_set_color(255, 255, 255, 255);
imlib_context_set_image(buffer);
imlib_image_fill_rectangle(0, 0, w, h);
imlib_blend_image_onto_image(image, 0, 0, 0, w, h, 0, 0, w, h);
imlib_context_set_image(image);
imlib_free_image();
imlib_context_set_image(buffer);
/* Failed attempt at manually setting alpha
DATA32 * data = imlib_image_get_data();
int x, y;
for (x=0; x<w; x++) {
for (y=0; y<h; y++) {
*data |= (255 << 24);
data++;
}
}
*/
/* 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]);
imlib_free_image();
} else {
fprintf(stderr,"Couldn't load image %s\n", argv[1]);
}
return 0;
}
