Main index > Python programming > image caching

By ZeroDivide (Desklet Author), on Tue Mar 22 14:15:38 2005: image caching.

just noticed that instead of loading 2 of the same images from disk, an image cache is used.
This isn't really a problem if you don't modify the images, but if you want to tint, or draw on one of the images it will show up on the other.
I got around this by cloning the loaded image and then freeing the original.

Maybe a way to disable this caching would be a good thing to have.

By syfou (Core Developer & Desklet Author), on Tue Mar 22 15:14:02 2005.

That is precicely what image_set_changes_on_disk is for. You can read about Imlib2 caching mechanism in adesklets' documentation (see appropriate appendix on Imlib2: appendix C at the time of writing).

Warning: I initially forgot about it, and so I just included it recently... Hence, you will need adesklets 0.4.6 for this to work.

By ZeroDivide (Desklet Author), on Tue Mar 22 18:20:20 2005.

I probably did a piss poor job of explaining myself so im going to give it another shot.

If you load the same image from disk twice it seems like both of the image IDs you get end up pointing to the same image. So when you modify one of these images ( in memory, not on disk ), the other is also modified.

I tried using image_set_changes_on_disk() but its not really what im looking for. imlib_load_image_without_cache() might be useful but I didn't see it in the adesklets documentation.

Here is a quick example of what im talking about

Code:

#! /usr/bin/env python
from adesklets.commands import *
from time import time, sleep
from os.path import dirname

# wget http://adesklets.sourceforge.net/images/acpumon_thumb.jpg
#load image twice
image1=load_image(dirname(__file__)+'acpumon_thumb.jpg')
image2=load_image(dirname(__file__)+'acpumon_thumb.jpg')

#apply filter to image1 only
context_set_image(image1)
apply_filter('tint(alpha=128,red=0,green=200,blue=0);')

#setup window
image_w=image_get_width()
image_h=image_get_height()
window_resize(image_w,image_h*2)
window_show()

#display images one on top of the other
context_set_image(0)
blend_image_onto_image(image1,0,0,0,image_w,image_h,0,0,image_w,image_h)
blend_image_onto_image(image2,0,0,0,image_w,image_h,0,image_h,image_w,image_h)

sleep(99999)

By syfou (Core Developer & Desklet Author), on Tue Mar 22 18:57:25 2005, last edited on Tue Mar 22 19:22:01 2005.

Sorry, I failed understanding you the first time... Well, as you already know, you can 'break' this link between images by using appropriate calls to clone_image.

From your request, I also added load_image_without_cache to adesklets commands... I am not absolutely sure it will help from what I read, but at least you will be able to test it. If you want to have it right away, you can apply this patch to the adesklets-0.4.6 source tree (or just resync yourself to the public bk tree). Regards,

By ZeroDivide (Desklet Author), on Tue Mar 22 19:16:26 2005.

Thanks syfou, that patch seems to work perfectly :D


adesklets is proud to be hosted on:

SourceForge.net Logo

Back to adesklets.sf.net.