BGRABitmap Miscellaneous types

From Free Pascal wiki
Jump to navigationJump to search

Miscellaneous types in BGRABitmap. They are provided by BGRABitmapTypes unit.

Miscellaneous types

const BGRABitmapVersion = 11050800;
Current version expressed as an integer with each part multiplied by 100
function BGRABitmapVersionStr: string;
String representation of the version, numbers separated by dots
TMultiFileContainer = BGRAMultiFileType.TMultiFileContainer;
Generic definition of a multifile container
Int32or64 = BGRAClasses.Int32or64;
Signed integer value of at least 32 bits
UInt32or64 = BGRAClasses.UInt32or64;
Unsigned integer value of at least 32 bits
HDC = {$ifdef BGRABITMAP_USE_LCL}LCLType.HDC{$else}PtrUInt{$endif};
Device context handle (using LCL if available)
TFloodfillMode = (
Options when doing a floodfill (also called bucket fill)
fmSet,
Pixels that are filled are replaced
fmDrawWithTransparency,
Pixels that are filled are drawn upon with the fill color
fmLinearBlend,
Pixels that are filled are drawn without gamma correction upon with the fill color
fmXor,
Pixels that are XORed with the fill color
fmProgressive);
Pixels that are filled are drawn upon to the extent that the color underneath is similar to the start color. The more different the different is, the less it is drawn upon
TMedianOption = (moNone, moLowSmooth, moMediumSmooth, moHighSmooth);
Specifies how much smoothing is applied to the computation of the median
TRadialBlurType = (
Specifies the shape of a predefined blur
rbNormal,
Gaussian-like, pixel importance decreases progressively
rbDisk,
Disk blur, pixel importance does not decrease progressively
rbCorona,
Pixel are considered when they are at a certain distance
rbPrecise,
Gaussian-like, but 10 times smaller than rbNormal
rbFast,
Gaussian-like but simplified to be computed faster
rbBox);
Box blur, pixel importance does not decrease progressively and the pixels are included when they are in a square. This is much faster than rbFast however you may get square shapes in the resulting image
const RadialBlurTypeToStr: array[TRadialBlurType] of string =
String constants to represent TRadialBlurType values
TEmbossOption = (
Possible options when applying emboss filter
eoTransparent,
Transparent output except when there borders were detected
eoPreserveHue);
Preserve the original hue
TEmbossOptions = set of TEmbossOption;
Sets of emboss options
TBGRAImageFormat = (
List of image formats
ifUnknown,
Unknown format
ifJpeg,
JPEG format, opaque, lossy compression
ifPng,
PNG format, transparency, lossless compression. Can be animated (see BGRAAnimatedGif)
ifGif,
GIF format, single transparent color, lossless in theory but only low number of colors allowed. Can be animated (see BGRAAnimatedGif)
ifBmp,
BMP format, transparency, no compression. Note that transparency is not supported by all BMP readers so it is recommended to avoid storing images with transparency in this format
ifBmpMioMap,
iGO BMP (16-bit, rudimentary lossless compression)
ifIco,
ICO format, contains different sizes of the same image
ifCur,
CUR format, has hotspot, contains different sizes of the same image
ifPcx,
PCX format, opaque, rudimentary lossless compression
ifPaintDotNet,
Paint.NET format, layers, lossless compression
ifLazPaint,
LazPaint format, layers, lossless compression
ifOpenRaster,
OpenRaster format, layers, lossless compression
ifPhoxo,
Phoxo format, layers
ifPsd,
Photoshop format, layers, rudimentary lossless compression
ifTarga,
Targa format (TGA), transparency, rudimentary lossless compression
ifTiff,
TIFF format, limited support
ifXwd,
X-Window capture, limited support
ifXPixMap,
X-Pixmap, text encoded image, limited support
ifPortableAnyMap,
text or binary encoded image, no compression, extension PBM, PGM, PPM
ifSvg,
Scalable Vector Graphic, vectorial, read-only as raster
ifWebP,
Lossless or lossy compression using V8 algorithm (need libwebp library)
ifAvif
Lossless or lossy compression using Avif algorithm (need libavif library)
DefaultBGRAImageReader: array[TBGRAImageFormat] of TFPCustomImageReaderClass;
List of stream readers for images
DefaultBGRAImageWriter: array[TBGRAImageFormat] of TFPCustomImageWriterClass;
List of stream writers for images
function DetectFileFormat(AFilenameUTF8: string): TBGRAImageFormat;
Detect the file format of a given file
function DetectFileFormat(AStream: TStream; ASuggestedExtensionUTF8: string = ''): TBGRAImageFormat;
Detect the file format of a given stream. ASuggestedExtensionUTF8 can be provided to guess the format
function SuggestImageFormat(AFilenameOrExtensionUTF8: string): TBGRAImageFormat;
Returns the file format that is most likely to be stored in the given filename (according to its extension)
function SuggestImageExtension(AFormat: TBGRAImageFormat): string;
Returns a likely image extension for the format
function CreateBGRAImageReader(AFormat: TBGRAImageFormat): TFPCustomImageReader;
Create an image reader for the given format
function CreateBGRAImageWriter(AFormat: TBGRAImageFormat; AHasTransparentPixels: boolean): TFPCustomImageWriter;
Create an image writer for the given format. AHasTransparentPixels specifies if alpha channel must be supported
TBGRALoadingOption = (
Possible options when loading an image
loKeepTransparentRGB,
Do not clear RGB channels when alpha is zero (not recommended)
loBmpAutoOpaque,
Consider BMP to be opaque if no alpha value is provided (for compatibility)
loJpegQuick);
Load JPEG quickly however with a lower quality
TBGRALoadingOptions = set of TBGRALoadingOption;
Set of options when loading
TTextLayout = BGRAGraphics.TTextLayout;
Text layout (vertical position)
tlTop = BGRAGraphics.tlTop;
Text aligned to the top
tlCenter = BGRAGraphics.tlCenter;
Text aligned vertically to the center
tlBottom = BGRAGraphics.tlBottom;
Text aligned to the bottom
TFontBidiMode = BGRAUnicode.TFontBidiMode;
Bidi-mode preference (right-to-left or left-to-right)
fbmAuto = BGRAUnicode.fbmAuto;
Automatic bidi-mode, depending on first letter type
fbmLeftToRight = BGRAUnicode.fbmLeftToRight;
Always left-to-right (but can embed another direction)
fbmRightToLeft = BGRAUnicode.fbmRightToLeft;
Always right-to-left (but can embed another direction)
TBidiTextAlignment = (
Alignment relative to the bidi-mode
btaNatural,
Natural alignment: left-aligned for left-to-right and right-aligned for right-to-left text
btaOpposite,
Opposite of natural alignment
btaLeftJustify,
Always left-aligned
btaRightJustify,
Always right-aligned
btaCenter);
Centered
function AlignmentToBidiTextAlignment(AAlign: TAlignment; ARightToLeft: boolean): TBidiTextAlignment; overload;
Converts an alignment to a bidi alignement relative to a bidi-mode
function AlignmentToBidiTextAlignment(AAlign: TAlignment): TBidiTextAlignment; overload;
Converts an alignment to a bidi alignement independent of bidi-mode
function BidiTextAlignmentToAlignment(ABidiAlign: TBidiTextAlignment; ARightToLeft: boolean): TAlignment;
Converts a bidi alignment to a classic alignement according to bidi-mode
function CheckPutImageBounds(x, y, tx, ty: integer; out minxb, minyb, maxxb, maxyb, ignoreleft: integer; const cliprect: TRect): boolean;
Checks the bounds of an image in the given clipping rectangle

Imported from GraphType

TRawImageLineOrder = (
Order of the lines in an image
riloTopToBottom,
The first line in memory (line 0) is the top line
riloBottomToTop);
The first line in memory (line 0) is the bottom line
TRawImageBitOrder = (
Order of the bits in a byte containing pixel values
riboBitsInOrder,
The lowest bit is on the left. So with a monochrome picture, bit 0 would be pixel 0
riboReversedBits);
The lowest bit is on the right. So with a momochrome picture, bit 0 would be pixel 7 (bit 1 would be pixel 6, ...)
TRawImageByteOrder = (
Order of the bytes in a group of byte containing pixel values
riboLSBFirst,
Least significant byte first (little endian)
riboMSBFirst);
most significant byte first (big endian)
TGraphicsBevelCut =
Definition of a single line 3D bevel
bvNone,
No bevel
bvLowered,
Shape is lowered, light is on the bottom-right corner
bvRaised,
Shape is raised, light is on the top-left corner
bvSpace);
Shape is at the same level, there is no particular lighting

Integer math

function PositiveMod(value, cycle: Int32or64): Int32or64; inline; overload;
Computes the value modulo cycle, and if the value is negative, the result is still positive
function Sin65536(value: word): Int32or64; inline;
Returns an integer approximation of the sine. Value ranges from 0 to 65535, where 65536 corresponds to the next cycle
function Cos65536(value: word): Int32or64; inline;
Returns an integer approximation of the cosine. Value ranges from 0 to 65535, where 65536 corresponds to the next cycle
function ByteSqrt(value: byte): byte; inline;
Returns the square root of the given byte, considering that 255 is equal to unity

Types provided for fonts

TBGRAFontQuality = (
Quality to be used to render text
fqSystem,
Use the system capabilities. It is rather fast however it may be not be smoothed.
fqSystemClearType,
Use the system capabilities to render with ClearType. This quality is of course better than fqSystem however it may not be perfect.
fqFineAntialiasing,
Garanties a high quality antialiasing.
fqFineClearTypeRGB,
Fine antialiasing with ClearType assuming an LCD display in red/green/blue order
fqFineClearTypeBGR);
Fine antialiasing with ClearType assuming an LCD display in blue/green/red order
TGetFineClearTypeAutoFunc = function(): TBGRAFontQuality;
Function type to detect the adequate ClearType mode
fqFineClearType : TGetFineClearTypeAutoFunc;
Provide function to detect the adequate ClearType mode
TFontPixelMetric = record
Measurements of a font
Defined: boolean;
The values have been computed
Baseline,
Position of the baseline, where most letters lie
xLine,
Position of the top of the small letters (x being one of them)
CapLine,
Position of the top of the UPPERCASE letters
DescentLine,
Position of the bottom of letters like g and p
Lineheight: integer;
Total line height including line spacing defined by the font
TFontPixelMetricF = record
Measurements of a font in floating point values
Defined: boolean;
The values have been computed
Baseline,
Position of the baseline, where most letters lie
xLine,
Position of the top of the small letters (x being one of them)
CapLine,
Position of the top of the UPPERCASE letters
DescentLine,
Position of the bottom of letters like g and p
Lineheight: single;
Total line height including line spacing defined by the font
TFontVerticalAnchor = (
Vertical anchoring of the font. When text is drawn, a start coordinate is necessary. Text can be positioned in different ways. This enum defines what position it is regarding the font
fvaTop,
The top of the font. Everything will be drawn below the start coordinate.
fvaCenter,
The center of the font
fvaCapLine,
The top of capital letters
fvaCapCenter,
The center of capital letters
fvaXLine,
The top of small letters
fvaXCenter,
The center of small letters
fvaBaseline,
The baseline, the bottom of most letters
fvaDescentLine,
The bottom of letters that go below the baseline
fvaBottom);
The bottom of the font. Everything will be drawn above the start coordinate
TWordBreakHandler = procedure(var ABeforeUTF8, AAfterUTF8: string) of object;
Definition of a function that handles work-break
TBGRATypeWriterAlignment = (twaTopLeft, twaTop, twaTopRight, twaLeft, twaMiddle, twaRight, twaBottomLeft, twaBottom, twaBottomRight);
Alignment for a typewriter, that does not have any more information than a square shape containing glyphs
TBGRATypeWriterOutlineMode = (twoPath, twoFill, twoStroke, twoFillOverStroke, twoStrokeOverFill, twoFillThenStroke, twoStrokeThenFill);
How a typewriter must render its content on a Canvas2d
TBGRACustomFontRenderer = class
Abstract class for all font renderers
FFontEmHeightF: single;
Specifies the height of the font without taking into account additional line spacing. A negative value means that it is the full height instead
function GetFontEmHeight: integer;
Retrieves the em-height of the font
procedure SetFontEmHeight(AValue: integer);
Sets the font height as em-height
FontName: string;
Specifies the font to use. Unless the font renderer accept otherwise, the name is in human readable form, like 'Arial', 'Times New Roman', ...
FontStyle: TFontStyles;
Specifies the set of styles to be applied to the font. These can be fsBold, fsItalic, fsStrikeOut, fsUnderline. So the value [fsBold, fsItalic] means that the font must be bold and italic
FontQuality: TBGRAFontQuality;
Specifies the quality of rendering. Default value is fqSystem
FontOrientation: integer;
Specifies the rotation of the text, for functions that support text rotation. It is expressed in tenth of degrees, positive values going counter-clockwise
function GetFontPixelMetric: TFontPixelMetric; virtual; abstract;
Returns measurement for the current font in pixels
function GetFontPixelMetricF: TFontPixelMetricF; virtual;
Returns measurement for the current font in fractional pixels
function FontExists(AName: string): boolean; virtual; abstract;
Checks whether a font exists
function TextVisible(const AColor: TBGRAPixel): boolean; virtual;
Checks if any text would be visible using the specified color
function TextSize(sUTF8: string): TSize; overload; virtual; abstract;
Returns the total size of the string provided using the current font. Orientation is not taken into account, so that the width is horizontal
function TextSizeF(sUTF8: string): TPointF; overload; virtual;
Returns the total floating point size of the string provided using the current font. Orientation is not taken into account, so that the width is horizontal
function TextSize(sUTF8: string; AMaxWidth: integer; ARightToLeft: boolean): TSize; overload; virtual; abstract;
Returns the total size of the string provided given a maximum width and RTL mode, using the current font. Orientation is not taken into account, so that the width is along the text
function TextSizeF(sUTF8: string; AMaxWidthF: single; ARightToLeft: boolean): TPointF; overload; virtual;
Returns the total floating point size of the string provided given a maximum width and RTL mode, using the current font. Orientation is not taken into account, so that the width is along the text
function TextSizeAngle(sUTF8: string; orientationTenthDegCCW: integer): TSize; virtual;
Returns the total size of the string provided using the current font, with the given orientation, along the text
function TextSizeAngleF(sUTF8: string; orientationTenthDegCCW: integer): TPointF; virtual;
Returns the total floating-point size of the string provided using the current font, with the given orientation, along the text
function TextFitInfo(sUTF8: string; AMaxWidth: integer): integer; virtual; abstract;
Returns the number of Unicode characters that fit into the specified size
function TextFitInfoF(sUTF8: string; AMaxWidthF: single): integer; virtual;
Returns the number of Unicode characters that fit into the specified floating-point size
procedure TextOut(ADest: TBGRACustomBitmap; x, y: single; sUTF8: string; c: TBGRAPixel; align: TAlignment); overload; virtual; abstract;
Draws the UTF8 encoded string, with color c. If align is taLeftJustify, (x, y) is the top-left corner. If align is taCenter, (x, y) is at the top and middle of the text. If align is taRightJustify, (x, y) is the top-right corner. The value of FontOrientation is taken into account, so that the text may be rotated
procedure TextOut(ADest: TBGRACustomBitmap; x, y: single; sUTF8: string; c: TBGRAPixel; align: TAlignment; ARightToLeft: boolean); overload; virtual;
Same as above but with given RTL mode
procedure TextOut(ADest: TBGRACustomBitmap; x, y: single; sUTF8: string; texture: IBGRAScanner; align: TAlignment); overload; virtual; abstract;
Same as above functions, except that the text is filled using texture. The value of FontOrientation is taken into account, so that the text may be rotated
procedure TextOut(ADest: TBGRACustomBitmap; x, y: single; sUTF8: string; texture: IBGRAScanner; align: TAlignment; ARightToLeft: boolean); overload; virtual;
Same as above but with given RTL mode
procedure TextOutAngle(ADest: TBGRACustomBitmap; x, y: single; orientationTenthDegCCW: integer; sUTF8: string; c: TBGRAPixel; align: TAlignment); overload; virtual; abstract;
Same as above, except that the orientation is specified, overriding the value of the property FontOrientation
procedure TextOutAngle(ADest: TBGRACustomBitmap; x, y: single; orientationTenthDegCCW: integer; sUTF8: string; c: TBGRAPixel; align: TAlignment; ARightToLeft: boolean); overload; virtual;
Same as above but with given RTL mode
procedure TextOutAngle(ADest: TBGRACustomBitmap; x, y: single; orientationTenthDegCCW: integer; sUTF8: string; texture: IBGRAScanner; align: TAlignment); overload; virtual; abstract;
Same as above, except that the orientation is specified, overriding the value of the property FontOrientation
procedure TextOutAngle(ADest: TBGRACustomBitmap; x, y: single; orientationTenthDegCCW: integer; sUTF8: string; texture: IBGRAScanner; align: TAlignment; ARightToLeft: boolean); overload; virtual;
Same as above but with given RTL mode
procedure TextRect(ADest: TBGRACustomBitmap; ARect: TRect; x, y: integer; sUTF8: string; style: TTextStyle; c: TBGRAPixel); overload; virtual; abstract;
Draw the UTF8 encoded string at the coordinate (x, y), clipped inside the rectangle ARect. Additional style information is provided by the style parameter. The color c is used to fill the text. No rotation is applied.
procedure TextRect(ADest: TBGRACustomBitmap; ARect: TRect; x, y: integer; sUTF8: string; style: TTextStyle; texture: IBGRAScanner); overload; virtual; abstract;
Same as above except a texture is used to fill the text
procedure CopyTextPathTo(ADest: IBGRAPath; x, y: single; s: string; align: TAlignment); virtual; //optional
Copy the path for the UTF8 encoded string into ADest. If align is taLeftJustify, (x, y) is the top-left corner. If align is taCenter, (x, y) is at the top and middle of the text. If align is taRightJustify, (x, y) is the top-right corner.
procedure CopyTextPathTo(ADest: IBGRAPath; x, y: single; s: string; align: TAlignment; ARightToLeft: boolean); virtual; //optional
Same as above but with given RTL mode
function HandlesTextPath: boolean; virtual;
Check whether the renderer can produce text path
property FontEmHeight: integer read GetFontEmHeight write SetFontEmHeight;
Font em-height as an integer
property FontEmHeightF: single read FFontEmHeightF write FFontEmHeightF;
Font em-height as a single-precision floating point value
TBGRATextOutImproveReadabilityMode = (
Output mode for the improved renderer for readability. This is used by the font renderer based on LCL in BGRAText
irMask,
Render the grayscale mask
irNormal,
Render normally with provided the color or texture
irClearTypeRGB,
Render with ClearType for RGB ordered display
irClearTypeBGR);
Render with ClearType for BGR ordered display
function CleanTextOutString(const s: string): string;
Removes line ending and tab characters from a string (for a function like TextOut that does not handle this). this works with UTF8 strings as well
function RemoveLineEnding(var s: string; indexByte: integer): boolean;
Remove the line ending at the specified position or return False. This works with UTF8 strings however the index is the byte index
function RemoveLineEndingUTF8(var sUTF8: string; indexUTF8: integer): boolean;
Remove the line ending at the specified position or return False. The index is the character index, that may be different from the byte index
procedure BGRADefaultWordBreakHandler(var ABefore, AAfter: string);
Default word break handler

Images and resampling

TResampleMode = (
How the resample is to be computed
rmSimpleStretch,
Low quality resample by repeating pixels, stretching them
rmFineResample);
Use resample filters. This gives high quality resampling however this the proportion changes slightly because the first and last pixel are considered to occupy only half a unit as they are considered as the border of the picture (pixel-centered coordinates)
TResampleFilter = (
List of resample filter to be used with rmFineResample
rfBox,
Equivalent of simple stretch with high quality and pixel-centered coordinates
rfLinear,
Linear interpolation giving slow transition between pixels
rfHalfCosine,
Mix of rfLinear and rfCosine giving medium speed stransition between pixels
rfCosine,
Cosine-like interpolation giving fast transition between pixels
rfBicubic,
Simple bi-cubic filter (blurry)
rfMitchell,
Mitchell filter, good for downsizing interpolation
rfSpline,
Spline filter, good for upsizing interpolation, however slightly blurry
rfLanczos2,
Lanczos with radius 2, blur is corrected
rfLanczos3,
Lanczos with radius 3, high contrast
rfLanczos4,
Lanczos with radius 4, high contrast
rfBestQuality);
Best quality using rfMitchell or rfSpline
ResampleFilterStr : array[TResampleFilter] of string =
List of strings to represent resample filters
function StrToResampleFilter(str: string): TResampleFilter;
Gives the sample filter represented by a string
TQuickImageInfo = record
Image information from superficial analysis
Width,
Width in pixels
Height,
Height in pixels
ColorDepth,
Bitdepth for colors (1, 2, 4, 8 for images with palette/grayscale, 16, 24 or 48 if each channel is present)
AlphaDepth: integer;
Bitdepth for alpha (0 if no alpha channel, 1 if bit mask, 8 or 16 if alpha channel)
TBGRAImageReader = class(TFPCustomImageReader)
Bitmap reader with additional features
function GetQuickInfo(AStream: TStream): TQuickImageInfo; virtual; abstract;
Return bitmap information (size, bit depth)
function GetBitmapDraft(AStream: TStream; AMaxWidth, AMaxHeight: integer; out AOriginalWidth,AOriginalHeight: integer): TBGRACustomBitmap; virtual; abstract;
Return a draft of the bitmap, the ratio may change compared to the original width and height (useful to make thumbnails)
TBGRACustomWriterPNG = class(TFPCustomImageWriter)
Generic definition for a PNG writer with alpha option
function GetUseAlpha: boolean; virtual; abstract;
Gets whether or not to use the alpha channel
procedure SetUseAlpha(AValue: boolean); virtual; abstract;
Sets whether or not to use the alpha channel
property UseAlpha : boolean read GetUseAlpha write SetUseAlpha;
Whether or not to use the alpha channel
operator =(const AGuid1, AGuid2: TGuid): boolean;
Check whether to GUID are equal
TBGRAResourceManager = class
Generic class for embedded resource management
var BGRAResource : TBGRAResourceManager;
Provides a resource manager 
function ResourceFile(AFilename: string): string;
Return the full path for a resource file on the disk. On Windows and Linux, it can be next to the binary but on MacOS, it can be outside of the application bundle when debugging