{***********************************************************
glBitmap by Steffen Xonna aka Lossy eX (2003-2008)
http://www.opengl24.de/index.php?cat=header&file=glbitmap
+
+modified by Delphi OpenGL Community (http://delphigl.com/)
+
+
------------------------------------------------------------
The contents of this file are used with permission, subject to
the Mozilla Public License Version 1.1 (the "License"); you may
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// activate to enable build-in OpenGL support with statically linked methods
// use dglOpenGL.pas if not enabled
-{$DEFINE GLB_NATIVE_OGL_STATIC}
+{.$DEFINE GLB_NATIVE_OGL_STATIC}
// activate to enable build-in OpenGL support with dynamically linked methods
// use dglOpenGL.pas if not enabled
-{$DEFINE GLB_NATIVE_OGL_DYNAMIC}
+{.$DEFINE GLB_NATIVE_OGL_DYNAMIC}
// activate to enable the support for SDL_surfaces
{.$DEFINE GLB_SDL}
// If you enable SDL_image all other libraries will be ignored!
{.$DEFINE GLB_SDL_IMAGE}
-// activate to enable png support with the unit pngimage. You can download it from http://pngdelphi.sourceforge.net/
+// PNG /////////////////////////////////////////////////////////////////////////////////////////////
+// activate to enable png support with the unit pngimage -> http://pngdelphi.sourceforge.net/
// if you enable pngimage the libPNG will be ignored
-{.$DEFINE GLB_PNGIMAGE}
+{$DEFINE GLB_PNGIMAGE}
-// activate to use the libPNG http://www.libpng.org/
-// You will need an aditional header.
-// http://www.opengl24.de/index.php?cat=header&file=libpng
+// activate to use the libPNG -> http://www.libpng.org/
+// You will need an aditional header -> http://www.opengl24.de/index.php?cat=header&file=libpng
{.$DEFINE GLB_LIB_PNG}
+// JPEG ////////////////////////////////////////////////////////////////////////////////////////////
// if you enable delphi jpegs the libJPEG will be ignored
{.$DEFINE GLB_DELPHI_JPEG}
-// activateto use the libJPEG http://www.ijg.org/
-// You will need an aditional header.
-// http://www.opengl24.de/index.php?cat=header&file=libjpeg
+// activate to use the libJPEG -> http://www.ijg.org/
+// You will need an aditional header -> http://www.opengl24.de/index.php?cat=header&file=libjpeg
{.$DEFINE GLB_LIB_JPEG}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// PRIVATE: DO not change anything! //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// PRIVATE: do not change anything! //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Delphi Versions
{$IFDEF fpc}
type
////////////////////////////////////////////////////////////////////////////////////////////////////
- EglBitmapException = class(Exception);
- EglBitmapSizeToLargeException = class(EglBitmapException);
- EglBitmapNonPowerOfTwoException = class(EglBitmapException);
- EglBitmapUnsupportedFormatFormat = class(EglBitmapException);
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
TglBitmapFormat = (
tfEmpty = 0, //must be smallest value!
nm3x3,
nm5x5);
+ ////////////////////////////////////////////////////////////////////////////////////////////////////
+ EglBitmapException = class(Exception);
+ EglBitmapSizeToLargeException = class(EglBitmapException);
+ EglBitmapNonPowerOfTwoException = class(EglBitmapException);
+ EglBitmapUnsupportedFormat = class(EglBitmapException)
+ constructor Create(const aFormat: TglBitmapFormat);
+ end;
+
////////////////////////////////////////////////////////////////////////////////////////////////////
TglBitmapColorRec = packed record
case Integer of
Position: TglBitmapPixelPosition;
Source: TglBitmapPixelData;
Dest: TglBitmapPixelData;
- Args: PtrInt;
+ Args: Pointer;
end;
TglBitmapFunction = procedure(var FuncRec: TglBitmapFunctionRec);
procedure SetAnisotropic(const aValue: Integer);
procedure CreateID;
- procedure SetupParameters(var aBuildWithGlu: Boolean);
+ procedure SetupParameters(out aBuildWithGlu: Boolean);
procedure SetDataPointer(const aData: PByte; const aFormat: TglBitmapFormat;
const aWidth: Integer = -1; const aHeight: Integer = -1); virtual;
procedure GenTexture(const aTestTextureSize: Boolean = true); virtual; abstract;
procedure LoadFromFile(const aFilename: String);
procedure LoadFromStream(const aStream: TStream); virtual;
procedure LoadFromFunc(const aSize: TglBitmapPixelPosition; const aFunc: TglBitmapFunction;
- const aFormat: TglBitmapFormat; const aArgs: PtrInt = 0);
+ const aFormat: TglBitmapFormat; const aArgs: Pointer = nil);
{$IFDEF GLB_DELPHI}
procedure LoadFromResource(const aInstance: Cardinal; const aResource: String; const aResType: PChar = nil);
procedure LoadFromResourceID(const sInstance: Cardinal; const aResourceID: Integer; const aResType: PChar);
procedure SaveToStream(const aStream: TStream; const aFileType: TglBitmapFileType); virtual;
//Convert
- function AddFunc(const aFunc: TglBitmapFunction; const aCreateTemp: Boolean; const aArgs: PtrInt = 0): Boolean; overload;
+ function AddFunc(const aFunc: TglBitmapFunction; const aCreateTemp: Boolean; const aArgs: Pointer = nil): Boolean; overload;
function AddFunc(const aSource: TglBitmap; const aFunc: TglBitmapFunction; aCreateTemp: Boolean;
- const aFormat: TglBitmapFormat; const aArgs: PtrInt = 0): Boolean; overload;
+ const aFormat: TglBitmapFormat; const aArgs: Pointer = nil): Boolean; overload;
public
//Alpha & Co
{$IFDEF GLB_SDL}
function AssignFromSurface(const aSurface: PSDL_Surface): Boolean;
function AssignAlphaToSurface(out aSurface: PSDL_Surface): Boolean;
function AddAlphaFromSurface(const aSurface: PSDL_Surface; const aFunc: TglBitmapFunction = nil;
- const aArgs: PtrInt = 0): Boolean;
+ const aArgs: Pointer = nil): Boolean;
{$ENDIF}
{$IFDEF GLB_DELPHI}
function AssignFromBitmap(const aBitmap: TBitmap): Boolean;
function AssignAlphaToBitmap(const aBitmap: TBitmap): Boolean;
function AddAlphaFromBitmap(const aBitmap: TBitmap; const aFunc: TglBitmapFunction = nil;
- const aArgs: PtrInt = 0): Boolean;
+ const aArgs: Pointer = nil): Boolean;
function AddAlphaFromResource(const aInstance: Cardinal; const aResource: String; const aResType: PChar = nil;
- const aFunc: TglBitmapFunction = nil; const aArgs: PtrInt = 0): Boolean;
+ 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: PtrInt = 0): Boolean;
+ const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;
{$ENDIF}
- function AddAlphaFromFunc(const aFunc: TglBitmapFunction; const aArgs: PtrInt = 0): Boolean; virtual;
- function AddAlphaFromFile(const aFileName: String; const aFunc: TglBitmapFunction = nil; const aArgs: PtrInt = 0): Boolean;
- function AddAlphaFromStream(const aStream: TStream; const aFunc: TglBitmapFunction = nil; const aArgs: PtrInt = 0): Boolean;
- function AddAlphaFromGlBitmap(const aBitmap: TglBitmap; aFunc: TglBitmapFunction = nil; const aArgs: PtrInt = 0): 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 AddAlphaFromGlBitmap(const aBitmap: TglBitmap; aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): 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;
const T: Cardinal = GL_CLAMP_TO_EDGE;
const R: Cardinal = GL_CLAMP_TO_EDGE);
- procedure GetPixel(const aPos: TglBitmapPixelPosition; var aPixel: TglBitmapPixelData); virtual;
- procedure SetPixel(const aPos: TglBitmapPixelPosition; const aPixel: TglBitmapPixelData); virtual;
-
procedure Bind(const aEnableTextureUnit: Boolean = true); virtual;
procedure Unbind(const aDisableTextureUnit: Boolean = true); virtual;
constructor Create(const aFileName: String); overload;
constructor Create(const aStream: TStream); overload;
constructor Create(const aSize: TglBitmapPixelPosition; const aFormat: TglBitmapFormat); overload;
- constructor Create(const aSize: TglBitmapPixelPosition; const aFormat: TglBitmapFormat; const aFunc: TglBitmapFunction; const aArgs: PtrInt = 0); overload;
+ constructor Create(const aSize: TglBitmapPixelPosition; const aFormat: TglBitmapFormat; const aFunc: TglBitmapFunction; const aArgs: Pointer = nil); overload;
{$IFDEF GLB_DELPHI}
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;
{$ENDIF}
private
- {$IFDEF GLB_SUPPORT_PNG_READ}
- function LoadPNG(const aStream: TStream): Boolean; virtual;
- procedure SavePNG(const aStream: TStream); virtual;
- {$ENDIF}
- {$IFDEF GLB_SUPPORT_JPEG_READ}
- function LoadJPEG(const aStream: TStream): Boolean; virtual;
- procedure SaveJPEG(const aStream: TStream); virtual;
- {$ENDIF}
+ {$IFDEF GLB_SUPPORT_PNG_READ} function LoadPNG(const aStream: TStream): Boolean; virtual; {$ENDIF}
+ {$ifdef GLB_SUPPORT_PNG_WRITE} procedure SavePNG(const aStream: TStream); virtual; {$ENDIF}
+
+ {$IFDEF GLB_SUPPORT_JPEG_READ} function LoadJPEG(const aStream: TStream): Boolean; virtual; {$ENDIF}
+ {$IFDEF GLB_SUPPORT_JPEG_WRITE} procedure SaveJPEG(const aStream: TStream); virtual; {$ENDIF}
+
function LoadBMP(const aStream: TStream): Boolean; virtual;
procedure SaveBMP(const aStream: TStream); virtual;
*)
uses
- Math, syncobjs;
+ Math, syncobjs, typinfo;
type
////////////////////////////////////////////////////////////////////////////////////////////////////
TFormatDescriptor = class(TObject)
private
- function GetRedMask: UInt64;
- function GetGreenMask: UInt64;
- function GetBlueMask: UInt64;
- function GetAlphaMask: UInt64;
+ function GetRedMask: QWord;
+ function GetGreenMask: QWord;
+ function GetBlueMask: QWord;
+ function GetAlphaMask: QWord;
protected
fFormat: TglBitmapFormat;
fWithAlpha: TglBitmapFormat;
property Range: TglBitmapColorRec read fRange;
property Shift: TShiftRec read fShift;
- property RedMask: UInt64 read GetRedMask;
- property GreenMask: UInt64 read GetGreenMask;
- property BlueMask: UInt64 read GetBlueMask;
- property AlphaMask: UInt64 read GetAlphaMask;
+ property RedMask: QWord read GetRedMask;
+ property GreenMask: QWord read GetGreenMask;
+ property BlueMask: QWord read GetBlueMask;
+ property AlphaMask: QWord read GetAlphaMask;
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); virtual; abstract;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); virtual; abstract;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); virtual; abstract;
function GetSize(const aSize: TglBitmapPixelPosition): Integer; virtual; overload;
function GetSize(const aWidth, aHeight: Integer): Integer; virtual; overload;
function IsEmpty: Boolean; virtual;
function HasAlpha: Boolean; virtual;
- function MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: UInt64): Boolean; virtual;
+ function MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: QWord): Boolean; virtual;
procedure PreparePixel(out aPixel: TglBitmapPixelData); virtual;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TfdAlpha_UB1 = class(TFormatDescriptor) //1* unsigned byte
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
TfdLuminance_UB1 = class(TFormatDescriptor) //1* unsigned byte
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
TfdUniversal_UB1 = class(TFormatDescriptor) //1* unsigned byte
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
TfdLuminanceAlpha_UB2 = class(TfdLuminance_UB1) //2* unsigned byte
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
TfdRGB_UB3 = class(TFormatDescriptor) //3* unsigned byte
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
TfdBGR_UB3 = class(TFormatDescriptor) //3* unsigned byte (inverse)
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
TfdRGBA_UB4 = class(TfdRGB_UB3) //4* unsigned byte
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
TfdBGRA_UB4 = class(TfdBGR_UB3) //4* unsigned byte (inverse)
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TfdAlpha_US1 = class(TFormatDescriptor) //1* unsigned short
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
TfdLuminance_US1 = class(TFormatDescriptor) //1* unsigned short
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
TfdUniversal_US1 = class(TFormatDescriptor) //1* unsigned short
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
TfdDepth_US1 = class(TFormatDescriptor) //1* unsigned short
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
TfdLuminanceAlpha_US2 = class(TfdLuminance_US1) //2* unsigned short
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
TfdRGB_US3 = class(TFormatDescriptor) //3* unsigned short
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
TfdBGR_US3 = class(TFormatDescriptor) //3* unsigned short (inverse)
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
TfdRGBA_US4 = class(TfdRGB_US3) //4* unsigned short
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
TfdBGRA_US4 = class(TfdBGR_US3) //4* unsigned short (inverse)
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TfdUniversal_UI1 = class(TFormatDescriptor) //1* unsigned int
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
TfdDepth_UI1 = class(TFormatDescriptor) //1* unsigned int
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
TfdS3tcDtx1RGBA = class(TFormatDescriptor)
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
TfdS3tcDtx3RGBA = class(TFormatDescriptor)
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
TfdS3tcDtx5RGBA = class(TFormatDescriptor)
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
constructor Create; override;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TbmpBitfieldFormat = class(TFormatDescriptor)
private
- procedure SetRedMask (const aValue: UInt64);
- procedure SetGreenMask(const aValue: UInt64);
- procedure SetBlueMask (const aValue: UInt64);
- procedure SetAlphaMask(const aValue: UInt64);
+ procedure SetRedMask (const aValue: QWord);
+ procedure SetGreenMask(const aValue: QWord);
+ procedure SetBlueMask (const aValue: QWord);
+ procedure SetAlphaMask(const aValue: QWord);
- procedure Update(aMask: UInt64; out aRange: Cardinal; out aShift: Byte);
+ procedure Update(aMask: QWord; out aRange: Cardinal; out aShift: Byte);
public
- property RedMask: UInt64 read GetRedMask write SetRedMask;
- property GreenMask: UInt64 read GetGreenMask write SetGreenMask;
- property BlueMask: UInt64 read GetBlueMask write SetBlueMask;
- property AlphaMask: UInt64 read GetAlphaMask write SetAlphaMask;
+ property RedMask: QWord read GetRedMask write SetRedMask;
+ property GreenMask: QWord read GetGreenMask write SetGreenMask;
+ property BlueMask: QWord read GetBlueMask write SetBlueMask;
+ property AlphaMask: QWord read GetAlphaMask write SetAlphaMask;
property PixelSize: Single read fPixelSize write fPixelSize;
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure CreateColorTable;
procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
- procedure Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+ procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
destructor Destroy; override;
end;
FormatDescriptorCS: TCriticalSection;
FormatDescriptors: array[TglBitmapFormat] of TFormatDescriptor;
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+constructor EglBitmapUnsupportedFormat.Create(const aFormat: TglBitmapFormat);
+begin
+ inherited Create('unsupported format: ' + GetEnumName(TypeInfo(TglBitmapFormat), Integer(aFormat)));
+end;
+
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function glBitmapPosition(X, Y: Integer): TglBitmapPixelPosition;
begin
tfS3tcDtx1RGBA, tfS3tcDtx3RGBA, tfS3tcDtx5RGBA]) then
result := result + [ftDDS];
- (* TODO
{$IFDEF GLB_SUPPORT_PNG_WRITE}
if aFormat in [
- tfAlpha4, tfAlpha8, tfAlpha12, tfAlpha16,
- tfLuminance4, tfLuminance8, tfLuminance12, tfLuminance16,
- tfuminance4Alpha4, tfLuminance6Alpha2, tfLuminance8Alpha8, tfLuminance12Alpha4, tfLuminance12Alpha12, tfLuminance16Alpha16,
- tfR3G3B2, tfRGB4, tfRGB5, tfRGB8, tfRGB10, tfRGB12, tfRGB16,
- tfRGBA2, tfRGBA4, tfRGB5A1, tfRGBA8, tfRGB10A2, tfRGBA12, tfRGBA16,
- tfDepth16, tfDepth24, tfDepth32]
- then
+ tfAlpha8, tfLuminance8, tfLuminance8Alpha8,
+ tfRGB8, tfRGBA8,
+ tfBGR8, tfBGRA8] then
result := result + [ftPNG];
{$ENDIF}
{$IFDEF GLB_SUPPORT_JPEG_WRITE}
- if Format in [
- tfAlpha4, tfAlpha8, tfAlpha12, tfAlpha16,
- tfLuminance4, tfLuminance8, tfLuminance12, tfLuminance16,
- tfR3G3B2, tfRGB4, tfRGB5, tfRGB8, tfRGB10, tfRGB12, tfRGB16,
- tfDepth16, tfDepth24, tfDepth32]
- then
+ if aFormat in [tfAlpha8, tfLuminance8, tfRGB8, tfBGR8] then
result := result + [ftJPEG];
{$ENDIF}
-
- if aFormat in [
- tfAlpha4, tfAlpha8, tfAlpha12, tfAlpha16,
- tfLuminance4, tfLuminance8, tfLuminance12, tfLuminance16,
- tfuminance4Alpha4, tfLuminance6Alpha2, tfLuminance8Alpha8, tfLuminance12Alpha4, tfLuminance12Alpha12, tfLuminance16Alpha16,
- tfR3G3B2, tfRGB4, tfRGB5, tfRGB8, tfRGB10, tfRGB12, tfRGB16,
- tfRGBA2, tfRGBA4, tfRGB5A1, tfRGBA8, tfRGB10A2, tfRGBA12, tfRGBA16,
- tfDepth16, tfDepth24, tfDepth32]
- then
- result := result + [ftDDS, ftTGA, ftBMP];
- *)
end;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
end;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function GetTopMostBit(aBitSet: UInt64): Integer;
+function GetTopMostBit(aBitSet: QWord): Integer;
begin
result := 0;
while aBitSet > 0 do begin
end;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function CountSetBits(aBitSet: UInt64): Integer;
+function CountSetBits(aBitSet: QWord): Integer;
begin
result := 0;
while aBitSet > 0 do begin
aLibHandle := GL_LibHandle;
{$IF DEFINED(GLB_WIN)}
- result := GetProcAddress(HMODULE(aLibHandle), aProcName);
+ result := GetProcAddress({%H-}HMODULE(aLibHandle), aProcName);
if Assigned(result) then
exit;
function glbLoadLibrary(const aName: PChar): Pointer;
begin
{$IF DEFINED(GLB_WIN)}
- result := Pointer(LoadLibrary(aName));
+ result := {%H-}Pointer(LoadLibrary(aName));
{$ELSEIF DEFINED(GLB_LINUX)}
result := dlopen(Name, RTLD_LAZY);
{$ELSE}
exit;
{$IF DEFINED(GLB_WIN)}
- Result := FreeLibrary(HINST(aLibHandle));
+ Result := FreeLibrary({%H-}HINST(aLibHandle));
{$ELSEIF DEFINED(GLB_LINUX)}
Result := dlclose(aLibHandle) = 0;
{$ENDIF}
end;
-var
- p: Pointer;
begin
if Assigned(GL_LibHandle) then
glbFreeLibrary(GL_LibHandle);
MajorVersion, MinorVersion: Integer;
///////////////////////////////////////////////////////////////////////////////////////////
- procedure TrimVersionString(Buffer: AnsiString; var Major, Minor: Integer);
+ procedure TrimVersionString(aBuffer: AnsiString; out aMajor, aMinor: Integer);
var
Separator: Integer;
begin
- Minor := 0;
- Major := 0;
+ aMinor := 0;
+ aMajor := 0;
- Separator := Pos(AnsiString('.'), Buffer);
- if (Separator > 1) and (Separator < Length(Buffer)) and
- (Buffer[Separator - 1] in ['0'..'9']) and
- (Buffer[Separator + 1] in ['0'..'9']) then begin
+ Separator := Pos(AnsiString('.'), aBuffer);
+ if (Separator > 1) and (Separator < Length(aBuffer)) and
+ (aBuffer[Separator - 1] in ['0'..'9']) and
+ (aBuffer[Separator + 1] in ['0'..'9']) then begin
Dec(Separator);
- while (Separator > 0) and (Buffer[Separator] in ['0'..'9']) do
+ while (Separator > 0) and (aBuffer[Separator] in ['0'..'9']) do
Dec(Separator);
- Delete(Buffer, 1, Separator);
- Separator := Pos(AnsiString('.'), Buffer) + 1;
+ Delete(aBuffer, 1, Separator);
+ Separator := Pos(AnsiString('.'), aBuffer) + 1;
- while (Separator <= Length(Buffer)) and (AnsiChar(Buffer[Separator]) in ['0'..'9']) do
+ while (Separator <= Length(aBuffer)) and (AnsiChar(aBuffer[Separator]) in ['0'..'9']) do
Inc(Separator);
- Delete(Buffer, Separator, 255);
- Separator := Pos(AnsiString('.'), Buffer);
+ Delete(aBuffer, Separator, 255);
+ Separator := Pos(AnsiString('.'), aBuffer);
- Major := StrToInt(Copy(String(Buffer), 1, Separator - 1));
- Minor := StrToInt(Copy(String(Buffer), Separator + 1, 1));
+ aMajor := StrToInt(Copy(String(aBuffer), 1, Separator - 1));
+ aMinor := StrToInt(Copy(String(aBuffer), Separator + 1, 1));
end;
end;
{$ENDIF}
*)
-(* TODO GLB_SDL_IMAGE
{$IFDEF GLB_SDL_IMAGE}
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+// SDL Image Helper /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function glBitmapRWseek(context: PSDL_RWops; offset: Integer; whence: Integer): Integer; cdecl;
begin
result := TStream(context^.unknown.data1).Seek(offset, whence);
result^.unknown.data1 := Stream;
end;
{$ENDIF}
-*)
(* TODO LoadFuncs
function LoadTexture(Filename: String; var Texture: Cardinal{$IFDEF GLB_DELPHI}; LoadFromRes : Boolean; Instance: Cardinal{$ENDIF}): Boolean;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TglBitmapFormatDescriptor///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TFormatDescriptor.GetRedMask: UInt64;
+function TFormatDescriptor.GetRedMask: QWord;
begin
result := fRange.r shl fShift.r;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TFormatDescriptor.GetGreenMask: UInt64;
+function TFormatDescriptor.GetGreenMask: QWord;
begin
result := fRange.g shl fShift.g;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TFormatDescriptor.GetBlueMask: UInt64;
+function TFormatDescriptor.GetBlueMask: QWord;
begin
result := fRange.b shl fShift.b;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TFormatDescriptor.GetAlphaMask: UInt64;
+function TFormatDescriptor.GetAlphaMask: QWord;
begin
result := fRange.a shl fShift.a;
end;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TFormatDescriptor.MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: UInt64): Boolean;
+function TFormatDescriptor.MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: QWord): Boolean;
begin
result := false;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TFormatDescriptor.PreparePixel(out aPixel: TglBitmapPixelData);
begin
- FillChar(aPixel, SizeOf(aPixel), 0);
+ FillChar(aPixel{%H-}, SizeOf(aPixel), 0);
aPixel.Data := fRange;
aPixel.Range := fRange;
aPixel.Format := fFormat;
inc(aData);
end;
-procedure TfdAlpha_UB1.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdAlpha_UB1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
begin
aPixel.Data.r := 0;
aPixel.Data.g := 0;
inc(aData);
end;
-procedure TfdLuminance_UB1.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdLuminance_UB1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
begin
aPixel.Data.r := aData^;
aPixel.Data.g := aData^;
inc(aData);
end;
-procedure TfdUniversal_UB1.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdUniversal_UB1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
var
i: Integer;
begin
inc(aData);
end;
-procedure TfdLuminanceAlpha_UB2.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdLuminanceAlpha_UB2.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
begin
inherited Unmap(aData, aPixel, aMapData);
aPixel.Data.a := aData^;
inc(aData);
end;
-procedure TfdRGB_UB3.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdRGB_UB3.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
begin
aPixel.Data.r := aData^;
inc(aData);
inc(aData);
end;
-procedure TfdBGR_UB3.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdBGR_UB3.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
begin
aPixel.Data.b := aData^;
inc(aData);
inc(aData);
end;
-procedure TfdRGBA_UB4.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdRGBA_UB4.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
begin
inherited Unmap(aData, aPixel, aMapData);
aPixel.Data.a := aData^;
inc(aData);
end;
-procedure TfdBGRA_UB4.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdBGRA_UB4.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
begin
inherited Unmap(aData, aPixel, aMapData);
aPixel.Data.a := aData^;
inc(aData, 2);
end;
-procedure TfdAlpha_US1.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdAlpha_US1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
begin
aPixel.Data.r := 0;
aPixel.Data.g := 0;
inc(aData, 2);
end;
-procedure TfdLuminance_US1.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdLuminance_US1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
begin
aPixel.Data.r := PWord(aData)^;
aPixel.Data.g := PWord(aData)^;
inc(aData, 2);
end;
-procedure TfdUniversal_US1.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdUniversal_US1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
var
i: Integer;
begin
inc(aData, 2);
end;
-procedure TfdDepth_US1.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdDepth_US1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
begin
aPixel.Data.r := PWord(aData)^;
aPixel.Data.g := PWord(aData)^;
inc(aData, 2);
end;
-procedure TfdLuminanceAlpha_US2.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdLuminanceAlpha_US2.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
begin
inherited Unmap(aData, aPixel, aMapData);
aPixel.Data.a := PWord(aData)^;
inc(aData, 2);
end;
-procedure TfdRGB_US3.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdRGB_US3.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
begin
aPixel.Data.r := PWord(aData)^;
inc(aData, 2);
inc(aData, 2);
end;
-procedure TfdBGR_US3.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdBGR_US3.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
begin
aPixel.Data.b := PWord(aData)^;
inc(aData, 2);
inc(aData, 2);
end;
-procedure TfdRGBA_US4.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdRGBA_US4.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
begin
inherited Unmap(aData, aPixel, aMapData);
aPixel.Data.a := PWord(aData)^;
inc(aData, 2);
end;
-procedure TfdBGRA_US4.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdBGRA_US4.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
begin
inherited Unmap(aData, aPixel, aMapData);
aPixel.Data.a := PWord(aData)^;
inc(aData, 4);
end;
-procedure TfdUniversal_UI1.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdUniversal_UI1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
var
i: Integer;
begin
inc(aData, 4);
end;
-procedure TfdDepth_UI1.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdDepth_UI1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
begin
aPixel.Data.r := PCardinal(aData)^;
aPixel.Data.g := PCardinal(aData)^;
raise EglBitmapException.Create('mapping for compressed formats is not supported');
end;
-procedure TfdS3tcDtx1RGBA.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdS3tcDtx1RGBA.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
begin
raise EglBitmapException.Create('mapping for compressed formats is not supported');
end;
raise EglBitmapException.Create('mapping for compressed formats is not supported');
end;
-procedure TfdS3tcDtx3RGBA.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdS3tcDtx3RGBA.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
begin
raise EglBitmapException.Create('mapping for compressed formats is not supported');
end;
raise EglBitmapException.Create('mapping for compressed formats is not supported');
end;
-procedure TfdS3tcDtx5RGBA.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdS3tcDtx5RGBA.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
begin
raise EglBitmapException.Create('mapping for compressed formats is not supported');
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//TBitfieldFormat/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TbmpBitfieldFormat.SetRedMask(const aValue: UInt64);
+procedure TbmpBitfieldFormat.SetRedMask(const aValue: QWord);
begin
Update(aValue, fRange.r, fShift.r);
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TbmpBitfieldFormat.SetGreenMask(const aValue: UInt64);
+procedure TbmpBitfieldFormat.SetGreenMask(const aValue: QWord);
begin
Update(aValue, fRange.g, fShift.g);
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TbmpBitfieldFormat.SetBlueMask(const aValue: UInt64);
+procedure TbmpBitfieldFormat.SetBlueMask(const aValue: QWord);
begin
Update(aValue, fRange.b, fShift.b);
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TbmpBitfieldFormat.SetAlphaMask(const aValue: UInt64);
+procedure TbmpBitfieldFormat.SetAlphaMask(const aValue: QWord);
begin
Update(aValue, fRange.a, fShift.a);
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TbmpBitfieldFormat.Update(aMask: UInt64; out aRange: Cardinal; out
+procedure TbmpBitfieldFormat.Update(aMask: QWord; out aRange: Cardinal; out
aShift: Byte);
begin
aShift := 0;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TbmpBitfieldFormat.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
var
- data: UInt64;
+ data: QWord;
s: Integer;
-type
- PUInt64 = ^UInt64;
begin
data :=
((aPixel.Data.r and fRange.r) shl fShift.r) or
1: aData^ := data;
2: PWord(aData)^ := data;
4: PCardinal(aData)^ := data;
- 8: PUInt64(aData)^ := data;
+ 8: PQWord(aData)^ := data;
else
raise EglBitmapException.CreateFmt('invalid pixel size: %.1f', [fPixelSize]);
end;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TbmpBitfieldFormat.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TbmpBitfieldFormat.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
var
- data: UInt64;
+ data: QWord;
s, i: Integer;
-type
- PUInt64 = ^UInt64;
begin
s := Round(fPixelSize);
case s of
1: data := aData^;
2: data := PWord(aData)^;
4: data := PCardinal(aData)^;
- 8: data := PUInt64(aData)^;
+ 8: data := PQWord(aData)^;
else
raise EglBitmapException.CreateFmt('invalid pixel size: %.1f', [fPixelSize]);
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TbmpColorTableFormat.CreateColorTable;
var
- bits: Byte;
- len: Integer;
i: Integer;
begin
if not (Format in [tfLuminance4, tfLuminance8, tfR3G3B2]) then
if (aMapData = nil) then
aData^ := 0;
d := LuminanceWeight(aPixel) and Range.r;
- aData^ := aData^ or (d shl (4 - PtrInt(aMapData)));
+ aData^ := aData^ or (d shl (4 - {%H-}PtrUInt(aMapData)));
inc(aMapData, 4);
- if (PtrInt(aMapData) >= 8) then begin
+ if ({%H-}PtrUInt(aMapData) >= 8) then begin
inc(aData);
aMapData := nil;
end;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TbmpColorTableFormat.Unmap(var aData: PByte; var aPixel: TglBitmapPixelData; var aMapData: Pointer);
-type
- PUInt64 = ^UInt64;
+procedure TbmpColorTableFormat.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
var
- idx: UInt64;
+ idx: QWord;
s: Integer;
bits: Byte;
f: Single;
f := fPixelSize - s;
bits := Round(8 * f);
case s of
- 0: idx := (aData^ shr (8 - bits - PtrInt(aMapData))) and ((1 shl bits) - 1);
+ 0: idx := (aData^ shr (8 - bits - {%H-}PtrUInt(aMapData))) and ((1 shl bits) - 1);
1: idx := aData^;
2: idx := PWord(aData)^;
4: idx := PCardinal(aData)^;
- 8: idx := PUInt64(aData)^;
+ 8: idx := PQWord(aData)^;
else
raise EglBitmapException.CreateFmt('invalid pixel size: %.3f', [fPixelSize]);
end;
aPixel.Data.a := a;
end;
inc(aMapData, bits);
- if (PtrInt(aMapData) >= 8) then begin
+ if ({%H-}PtrUInt(aMapData) >= 8) then begin
inc(aData, 1);
dec(aMapData, 8);
end;
begin
with aFuncRec do begin
Dest.Data := Source.Data;
- if (Args and $1 > 0) then begin
+ if ({%H-}PtrUInt(Args) and $1 > 0) then begin
Dest.Data.r := Dest.Data.r xor Dest.Range.r;
Dest.Data.g := Dest.Data.g xor Dest.Range.g;
Dest.Data.b := Dest.Data.b xor Dest.Range.b;
end;
- if (Args and $2 > 0) then begin
+ if ({%H-}PtrUInt(Args) and $2 > 0) then begin
Dest.Data.a := Dest.Data.a xor Dest.Range.a;
end;
end;
Temp: Single;
begin
with FuncRec do begin
- if (FuncRec.Args = 0) then begin //source has no alpha
+ if (FuncRec.Args = nil) then begin //source has no alpha
Temp :=
Source.Data.r / Source.Range.r * ALPHA_WEIGHT_R +
Source.Data.g / Source.Range.g * ALPHA_WEIGHT_G +
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure glBitmapValueAlphaFunc(var FuncRec: TglBitmapFunctionRec);
-type
- PglBitmapPixelData = ^TglBitmapPixelData;
begin
with FuncRec do begin
Dest.Data.r := Source.Data.r;
if fFormat = aValue then
exit;
if TFormatDescriptor.Get(Format).PixelSize <> TFormatDescriptor.Get(aValue).PixelSize then
- raise EglBitmapUnsupportedFormatFormat.Create('SetInternalFormat - ' + UNSUPPORTED_FORMAT);
+ raise EglBitmapUnsupportedFormat.Create(Format);
SetDataPointer(Data, aValue, Width, Height);
end;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TglBitmap.SetupParameters(var aBuildWithGlu: Boolean);
+procedure TglBitmap.SetupParameters(out aBuildWithGlu: Boolean);
begin
// Set Up Parameters
SetWrap(fWrapS, fWrapT, fWrapR);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TglBitmap.LoadFromFunc(const aSize: TglBitmapPixelPosition; const aFunc: TglBitmapFunction;
- const aFormat: TglBitmapFormat; const aArgs: PtrInt);
+ const aFormat: TglBitmapFormat; const aArgs: Pointer);
var
tmpData: PByte;
size: Integer;
begin
case aFileType of
{$IFDEF GLB_SUPPORT_PNG_WRITE}
- ftPNG: SavePng(aStream);
+ ftPNG: SavePNG(aStream);
{$ENDIF}
{$IFDEF GLB_SUPPORT_JPEG_WRITE}
ftJPEG: SaveJPEG(aStream);
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TglBitmap.AddFunc(const aFunc: TglBitmapFunction; const aCreateTemp: Boolean; const aArgs: PtrInt): Boolean;
+function TglBitmap.AddFunc(const aFunc: TglBitmapFunction; const aCreateTemp: Boolean; const aArgs: Pointer): Boolean;
begin
result := AddFunc(Self, aFunc, aCreateTemp, Format, aArgs);
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TglBitmap.AddFunc(const aSource: TglBitmap; const aFunc: TglBitmapFunction; aCreateTemp: Boolean;
- const aFormat: TglBitmapFormat; const aArgs: PtrInt): Boolean;
+ const aFormat: TglBitmapFormat; const aArgs: Pointer): Boolean;
var
DestData, TmpData, SourceData: pByte;
TempHeight, TempWidth: Integer;
Row, RowSize: Integer;
SourceData, TmpData: PByte;
TempDepth: Integer;
- Pix: TglBitmapPixelData;
- FormatDesc: TglBitmapFormatDescriptor;
+ FormatDesc: TFormatDescriptor;
function GetRowPointer(Row: Integer): pByte;
begin
- result := Surface.pixels;
+ result := aSurface.pixels;
Inc(result, Row * RowSize);
end;
begin
result := false;
- (* TODO
- if not FormatIsUncompressed(InternalFormat) then
- raise EglBitmapUnsupportedInternalFormat.Create('AssignToSurface - ' + UNSUPPORTED_INTERNAL_FORMAT);
- *)
+ FormatDesc := TFormatDescriptor.Get(Format);
+ if FormatDesc.IsCompressed then
+ raise EglBitmapUnsupportedFormat.Create(Format);
- FormatDesc := FORMAT_DESCRIPTORS[Format];
if Assigned(Data) then begin
- case Trunc(FormatDesc.GetSize) of
+ case Trunc(FormatDesc.PixelSize) of
1: TempDepth := 8;
2: TempDepth := 16;
3: TempDepth := 24;
4: TempDepth := 32;
else
- raise EglBitmapException.Create('AssignToSurface - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ raise EglBitmapUnsupportedFormat.Create(Format);
end;
- FormatDesc.PreparePixel(Pix);
- with Pix.PixelDesc do
- Surface := SDL_CreateRGBSurface(SDL_SWSURFACE, Width, Height, TempDepth,
- RedRange shl RedShift, GreenRange shl GreenShift, BlueRange shl BlueShift, AlphaRange shl AlphaShift);
+ aSurface := SDL_CreateRGBSurface(SDL_SWSURFACE, Width, Height, TempDepth,
+ FormatDesc.RedMask, FormatDesc.GreenMask, FormatDesc.BlueMask, FormatDesc.AlphaMask);
SourceData := Data;
- RowSize := Ceil(FileWidth * FormatDesc.GetSize);
+ RowSize := FormatDesc.GetSize(FileWidth, 1);
- for Row := 0 to FileHeight -1 do begin
+ for Row := 0 to FileHeight-1 do begin
TmpData := GetRowPointer(Row);
if Assigned(TmpData) then begin
Move(SourceData^, TmpData^, RowSize);
var
pSource, pData, pTempData: PByte;
Row, RowSize, TempWidth, TempHeight: Integer;
- IntFormat, f: TglBitmapInternalFormat;
- FormatDesc: TglBitmapFormatDescriptor;
+ IntFormat: TglBitmapFormat;
+ FormatDesc: TFormatDescriptor;
function GetRowPointer(Row: Integer): pByte;
begin
- result := Surface^.pixels;
+ result := aSurface^.pixels;
Inc(result, Row * RowSize);
end;
begin
result := false;
- if (Assigned(Surface)) then begin
- with Surface^.format^ do begin
- IntFormat := tfEmpty;
- for f := Low(f) to High(f) do begin
- if FORMAT_DESCRIPTORS[f].MaskMatch(RMask, GMask, BMask, AMask) then begin
- IntFormat := f;
+ if (Assigned(aSurface)) then begin
+ with aSurface^.format^ do begin
+ for IntFormat := High(TglBitmapFormat) to Low(TglBitmapFormat) do begin
+ FormatDesc := TFormatDescriptor.Get(IntFormat);
+ if (FormatDesc.MaskMatch(RMask, GMask, BMask, AMask)) then
break;
- end;
end;
if (IntFormat = tfEmpty) then
raise EglBitmapException.Create('AssignFromSurface - Invalid Pixelformat.');
end;
- FormatDesc := FORMAT_DESCRIPTORS[IntFormat];
- TempWidth := Surface^.w;
- TempHeight := Surface^.h;
- RowSize := Trunc(TempWidth * FormatDesc.GetSize);
+ TempWidth := aSurface^.w;
+ TempHeight := aSurface^.h;
+ RowSize := FormatDesc.GetSize(TempWidth, 1);
GetMem(pData, TempHeight * RowSize);
try
pTempData := pData;
AlphaInterleave := 0;
case Format of
- ifLuminance8Alpha8:
+ tfLuminance8Alpha8:
AlphaInterleave := 1;
- ifBGRA8, ifRGBA8:
+ tfBGRA8, tfRGBA8:
AlphaInterleave := 3;
end;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TglBitmap.AddAlphaFromSurface(const aSurface: PSDL_Surface; const aFunc: TglBitmapFunction; const aArgs: PtrInt): Boolean;
+function TglBitmap.AddAlphaFromSurface(const aSurface: PSDL_Surface; const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean;
var
bmp: TglBitmap2D;
begin
bmp := TglBitmap2D.Create;
try
- bmp.AssignFromSurface(Surface);
- result := AddAlphaFromGlBitmap(bmp, Func, CustomData);
+ bmp.AssignFromSurface(aSurface);
+ result := AddAlphaFromGlBitmap(bmp, aFunc, aArgs);
finally
bmp.Free;
end;
{$ENDIF}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TglBitmap.AddAlphaFromFunc(const aFunc: TglBitmapFunction; const aArgs: PtrInt): Boolean;
+function TglBitmap.AddAlphaFromFunc(const aFunc: TglBitmapFunction; const aArgs: Pointer): Boolean;
begin
- (* TODO
- if not FormatIsUncompressed(InternalFormat) then
- raise EglBitmapUnsupportedFormatFormat.Create('AddAlphaFromFunc - ' + UNSUPPORTED_FORMAT);
- *)
+ if TFormatDescriptor.Get(Format).IsCompressed then
+ raise EglBitmapUnsupportedFormat.Create(Format);
result := AddFunc(Self, aFunc, false, TFormatDescriptor.Get(Format).WithAlpha, aArgs);
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TglBitmap.AddAlphaFromFile(const aFileName: String; const aFunc: TglBitmapFunction; const aArgs: PtrInt): Boolean;
+function TglBitmap.AddAlphaFromFile(const aFileName: String; const aFunc: TglBitmapFunction; const aArgs: Pointer): Boolean;
var
FS: TFileStream;
begin
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TglBitmap.AddAlphaFromStream(const aStream: TStream; const aFunc: TglBitmapFunction; const aArgs: PtrInt): Boolean;
+function TglBitmap.AddAlphaFromStream(const aStream: TStream; const aFunc: TglBitmapFunction; const aArgs: Pointer): Boolean;
var
tex: TglBitmap2D;
begin
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TglBitmap.AddAlphaFromGlBitmap(const aBitmap: TglBitmap; aFunc: TglBitmapFunction; const aArgs: PtrInt): Boolean;
+function TglBitmap.AddAlphaFromGlBitmap(const aBitmap: TglBitmap; aFunc: TglBitmapFunction; const aArgs: Pointer): Boolean;
var
DestData, DestData2, SourceData: pByte;
TempHeight, TempWidth: Integer;
if ((aBitmap.Width = Width) and (aBitmap.Height = Height)) then begin
result := ConvertTo(TFormatDescriptor.Get(Format).WithAlpha);
- if not Assigned(aFunc) then
- aFunc := glBitmapAlphaFunc;
SourceFD := TFormatDescriptor.Get(aBitmap.Format);
DestFD := TFormatDescriptor.Get(Format);
+ if not Assigned(aFunc) then begin
+ aFunc := glBitmapAlphaFunc;
+ FuncRec.Args := {%H-}Pointer(SourceFD.HasAlpha);
+ end else
+ FuncRec.Args := aArgs;
+
// Values
TempHeight := aBitmap.FileHeight;
TempWidth := aBitmap.FileWidth;
FuncRec.Sender := Self;
- FuncRec.Args := aArgs;
FuncRec.Size := Dimension;
FuncRec.Position.Fields := FuncRec.Size.Fields;
- FuncRec.Args := PtrInt(SourceFD.HasAlpha) and 1;
DestData := Data;
DestData2 := Data;
Data.a := 0;
Range.a := 0;
end;
- result := AddAlphaFromFunc(glBitmapColorKeyAlphaFunc, PtrInt(@PixelData));
+ result := AddAlphaFromFunc(glBitmapColorKeyAlphaFunc, @PixelData);
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
TFormatDescriptor.GetWithAlpha(Format).PreparePixel(PixelData);
with PixelData do
Data.a := Min(Range.a, Max(0, Round(Range.a * aAlpha)));
- result := AddAlphaFromFunc(glBitmapValueAlphaFunc, PtrInt(@PixelData.Data.a));
+ result := AddAlphaFromFunc(glBitmapValueAlphaFunc, @PixelData.Data.a);
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
FormatDesc := TFormatDescriptor.Get(Format);
if Assigned(Data) then begin
if FormatDesc.IsCompressed or not FormatDesc.HasAlpha then
- raise EglBitmapUnsupportedFormatFormat.Create('RemoveAlpha - ' + UNSUPPORTED_FORMAT);
+ raise EglBitmapUnsupportedFormat.Create(Format);
result := ConvertTo(FormatDesc.WithoutAlpha);
end;
end;
ShiftData.g := GetShift(SourcePD.Range.g, DestPD.Range.g);
ShiftData.b := GetShift(SourcePD.Range.b, DestPD.Range.b);
ShiftData.a := GetShift(SourcePD.Range.a, DestPD.Range.a);
- result := AddFunc(Self, glBitmapConvertShiftRGBAFunc, false, aFormat, PtrInt(@ShiftData));
+ result := AddFunc(Self, glBitmapConvertShiftRGBAFunc, false, aFormat, @ShiftData);
end else
result := AddFunc(Self, glBitmapConvertCalculateRGBAFunc, false, aFormat);
end else
procedure TglBitmap.Invert(const aUseRGB: Boolean; const aUseAlpha: Boolean);
begin
if aUseRGB or aUseAlpha then
- AddFunc(glBitmapInvertFunc, false, ((PtrInt(aUseAlpha) and 1) shl 1) or (PtrInt(aUseRGB) and 1));
+ AddFunc(glBitmapInvertFunc, false, {%H-}Pointer(
+ ((PtrInt(aUseAlpha) and 1) shl 1) or
+ (PtrInt(aUseRGB) and 1) ));
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Data.b := Max(0, Min(Range.b, Trunc(Range.b * aBlue)));
Data.a := Max(0, Min(Range.a, Trunc(Range.a * aAlpha)));
end;
- AddFunc(glBitmapFillWithColorFunc, false, PtrInt(@PixelData));
+ AddFunc(glBitmapFillWithColorFunc, false, @PixelData);
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TglBitmap.GetPixel(const aPos: TglBitmapPixelPosition; var aPixel: TglBitmapPixelData);
-begin
- { TODO delete?
- if Assigned (fGetPixelFunc) then
- fGetPixelFunc(aPos, aPixel);
- }
-end;
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TglBitmap.SetPixel(const aPos: TglBitmapPixelPosition; const aPixel: TglBitmapPixelData);
-begin
- {TODO delete?
- if Assigned (fSetPixelFunc) then
- fSetPixelFuc(aPos, aPixel);
- }
-end;
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TglBitmap.Bind(const aEnableTextureUnit: Boolean);
begin
if aEnableTextureUnit then
ImageSize: Integer;
begin
Create;
- TFormatDescriptor.Get(aFormat).GetSize(aSize);
+ ImageSize := TFormatDescriptor.Get(aFormat).GetSize(aSize);
GetMem(Image, ImageSize);
try
FillChar(Image^, ImageSize, #$FF);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
constructor TglBitmap.Create(const aSize: TglBitmapPixelPosition; const aFormat: TglBitmapFormat;
- const aFunc: TglBitmapFunction; const aArgs: PtrInt);
+ const aFunc: TglBitmapFunction; const aArgs: Pointer);
begin
Create;
LoadFromFunc(aSize, aFunc, aFormat, aArgs);
Surface := IMG_LoadPNG_RW(RWops);
try
AssignFromSurface(Surface);
- Rresult := true;
+ result := true;
finally
SDL_FreeSurface(Surface);
end;
png_info: png_infop;
TempHeight, TempWidth: Integer;
- Format: TglBitmapInternalFormat;
+ Format: TglBitmapFormat;
png_data: pByte;
png_rows: array of pByte;
try
// signature
- StreamPos := Stream.Position;
- Stream.Read(signature, 8);
- Stream.Position := StreamPos;
+ StreamPos := aStream.Position;
+ aStream.Read(signature{%H-}, 8);
+ aStream.Position := StreamPos;
if png_check_sig(@signature, 8) <> 0 then begin
// png read struct
end;
// set read callback
- png_set_read_fn(png, stream, glBitmap_libPNG_read_func);
+ png_set_read_fn(png, aStream, glBitmap_libPNG_read_func);
// read informations
png_read_info(png, png_info);
var
StreamPos: Int64;
Png: TPNGObject;
- Header: Array[0..7] of Byte;
+ Header: String[8];
Row, Col, PixSize, LineSize: Integer;
NewImage, pSource, pDest, pAlpha: pByte;
- Format: TglBitmapInternalFormat;
+ PngFormat: TglBitmapFormat;
+ FormatDesc: TFormatDescriptor;
const
- PngHeader: Array[0..7] of Byte = (#137, #80, #78, #71, #13, #10, #26, #10);
+ PngHeader: String[8] = #137#80#78#71#13#10#26#10;
begin
result := false;
- StreamPos := Stream.Position;
- Stream.Read(Header[0], SizeOf(Header));
- Stream.Position := StreamPos;
+ StreamPos := aStream.Position;
+ aStream.Read(Header[0], SizeOf(Header));
+ aStream.Position := StreamPos;
{Test if the header matches}
if Header = PngHeader then begin
Png := TPNGObject.Create;
try
- Png.LoadFromStream(Stream);
+ Png.LoadFromStream(aStream);
case Png.Header.ColorType of
COLOR_GRAYSCALE:
- Format := ifLuminance;
+ PngFormat := tfLuminance8;
COLOR_GRAYSCALEALPHA:
- Format := ifLuminanceAlpha;
+ PngFormat := tfLuminance8Alpha8;
COLOR_RGB:
- Format := ifBGR8;
+ PngFormat := tfBGR8;
COLOR_RGBALPHA:
- Format := ifBGRA8;
+ PngFormat := tfBGRA8;
else
raise EglBitmapException.Create ('LoadPng - Unsupported Colortype found.');
end;
- PixSize := Trunc(FormatGetSize(Format));
- LineSize := Integer(Png.Header.Width) * PixSize;
+ FormatDesc := TFormatDescriptor.Get(PngFormat);
+ PixSize := Round(FormatDesc.PixelSize);
+ LineSize := FormatDesc.GetSize(Png.Header.Width, 1);
GetMem(NewImage, LineSize * Integer(Png.Header.Height));
try
raise EglBitmapException.Create ('LoadPng - Unsupported Colortype found.');
end;
- SetDataPointer(NewImage, Format, Png.Header.Width, Png.Header.Height);
+ SetDataPointer(NewImage, PngFormat, Png.Header.Width, Png.Header.Height);
result := true;
except
LineSize: Integer;
ColorType: Integer;
Row: Integer;
+ FormatDesc: TFormatDescriptor;
begin
- if not (ftPNG in FormatGetSupportedFiles (InternalFormat)) then
- raise EglBitmapUnsupportedInternalFormat.Create('SavePng - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ if not (ftPNG in FormatGetSupportedFiles(Format)) then
+ raise EglBitmapUnsupportedFormat.Create(Format);
if not init_libPNG then
- raise Exception.Create('SavePNG - unable to initialize libPNG.');
+ raise Exception.Create('unable to initialize libPNG.');
try
- case FInternalFormat of
- ifAlpha, ifLuminance, ifDepth8:
+ case Format of
+ tfAlpha8, tfLuminance8:
ColorType := PNG_COLOR_TYPE_GRAY;
- ifLuminanceAlpha:
+ tfLuminance8Alpha8:
ColorType := PNG_COLOR_TYPE_GRAY_ALPHA;
- ifBGR8, ifRGB8:
+ tfBGR8, tfRGB8:
ColorType := PNG_COLOR_TYPE_RGB;
- ifBGRA8, ifRGBA8:
+ tfBGRA8, tfRGBA8:
ColorType := PNG_COLOR_TYPE_RGBA;
else
- raise EglBitmapUnsupportedInternalFormat.Create('SavePng - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ raise EglBitmapUnsupportedFormat.Create(Format);
end;
- LineSize := Trunc(FormatGetSize(FInternalFormat) * Width);
+
+ FormatDesc := TFormatDescriptor.Get(Format);
+ LineSize := FormatDesc.GetSize(Width, 1);
// creating array for scanline
SetLength(png_rows, Height);
end;
// set read callback
- png_set_write_fn(png, stream, glBitmap_libPNG_write_func, nil);
+ png_set_write_fn(png, aStream, glBitmap_libPNG_write_func, nil);
// set compression
png_set_compression_level(png, 6);
- if InternalFormat in [ifBGR8, ifBGRA8] then
+ if Format in [tfBGR8, tfBGRA8] then
png_set_bgr(png);
png_set_IHDR(png, png_info, Width, Height, 8, ColorType, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
pTemp: pByte;
Temp: Byte;
begin
- if not (ftPNG in FormatGetSupportedFiles (InternalFormat)) then
- raise EglBitmapUnsupportedInternalFormat.Create('SavePng - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ if not (ftPNG in FormatGetSupportedFiles (Format)) then
+ raise EglBitmapUnsupportedFormat.Create(Format);
- case FInternalFormat of
- ifAlpha, ifLuminance, ifDepth8: begin
+ case Format of
+ tfAlpha8, tfLuminance8: begin
ColorType := COLOR_GRAYSCALE;
- PixSize := 1;
- Alpha := false;
+ PixSize := 1;
+ Alpha := false;
end;
- ifLuminanceAlpha: begin
+ tfLuminance8Alpha8: begin
ColorType := COLOR_GRAYSCALEALPHA;
- PixSize := 1;
- Alpha := true;
+ PixSize := 1;
+ Alpha := true;
end;
- ifBGR8, ifRGB8: begin
+ tfBGR8, tfRGB8: begin
ColorType := COLOR_RGB;
- PixSize := 3;
- Alpha := false;
+ PixSize := 3;
+ Alpha := false;
end;
- ifBGRA8, ifRGBA8: begin
+ tfBGRA8, tfRGBA8: begin
ColorType := COLOR_RGBALPHA;
- PixSize := 3;
- Alpha := true
+ PixSize := 3;
+ Alpha := true
end;
else
- raise EglBitmapUnsupportedInternalFormat.Create('SavePng - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ raise EglBitmapUnsupportedFormat.Create(Format);
end;
Png := TPNGObject.CreateBlank(ColorType, 8, Width, Height);
end;
// convert RGB line to BGR
- if InternalFormat in [ifRGB8, ifRGBA8] then begin
+ if Format in [tfRGB8, tfRGBA8] then begin
pTemp := png.ScanLine[Y];
for X := 0 to Width -1 do begin
Temp := pByteArray(pTemp)^[0];
// Save to Stream
Png.CompressionLevel := 6;
- Png.SaveToStream(Stream);
+ Png.SaveToStream(aStream);
finally
FreeAndNil(Png);
end;
DestBuffer: array [1..4096] of byte;
end;
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-{
procedure glBitmap_libJPEG_error_exit(cinfo: j_common_ptr); cdecl;
-var
- Msg: String;
begin
- SetLength(Msg, 256);
- cinfo^.err^.format_message(cinfo, pChar(Msg));
- Writeln('ERROR [' + IntToStr(cinfo^.err^.msg_code) + '] ' + Msg);
- cinfo^.global_state := 0;
- jpeg_abort(cinfo);
+ //DUMMY
end;
-}
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-{
+
procedure glBitmap_libJPEG_output_message(cinfo: j_common_ptr); cdecl;
-var
- Msg: String;
begin
- SetLength(Msg, 256);
- cinfo^.err^.format_message(cinfo, pChar(Msg));
- Writeln('OUTPUT [' + IntToStr(cinfo^.err^.msg_code) + '] ' + Msg);
- cinfo^.global_state := 0;
+ //DUMMY
end;
-}
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-{
+
procedure glBitmap_libJPEG_init_source(cinfo: j_decompress_ptr); cdecl;
begin
+ //DUMMY
+end;
+
+procedure glBitmap_libJPEG_term_source(cinfo: j_decompress_ptr); cdecl;
+begin
+ //DUMMY
+end;
+
+
+procedure glBitmap_libJPEG_init_destination(cinfo: j_compress_ptr); cdecl;
+begin
+ //DUMMY
end;
-}
+
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function glBitmap_libJPEG_fill_input_buffer(cinfo: j_decompress_ptr): boolean; cdecl;
end;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-{
-procedure glBitmap_libJPEG_term_source(cinfo: j_decompress_ptr); cdecl;
-begin
-end;
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-{
-procedure glBitmap_libJPEG_init_destination(cinfo: j_compress_ptr); cdecl;
-begin
-end;
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function glBitmap_libJPEG_empty_output_buffer(cinfo: j_compress_ptr): boolean; cdecl;
var
dest: glBitmap_libJPEG_dest_mgr_ptr;
begin
result := false;
- RWops := glBitmapCreateRWops(Stream);
+ RWops := glBitmapCreateRWops(aStream);
try
if IMG_isJPG(RWops) > 0 then begin
Surface := IMG_LoadJPG_RW(RWops);
jpeg: jpeg_decompress_struct;
jpeg_err: jpeg_error_mgr;
- IntFormat: TglBitmapInternalFormat;
+ IntFormat: TglBitmapFormat;
pImage: pByte;
TempHeight, TempWidth: Integer;
pTemp: pByte;
Row: Integer;
+
+ FormatDesc: TFormatDescriptor;
begin
result := false;
try
// reading first two bytes to test file and set cursor back to begin
- StreamPos := Stream.Position;
- Stream.Read(Temp[0], 2);
- Stream.Position := StreamPos;
+ StreamPos := aStream.Position;
+ aStream.Read({%H-}Temp[0], 2);
+ aStream.Position := StreamPos;
// if Bitmap then read file.
if ((Temp[0] = $FF) and (Temp[1] = $D8)) then begin
- FillChar(jpeg, SizeOf(jpeg_decompress_struct), $00);
- FillChar(jpeg_err, SizeOf(jpeg_error_mgr), $00);
+ FillChar(jpeg{%H-}, SizeOf(jpeg_decompress_struct), $00);
+ FillChar(jpeg_err{%H-}, SizeOf(jpeg_error_mgr), $00);
// error managment
jpeg.err := jpeg_std_error(@jpeg_err);
- jpeg_err.error_exit := glBitmap_libJPEG_error_exit;
+ jpeg_err.error_exit := glBitmap_libJPEG_error_exit;
jpeg_err.output_message := glBitmap_libJPEG_output_message;
// decompression struct
pub.bytes_in_buffer := 0; // forces fill_input_buffer on first read
pub.next_input_byte := nil; // until buffer loaded
- SrcStream := Stream;
+ SrcStream := aStream;
end;
// set global decoding state
JCS_GRAYSCALE:
begin
jpeg.out_color_space := JCS_GRAYSCALE;
- IntFormat := ifLuminance;
+ IntFormat := tfLuminance8;
end;
else
jpeg.out_color_space := JCS_RGB;
- IntFormat := ifRGB8;
+ IntFormat := tfRGB8;
end;
// reading image
TempHeight := jpeg.output_height;
TempWidth := jpeg.output_width;
+ FormatDesc := TFormatDescriptor.Get(IntFormat);
+
// creating new image
- GetMem(pImage, FormatGetImageSize(glBitmapPosition(TempWidth, TempHeight), IntFormat));
+ GetMem(pImage, FormatDesc.GetSize(TempWidth, TempHeight));
try
pTemp := pImage;
for Row := 0 to TempHeight -1 do begin
jpeg_read_scanlines(@jpeg, @pTemp, 1);
- Inc(pTemp, Trunc(FormatGetSize(IntFormat) * TempWidth));
+ Inc(pTemp, FormatDesc.GetSize(TempWidth, 1));
end;
// finish decompression
{$ENDIF}
{$IFDEF GLB_SUPPORT_JPEG_WRITE}
-{$IF DEFEFINED(GLB_LIB_JPEG)}
+{$IF DEFINED(GLB_LIB_JPEG)}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TglBitmap.SaveJPEG(Stream: TStream);
+procedure TglBitmap.SaveJPEG(const aStream: TStream);
var
jpeg: jpeg_compress_struct;
jpeg_err: jpeg_error_mgr;
begin
if not (ftJPEG in FormatGetSupportedFiles(Format)) then
- raise EglBitmapUnsupportedInternalFormat.Create('SaveJpg - ' + UNSUPPORTED_INTERNAL_FORMAT);
+ raise EglBitmapUnsupportedFormat.Create(Format);
if not init_libJPEG then
raise Exception.Create('SaveJPG - unable to initialize libJPEG.');
try
- FillChar(jpeg, SizeOf(jpeg_compress_struct), $00);
- FillChar(jpeg_err, SizeOf(jpeg_error_mgr), $00);
+ FillChar(jpeg{%H-}, SizeOf(jpeg_compress_struct), $00);
+ FillChar(jpeg_err{%H-}, SizeOf(jpeg_error_mgr), $00);
// error managment
jpeg.err := jpeg_std_error(@jpeg_err);
- jpeg_err.error_exit := glBitmap_libJPEG_error_exit;
+ jpeg_err.error_exit := glBitmap_libJPEG_error_exit;
jpeg_err.output_message := glBitmap_libJPEG_output_message;
// compression struct
pub.next_output_byte := @DestBuffer[1];
pub.free_in_buffer := Length(DestBuffer);
- DestStream := Stream;
+ DestStream := aStream;
end;
// very important state
jpeg.global_state := CSTATE_START;
jpeg.image_width := Width;
jpeg.image_height := Height;
- case InternalFormat of
- ifAlpha, ifLuminance, ifDepth8: begin
+ case Format of
+ tfAlpha8, tfLuminance8: begin
jpeg.input_components := 1;
- jpeg.in_color_space := JCS_GRAYSCALE;
+ jpeg.in_color_space := JCS_GRAYSCALE;
end;
- ifRGB8, ifBGR8: begin
+ tfRGB8, tfBGR8: begin
jpeg.input_components := 3;
- jpeg.in_color_space := JCS_RGB;
+ jpeg.in_color_space := JCS_RGB;
end;
end;
jpeg_start_compress(@jpeg, true);
pTemp := Data;
- if InternalFormat = ifBGR8 then
+ if Format = tfBGR8 then
GetMem(pTemp2, fRowSize)
else
pTemp2 := pTemp;
try
for Row := 0 to jpeg.image_height -1 do begin
// prepare row
- if InternalFormat = ifBGR8 then
+ if Format = tfBGR8 then
CopyRow(pTemp2, pTemp)
else
pTemp2 := pTemp;
end;
finally
// free memory
- if InternalFormat = ifBGR8 then
+ if Format = tfBGR8 then
FreeMem(pTemp2);
end;
jpeg_finish_compress(@jpeg);
function TglBitmap.LoadBMP(const aStream: TStream): Boolean;
//////////////////////////////////////////////////////////////////////////////////////////////////
- function ReadInfo(var aInfo: TBMPInfo; var aMask: TglBitmapColorRec): TglBitmapFormat;
+ function ReadInfo(out aInfo: TBMPInfo; out aMask: TglBitmapColorRec): TglBitmapFormat;
begin
result := tfEmpty;
- aStream.Read(aInfo, SizeOf(aInfo));
- FillChar(aMask, SizeOf(aMask), 0);
+ aStream.Read(aInfo{%H-}, SizeOf(aInfo));
+ FillChar(aMask{%H-}, SizeOf(aMask), 0);
//Read Compression
case aInfo.biCompression of
LineBuf, ImageData, TmpData: PByte;
SourceMD, DestMD: Pointer;
BmpFormat: TglBitmapFormat;
- ColorTable: TbmpColorTable;
//records
Mask: TglBitmapColorRec;
//////////////////////////////////////////////////////////////////////////////////////////////////
procedure SpecialFormatReadLine(aData: PByte; aLineBuf: PByte);
var
- i, j: Integer;
+ i: Integer;
Pixel: TglBitmapPixelData;
begin
aStream.Read(aLineBuf^, rbLineSize);
// Header
StartPos := aStream.Position;
- aStream.Read(Header, SizeOf(Header));
+ aStream.Read(Header{%H-}, SizeOf(Header));
if Header.bfType = BMP_MAGIC then begin
try try
dec(TmpData, wbLineSize)
else
inc(TmpData, wbLineSize);
- aStream.Read(PaddingBuff, Padding);
+ aStream.Read(PaddingBuff{%H-}, Padding);
end;
SetDataPointer(ImageData, BmpFormat, Info.biWidth, abs(Info.biHeight));
result := true;
pData, srcData, dstData, ConvertBuffer: pByte;
Pixel: TglBitmapPixelData;
- PixelFormat: TglBitmapPixelData;
- ImageSize, wbLineSize, rbLineSize, Padding, LineIdx, PixelIdx, i: Integer;
+ ImageSize, wbLineSize, rbLineSize, Padding, LineIdx, PixelIdx: Integer;
RedMask, GreenMask, BlueMask, AlphaMask: Cardinal;
PaddingBuff: Cardinal;
begin
if not (ftBMP in FormatGetSupportedFiles(Format)) then
- raise EglBitmapUnsupportedFormatFormat.Create('SaveBMP - ' + UNSUPPORTED_FORMAT);
+ raise EglBitmapUnsupportedFormat.Create(Format);
Converter := nil;
FormatDesc := TFormatDescriptor.Get(Format);
ImageSize := FormatDesc.GetSize(Dimension);
- FillChar(Header, SizeOf(Header), 0);
+ FillChar(Header{%H-}, SizeOf(Header), 0);
Header.bfType := BMP_MAGIC;
Header.bfSize := SizeOf(Header) + SizeOf(Info) + ImageSize;
Header.bfReserved1 := 0;
Header.bfReserved2 := 0;
Header.bfOffBits := SizeOf(Header) + SizeOf(Info);
- FillChar(Info, SizeOf(Info), 0);
+ FillChar(Info{%H-}, SizeOf(Info), 0);
Info.biSize := SizeOf(Info);
Info.biWidth := Width;
Info.biHeight := Height;
Info.biCompression := BMP_COMP_BITFIELDS;
end;
else
- raise EglBitmapUnsupportedFormatFormat.Create('SaveBMP - ' + UNSUPPORTED_FORMAT);
+ raise EglBitmapUnsupportedFormat.Create(Format);
end;
Info.biXPelsPerMeter := 2835;
Info.biYPelsPerMeter := 2835;
function TglBitmap.LoadTGA(const aStream: TStream): Boolean;
var
Header: TTGAHeader;
- ImageData: PByte;
+ ImageData: System.PByte;
StartPosition: Int64;
PixelSize, LineSize: Integer;
tgaFormat: TglBitmapFormat;
procedure ReadUncompressed;
var
i, j: Integer;
- buf, tmp1, tmp2: PByte;
+ buf, tmp1, tmp2: System.PByte;
begin
buf := nil;
if (Counter.X.dir < 0) then
/////////////////////////////////////////////////////////////////
var
- TmpData: PByte;
+ TmpData: System.PByte;
LinePixelsRead: Integer;
procedure CheckLine;
begin
BytesRead := 0;
if (CacheSize - CachePos > 0) then begin
BytesRead := CacheSize - CachePos;
- Move(PByteArray(Cache)^[CachePos], Buffer, BytesRead);
+ Move(PByteArray(Cache)^[CachePos], Buffer{%H-}, BytesRead);
inc(CachePos, BytesRead);
end;
// reading header to test file and set cursor back to begin
StartPosition := aStream.Position;
- aStream.Read(Header, SizeOf(Header));
+ aStream.Read(Header{%H-}, SizeOf(Header));
// no colormapped files
if (Header.ColorMapType = TGA_NONE_COLOR_TABLE) and (Header.ImageType in [
Converter: TFormatDescriptor;
begin
if not (ftTGA in FormatGetSupportedFiles(Format)) then
- raise EglBitmapUnsupportedFormatFormat.Create('SaveTGA - ' + UNSUPPORTED_FORMAT);
+ raise EglBitmapUnsupportedFormat.Create(Format);
//prepare header
- FillChar(Header, SizeOf(Header), 0);
+ FillChar(Header{%H-}, SizeOf(Header), 0);
//set ImageType
if (Format in [tfLuminance8, tfLuminance6Alpha2, tfLuminance4Alpha4, tfAlpha8,
var
StreamPos: Int64;
- x, y, j, LineSize, RowSize, Magic: Cardinal;
- NewImage, TmpData, RowData, SrcData: PByte;
+ x, y, LineSize, RowSize, Magic: Cardinal;
+ NewImage, TmpData, RowData, SrcData: System.PByte;
SourceMD, DestMD: Pointer;
Pixel: TglBitmapPixelData;
ddsFormat: TglBitmapFormat;
StreamPos := aStream.Position;
// Magic
- aStream.Read(Magic, sizeof(Magic));
+ aStream.Read(Magic{%H-}, sizeof(Magic));
if (Magic <> DDS_MAGIC) then begin
aStream.Position := StreamPos;
exit;
end;
//Header
- aStream.Read(Header, sizeof(Header));
+ aStream.Read(Header{%H-}, sizeof(Header));
if (Header.dwSize <> SizeOf(Header)) or
((Header.dwFlags and (DDSD_PIXELFORMAT or DDSD_CAPS or DDSD_WIDTH or DDSD_HEIGHT)) <>
(DDSD_PIXELFORMAT or DDSD_CAPS or DDSD_WIDTH or DDSD_HEIGHT)) then
FormatDesc: TFormatDescriptor;
begin
if not (ftDDS in FormatGetSupportedFiles(Format)) then
- raise EglBitmapUnsupportedFormatFormat.Create('SaveDDS - ' + UNSUPPORTED_FORMAT);
+ raise EglBitmapUnsupportedFormat.Create(Format);
FormatDesc := TFormatDescriptor.Get(Format);
// Generell
- FillChar(Header, SizeOf(Header), 0);
+ FillChar(Header{%H-}, SizeOf(Header), 0);
Header.dwSize := SizeOf(Header);
Header.dwFlags := DDSD_WIDTH or DDSD_HEIGHT or DDSD_CAPS or DDSD_PIXELFORMAT;
begin
FormatDesc := TFormatDescriptor.Get(Format);
if FormatDesc.IsCompressed then
- raise EglBitmapUnsupportedFormatFormat.Create('TglBitmap2D.GrabScreen - ' + UNSUPPORTED_FORMAT);
+ raise EglBitmapUnsupportedFormat.Create(Format);
w := aRight - aLeft;
h := aBottom - aTop;
var
Temp: PByte;
TempWidth, TempHeight: Integer;
- TempType, TempIntFormat: Cardinal;
+ TempIntFormat: Cardinal;
IntFormat, f: TglBitmapFormat;
FormatDesc: TFormatDescriptor;
begin
glGetTexLevelParameteriv(Target, 0, GL_TEXTURE_INTERNAL_FORMAT, @TempIntFormat);
IntFormat := tfEmpty;
- for f := Low(TglBitmapFormat) to High(TglBitmapFormat) do
- if (TFormatDescriptor.Get(f).glInternalFormat = TempIntFormat) then begin
+ for f := Low(TglBitmapFormat) to High(TglBitmapFormat) do begin
+ FormatDesc := TFormatDescriptor.Get(f);
+ if (FormatDesc.glInternalFormat = TempIntFormat) then begin
IntFormat := FormatDesc.Format;
break;
end;
+ end;
// Getting data from OpenGL
FormatDesc := TFormatDescriptor.Get(IntFormat);
end;
begin
- (* TODO Compression
- if not FormatIsUncompressed(InternalFormat) then
- raise EglBitmapUnsupportedFormatFormat.Create('TglBitmap2D.ToNormalMap - ' + UNSUPPORTED_FORMAT);
- *)
+ if TFormatDescriptor.Get(Format).IsCompressed then
+ raise EglBitmapUnsupportedFormat.Create(Format);
if aScale > 100 then
Rec.Scale := 100
// Daten Sammeln
if aUseAlpha and TFormatDescriptor.Get(Format).HasAlpha then
- AddFunc(glBitmapToNormalMapPrepareAlphaFunc, false, PtrInt(@Rec))
+ AddFunc(glBitmapToNormalMapPrepareAlphaFunc, false, @Rec)
else
- AddFunc(glBitmapToNormalMapPrepareFunc, false, PtrInt(@Rec));
- AddFunc(glBitmapToNormalMapFunc, false, PtrInt(@Rec));
+ AddFunc(glBitmapToNormalMapPrepareFunc, false, @Rec);
+ AddFunc(glBitmapToNormalMapFunc, false, @Rec);
finally
SetLength(Rec.Heights, 0);
end;