QB64 Phoenix Edition
How to Color Mask? - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: How to Color Mask? (/showthread.php?tid=3315)



How to Color Mask? - James D Jarvis - 12-24-2024

So how do we make color masks with the "newer" commands?   The old put and get method makes sense but I am clueless as to how to get it to work with _putimage. 

Alpha blending????  How's the color not overwrite the black pixels? Help!

Code: (Select All)
'How to mask?
a$ = Space$(4 + 100)
b$ = Space$(4 + 100)
i& = _NewImage(10, 10, 256)
i2& = _NewImage(10, 10, 256)

Screen 13
Locate 1, 1: Print "Base image"
Line (40, 40)-(49, 49), 15, B
Get (40, 40)-(49, 49), a$
_PutImage (0, 0)-(9, 9), 0, i&, (40, 40)-(49, 49)
Sleep
Locate 1, 1: Print "Color Mask"
Line (40, 40)-(49, 49), 12, BF
Get (40, 40)-(49, 49), b$
_PutImage (0, 0)-(9, 9), 0, i2&, (40, 40)-(49, 49)
Sleep
Cls
_PrintString (10, 10), "Put & And "
Put (200, 10), a$, PSet
Put (200, 10), b$, And
_PrintString (10, 50), "_Putimage & And "

_PutImage (200, 50), i&
Put (200, 50), b$, And

_PrintString (10, 100), "_Putimage & _Putimage "
_PutImage (200, 100), i&
_PutImage (200, 100), i2&
_PrintString (10, 150), "So how do you do a color mask"
_PrintString (10, 159), " with _putimage?"



RE: How to Color Mask? - RhoSigma - 12-31-2024

I've swapped lines 28 and 29 of your example above, so the red filled square ist put first, then set the white (color 15) parts in the original image as transparent and put it over the colored one. This works for this specific example, doesn't mean it's the general way to go. If you wanna work with alphablending you would need to go with 32bit images anyways, alpha is not possibe in SCREEN 13 or 256 color images, here you can only define one color as fully transparent with the _CLEARCOLOR statement.

Code: (Select All)
'How to mask?
a$ = SPACE$(4 + 100)
b$ = SPACE$(4 + 100)
i& = _NEWIMAGE(10, 10, 256)
i2& = _NEWIMAGE(10, 10, 256)

SCREEN 13
LOCATE 1, 1: PRINT "Base image"
LINE (40, 40)-(49, 49), 15, B
GET (40, 40)-(49, 49), a$
_PUTIMAGE (0, 0)-(9, 9), 0, i&, (40, 40)-(49, 49)
SLEEP
LOCATE 1, 1: PRINT "Color Mask"
LINE (40, 40)-(49, 49), 12, BF
GET (40, 40)-(49, 49), b$
_PUTIMAGE (0, 0)-(9, 9), 0, i2&, (40, 40)-(49, 49)
SLEEP
CLS
_PRINTSTRING (10, 10), "Put & And "
PUT (200, 10), a$, PSET
PUT (200, 10), b$, AND
_PRINTSTRING (10, 50), "_Putimage & And "

_PUTIMAGE (200, 50), i&
PUT (200, 50), b$, AND

_PRINTSTRING (10, 100), "_Putimage & _Putimage "
_PUTIMAGE (200, 100), i2&
_CLEARCOLOR 15, i&
_PUTIMAGE (200, 100), i&
_PRINTSTRING (10, 150), "So how do you do a color mask"
_PRINTSTRING (10, 159), " with _putimage?"



RE: How to Color Mask? - James D Jarvis - 01-02-2025

Thank you. I mostly want to be able to do simple recolors of an image without doing a full recolor. In the past white mask and color overlays and black wasn't touched. Doesn't alpha blending color any pixels under an area?


RE: How to Color Mask? - bplus - 01-03-2025

I have code that switches one color to another in an image, how 'bout that?

Your request for a "mask" threw me off.