Discussion:
[Fluxbox-users] using imlib2 to display images doesn't seem to work correctly
Mike Ranweiler
2011-01-20 17:00:35 UTC
Permalink
I've found an odd issue where some images don't display using imlib_render_image_on_drawable() on fluxbox, but work fine elsewhere. I found this using Fedora 14 and basically just using a modified version of the imlib test code in the documentation from Carsten Haitzler [1]. What happens is just an empty (black) window is displayed, imlib_image_get_height(), etc, return the correct results, but the image isn't displayed. I don't know if this is a fluxbox problem or imlib, really, but I thought I'd start here.

Many larger images (like from my camera) work fine, but the problem can be recreated with these:
Loading Image...
Loading Image...

I don't think it correlates just to the image size, but I don't know why some work - just that it seems that images larger than the standard 2meg cache work fine (even if the cache is disabled).

I tried updating imlib to 1.4.4, I didn't see any changes to fluxbox that lead me to a rebuild past 1.1.1 that's in Fedora. Let me know, I can try that.

Using imlib_render_image_on_drawable_at_size() using the size of the image does always display the image correctly, it's in the test case after the failing call. I tried turning off the cache, both in the small test application and in fluxbox (src/FbTk/ImageImlib2.cc), but that doesn't make any difference. I'm typically doing this under VNC, it works fine on mwm and the Fedora-standard gnome/metacity desktop - I only see this problem using the testcase on fluxbox.

I've included a test case where you provide an image file and a display time, it first tries with imlib_render_image_on_drawable(), and then with imlib_render_image_on_drawable_at_size(). With fluxbox and the images above it always just gives a black window with imlib_render_image_on_drawable(), and then the image when it imlib_render_image_on_drawable_at_size().

Anyone have any ideas? It's confusing to me, I'm not sure if I'm missing something I should be doing or where a bug might be. Both functions just call __imlib_RenderImage with slightly different parameters, I checked that __imlib_RenderImage is not simply exiting because of a 0 dw/dh.

It may be unrelated, but I initially had difficulties getting fbdesk to work correctly. Certainly all the icon image files I tried to use with fbdesk fail to display with this test case, but again, it could be completely unrelated.

Thanks much,

Mike

1. http://docs.enlightenment.org/api/imlib2/html/

Compile with gcc -o testcase testcase.c `imlib2-config --cflags` `imlib2-config --libs` as per the docs above.


/* This is based on the code provided in the documentation.
* See either doc/index.html or online at:
* http://docs.enlightenment.org/api/imlib2/html/
*
* This package is under a BSD-like license, included below:
*
* Copyright (C) 2000 Carsten Haitzler and various contributors (see AUTHORS)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies of the Software and its Copyright notices. In addition publicly
* documented acknowledgment must be given that this software has been used if no
* source code of this software is made available publicly. This includes
* acknowledgments in either Copyright notices, Manuals, Publicity and Marketing
* documents or any documentation provided with any product containing this
* software. This License does not apply to any software that links to the
* libraries provided by this software (statically or dynamically), but only to
* the software provided.
* /

/* include X11 stuff */
#include <X11/Xlib.h>
/* include Imlib2 stuff */
#include <Imlib2.h>
/* sprintf include */
#include <stdio.h>

/* some globals for our window & X display */
Display *disp;
Window win;
Visual *vis;
Colormap cm;
int depth;

/* the program... */
int main(int argc, char **argv)
{
/* image variable */
Imlib_Image image;
/* the height and width of the window */
int h, w;
/* arguments */
char imagename[256];
int sleeptime;

if (argc !=3) {
printf("This test takes 3 arguments, an image file and a time to "
"display the image.\n");
return 1;
}
snprintf(imagename, 256, "%s", argv[1]);
sleeptime = atoi(argv[2]);

/* 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));
win = XCreateSimpleWindow(disp, DefaultRootWindow(disp),
0, 0, 640,
480, 0, 0, 0);
XMapWindow(disp, win);

/* set our cache to 0 so it's unused */
imlib_set_cache_size(0);
/* set the maximum number of colors to allocate for 8bpp and less to 128 */
imlib_set_color_usage(128);
/* dither for depths < 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);


/* load the image */
image = imlib_load_image(imagename);
if (!image) {
printf("image didn't load\n");
return -1;
}
imlib_context_set_image(image);

imlib_render_image_on_drawable(0, 0);
sleep(sleeptime);
imlib_render_image_on_drawable_at_size(0, 0, imlib_image_get_width(),
imlib_image_get_height());
sleep(sleeptime);
imlib_free_image_and_decache();

return 0;
}
--
Mike Ranweiler
Mathias Gumz
2011-01-20 18:54:59 UTC
Permalink
hello,
Post by Mike Ranweiler
I've found an odd issue where some images don't display using imlib_render_image_on_drawable() on fluxbox, but work fine elsewhere.
it is a bit unclear to me, what problem you are describing:

a) you feed pictures into fluxbox (eg. to render buttons on the
windows) and fluxbox is not able to draw them correctly.

b) you feed pictures into your own program and your own program is not
able to render these pictures onto a canvas (drawable). amd, as a
conicidence, you happen to experience this when you run your program
inside fluxbox.
Post by Mike Ranweiler
http://fluxbox.org/screenshots/screenshots_full/screenshot_bobbens.png
http://fluxbox.org/screenshots/screenshots_full/screenshot_zan.png
what are these pictures showing? or do you feed these pictures into
your program, guessing that you really mean b) and not a)?
Post by Mike Ranweiler
Using imlib_render_image_on_drawable_at_size() using the size of the image does always display the image correctly, it's in the test case after the failing call.  I tried turning off the cache, both in the small test application and in fluxbox (src/FbTk/ImageImlib2.cc), but that doesn't make any difference.  I'm typically doing this under VNC, it works fine on mwm and the Fedora-standard gnome/metacity desktop - I only see this problem using the testcase on fluxbox.
you disabled the imlib2-cache in fluxbox to achieve what effect in
your app (again guessing, that you want to solve b))?

maybe you can clarify your problem a little bit better.

best regards,
mathias
--
  [uid] mathias gumz [mail] akira at fluxbox dot org [pgp] 1024D/F6F6B18C
  [www] http://www.darkshed.net/ [irc] ak|ra (#fluxbox at freenode.org)
Mike Ranweiler
2011-01-20 20:38:19 UTC
Permalink
Post by Mathias Gumz
hello,
Post by Mike Ranweiler
I've found an odd issue where some images don't display using imlib_render_image_on_drawable() on fluxbox, but work fine elsewhere.
a) you feed pictures into fluxbox (eg. to render buttons on the
windows) and fluxbox is not able to draw them correctly.
b) you feed pictures into your own program and your own program is not
able to render these pictures onto a canvas (drawable). amd, as a
conicidence, you happen to experience this when you run your program
inside fluxbox.
Sorry for not stating it clearly, appreciate the quick response. It's b
- application doesn't render correctly using the imlib2 library. I
attached the test program as an example.
Post by Mathias Gumz
Post by Mike Ranweiler
http://fluxbox.org/screenshots/screenshots_full/screenshot_bobbens.png
http://fluxbox.org/screenshots/screenshots_full/screenshot_zan.png
what are these pictures showing? or do you feed these pictures into
your program, guessing that you really mean b) and not a)?
Post by Mike Ranweiler
Using imlib_render_image_on_drawable_at_size() using the size of the image does always display the image correctly, it's in the test case after the failing call. I tried turning off the cache, both in the small test application and in fluxbox (src/FbTk/ImageImlib2.cc), but that doesn't make any difference. I'm typically doing this under VNC, it works fine on mwm and the Fedora-standard gnome/metacity desktop - I only see this problem using the testcase on fluxbox.
you disabled the imlib2-cache in fluxbox to achieve what effect in
your app (again guessing, that you want to solve b))?
Yes, for no real good reason. It seemed like there could be an issue
with caching, so this seemed like something quick to try.
Post by Mathias Gumz
maybe you can clarify your problem a little bit better.
Did that help?

Thanks,

Mike
Post by Mathias Gumz
best regards,
mathias
--
Mike Ranweiler
Loading...