Performance of reading from Jpeg

Marcelo Fern?ndez wrote:

Dave Angel wrote:

I'm writing a wxPython application that displays jpeg images in two > frames. Currently, it's a single image at a time, but I will be doing > multiple ones. <snip>...
     self._img = wx.Image(self.fname, wx.BITMAP_TYPE_ANY) <snip>...

Just to add a comment... If the application (and its use case) allows it, you could make an "image cache" in a background thread/process while the user is watching some image in foreground. This is very common in image viewers, which preloads the next (one or two) images in the viewing list.

Regards
Marcelo
  -- Marcelo F. Fernández

Thanks to all of you for your suggestions. It helps to put it all in perspective.

Since the real problem is one of latency, the image cache would seem to be the most promising. I'm already planning to cache the thumbnails I'll be creating for a scrolling window. But at 30mb per, I can't cache too many of the main Image. So the preload makes lots of sense. Some questions, though, please.

If I did the speculative image load in the GUI thread, I'd be blocking events while it's loading. Is there any way to get periodic control during the load (Image constructor) so I can keep the GUI alive, like you'd do with a long-running calculation? I believe in wxPython, this would involve calls to wx.App.Yield().

If I do it in a separate thread (as you suggest), do you know that calls to Image constructor are safe? I understand that some things are unsafe outside of the GUI thread, and that can depend on the platform, but I don't see any definitive list. And similarly to the Yield question, it'd be very nice to get control periodically, so that if it turns out that this is the wrong image, I can abort the process and get busy on the right one. I know I could accomplish that by killing the thread (by calling the system function directly), but won't because I'd undoubtedly risk leaking some system resources. As far as I can tell, I can't even suspend the thread through well-behaved Python code.

I could also do some experiments with preprocessing the images to have a second set of low-res ones. I'll have to see how bad it'd look to display a low-res image (magnified during the Image.Scale call) turn later into the real one. I could process the real image in an idle event, so that if they go rapidly through the list, the real ones don't get loaded until they slow down.

Does wxPython provide any way to get the thumbnail image out of a jpeg file?

Hi Dave,

Marcelo Fern?ndez wrote:

Dave Angel wrote:

I'm writing a wxPython application that displays jpeg images in two >
frames. Currently, it's a single image at a time, but I will be doing >
multiple ones. <snip>...
self._img = wx.Image(self.fname, wx.BITMAP_TYPE_ANY) <snip>...

Just to add a comment... If the application (and its use case) allows it,
you could make an "image cache" in a background thread/process while the
user is watching some image in foreground. This is very common in image
viewers, which preloads the next (one or two) images in the viewing list.

Regards
Marcelo
-- Marcelo F. Fernández

Thanks to all of you for your suggestions. It helps to put it all in
perspective.

Since the real problem is one of latency, the image cache would seem to be
the most promising. I'm already planning to cache the thumbnails I'll be
creating for a scrolling window. But at 30mb per, I can't cache too many of
the main Image. So the preload makes lots of sense. Some questions,
though, please.

If I did the speculative image load in the GUI thread, I'd be blocking
events while it's loading. Is there any way to get periodic control during
the load (Image constructor) so I can keep the GUI alive, like you'd do with
a long-running calculation? I believe in wxPython, this would involve calls
to wx.App.Yield().

If I do it in a separate thread (as you suggest), do you know that calls to
Image constructor are safe? I understand that some things are unsafe
outside of the GUI thread, and that can depend on the platform, but I don't
see any definitive list. And similarly to the Yield question, it'd be very
nice to get control periodically, so that if it turns out that this is the
wrong image, I can abort the process and get busy on the right one. I know
I could accomplish that by killing the thread (by calling the system
function directly), but won't because I'd undoubtedly risk leaking some
system resources. As far as I can tell, I can't even suspend the thread
through well-behaved Python code.

I could also do some experiments with preprocessing the images to have a
second set of low-res ones. I'll have to see how bad it'd look to display a
low-res image (magnified during the Image.Scale call) turn later into the
real one. I could process the real image in an idle event, so that if they
go rapidly through the list, the real ones don't get loaded until they slow
down.

Does wxPython provide any way to get the thumbnail image out of a jpeg file?

For some answers, you may look at my implementation of ThumbnailCtrl
in wx.lib.agw or here:

http://svn.wxwidgets.org/viewvc/wx/wxPython/3rdParty/AGW/agw/thumbnailctrl.py?view=markup

It uses threads to load images using PIL, and it also generates thumbnails.

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.alice.it/infinity77/

···

On Wed, Apr 22, 2009 at 2:12 PM, Dave Angel wrote:

Dave Angel wrote:

I could also do some experiments with preprocessing the images to have a second set of low-res ones.

along these lines: I don't know if PIL support it, but in theory, you can read just the "DC" signal from a jpeg, and get essentially a 1/8 x 1/8 scale version of the image -- with very little processing. That might be a way to get a low-res version fast.

Does wxPython provide any way to get the thumbnail image out of a jpeg file?

I don't think so, but PIL might, or one of the other image processing packages for Python

-CHB

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Dave Angel wrote:

If I do it in a separate thread (as you suggest), do you know that calls to Image constructor are safe? I understand that some things are unsafe outside of the GUI thread, and that can depend on the platform, but I don't see any definitive list.

PIL Images should be safe as long as you take care to not modify a Image at the same time that another thread is accessing or modifying the same image. wx.Image should probably be the same although I don't know if that has been tested/verified or not. Converting to a wx.Bitmap on the other hand must be done in the gui thread because it needs access to the display device.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!