Textures - BMP vs JPG

Blitz3D Forums/Blitz3D Programming/Textures - BMP vs JPG

KuRiX(Posted 2005) [#1]
Hello friends. I am creating a map with more than 300 textures (one for every building). I am using 256x256 bmps for most of them. The only problem i am having now is the loading time.

My question is that if i change to jpg format perhaps i will increase the computing time for the decompression time but i will decrease the hard disk access.

Will then this be faster? (i know jpg's are losing quality in the compression, no problem).

Thanks, KuRi.


Rhyolite(Posted 2005) [#2]
Hi KuRiX,

I have no idea about this specific situation, but in my career so far hard disc access has ALWAYS been way slower than anything done in CPU. You are talking a factor of 1000's here, probably more - so I would say use JPG if quality is ok.

Although, one thing to consider is the cluster size of the hard disk (which varies from drive to drive). But if your bmp textures are smaller than the cluster size anyway, then a smaller file size will make no difference!! Hmmm, well I think thats right - not had to remember that kinda stuff for a long time ;)

Rhy :)


KuRiX(Posted 2005) [#3]
Thanks Rhy. The problem is that to test this (very interesting test...) i have to change that 300 bmp textures to jpg's, and then change the references one by one (perhaps i will edit the binary b3d file).

About the bmp size, the files are greater than the cluster size (about 192KB for every bmp).

I will try to test it. Any more ideas?


Bot Builder(Posted 2005) [#4]
Smaller files will definitly help. Alot of games use pak files so that it can load everything faster (at least thats my theory for it, it could also be a mod distro system, and a way to hide files from the average user). I would compress all the bmps using png. This will likely be alot bigger than jpg, and I'm not sure how they compare in decompression speeds, but png is lossless. I would try all three and see how they compare. In any event, I doubt your users will appreciate you distributing with bmps.

For converting I would search for a batch image convertor - I can't really recommend a good one. For the references, assuming its some sort of model file or map file, open it up in a text editor and do a find/replace with .bmp to .jpg/.png


John J.(Posted 2005) [#5]
As far as I know, there would be no slow-down during real-time rendering when using JPG images, because Blitz3D first decompresses the JPG image to a bitmap. The only slow-down you would get is at loading time, when the LoadTexture() command loads and decompresses the image (which may take a little longer to load than a standard bmp or png file).

If you plan on loading huge images (4096 x 4096, for example), it's probably best to use JPG images. This not only saves space, but would save the time of loading a 45MB file from the hard drive.

If the images are relatively medium sized or small (less than 512 x 512), the hard disc access time might not be a problem, and BMP or PNG files may load faster. Using a PNG or BMP file in this case would probably be best, unless you plan to distribute your app/game online as shareware/freeware, where it is essential to keep file sizes to a minimum.

It might help to do a small experiment to find which file format loads faster, using MilliSecs() to calculate loading times.


KuRiX(Posted 2005) [#6]
Of course i need to optimize the loading time. Any ideas are welcome.

The question is if 300xjpg's would load faster than 300xbmp's.

The simpler question should be: What is it faster?:
1- Load a Bmp (192KB readed from disk)
2- Load a Jpg (35KB readed fom disk + decompression time).

Thanks All!


ashmantle(Posted 2005) [#7]
BMP / PNG isn't really a choice.. always go for PNG as it does everything BMP does better and much more, like compression (lossless) and alpha channel.


KuRiX(Posted 2005) [#8]
First Tests give the win to the BMPS:

time1 = MilliSecs()
For i=1 To 1000
tex = LoadTexture("C:\foto1.bmp")
Next
time2 = MilliSecs() - time1
RuntimeError(time2)

With BMPS: 78 ms
With JPGS: 90 ms

:(

EDITED: PNG's ARE EVEN SLOWER


Hotcakes(Posted 2005) [#9]
I do believe Blitz keeps a cache/log of files already loaded, so it could be that the test you posted is showing 'loading time only once + cpu time to decrypt bmp 1000 times' vs 'loading time only once + cpu time to decrypt jpg 1000 times'... if you get what I mean.

I would do this : time your actual game loader routines, similar to above, then convert your 300 pictures to jpg or png but KEEP the .bmp extension - Blitz is smart enough to recognise the filetype regardless of it's extension and this saves you from having to change 300 lines of code ;] The actual conversion process should be an easy batch render in your favourite paint program...


Nicstt(Posted 2005) [#10]
copy and paste the relavent code to word for example, do a find and replace, if it changes what u want, copy it back to blitz


Rhyolite(Posted 2005) [#11]
I think Hotcakes is onto a good point their with caching. Also, the 'fragmented' state of your hard drive is gonna effect your times - so you may want to consider defragging it.

Rhy :)


KuRiX(Posted 2005) [#12]
Well the fragmented state is something i don't care, because i am going to distribute the game, and i can't say: "Mininum requeriments: Defrag your HD" xDD

The cache state is something i should take care. But anyway i have tested the code above with loadimage instead of loadtexture, and jpg's and png's are slower (much) that bmp,s.

Any ideas to optimize the loading time? (of course having less textures is an idea... hehe)


Beaker(Posted 2005) [#13]
Something that a couple of people did, was to use 8 bit BMPs. This reduced loading time & decompression time, and also reduced the zipped size dramatically, at the cost of image fidelity. A lot of textures don't suffer that much because they don't have that wide a range of colors.

Worth a look?


John Pickford(Posted 2005) [#14]
That benchmark is useless as the file will be cached after the first load. At best it will give you a hint of the CPU overhead (decompression).

In reality the decompression is more than made up for by the shorter loading times. JPG's will load a lot quicker in practice. PNG's are absolutely the best solution as they use a non-lossy compression meaning no loss of quality.


KuRiX(Posted 2005) [#15]
Well, i have made the same test with 100 different bmp's and 100 different jpg's (for the test i have made a list of files of the same size).

Bmp's are faster in this test too...

Perhap's JPG's get faster for much larger files.

I Keep Testing anyway! Thanks All!

P.D: The change of 24 bits to 16 bits speed up things a lot...


jfk EO-11110(Posted 2005) [#16]
this is surprising. tho 100 ms for thousand pics - No problem IMHO. Just remember about every game loads some dozens of seconds, and some suckers even several minutes. And I remember nolf 1 told me to defrag my harddrive before it let me install the game. ^^


KuRiX(Posted 2005) [#17]
The 100ms were due to the caching. With different images the loading time is 30 secs for 200 bmp's. I have a loading time

Cheers, KuRi.