Main index > Usage problems > Problem with load_image example [CLOSED]

By dana_w (User), on Thu Aug 18 19:23:18 2005: Problem with load_image example [CLOSED].

I have been working my way through the on-line examples and can?t seem to get load_image and blend to work.

The window opens but nothing is displayed. I have verified that an image was successfully created and no errors occur.

0 >>> window_resize 100 100
command 0 ok: window_resize 100 100
1 >>> window_reset managed
command 1 ok: window_reset managed
2 >>> window_set_transparency 1
command 2 ok: window_set_transparency 1
3 >>> load_image out.png
command 3 ok: new image 2
4 >>> blend_image_onto_image 2 0 0 0 100 100 0 0 100 100
command 4 ok: blend_image_onto_image 2 0 0 0 100 100 0 0 100 100
5 >>> window_show
command 5 ok: window_show
6 >>> free_image 2
command 6 ok: free_image 2


I?ve also noticed that loading commands from a file don?t seem to produce the same results as typing commands into the shell.

Typing these commands gives me a nice red square in the middle of a transparent window.

0 >>> window_resize 100 100
command 0 ok: window_resize 100 100
1 >>> window_reset managed
command 1 ok: window_reset managed
2 >>> window_show
command 2 ok: window_show
3 >>> window_set_transparency 1
command 3 ok: window_set_transparency 1
4 >>> context_set_color 255 0 0 200
command 4 ok: context_set_color 255 0 0 200
5 >>> image_fill_rectangle 25 25 50 50
command 5 ok: image_fill_rectangle 25 25 50 50

Running this script gives me a pale window with no red square and a light blue background.

#!/usr/bin/adesklets -f
window_resize 100 100
window_reset managed
window_show
window_set_transparency 1
context_set_color 255 0 0 200
image_fill_rectangle 25 25 50 50
pause 10

Adesklets looks very interesting. I have been struggling with Xlib and imlib2 for a while now and this could sure make my life easier.

Dana

By syfou (Core Developer & Desklet Author), on Thu Aug 18 21:27:08 2005.

dana_w wrote:


[I] can?t seem to get load_image and blend to work.

Grr... I do not know how I managed to get it wrong in the documentation, but I did (while being positively sure I cross-checked the examples). I really wondered how it stayed that way for so many months. :oops:

In you first code snipset, the problem is simply that it do not copy the image alpha channel information back to the foreground image during the blend (first parameter should be one, not zero), which cause the foreground to be interpreted as purely transparent (the default alpha for the whole foreground image is 0) when displayed with window transparency set to true.

As for the second problem, well, keep in mind that direct piping of commands into the interpreter do not fit that well with regular X11 use; pause brutally freeze the interpreter, and no window refresh of any kind will occur during its execution: it is an internal debugging convenience, really. This explains why it is possible to have all sort of buggy X11 display using it. ;-) In fact, scripts similar to yours are not usually used under X11, but more for headless processing of images (it is generally more simple to use the Python module for interactive display). Anyway, here is a rough but functionnal POSIX compliant shell script that replicate yours:

Code:


#! /bin/sh

# Variables
#
IMAGE=redbox.png
KEEPIMAGE=false
TIMEOUT=10

# Auto image remove on exit.
#
trap -- "$KEEPIMAGE && rm $IMAGE" EXIT

# First, create the image 
#
(
(
cat <<EOF
echo Image creation
window_resize 100 100
context_set_color 255 0 0 200
image_fill_rectangle 25 25 50 50
save_image $IMAGE
EOF
) | adesklets ':' 
)

# Then, reload it, just for experimentation' sake.
#
(
cat <<EOF
echo Image display for $TIMEOUT seconds
window_resize 100 100
window_reset managed
load_image $IMAGE
blend_image_onto_image 2 1 0 0 100 100 0 0 100 100
window_set_transparency 1
window_show
EOF
sleep $TIMEOUT
echo 'quit'
) | adesklets :



Yours,

By dana_w (User), on Thu Aug 18 21:43:16 2005: Thanks for the rabid response.

I?ll continue my exploration in the morning. I am a very reluctant programmer and Adesklets looks like a great way for me to use imlib2 while avoiding Xlib.

Thanks again,
Dana


adesklets is proud to be hosted on:

SourceForge.net Logo

Back to adesklets.sf.net.