BGRABitmap Pixel types
From Free Pascal wiki
Jump to navigationJump to search
│ English (en) │ русский (ru) │
List of pixel types and functions of BGRABitmap library. They are provided by BGRABitmapTypes unit.
Pixel types and functions
PBGRAPixel = ^TBGRAPixel; | ||
Pointer for direct pixel access. Data is stored as a sequence of TBGRAPixel. See Tutorial 4 | ||
TBGRAPixel = packed record | ||
Each pixel is a sequence of 4 bytes containing blue, green, red and alpha channel. Values range from 0 to 255, color is in sRGB colorspace. The alpha value of 0 is transparent and 255 is opaque. In the bitmap data, when the pixel is fully transparent, the RGB values are supposed to be set to zero. | ||
red, green, blue, alpha: byte; | ||
Fields if ordered RGBA ordered | ||
blue, green, red, alpha: byte; | ||
Fields if ordered BGRA ordered | ||
procedure FromRGB(ARed,AGreen,ABlue: Byte; AAlpha: Byte = 255); | ||
Sets the pixel with given RGB values | ||
procedure FromColor(AColor: TColor; AAlpha: Byte = 255); | ||
Sets the pixel with given TColor | ||
procedure FromString(AStr: string); | ||
Sets the pixel according to a color name or CSS expression | ||
procedure FromFPColor(AColor: TFPColor); | ||
Sets the pixel with given TFPColor (16-bit per channel) | ||
procedure ToRGB(out ARed,AGreen,ABlue,AAlpha: Byte); overload; | ||
Extras RGBA channels | ||
procedure ToRGB(out ARed,AGreen,ABlue: Byte); overload; | ||
Extras RGB channels | ||
function ToColor: TColor; | ||
Converts to TColor | ||
function ToString: string; | ||
Converts to a CSS string representation | ||
function ToGrayscale(AGammaCorrection: boolean = true): TBGRAPixel; | ||
Compute grayscale equivalent | ||
function ToFPColor: TFPColor; | ||
Converts to TFPColor (16-bit per channel) | ||
function EqualsExactly(constref AColor: TBGRAPixel): boolean; | ||
Check whether all channels are equal (this is generally not necessary to use this fonction unless the RGB value of a transparent color matter) | ||
class operator := (Source: TBGRAPixel): TColor; | ||
Assign a TBGRAPixel to a TColor | ||
class operator := (Source: TColor): TBGRAPixel; | ||
Assign a TColor to a TBGRAPixel | ||
property Intensity: word read GetClassIntensity write SetClassIntensity; | ||
Intensity of the color (how much channels are saturated) | ||
property Lightness: word read GetClassLightness write SetClassLightness; | ||
Lightness of the color (the resulting lightness of combined channels) | ||
operator = (const c1, c2: TBGRAPixel): boolean; inline; | ||
Checks if two pixels are equal. If they are both transparent, RGB values are ignored | ||
const TBGRAPixel_RGBAOrder = False; | ||
Order of the channels (when BGRA) | ||
const TBGRAPixel_BlueByteOffset = 0; | ||
Offset of the blue channel (when BGRA) | ||
const TBGRAPixel_GreenByteOffset = 1; | ||
Offset of the green channel (when BGRA) | ||
const TBGRAPixel_RedByteOffset = 2; | ||
Offset of the blue channel (when BGRA) | ||
const TBGRAPixel_AlphaByteOffset = 3; | ||
Offset of the alpha channel | ||
function BGRA(red, green, blue, alpha: byte): TBGRAPixel; overload; inline; | ||
Creates a pixel with given RGBA values | ||
function BGRA(red, green, blue: byte): TBGRAPixel; overload; inline; | ||
Creates a opaque pixel with given RGB values | ||
function GetIntensity(c: TBGRAPixel): word; inline; | ||
Returns the intensity of a pixel. The intensity is the maximum value reached by any component | ||
function SetIntensity(c: TBGRAPixel; intensity: word): TBGRAPixel; | ||
Sets the intensity of a pixel | ||
function GetLightness(c: TBGRAPixel): word; overload; | ||
Returns the lightness of a pixel. The lightness is the perceived brightness, 0 being black and 65535 being white | ||
function SetLightness(c: TBGRAPixel; lightness: word): TBGRAPixel; overload; | ||
Sets the lightness of a pixel | ||
function ApplyLightnessFast(color: TBGRAPixel; lightness: word): TBGRAPixel; inline; | ||
Sets the lightness quickly, by fading towards black if lightness is less than 32768, and fading towards white if lightness is more than 32768 | ||
function ApplyIntensityFast(color: TBGRAPixel; lightness: LongWord): TBGRAPixel; | ||
Sets the intensity quickly, by fading towards black if lightness is less than 32768, and multiplying all components if lightness is more than 32768. In case of saturation, it fades towards white | ||
function CombineLightness(lightness1,lightness2: Int32or64): Int32or64; | ||
Combines two lightnesses together. A value of 32768 is neutral. The result may exceed 65535 | ||
function BGRAToGrayscale(c: TBGRAPixel): TBGRAPixel; | ||
Converts a color into grayscale | ||
function BGRAToGrayscaleLinear(c: TBGRAPixel): TBGRAPixel; | ||
Converts a color into grayscale assuming linear colorspace | ||
function GrayscaleToBGRA(lightness: word): TBGRAPixel; | ||
Create a gray color with the given lightness | ||
function MergeBGRA(c1, c2: TBGRAPixel): TBGRAPixel; overload; | ||
Merge two colors without gamma correction | ||
function MergeBGRA(c1: TBGRAPixel; weight1: integer; c2: TBGRAPixel; weight2: integer): TBGRAPixel; overload; | ||
Merge two colors without gamma correction. weight1 and weight2 indicates the weight of the color barycentre | ||
function MergeBGRAWithGammaCorrection(c1: TBGRAPixel; weight1: byte; c2: TBGRAPixel; weight2: byte): TBGRAPixel; | ||
Merge two colors with gamma correction. weight1 and weight2 indicates the weight of the color barycentre | ||
function ColorToBGRA(color: TColor): TBGRAPixel; overload; | ||
Converts a TColor value into an opaque pixel | ||
function ColorToBGRA(color: TColor; opacity: byte): TBGRAPixel; overload; | ||
Converts a TColor value into a pixel with given opacity | ||
function BGRAToColor(c: TBGRAPixel): TColor; | ||
Converts a pixel into a TColor value, discarding the alpha value | ||
function FastRoundDiv257(valueWord: LongWord): byte; inline; | ||
Fonction to divide by 257 (not quite the same as shr 8) | ||
function FPColorToBGRA(AValue: TFPColor): TBGRAPixel; | ||
Converts a TFPColor value into a pixel. Note that even if TFPColor have 16-bit values, they are not considered as gamma expanded | ||
function BGRAToFPColor(AValue: TBGRAPixel): TFPColor; inline; | ||
Converts a pixel into a TFPColor | ||
function Color16BitToBGRA(AColor: Word): TBGRAPixel; | ||
Converts a 16-bit packed color into a TBGRAPixel | ||
function BGRAToColor16Bit(const AColor: TBGRAPixel): Word; | ||
Converts a TBGRAPixel into a 16-bit packed color | ||
function BGRAWordDiff(c1, c2: TBGRAPixel): word; | ||
Computes the difference (with gamma correction) between two pixels, taking into account all dimensions, including transparency. The result ranges from 0 to 65535 | ||
function BGRADiff(c1, c2: TBGRAPixel): byte; | ||
Computes the difference (with gamma correction) between two pixels, taking into account all dimensions, including transparency. The result ranges from 0 to 255 | ||
function FastBGRALinearDiff(c1,c2: TBGRAPixel): byte; | ||
Fast computation of difference, without weighing the alpha channel and without gamma correction | ||
function FastBGRAExpandedDiff(c1,c2: TBGRAPixel): word; | ||
Fast computation of difference, without weighing the alpha channel | ||
function MapHeight(Color: TBGRAPixel): Single; | ||
Get height [0..1] stored in a TBGRAPixel | ||
function MapHeightToBGRA(Height: Single; Alpha: Byte): TBGRAPixel; | ||
Get TBGRAPixel to store height [0..1] | ||
TBGRAPixelBuffer = packed array of TBGRAPixel; | ||
Array of TBGRAPixel to be used as a buffer | ||
procedure AllocateBGRAPixelBuffer(var ABuffer: TBGRAPixelBuffer; ASize: integer); | ||
Allocate a buffer of TBGRAPixel | ||
ArrayOfTBGRAPixel = array of TBGRAPixel; | ||
Array of pixels, not to be used as a buffer | ||
function MergeBGRA(const colors: array of TBGRAPixel): TBGRAPixel; overload; | ||
Merge given colors without gamma correction | ||
TDrawMode = ( | ||
Possible modes when drawing a pixel over another one | ||
dmSet, | ||
The pixel is replaced | ||
dmSetExceptTransparent, | ||
The pixel is replaced if the pixel over has an alpha value of 255 | ||
dmLinearBlend, | ||
The pixel is blend over the other one according to alpha values, however no gamma correction is applied. In other words, the color space is assumed to be linear | ||
dmDrawWithTransparency, | ||
The pixel is blend over the other one according to alpha values, and a gamma correction is applied. In other word, the color space is assumed to be sRGB | ||
dmXor); | ||
Values of all channels are combined with Xor. This is useful to compute the binary difference, however it is not something that makes much sense to display on the screen | ||
dmFastBlend = dmLinearBlend; | ||
An alias for the linear blend, because it is faster than blending with gamma correction | ||
TBlendOperation = ( | ||
Advanced blending modes. See Paint.NET blend modes and Formulas. Blending layers has two steps. The first one is to apply the blend operations listed below, and the second is the actual merging of the colors | ||
boLinearBlend, | ||
Simple blend, except that it forces a linear merge so it is equivalent to dmLinearBlend | ||
boTransparent, | ||
Simple blend. It is equivalent to dmLinearBlend or dmDrawWithTransparency | ||
boLighten, boScreen, boAdditive, boLinearAdd, boColorDodge, boDivide, boNiceGlow, boSoftLight, boHardLight, | ||
Lighting blend modes (tends to increase the luminosity) | ||
boGlow, boReflect, boOverlay, boDarkOverlay, boDarken, boMultiply, boColorBurn, | ||
Masking blend modes (tends to decrease the luminosity) | ||
boDifference, boLinearDifference, boExclusion, boLinearExclusion, boSubtract, boLinearSubtract, boSubtractInverse, boLinearSubtractInverse, | ||
Difference blend modes | ||
boNegation, boLinearNegation, | ||
Negation blend modes | ||
boXor, | ||
Xor blend mode. It is sightly different from dmXor because the alpha value is used like in other blends modes | ||
boSvgSoftLight, | ||
SVG implementation of soft light | ||
boMask, | ||
Apply mask | ||
boLinearMultiplySaturation, boLinearHue, boLinearColor, boLinearLightness, boLinearSaturation, | ||
Standard HSL colorspace | ||
boCorrectedHue, boCorrectedColor, boCorrectedLightness, boCorrectedSaturation | ||
Corrected HSL colorspace (GSB) | ||
boGlowMask = boGlow; | ||
Alias to glow that express that this blend mode masks the part where the top layer is black | ||
boLinearMultiply = boMultiply; | ||
Alias because linear or non linear multiply modes are identical | ||
boNonLinearOverlay = boDarkOverlay; | ||
Alias to express that dark overlay is simply an overlay with gamma correction | ||
BlendOperationStr : array[TBlendOperation] of string | ||
String constants for blend modes | ||
function StrToBlendOperation(str: string): TBlendOperation; | ||
Returns the blend mode expressed by the string | ||
TAlphaChannelPaletteOption = ( | ||
Specifies how a palette handles the alpha channel | ||
acIgnore, | ||
The alpha channel is ignored. The alpha channel is considered to be stored elsewhere | ||
acTransparentEntry, | ||
One entry is allocated the fully transparent color | ||
acFullChannelInPalette); | ||
The alpha channel is fully embedded in the palette so that a color is identified by its four RGBA channels | ||
TDitheringAlgorithm = ( | ||
Dithering algorithms that specifies how to handle colors that are not found in the palette | ||
daNearestNeighbor, | ||
The nearest color is to be used instead | ||
daFloydSteinberg); | ||
The nearest color may be used however another color may be used to compensate for the error, following Floyd-Steinberg algorithm | ||