grabjacket
07-12-2011, 10:41 AM
Hi,
I need to check some generated wirecolor-elements for red pixels. If there are any, they need to be processed some more. I have made something which checks for red pixels, but it uses try/catch. I'm wondering if there is a more elegant solution out there.
function fn_pasteCheckForRed colorRedWire p1 c2 p2 =
(
/*
<DOC> Checks an image for any red pixels. Returns an undefined value if this happens. This will create an error which can be caught.
Arguments:
<color> colorRedWire: the red wirecolor channel
Return:
<color> the resulting color.
*/
if (colorRedWire as point4).x > 0.0 do colorRedWire=undefined
colorRedWire
)
--theBmp is the bitmaptexture I'm checking for red pixels
redPresent = try(pastebitmap theBmp theBmp[0,0] [0,0] type:#function function:fn_pasteCheckForRed)catch(true)
If there's any pixel with a hint of red, the pastebitmap function will create an error. This is caught by the try/catch.
Thanks,
Klaas Nienhuis
I need to check some generated wirecolor-elements for red pixels. If there are any, they need to be processed some more. I have made something which checks for red pixels, but it uses try/catch. I'm wondering if there is a more elegant solution out there.
function fn_pasteCheckForRed colorRedWire p1 c2 p2 =
(
/*
<DOC> Checks an image for any red pixels. Returns an undefined value if this happens. This will create an error which can be caught.
Arguments:
<color> colorRedWire: the red wirecolor channel
Return:
<color> the resulting color.
*/
if (colorRedWire as point4).x > 0.0 do colorRedWire=undefined
colorRedWire
)
--theBmp is the bitmaptexture I'm checking for red pixels
redPresent = try(pastebitmap theBmp theBmp[0,0] [0,0] type:#function function:fn_pasteCheckForRed)catch(true)
If there's any pixel with a hint of red, the pastebitmap function will create an error. This is caught by the try/catch.
Thanks,
Klaas Nienhuis
