How to mask images?

BlitzMax Forums/BlitzMax Beginners Area/How to mask images?

Koekelas(Posted 2004) [#1]
In pre BlitzMax you ware able to mask images like MaskImage testImage, red, green, blue but this no longer works in BlitzMax. The only two commands that have something to do with masking are SetMaskColor and MaskPixmap. I don't even have a clue what SetMaskColor does since I don't see any changes whit SetMaskColor on or off. Then you have MaskPixmap... First I don't really understand the thing whit pixmaps... So when I want to change something of an image (in this case masking the image), I have to take the image out of VRam and put it into CPU addressable Ram, right? And this is done like:

Local pixmapTestImage:TPixmap = LockImage(testImage)

MaskPixmap pixmapTestImage, red, green, blue

UnlockImage(testImage)

But when I do this I get an Runtime Error: Image frame cannot be locked. Cane somebody help me out whit this?

Thank you, Nicolas.


MRaven(Posted 2004) [#2]
With SetMaskcolor you can define a global mask color (e.g. 255,0,255). If you want to load a imaged masked use LoadImage(file$, MASKEDIMAGE)


ImaginaryHuman(Posted 2004) [#3]
I think you have to set the mask color before loading the image so that it knows to convert pixels of that color into a mask?

Not sure how to use maskpixmap


Koekelas(Posted 2004) [#4]
Works perfect, thank you very much!

Nicolas.


Diordna(Posted 2004) [#5]
Yes, but what about fuzzy masks? Setting one color will make anti-aliased images have halos. If you can't make a normal mask and you don't have a program that lets you work with alphas, then you can't make anti-aliased transparent images.


MRaven(Posted 2004) [#6]
True, you should have a nice graphic suite to make pngs or tgas with alpha layers. If you don't have one, I strongly commend Photoshop Elements. It have everything you need and can purchased for a VERY reasonable price.


ImaginaryHuman(Posted 2004) [#7]
Well, technically you can write a small program in BlitzMax. It could take any given ordinary non-antialiased image and draw it with an alpha channel setting of, say, 25% visible, and draw it four times each at a slightly different location less than 1 pixel wide and high overall, and then grab that back from the backbuffer into an image. Or with OpenGL directly you could use the accumulation buffer to antialiase.


Koekelas(Posted 2004) [#8]
Why does it always have to be expensive :-)? Just make them whit GIMP, free and easy, don't you just love open source some times?

Nicolas.


MRaven(Posted 2004) [#9]
Expensive? Hm, 90 bucks for Photoshop Elements seems not expensive to me, it's relative though. :) GIMP is fine... but hm, well it's fine. :)


Diordna(Posted 2004) [#10]
It's expensive if you don't have a job or if you're in high school or college.


MRaven(Posted 2004) [#11]
Sure, then Blitz Max is expensive too... :)


Diordna(Posted 2004) [#12]
Not if you're a beta tester :D

HS sophomore here ;)


Kanati(Posted 2004) [#13]
It's also expensive when you just bought bmax and then dropped a grand on a powerbook and osx panther. :)


Koekelas(Posted 2004) [#14]
What I want to say, why buy something when you have a free and legal alternative?
It's just a matter of taste I think. I prefer making my artwork into Flash and Swift3D (I know this sounds strange) and for the rest I use GIMP or Teal.

But back to masking images :-). Diordna said something about fuzzy mask, halo's and anti-allised images. Apparently I have no trouble at al masking anti-allised images but that's not what Diordna wanted to say isn't it? So what are fuzzy masks?


MRaven(Posted 2004) [#15]
Sure, why buy something when you have a free and legal alternative. And there is nothing wrong with GIMP. I'm just a photoshop fan, think that it is a software written by the lord himself. :) Just wanted to point out that there is an expensive alternative to photoshop cs with the elements version. Maybe some don't know this.

But I don't know what fuzzy masks are. Don't have problems with alpha layered pngs or tgas so far.


Wunderkind(Posted 2004) [#16]
Hiho,

SetMaskColor() + LoadImage(...,MASKEDIMAGE) + SetBlend(MASKBLEND) doesn't work for me. Maybe someone could check this small piece of an example code. Thanks a lot.

Strict

framework brl.glmax2d
Import brl.basic
Import brl.system
Import brl.pngloader


Const SCREEN_WIDTH = 1280
Const SCREEN_HEIGHT = 1024
Const BPP = 32 ' bits per pixel


Global mx
Global my


Type tsprite
	Field img:timage
	Field width, height
	Field frame_count
	Field frame ' actual frame
	Field file_name$
	Field xpos, ypos

	Method load(fname$,h,w,fcount)
		width = w
		height = h
		frame_count = fcount
		frame = 0
		file_name$ = fname$
		SetMaskColor(255,0,255)
		img = LoadAnimImage(fname$,width,height,0,frame_count,MASKEDIMAGE)
	End Method
	
	Method draw(x,y)
		SetBlend(MASKBLEND)
		DrawImage(img,x,y,frame)
		xpos = x
		ypos = y
	End Method
End Type


Graphics(SCREEN_WIDTH,SCREEN_HEIGHT,BPP)

Global mouse:tsprite = New tsprite
mouse.load("./gfx/button_01_01.png",100,250,10)

While Not KeyHit(27)
	Cls()
	mx = MouseX()
	my = MouseY()
	DrawText("Esc >> Beenden",10,10)
	mouse.draw(mx,my)
	Flip()
Wend

End



Koekelas(Posted 2004) [#17]
From the BlitzMax manual:
MASKBLEND: Pixels are drawn only if their alpha component is greater than .5

It's a wild guess...

Nicolas.


MRaven(Posted 2004) [#18]
Yes, try SetBlend(ALPHABLEND). That should work.


Wunderkind(Posted 2004) [#19]
Thanks for your reply. I simply set transparent pixel to fully alpha and use MASKBLEND. Works fine. I guess that's not the best solution, because saving alpha info blows up the image file size.