LoginLogin
Might make SBS readonly: thread

GCOMP

Root / Submissions / [.]

MZ952Created:
This serves a really niche purpose. Basically, I'm working on a piece of code that constantly needs to reference/make changes to the color & alpha components of an image, but redrawing all those pixels and/or their individual color components takes a *ton* of time, so I came up with this:
DEF GCOMP U,V,W,H,A#[],R[],G[],B[]
 ARYOP #AOPCLP,A#,0,255'clamp input values to 0-255, just in case
 ARYOP #AOPCLP,R, 0,255
 ARYOP #AOPCLP,G, 0,255
 ARYOP #AOPCLP,B ,0,255
 ARYOP #AOPMUL,A#,A#,16777216'shift alpha values (notice that alpha must be real type, or else overflow occurs)
 GLOAD U,V,W,H,A#,0'GLOAD converts floating point alpha values to integer; no other way to do this
 DIM Comp=ARRAY%(0):GSAVE U,V,W,H,Comp'get converted alpha values into array
 ARYOP #AOPMAD,Comp,R,65536,Comp'compose the remaining channels via shift+add
 ARYOP #AOPMAD,Comp,G,256,Comp
 ARYOP #AOPADD,Comp,B,Comp
 GLOAD U,V,W,H,Comp,0'load result
END
Basically, the image is worked upon inside of arrays, one for each component, and when the time comes to update the image at the end of the routine, GCOMP is called and the separate color channels are "composed". It works around 20x faster than just looping through the color channel arrays and doing
GPSET X,Y,RGB(A[I],R[I],G[I],B[I]) ...
, and that's not taking into consideration the time shaved off by not needing to call GPGET & RGB &GPSET a *bunch* every time the routine needs to alter a color component value... Yeah, it's a lot faster. It's also a blessing that GLOAD converts the floating point values of Alpha properly, or else this whole thing wouldn't work for me.

No posts yet (will you be the first?)