Query with MASKEDIMAGE
BlitzMax Forums/BlitzMax Programming/Query with MASKEDIMAGE
| ||
For some reason I cannot seem to get masking to work. This example loads the tree (see image below) but fails to mask out the background (which is 255,0,128) Am I doing something silly? IMAGE: ![]() |
| ||
Your code is setting blend to SOLIDBLEND - does it mask correctly if you comment out the 2nd SetBlend statement? |
| ||
No, his code sets blend mode to MASKBLEND then begins rendering until you press a key. Then it sets to SOLIDBLEND and renders until you press a key. |
| ||
definition of MASKBLEND blend states: Pixels are drawn only if their alpha component is greater than .5 I got the same problem so I went and removed the alpha channel from the image and it worked. My conclusion is that it doesn't work as you expect with 32 bit images only with 24 bit. |
| ||
Loading the image as MASKEDIMAGE must not do anything if the image already has an alpha channel. MASKEDIMAGE is suppose to create an alpha channel based off of the SetMaskColor. |
| ||
Additional info: I edited the image with MSPaint (just filled the background with 255,0,128). I assumed MSPaint kills the alpha detail but it seems not to The image properties show the depth as 32 bit Having saved the image as 24bit *.bmp the masking works One more trick which helps: Local pm:TPixmap=LoadPixmap("tree.png") pm=MaskPixmap(pm,255,0,128) i=LoadImage(pm,MASKEDIMAGE) However, if the image happens to be black with a transparent background then the above fails. Case in point, this image, shows up as a black square: ![]() |
| ||
Apparently, MASKEDIMAGE flag doesn't work if there is already an alpha channel. Here is the same program, loading into a pixmap, converting format, then loading into a TImage. |
| ||
Thanks for the idea Tom, although the 'black fish' does not render in MASKEDIMAGE mode What I am trying to do is find a universal way to load images and apply the background mask UPDATED code shows what I mean. I think the trick is to test for alpha before converting: |
| ||
maskimage is a function that coverts all of the maskcolor pixels from the image to black. The way it is and how Timage handles it, it shouldn't work with any black images. either way, there seems to be a bug with the way images' masks are processed. |
| ||
Perhaps what should happen (behind the scenes) is that whenever the optional MASKBLEND is used in LoadImage(), BlitzMax should automatically convert the image to 24bit (stripping the alpha layer entirely) then apply the mask accordingly As things are at the moment, the current implementation leads to some head-scratching unless you are fully clued up on how alpha works |
| ||
Perhaps what should happen (behind the scenes) is that whenever the optional MASKBLEND is used in LoadImage(), BlitzMax should automatically convert the image to 24bit (stripping the alpha layer entirely) then apply the mask accordingly from what I understand by looking at the code, the pixmaps(from Timage) go to the video card as 32 bits only but I could be wrong. the problem is that maskImage converts all of the mask pixels to black and sense drawimage displays any color but solid black(except when using SOLIDBLEND), you are pretty much out of luck with it. The only possible solution is to convert color 0,0,0 to maybe 1,1,1. :/ as I said I could be wrong I han't looked in to the low level stuff. one more thing: the only thing is that when applying the mask to the image it does a simple edge antialias on the pixmap. the alpha works as spected when an image is converted from 24 to 32 bitb it just sets 255 as the alpha byte of the pixel: from pixel.bmx(part of pixmap.bmx): Case PF_RGB888 While out<>out_end out[0]=in[0] out[1]=in[1] out[2]=in[2] out[3]=255 in:+3;out:+4 Wend I don't think it's anything different than what you suspect. this is the culprit for not processing images already with alpha: it's in "image.bmx": Method SetPixmap( index,pixmap:TPixmap ) If (flags & MASKEDIMAGE) And AlphaBitsPerPixel[pixmap.format]=0 pixmap=MaskPixmap( pixmap,mask_r,mask_g,mask_b ) EndIf pixmaps[index]=pixmap seqs[index]=0 frames[index]=Null End Method the AlphaBitsPerPixel test is a test to see if the pixmap already has an alpha channel if it does, it is not processed. |
| ||
No, his code sets blend mode to MASKBLEND then begins rendering until you press a key. Then it sets to SOLIDBLEND and renders until you press a key. So it does - that'll teach me not to confuse a blitz3d comment with a max line separator... :/ |