Image Loading Libraries (23)

1 Name: !WAHa.06x36 2005-08-06 19:44 ID:D0PZViy0

So, I've been working on an image viewer for Mac OS. This uses Quicktime to load its images. However, Quicktime is a bit limited when it comes to loading more obscure image formats, and it is also a royal pain in the ass to use.

So I was wondering what image loading libraries there are out there. So here's a thread for discussing image loading in general!

Personally, I wouldn't mind replacing Quicktime with something better. What I'd want is something is:

  • Fast. I mean, really fast. This means something that does NOT use IJG's libjpeg like everyone else. There are commercial JPEG loaders for Windows that are at least twice the speed of the IJG code, I know that much. What about open-source loaders? Is everyone just following the crowd and using libjpeg?
  • Lean. An image loading library will always be a bit bulky due to the need to support many formats, but I really don't want to include ten megabytes of ImageMagick in my program.
  • Some minor things, like supporting animgifs, multi-image formats (layers in Photoshop files), getting useful image property data, supporting progressive and interruptable loading, and being thread-safe.

I don't hold out much hope for anything like this actually existing, though.

2 Name: dmpk2k!hinhT6kz2E 2005-08-07 02:17 ID:Heaven

I was going to suggest Imlib 1 or 2, but neither is thread-safe.

3 Name: !WAHa.06x36 2005-08-07 10:54 ID:D0PZViy0

I looked a bit at Imlib, but it seems to just use the standard external dependencies and doesn't seem to make any attempt to be fast at loading. Also, it keeps mentioning X and I wonder if it's not too tightly tied into the X libraries to be useful.

4 Name: dmpk2k!hinhT6kz2E 2005-08-07 15:14 ID:Heaven

I don't know about that. Imlib was written by the Enlightenment folks, and we know just how crazy they are about performance.

Mind you, loader_jpeg.c doesn't look particularly special in any way (other than having almost no comments). What are they bragging about? Performance of all the other operations?

5 Name: !WAHa.06x36 2005-08-07 21:03 ID:D0PZViy0

> What are they bragging about? Performance of all the other operations?

Sure looked that way to me when I looked at it. Loading seems to be mostly done by external libraries...

Why is it that everybody uses libjpeg? I mean, it's a reference implementation, isn't it? It's not a bad reference implementation, but it sure can (and has) been improved on. Why does everyone think there's just the one way of loading JPEGs?

6 Name: Sling!XD/uSlingU 2005-08-07 23:56 ID:Qxgvaaqa

From what I gathered a few years back, LIBJPEG was the only one that was free, complete and portable. They were other implementations but they were either incomplete, unreliable, pinned to one OS and/or commercial/not free.
Has this changed nowadays?
Which other implementation is free, complete and portable?

7 Name: dmpk2k!hinhT6kz2E 2005-08-08 02:38 ID:tfkoG4cb

I think the reason libjpeg is used is because it's mature and trusted. When was the last time it contained a bug or overflow?

That said, you might find Epeg interesting, if only for ideas. It gains a speedup by only considering necessary pixels.

I also came across this: http://openil.sourceforge.net/ . I'm a bit confused though because I read somewhere that its dependencies to libjpeg were removed, but the source definitely uses libjpeg.

8 Name: !WAHa.06x36 2005-08-08 18:35 ID:D0PZViy0

Well, for me, all pixels are necessary. libjpeg already can do fast loading of scaled-down versions by not using all data. But it's of no use to me.

DevIL doesn't seem very threadsafe. It also says:

> Choose whether to use the Intel Jpeg Library or libjpeg.

The Intel Jpeg Library is suppoed to be very good, and it used to be free. I wanted to use it once back in the day, and found out it was no longer free. And of course, I doubt it'd do much good on a Mac.

9 Name: dmpk2k!hinhT6kz2E 2005-08-09 15:47 ID:3Cmw4z3F

I just ran xzgv, which uses libjpeg, through a directory containing 750 jpegs, with a range of 400x300 to 1600x1400 pixels. It took 105 seconds to fully render all of them (so, about 7fps) on a 1.6GHz Athlon.

If you preload images and also allow operations to be interrupted, surely this would fast enough? It's a far cry from a certain viewer, but it's not that bad.

If you're really slick, you could switch to linearly scaled-up images that were loaded with some variant of epeg hackery once you're going faster than libjpeg can handle.

10 Name: dmpk2k!hinhT6kz2E 2005-08-10 08:45 ID:4BO2PLRd

759 images (95% jpg, 3% png, 2% gif). Precached the files on each OS. Average of three runs:

xzgv (libjpeg 6.2): 90sec  (8.4 fps)
acdsee 2.43: 67sec (11.3 fps)

11 Name: !WAHa.06x36 2005-08-10 12:41 ID:4dKup1hZ

Interesting. How about a test run with only really, really big JPEGs for comparison, to see how much is taken up by the actual JPEG decompression?

12 Name: dmpk2k!hinhT6kz2E 2005-08-11 04:13 ID:Heaven

The results this time were strange.

200 JPEGs, 157KB-4719KB, 1875x1688-6030x8634.

     xzgv: 103sec (1.94 fps)

acdsee (low): 110sec (1.81 fps)

xzgv (cj): 114sec (1.75 fps)

acdsee (high): 137sec (1.46 fps)

xzgv is normal mode, while xzgv (cf) uses the --careful-jpeg option. acdsee (low) is one cluster of datapoints (112sec, 110sec, 109sec), while acdsee (high) is another (137sec, 140sec, 135 sec).

There is no difference between acdsee low and high, other than a few minutes between the two runs. While xzgv was always consistent, acdsee was not. I suspect the variation was a result of Window's CPUfreq governor lowering the frequency to cool the CPU, although I haven't confirmed that.

13 Name: dmpk2k!hinhT6kz2E 2005-08-11 04:14 ID:Heaven

Whoops.

         xzgv: 103sec (1.94 fps)
acdsee (low): 110sec (1.81 fps)
xzgv (cj): 114sec (1.75 fps)
acdsee (high): 137sec (1.46 fps)

14 Name: dmpk2k!hinhT6kz2E 2005-08-11 04:18 ID:Heaven

I suppose this supports "interface is everything"?

15 Name: !WAHa.06x36 2005-08-11 13:35 ID:4dKup1hZ

Now, that really is surprising. I would agree with the conclusion in >>14, then.

Well, one more factor: Were these images loaded and shown pixel-for-pixel, or were they scaled to fit on screen? Was the behaviour the same for both programs?

16 Name: dmpk2k!hinhT6kz2E 2005-08-11 14:24 ID:Heaven

Both displayed fully-rendered unscaled images with no post-processing. As far as I can tell, the behaviour of the two was as identical as could be made. I even disabled acdsee's cache-behind, although it should have no real effect.

I didn't have any programs in the background, other than the normal daemons/services, which were minimal (XFCE and XP).

That said, I cannot guarantee that the images were fully-rendered, given that I wasn't scrolling around in them. However, xzgv spent a long time decoding all the right images (some of them took 4sec on both viewers), so I doubt it was cutting corners.

xzgv's screen space was ~10% smaller than acdsee's, due to the WM (both were windowed). If I repeat this, I'll try to get it fullscreen.

I did have one acdsee run that was 90sec, but I think I mistimed it. Assuming that it was real, 90sec still is not as much faster as I would have expected.

17 Name: Mr VacBob!JqK7T7zan. 2005-08-16 00:23 ID:nQox7Kcy

You might want to try FFmpeg. If you disable all the encoders and most of the other stuff, dead code stripping should make it reasonably small, and it can actually use Altivec for JPEG decoding.

18 Name: Mr VacBob!JqK7T7zan. 2005-08-16 00:26 ID:nQox7Kcy

> Both displayed fully-rendered unscaled images with no post-processing.

What about the YUV->RGB upsample and matrix multiplying? That's kind of postprocessing.

Unless it uses Xv/OpenGL, I guess.

19 Name: !WAHa.06x36 2005-08-16 15:31 ID:4dKup1hZ

>>17

Hmm, that does sound somewhat tempting. I'll have to look into it.

20 Name: !WAHa.06x36 2005-08-23 10:30 ID:D0PZViy0

Ok, after considering this, I have come to some new conclusions.

One is that I do not wish to keep using Quicktime, because it's a pain in the ass. That means I would like an image loading library that loads both the popular formats (JPEG, PNG, GIF), and as many less popular formats as possible (I've personally got files in PSD, TIFF, BMP, PCX, TGA and ILBM, and I'm sure there are several other that it would be nice to support). I've given up on the idea of finding a fast library (unless I start splicing in code from FFmpeg - not an impossible idea), so now I just want something that is not too huge and loads a large number of formats. Also, still threadsafe.

Another feature that would be nice to have, but which I may also have to give up on in, is to load JPEGs into YUV data and letting OpenGL handle that on its own (I've not checked how likely this is to work, but it would save on time and memory).

ImageMagick is the obvious candidate, I guess, if it will slim down enough if you don't use the image processing features. I'll need to do some experiments on that. However, I don't know if it can do the YUV trick.

Any other candidates? I looked at DevIL but decided that the project is dead, and that I don't much like the OpenGL-inspired API anyway. And it's only barely threadsafe.

21 Name: !WAHa.06x36 2005-08-23 10:44 ID:D0PZViy0

On second thought: I see no way to interrupt image loading in ImageMagick, which is another must-have feature for this project.

22 Name: dmpk2k!hinhT6kz2E 2005-08-24 00:11 ID:Heaven

Well, like VacBob pointed out, there's still FFmpeg. FFmpeg has been used by people porting away from Quicktime.

Since you're going to be distributing a binary for most platforms anyway, you can leave most optional dependencies out.

23 Name: !WAHa.06x36 2005-08-24 01:26 ID:D0PZViy0

Yeah, but FFmpeg only does JPEG, PNG and GIF. I need the rest, too.

This thread has been closed. You cannot post in this thread any longer.