Why is there LoadPixmap and LoadPixmapPNG?

BlitzMax Forums/BlitzMax Beginners Area/Why is there LoadPixmap and LoadPixmapPNG?

sswift(Posted 2006) [#1]
Why not just have LoadPixmap?


Michael Reitzenstein(Posted 2006) [#2]
LoadPixmapPNG is an internal function that's called by LoadPixmap. There is also LoadPixmapJpeg. Due to the way the BlitzMax modules are structured, LoadPixmapPNG/LoadPixmapJPG have to be public to be accessable by pixmap loading system.

It's also significantly faster to load what you know will be a PNG with LoadPixmapPNG than LoadPixmap. BlitzMax tries each loader in series rather than guessing to try LoadPixmapPNG if the extension is .png - at least, it did when I did Inca Quest, and that's a trick I used to save many many seconds off the load time.


Hotcakes(Posted 2006) [#3]
Ah, yes, Max still does things that way. Its implementation looks really sexy until you think about it in that way...


sswift(Posted 2006) [#4]
Michael:
So wait, if you saved several seconds with this technique, then what did you do? Use LoadPixmapPNG, and then convert the pixmaps to images with one of the other commands?


Also, I was looking at the source for LoadImage, and I found this:

	Function Load:TImage( url:Object,flags,mr,mg,mb )
		Local pixmap:TPixmap=TPixmap(url)


TPixmap is a type. Where's New, and what the heck is that (Url) bit doing on there? The pixmap type doesn't seem to shed any light on this.


H&K(Posted 2006) [#5]
@SSwift

LoadPixmap and LoadPixmapPNG both return a TPixmap, so what I Imagine Michael did, was instead of using LoadPixmap, he used either LoadPixmapPNG or LoadPixmapJPG directly.

It looks to me as if there is also Function TPixmap that excets A URL as parameter. (But thats just a guess)


Yan(Posted 2006) [#6]
It's trying to cast the URL object to a pixmap, if it succeeds, the image is generated from the pixmap, otherwise the URL is passed on to LoadPixMap() where the pixmap is loaded via the TPixmapLoaders.

Don't ya just love this OO stuff. :o)

As Michael R has stated, you can bypass the usual TPixmapLoader chain by supplying the pixmap directly...
Local image:TImage = LoadImage(LoadPixMapPNG("image.png"))



sswift(Posted 2006) [#7]
H&K:
Yes, but you need IMAGES to draw stuff, so he'd have to convert those pixmaps to images.

Yan:
"if it succeeds, the image is generated from the pixmap, otherwise the URL is assumed to be a file path string and the pixmap is loaded via the TPixmapLoaders."

Ah... I see!


"Don't ya just love this OO stuff. :o)"

Nope! I don't love not being able to tell when something is a cast or a function call! :-)


I do like the idea of being able to use loadimage on a pixmap though. That explains how Michael was able to speed up his loader so easily. I guess I'll implement a file extension pixmap loading thing into my custom loadimage function I already use which ovverides the normal one and see if my load times get sped up.


sswift(Posted 2006) [#8]
Well, I tested it, and using ExtractExt to determine the file extension before calling the appropriate LoadPixmap function then calling LoadImage on that isn't any faster than calling LoadImage normally.

So I'd like to know what Michael did that supposedly shaved seconds off his load time. :-)

Maybe all your images were bmp's or jpeg? Most of mine are png's.


Hotcakes(Posted 2006) [#9]
I don't love not being able to tell when something is a cast or a function call!

It was obvious. url:Object was the first parameter right above that line =]

I'd like to know what Michael did that supposedly shaved seconds off his load time. :-)

Presumably he had a hell of a lot of images being loaded, because most picture ident methods don't check for much... usually 12-20 bytes of header info and then quits out... it depends on how many image modules you have and how complicated they are. I havn't seen any complicated ones though.


H&K(Posted 2006) [#10]
@Sswift, Oh yes I see what you mean. Bit slow there, sorry


Grisu(Posted 2006) [#11]
So

Local image:TImage = LoadImage(LoadPixMapPNG("image.png"))

is faster than normal Loadimage()?


tonyg(Posted 2006) [#12]
yep. Obviously varies but it's about 1-3ms per load.


sswift(Posted 2006) [#13]
"yep. Obviously varies but it's about 1-3ms per load."

Not quite! I loaded 60 files and I didn't even see a 1ms difference. In fact it took more time.

I ran two tests each, and without it, I got 4331 and 4342. But with it I got 4359 and 4349.

The majority of my load time is an ogg file, but you're talking about a 180ms difference for 60 image files and I'm just not seeing that in those numbers.


tonyg(Posted 2006) [#14]
Running larger tests has more variety of responses which could suggest a problem with my testing.
9/10 times loadpixmappng is faster (for me). Admittedly between 1-60ms. Lower numbers of loads show a larger difference
e.g. 5 images show between 1-15ms difference... for me.
Please can some run/check/correct the following...
Graphics 640 , 480
GCCollect()
Local image:TImage
t1:Int=MilliSecs()
For x = 0 To 5
	image = LoadImage("max.png")
Next
t2:Int=MilliSecs()
GCCollect()
Print "loadimage done"
t3:Int=MilliSecs()
For x = 0 To 5
	image = LoadImage(LoadPixmapPNG("max.png"))
Next
t4 = MilliSecs()
Print "loadpixmap done"
Print t2 - t1
Print t4-t3


<edit> Scratch all that. They do seem the same if I load a dummy image first then run through the loops.
<edit2> In fact, scratch it all again. Getting some very odd results. Still suggests Loadpixmappng is slightly quicker but results vary too much to be sure.


Warren(Posted 2006) [#15]
Glad you guys are spending your time on something really important. :)


tonyg(Posted 2006) [#16]
It's this or X-Factor!


H&K(Posted 2006) [#17]
Or that maria thing


sswift(Posted 2006) [#18]
Getting load times down IS important!

But not shaving off 20ms. If it was like a second it would be worthwhile. Which is why I'm probably gonna implement that ogg to wav thing.


tonyg(Posted 2006) [#19]
Is MaxMod an option for reducing OGG load times as it has streaming?


Warren(Posted 2006) [#20]
Getting load times down IS important!

incbin FTW. :P


sswift(Posted 2006) [#21]
You're saying Incbin will make everything load much faster?

Hm...

I'll have to test that.


Warren(Posted 2006) [#22]
I'm theorizing. It should, but who knows...


sswift(Posted 2006) [#23]
Well you don't go around throwing out statements like INCBIN FTW! without solid evidence to back you up! You might look quite silly later. :-)


Warren(Posted 2006) [#24]
Eh, could be faster, could not be ... try it and see. And get off my lawn.


Michael Reitzenstein(Posted 2006) [#25]
Post your code.


Grisu(Posted 2006) [#26]
Incbin should be slower as the files need to be extracted first.

You can stream ogg files via fmod. That's what I'm doing to get rid of the loading times.


Warren(Posted 2006) [#27]
Incbin should be slower as the files need to be extracted first.

If it's slower, there's something seriously wrong.


tonyg(Posted 2006) [#28]
WarrenM, thanks for the suggestion. Works great for me.


Grisu(Posted 2006) [#29]
^^Is that a feeling or fact?


Warren(Posted 2006) [#30]
It's a leap of logic, but call it faith if you will. Once the EXE is loaded into memory all of the incbin stuff should be there as well. I can't imagine loading from that memory bank is slower than going to to disk for each file.


sswift(Posted 2006) [#31]
Didn't you hear him tell you to get off his lawn? :-)


tonyg(Posted 2006) [#32]
^^Is that a feeling or fact?

I believe it but not sure what that means.