Fast image loading

Hello,
I am trying to write a photo browsing application using SDL, but I found one
serious problem.
Loading jpeg image by SDL_Image is very slow.
Applications like gqview can display image much faster.
I was browsing both SDL_Image and gqview code, then I tried to learn how to
use raw jpeglib.
I was able to disable “high quality” settings (which SDL_Image has
hardcoded), but still speed was not good.
Is there a way to load image in lower resolution, like most photo browsing
applications do?
Do you know any SDL-based library which can do it?–
Free Software - find interesting programs and change them
NetHack - meet interesting creatures, kill them and eat their bodies
Usenet - meet interesting people from all over the world and flame them
Decopter - unrealistic helicopter simulator, get it from
http://decopter.sf.net

SDL_image probably isn’t a good place to do this (although maybe it could
be?), but some image formats often allow for the inclusion of 'preview’
versions of the image, built-into the image file itself. I forget if JPEG
does (probably), and perhaps that’s what gqview is showing you.
(You didn’t mention if this was when viewing the full image, or a thumbnail
preview in a browser/gallery kind of view.)

Additionally, JPEGs can be saved in a ‘progressive’ mode, where you get
the entire image’s area more quickly. It’s useful on slow connections and/or
for very large images – in a browser, for example.

Normally, you see more and more scanlines of the image at 100% quality.
With progressive, you see all of the image, and greater and greater resolution.
(Wikipedia could probably explain it better – I’m tired and need food ;^) )

An image library for SDL that exposed things like:

  • Built-in thumbnail
  • Perhaps some desktop/OS-specific thumbnail (let the OS handle
    generation and storage of thumbnails, w/o your app having to do it again)
  • Image at certain stages of quality, if applicable
    (e.g., "show me the lowest quality rendering of the JPEG, which will
    take 1/16th the time to decompress… I’m only showing it at 64x64px! :slight_smile: )
  • Other metadata (creation date, camera stats, comments, etc.)

would be nice. Perhaps an “SDL_Image_Pro”, since 99% of the time in SDL,
programmers don’t need things like the above. But people like you and I
(for Tux Paint) could take advantage of some of it. ;)On Sun, Jul 22, 2007 at 03:59:25AM +0200, Jacek Poplawski wrote:

Hello,
I am trying to write a photo browsing application using SDL, but I found one
serious problem.
Loading jpeg image by SDL_Image is very slow.
Applications like gqview can display image much faster.
I was browsing both SDL_Image and gqview code, then I tried to learn how to
use raw jpeglib.
I was able to disable “high quality” settings (which SDL_Image has
hardcoded), but still speed was not good.
Is there a way to load image in lower resolution, like most photo browsing
applications do?


-bill!
bill at newbreedsoftware.com
http://www.newbreedsoftware.com/

Loading jpeg image by SDL_Image is very slow.
Applications like gqview can display image much faster.
I was browsing both SDL_Image and gqview code, then I tried to learn how to
use raw jpeglib.
I was able to disable “high quality” settings (which SDL_Image has
hardcoded), but still speed was not good.
Is there a way to load image in lower resolution, like most photo browsing
applications do?

Some ideas:

  • Preloading next and previous picture, so they are already present when
    needed or other caching strategies.
  • Generate thumbnails in advance.
  • Load images in a background thread, so the application stays responsive and
    delays don’t hurt.

Do you know any SDL-based library which can do it?

No.

UliOn Sunday 22 July 2007 03:59:25 Jacek Poplawski wrote:

I am already using threads and cache.
But please try to load 6megapixel photo into SDL_Surface then generate
OpenGL texture from it.
That takes time.
I need to load image in lower quality/resolution.On 7/22/07, Ulrich Eckhardt wrote:

Some ideas:

  • Preloading next and previous picture, so they are already present when
    needed or other caching strategies.
  • Generate thumbnails in advance.
  • Load images in a background thread, so the application stays responsive
    and
    delays don’t hurt.


Free Software - find interesting programs and change them
NetHack - meet interesting creatures, kill them and eat their bodies
Usenet - meet interesting people from all over the world and flame them
Decopter - unrealistic helicopter simulator, get it from
http://decopter.sf.net

Hi Bill!

SDL_image probably isn’t a good place to do this (although maybe it could
be?), but some image formats often allow for the inclusion of 'preview’
versions of the image, built-into the image file itself. I forget if JPEG
does (probably), and perhaps that’s what gqview is showing you.

Yes, that’s exactly what I need.
I don’t know how to load “preview version” with jpeglib (example?).
I tried to look into gqview, but it just uses another gtk-based library.

Additionally, JPEGs can be saved in a ‘progressive’ mode, where you get

the entire image’s area more quickly. It’s useful on slow connections
and/or
for very large images – in a browser, for example.

It may be good idea to use this mode when displaying full-size image, but
for displaying whole directory of images I need full picture, because I am
generating OpenGL textures from them.

An image library for SDL that exposed things like:

  • Built-in thumbnail
  • Perhaps some desktop/OS-specific thumbnail (let the OS handle
    generation and storage of thumbnails, w/o your app having to do it
    again)
  • Image at certain stages of quality, if applicable
    (e.g., "show me the lowest quality rendering of the JPEG, which will
    take 1/16th the time to decompress… I’m only showing it at 64x64px!
    :slight_smile: )
  • Other metadata (creation date, camera stats, comments, etc.)

OK, so we all need this library. But can you point me to any examples or
documentation so I could at least try to implement these features? :slight_smile:

Should I just set low-quality flags in libjpeg functions?
But what about resolution?
It’s not clear to me how to configure it in libjpeg.On 7/22/07, Bill Kendrick wrote:


Free Software - find interesting programs and change them
NetHack - meet interesting creatures, kill them and eat their bodies
Usenet - meet interesting people from all over the world and flame them
Decopter - unrealistic helicopter simulator, get it from
http://decopter.sf.net

Jacek Poplawski wrote:On 7/22/07, Ulrich Eckhardt doomster@knuut.de wrote:

Some ideas:
- Preloading next and previous picture, so they are already present
when
needed or other caching strategies.
- Generate thumbnails in advance.
- Load images in a background thread, so the application stays
responsive and
delays don't hurt.

I am already using threads and cache.
But please try to load 6megapixel photo into SDL_Surface then generate
OpenGL texture from it.
That takes time.
I need to load image in lower quality/resolution.

The following gets progressively further away from SDL:

I don’t think SDL_image exposes these for jpeg, but you want to set these
jpeg parameters:

cinfo.scale_num
cinfo.scale_denom

the IJG jpeg decoder supports 1,2,4,8 for the denominator.

There are some mmx versions of the jpeg lib around, but IIRC they were
quite buggy.

If you want to squeeze the last bit of performance out of the thing you
are building,
you may want to take a look at Intel’s icc.

Intel’s performance primitives (IPP) used to have a jpeg decoder, but it
didn’t support
all types of jpegs at the time, which made it rather useless. That was
about 3 years ago.

NVidia has some sample code in their SDK to do the DCT on the GPU. Cool,
but incomplete
for a jpeg viewer.

Cheers,
Frank.


Need a break? http://criticalmass.sf.net/