3D Graphics Programming with QuickDraw 3D 1.5.4

Previous | QD3D Book | Overview | Chapter Contents

QuickDraw 3D Color Utilities

This section describes the QuickDraw 3D utilities you can use to handle colors. Because most of these routines return a pointer to an RGB color structure both as a function result and through the result parameter, you can nest these routines.

Q3ColorRGB_Set

You can use the Q3ColorRGB_Set function to set the fields of an RGB color structure.

TQ3ColorRGB *Q3ColorRGB_Set (
                     TQ3ColorRGB *color,
                     float r,
                     float g,
                     float b);
color
On exit, a pointer to an RGB color structure.
r
The red component of the color.
g
The green component of the color.
b
The blue component of the color.

DESCRIPTION

The Q3ColorRGB_Set function returns, as its function result and in the color parameter, a pointer to an RGB color structure whose fields contain the values in the r , g , and b parameters.

Q3ColorARGB_Set

You can use the Q3ColorARGB_Set function to set the fields of an ARGB color structure.

TQ3ColorARGB *Q3ColorARGB_Set (
                     TQ3ColorARGB *color,
                     float a,
                     float r,
                     float g,
                     float b);
color
On exit, a pointer to an ARGB color structure.
a
The alpha channel of the color.
r
The red component of the color.
g
The green component of the color.
b
The blue component of the color.

DESCRIPTION

The Q3ColorARGB_Set function returns, as its function result and in the color parameter, a pointer to an ARGB color structure whose fields contain the values in the a , r , g , and b parameters.

Q3ColorRGB_Add

You can use the Q3ColorRGB_Add function to add two colors.

TQ3ColorRGB *Q3ColorRGB_Add (
                     const TQ3ColorRGB *c1,
                     const TQ3ColorRGB *c2,
                     TQ3ColorRGB *result);
c1
An RGB color structure.
c2
An RGB color structure.
result
On exit, a pointer to an RGB color structure for the color that is the sum of the two specified colors.

DESCRIPTION

The Q3ColorRGB_Add function returns, as its function result and in the result parameter, a pointer to an RGB color structure that represents the sum of the colors specified by the c1 and c2 parameters.

Q3ColorRGB_Subtract

You can use the Q3ColorRGB_Subtract function to subtract one color from another.

TQ3ColorRGB *Q3ColorRGB_Subtract (
                     const TQ3ColorRGB *c1,
                     const TQ3ColorRGB *c2,
                     TQ3ColorRGB *result);
c1
An RGB color structure.
c2
An RGB color structure.
result
On exit, a pointer to an RGB color structure for the color that is the difference of the two specified colors.

DESCRIPTION

The Q3ColorRGB_Subtract function returns, as its function result and in the result parameter, a pointer to an RGB color structure that represents the result of subtracting the color specified by the c2 parameter from the color specified by the c1 parameter.

Q3ColorRGB_Scale

You can use the Q3ColorRGB_Scale function to scale a color.

TQ3ColorRGB *Q3ColorRGB_Scale (
                     const TQ3ColorRGB *color,
                     float scale,
                     TQ3ColorRGB *result);
color
An RGB color structure.
scale
A scaling factor.
result
On exit, a pointer to an RGB color structure for the color that is the scale of the specified color.

DESCRIPTION

The Q3ColorRGB_Scale function returns, as its function result and in the result parameter, a pointer to an RGB color structure that represents the result of scaling the color specified by the color parameter by the factor specified by the scale parameter.

Q3ColorRGB_Clamp

You can use the Q3ColorRGB_Clamp function to clamp a color.

TQ3ColorRGB *Q3ColorRGB_Clamp (
                     const TQ3ColorRGB *color,
                     TQ3ColorRGB *result);
color
An RGB color structure.
result
On exit, a pointer to an RGB color structure for the color that is the clamped version of the specified color.

DESCRIPTION

The Q3ColorRGB_Clamp function returns, as its function result and in the result parameter, a pointer to an RGB color structure that clamps each component of the color specified by the color parameter. A clamped component lies between 0.0 and 1.0, inclusive.

Q3ColorRGB_Lerp

You can use the Q3ColorRGB_Lerp function to interpolate two colors linearly.

TQ3ColorRGB *Q3ColorRGB_Lerp (
                     const TQ3ColorRGB *first,
                     const TQ3ColorRGB *last,
                     float alpha,
                     TQ3ColorRGB *result);
first
An RGB color structure.
last
An RGB color structure.
alpha
An alpha value.
result
On exit, a pointer to an RGB color structure for the color that is the linear interpolation, by the specified alpha value, of the two specified colors.

DESCRIPTION

The Q3ColorRGB_Lerp function returns, as its function result and in the result parameter, a pointer to an RGB color structure that is linearly interpolated between the two colors specified by the first and last parameters. The alpha parameter specifies the desired alpha value for the interpolation.

Q3ColorRGB_Accumulate

You can use the Q3ColorRGB_Accumulate function to accumulate colors.

TQ3ColorRGB *Q3ColorRGB_Accumulate (
                     const TQ3ColorRGB *src,
                     TQ3ColorRGB *result);
src
An RGB color structure.
result
On entry, an RGB color structure. On exit, a pointer to an RGB color structure for the color that is the result of adding the source color to the result color.

DESCRIPTION

The Q3ColorRGB_Accumulate function returns, as its function result and in the result parameter, a pointer to an RGB color structure that is the result of adding the color specified by the src parameter to the color specified by the result parameter.

Q3ColorRGB_Luminance

You can use the Q3ColorRGB_Luminance function to compute the luminance of a color.

float *Q3ColorRGB_Luminance (
                     const TQ3ColorRGB *color,
                     float *luminance);
color
An RGB color structure.
luminance
On exit, the luminance of the specified color.

DESCRIPTION

The Q3ColorRGB_Luminance function returns, as its function result and in the luminance parameter, the luminance of the color specified by the color parameter. A color's luminance is computed using this formula:

luminance =              (0.30078125 color.r ) + (0.58984375 color.g ) + (0.109375 color.b )

 

 


© 1997 Apple Computer, Inc.

Previous | QD3D Book | Overview | Chapter Contents