Channel Info Comp Info Globals Table of Contents

Color Space

Availability  LightWave® 10.0
Component  Layout, Modeler
Header  lwcolorspace.h

The color space global returns a structure that contains function pointers to the LightWave® color space conversion functions. These functions allow the user to change their color values to those selected in the color space of LightWave®.

To determine the current color space settings, one needs to refresh the LWColorSpaceFuncs structure.

The functions come in two types. The first type is to determine which color space is being used. The second type, after a color space has been determined, returns the functions that change RGB or A values into another color space.

Global Call

   LWColorSpaceFuncs *colorspacefuncs;
   colorspacefuncs = global( LWCOLORSPACEFUNCS_GLOBAL, GFUSE_TRANSIENT );

The global function returns a pointer to an LWColorSpaceFuncs structure. The color space conversion functions use these prototypes.

   typedef void LWPIXELCONVERSIONRGB(   struct st_lwimagelookup *, float *, float * );
   typedef void LWPIXELCONVERSIONALPHA( struct st_lwimagelookup *, float *, float * );

The Local Structure

The color space is a enumeration of built-in color spaces. If the color space value is greater than or equal to lwcs_sizeof, then it is a color space loaded from the disk.

 typedef enum en_lwcolorspace {
    lwcs_linear = 0,    /*!< LightWave linear color space. */
    lwcs_sRGB,          /*!< Standard RGB color space.     */
    lwcs_rec709,        /*!< Recommendation BT.709, HDTV.  */
    lwcs_cineon,        /*!< Eastman Kodak Co.             */
    lwcs_sizeof
} LWCOLORSPACE;

typedef void LWPIXELCONVERSIONRGB(   struct st_lwimagelookup *, float *, float * ); /*!< Conversion function prototype. */
typedef void LWPIXELCONVERSIONALPHA( struct st_lwimagelookup *, float *, float * ); /*!< Conversion function prototype. */

typedef struct st_lwcolorspacefuncs {
    LWCOLORSPACE            (*nameToColorSpace)( char * );
    LWCOLORSPACE            (*getPixelConversionLookupTable)( char * );
    LWPIXELCONVERSIONRGB   *(*getPixelConversionNonLinearToLinearRGB)(  LWCOLORSPACE, struct st_lwimagelookup ** );
    LWPIXELCONVERSIONRGB   *(*getPixelConversionLinearToNonLinearRGB)(  LWCOLORSPACE, struct st_lwimagelookup ** );
    LWPIXELCONVERSIONALPHA *(*getPixelConversionNonLinearToLinearAlpha)(LWCOLORSPACE, struct st_lwimagelookup ** );
    LWPIXELCONVERSIONALPHA *(*getPixelConversionLinearToNonLinearAlpha)(LWCOLORSPACE, struct st_lwimagelookup ** );
    const char * color_space_viewer_name;
    const char * color_space_viewer_file;
    const char * color_space_viewer_alpha_name;
    const char * color_space_viewer_alpha_file;
    const char * color_space_palette_files_name;
    const char * color_space_palette_files_file;
    const char * color_space_8bit_files_name;
    const char * color_space_8bit_files_file;
    const char * color_space_float_files_name;
    const char * color_space_float_files_file;
    const char * color_space_alpha_files_name;
    const char * color_space_alpha_files_file;
    const char * color_space_output_name;
    const char * color_space_output_file;
    const char * color_space_output_alpha_name;
    const char * color_space_output_alpha_file;
} LWColorSpaceFuncs;
nameToColorSpace( colorspacename )
Returns the color space of the given color space name. A color space of lwcs_linear indicates there is no conversion.

getPixelConversionLookupTable( filename )
Returns the color space of the given file name. If the color space does not exist, then the color space is loaded from the disk. A color space of lwcs_linear indicates the function failed.

getPixelConversionNonLinearToLinearRGB( colorspace, &instance )
Returns a function pointer to the non-linear to linear rgb conversion function. The function returns NULL if there is no conversion.

getPixelConversionLinearToNonLinearRGB( colorspace, &instance )
Returns a function pointer to the linear to non-linear rgb conversion function. The function returns NULL if there is no conversion.

getPixelConversionNonLinearToLinearAlpha( colorspace, &instance )
Returns a function pointer to the non-linear to linear alpha conversion function. The function returns NULL if there is no conversion.

getPixelConversionLinearToNonLinearAlpha( colorspace, &instance )
Returns a function pointer to the linear to non-linear alpha conversion function. The function returns NULL if there is no conversion.

color_space_viewer_name
Name of color space for viewer.

color_space_viewer_file
File name of color space for viewer. If the color space was loaded from a file.

color_space_viewer_alpha_name
Name of color space for viewer alpha.

color_space_viewer_alpha_file
File name of color space for viewer alpha. If the color space was loaded from a file.

color_space_palette_files_name
Name of color space for palette files.

color_space_palette_files_file
File name of color space for palette files. If the color space was loaded from a file.

color_space_8bit_files_name
Name of color space for 8 bit files.

color_space_8bit_files_file
File name of color space for 8 bit files. If the color space was loaded from a file.

color_space_float_files_name
Name of color space for float files.

color_space_float_files_file
File name of color space for float files. If the color space was loaded from a file.

color_space_alpha_files_name
Name of color space for alpha from files.

color_space_alpha_files_file
File name of color space for alpha from files. If the color space was loaded from a file.

color_space_output_name
Name of color space for output files.

color_space_output_file
File name of color space for output files. If the color space was loaded from a file.

color_space_output_alpha_name
Name of color space for output files alpha.

color_space_output_alpha_file
File name of color space for output files alpha. If the color space was loaded from a file.

Example

This code fragment converts a single pixel to the viewer.

    #include <lwrenderer.h>

    LWColorSpaceFuncs  *colorspacefuncs;
    LWCOLORSPACE        color_space_rgb;
    LWCOLORSPACE        color_space_alpha;
    LWPIXELCONVERSIONRGB    *convert_rgb;
    LWPIXELCONVERSIONALPHA  *convert_alpha;
    struct st_lwimagelookup *instance_rgb;
    struct st_lwimagelookup *instance_alpha;
    float in[ 4 ], out[ 4 ];

    colorspacefuncs = (LWColorSpaceFuncs *) global( LWCOLORSPACEFUNCS_GLOBAL, GFUSE_TRANSIENT );

    if( colorspacefuncs != (LWColorSpaceFuncs *) NULL ) {

        color_space_rgb   = ( ( colorspacefuncs->color_space_viewer_name != (const char *) NULL ) &&
                              ( colorspacefuncs->color_space_viewer_name[ 0 ] ) )?
            colorspacefuncs->nameToColorSpace( (char *) colorspacefuncs->color_space_viewer_name ):
            lwcs_linear;

        color_space_alpha = ( ( colorspacefuncs->color_space_viewer_alpha_name != (const char *) NULL ) &&
                              ( colorspacefuncs->color_space_viewer_alpha_name[ 0 ] ) )?
            colorspacefuncs->nameToColorSpace( (char *) colorspacefuncs->color_space_viewer_alpha_name ):
            lwcs_linear;

        convert_rgb   = colorspacefuncs->getPixelConversionLinearToNonLinearRGB(   color_space_rgb,   &instance_rgb   );
        convert_alpha = colorspacefuncs->getPixelConversionLinearToNonLinearAlpha( color_space_alpha, &instance_alpha );

        in[ 0 ] = 0.5f; /* Color to convert. */
        in[ 1 ] = 0.5f;
        in[ 2 ] = 0.5f;
        in[ 3 ] = 1.0f; /* Alpha to convert. */

        if( convert_rgb   != (LWPIXELCONVERSIONRGB *)   NULL ) {
            convert_rgb( instance_rgb, in, out );           /* Color convert pixel [0], [1], [2]. */
        }
        if( convert_alpha != (LWPIXELCONVERSIONALPHA *) NULL ) {
            convert_alpha( instance_alpha, in, out );       /* Alpha convert pixel [3]. */
        }

        /* Out[ 4 ] contains converted to viewer color space pixel. */
    }