Hi,
we wrote an extension in C to Tk for aMSN which let us
to load animated gifs and we display each frame after a
delay with Tk_PhotoPutBlock. But when we have many
animated GIFs loaded it take many CPU power and we
would like to reduce it. To do that we would need a
function to know the visibility of the image. Not if it
is bind to a widget but if it is displayed in any
widget. Or maybe you have another idea to know that...
Thanks
Logged In: YES
user_id=72656
Does the 'image inuse' command suffice?
Note that you can control GIF index display at the Tcl level
with
'$image configure -index #'
It may be faster to let Tcl handle the transitions.
Logged In: YES
user_id=1212799
Thanks for the fast reply.
The image inuse command doesn't suffice since it tell us if
the image is used by a widget but not if it is showed. For
the "configure -index" I don't see any documentation on it
but after a quick look at Tk code I saw it was related with
GIF loading so I think it say to Tk to load the specified
frame but I didn't manage to make it work...
Logged In: YES
user_id=686750
Hi,
I'm also a developper on the aMSN project and I may know a
bit more about that.. I almost rewrote the whole anigif
extension (pure tcl) for Tk that uses the -index argument so I
know about that, but we actually dropped the anigif extension
in favor of TkCximage (one of my own extensions, made with
the help of lephilousophe, the guy who originaly posted this
support request)... It's an extension that does quite the same
thing as the Img extension, once loaded, any image of types
jpg/png/gif/bmp/tga is recognized by Tk.
When it comes to gif images, it will automatically detect
whether the gif is animated or not, if it is, it will automatically
set a timer, depending on the next frame's delay and in the
callback function, it will do a Tk_PhotoPutBlock of the next
frame and reset the timer for the frame that should come after.
It works great, the only problem is that when it comes to
aMSN (an MSN messenger clone : amsn.sf.net), a pretty big
application, and where users can send animated smileys, you
can chat with someone and get something like 100 of
animated smileys. This makes it do something like 100*10 =
1000 Tk_PhotoPutBlock calls per second (we suppose they
use 10 frames per second per image). and those calls will
occur even if no smiley is shown in the chat window (because
it's scrolled or whatever).
What we can do, for example, if we have the image inside a
label :
bind $label <Visibility> "setAnimation_depending_on_state %
s"
but that brings up two problems :
1 - if the image is inside a text widget, then we can only have
the visibility of the text widget even if the text is scrolled and
the image is not shown.
2 - we would have to wrap each image in a label and use
bindings each time we open an image.
3 - if we embed the image in labels, we will most probably
loose any alpha blending.
4- TkCximage extension should work "natively", which mean,
no modification to the Tcl code or anything.
Now.. a hack has been done by lephilousophe
we hook the Photo function for displaying the image (The Paint
function from the Tk Photo internals), so if it's mapped to the
screen, he will know and he will update the image with a
Tk_PhotoPutBlock, before calling the original paint function of
the Photo command.
This is an ugly hack which doesn't work for everyone and it
depends too much on Tk's internals instead of the public API.
This is why this post was originally made, it is to ask if there
is a way to do a bind <Visibility> for an image instead of a
window/widget, or do something that looks like it...
If we can't have it as an event, then it would be also interesting
to have a function or something like Tk_IsImageMapped so we
can know if the image is mapped to the screen, so we know if
we can do the Tk_PhotoPutBlock or if it's not necessary.
The "inuse" command only tells us if the image is embeded in
another widget, but we don't know which widget(s), if the
widget is visible or not, and if the image in the widget is visible
too.
Now, we're asking here for a solution to this problem,
something that might help us with this issue. We ask for help
because, since you know Tk better than us, you will most
probably see a solution that we won't be able to see.
Here's what I'm thinking (in preferred order) :
1- a function that notifies us when the image's visibility
changes (a bind for an image instead of restricting the bind
only to windows/widgets)
2- a function that tells us if the image is mapped to the screen
or not
3- a way to draw to the screen easily (in order to create a new
Image type instead of a new Photo type, and we won't need to
rewrite a paint procedure, letting Tk take care of all the
painting by providing it only with the RGBA to draw)
4- Any other solution that advanced Tk devels would see or
any undocummented function.
Please note that my friend lephilousophe made a mistake, this
tracker item should be a "Support Request", not a "Feature
Request", so if you could please re-assign it to the correct
tracker, that would be nice.
This also means that we're not asking for a new function/
feature in Tk 8.5, but a solution that will work on any 8.4
interpreter.
Thanks for reading this and I hope you understand the
situation better and that you'll eventually come up with a
solution.
KaKaRoTo