View Raw SPL

/* replace RGB colors of an image with transparency */
imrgb2alpha(img = refwindow(w0), rgb = {}, alpha = 0, normalize = 1)
{
        local r, g, b, a, ro, go, bo, idx;

        if (not(isarray(img)))
        {
                error(sprintf("%s - input image required", __FUNC__));
        }

        if (not(isempty(rgb)))
        {
                /* image RGB and alpha values */
                (r, g, b, a) = getrgb(img);

                /* get individual normalized RGB components */
                (ro, go, bo) = rgbsplit(rgb, normalize);

                idx = find(r == ro && g == go && b == bo);

                if (length(idx) > 0)
                {
                        a[idx] = alpha;
        
                        img = rgbimage(r, g, b, a);

                        return(img);
                }
        }
        else
        {
                error(sprintf("%s - RGB color and Alpha value expected", __FUNC__));
        }
}