Class TGrayscaleImage

Unit

Declaration

type TGrayscaleImage = class(TCastleImage)

Description

Grayscale image. Color is a simple Byte value.

Hierarchy

Overview

Methods

Protected procedure DrawFromCore(Source: TCastleImage; 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 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

Methods

Protected procedure DrawFromCore(Source: TCastleImage; 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).

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

This item has no description.

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

This item has no description.

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).

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.

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.

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)).

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

This item has no description.

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

This item has no description.

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.

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.

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.

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

This item has no description.

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

This item has no description.

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.

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 intensity will be derived from ColorWhenTreatedAsAlpha.

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.

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.

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.

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.

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.

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.

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

This item has no description.

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

This item has no description.

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

This item has no description.

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

This item has no description.

Properties

Public property Pixels: PByte read GetPixels;

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

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

Warning: this symbol is deprecated: use Pixels

This item has no description.

Public property PixelsArray: PByteArray read GetPixelsArray;

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

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.

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).

Public property GrayscaleColorWhenTreatedAsAlpha: Byte read FGrayscaleColorWhenTreatedAsAlpha;

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


Generated by PasDoc 0.16.0-snapshot.