Index

NAME

ColorScale  -  Collection  of color-related definitions and func­
tions


INCLUDE

include "ColorScale.h"

SYNTAX

 struct Colors
 {
   real r, g, b;   // basic colors

   Colors ()                                            { r=g=b=0; }

   Colors (real c)                                   { r=g=b=c; }
   Colors (real rr, double gg, double bb)           { r=rr; g=gg; b=bb; }
   Colors (const Colors& c)                           { r=c.r; g=c.g; b=c.b; }

   void operator = (const Colors& c)                { r=c.r; g=c.g; b=c.b; }

   void setColors (const Colors& c)                 { r=c.r; g=c.g; b=c.b; }
   void setColors (real rr, real gg, real bb)       { r=rr; g=gg; b=bb; }
   void setColors (real c)                          { r=g=b=c; }

   void print (Os out) {
     out->getFormat()==BINARY?out<<r<<g<<b:out<<r<<nl<<g<<nl<<b<<nl; }
   void scan  (Is in )                              { in >> r >> b >> g; }

   bool isBlack()         { return getbool(r==0 && g==0 && b==0); }
   bool isWhite()         { return getbool(r==g && g==b && b==r); }
 };


SYNTAX

 struct ColorScale
 {
   Colors low;
   Colors high;

   real min_value;
   real max_value;


   void rgb2ihs
      (
       const real& r,
       const real& g,
       const real& b,
             real& i,
             real& h,
             real& s
      );

   void ihs2rgb
      (
       const real& i,
       const real& h,
       const real& s,
             real& r,
             real& g,
             real& b
      );

   Colors ihs_interpolation
      (
       const real& value
      );



   void rgb2cie
      (
       const real& r,
                const real& g,
                const real& b,
                      real& x,
                      real& y,
                      real& z
      );

   void cie2rgb
      (
       const real& l,
       const real& u,
       const real& v,
             real& x,
             real& y,
             real& z
      );

   Colors cie_interpolation
      (
       const real& value
      );



   void rgb2luv
      (
       const real& r,
       const real& g,
       const real& b,
             real& l,
             real& u,
             real& v
      );

   void luv2rgb
      (
       const real& l,
       const real& u,
       const real& v,
             real& r,
             real& g,
             real& b
      );

   Colors luv_interpolation
      (
       const real& value
      );



   // returns a color based on min/max/value/high/low.
   Colors getColor
      (
       const real& value,
       const char* colorspace = "CIE" // uses char* to allow default value
      );
 };



KEYWORDS

color scales, color conversion, color spaces, RGB, IHS, CIE, LUV



DESCRIPTION

The structs implement several useful functions for  interpolation
in and conversion of color scales.

The  Colors struct contains a (r,g,b) color, and basic functions.

The  ColorScale  struct  contains  two  floating   point   values
(min_value,  max_value) and two colors (low, high). The low color
is associated with the minimum value, and the high color is asso­
ciated  with  the  maximum value.  Functions for color conversion
between RGB and the color spaces IHS, CIE and LUV are  available.
A  floating  point  value  between min_value and max_value can be
given to find an associated color. The color is  found  using  an
interpolation in one of the above color spaces, based on the val­
ues of the data members of the struct,  and  the  given  floating
point value.



CONSTRUCTORS AND INITIALIZATION

Colors()  -  Creates  a  color  object  with  default color black
(r=g=b=0).

Colors(float intensity) - Creates a color object  with  specified
intensity.  (r=g=b=intensity)

Colors(float r, float g, float b) - Creates a color object with a
specified RGB color.

Colors(Colors&) - Copy constructor.

ColorScale() - No constructor, data members must be  set  explic­
itly.



MEMBER FUNCTIONS

rgb2ihs - converts a RGB color to an IHS color.

ihs2rgb - converts an IHS color to a RGB color.

ihs_interpolation  -  Performs  an interpolation in the IHS color
space to find a color corresponding to a specified value and  the
values of the data members of the struct.

rgb2cie - converts a RGB color to a CIE color.

cie2rgb - converts a CIE color to a RGB color.

cie_interpolation  -  Performs  an interpolation in the CIE color
space to find a color corresponding to a specified value and  the
values of the data members of the struct.

rgb2luv - converts a RGB color to a LUV color.

luv2rgb - converts a LUV color to a RGB color.

luv_interpolation  -  Performs  an interpolation in the LUV color
space to find a color corresponding to a specified value and  the
values of the data members of the struct.

getColor  -  Performs  an  interpolation  in the one of the color
spaces to find a color corresponding to a specified value and the
values  of  the  data  members of the struct.  The selected color
space is specified as a parameter (IHS, CIE or LUV).



DEVELOPED BY

SINTEF Applied Mathematics, Oslo, Norway, and University of Oslo,
Dept. of Mathematics, Norway


AUTHOR

Fred Ivar Larsen, SINTEF/UiO.