View Raw SPL
/*****************************************************************************
*                                                                            *
*   IMAGE24.SPL  Copyright (C) 1998 DSP Development Corporation              *
*                               All Rights Reserved                          *
*                                                                            *
*   Author:      Randy Race                                                  *
*                                                                            *
*   Synopsis:    Converts an image to a 24 bit color image                   *
*                                                                            *
*   Revisions:    7 Jun 1998  RRR  Creation                                  *
*                                                                            *
*****************************************************************************/

#include 

#if @HELP_IMAGE24

    IMAGE24

    Purpose: Converts an image with a colormap to a 24 bit color image

    Syntax:  IMAGE24(s)

              s - an optional series containing the source image,
                  defaults to the current window

    Returns: An array, a 24 bit color image

    Example:

             W1: Density(spline2(ravel(gnorm(100,1),10), 8));rainbow()
             W2: Image24(W1);

             W1 contains an image of a random surface shaded with
             the colors of the spectrum ranging from red to blue. W2
             converts the image into a 24 bit color image.

    Remarks:
             Unlike standard images, a 24 bit image does not
             reference a separate colormap.  Instead, each pixel of
             the image is comprised of a composite 24 bit RED, GREEN,
             BLUE value packed into a long integer (4 bytes). Use

                           (r, g, b) = GETRGB(image)

             to retrieve the separate red, green and blue values from
             a composite 24 bit image.

                           image = RGBIMAGE(r, g, b)

             To construct a 24 bit composite image from separate RGB
             values.

             Because 24 bit color images do not require a colormap
             (the colors are implicit), the image can be saved and
             restored automatically with the correct colors.


    See Also:
             Density
             Getcolormap
             Getrgb
             Iminterp
             Rgbimage
             Spline2
             Interp2

#endif


/* convert to 24 bit image */
image24(s, imbits)
{
        local r, g, b, a, image;

        if (argc < 2)
        {
                if (argc < 1)
                {
                        s = refwindow(w0);
                }

                imbits = 0;
        }

        if (numcols(s) < 2)
        {
                error(sprintf("%s - Image required", __FUNC__));
        }

        /* get and set rgb values */
        (r, g, b, a) = getrgb(s, imbits);
                
        image = rgbimage(r, g, b, a);

        if (argc == 0)
        {
                /* stick in window */
                w0 = image;

                setplotstyle(w0, 0);
                setplottype(w0, 3);
        }
        else
        {
                setplotstyle(image, 0);
                setplottype(image, 3);
        
                return(image);
        }
}