Tip for loading images

BlitzMax Forums/BlitzMax Programming/Tip for loading images

Grey Alien(Posted 2006) [#1]
Found this out today.

Well, normally if you load an image and don't specify any flags, it will use AutoImageFlags which (unless you've changed them) are MASKEDIMAGE and FILTEREDIMAGE. This is normally fine as you want your sprite to be masked and filtered image means that if it's scaled up, rotated or drawn at fractional pixel sizes it looks cool (antialiased).

However, if you load in a background image with these flags that has a lot of black in (I had a jpg like this), it may not have the desired effect. My jpg was black with white writing (which was anti-aliased in a paint package) and although the edges of text were fine in the paint package, it looked weird and jagged in BlitzMax. I assume this is because the defaul mask colour is not using plain 0,0,0, it's actually using a range e.g. 8,8,8 or something and cutting those colours out. Anyone have more info on this...? (I can post an example)

Anyway, so I recommend always loading background images with a flag of 0, unless you plan to rotate or scale or scroll (draw at floating point coords) the background.

Also, am I correct in thinking that filtered images take up more memory or is that just mipmapped images? Also are filtered images slower to draw, even at integer coords, non-scaled and non-rotated?


Curtastic(Posted 2006) [#2]
I didn't notice a difference with my background image, but it sounds like a good idea


Grey Alien(Posted 2006) [#3]
yeah you may not notice on many images, but it's a good precatution.


Avon(Posted 2006) [#4]
Personally I don't use JPG for anything in a game (even a background) as they are too lossy. PNG is my preferred format.


Grey Alien(Posted 2006) [#5]
I use PNG for all game graphics, but sometimes certain backgrounds can look OK as jpg and are 100K whereas a png is 500K so it's a trade off for final install size. If download size meant nothing I'd use a png. However, the issue above may still occur on pngs, I just noticed on a jpg I was given. Lot's of professional games use jpgs, some with horrible compressiona artifacts. I personally check them and make sure they don't have anything obvious/horrible.


Avon(Posted 2006) [#6]
sometimes certain backgrounds can look OK as jpg and are 100K whereas a png is 500K

That's a fair point. I guess if the difference is negligible and you can save 400K, then it's worth doing.


Dreamora(Posted 2006) [#7]
You do not need to disable maskedimage.
All you need to do is render it with SolidBlend, that should solve JPGs nearly 0,0,0 color problem.


ImaginaryHuman(Posted 2006) [#8]
Filtered images do not take up any more memory. The filtering is to do with the way that the texture is looked up and interpolated on the fly, nothing to do with how the original data is stored. You aren't storing sub-pixel-accurate image data, you're just representing regular image data at a sub-pixel offset. Filtering is a combination of the values from the surrounding pixels multiplied by how much percentage of the pixel they take up, at a sub-pixel level, so that the overall color represents contributions from all the nearby pixels, and gives the appearance of drawing it at a sub-pixel position.

Usually filtering IS slower. At least, it is on my system. But even so, I found no problem doing much the same routines with filtering on. You might eat up 20-30% extra GPU time or something, depends on the card.

At integer coordinates, if filtering is on it still (probably) filters the image with sub-pixel accuracy and is the same speed. Being non-scaled and non-rotated doesn't appear to have any influence on the speed. Some cards might accelerate that but I don't think it's standard. Especially with OpenGL for example, I think it applies full rotation and scaling matrix operations regardless of the angle or scale.


Grey Alien(Posted 2006) [#9]
All you need to do is render it with SolidBlend
Good point *BUT* I was drawing it solid blend yet still it looked funny!

AngelDaniel: Thanks for the extra info and opinion.


Dreamora(Posted 2006) [#10]
(Looking funny and GraphicsDepth() = 32) ?

Because in 16Bit much stuff will look funny especially when it came from jpg.


Grey Alien(Posted 2006) [#11]
yep depth = 32, this is why I don't get it!

here's the draw code:

	Method Draw()
		If Image <> Null Then
			SetBlend SOLIDBLEND
			DrawImage(Image,0,0)
		EndIf
		If Header <> Null Then
			SetBlend ALPHABLEND
			Header.Draw()
		EndIf
		If Menu<>Null Then Menu.Draw()
	End Method


pretty obvious. When the jpg is loaded with MASKIMAGE it looks crap, when flags = 0 it's fine.