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
ARYOP #AOPCLP,R, 0,255
ARYOP #AOPCLP,G, 0,255
ARYOP #AOPCLP,B ,0,255
ARYOP #AOPMUL,A#,A#,16777216
GLOAD U,V,W,H,A#,0
DIM Comp=ARRAY%(0):GSAVE U,V,W,H,Comp
ARYOP #AOPMAD,Comp,R,65536,Comp
ARYOP #AOPMAD,Comp,G,256,Comp
ARYOP #AOPADD,Comp,B,Comp
GLOAD U,V,W,H,Comp,0
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.