alpha_blend_rgb_rgb Tcl_Obj* imageForeObj Tcl_Obj* imageBackObj int alpha /* * Alpha-based blending of two images, foreground, and background, controlled * by a scalar (and extern) alpha factor. * * alpha is Opacity * 255 <=> Fully opaque <=> imageF * 0 <=> Fully transparent <=> imageB * * => OUT = F*alpha + B*(1-alpha) */ crimp_image* result; crimp_image* imageF; crimp_image* imageB; int x, y, ralpha; crimp_input (imageForeObj, imageF, rgb); crimp_input (imageBackObj, imageB, rgb); if (!crimp_eq_dim (imageF, imageB)) { Tcl_SetResult(interp, "image dimensions do not match", TCL_STATIC); return TCL_ERROR; } result = crimp_new_like (imageF); ralpha = 255 - alpha; #define MIX(fore,back) ((((fore)*alpha) + ((back)*ralpha))/255) for (y = 0; y < result->h; y++) { for (x = 0; x < result->w; x++) { R (result, x, y) = MIX (R (imageF, x, y), R (imageB, x, y)); G (result, x, y) = MIX (G (imageF, x, y), G (imageB, x, y)); B (result, x, y) = MIX (B (imageF, x, y), B (imageB, x, y)); } } Tcl_SetObjResult(interp, crimp_new_image_obj (result)); return TCL_OK; /* vim: set sts=4 sw=4 tw=80 et ft=c: */ /* * Local Variables: * mode: c * c-basic-offset: 4 * fill-column: 78 * End: */