BGRABitmap Color definitions: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: BGRABitmap Color definitions
| Old | New | Line | |
|---|---|---|---|
| 1 | + | List of color definitions and string conversion functions in [[BGRABitmap]] library. They are provided by [BGRABitmapTypes unit](<https://bgrabitmap.github.io/doc/BGRABitmapTypes.html>). | |
| 2 | + | ||
| 3 | + | ### Color definitions | |
| 4 | + | ||
| 5 | + | _BGRAPixelTransparent_ : TBGRAPixel; | |
| 6 | + | --- | |
| 7 | + | | 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. | |
| 8 | + | _BGRAWhite_ : TBGRAPixel; | |
| 9 | + | | White opaque | |
| 10 | + | _BGRABlack_ : TBGRAPixel; | |
| 11 | + | | Black opaque | |
| 12 | + | _clBlackOpaque_ = TColor($010000); | |
| 13 | + | | 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 | |
| 14 | + | _TBGRAColorList_ = **class** | |
| 15 | + | | Contains a fixed list of colors | |
| 16 | + | | **constructor** Create; | |
| 17 | + | | | Creates an empty color list | |
| 18 | + | | **procedure** Add(Name: **string** ; **const** Color: TBGRAPixel); **overload** ; | |
| 19 | + | | | Add a color to the list | |
| 20 | + | | **procedure** Finished; | |
| 21 | + | | | Ends the color list and prevents further modifications | |
| 22 | + | | **function** IndexOf(Name: **string**): integer; | |
| 23 | + | | | Returns the index of a color with a given name | |
| 24 | + | | **function** IndexOfColor(**const** AColor: TBGRAPixel; AMaxDiff: Word = 0): integer; | |
| 25 | + | | | Returns the index of a color. Colors are considered to match if the difference is less than or equal to _AMaxDiff_ | |
| 26 | + | | **property** ByName[Name: **string**]: TBGRAPixel **read** GetByName; | |
| 27 | + | | | Gets the color associated with a color name | |
| 28 | + | | **property** ByIndex[Index: integer]: TBGRAPixel **read** GetByIndex; **default** ; | |
| 29 | + | | | Gets the color at the specified index | |
| 30 | + | | **property** Name[Index: integer]: **string** **read** GetName; | |
| 31 | + | | | Gets the name of the color at the specified index | |
| 32 | + | | **property** Count: integer **read** FNbColors; | |
| 33 | + | | | Gets the number of colors | |
| 34 | + | _VGAColors_ : TBGRAColorList; | |
| 35 | + | | 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_... | |
| 36 | + | _CSSColors_ : TBGRAColorList; | |
| 37 | + | | List of [web colors](<https://www.w3schools.com/cssref/css_colors.asp>). Shortcut constants are provided: _CSSBlack_ , _CSSRed_... | |
| 38 | + | **function** BGRAToStr(c: TBGRAPixel; AColorList: TBGRAColorList = **nil** ; | |
| 39 | + | | 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_ | |
| 40 | + | **function** StrToBGRA(str: **string**): TBGRAPixel; **overload** ; | |
| 41 | + | | Converts a fully defined string into a TBGRAPixel value. Color names from _VGAColors_ and _CSSColors_ are used if there is an exact match | |
| 42 | + | **function** StrToBGRA(str: **string** ; **const** DefaultColor: TBGRAPixel): TBGRAPixel; **overload** ; | |
| 43 | + | | 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. | |
| 44 | + | **function** PartialStrToBGRA(str: **string** ; **const** fallbackValues: TBGRAPixel; **out** error: boolean): TBGRAPixel; | |
| 45 | + | | 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. | |
| 46 | + | **procedure** TryStrToBGRA(str: **string** ; **var** parsedValue: TBGRAPixel; **out** missingValues: boolean; **out** error: boolean); | |
| 47 | + | | 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. | |
| 48 | + | ||
| 49 | + | ## See also | |
| 50 | + | ||
| 51 | + | * [[BGRABitmap XYZ|Using XYZ colorspace in BGRABitmap]] | |
| 52 | + | ||
| 53 | + | --- | |
| 54 | + | *From the Free Pascal wiki, page "BGRABitmap Color definitions", as the Internet Archive kept it on 2025-05-15. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
