Unit CastleColors

DescriptionUsesClasses, Interfaces, Objects and RecordsFunctions and ProceduresTypesConstantsVariables

Description

Color utilities, including HSV <-> RGB convertion.

Uses

Overview

Functions and Procedures

function GrayscaleValue(const v: TVector3Single): Single; overload;
function GrayscaleValue(const v: TVector3Byte): Byte; overload;
function GrayscaleValue(const v: TCastleColor): Single; overload;
function Grayscale(const v: TVector3Single): TVector3Single; overload;
function Grayscale(const v: TVector3Byte): TVector3Byte; overload;
function Grayscale(const v: TCastleColor): TCastleColor; overload;
function ColorGrayscaleByte(const Color: TVector3Byte): TVector3Byte;
function ColorRedConvertByte(const Color: TVector3Byte): TVector3Byte;
function ColorGreenConvertByte(const Color: TVector3Byte): TVector3Byte;
function ColorBlueConvertByte(const Color: TVector3Byte): TVector3Byte;
function ColorRedStripByte(const Color: TVector3Byte): TVector3Byte;
function ColorGreenStripByte(const Color: TVector3Byte): TVector3Byte;
function ColorBlueStripByte(const Color: TVector3Byte): TVector3Byte;
function HsvToRgb(const Value: TVector3Single): TVector3Single;
function RgbToHsv(const Value: TVector3Single): TVector3Single;
function RgbToHsv(const Value: TVector3Byte): TVector3Single;
function HsvToRgbByte(const Value: TVector3Single): TVector3Byte;
function LerpRgbInHsv(const A: Single; const V1, V2: TVector3Single): TVector3Single;
function ColorToHex(const V: TCastleColor): string;
function HexToColor(const S: string): TCastleColor;

Types

TCastleColor = TVector4Single;
TColorModulatorByteFunc = function (const Color: TVector3Byte): TVector3Byte;

Constants

Maroon : TCastleColor = ( 0.5 , 0.0 , 0.0 , 1.0);
Red : TCastleColor = ( 1.0 , 0.0 , 0.0 , 1.0);
Orange : TCastleColor = ( 1.0 , 0.65, 0.0 , 1.0);
Yellow : TCastleColor = ( 1.0 , 1.0 , 0.0 , 1.0);
Olive : TCastleColor = ( 0.5 , 0.5 , 0.0 , 1.0);
Purple : TCastleColor = ( 0.5 , 0.0 , 0.5 , 1.0);
Fuchsia: TCastleColor = ( 1.0 , 0.0 , 1.0 , 1.0);
White : TCastleColor = ( 1.0 , 1.0 , 1.0 , 1.0);
Lime : TCastleColor = ( 0.0 , 1.0 , 0.0 , 1.0);
Green : TCastleColor = ( 0.0 , 0.5 , 0.0 , 1.0);
Navy : TCastleColor = ( 0.0 , 0.0 , 0.5 , 1.0);
Blue : TCastleColor = ( 0.0 , 0.0 , 1.0 , 1.0);
Aqua : TCastleColor = ( 0.0 , 1.0 , 1.0 , 1.0);
Teal : TCastleColor = ( 0.0 , 0.5 , 0.5 , 1.0);
Black : TCastleColor = ( 0.0 , 0.0 , 0.0 , 1.0);
Silver : TCastleColor = ( 0.75, 0.75, 0.75, 1.0);
Gray : TCastleColor = ( 0.5 , 0.5 , 0.5 , 1.0);
LightGreen: TCastleColor = ( 0.33, 1.0 , 0.33, 1.0);
LightBlue : TCastleColor = ( 0.33, 0.33, 1.0 , 1.0);
White3Single : TVector3Single = ( 1.0 , 1.0 , 1.0);
Black3Single : TVector3Single = ( 0.0 , 0.0 , 0.0);
Red3Single : TVector3Single = ( 1.0 , 0.0 , 0.0);
Green3Single : TVector3Single = ( 0.0 , 0.5 , 0.0);
Blue3Single : TVector3Single = ( 0.0 , 0.0 , 1.0);

Description

Functions and Procedures

function GrayscaleValue(const v: TVector3Single): Single; overload;

Calculate color intensity, for converting color to grayscale.

function GrayscaleValue(const v: TVector3Byte): Byte; overload;
 
function GrayscaleValue(const v: TCastleColor): Single; overload;
 
function Grayscale(const v: TVector3Single): TVector3Single; overload;
 
function Grayscale(const v: TVector3Byte): TVector3Byte; overload;
 
function Grayscale(const v: TCastleColor): TCastleColor; overload;
 
function ColorGrayscaleByte(const Color: TVector3Byte): TVector3Byte;

Convert color to grayscale.

function ColorRedConvertByte(const Color: TVector3Byte): TVector3Byte;

Place color intensity (calculated like for grayscale) into the given color component. Set the other components zero.

function ColorGreenConvertByte(const Color: TVector3Byte): TVector3Byte;
 
function ColorBlueConvertByte(const Color: TVector3Byte): TVector3Byte;
 
function ColorRedStripByte(const Color: TVector3Byte): TVector3Byte;

Set color values for two other channels to 0. Note that it's something entirely different than ImageConvertToChannelTo1st: here we preserve original channel values, and remove values on two other channels.

function ColorGreenStripByte(const Color: TVector3Byte): TVector3Byte;
 
function ColorBlueStripByte(const Color: TVector3Byte): TVector3Byte;
 
function HsvToRgb(const Value: TVector3Single): TVector3Single;

Converting between RGB and HSV. For HSV, we keep components as floating-point values, with hue in 0..6 range, saturation and value in 0..1. For RGB, one version keeps components as bytes (0..255 range), and the other as floating-point values (0..1 range).

function RgbToHsv(const Value: TVector3Single): TVector3Single;
 
function RgbToHsv(const Value: TVector3Byte): TVector3Single;
 
function HsvToRgbByte(const Value: TVector3Single): TVector3Byte;
 
function LerpRgbInHsv(const A: Single; const V1, V2: TVector3Single): TVector3Single;

Given two colors in RGB, interpolate them in HSV space.

function ColorToHex(const V: TCastleColor): string;

Change color into a hexadecimal notation of it (like in HTML). Note that version it takes 4-component vector and adds the alpha too at the end.

function HexToColor(const S: string): TCastleColor;

Convert hexadecimal color notation (like in HTML) into an RGBA color. Handles 8 or 6 digit color (RGB or RGBA with 2 letters per component; for 6 digits, alpha is assumed to be 1.0 (opaque)).

Exceptions raised
EConvertError
In case of invalid color as string.

Types

TCastleColor = TVector4Single;
 
TColorModulatorByteFunc = function (const Color: TVector3Byte): TVector3Byte;

Function that processes RGB colors, used by TCastleImage.ModulateRGB.

Constants

Maroon : TCastleColor = ( 0.5 , 0.0 , 0.0 , 1.0);

Common color constants, for comfort. They follow the CSS colors constants [http://www.w3.org/TR/CSS21/syndata.html#color-units].

Red : TCastleColor = ( 1.0 , 0.0 , 0.0 , 1.0);
 
Orange : TCastleColor = ( 1.0 , 0.65, 0.0 , 1.0);
 
Yellow : TCastleColor = ( 1.0 , 1.0 , 0.0 , 1.0);
 
Olive : TCastleColor = ( 0.5 , 0.5 , 0.0 , 1.0);
 
Purple : TCastleColor = ( 0.5 , 0.0 , 0.5 , 1.0);
 
Fuchsia: TCastleColor = ( 1.0 , 0.0 , 1.0 , 1.0);
 
White : TCastleColor = ( 1.0 , 1.0 , 1.0 , 1.0);
 
Lime : TCastleColor = ( 0.0 , 1.0 , 0.0 , 1.0);
 
Green : TCastleColor = ( 0.0 , 0.5 , 0.0 , 1.0);
 
Navy : TCastleColor = ( 0.0 , 0.0 , 0.5 , 1.0);
 
Blue : TCastleColor = ( 0.0 , 0.0 , 1.0 , 1.0);
 
Aqua : TCastleColor = ( 0.0 , 1.0 , 1.0 , 1.0);
 
Teal : TCastleColor = ( 0.0 , 0.5 , 0.5 , 1.0);
 
Black : TCastleColor = ( 0.0 , 0.0 , 0.0 , 1.0);
 
Silver : TCastleColor = ( 0.75, 0.75, 0.75, 1.0);
 
Gray : TCastleColor = ( 0.5 , 0.5 , 0.5 , 1.0);
 
LightGreen: TCastleColor = ( 0.33, 1.0 , 0.33, 1.0);
 
LightBlue : TCastleColor = ( 0.33, 0.33, 1.0 , 1.0);
 
White3Single : TVector3Single = ( 1.0 , 1.0 , 1.0);
 
Black3Single : TVector3Single = ( 0.0 , 0.0 , 0.0);
 
Red3Single : TVector3Single = ( 1.0 , 0.0 , 0.0);
 
Green3Single : TVector3Single = ( 0.0 , 0.5 , 0.0);
 
Blue3Single : TVector3Single = ( 0.0 , 0.0 , 1.0);