PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Speeding up image loading

My current game project is nearing completion and I'm just doing final debugging and optimizing and all that jazz.

I am loading A LOT of images, and it's making startup time a lot longer than I'd like.

I believe all the calls to imgdecmp.dll are going slower than I'd like, and my question is this...

Is there a way to statically link the DLL to my executable (let's ignore the question of whether it's a good idea or not)?

If so, does anyone suspect that WOULDN'T make much of a difference in speeding things up?

Actually, one other question...

Has anyone benchmarked to see what the difference is, if any, between loading 10 10K images and 1 100K image? I ask because the other option I have is of course combining images and blitting sections. I didn't do that initially because (a) it's easier to work on the graphics when they are individual files and (b) I suspected blitting sections rather than a whole surface might affect performance. I didn't do any testing to verify this (yes, I SHOULD have!), it's just a suspicion.

Thanks all!
Well, you can always write your own imageloader. Shouldn't be that hard.

I'm also having trouble with the LoadImage taking a long time. I'm trying to write a video stream (a stream of frames from a network video camera) but it's hard to get good performance. I never thought it could be traced back to the DLL though, but perhaps it's not an optimal way of doing this. Let me know what you find out.

And I don't think blitting a section of an image is any slower than blitting the whole image (provided they are the same size). In fact, I guarantee it isn't. Why should it? Have you looked at the code? A source rectangle is used whether you provided one or not. If you did not provide one, one will be created covering the entire source Surface.
Well, you can always write your own imageloader. Shouldn't be that hard.

Hmm.. I might have said to much. The JPEG format was a bit more complex than I first though, but have a look at this library if you don't like the imgdecmp.dll.

http://www.aoi.it/midcximage.html

It's called CxImage and works for all platforms (and is freeware). Despite its name, it is NOT an MFC class. And it works for most common formats.

I havn't found a benchmark of the IMGDECMP.DLL but according to MSDN "Performance is very good.". But coming from MSDN this doesn't mean anything.
Check this thread where Sbl talks about the overhead in GapiDraw of using IMGDECMP.DLL to load images.

http://forums.pocketmatrix.com/viewtopic.php?t=10173&highlight=image

Pam
I tried to load 5 small jpgs on my E-125 while GameInit and something interesting occured: I got 5 jpg images a sort of "progressive jpg format for internet " it was 5 BIG PIXEL-LIKE SQARES. I tried also gifs the same size and they are OK!

Now I use this way - each time I call GameLoop I load ONLY one jpg
- it works.(I use it also for gif's)
I finally had time to do a little unscientific benchmark...

I took the title screen for Invasion: Trivia, a colorful 240x320 PNG file, 256-color optimized pallete, no transparency, non-interlaced . It's 40K.

I then took that image and broke it down into twelve 80x80 tiles and saved it in the exact same format as the original. The total size of all twelve files is 42K, so it's a reasonable comparison I think.

I wrote a simple test program to load all twelve individual pieces and blit them (although the fact that they are displayed doesn't matter for the sake of this discussion). I recorded tick count using PocketPC:GetTickCount() before I began loading the images, and immediately after. Obviously, the difference is how long it took to load them all.

Here are the results on my stock Casio E-125, all are in milliseconds of course:

1120, 1114, 1105, 1116, 1105, 1120, 1112, 1116, 1109, 1114
Average: 1113

Now, I changed the program to just load the one single image and blit that. Here are the results for that:

829, 828, 835, 830, 834, 833, 830, 830, 833, 828
Average: 831

So, while I admit I absolutely suck at math, if I'm even close to right, it seems reasonable to say that for a single image of size equal to the total size of a given number of smaller images, the load time should be around 25% better for the single image than all the individual images combined.

I think it's also reasonable to assume that as the number of individual images goes up, the percent difference will increase for the single image as well.

I also did the test with the files as JPG's. JPG's of course can't be palettized, so one would assume they take a bit longer to load (I should be fair and do a 24-bit PNG...) but in any case, here are the results for the 12 individual loads:

6452, 6439, 6428, 6439, 6437, 6440, 6441, 6439, 6438, 6438
Average: 6439

For the single file:

6111, 6112, 6112, 6114, 6115, 6117, 6113, 6114, 6115, 6116
Average: 6114

Looks like about a 6% improvement.

So, what I *think* we've learned here is actually two-fold...

(1) Most importantly, loading a single image is faster than loading a number of smaller images who's size equals the single image.

(2) Use PNG's!

Again, I did not compare a 24-bit PNG to JPG, it could be that that comparison would favor JPG. In addition, I didn't even bother with GIF, I view it as a dead format unless you need animated images, which doesn't apply to this discussion.

Anyone see any obvious flaws with my thought process here? I believe I remember Thierry stating that blitting a section of an image should be just about as fast (or maybe just as fast?) as blitting an entire image, which does stand to reason... That would have been my only reason for not using composite images... With that in mind, it seems clear that my original question about load times is answered by stating that you should combine as many images as possible into a smaller number of large images and just blit sections of it, and make sure you use PNG's, most definitely if you are dealing with a 256-color palettized image.
Conan · 01 May 2003, 21:06 UTC — what about
just in time loading. While the questions or a cut scene or other pause point are up load some images rather than at the start. This way you get the player to the menu faster.

Also you could reduce images by making a simple background smaller then stretch it up & blit the main pic on top or similar. ie: don't have full screen images. I use lots of plain color with line drawing to save on big graphics. About 40% of all my screens are done this way. Of course using 3D also keeps file sizes down as a few meshes and a wee texture take a lot less room that the equivalent bitmap and can be scaled, rotated etc
I tried doing things like that originally, but it always resulted in stutters at various points. I found this to be unacceptable.

At one point I tried calling out from GameLoop to a loader function that would load a single image each time... No good, as the call to imgdecmp.dll blocks... I also tried having a low-priority thread running in the background to do the loads... That works a bit better, and it might be possible to tweak that to work acceptably well. In fact, the current loading screen is utilizing a thread to do the loading while GameLoop continues to fire to update the screen, but if you notice the pulsating blocks on the status bar stutter because of the activity of the thread. As I said, it might be something I could tweak, but you can at least see why I suspect it's probably not going to work.

In the end, for Invasion: Trivia anyway, the best results resulted from doing a complete up-front load. Obviously that makes the load time not good, but the alternatives seemed worse.

But, I do wish I would have at least done this benchmark early on because it obviously would have helped somewhat. I mean, if I figure on a 90-second load time (this is on my E-125 mind you), if I could have realized that 25% improvement I indiciated above, we're talking about shaving off about 23 seconds load time. That's a pretty substantial savings.

Well, live and learn anyway. I have a number of schemes in mind for the next game to avoid such problems, we'll see how it goes.
Dave Johnston · 02 May 2003, 08:02 UTC — what about
Conan wrote:
Also you could reduce images by making a simple background smaller then stretch it up & blit the main pic on top or similar.


Add some noise to the stretched image and it looks better and less-pixelated, IMO. Works better when the stretching is filtered, but we obviously can't do that sensibly :)

Of course, adding noise can be expensive, but hey, if you have the cycles...