Class TGrayscaleImage

Unit

Declaration

type TGrayscaleImage = class(TCastleImage)

Description

Grayscale image. Color is a simple Byte value.

Source: images/castleimages_class_grayscale.inc (line 19).

Hierarchy

Show Additional Members:

Overview

Fields

Protected FRawPixels: Pointer;

Methods

Public destructor Destroy; override;
Public function Size: Cardinal; virtual; abstract;
Public function Dimensions: TVector3Cardinal;
Public function IsEmpty: boolean;
Public function HasAlpha: boolean; virtual;
Public function AlphaChannel( const AlphaTolerance: Byte = DefaultAlphaTolerance): TAlphaChannel; virtual;
Public function Rect: TRectangle;
Public function CreateCopy: TEncodedImage; virtual; abstract;
Public procedure FlipVertical; virtual; abstract;
Public function ToFpImage: TInternalCastleFpImage; virtual; deprecated 'interoperability with FpImage may be dropped in the future';
Protected procedure LerpSimpleCheckConditions(SecondImage: TCastleImage);
Protected procedure DrawFromCore(const Source: TCastleImage; const X, Y, SourceX, SourceY, SourceWidth, SourceHeight: Integer; const Mode: TDrawMode); virtual;
Protected function MakeResizedToFpImage(ResizeWidth, ResizeHeight: Cardinal; const Interpolation: TResizeInterpolation): TInternalCastleFpImage;
Protected function GetColors(const X, Y, Z: Integer): TCastleColor; virtual;
Protected procedure SetColors(const X, Y, Z: Integer; const C: TCastleColor); virtual;
Protected procedure AssignProperties(const Source: TCastleImage); virtual;
Public constructor Create; overload; virtual;
Public constructor Create(const AWidth, AHeight: Cardinal; const ADepth: Cardinal = 1); overload;
Public procedure Empty;
Public procedure SetSize( const AWidth, AHeight: Cardinal; const ADepth: Cardinal = 1); overload;
Public procedure SetSize(const Source: TCastleImage); overload;
Public class function PixelSize: Cardinal; virtual; abstract;
Public function Size: Cardinal; override;
Public function ImageSize: Cardinal; deprecated;
Public class function ColorComponentsCount: Cardinal; virtual; abstract;
Public function PixelPtr(const X, Y: Cardinal; const Z: Cardinal = 0): Pointer;
Public function RowPtr(const Y: Cardinal; const Z: Cardinal = 0): Pointer;
Public procedure InvertColors; virtual;
Public procedure SetColorRGB(const X, Y: Integer; const v: TVector3); deprecated 'use Colors[X, Y, 0] to get or set colors';
Public function MakeCopy: TCastleImage;
Public function CreateCopy: TEncodedImage; override;
Public procedure Resize(ResizeWidth, ResizeHeight: Cardinal; const Interpolation: TResizeInterpolation = riBilinear);
Public procedure Resize3x3(const ResizeWidth, ResizeHeight: Cardinal; var Corners: TVector4Integer; const Interpolation: TResizeInterpolationInternal); deprecated 'This method is seldom useful, and it is confused with TCastleImage.DrawFrom3x3 and TDrawableImage.Draw3x3 too often. Please report if you have a use-case when this method is useful, otherwise it may get removed from the engine one day.';
Public function MakeResized(ResizeWidth, ResizeHeight: Cardinal; const Interpolation: TResizeInterpolation = riBilinear): TCastleImage;
Public procedure FlipHorizontal;
Public procedure FlipVertical; override;
Public function MakeRotated(Angle: Integer): TCastleImage;
Public procedure Rotate(const Angle: Integer);
Public function MakeTiled(TileX, TileY: Cardinal): TCastleImage;
Public function MakeExtracted(X0, Y0, ExtractWidth, ExtractHeight: Cardinal): TCastleImage;
Public procedure Clear(const Pixel: TVector4Byte); overload; virtual;
Public procedure Clear(const Pixel: TCastleColor); overload;
Public function IsClear(const Pixel: TVector4Byte): boolean; overload; virtual;
Public procedure TransformRGB(const Matrix: TMatrix3); virtual;
Public procedure ModulateRGB(const ColorModulator: TColorModulatorByteFunc); virtual;
Public function MakeModulatedRGB( const ColorModulator: TColorModulatorByteFunc): TCastleImage;
Public procedure Grayscale;
Public procedure ConvertToChannelRGB(Channel: Integer);
Public procedure StripToChannelRGB(Channel: Integer);
Public function IsEqual(Image: TCastleImage): boolean;
Public function ArePartsEqual( const SelfX0, SelfY0, SelfWidth, SelfHeight: Cardinal; Image: TCastleImage; const ImageX0, ImageY0, ImageWidth, ImageHeight: Cardinal): boolean; overload;
Public function ArePartsEqual( Image: TCastleImage; const ImageX0, ImageY0, ImageWidth, ImageHeight: Cardinal): boolean; overload;
Public function ArePartsEqual( const SelfX0, SelfY0, SelfWidth, SelfHeight: Cardinal; Image: TCastleImage): boolean; overload;
Public procedure DrawFrom(const Source: TCastleImage; const X, Y: Integer; const Mode: TDrawMode = dmBlend); overload;
Public procedure DrawFrom(const Source: TCastleImage; X, Y, SourceX, SourceY, SourceWidth, SourceHeight: Integer; const Mode: TDrawMode = dmBlend); overload;
Public procedure DrawFrom(const Source: TCastleImage; const X, Y: Integer; const SourceRect: TRectangle; const Mode: TDrawMode = dmBlend); overload;
Public procedure DrawTo(const Destination: TCastleImage; const X, Y: Integer; const Mode: TDrawMode = dmBlend);
Public procedure DrawFrom3x3(const DestinationRect: TRectangle; const Source: TCastleImage; const SourceCorners: TVector4Integer; const DrawMode: TDrawMode; const Interpolation: TResizeInterpolation = riBilinear);
Public procedure LerpWith(const Value: Single; SecondImage: TCastleImage); virtual;
Public class procedure MixColors(const OutputColor: Pointer; const Weights: TVector4; const AColors: TVector4Pointer); virtual;
Public procedure Assign(const Source: TCastleImage); virtual;
Public procedure SaveToPascalCode(const ImageName: string; var CodeInterface, CodeImplementation, CodeInitialization, CodeFinalization: string);
Public procedure AlphaBleed(const ProgressTitle: string = ''); virtual;
Public function MakeAlphaBleed(const ProgressTitle: string = ''): TCastleImage; virtual;
Public procedure FillEllipse(const x, y: single; const aRadiusX, aRadiusY: single; const aColor: TCastleColor); virtual; deprecated 'do not use TCastleImage drawing; use other libraries (like FpImage or Vampyre Imaging or BGRABitmap) or our TDrawableImage (use RenderToImageBegin/End, and DrawCircle/DrawCircleOutline to draw ellipses using GPU)';
Public procedure Ellipse(const x, y: single; const aRadiusX, aRadiusY: single; const aWidth: single; const aColor: TCastleColor); virtual; deprecated 'do not use TCastleImage drawing; use other libraries (like FpImage or Vampyre Imaging or BGRABitmap) or our TDrawableImage (use RenderToImageBegin/End, and DrawCircle/DrawCircleOutline to draw ellipses using GPU)';
Public procedure FillRectangle(const x1, y1, x2, y2: single; const aColor: TCastleColor); virtual; deprecated 'do not use TCastleImage drawing; use other libraries (like FpImage or Vampyre Imaging or BGRABitmap) or our TDrawableImage (use RenderToImageBegin/End, and DrawRectangle/DrawRectangleOutline to draw rectangles using GPU)';
Public procedure Rectangle(const x1, y1, x2, y2: single; const aWidth: single; const aColor: TCastleColor); virtual; deprecated 'do not use TCastleImage drawing; use other libraries (like FpImage or Vampyre Imaging or BGRABitmap) or our TDrawableImage (use RenderToImageBegin/End, and DrawRectangle/DrawRectangleOutline to draw rectangles using GPU)';
Public procedure Line(const x1, y1, x2, y2: single; const aWidth: single; const aColor: TCastleColor); virtual; deprecated 'do not use TCastleImage drawing; use other libraries (like FpImage or Vampyre Imaging or BGRABitmap) or our TDrawableImage (use RenderToImageBegin/End, and DrawPrimitive2D to draw lines using GPU)';
Public procedure FloodFill(const x, y: integer; const aColor: TCastleColor; const aThreshold: single = 0); deprecated 'do not use TCastleImage drawing; use other libraries (like FpImage or Vampyre Imaging or BGRABitmap) for drawing on images';
Protected procedure DrawFromCore(const Source: TCastleImage; const X, Y, SourceX, SourceY, SourceWidth, SourceHeight: Integer; const Mode: TDrawMode); override;
Protected function GetColors(const X, Y, Z: Integer): TCastleColor; override;
Protected procedure SetColors(const X, Y, Z: Integer; const C: TCastleColor); override;
Protected procedure AssignProperties(const Source: TCastleImage); override;
Public constructor Create; overload; override;
Public class function PixelSize: Cardinal; override;
Public class function ColorComponentsCount: Cardinal; override;
Public function PixelPtr(const X, Y: Cardinal; const Z: Cardinal = 0): PByte;
Public function RowPtr(const Y: Cardinal; const Z: Cardinal = 0): PByteArray;
Public procedure InvertColors; override;
Public procedure Clear(const Pixel: TVector4Byte); override;
Public function IsClear(const Pixel: TVector4Byte): boolean; override;
Public procedure Clear(const Pixel: Byte); reintroduce; overload;
Public function IsClear(const Pixel: Byte): boolean; reintroduce; overload;
Public procedure HalfColors;
Public function ToGrayscaleAlphaImage: TGrayscaleAlphaImage; deprecated 'create TGrayscaleAlphaImage and use TGrayscaleAlphaImage.Assign';
Public function ToFpImage: TInternalCastleFpImage; override;
Public procedure LerpWith(const Value: Single; SecondImage: TCastleImage); override;
Public class procedure MixColors(const OutputColor: Pointer; const Weights: TVector4; const AColors: TVector4Pointer); override;
Public function AlphaChannel( const AlphaTolerance: Byte): TAlphaChannel; override;
Public procedure Assign(const Source: TCastleImage); override;
Public procedure FillEllipse(const x, y: single; const aRadiusX, aRadiusY: single; const aColor: TCastleColor); override;
Public procedure Ellipse(const x, y: single; const aRadiusX, aRadiusY: single; const aWidth: single; const aColor: TCastleColor); override;
Public procedure FillRectangle(const x1, y1, x2, y2: single; const aColor: TCastleColor); override;
Public procedure Rectangle(const x1, y1, x2, y2: single; const aWidth: single; const aColor: TCastleColor); override;
Public procedure Line(const x1, y1, x2, y2: single; const aWidth: single; const aColor: TCastleColor); override;

Properties

Public property Url: String read FUrl write FUrl;
Public property Width: Cardinal read FWidth;
Public property Height: Cardinal read FHeight;
Public property Depth: Cardinal read FDepth;
Public property RawPixels: Pointer read FRawPixels;
Public property Colors [const X,Y,Z: Integer]: TCastleColor read GetColors write SetColors;
Public property Pixels: PByte read GetPixels;
Public property GrayscalePixels: PByte read GetPixels; deprecated 'use Pixels';
Public property PixelsArray: PByteArray read GetPixelsArray;
Public property TreatAsAlpha: boolean read FTreatAsAlpha write FTreatAsAlpha default false;
Public property ColorWhenTreatedAsAlpha: TVector3Byte read FColorWhenTreatedAsAlpha write SetColorWhenTreatedAsAlpha;
Public property GrayscaleColorWhenTreatedAsAlpha: Byte read FGrayscaleColorWhenTreatedAsAlpha;

Description

Fields

Protected FRawPixels: Pointer;

Operate on this by Get/Realloc/FreeMem. It's always freed and nil'ed in destructor.

Source: images/castleimages.pas (line 183).

Methods

Public destructor Destroy; override;

This item has no description.

Source: images/castleimages.pas (line 188).

Public function Size: Cardinal; virtual; abstract;

Size of image contents in bytes.

Source: images/castleimages.pas (line 227).

Public function Dimensions: TVector3Cardinal;

Get a 3D vector with Width, Height, Depth.

Source: images/castleimages.pas (line 230).

Public function IsEmpty: boolean;

Is an image empty.

True means that RawPixels = Nil, and Width * Height * Depth = 0 (so either Width = 0 or Height = 0 or Depth = 0).

False means that RawPixels <> nil and Width * Height * Depth <> 0 (so all Width > 0 and Height > 0 and Depth > 0, since they are Cardinal (unsigned) always).

Source: images/castleimages.pas (line 241).

Public function HasAlpha: boolean; virtual;

Does an image have an alpha channel.

You may also be interested in the AlphaChannel that can make a distinction between alpha channel for blending and for alpha test. AlphaChannel answers always atNone if HasAlpha = false, and always acTest or acBlending if HasAlpha = true. But AlphaChannel may perform longer analysis of pixels (to differ between acTest and acBlending), while this function always executes ultra-fast (as it's constant for each TCastleImage descendant).

Descendants implementors notes: in this class, TCastleImage, this returns False. Override to return True for images with alpha channel.

Source: images/castleimages.pas (line 257).

Public function AlphaChannel( const AlphaTolerance: Byte = DefaultAlphaTolerance): TAlphaChannel; virtual;

Analyze image contents to determine if, and what kind, of alpha channel it has.

This may be a time-consuming operation. When the image has alpha channel and we need to decide whether it's suitable for "alpha test" (only fully opaque or fully transparent pixels) or "alpha blending" (any alpha value makes sense) then this method needs to iterate over image pixels.

For this reason, the result of this operation is cached at various levels, e.g. TImageTextureNode and TDrawableImage cache it internally.

We determine "alpha test - simple yes/no alpha channel" if all the alpha values (for every pixel) are 0, or 255, or (when AlphaTolerance <> 0) are close to them by AlphaTolerance. So, to be precise, alpha value must be <= AlphaTolerance, or >= 255 - AlphaTolerance. If any alpha value is between [AlphaTolerance + 1, 255 - AlphaTolerance - 1] then we return "alpha blending - full range alpha channel".

Note that big values of AlphaTolerance make it easier to quality image as "alpha test - simple yes/no alpha channel". When AlphaTolerance >= 128, all images are treated as "simple yes/no alpha". Usually, you want to keep AlphaTolerance small.

Descendants implementors notes: in this class, this simply always returns atNone. For descendants that have alpha channel, implement it, honouring AlphaTolerance as described.

Source: images/castleimages.pas (line 286).

Public function Rect: TRectangle;

Rectangle representing the inside of this image. Always (Left,Bottom) are zero, and (Width,Height) correspond to image sizes.

Source: images/castleimages.pas (line 293).

Public function CreateCopy: TEncodedImage; virtual; abstract;

Create a new image object that has exactly the same class and the same data (size, pixels) as this image.

Source: images/castleimages.pas (line 297).

Public procedure FlipVertical; virtual; abstract;

Mirror image vertically.

Source: images/castleimages.pas (line 300).

Public function ToFpImage: TInternalCastleFpImage; virtual; deprecated 'interoperability with FpImage may be dropped in the future';

Warning: this symbol is deprecated: interoperability with FpImage may be dropped in the future

Convert image contents to FpImage instance. The resulting instance is owned by the caller.

Source: images/castleimages.pas (line 305).

Protected procedure LerpSimpleCheckConditions(SecondImage: TCastleImage);

Check that both images have the same sizes and Second image class descends from First image class. If not, raise appropriate ELerpXxx exceptions.

Some implementation of TRGBImage.LerpWith may require other checks (since LerpWith may be sometimes allowed between unequal classes), so this doesn't have to be used by all TRGBImage.LerpWith implementations (although it's comfortable for simple implementations).

Source: images/castleimages.pas (line 479).

Protected procedure DrawFromCore(const Source: TCastleImage; const X, Y, SourceX, SourceY, SourceWidth, SourceHeight: Integer; const Mode: TDrawMode); virtual;

Like DrawFrom, but can assume that all coordinates and sizes are valid. Override this to add copying using some more sophisticated method than just memory copying (so also for handling mode other than dmBlend).

Source: images/castleimages.pas (line 485).

Protected function MakeResizedToFpImage(ResizeWidth, ResizeHeight: Cardinal; const Interpolation: TResizeInterpolation): TInternalCastleFpImage;

This item has no description.

Source: images/castleimages.pas (line 490).

Protected function GetColors(const X, Y, Z: Integer): TCastleColor; virtual;

This item has no description.

Source: images/castleimages.pas (line 494).

Protected procedure SetColors(const X, Y, Z: Integer; const C: TCastleColor); virtual;

This item has no description.

Source: images/castleimages.pas (line 495).

Protected procedure AssignProperties(const Source: TCastleImage); virtual;

Assign properties (other than Url, sizes and pixel contents).

Used when creating a copy like MakeCopy, MakeRotated, MakeResized and so on. This is not used by Assign, so Assign implementation overrides must make sure to do the same thing (or call AssignProperties in descendants).

Source: images/castleimages.pas (line 504).

Public constructor Create; overload; virtual;

Constructor without parameters creates image with Width = Height = Depth = 0 and RawPixels = nil, so IsEmpty will return True.

Source: images/castleimages.pas (line 508).

Public constructor Create(const AWidth, AHeight: Cardinal; const ADepth: Cardinal = 1); overload;

This item has no description.

Source: images/castleimages.pas (line 509).

Public procedure Empty;

This is equivalent to SetSize(0, 0, 0). It sets Width = Height = 0 and RawPixels = nil.

Source: images/castleimages.pas (line 513).

Public procedure SetSize( const AWidth, AHeight: Cardinal; const ADepth: Cardinal = 1); overload;

Change size (Width and Height and Depth). Previous pixel contents (RawPixels) are lost, and the contents of new pixels are undefined.

Use other method, like Resize, if you want to change image size preserving it's contents.

Source: images/castleimages.pas (line 521).

Public procedure SetSize(const Source: TCastleImage); overload;

This item has no description.

Source: images/castleimages.pas (line 524).

Public class function PixelSize: Cardinal; virtual; abstract;

Size of TPixel in bytes for this TCastleImage descendant.

Source: images/castleimages.pas (line 527).

Public function Size: Cardinal; override;

Size of image contents in bytes.

Source: images/castleimages.pas (line 530).

Public function ImageSize: Cardinal; deprecated;

Warning: this symbol is deprecated.

Deprecated name for ImageSize.

Source: images/castleimages.pas (line 533).

Public class function ColorComponentsCount: Cardinal; virtual; abstract;

Number of color components in TPixel.

E.g. RGB is 3 components and RGB+Alpha is 4 components, RGB+Exponent is 3 components (because it describes only Red, Green and Blue values (Exponent value is just used to correctly interpret these, it's not a 4th component)).

Source: images/castleimages.pas (line 541).

Public function PixelPtr(const X, Y: Cardinal; const Z: Cardinal = 0): Pointer;

Pointer to the (x, y, z) pixel of image.

Note that they don't check X, Y, Z correctness in any way, it's your responsibility to always pass 0 <= X < Width and 0 <= Y < Height and 0 <= Z < Depth.

Note that this function should be reintroduced in descendants to return the same value but typecasted to something better then Pointer (something like ˆTPixel).

Source: images/castleimages.pas (line 552).

Public function RowPtr(const Y: Cardinal; const Z: Cardinal = 0): Pointer;

Pointer to the first pixel in the Y row of the image. Same thing as PixelPtr but always with X = 0.

Note that this function should be reintroduced in descendants to return the same value but typecasted to something better then Pointer, preferably something like ˆ(array of TPixel).

Source: images/castleimages.pas (line 560).

Public procedure InvertColors; virtual;

Inverts all colors (RGB or grayscale, but doesn't touch alpha channel). "Inverting" means changing color C in range [0..1] to 1-C, so black becomes white, white becomes black etc.

For descendants implementors: Override it if necessary, otherwise the default implementation in this class will raise EInternalError.

Source: images/castleimages.pas (line 569).

Public procedure SetColorRGB(const X, Y: Integer; const v: TVector3); deprecated 'use Colors[X, Y, 0] to get or set colors';

Warning: this symbol is deprecated: use Colors[X, Y, 0] to get or set colors

This item has no description.

Source: images/castleimages.pas (line 594).

Public function MakeCopy: TCastleImage;

Create a new image object that has exactly the same class and the same data (size, pixels) as this image.

(Design note: this function is *not* a constructor, because it's implemented in TCastleImage, but it always returns some descendant of TCastleImage.)

Source: images/castleimages.pas (line 602).

Public function CreateCopy: TEncodedImage; override;

Create a new image object that has exactly the same class and the same data (size, pixels) as this image.

Equivalent to MakeCopy, but virtual and declared as returning TEncodedImage class.

Source: images/castleimages.pas (line 608).

Public procedure Resize(ResizeWidth, ResizeHeight: Cardinal; const Interpolation: TResizeInterpolation = riBilinear);

Change Width and Height and appropriately stretch image contents.

If ResizeWidth or ResizeHeight is 0 then it means to take Width or Height, respectively. So e.g. using ResizeWidth = ResizeHeight = 0 is the same thing as using ResizeWidth = Width and ResizeHeight = Height and this is NOP.

Remember that resizing may change RawPixels pointer, so all pointers that you aquired using functions like RawPixels, Pixels, PixelsArray, RowPtr, PixelPtr may be invalid after calling Resize.

Source: images/castleimages.pas (line 622).

Public procedure Resize3x3(const ResizeWidth, ResizeHeight: Cardinal; var Corners: TVector4Integer; const Interpolation: TResizeInterpolationInternal); deprecated 'This method is seldom useful, and it is confused with TCastleImage.DrawFrom3x3 and TDrawableImage.Draw3x3 too often. Please report if you have a use-case when this method is useful, otherwise it may get removed from the engine one day.';

Warning: this symbol is deprecated: This method is seldom useful, and it is confused with TCastleImage.DrawFrom3x3 and TDrawableImage.Draw3x3 too often. Please report if you have a use-case when this method is useful, otherwise it may get removed from the engine one day.

Change Width and Height and appropriately stretch image contents.

This scales the image in almost the same way as standard Resize. However, this is aware of the image corners and edges, which is good if you plan to use this image with TDrawableImage.Draw3x3 drawing.

The Corners parameter specifies the corners size, in the same clockwise order as for TDrawableImage.Draw3x3: top, right, bottom, left. The corners will be scaled (proportially to image scaling), and new Corners size returned. Additionally it makes sure that filtering (especially bilinear) does not "leak" colors from one image area to another. Effectively, the image is scaled like a 9 separate parts, and colors cannot bleed from one part to another.

Both ResizeWidth, ResizeHeight parameters must be provided and non-zero.

For now, only a subset of TResizeInterpolation values are supported by this method, namely the ones in TResizeInterpolationInternal.

Source: images/castleimages.pas (line 644).

Public function MakeResized(ResizeWidth, ResizeHeight: Cardinal; const Interpolation: TResizeInterpolation = riBilinear): TCastleImage;

Create a new TCastleImage instance with size ResizeWidth, ResizeHeight and pixels copied from the input and appropriately stretched. The exact class of the new instance is the same as our class.

As with Resize method, when the parameter ResizeTo* is 0 it means to use current Width/Height. So e.g. using MakeResized(0, 0) is the same thing as using CreateCopy.

Source: images/castleimages.pas (line 656).

Public procedure FlipHorizontal;

Mirror image horizontally (that is, the right edge is swapped with the left edge).

Source: images/castleimages.pas (line 660).

Public procedure FlipVertical; override;

Mirror image vertically.

Source: images/castleimages.pas (line 663).

Public function MakeRotated(Angle: Integer): TCastleImage;

Make rotated version of the image. See Rotate for description of parameters.

Source: images/castleimages.pas (line 667).

Public procedure Rotate(const Angle: Integer);

Rotate image by Angle * 90 degrees, clockwise. For example, 0 does nothing. 1 rotates by 90 degrees, 2 rotates by 180, 3 rotates by 270. All other values (negative too) are circular (modulo), so e.g. 4 again does nothing, 5 rotates by 90 degrees and so on.

Source: images/castleimages.pas (line 673).

Public function MakeTiled(TileX, TileY: Cardinal): TCastleImage;

Create a new instance with the same class, and size TileX * Width and TileY * Height and contents being our contents duplicated (tiled). Must be TileX, TileY > 0.

Source: images/castleimages.pas (line 679).

Public function MakeExtracted(X0, Y0, ExtractWidth, ExtractHeight: Cardinal): TCastleImage;

Extract rectangular area of this image. X0 and Y0 are start position (lower-left corner), ExtractWidth, ExtractHeight specify size of area.

This checks parameters for correctness – if start position is not correct or ExtractWidth/Height are too large then exception EImagePosOutOfRange is raised.

Source: images/castleimages.pas (line 688).

Public procedure Clear(const Pixel: TVector4Byte); overload; virtual;

Set all image pixels to the same color.

Source: images/castleimages.pas (line 691).

Public procedure Clear(const Pixel: TCastleColor); overload;

This item has no description.

Source: images/castleimages.pas (line 692).

Public function IsClear(const Pixel: TVector4Byte): boolean; overload; virtual;

Check do all image pixels have the same color.

Source: images/castleimages.pas (line 695).

Public procedure TransformRGB(const Matrix: TMatrix3); virtual;

Multiply each RGB color by a matrix. This is a useful routine for many various conversions of image colors. Every pixel's RGB color is multiplied by given Matrix, i.e. PixelRGBColor := Matrix * PixelRGBColor.

If some value in some channel will be < 0, it will be set to 0. And if it will be > High(Byte), it will be set to High(Byte).

Examples: when Matrix = TMatrix3.Identity, this is NOOP. Matrix = ((2, 0, 0), (0, 1, 0), (0, 0, 1)) red channel is made lighter. Matrix = ((0, 0, 1), (0, 1, 0), (1, 0, 0)) swaps red and blue channel. Matrix = ((0.33, 0.33, 0.33), (0.33, 0.33, 0.33), (0.33, 0.33, 0.33)) is a simple conversion to grayscale (actually incorrect, even if often visually acceptable; actually instead of 0.33 one has to use GrayscaleFloat/ByteValues, this is already implemented in ImageTransformColorsVar function)

Note: it's often more optimal to hard-code necessary color transformations as TColorModulatorFunc and use ModulateRGB.

This function is only implemented for images that represent Pixel as RGB values, for now this means TRGBImage and TRGBAlphaImage. In case of TRGBAlphaImage (or any other class that represents colors as RGB + something more) alpha channel (i.e. "something more") is ignored (i.e. left without any modification).

In this class this simply raises EInternalError to say 'not implemented'. This also means that you must not call inherited in descendants when overriding this method.

Source: images/castleimages.pas (line 731).

Public procedure ModulateRGB(const ColorModulator: TColorModulatorByteFunc); virtual;

Process each pixel by given function. If ColorModulator = nil then this procedure does nothing. Else, every RGB color value of an image will be transformed using ColorModulator.

Like TransformRGB: This function is only implemented for images that represent Pixel as RGB values, for now this means TRGBImage and TRGBAlphaImage. In case of TRGBAlphaImage (or any other class that represents colors as RGB + something more) alpha channel (i.e. "something more") is ignored (i.e. left without any modification).

In this class this simply raises EInternalError to say 'not implemented'. This also means that you must not call inherited in descendants when overriding this method.

Source: images/castleimages.pas (line 748).

Public function MakeModulatedRGB( const ColorModulator: TColorModulatorByteFunc): TCastleImage;

Just like ModulateRGB, but this returns new image, not changing initial image. This means that if ColorModulator = nil this is equivalent to CreateCopy.

Implemented if and only if ModulateRGB is implemented.

Source: images/castleimages.pas (line 755).

Public procedure Grayscale;

Convert image colors to grayscale.

Implemented if and only if ModulateRGB is implemented. When image has alpha channel, alpha channel value (or just anything beyond 3 rgb components) is ignored (not modified).

This changes color to grayscale, but format of memory storage is the same. For example, for TRGBImage, they are still kept in RGB format (just Red = Green = Blue). If you want to convert to true Grayscale format, you should use TRGBImage.ToGrayscale that will create new TGrayscaleImage instance.

Source: images/castleimages.pas (line 769).

Public procedure ConvertToChannelRGB(Channel: Integer);

Convert every image color using Color*Convert function from CastleVectors. "Channel" parameter determines which Color*Convert function to use (Red, Green or Blue), must be 0, 1 or 2.

Implemented if and only if ModulateRGB is implemented.

Source: images/castleimages.pas (line 776).

Public procedure StripToChannelRGB(Channel: Integer);

Converts every image color using Color*Strip function from CastleVectors. "Channel" parameter determines which Color*Strip function to use (Red, Green or Blue), must be 0, 1 or 2.

Implemented if and only if ModulateRGB is implemented.

Source: images/castleimages.pas (line 783).

Public function IsEqual(Image: TCastleImage): boolean;

Check if given Image has the same class, the same sizes (Width, Height) and contains exactly the same pixel values.

Source: images/castleimages.pas (line 787).

Public function ArePartsEqual( const SelfX0, SelfY0, SelfWidth, SelfHeight: Cardinal; Image: TCastleImage; const ImageX0, ImageY0, ImageWidth, ImageHeight: Cardinal): boolean; overload;

This is like IsEqual, but is compares only given parts of the images. Note that it's your responsibility to make sure that given areas are really within the sizes of Self or Image.

Overloaded version without SelfXxx parameters compares whole Self to given part of Image. Analogously, version without ImageXxx parameters compares whole Image to part of Self.

Source: images/castleimages.pas (line 798).

Public function ArePartsEqual( Image: TCastleImage; const ImageX0, ImageY0, ImageWidth, ImageHeight: Cardinal): boolean; overload;

This item has no description.

Source: images/castleimages.pas (line 803).

Public function ArePartsEqual( const SelfX0, SelfY0, SelfWidth, SelfHeight: Cardinal; Image: TCastleImage): boolean; overload;

This item has no description.

Source: images/castleimages.pas (line 807).

Public procedure DrawFrom(const Source: TCastleImage; const X, Y: Integer; const Mode: TDrawMode = dmBlend); overload;

Draw one image part on another image. X, Y is the lower-left position on the destination image where we draw. Optional SourceX, SourceY, SourceWidth, SourceHeight specify to use only a part of the source image (without them, we take whole source image). The pixel on source image (SourceX, SourceY) will be drawn on destination image on (X, Y).

The coordinates and sizes are carefully checked, so that we do not try to take some pixels outside of the source or destination image.

Warning: It is not efficient to use this drawing method. This drawing is performed on CPU and cannot be fast. If possible, use instead TDrawableImage.DrawFrom, that performs image-on-image drawing using GPU, or just draw TDrawableImage straight to the screen by TDrawableImage.Draw. See examples/images_videos/draw_images_on_gpu.lpr for an example of TDrawableImage.DrawFrom. Using this method makes most sense in image manipulation tools, or during the loading / preparation stage of your game, not during actual game.

Note for descendants implementors: The default implementation of this function in TCastleImage can only directly copy the pixels, regardless of what information they have. This makes it very fast, but not suitable if the source image has some alpha channel and you want to apply it over a destination image with blending (adding scaled source to a destination color), and not suitable when Mode is <> dmBlend. Descendants with alpha channel should override DrawFromCore to handle drawing with blending (for dmBlend), all descendants should override DrawFromCore to handle drawing with Mode <> dmBlend.

Exceptions raised
EImageDrawError
When drawing cannot be performed, for example because drawing with this Mode, and/or for this Source and destination classes, is not implemented yet.

Source: images/castleimages.pas (line 853).

Public procedure DrawFrom(const Source: TCastleImage; X, Y, SourceX, SourceY, SourceWidth, SourceHeight: Integer; const Mode: TDrawMode = dmBlend); overload;

This item has no description.

Source: images/castleimages.pas (line 855).

Public procedure DrawFrom(const Source: TCastleImage; const X, Y: Integer; const SourceRect: TRectangle; const Mode: TDrawMode = dmBlend); overload;

This item has no description.

Source: images/castleimages.pas (line 858).

Public procedure DrawTo(const Destination: TCastleImage; const X, Y: Integer; const Mode: TDrawMode = dmBlend);

This item has no description.

Source: images/castleimages.pas (line 861).

Public procedure DrawFrom3x3(const DestinationRect: TRectangle; const Source: TCastleImage; const SourceCorners: TVector4Integer; const DrawMode: TDrawMode; const Interpolation: TResizeInterpolation = riBilinear);

Draw the Source image on this image, dividing the source image into 3x3 parts for corners, sides, and inside.

The source image is divided into 3 * 3 = 9 parts:

  • 4 corners, used to fill the corners of the DestinationRect. They are not stretched.

  • 4 sides, used to fill the sides of the DestinationRect between the corners. They are scaled in one dimension, to fill the space between corners completely.

  • the inside. Used to fill the rectangular inside. Scaled in both dimensions as necessary.

The size of corners is specified in the SourceCorners parameter, in the order: top, right, bottom, left. (It's the same order as e.g. CSS margins.)

Warning: It is not efficient to use this drawing method. This drawing is performed on CPU and cannot be fast. If possible, use instead TDrawableImage, and either draw it to the screen by TDrawableImage.Draw3x3, or draw it to another TDrawableImage by combining TDrawableImage.Draw3x3 with TDrawableImage.RenderToImageBegin. Using this method makes most sense in image manipulation tools, or during the loading / preparation stage of your game, not during actual game.

Source: images/castleimages.pas (line 895).

Public procedure LerpWith(const Value: Single; SecondImage: TCastleImage); virtual;

Makes linear interpolation of colors from this image and the SecondImage. Intuitively, every pixel in new image is set to

(1 - Value) * Self[pixel] + Value * SecondImage[pixel]

Both images need to have the exact same size. If they are not, EImageLerpDifferentSizes is raised.

Not all TCastleImage combinations are allowed. Every subclass is required to override this to at least handle Lerp between itself. That is, TRGBImage.Lerp has to handle Lerp with other TRGBImage, TRGBAlphaImage.Lerp has to handle Lerp with other TRGBAlphaImage etc. Other combinations may be permitted, if useful and implemented. EImageLerpInvalidClasses is raised if given class combinations are not allowed.

In this class, this simply always raises EImageLerpInvalidClasses.

Exceptions raised
EImageLerpDifferentSizes
When SecondImage size differs from this image.
EImageLerpInvalidClasses
When Lerp between this TCastleImage descendant class and SecondImage class is not implemented.

Source: images/castleimages.pas (line 924).

Public class procedure MixColors(const OutputColor: Pointer; const Weights: TVector4; const AColors: TVector4Pointer); virtual;

Mix 4 colors, with 4 weights, into a resulting color. All 4 Colors and OutputColor must be pointers to a pixel of current image class, that is they must point to PixelSize bytes of memory.

Exceptions raised
EImageLerpInvalidClasses
When mixing is not implemented for this image class.

Source: images/castleimages.pas (line 932).

Public procedure Assign(const Source: TCastleImage); virtual;

Copy size and contents from Source. This sets our size (Width, Height and Depth) to match Source image, and copies pixels from the Source image, converting them as closely as possible. For example, converting RGBA to RGB will strip alpha channel, but copy RGB values.

When implementing descendants: the base implementation of this method in TCastleImage handles only the case when Image class equals our own class. And raises EImageAssignmentError in other cases. Override this method if you want to actually handle some conversions when assignning.

Exceptions raised
EImageAssignmentError
If it's not possible to convert from Source class to us.

Source: images/castleimages.pas (line 951).

Public procedure SaveToPascalCode(const ImageName: string; var CodeInterface, CodeImplementation, CodeInitialization, CodeFinalization: string);

Append code to embed this image inside Pascal source code.

Source: images/castleimages.pas (line 954).

Public procedure AlphaBleed(const ProgressTitle: string = ''); virtual;

Set the RGB colors for transparent pixels to the nearest non-transparent colors. This fixes problems with black/white borders around the texture regions, when the texture is scaled down (by any means – on CPU, during rendering on GPU...).

The algorithm implemented here, for now, is really slow (but also really correct). It should only be used as a last resort, when your normal tool (like Spine atlas packer) cannot do a decent job on a given image. You should use this when creating assets, and save the resulting image to disk (avoid doing this at runtime during the game, since it's really really slow).

Source: images/castleimages.pas (line 971).

Public function MakeAlphaBleed(const ProgressTitle: string = ''): TCastleImage; virtual;

This item has no description.

Source: images/castleimages.pas (line 972).

Public procedure FillEllipse(const x, y: single; const aRadiusX, aRadiusY: single; const aColor: TCastleColor); virtual; deprecated 'do not use TCastleImage drawing; use other libraries (like FpImage or Vampyre Imaging or BGRABitmap) or our TDrawableImage (use RenderToImageBegin/End, and DrawCircle/DrawCircleOutline to draw ellipses using GPU)';

Warning: this symbol is deprecated: do not use TCastleImage drawing; use other libraries (like FpImage or Vampyre Imaging or BGRABitmap) or our TDrawableImage (use RenderToImageBegin/End, and DrawCircle/DrawCircleOutline to draw ellipses using GPU)

Draw simple geometric shapes like circles, rectangles, lines, etc.

Source: images/castleimages.pas (line 977).

Public procedure Ellipse(const x, y: single; const aRadiusX, aRadiusY: single; const aWidth: single; const aColor: TCastleColor); virtual; deprecated 'do not use TCastleImage drawing; use other libraries (like FpImage or Vampyre Imaging or BGRABitmap) or our TDrawableImage (use RenderToImageBegin/End, and DrawCircle/DrawCircleOutline to draw ellipses using GPU)';

Warning: this symbol is deprecated: do not use TCastleImage drawing; use other libraries (like FpImage or Vampyre Imaging or BGRABitmap) or our TDrawableImage (use RenderToImageBegin/End, and DrawCircle/DrawCircleOutline to draw ellipses using GPU)

This item has no description.

Source: images/castleimages.pas (line 980).

Public procedure FillRectangle(const x1, y1, x2, y2: single; const aColor: TCastleColor); virtual; deprecated 'do not use TCastleImage drawing; use other libraries (like FpImage or Vampyre Imaging or BGRABitmap) or our TDrawableImage (use RenderToImageBegin/End, and DrawRectangle/DrawRectangleOutline to draw rectangles using GPU)';

Warning: this symbol is deprecated: do not use TCastleImage drawing; use other libraries (like FpImage or Vampyre Imaging or BGRABitmap) or our TDrawableImage (use RenderToImageBegin/End, and DrawRectangle/DrawRectangleOutline to draw rectangles using GPU)

This item has no description.

Source: images/castleimages.pas (line 983).

Public procedure Rectangle(const x1, y1, x2, y2: single; const aWidth: single; const aColor: TCastleColor); virtual; deprecated 'do not use TCastleImage drawing; use other libraries (like FpImage or Vampyre Imaging or BGRABitmap) or our TDrawableImage (use RenderToImageBegin/End, and DrawRectangle/DrawRectangleOutline to draw rectangles using GPU)';

Warning: this symbol is deprecated: do not use TCastleImage drawing; use other libraries (like FpImage or Vampyre Imaging or BGRABitmap) or our TDrawableImage (use RenderToImageBegin/End, and DrawRectangle/DrawRectangleOutline to draw rectangles using GPU)

This item has no description.

Source: images/castleimages.pas (line 986).

Public procedure Line(const x1, y1, x2, y2: single; const aWidth: single; const aColor: TCastleColor); virtual; deprecated 'do not use TCastleImage drawing; use other libraries (like FpImage or Vampyre Imaging or BGRABitmap) or our TDrawableImage (use RenderToImageBegin/End, and DrawPrimitive2D to draw lines using GPU)';

Warning: this symbol is deprecated: do not use TCastleImage drawing; use other libraries (like FpImage or Vampyre Imaging or BGRABitmap) or our TDrawableImage (use RenderToImageBegin/End, and DrawPrimitive2D to draw lines using GPU)

This item has no description.

Source: images/castleimages.pas (line 989).

Public procedure FloodFill(const x, y: integer; const aColor: TCastleColor; const aThreshold: single = 0); deprecated 'do not use TCastleImage drawing; use other libraries (like FpImage or Vampyre Imaging or BGRABitmap) for drawing on images';

Warning: this symbol is deprecated: do not use TCastleImage drawing; use other libraries (like FpImage or Vampyre Imaging or BGRABitmap) for drawing on images

This item has no description.

Source: images/castleimages.pas (line 992).

Protected procedure DrawFromCore(const Source: TCastleImage; const X, Y, SourceX, SourceY, SourceWidth, SourceHeight: Integer; const Mode: TDrawMode); override;

This item has no description. Showing description inherited from TCastleImage.DrawFromCore.

Like DrawFrom, but can assume that all coordinates and sizes are valid. Override this to add copying using some more sophisticated method than just memory copying (so also for handling mode other than dmBlend).

Source: images/castleimages_class_grayscale.inc (line 31).

Protected function GetColors(const X, Y, Z: Integer): TCastleColor; override;

This item has no description.

Source: images/castleimages_class_grayscale.inc (line 34).

Protected procedure SetColors(const X, Y, Z: Integer; const C: TCastleColor); override;

This item has no description.

Source: images/castleimages_class_grayscale.inc (line 35).

Protected procedure AssignProperties(const Source: TCastleImage); override;

This item has no description. Showing description inherited from TCastleImage.AssignProperties.

Assign properties (other than Url, sizes and pixel contents).

Used when creating a copy like MakeCopy, MakeRotated, MakeResized and so on. This is not used by Assign, so Assign implementation overrides must make sure to do the same thing (or call AssignProperties in descendants).

Source: images/castleimages_class_grayscale.inc (line 36).

Public constructor Create; overload; override;

This item has no description. Showing description inherited from TCastleImage.Create.

Constructor without parameters creates image with Width = Height = Depth = 0 and RawPixels = nil, so IsEmpty will return True.

Source: images/castleimages_class_grayscale.inc (line 38).

Public class function PixelSize: Cardinal; override;

This item has no description. Showing description inherited from TCastleImage.PixelSize.

Size of TPixel in bytes for this TCastleImage descendant.

Source: images/castleimages_class_grayscale.inc (line 46).

Public class function ColorComponentsCount: Cardinal; override;

This item has no description. Showing description inherited from TCastleImage.ColorComponentsCount.

Number of color components in TPixel.

E.g. RGB is 3 components and RGB+Alpha is 4 components, RGB+Exponent is 3 components (because it describes only Red, Green and Blue values (Exponent value is just used to correctly interpret these, it's not a 4th component)).

Source: images/castleimages_class_grayscale.inc (line 47).

Public function PixelPtr(const X, Y: Cardinal; const Z: Cardinal = 0): PByte;

This item has no description.

Source: images/castleimages_class_grayscale.inc (line 49).

Public function RowPtr(const Y: Cardinal; const Z: Cardinal = 0): PByteArray;

This item has no description.

Source: images/castleimages_class_grayscale.inc (line 50).

Public procedure InvertColors; override;

This item has no description. Showing description inherited from TCastleImage.InvertColors.

Inverts all colors (RGB or grayscale, but doesn't touch alpha channel). "Inverting" means changing color C in range [0..1] to 1-C, so black becomes white, white becomes black etc.

For descendants implementors: Override it if necessary, otherwise the default implementation in this class will raise EInternalError.

Source: images/castleimages_class_grayscale.inc (line 52).

Public procedure Clear(const Pixel: TVector4Byte); override;

This item has no description. Showing description inherited from TCastleImage.Clear.

Set all image pixels to the same color.

Source: images/castleimages_class_grayscale.inc (line 54).

Public function IsClear(const Pixel: TVector4Byte): boolean; override;

This item has no description. Showing description inherited from TCastleImage.IsClear.

Check do all image pixels have the same color.

Source: images/castleimages_class_grayscale.inc (line 55).

Public procedure Clear(const Pixel: Byte); reintroduce; overload;

This item has no description.

Source: images/castleimages_class_grayscale.inc (line 57).

Public function IsClear(const Pixel: Byte): boolean; reintroduce; overload;

This item has no description.

Source: images/castleimages_class_grayscale.inc (line 58).

Public procedure HalfColors;

Every pixels value is halved (divided by 2). This is done by simple bitshift, so you can be sure that all components are < 2ˆ7 after this.

Source: images/castleimages_class_grayscale.inc (line 63).

Public function ToGrayscaleAlphaImage: TGrayscaleAlphaImage; deprecated 'create TGrayscaleAlphaImage and use TGrayscaleAlphaImage.Assign';

Warning: this symbol is deprecated: create TGrayscaleAlphaImage and use TGrayscaleAlphaImage.Assign

Add alpha channel.

If TreatAsAlpha = False: add constant opaque alpha.

If TreatAsAlpha = True: output alpha will be derived from source grayscale, output luminance will be derived from ColorWhenTreatedAsAlpha.

Source: images/castleimages_class_grayscale.inc (line 71).

Public function ToFpImage: TInternalCastleFpImage; override;

This item has no description. Showing description inherited from TEncodedImage.ToFpImage.

Convert image contents to FpImage instance. The resulting instance is owned by the caller.

Source: images/castleimages_class_grayscale.inc (line 74).

Public procedure LerpWith(const Value: Single; SecondImage: TCastleImage); override;

This item has no description. Showing description inherited from TCastleImage.LerpWith.

Makes linear interpolation of colors from this image and the SecondImage. Intuitively, every pixel in new image is set to

(1 - Value) * Self[pixel] + Value * SecondImage[pixel]

Both images need to have the exact same size. If they are not, EImageLerpDifferentSizes is raised.

Not all TCastleImage combinations are allowed. Every subclass is required to override this to at least handle Lerp between itself. That is, TRGBImage.Lerp has to handle Lerp with other TRGBImage, TRGBAlphaImage.Lerp has to handle Lerp with other TRGBAlphaImage etc. Other combinations may be permitted, if useful and implemented. EImageLerpInvalidClasses is raised if given class combinations are not allowed.

In this class, this simply always raises EImageLerpInvalidClasses.

Source: images/castleimages_class_grayscale.inc (line 77).

Public class procedure MixColors(const OutputColor: Pointer; const Weights: TVector4; const AColors: TVector4Pointer); override;

This item has no description. Showing description inherited from TCastleImage.MixColors.

Mix 4 colors, with 4 weights, into a resulting color. All 4 Colors and OutputColor must be pointers to a pixel of current image class, that is they must point to PixelSize bytes of memory.

Source: images/castleimages_class_grayscale.inc (line 78).

Public function AlphaChannel( const AlphaTolerance: Byte): TAlphaChannel; override;

This item has no description. Showing description inherited from TEncodedImage.AlphaChannel.

Analyze image contents to determine if, and what kind, of alpha channel it has.

This may be a time-consuming operation. When the image has alpha channel and we need to decide whether it's suitable for "alpha test" (only fully opaque or fully transparent pixels) or "alpha blending" (any alpha value makes sense) then this method needs to iterate over image pixels.

For this reason, the result of this operation is cached at various levels, e.g. TImageTextureNode and TDrawableImage cache it internally.

We determine "alpha test - simple yes/no alpha channel" if all the alpha values (for every pixel) are 0, or 255, or (when AlphaTolerance <> 0) are close to them by AlphaTolerance. So, to be precise, alpha value must be <= AlphaTolerance, or >= 255 - AlphaTolerance. If any alpha value is between [AlphaTolerance + 1, 255 - AlphaTolerance - 1] then we return "alpha blending - full range alpha channel".

Note that big values of AlphaTolerance make it easier to quality image as "alpha test - simple yes/no alpha channel". When AlphaTolerance >= 128, all images are treated as "simple yes/no alpha". Usually, you want to keep AlphaTolerance small.

Descendants implementors notes: in this class, this simply always returns atNone. For descendants that have alpha channel, implement it, honouring AlphaTolerance as described.

Source: images/castleimages_class_grayscale.inc (line 123).

Public procedure Assign(const Source: TCastleImage); override;

This item has no description. Showing description inherited from TCastleImage.Assign.

Copy size and contents from Source. This sets our size (Width, Height and Depth) to match Source image, and copies pixels from the Source image, converting them as closely as possible. For example, converting RGBA to RGB will strip alpha channel, but copy RGB values.

When implementing descendants: the base implementation of this method in TCastleImage handles only the case when Image class equals our own class. And raises EImageAssignmentError in other cases. Override this method if you want to actually handle some conversions when assignning.

Source: images/castleimages_class_grayscale.inc (line 126).

Public procedure FillEllipse(const x, y: single; const aRadiusX, aRadiusY: single; const aColor: TCastleColor); override;

This item has no description. Showing description inherited from TCastleImage.FillEllipse.

Draw simple geometric shapes like circles, rectangles, lines, etc.

Source: images/castleimages_class_grayscale.inc (line 128).

Public procedure Ellipse(const x, y: single; const aRadiusX, aRadiusY: single; const aWidth: single; const aColor: TCastleColor); override;

This item has no description.

Source: images/castleimages_class_grayscale.inc (line 130).

Public procedure FillRectangle(const x1, y1, x2, y2: single; const aColor: TCastleColor); override;

This item has no description.

Source: images/castleimages_class_grayscale.inc (line 132).

Public procedure Rectangle(const x1, y1, x2, y2: single; const aWidth: single; const aColor: TCastleColor); override;

This item has no description.

Source: images/castleimages_class_grayscale.inc (line 134).

Public procedure Line(const x1, y1, x2, y2: single; const aWidth: single; const aColor: TCastleColor); override;

This item has no description.

Source: images/castleimages_class_grayscale.inc (line 136).

Properties

Public property Url: String read FUrl write FUrl;

Url from which this image was loaded, if any.

Source: images/castleimages.pas (line 186).

Public property Width: Cardinal read FWidth;

This item has no description.

Source: images/castleimages.pas (line 190).

Public property Height: Cardinal read FHeight;

This item has no description.

Source: images/castleimages.pas (line 191).

Public property Depth: Cardinal read FDepth;

Depth of the image. For 2D images (most common) this is just 1.

All images in CastleImages can be potentially 3D, which means they can have Depth > 1. A 3D image is just a 3-dimensional array of pixels, and you can use it e.g. as a texture with 3D texture coordinates. A sample use-cases for 3D textures are:

  • Generated colors of some material that you can imagine as a 3D volume, like a volume of wood or marble. This is nice to apply on any complicated 3D shape, because the necessary 3D texture coordinates are trivial, since 3D position of a point on the shape can be used as a reasonable 3D texture coordinate.

  • Medical data, some scans are 3D.

  • Noise (like Perlin noise) used for various effects in shaders.

  • Specialized noise, e.g. a volume of smoke, or a volume of clouds.

Source: images/castleimages.pas (line 215).

Public property RawPixels: Pointer read FRawPixels;

Image data. The layout of this memory is defined by descendants. For example, for TCastleImage it's a simple array of pixels (see TCastleImage docs for exact description of the memory layout), for TGPUCompressedImage it's a compressed data for GPU.

Note that this may be Nil, if Width * Height * Depth = 0. In this case, IsEmpty returns True.

Source: images/castleimages.pas (line 224).

Public property Colors [const X,Y,Z: Integer]: TCastleColor read GetColors write SetColors;

Get or set the color of the pixel. The given value TCastleColor is a 4D vector representing the color RGB and "alpha" (opacity).

When setting the TCastleColor value on image descendants that don't store alpha information, we ignore the provided alpha value. For example, if you do MyImage.Colors[0, 0, 0] := Vector4(1, 1, 0, 0.5) (setting color to half-transparent yellow) but MyImage is TRGBImage, then the alpha value 0.5 will be ignored. We will only set the RGB channels, to (1,1,0), in the above example.

When reading the color for image descendants that store only grayscale color, we just replicate the grayscale value to all three RGB channels.

When setting the color for image descendants that store only grayscale color, we calculate the weighted average (see GrayscaleValue) of RGB channels provided.

Caller is responsible for checking the correctness of given X, Y, Z coordinates. For speed, we may not check them inside (so nasty memory errors will occur in case of invalid coordinates).

Source: images/castleimages.pas (line 592).

Public property Pixels: PByte read GetPixels;

Pointer to pixels. Same as RawPixels, only typecasted to PByte.

Source: images/castleimages_class_grayscale.inc (line 41).

Public property GrayscalePixels: PByte read GetPixels; deprecated 'use Pixels';

Warning: this symbol is deprecated: use Pixels

This item has no description.

Source: images/castleimages_class_grayscale.inc (line 42).

Public property PixelsArray: PByteArray read GetPixelsArray;

Pointer to pixels. Same as RawPixels, only typecasted to PByteArray.

Source: images/castleimages_class_grayscale.inc (line 44).

Public property TreatAsAlpha: boolean read FTreatAsAlpha write FTreatAsAlpha default false;

Should we treat grayscale image as pure alpha channel (without any color information) when using this as a texture.

This property is meaningful for some operations:

  1. When creating OpenGL texture from this image. If True, then the grayscale pixel data will be loaded as alpha channel contents. When the texture is read by shaders, the RGB is (1,1,1) and alpha comes from the image.

    Note the we don't pass ColorWhenTreatedAsAlpha to OpenGL, as we don't have this functionality (e.g. https://www.khronos.org/opengl/wiki/Texture#Swizzle_mask cannot express an arbitrary but constant color on some channels.)

  2. When using DrawFrom / DrawTo methods or being assigned to something using Assign. If True, this image is drawn like an RGBA image, with constant RGB color ColorWhenTreatedAsAlpha, and alpha channel taken from contents of this image.

  3. It is also the only way for TGrayscaleImage to return AlphaChannel <> acNone.

Source: images/castleimages_class_grayscale.inc (line 108).

Public property ColorWhenTreatedAsAlpha: TVector3Byte read FColorWhenTreatedAsAlpha write SetColorWhenTreatedAsAlpha;

Used for drawing/assigning when TreatAsAlpha is True, and we need the base (not alpha) color for some equation. By default white (255, 255, 255).

Source: images/castleimages_class_grayscale.inc (line 114).

Public property GrayscaleColorWhenTreatedAsAlpha: Byte read FGrayscaleColorWhenTreatedAsAlpha;

Automatically derived from ColorWhenTreatedAsAlpha by averaging RGB components to calculate grayscale luminance. By default 255.

Source: images/castleimages_class_grayscale.inc (line 120).


Generated by PasDoc 0.17.0.snapshot.