Class TglBitmapData

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TglBitmapData = class(TObject)

Description

class to store texture data in. used to load, save and manipulate data before assigned to texture object all operations on a data object can be done from a background thread

Hierarchy

  • TObject
  • TglBitmapData

Overview

Fields

Private fData: PByte;
Private fDimension: TglBitmapSize;
Private fFormat: TglBitmapFormat;
Private fFilename: String;
Private fScanlines: array of PByte;
Private fHasScanlines: Boolean;

Methods

Private function GetFormatDescriptor: TglBitmapFormatDescriptor;
Private function GetWidth: Integer;
Private function GetHeight: Integer;
Private function GetScanlines(const aIndex: Integer): PByte;
Private procedure SetFormat(const aValue: TglBitmapFormat);
Private procedure PrepareResType(var aResource: String; var aResType: PChar);
Private procedure UpdateScanlines;
Private function LoadPNG(const aStream: TStream): Boolean; virtual;
Private procedure SavePNG(const aStream: TStream); virtual;
Private function LoadJPEG(const aStream: TStream): Boolean; virtual;
Private procedure SaveJPEG(const aStream: TStream); virtual;
Private function LoadRAW(const aStream: TStream): Boolean;
Private procedure SaveRAW(const aStream: TStream);
Private function LoadBMP(const aStream: TStream): Boolean;
Private procedure SaveBMP(const aStream: TStream);
Private function LoadTGA(const aStream: TStream): Boolean;
Private procedure SaveTGA(const aStream: TStream);
Private function LoadDDS(const aStream: TStream): Boolean;
Private procedure SaveDDS(const aStream: TStream);
Public function FlipHorz: Boolean; virtual;
Public function FlipVert: Boolean; virtual;
Public procedure LoadFromFile(const aFilename: String);
Public procedure LoadFromStream(const aStream: TStream); virtual;
Public procedure LoadFromFunc(const aSize: TglBitmapSize; const aFunc: TglBitmapFunction; const aFormat: TglBitmapFormat; const aArgs: Pointer = nil);
Public procedure LoadFromResource(const aInstance: Cardinal; aResource: String; aResType: PChar = nil);
Public procedure LoadFromResourceID(const aInstance: Cardinal; const aResourceID: Integer; const aResType: PChar);
Public procedure SaveToFile(const aFilename: String; const aFileType: TglBitmapFileType);
Public procedure SaveToStream(const aStream: TStream; const aFileType: TglBitmapFileType); virtual;
Public function Convert(const aFunc: TglBitmapFunction; const aCreateTemp: Boolean; const aArgs: Pointer = nil): Boolean; overload;
Public function Convert(const aSource: TglBitmapData; const aFunc: TglBitmapFunction; aCreateTemp: Boolean; const aFormat: TglBitmapFormat; const aArgs: Pointer = nil): Boolean; overload;
Public function ConvertTo(const aFormat: TglBitmapFormat): Boolean; virtual;
Public function AssignToLazIntfImage(const aImage: TLazIntfImage): Boolean;
Public function AssignFromLazIntfImage(const aImage: TLazIntfImage): Boolean;
Public function AssignAlphaToLazIntfImage(const aImage: TLazIntfImage): Boolean;
Public function AddAlphaFromLazIntfImage(const aImage: TLazIntfImage; const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;
Public function AddAlphaFromResource(const aInstance: Cardinal; aResource: String; aResType: PChar = nil; const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;
Public function AddAlphaFromResourceID(const aInstance: Cardinal; const aResourceID: Integer; const aResType: PChar; const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;
Public function AddAlphaFromFunc(const aFunc: TglBitmapFunction; const aArgs: Pointer = nil): Boolean; virtual;
Public function AddAlphaFromFile(const aFileName: String; const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;
Public function AddAlphaFromStream(const aStream: TStream; const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;
Public function AddAlphaFromDataObj(const aDataObj: TglBitmapData; aFunc: TglBitmapFunction; const aArgs: Pointer): Boolean;
Public function AddAlphaFromColorKey(const aRed, aGreen, aBlue: Byte; const aDeviation: Byte = 0): Boolean;
Public function AddAlphaFromColorKeyRange(const aRed, aGreen, aBlue: Cardinal; const aDeviation: Cardinal = 0): Boolean;
Public function AddAlphaFromColorKeyFloat(const aRed, aGreen, aBlue: Single; const aDeviation: Single = 0): Boolean;
Public function AddAlphaFromValue(const aAlpha: Byte): Boolean;
Public function AddAlphaFromValueRange(const aAlpha: Cardinal): Boolean;
Public function AddAlphaFromValueFloat(const aAlpha: Single): Boolean;
Public function RemoveAlpha: Boolean; virtual;
Public procedure FillWithColor(const aRed, aGreen, aBlue: Byte; const aAlpha: Byte = 255);
Public procedure FillWithColorRange(const aRed, aGreen, aBlue: Cardinal; const aAlpha: Cardinal = $FFFFFFFF);
Public procedure FillWithColorFloat(const aRed, aGreen, aBlue: Single; const aAlpha: Single = 1.0);
Public procedure SetData(const aData: PByte; const aFormat: TglBitmapFormat; const aWidth: Integer = -1; const aHeight: Integer = -1); virtual;
Public function Clone: TglBitmapData;
Public procedure Invert(const aRed, aGreen, aBlue, aAlpha: Boolean);
Public procedure GenerateNormalMap(const aFunc: TglBitmapNormalMapFunc = nm3x3; const aScale: Single = 2; const aUseAlpha: Boolean = false);
Public constructor Create; overload;
Public constructor Create(const aFileName: String); overload;
Public constructor Create(const aStream: TStream); overload;
Public constructor Create(const aSize: TglBitmapSize; const aFormat: TglBitmapFormat; aData: PByte = nil); overload;
Public constructor Create(const aSize: TglBitmapSize; const aFormat: TglBitmapFormat; const aFunc: TglBitmapFunction; const aArgs: Pointer = nil); overload;
Public constructor Create(const aInstance: Cardinal; const aResource: String; const aResType: PChar = nil); overload;
Public constructor Create(const aInstance: Cardinal; const aResourceID: Integer; const aResType: PChar); overload;
Public destructor Destroy; override;

Properties

Public property Data: PByte read fData;
Public property Dimension: TglBitmapSize read fDimension;
Public property Filename: String read fFilename;
Public property Width: Integer read GetWidth;
Public property Height: Integer read GetHeight;
Public property Format: TglBitmapFormat read fFormat write SetFormat;
Public property Scanlines[constaIndex:Integer]: PByte read GetScanlines;
Public property FormatDescriptor: TglBitmapFormatDescriptor read GetFormatDescriptor;

Description

Fields

Private fData: PByte;

texture data

Private fDimension: TglBitmapSize;

pixel size of the data

Private fFormat: TglBitmapFormat;

format the texture data is stored in

Private fFilename: String;

file the data was load from

Private fScanlines: array of PByte;

pointer to begin of each line

Private fHasScanlines: Boolean;

True if scanlines are initialized, False otherwise

Methods

Private function GetFormatDescriptor: TglBitmapFormatDescriptor;
 
Returns

the format descriptor suitable to the texture data format

Private function GetWidth: Integer;
 
Returns

the width of the texture data (in pixel) or -1 if no data is set

Private function GetHeight: Integer;
 
Returns

the height of the texture data (in pixel) or -1 if no data is set

Private function GetScanlines(const aIndex: Integer): PByte;

get scanline at index aIndex

Returns

Pointer to start of line or Nil

Private procedure SetFormat(const aValue: TglBitmapFormat);

set new value for the data format. only possible if new format has the same pixel size. if you want to convert the texture data, see ConvertTo function

Private procedure PrepareResType(var aResource: String; var aResType: PChar);

splits a resource identifier into the resource and it's type

Parameters
aResource
resource identifier to split and store name in
aResType
type of the resource
Private procedure UpdateScanlines;

updates scanlines array

Private function LoadPNG(const aStream: TStream): Boolean; virtual;

try to load a PNG from a stream

Parameters
aStream
stream to load PNG from
Returns

True on success, False otherwise

Private procedure SavePNG(const aStream: TStream); virtual;

save texture data as PNG to stream

Parameters
aStream
stream to save data to
Private function LoadJPEG(const aStream: TStream): Boolean; virtual;

try to load a JPEG from a stream

Parameters
aStream
stream to load JPEG from
Returns

True on success, False otherwise

Private procedure SaveJPEG(const aStream: TStream); virtual;

save texture data as JPEG to stream

Parameters
aStream
stream to save data to
Private function LoadRAW(const aStream: TStream): Boolean;

try to load a RAW image from a stream

Parameters
aStream
stream to load RAW image from
Returns

True on success, False otherwise

Private procedure SaveRAW(const aStream: TStream);

save texture data as RAW image to stream

Parameters
aStream
stream to save data to
Private function LoadBMP(const aStream: TStream): Boolean;

try to load a BMP from a stream

Parameters
aStream
stream to load BMP from
Returns

True on success, False otherwise

Private procedure SaveBMP(const aStream: TStream);

save texture data as BMP to stream

Parameters
aStream
stream to save data to
Private function LoadTGA(const aStream: TStream): Boolean;

try to load a TGA from a stream

Parameters
aStream
stream to load TGA from
Returns

True on success, False otherwise

Private procedure SaveTGA(const aStream: TStream);

save texture data as TGA to stream

Parameters
aStream
stream to save data to
Private function LoadDDS(const aStream: TStream): Boolean;

try to load a DDS from a stream

Parameters
aStream
stream to load DDS from
Returns

True on success, False otherwise

Private procedure SaveDDS(const aStream: TStream);

save texture data as DDS to stream

Parameters
aStream
stream to save data to
Public function FlipHorz: Boolean; virtual;

flip texture horizontal

Returns

True in success, False otherwise

Public function FlipVert: Boolean; virtual;

flip texture vertical

Returns

True in success, False otherwise

Public procedure LoadFromFile(const aFilename: String);

load a texture from a file

Parameters
aFilename
file to load texuture from
Public procedure LoadFromStream(const aStream: TStream); virtual;

load a texture from a stream

Parameters
aStream
stream to load texture from
Public procedure LoadFromFunc(const aSize: TglBitmapSize; const aFunc: TglBitmapFunction; const aFormat: TglBitmapFormat; const aArgs: Pointer = nil);

use a function to generate texture data

Parameters
aSize
size of the texture
aFunc
callback to use for generation
aFormat
format of the texture data
aArgs
user defined paramaters (use at will)
Public procedure LoadFromResource(const aInstance: Cardinal; aResource: String; aResType: PChar = nil);

load a texture from a resource

Parameters
aInstance
resource handle
aResource
resource indentifier
aResType
resource type (if known)
Public procedure LoadFromResourceID(const aInstance: Cardinal; const aResourceID: Integer; const aResType: PChar);

load a texture from a resource id

Parameters
aInstance
resource handle
aResource
resource ID
aResType
resource type
Public procedure SaveToFile(const aFilename: String; const aFileType: TglBitmapFileType);

save texture data to a file

Parameters
aFilename
filename to store texture in
aFileType
file type to store data into
Public procedure SaveToStream(const aStream: TStream; const aFileType: TglBitmapFileType); virtual;

save texture data to a stream

Parameters
aFilename
filename to store texture in
aFileType
file type to store data into
Public function Convert(const aFunc: TglBitmapFunction; const aCreateTemp: Boolean; const aArgs: Pointer = nil): Boolean; overload;

convert texture data using a user defined callback

Parameters
aFunc
callback to use for converting
aCreateTemp
create a temporary buffer to use for converting
aArgs
user defined paramters (use at will)
Returns

True if converting was successful, False otherwise

Public function Convert(const aSource: TglBitmapData; const aFunc: TglBitmapFunction; aCreateTemp: Boolean; const aFormat: TglBitmapFormat; const aArgs: Pointer = nil): Boolean; overload;

convert texture data using a user defined callback

Parameters
aSource
glBitmap to read data from
aFunc
callback to use for converting
aCreateTemp
create a temporary buffer to use for converting
aFormat
format of the new data
aArgs
user defined paramters (use at will)
Returns

True if converting was successful, False otherwise

Public function ConvertTo(const aFormat: TglBitmapFormat): Boolean; virtual;

convert texture data using a specific format

Parameters
aFormat
new format of texture data
Returns

True if converting was successful, False otherwise

Public function AssignToLazIntfImage(const aImage: TLazIntfImage): Boolean;

assign texture data to TLazIntfImage object

Parameters
aImage
TLazIntfImage to write data to
Returns

True on success, False otherwise

Public function AssignFromLazIntfImage(const aImage: TLazIntfImage): Boolean;

assign texture data from TLazIntfImage object

Parameters
aImage
TLazIntfImage to read data from
Returns

True on success, False otherwise

Public function AssignAlphaToLazIntfImage(const aImage: TLazIntfImage): Boolean;

assign alpha channel data to TLazIntfImage object

Parameters
aImage
TLazIntfImage to write data to
Returns

True on success, False otherwise

Public function AddAlphaFromLazIntfImage(const aImage: TLazIntfImage; const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;

assign alpha channel data from TLazIntfImage object

Parameters
aImage
TLazIntfImage to read data from
aFunc
callback to use for converting
aArgs
user defined parameters (use at will)
Returns

True on success, False otherwise

Public function AddAlphaFromResource(const aInstance: Cardinal; aResource: String; aResType: PChar = nil; const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;

load alpha channel data from resource

Parameters
aInstance
resource handle
aResource
resource ID
aResType
resource type
aFunc
callback to use for converting
aArgs
user defined parameters (use at will)
Returns

True on success, False otherwise

Public function AddAlphaFromResourceID(const aInstance: Cardinal; const aResourceID: Integer; const aResType: PChar; const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;

load alpha channel data from resource ID

Parameters
aInstance
resource handle
aResourceID
resource ID
aResType
resource type
aFunc
callback to use for converting
aArgs
user defined parameters (use at will)
Returns

True on success, False otherwise

Public function AddAlphaFromFunc(const aFunc: TglBitmapFunction; const aArgs: Pointer = nil): Boolean; virtual;

add alpha channel data from function

Parameters
aFunc
callback to get data from
aArgs
user defined parameters (use at will)
Returns

True on success, False otherwise

Public function AddAlphaFromFile(const aFileName: String; const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;

add alpha channel data from file (macro for: new glBitmap, LoadFromFile, AddAlphaFromGlBitmap)

Parameters
aFilename
file to load alpha channel data from
aFunc
callback to use for converting
aArgs
SetFormat user defined parameters (use at will)
Returns

True on success, False otherwise

Public function AddAlphaFromStream(const aStream: TStream; const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;

add alpha channel data from stream (macro for: new glBitmap, LoadFromStream, AddAlphaFromGlBitmap)

Parameters
aStream
stream to load alpha channel data from
aFunc
callback to use for converting
aArgs
user defined parameters (use at will)
Returns

True on success, False otherwise

Public function AddAlphaFromDataObj(const aDataObj: TglBitmapData; aFunc: TglBitmapFunction; const aArgs: Pointer): Boolean;

add alpha channel data from existing glBitmap object

Parameters
aBitmap
TglBitmap to copy alpha channel data from
aFunc
callback to use for converting
aArgs
user defined parameters (use at will)
Returns

True on success, False otherwise

Public function AddAlphaFromColorKey(const aRed, aGreen, aBlue: Byte; const aDeviation: Byte = 0): Boolean;

add alpha to pixel if the pixels color is greter than the given color value

Parameters
aRed
red threshold (0-255)
aGreen
green threshold (0-255)
aBlue
blue threshold (0-255)
aDeviatation
accepted deviatation (0-255)
Returns

True on success, False otherwise

Public function AddAlphaFromColorKeyRange(const aRed, aGreen, aBlue: Cardinal; const aDeviation: Cardinal = 0): Boolean;

add alpha to pixel if the pixels color is greter than the given color value

Parameters
aRed
red threshold (0-Range.r)
aGreen
green threshold (0-Range.g)
aBlue
blue threshold (0-Range.b)
aDeviatation
accepted deviatation (0-max(Range.rgb))
Returns

True on success, False otherwise

Public function AddAlphaFromColorKeyFloat(const aRed, aGreen, aBlue: Single; const aDeviation: Single = 0): Boolean;

add alpha to pixel if the pixels color is greter than the given color value

Parameters
aRed
red threshold (0.0-1.0)
aGreen
green threshold (0.0-1.0)
aBlue
blue threshold (0.0-1.0)
aDeviatation
accepted deviatation (0.0-1.0)
Returns

True on success, False otherwise

Public function AddAlphaFromValue(const aAlpha: Byte): Boolean;

add a constand alpha value to all pixels

Parameters
aAlpha
alpha value to add (0-255)
Returns

True on success, False otherwise

Public function AddAlphaFromValueRange(const aAlpha: Cardinal): Boolean;

add a constand alpha value to all pixels

Parameters
aAlpha
alpha value to add (0-max(Range.rgb))
Returns

True on success, False otherwise

Public function AddAlphaFromValueFloat(const aAlpha: Single): Boolean;

add a constand alpha value to all pixels

Parameters
aAlpha
alpha value to add (0.0-1.0)
Returns

True on success, False otherwise

Public function RemoveAlpha: Boolean; virtual;

remove alpha channel

Returns

True on success, False otherwise

Public procedure FillWithColor(const aRed, aGreen, aBlue: Byte; const aAlpha: Byte = 255);

fill complete texture with one color

Parameters
aRed
red color for border (0-255)
aGreen
green color for border (0-255)
aBlue
blue color for border (0-255)
aAlpha
alpha color for border (0-255)
Public procedure FillWithColorRange(const aRed, aGreen, aBlue: Cardinal; const aAlpha: Cardinal = $FFFFFFFF);

fill complete texture with one color

Parameters
aRed
red color for border (0-Range.r)
aGreen
green color for border (0-Range.g)
aBlue
blue color for border (0-Range.b)
aAlpha
alpha color for border (0-Range.a)
Public procedure FillWithColorFloat(const aRed, aGreen, aBlue: Single; const aAlpha: Single = 1.0);

fill complete texture with one color

Parameters
aRed
red color for border (0.0-1.0)
aGreen
green color for border (0.0-1.0)
aBlue
blue color for border (0.0-1.0)
aAlpha
alpha color for border (0.0-1.0)
Public procedure SetData(const aData: PByte; const aFormat: TglBitmapFormat; const aWidth: Integer = -1; const aHeight: Integer = -1); virtual;

set data pointer of texture data

Parameters
aData
pointer to new texture data
aFormat
format of the data stored at aData
aWidth
width of the texture data
aHeight
height of the texture data
Public function Clone: TglBitmapData;

create a clone of the current object

Returns

clone of this object

Public procedure Invert(const aRed, aGreen, aBlue, aAlpha: Boolean);

invert color data (bitwise not)

Parameters
aRed
invert red channel
aGreen
invert green channel
aBlue
invert blue channel
aAlpha
invert alpha channel
Public procedure GenerateNormalMap(const aFunc: TglBitmapNormalMapFunc = nm3x3; const aScale: Single = 2; const aUseAlpha: Boolean = false);

create normal map from texture data

Parameters
aFunc
normal map function to generate normalmap with
aScale
scale of the normale stored in the normal map
aUseAlpha
generate normalmap from alpha channel data (if present)
Public constructor Create; overload;

constructor - creates a texutre data object

Public constructor Create(const aFileName: String); overload;

constructor - creates a texture data object and loads it from a file

Parameters
aFilename
file to load texture from
Public constructor Create(const aStream: TStream); overload;

constructor - creates a texture data object and loads it from a stream

Parameters
aStream
stream to load texture from
Public constructor Create(const aSize: TglBitmapSize; const aFormat: TglBitmapFormat; aData: PByte = nil); overload;

constructor - creates a texture data object with the given size, format and data

Parameters
aSize
size of the texture
aFormat
format of the given data
aData
texture data - be carefull: the data will now be managed by the texture data object
Public constructor Create(const aSize: TglBitmapSize; const aFormat: TglBitmapFormat; const aFunc: TglBitmapFunction; const aArgs: Pointer = nil); overload;

constructor - creates a texture data object with the given size and format and uses the given callback to create the data

Parameters
aSize
size of the texture
aFormat
format of the given data
aFunc
callback to use for generating the data
aArgs
user defined parameters (use at will)
Public constructor Create(const aInstance: Cardinal; const aResource: String; const aResType: PChar = nil); overload;

constructor - creates a texture data object and loads it from a resource

Parameters
aInstance
resource handle
aResource
resource indentifier
aResType
resource type (if known)
Public constructor Create(const aInstance: Cardinal; const aResourceID: Integer; const aResType: PChar); overload;

constructor - creates a texture data object and loads it from a resource

Parameters
aInstance
resource handle
aResourceID
resource ID
aResType
resource type (if known)
Public destructor Destroy; override;

destructor

Properties

Public property Data: PByte read fData;

texture data (be carefull with this!)

Public property Dimension: TglBitmapSize read fDimension;

size of the texture data (in pixel)

Public property Filename: String read fFilename;

file the data was loaded from

Public property Width: Integer read GetWidth;

width of the texture data (in pixel)

Public property Height: Integer read GetHeight;

height of the texture data (in pixel)

Public property Format: TglBitmapFormat read fFormat write SetFormat;

format the texture data is stored in

Public property Scanlines[constaIndex:Integer]: PByte read GetScanlines;

pointer to begin of line at given index or Nil

Public property FormatDescriptor: TglBitmapFormatDescriptor read GetFormatDescriptor;

descriptor object that describes the format of the stored data


Generated by PasDoc 0.13.0 on 2014-12-24 04:27:09