Getting image size before loading

BlitzMax Forums/BlitzMax Programming/Getting image size before loading

Sin of Nature(Posted 2006) [#1]
Hi,
I think the answer is no, but I want to check. Is there away of getting the size of the image before it it loading into memory using blitz commands (or possible anyone coded a API mod)? I know you can code the reading of the image header, but I'd need to do it for all image formats (BMP, JPG, PNG... etc) which would take ages.

Has anyone got a trick for doing this? At the moment I'm loading them into memory, getting the banksize, then using the automatic garbage collection to delete them straight afterwards. I'm a little jumpy about doing that way, especially as some of the images could be large.

Ideas?

Sin


CS_TBL(Posted 2006) [#2]
Dunno, if you already know what images you want to load (e.g. sprites for a game), then you could preprocess those images in some seperate tool: load image, observe size, rename file as filename+"_"+width+"x"+height.
Then it's a matter of extracting this info from the filename..

Other than that, I'll pass. :)


Dreamora(Posted 2006) [#3]
Possible without loading: NO
But you can use pixmaps which loads it to ram and if you want to make an image out of it, just use the reference to the pixmap :-)


H&K(Posted 2006) [#4]
I dont know at all. So no one shout @ me if this is a stupid question.

But could you just ask the operating system how large the images are? (And I do mean dimentions and not just bytes)


Dreamora(Posted 2006) [#5]
No
You would need to use the BM image loaders and add the functionality (if it isn't present)


Sin of Nature(Posted 2006) [#6]
Hi,

CS_TBL: The image sizes are unknown size as the program is a graphical tool, so unfortunately its not possible.

Thanks all, I thought that was the case. I was just making sure. :)

Sin


ImaginaryHuman(Posted 2006) [#7]
Yah, if it's just a randon selection of images and you don't really know what they contain, then you'll have to open each file one by one as a stream, read in some bytes, figure out what file type it is (maybe a clue from the file extension), then read some chunks based on the file formats themselves till you get to the part that defines the dimensions, then close the file. You have to do that for each file. That's what the O/S has to do if it did it.

If the files are known, ie your own media, then you should know the dimensions already.

Having said that, BMax should already have code somewhere within its modules that finds the dimensions of each of these image types - maybe you could take that code and modify it to stop loading after it finds the dimensions.