# Class TglBitmapData

Description | Hierarchy | Fields | Methods | Properties

## Unit

glBitmap

## 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

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

### Methods

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

### Properties

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

## Description

### Fields

| `fData: PByte;`
texture data

| `fDimension: TglBitmapSize;`
pixel size of the data

| `fFormat: TglBitmapFormat;`
format the texture data is stored in

| `fFilename: String;`
file the data was load from

| `fScanlines: array of PByte;`
pointer to begin of each line

| `fHasScanlines: Boolean;`
`True` if scanlines are initialized, `False` otherwise

### Methods

| `function GetFormatDescriptor: TglBitmapFormatDescriptor;`

###### Returns

the format descriptor suitable to the texture data format

| `function GetWidth: Integer;`

###### Returns

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

| `function GetHeight: Integer;`

###### Returns

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

| `function GetScanlines(const aIndex: Integer): PByte;`

get scanline at index aIndex

###### Returns

Pointer to start of line or `Nil`

| `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

| `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

| `procedure UpdateScanlines;`
updates scanlines array

| `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

| `procedure SavePNG(const aStream: TStream); virtual;`

save texture data as PNG to stream

###### Parameters

aStream
  stream to save data to

| `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

| `procedure SaveJPEG(const aStream: TStream); virtual;`

save texture data as JPEG to stream

###### Parameters

aStream
  stream to save data to

| `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

| `procedure SaveRAW(const aStream: TStream);`

save texture data as RAW image to stream

###### Parameters

aStream
  stream to save data to

| `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

| `procedure SaveBMP(const aStream: TStream);`

save texture data as BMP to stream

###### Parameters

aStream
  stream to save data to

| `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

| `procedure SaveTGA(const aStream: TStream);`

save texture data as TGA to stream

###### Parameters

aStream
  stream to save data to

| `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

| `procedure SaveDDS(const aStream: TStream);`

save texture data as DDS to stream

###### Parameters

aStream
  stream to save data to

| `function FlipHorz: Boolean; virtual;`

flip texture horizontal

###### Returns

`True` in success, `False` otherwise

| `function FlipVert: Boolean; virtual;`

flip texture vertical

###### Returns

`True` in success, `False` otherwise

| `procedure LoadFromFile(const aFilename: String);`

load a texture from a file

###### Parameters

aFilename
  file to load texuture from

| `procedure LoadFromStream(const aStream: TStream); virtual;`

load a texture from a stream

###### Parameters

aStream
  stream to load texture from

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

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

| `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

| `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

| `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

| `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

| `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

| `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

| `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

| `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

| `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

| `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

| `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

| `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

| `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

| `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

| `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

| `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

| `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

| `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

| `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

| `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

| `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

| `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

| `function RemoveAlpha: Boolean; virtual;`

remove alpha channel

###### Returns

`True` on success, `False` otherwise

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

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

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

| `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

| `function Clone: TglBitmapData;`

create a clone of the current object

###### Returns

clone of this object

| `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

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

| `constructor Create; overload;`
constructor - creates a texutre data object

| `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

| `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

| `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

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

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

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

| `destructor Destroy; override;`
destructor

### Properties

| `property Data: PByte read fData;`
texture data (be carefull with this!)

| `property Dimension: TglBitmapSize read fDimension;`
size of the texture data (in pixel)

| `property Filename: String read fFilename;`
file the data was loaded from

| `property Width: Integer read GetWidth;`
width of the texture data (in pixel)

| `property Height: Integer read GetHeight;`
height of the texture data (in pixel)

| `property Format: TglBitmapFormat read fFormat write SetFormat;`
format the texture data is stored in

| `property Scanlines[constaIndex:Integer]: PByte read GetScanlines;`
pointer to begin of line at given index or `Nil`

| `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