BGRABitmap Color definitions

From Free Pascal wiki
Jump to: navigation, search

List of color definitions and string conversion functions in BGRABitmap library. They are provided by BGRABitmapTypes unit.

Color definitions

BGRAPixelTransparent: TBGRAPixel = (blue: 0; green: 0; red: 0; alpha: 0);
This is the value used for transparent pixels. In theory, any color with alpha = 0 is transparent, however it is recommended to use all other channels to zero as well.
BGRAWhite: TBGRAPixel = (blue: 255; green: 255; red: 255; alpha: 255);
White opaque
BGRABlack: TBGRAPixel = (blue: 0; green: 0; red: 0; alpha: 255);
Black opaque
clBlackOpaque = TColor($010000);
This color looks just like black. It is needed for drawing black shapes using the Canvas property of TBGRABitmap. This is a standard TCanvas and when drawing with pure black (clBlack), there is no way to know if something has been drawn or if it is transparent
TBGRAColorList = class
Contains a fixed list of colors
constructor Create;
Creates an empty color list
procedure Add(Name: string; const Color: TBGRAPixel);
Add a color to the list
procedure Finished;
Ends the color list and prevents further modifications
function IndexOf(Name: string): integer;
Returns the index of a color with a given name
function IndexOfColor(const AColor: TBGRAPixel; AMaxDiff: Word = 0): integer;
Returns the index of a color. Colors are considered to match if the difference is less than or equal to AMaxDiff
property ByName[Name: string]: TBGRAPixel read;
Gets the color associated with a color name
property ByIndex[Index: integer]: TBGRAPixel read;
Gets the color at the specified index
property Name[Index: integer]: string read;
Gets the name of the color at the specified index
property Count: integer read;
Gets the number of colors
VGAColors: TBGRAColorList;
List of VGA colors:
Black, Gray, Silver, White,
Maroon, Red, Purple, Fuchsia,
Green, Lime, Olive, Yellow,
Navy, Blue, Teal, Aqua.
Shortcut constants are provided: VGABlack, VGAGray...
CSSColors: TBGRAColorList;
List of web colors. Shortcut constants are provided: CSSBlack, CSSRed...
function BGRAToStr(c: TBGRAPixel; AColorList: TBGRAColorList = nil; AMaxDiff: Word= 0): string;
Converts a TBGRAPixel value into a string, using color names provided in AColorList, and considering that a color matches in the color list if its difference is within AMaxDiff
function StrToBGRA(str: string): TBGRAPixel;
Converts a fully defined string into a TBGRAPixel value. Color names from VGAColors and CSSColors are used if there is an exact match
function StrToBGRA(str: string; const DefaultColor: TBGRAPixel): TBGRAPixel;
Converts a string into a TBGRAPixel value. If the value is not fully defined or that there is an error, DefaultColor is returned. Color names from VGAColors and CSSColors are used if there is an exact match.
function PartialStrToBGRA(str: string; const fallbackValues: TBGRAPixel; out error: boolean): TBGRAPixel;
Converts a string into a TBGRAPixel value. If the value is not fully defined, missing channels (expressed with '?') are filled with fallbackValues. You can check if there was an error with the provided boolean. Color names from VGAColors and CSSColors are used if there is an exact match.
procedure TryStrToBGRA(str: string; var parsedValue: TBGRAPixel; out missingValues: boolean; out error: boolean);
Converts a string into a TBGRAPixel value into parsedValue. parsedValue is not changed if some channels are missing (expressed with '?'). You can check if there was an error with the provided boolean. Color names from VGAColors and CSSColors are used if there is an exact match.