* added pngimage Support
[glBitmap.git] / glBitmap.pas
index 1a547ac..f745956 100644 (file)
@@ -1,6 +1,10 @@
 {***********************************************************
 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
@@ -223,11 +227,11 @@ unit glBitmap;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 // 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}
@@ -241,26 +245,26 @@ unit glBitmap;
 // 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}
@@ -678,12 +682,6 @@ var
 
 type
 ////////////////////////////////////////////////////////////////////////////////////////////////////
-  EglBitmapException               = class(Exception);
-  EglBitmapSizeToLargeException    = class(EglBitmapException);
-  EglBitmapNonPowerOfTwoException  = class(EglBitmapException);
-  EglBitmapUnsupportedFormatFormat = class(EglBitmapException);
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
   TglBitmapFormat = (
     tfEmpty = 0, //must be smallest value!
 
@@ -765,6 +763,14 @@ type
      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
@@ -794,7 +800,7 @@ type
     Position: TglBitmapPixelPosition;
     Source:   TglBitmapPixelData;
     Dest:     TglBitmapPixelData;
-    Args:     PtrInt;
+    Args:     Pointer;
   end;
   TglBitmapFunction = procedure(var FuncRec: TglBitmapFunctionRec);
 
@@ -853,7 +859,7 @@ type
     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;
@@ -893,7 +899,7 @@ type
     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);
@@ -904,9 +910,9 @@ type
     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}
@@ -914,7 +920,7 @@ type
     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}
@@ -922,17 +928,17 @@ type
     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;
@@ -963,9 +969,6 @@ type
       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;
 
@@ -974,20 +977,18 @@ type
     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;
 
@@ -1131,7 +1132,7 @@ implementation
     *)
 
 uses
-  Math, syncobjs;
+  Math, syncobjs, typinfo;
 
 type
 ////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1143,10 +1144,10 @@ 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;
@@ -1180,13 +1181,13 @@ type
     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;
@@ -1196,7 +1197,7 @@ type
 
     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;
 
@@ -1215,117 +1216,117 @@ type
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
   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;
 
@@ -1516,41 +1517,41 @@ type
 
   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;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1571,7 +1572,7 @@ type
     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;
 
@@ -1656,6 +1657,12 @@ var
   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
@@ -1762,39 +1769,18 @@ 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;
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1806,7 +1792,7 @@ begin
 end;
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function GetTopMostBit(aBitSet: UInt64): Integer;
+function GetTopMostBit(aBitSet: QWord): Integer;
 begin
   result := 0;
   while aBitSet > 0 do begin
@@ -1816,7 +1802,7 @@ begin
 end;
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function CountSetBits(aBitSet: UInt64): Integer;
+function CountSetBits(aBitSet: QWord): Integer;
 begin
   result := 0;
   while aBitSet > 0 do begin
@@ -1859,7 +1845,7 @@ begin
     aLibHandle := GL_LibHandle;
 
 {$IF DEFINED(GLB_WIN)}
-  result := GetProcAddress(HMODULE(aLibHandle), aProcName);
+  result := GetProcAddress({%H-}HMODULE(aLibHandle), aProcName);
   if Assigned(result) then
     exit;
 
@@ -1897,7 +1883,7 @@ procedure glbInitOpenGL;
   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}
@@ -1913,14 +1899,12 @@ procedure glbInitOpenGL;
       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);
@@ -1983,33 +1967,33 @@ var
   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;
 
@@ -2131,8 +2115,10 @@ 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);
@@ -2167,7 +2153,6 @@ begin
   result^.unknown.data1 := Stream;
 end;
 {$ENDIF}
-*)
 
 (* TODO LoadFuncs
 function LoadTexture(Filename: String; var Texture: Cardinal{$IFDEF GLB_DELPHI}; LoadFromRes : Boolean; Instance: Cardinal{$ENDIF}): Boolean;
@@ -2371,25 +2356,25 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //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;
@@ -2452,7 +2437,7 @@ begin
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TFormatDescriptor.MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: UInt64): Boolean;
+function TFormatDescriptor.MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: QWord): Boolean;
 begin
   result := false;
 
@@ -2473,7 +2458,7 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 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;
@@ -2509,7 +2494,7 @@ begin
   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;
@@ -2536,7 +2521,7 @@ begin
   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^;
@@ -2570,7 +2555,7 @@ begin
   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
@@ -2595,7 +2580,7 @@ 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^;
@@ -2625,7 +2610,7 @@ begin
   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);
@@ -2663,7 +2648,7 @@ begin
   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);
@@ -2697,7 +2682,7 @@ begin
   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^;
@@ -2724,7 +2709,7 @@ begin
   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^;
@@ -2750,7 +2735,7 @@ begin
   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;
@@ -2777,7 +2762,7 @@ begin
   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)^;
@@ -2811,7 +2796,7 @@ begin
   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
@@ -2835,7 +2820,7 @@ 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)^;
@@ -2865,7 +2850,7 @@ begin
   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)^;
@@ -2895,7 +2880,7 @@ begin
   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);
@@ -2933,7 +2918,7 @@ begin
   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);
@@ -2968,7 +2953,7 @@ begin
   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)^;
@@ -2995,7 +2980,7 @@ begin
   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)^;
@@ -3026,7 +3011,7 @@ begin
   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
@@ -3050,7 +3035,7 @@ 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)^;
@@ -3662,7 +3647,7 @@ begin
   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;
@@ -3688,7 +3673,7 @@ begin
   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;
@@ -3714,7 +3699,7 @@ begin
   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;
@@ -3786,31 +3771,31 @@ 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;
@@ -3834,10 +3819,8 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 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
@@ -3849,7 +3832,7 @@ begin
     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;
@@ -3857,19 +3840,17 @@ begin
 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;
@@ -3883,8 +3864,6 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 procedure TbmpColorTableFormat.CreateColorTable;
 var
-  bits: Byte;
-  len: Integer;
   i: Integer;
 begin
   if not (Format in [tfLuminance4, tfLuminance8, tfR3G3B2]) then
@@ -3938,9 +3917,9 @@ begin
       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;
@@ -3962,11 +3941,9 @@ begin
 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;
@@ -3975,11 +3952,11 @@ begin
   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;
@@ -3992,7 +3969,7 @@ begin
     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;
@@ -4073,12 +4050,12 @@ procedure glBitmapInvertFunc(var aFuncRec: TglBitmapFunctionRec);
 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;
@@ -4101,7 +4078,7 @@ var
   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 +
@@ -4134,8 +4111,6 @@ end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 procedure glBitmapValueAlphaFunc(var FuncRec: TglBitmapFunctionRec);
-type
-  PglBitmapPixelData = ^TglBitmapPixelData;
 begin
   with FuncRec do begin
     Dest.Data.r := Source.Data.r;
@@ -4236,7 +4211,7 @@ begin
   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;
 
@@ -4303,7 +4278,7 @@ begin
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TglBitmap.SetupParameters(var aBuildWithGlu: Boolean);
+procedure TglBitmap.SetupParameters(out aBuildWithGlu: Boolean);
 begin
   // Set Up Parameters
   SetWrap(fWrapS, fWrapT, fWrapR);
@@ -4432,7 +4407,7 @@ end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 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;
@@ -4507,7 +4482,7 @@ procedure TglBitmap.SaveToStream(const aStream: TStream; const aFileType: TglBit
 begin
   case aFileType of
     {$IFDEF GLB_SUPPORT_PNG_WRITE}
-    ftPNG:  SavePng(aStream);
+    ftPNG:  SavePNG(aStream);
     {$ENDIF}
     {$IFDEF GLB_SUPPORT_JPEG_WRITE}
     ftJPEG: SaveJPEG(aStream);
@@ -4519,14 +4494,14 @@ begin
 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;
@@ -4612,42 +4587,37 @@ var
   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);
@@ -4663,34 +4633,31 @@ function TglBitmap.AssignFromSurface(const aSurface: PSDL_Surface): Boolean;
 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;
@@ -4730,9 +4697,9 @@ begin
 
       AlphaInterleave := 0;
       case Format of
-        ifLuminance8Alpha8:
+        tfLuminance8Alpha8:
           AlphaInterleave := 1;
-        ifBGRA8, ifRGBA8:
+        tfBGRA8, tfRGBA8:
           AlphaInterleave := 3;
       end;
 
@@ -4754,14 +4721,14 @@ begin
 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;
@@ -4974,17 +4941,15 @@ 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
@@ -4997,7 +4962,7 @@ 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
@@ -5010,7 +4975,7 @@ 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;
@@ -5027,21 +4992,23 @@ begin
 
   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;
@@ -5116,7 +5083,7 @@ begin
     Data.a  := 0;
     Range.a := 0;
   end;
-  result := AddAlphaFromFunc(glBitmapColorKeyAlphaFunc, PtrInt(@PixelData));
+  result := AddAlphaFromFunc(glBitmapColorKeyAlphaFunc, @PixelData);
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -5142,7 +5109,7 @@ begin
   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;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -5154,7 +5121,7 @@ begin
   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;
@@ -5258,7 +5225,7 @@ begin
       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
@@ -5269,7 +5236,9 @@ end;
 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;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -5323,7 +5292,7 @@ begin
     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;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -5427,24 +5396,6 @@ begin
 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
@@ -5493,7 +5444,7 @@ var
   ImageSize: Integer;
 begin
   Create;
-  TFormatDescriptor.Get(aFormat).GetSize(aSize);
+  ImageSize := TFormatDescriptor.Get(aFormat).GetSize(aSize);
   GetMem(Image, ImageSize);
   try
     FillChar(Image^, ImageSize, #$FF);
@@ -5506,7 +5457,7 @@ end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 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);
@@ -5545,7 +5496,7 @@ begin
       Surface := IMG_LoadPNG_RW(RWops);
       try
         AssignFromSurface(Surface);
-        Rresult := true;
+        result := true;
       finally
         SDL_FreeSurface(Surface);
       end;
@@ -5571,7 +5522,7 @@ var
   png_info: png_infop;
 
   TempHeight, TempWidth: Integer;
-  Format: TglBitmapInternalFormat;
+  Format: TglBitmapFormat;
 
   png_data: pByte;
   png_rows: array of pByte;
@@ -5584,9 +5535,9 @@ begin
 
   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
@@ -5602,7 +5553,7 @@ begin
       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);
@@ -5674,42 +5625,44 @@ function TglBitmap.LoadPNG(const aStream: TStream): Boolean;
 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
@@ -5746,7 +5699,7 @@ begin
             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
@@ -5780,27 +5733,30 @@ var
   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);
@@ -5823,12 +5779,12 @@ begin
       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);
@@ -5858,32 +5814,32 @@ var
   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);
@@ -5903,7 +5859,7 @@ begin
       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];
@@ -5916,7 +5872,7 @@ begin
 
     // Save to Stream
     Png.CompressionLevel := 6;
-    Png.SaveToStream(Stream);
+    Png.SaveToStream(aStream);
   finally
     FreeAndNil(Png);
   end;
@@ -5945,39 +5901,34 @@ type
     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;
@@ -6021,20 +5972,6 @@ begin
 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;
@@ -6085,7 +6022,7 @@ var
 begin
   result := false;
 
-  RWops := glBitmapCreateRWops(Stream);
+  RWops := glBitmapCreateRWops(aStream);
   try
     if IMG_isJPG(RWops) > 0 then begin
       Surface := IMG_LoadJPG_RW(RWops);
@@ -6111,12 +6048,14 @@ var
   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;
 
@@ -6125,18 +6064,18 @@ begin
 
   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
@@ -6156,7 +6095,7 @@ begin
         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
@@ -6170,11 +6109,11 @@ begin
         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
@@ -6183,14 +6122,16 @@ begin
       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
@@ -6249,9 +6190,9 @@ end;
 {$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;
@@ -6273,18 +6214,18 @@ var
 
 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
@@ -6302,21 +6243,21 @@ begin
       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;
 
@@ -6325,7 +6266,7 @@ begin
     jpeg_start_compress(@jpeg, true);
     pTemp := Data;
 
-    if InternalFormat = ifBGR8 then
+    if Format = tfBGR8 then
       GetMem(pTemp2, fRowSize)
     else
       pTemp2 := pTemp;
@@ -6333,7 +6274,7 @@ begin
     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;
@@ -6344,7 +6285,7 @@ begin
       end;
     finally
       // free memory
-      if InternalFormat = ifBGR8 then
+      if Format = tfBGR8 then
         FreeMem(pTemp2);
     end;
     jpeg_finish_compress(@jpeg);
@@ -6423,11 +6364,11 @@ type
 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
@@ -6519,7 +6460,6 @@ var
   LineBuf, ImageData, TmpData: PByte;
   SourceMD, DestMD: Pointer;
   BmpFormat: TglBitmapFormat;
-  ColorTable: TbmpColorTable;
 
   //records
   Mask: TglBitmapColorRec;
@@ -6533,7 +6473,7 @@ var
   //////////////////////////////////////////////////////////////////////////////////////////////////
   procedure SpecialFormatReadLine(aData: PByte; aLineBuf: PByte);
   var
-    i, j: Integer;
+    i: Integer;
     Pixel: TglBitmapPixelData;
   begin
     aStream.Read(aLineBuf^, rbLineSize);
@@ -6555,7 +6495,7 @@ begin
 
   // Header
   StartPos := aStream.Position;
-  aStream.Read(Header, SizeOf(Header));
+  aStream.Read(Header{%H-}, SizeOf(Header));
 
   if Header.bfType = BMP_MAGIC then begin
     try try
@@ -6595,7 +6535,7 @@ begin
               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;
@@ -6634,8 +6574,7 @@ var
   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;
@@ -6647,20 +6586,20 @@ var
 
 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;
@@ -6712,7 +6651,7 @@ begin
         Info.biCompression := BMP_COMP_BITFIELDS;
       end;
     else
-      raise EglBitmapUnsupportedFormatFormat.Create('SaveBMP - ' + UNSUPPORTED_FORMAT);
+      raise EglBitmapUnsupportedFormat.Create(Format);
     end;
     Info.biXPelsPerMeter := 2835;
     Info.biYPelsPerMeter := 2835;
@@ -6829,7 +6768,7 @@ const
 function TglBitmap.LoadTGA(const aStream: TStream): Boolean;
 var
   Header: TTGAHeader;
-  ImageData: PByte;
+  ImageData: System.PByte;
   StartPosition: Int64;
   PixelSize, LineSize: Integer;
   tgaFormat: TglBitmapFormat;
@@ -6847,7 +6786,7 @@ const
   procedure ReadUncompressed;
   var
     i, j: Integer;
-    buf, tmp1, tmp2: PByte;
+    buf, tmp1, tmp2: System.PByte;
   begin
     buf := nil;
     if (Counter.X.dir < 0) then
@@ -6881,7 +6820,7 @@ const
 
     /////////////////////////////////////////////////////////////////
     var
-      TmpData: PByte;
+      TmpData: System.PByte;
       LinePixelsRead: Integer;
     procedure CheckLine;
     begin
@@ -6907,7 +6846,7 @@ const
         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;
 
@@ -7009,7 +6948,7 @@ begin
 
   // 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 [
@@ -7108,10 +7047,10 @@ var
   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,
@@ -7320,8 +7259,8 @@ var
 
 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;
@@ -7333,14 +7272,14 @@ begin
   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
@@ -7424,12 +7363,12 @@ var
   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;
 
@@ -7567,7 +7506,7 @@ var
 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;
@@ -7589,7 +7528,7 @@ procedure TglBitmap2D.GetDataFromTexture;
 var
   Temp: PByte;
   TempWidth, TempHeight: Integer;
-  TempType, TempIntFormat: Cardinal;
+  TempIntFormat: Cardinal;
   IntFormat, f: TglBitmapFormat;
   FormatDesc: TFormatDescriptor;
 begin
@@ -7601,11 +7540,13 @@ 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);
@@ -7815,10 +7756,8 @@ var
   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
@@ -7925,10 +7864,10 @@ begin
 
     // 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;