View Raw SPL

/* replace RGB colors of an image */
imrgbrep(img = refwindow(w0), orgb = {}, nrgb = {}, normalize = 1)
{
        local r, g, b, a, ro, go, bo, rn, gn, bn, idx;

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

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

                /* get individual normalized RGB components */
                (ro, go, bo) = rgbsplit(orgb, normalize);
                (rn, gn, bn) = rgbsplit(nrgb, normalize);

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

                if (length(idx) > 0)
                {
                        r[idx] = rn;
                        g[idx] = gn;
                        b[idx] = bn;

                        img = rgbimage(r, g, b, a);
                }
        }
        else
        {
                error(sprintf("%s - original RGB color and new RGB color expected", __FUNC__));
        }

        return(img);

}