[visionegg] Re: Help request : Image loading latency running VE in Windows
- From: Andrew Straw <astraw@xxxxxxxxxxx>
- To: visionegg@xxxxxxxxxxxxx
- Date: Sun, 21 Jan 2007 16:20:55 -0800
Ted Strauss wrote:
> We're having the following problem:
> -- When switching background images, VE hangs for 10-30 seconds (on 2
> year old Macs and PCs).
> -- All JPGs (range from 100k-600k) are loaded to objects when the
> script starts like this:
> names = os.listdir("bgPics/")
> _i=0
> bgTextureList = {}
> for name in names:
> if re.compile(".*jpg").match(str(name)):
> bgTextureList[_i] = Texture( os.path.join("bgPics/"+name))
> _i+=1
>
> -- The object being used to display the background is this:
> bg = TextureStimulus(texture = bgTextureList[0],
> size = ( config.VISIONEGG_SCREEN_W,
> config.VISIONEGG_SCREEN_H), #bg_texture.size,
> max_alpha = 0.5,
> shrink_texture_ok=1)
>
> -- Then the call to switch the background image is this:
> bg.parameters.texture = bgTextureList[var_k]
>
> -- This all works fine on a new MacBook, but hangs on an 2 y.o. XP,
> Win2k, and OS X machines.
>
> Any advice would be appreciated. Thanks
Hi Ted,
The following suggestions moves the JPEG decoding step to the initial
startup (rather than on-the-fly).
bgTexelData = []
_i=0
for name in names:
if re.compile(".*jpg").match(str(name)):
# load .jpg image using PIL
im = Image.Image(os.path.join("bgPics/"+name))
# decode JPEG into raw bytes
byte_string = im.tostring('raw','RGB',0,-1)
# store as Numeric array
imdata = Numeric.fromstring(byte_string,Numeric.UInt8)
imdata = Numeric.reshape(imdata,(im.size[1],im.size[0],3))
bgTexelData.append( imdata )
_i+=1
Get the OpenGL texture object using the following:
texture_object = bg.parameters.texture.get_texture_object()
Then, when you want to switch the image, call:
texture_object.put_sub_image( bgTexelData[vak_k] )
Another option is to load all the images into video RAM before beginning
(creating a new TextureObject instance for each image). This is a little
more involved -- let me know if demo could would be useful for that, and
I'll try write one up.
Cheers!
Andrew
======================================
The Vision Egg mailing list
Archives: http://www.freelists.org/archives/visionegg
Website: http://www.visionegg.org/mailinglist.html
Other related posts: