View Raw SPL
/* split RGB array or scalar into individual RGB values */
rgbsplit(rgb = 0, normalize = 0)
{
        if (isarray(rgb))
        {
                if (not(numcol(rgb) == 3))
                {
                        error(sprintf("%s - RGB array must have 3 columns", __FUNC__));
                }
                else
                {
                        r = rgb[.., 1];
                        g = rgb[.., 2];
                        b = rgb[.., 3];
                }
        }
        else if (isscalar(rgb))
        {
                (r, g, b) = int2rgb(rgb);
        }
        else
        {
                error(sprintf("%s - invalid RGB value", __FUNC__));
        }

        if (normalize)
        {
                /* normalize from 0 to 1 */
                r /= 255;
                g /= 255;
                b /= 255;
        }

        return(r, g, b);
}