Unit CastleColors

Description

Color utilities, including HSV <-> RGB conversion.

Source: base/castlecolors.pas (line 17).

Uses

Overview

Classes, Interfaces, Objects and Records

Name Description
Record TCastleColorHelper  
Record TCastleColorRGBHelper  
Class TCastleColorRGBPersistent TCastleColorRGB record represented as a TPersistent descendant, to be able to visually edit it (in Lazarus and Delphi visual designer, and Castle Game Engine visual designer) and to serialize it.
Class TCastleColorPersistent TCastleColor record represented as a TPersistent descendant, to be able to visually edit it (in Lazarus and Delphi visual designer, and Castle Game Engine visual designer) and to serialize it.
Class TSerializationProcessColorsHelper Helper methods you can use from TCastleComponent.CustomSerialization to manage reading/writing of colors.

Functions and Procedures

function GrayscaleValue(const v: TCastleColorRGB): Single; inline; overload;
function GrayscaleValue(const v: TCastleColor): Single; inline; overload;
function GrayscaleValue(const v: TVector3Byte): Byte; inline; overload;
function GrayscaleValue(const v: TVector4Byte): Byte; inline; overload;
function Grayscale(const v: TCastleColorRGB): TCastleColorRGB; inline; overload;
function Grayscale(const v: TVector3Byte): TVector3Byte; inline; overload;
function Grayscale(const v: TCastleColor): TCastleColor; inline; 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: TVector3): TCastleColorRGB;
function HsvToRgba(const Value: TVector3; const Alpha: Single): TCastleColor;
function RgbToHsv(const Value: TVector3): TVector3; overload;
function RgbToHsv(const Value: TVector3Byte): TVector3; overload; deprecated 'use float-based colors, like TCastleColorRGB and TCastleColor, not Byte-based like TVector3Byte';
function HsvToRgbByte(const Value: TVector3): TVector3Byte; deprecated 'use float-based colors, like TCastleColorRGB and TCastleColor, not Byte-based like TVector3Byte';
function LerpRgbInHsv(const A: Single; const V1, V2: TVector3): TVector3;
function ColorToHex(const V: TCastleColor): String;
function ColorRGBToHex(const V: TCastleColorRGB): string;
function HexToColor(const S: string): TCastleColor;
function HexToColorRGB(const S: string): TCastleColorRGB;
function ColorOpacity(const Color: TCastleColor; const Opacity: Single): TCastleColor;
function FadeDarkColor(const Color: TCastleColor; const FadeIntensity: Single): TCastleColor;
function FadeColor(const Color: TCastleColor; const FadeIntensity: Single): TCastleColor;

Types

TCastleColor = TVector4;
PCastleColor = PVector4;
TCastleColorRGB = TVector3;
PCastleColorRGB = PVector3;
TColorModulatorByteFunc = function (const Color: TVector3Byte): TVector3Byte;

Constants

Maroon : TCastleColor = (X: 0.5; Y: 0.0; Z: 0.0; W: 1.0);
Red : TCastleColor = (X: 1.0; Y: 0.0; Z: 0.0; W: 1.0);
Orange : TCastleColor = (X: 1.0; Y: 0.65; Z: 0.0; W: 1.0);
Yellow : TCastleColor = (X: 1.0; Y: 1.0; Z: 0.0; W: 1.0);
Olive : TCastleColor = (X: 0.5; Y: 0.5; Z: 0.0; W: 1.0);
Purple : TCastleColor = (X: 0.5; Y: 0.0; Z: 0.5; W: 1.0);
Fuchsia: TCastleColor = (X: 1.0; Y: 0.0; Z: 1.0; W: 1.0);
White : TCastleColor = (X: 1.0; Y: 1.0; Z: 1.0; W: 1.0);
Lime : TCastleColor = (X: 0.0; Y: 1.0; Z: 0.0; W: 1.0);
Green : TCastleColor = (X: 0.0; Y: 1.0; Z: 0.0; W: 1.0);
Navy : TCastleColor = (X: 0.0; Y: 0.0; Z: 0.5; W: 1.0);
Blue : TCastleColor = (X: 0.0; Y: 0.0; Z: 1.0; W: 1.0);
Aqua : TCastleColor = (X: 0.0; Y: 1.0; Z: 1.0; W: 1.0);
Teal : TCastleColor = (X: 0.0; Y: 0.5; Z: 0.5; W: 1.0);
Black : TCastleColor = (X: 0.0; Y: 0.0; Z: 0.0; W: 1.0);
Silver : TCastleColor = (X: 0.75; Y: 0.75; Z: 0.75; W: 1.0);
Gray : TCastleColor = (X: 0.5; Y: 0.5; Z: 0.5; W: 1.0);
LightRed : TCastleColor = (X: 1.0; Y: 0.33; Z: 0.33; W: 1.0);
LightGreen: TCastleColor = (X: 0.33; Y: 1.0; Z: 0.33; W: 1.0);
LightBlue : TCastleColor = (X: 0.33; Y: 0.33; Z: 1.0; W: 1.0);
WhiteRGB : TCastleColorRGB = (X: 1.0; Y: 1.0; Z: 1.0);
BlackRGB : TCastleColorRGB = (X: 0.0; Y: 0.0; Z: 0.0);
RedRGB : TCastleColorRGB = (X: 1.0; Y: 0.0; Z: 0.0);
YellowRGB : TCastleColorRGB = (X: 1.0; Y: 1.0; Z: 0.0);
GreenRGB : TCastleColorRGB = (X: 0.0; Y: 1.0; Z: 0.0);
BlueRGB : TCastleColorRGB = (X: 0.0; Y: 0.0; Z: 1.0);
GrayRGB : TCastleColorRGB = (X: 0.5; Y: 0.5; Z: 0.5);
White3Single : TCastleColorRGB = (X: 1.0; Y: 1.0; Z: 1.0) deprecated;
Black3Single : TCastleColorRGB = (X: 0.0; Y: 0.0; Z: 0.0) deprecated;
Red3Single : TCastleColorRGB = (X: 1.0; Y: 0.0; Z: 0.0) deprecated;
Green3Single : TCastleColorRGB = (X: 0.0; Y: 1.0; Z: 0.0) deprecated;
Blue3Single : TCastleColorRGB = (X: 0.0; Y: 0.0; Z: 1.0) deprecated;

Description

Functions and Procedures

function GrayscaleValue(const v: TCastleColorRGB): Single; inline; overload;

Calculate color luminance (intensity), for converting color to grayscale.

Source: base/castlecolors.pas (line 100).

function GrayscaleValue(const v: TCastleColor): Single; inline; overload;

This item has no description.

Source: base/castlecolors.pas (line 101).

function GrayscaleValue(const v: TVector3Byte): Byte; inline; overload;

This item has no description.

Source: base/castlecolors.pas (line 102).

function GrayscaleValue(const v: TVector4Byte): Byte; inline; overload;

This item has no description.

Source: base/castlecolors.pas (line 103).

function Grayscale(const v: TCastleColorRGB): TCastleColorRGB; inline; overload;

This item has no description.

Source: base/castlecolors.pas (line 106).

function Grayscale(const v: TVector3Byte): TVector3Byte; inline; overload;

This item has no description.

Source: base/castlecolors.pas (line 107).

function Grayscale(const v: TCastleColor): TCastleColor; inline; overload;

This item has no description.

Source: base/castlecolors.pas (line 108).

function ColorGrayscaleByte(const Color: TVector3Byte): TVector3Byte;

Convert color to grayscale.

Source: base/castlecolors.pas (line 118).

function ColorRedConvertByte(const Color: TVector3Byte): TVector3Byte;

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

Source: base/castlecolors.pas (line 124).

function ColorGreenConvertByte(const Color: TVector3Byte): TVector3Byte;

This item has no description.

Source: base/castlecolors.pas (line 125).

function ColorBlueConvertByte(const Color: TVector3Byte): TVector3Byte;

This item has no description.

Source: base/castlecolors.pas (line 126).

function ColorRedStripByte(const Color: TVector3Byte): TVector3Byte;

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

Source: base/castlecolors.pas (line 135).

function ColorGreenStripByte(const Color: TVector3Byte): TVector3Byte;

This item has no description.

Source: base/castlecolors.pas (line 136).

function ColorBlueStripByte(const Color: TVector3Byte): TVector3Byte;

This item has no description.

Source: base/castlecolors.pas (line 137).

function HsvToRgb(const Value: TVector3): TCastleColorRGB;

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, we keep components as floating-point values (0..1 range).

Source: base/castlecolors.pas (line 148).

function HsvToRgba(const Value: TVector3; const Alpha: Single): TCastleColor;

This item has no description.

Source: base/castlecolors.pas (line 149).

function RgbToHsv(const Value: TVector3): TVector3; overload;

This item has no description.

Source: base/castlecolors.pas (line 150).

function RgbToHsv(const Value: TVector3Byte): TVector3; overload; deprecated 'use float-based colors, like TCastleColorRGB and TCastleColor, not Byte-based like TVector3Byte';

Warning: this symbol is deprecated: use float-based colors, like TCastleColorRGB and TCastleColor, not Byte-based like TVector3Byte

This item has no description.

Source: base/castlecolors.pas (line 153).

function HsvToRgbByte(const Value: TVector3): TVector3Byte; deprecated 'use float-based colors, like TCastleColorRGB and TCastleColor, not Byte-based like TVector3Byte';

Warning: this symbol is deprecated: use float-based colors, like TCastleColorRGB and TCastleColor, not Byte-based like TVector3Byte

This item has no description.

Source: base/castlecolors.pas (line 154).

function LerpRgbInHsv(const A: Single; const V1, V2: TVector3): TVector3;

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

Source: base/castlecolors.pas (line 157).

function ColorToHex(const V: TCastleColor): String;

Change color into a hexadecimal notation of it (like in HTML). This color includes an alpha channel (as 4th component), and so the output contains the alpha value at the end (so it's 8 hex digits), unless alpha is opaque in which case it's not written (and result is 6 hex digits).

Source: base/castlecolors.pas (line 164).

function ColorRGBToHex(const V: TCastleColorRGB): string;

Change color into a hexadecimal notation of it (like in HTML). This color has no alpha channel, so it's always 6 hex digits.

Source: base/castlecolors.pas (line 169).

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.

Source: base/castlecolors.pas (line 176).

function HexToColorRGB(const S: string): TCastleColorRGB;

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

Exceptions raised
EConvertError
In case of invalid color as string.

Source: base/castlecolors.pas (line 183).

function ColorOpacity(const Color: TCastleColor; const Opacity: Single): TCastleColor;

Change color opacity (alpha).

Source: base/castlecolors.pas (line 186).

function FadeDarkColor(const Color: TCastleColor; const FadeIntensity: Single): TCastleColor;

This item has no description.

Source: base/castlecolors.pas (line 188).

function FadeColor(const Color: TCastleColor; const FadeIntensity: Single): TCastleColor;

This item has no description.

Source: base/castlecolors.pas (line 190).

Types

TCastleColor = TVector4;

This item has no description.

Source: base/castlecolors.pas (line 27).

PCastleColor = PVector4;

This item has no description.

Source: base/castlecolors.pas (line 28).

TCastleColorRGB = TVector3;

This item has no description.

Source: base/castlecolors.pas (line 29).

PCastleColorRGB = PVector3;

This item has no description.

Source: base/castlecolors.pas (line 30).

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

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

Constants

Maroon : TCastleColor = (X: 0.5; Y: 0.0; Z: 0.0; W: 1.0);

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

Source: base/castlecolors.pas (line 49).

Red : TCastleColor = (X: 1.0; Y: 0.0; Z: 0.0; W: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 50).

Orange : TCastleColor = (X: 1.0; Y: 0.65; Z: 0.0; W: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 51).

Yellow : TCastleColor = (X: 1.0; Y: 1.0; Z: 0.0; W: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 52).

Olive : TCastleColor = (X: 0.5; Y: 0.5; Z: 0.0; W: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 53).

Purple : TCastleColor = (X: 0.5; Y: 0.0; Z: 0.5; W: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 54).

Fuchsia: TCastleColor = (X: 1.0; Y: 0.0; Z: 1.0; W: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 55).

White : TCastleColor = (X: 1.0; Y: 1.0; Z: 1.0; W: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 56).

Lime : TCastleColor = (X: 0.0; Y: 1.0; Z: 0.0; W: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 57).

Green : TCastleColor = (X: 0.0; Y: 1.0; Z: 0.0; W: 1.0);

Opaque green, equal to (0,1,0) in RGB.

Note that this constant definition is inconsistent with CSS green constant (which is (0,0.5,0)). Moreover this constant is just equal to Lime. But we consider below "Green" definition more obvious to developers – people expect "green" to have max value in the green channel.

Source: base/castlecolors.pas (line 64).

Navy : TCastleColor = (X: 0.0; Y: 0.0; Z: 0.5; W: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 65).

Blue : TCastleColor = (X: 0.0; Y: 0.0; Z: 1.0; W: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 66).

Aqua : TCastleColor = (X: 0.0; Y: 1.0; Z: 1.0; W: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 67).

Teal : TCastleColor = (X: 0.0; Y: 0.5; Z: 0.5; W: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 68).

Black : TCastleColor = (X: 0.0; Y: 0.0; Z: 0.0; W: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 69).

Silver : TCastleColor = (X: 0.75; Y: 0.75; Z: 0.75; W: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 70).

Gray : TCastleColor = (X: 0.5; Y: 0.5; Z: 0.5; W: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 71).

LightRed : TCastleColor = (X: 1.0; Y: 0.33; Z: 0.33; W: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 75).

LightGreen: TCastleColor = (X: 0.33; Y: 1.0; Z: 0.33; W: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 76).

LightBlue : TCastleColor = (X: 0.33; Y: 0.33; Z: 1.0; W: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 77).

WhiteRGB : TCastleColorRGB = (X: 1.0; Y: 1.0; Z: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 79).

BlackRGB : TCastleColorRGB = (X: 0.0; Y: 0.0; Z: 0.0);

This item has no description.

Source: base/castlecolors.pas (line 80).

RedRGB : TCastleColorRGB = (X: 1.0; Y: 0.0; Z: 0.0);

This item has no description.

Source: base/castlecolors.pas (line 81).

YellowRGB : TCastleColorRGB = (X: 1.0; Y: 1.0; Z: 0.0);

This item has no description.

Source: base/castlecolors.pas (line 82).

GreenRGB : TCastleColorRGB = (X: 0.0; Y: 1.0; Z: 0.0);

This item has no description.

Source: base/castlecolors.pas (line 83).

BlueRGB : TCastleColorRGB = (X: 0.0; Y: 0.0; Z: 1.0);

This item has no description.

Source: base/castlecolors.pas (line 84).

GrayRGB : TCastleColorRGB = (X: 0.5; Y: 0.5; Z: 0.5);

This item has no description.

Source: base/castlecolors.pas (line 85).

White3Single : TCastleColorRGB = (X: 1.0; Y: 1.0; Z: 1.0) deprecated;

Warning: this symbol is deprecated.

Deprecated, use WhiteRGB.

Source: base/castlecolors.pas (line 88).

Black3Single : TCastleColorRGB = (X: 0.0; Y: 0.0; Z: 0.0) deprecated;

Warning: this symbol is deprecated.

Deprecated, use BlackRGB.

Source: base/castlecolors.pas (line 90).

Red3Single : TCastleColorRGB = (X: 1.0; Y: 0.0; Z: 0.0) deprecated;

Warning: this symbol is deprecated.

Deprecated, use RedRGB.

Source: base/castlecolors.pas (line 92).

Green3Single : TCastleColorRGB = (X: 0.0; Y: 1.0; Z: 0.0) deprecated;

Warning: this symbol is deprecated.

Deprecated, use GreenRGB.

Source: base/castlecolors.pas (line 94).

Blue3Single : TCastleColorRGB = (X: 0.0; Y: 0.0; Z: 1.0) deprecated;

Warning: this symbol is deprecated.

Deprecated, use BlueRGB.

Source: base/castlecolors.pas (line 96).


Generated by PasDoc 0.17.0.snapshot.