Mask Color

BlitzMax Forums/BlitzMax Beginners Area/Mask Color

Lukasha(Posted 2014) [#1]
Hey.

I'm having some problems with the Mask Color in Blitzmax.

Basically my code is:

----------
Strict
Graphics 800,600

SetMaskColor 128,0,0
Global symbol1:TImage = LoadImage ("Symbol1.png",1)

DrawImage symbol1,10,10
----------

The image gets drawn, but the MaskColor doesn't get removed. Any idea why?
If it has anything to do with it being a png, I used a bmp before, and when using drawimage in the same code it gave me the error 'pixmap coordinates out of bounds'.

Any help for any of those problems would be highly appreciated!
Thanks!


Chapman7(Posted 2014) [#2]
That code works for me... Can you post what image you are trying to use?


Kryzon(Posted 2014) [#3]
Don't you need to SetBlend( MASKBLEND ) before using DrawImage?


xlsior(Posted 2014) [#4]
Don't you need to SetBlend( MASKBLEND ) before using DrawImage?


Before LoadImage, possibly?


Kryzon(Posted 2014) [#5]
SetBlend( MASKBLEND ) turns on the alpha-test API state for rendering.
The Set Blend, Color, Alpha and Scale commands are used right before drawing, when you already have the image loaded.

Before loading, you need to set the mask colour for the image to be processed with when it is loaded, and the LoadImage call needs the MASKEDIMAGE flag (value 1).


Chapman7(Posted 2014) [#6]
Doesn't initiating graphics automatically set the blend mode to MASKBLEND?
This:
Strict
Graphics 800,600
Print GetBlend()

Outputs:
1

I don't recall ever having to use SetBlend before masking an image (unless of-course I changed the blend mode.


Derron(Posted 2014) [#7]
Depending on the PNG the mask color is not correct. Maybe you try to compare the "getpixel"-value (of a to-mask-pixel) to the mask color value you want to set. I think i slightly remember to have had similar issues when manipulating png-pixmaps.

@pixmap coordinates out of bounds
Another indicator you are doing something wrong. Happens if something tries to access pixels > width,height of the underlaying pixmap.

Why do you manually append the ",1", should not be needed for this example. Auto image flag are MaskedImage + FilteredImage.



bye
Ron


TomToad(Posted 2014) [#8]
If I remember correctly, SetMaskColor doesn't work with images that already have an alpha channel present. Maybe you could try removing the alpha channel first?

Local Image:TImage = LoadImage(ConvertPixmap(LoadPixmap("MyImage.png"),PF_RGB888))


ETA: Seems I am right. From the Image.bmx source, this code skips masking if an alpha channel is present.

If (flags & MASKEDIMAGE) And AlphaBitsPerPixel[pixmap.format]=0
pixmap=MaskPixmap( pixmap,mask_r,mask_g,mask_b )
EndIf