* renamed formats
[glBitmap.git] / glBitmap.pas
index 4ee797b..f5ba747 100644 (file)
@@ -773,71 +773,81 @@ var
 
 type
 ////////////////////////////////////////////////////////////////////////////////////////////////////
+// the name of formats is composed of the following constituents:
+// - multiple chanals:
+//    - channel                          (e.g. R, G, B, A or Alpha, Luminance or X (reserved)
+//    - width of the chanel in bit       (4, 8, 16, ...)
+// - data type                           (e.g. ub, us, ui)
+// - number of data types
+
+
   TglBitmapFormat = (
-    tfEmpty = 0, //must be smallest value!
-
-    tfAlpha4,
-    tfAlpha8,
-    tfAlpha16,
-
-    tfLuminance4,
-    tfLuminance8,
-    tfLuminance16,
-
-    tfLuminance4Alpha4,
-    tfLuminance6Alpha2,
-    tfLuminance8Alpha8,
-    tfLuminance12Alpha4,
-    tfLuminance16Alpha16,
-
-    tfR3G3B2,
-    tfRGBX4,
-    tfXRGB4,
-    tfR5G6B5,
-    tfRGB5X1,
-    tfX1RGB5,
-    tfRGB8,
-    tfRGBX8,
-    tfXRGB8,
-    tfRGB10X2,
-    tfX2RGB10,
-    tfRGB16,
-
-    tfRGBA4,
-    tfARGB4,
-    tfRGB5A1,
-    tfA1RGB5,
-    tfRGBA8,
-    tfARGB8,
-    tfRGB10A2,
-    tfA2RGB10,
-    tfRGBA16,
-
-    tfBGRX4,
-    tfXBGR4,
-    tfB5G6R5,
-    tfBGR5X1,
-    tfX1BGR5,
-    tfBGR8,
-    tfBGRX8,
-    tfXBGR8,
-    tfBGR10X2,
-    tfX2BGR10,
-    tfBGR16,
-
-    tfBGRA4,
-    tfABGR4,
-    tfBGR5A1,
-    tfA1BGR5,
-    tfBGRA8,
-    tfABGR8,
-    tfBGR10A2,
-    tfA2BGR10,
-    tfBGRA16,
-
-    tfDepth16,
-    tfDepth24,
-    tfDepth32,
+    tfEmpty = 0,                //must be smallest value!
+
+    tfAlpha4ub1,                // 1 x unsigned byte
+    tfAlpha8ub1,                // 1 x unsigned byte
+    tfAlpha16us1,               // 1 x unsigned short
+
+    tfLuminance4ub1,            // 1 x unsigned byte
+    tfLuminance8ub1,            // 1 x unsigned byte
+    tfLuminance16us1,           // 1 x unsigned short
+
+    tfLuminance4Alpha4ub2,      // 1 x unsigned byte (lum), 1 x unsigned byte (alpha)
+    tfLuminance6Alpha2ub2,      // 1 x unsigned byte (lum), 1 x unsigned byte (alpha)
+    tfLuminance8Alpha8ub2,      // 1 x unsigned byte (lum), 1 x unsigned byte (alpha)
+    tfLuminance12Alpha4us2,     // 1 x unsigned short (lum), 1 x unsigned short (alpha)
+    tfLuminance16Alpha16us2,    // 1 x unsigned short (lum), 1 x unsigned short (alpha)
+
+    tfR3G3B2ub1,                // 1 x unsigned byte (3bit red, 3bit green, 2bit blue)
+    tfRGBX4us1,                 // 1 x unsigned short (4bit red, 4bit green, 4bit blue, 4bit reserverd)
+    tfXRGB4us1,                 // 1 x unsigned short (4bit reserved, 4bit red, 4bit green, 4bit blue)
+    tfR5G6B5us1,                // 1 x unsigned short (5bit red, 6bit green, 5bit blue)
+    tfRGB5X1us1,                // 1 x unsigned short (5bit red, 5bit green, 5bit blue, 1bit reserved)
+    tfX1RGB5us1,                // 1 x unsigned short (1bit reserved, 5bit red, 5bit green, 5bit blue)
+    tfRGB8ub3,                  // 1 x unsigned byte (red), 1 x unsigned byte (green), 1 x unsigned byte (blue)
+    tfRGBX8ui1,                 // 1 x unsigned int (8bit red, 8bit green, 8bit blue, 8bit reserved)
+    tfXRGB8ui1,                 // 1 x unsigned int (8bit reserved, 8bit red, 8bit green, 8bit blue)
+    tfRGB10X2ui1,               // 1 x unsigned int (10bit red, 10bit green, 10bit blue, 2bit reserved)
+    tfX2RGB10ui1,               // 1 x unsigned int (2bit reserved, 10bit red, 10bit green, 10bit blue)
+    tfRGB16us3,                 // 1 x unsigned short (red), 1 x unsigned short (green), 1 x unsigned short (blue)
+
+    tfRGBA4us1,                 // 1 x unsigned short (4bit red, 4bit green, 4bit blue, 4bit alpha)
+    tfARGB4us1,                 // 1 x unsigned short (4bit alpha, 4bit red, 4bit green, 4bit blue)
+    tfRGB5A1us1,                // 1 x unsigned short (5bit red, 5bit green, 5bit blue, 1bit alpha)
+    tfA1RGB5us1,                // 1 x unsigned short (1bit alpha, 5bit red, 5bit green, 5bit blue)
+    tfRGBA8ui1,                 // 1 x unsigned int (8bit red, 8bit green, 8bit blue, 8 bit alpha)
+    tfARGB8ui1,                 // 1 x unsigned int (8 bit alpha, 8bit red, 8bit green, 8bit blue)
+    tfRGBA8ub4,                 // 1 x unsigned byte (red), 1 x unsigned byte (green), 1 x unsigned byte (blue), 1 x unsigned byte (alpha)
+    tfRGB10A2ui1,               // 1 x unsigned int (10bit red, 10bit green, 10bit blue, 2bit alpha)
+    tfA2RGB10ui1,               // 1 x unsigned int (2bit alpha, 10bit red, 10bit green, 10bit blue)
+    tfRGBA16us4,                // 1 x unsigned short (red), 1 x unsigned short (green), 1 x unsigned short (blue), 1 x unsigned short (alpha)
+
+    tfBGRX4us1,                 // 1 x unsigned short (4bit blue, 4bit green, 4bit red, 4bit reserved)
+    tfXBGR4us1,                 // 1 x unsigned short (4bit reserved, 4bit blue, 4bit green, 4bit red)
+    tfB5G6R5us1,                // 1 x unsigned short (5bit blue, 6bit green, 5bit red)
+    tfBGR5X1us1,                // 1 x unsigned short (5bit blue, 5bit green, 5bit red, 1bit reserved)
+    tfX1BGR5us1,                // 1 x unsigned short (1bit reserved, 5bit blue, 5bit green, 5bit red)
+    tfBGR8ub3,                  // 1 x unsigned byte (blue), 1 x unsigned byte (green), 1 x unsigned byte (red)
+    tfBGRX8ui1,                 // 1 x unsigned int (8bit blue, 8bit green, 8bit red, 8bit reserved)
+    tfXBGR8ui1,                 // 1 x unsigned int (8bit reserved, 8bit blue, 8bit green, 8bit red)
+    tfBGR10X2ui1,               // 1 x unsigned int (10bit blue, 10bit green, 10bit red, 2bit reserved)
+    tfX2BGR10ui1,               // 1 x unsigned int (2bit reserved, 10bit blue, 10bit green, 10bit red)
+    tfBGR16us3,                 // 1 x unsigned short (blue), 1 x unsigned short (green), 1 x unsigned short (red)
+
+    tfBGRA4us1,                 // 1 x unsigned short (4bit blue, 4bit green, 4bit red, 4bit alpha)
+    tfABGR4us1,                 // 1 x unsigned short (4bit alpha, 4bit blue, 4bit green, 4bit red)
+    tfBGR5A1us1,                // 1 x unsigned short (5bit blue, 5bit green, 5bit red, 1bit alpha)
+    tfA1BGR5us1,                // 1 x unsigned short (1bit alpha, 5bit blue, 5bit green, 5bit red)
+    tfBGRA8ui1,                 // 1 x unsigned int (8bit blue, 8bit green, 8bit red, 8bit alpha)
+    tfABGR8ui1,                 // 1 x unsigned int (8bit alpha, 8bit blue, 8bit green, 8bit red)
+    tfBGRA8ub4,                 // 1 x unsigned byte (blue), 1 x unsigned byte (green), 1 x unsigned byte (red), 1 x unsigned byte (alpha)
+    tfBGR10A2ui1,               // 1 x unsigned int (10bit blue, 10bit green, 10bit red, 2bit alpha)
+    tfA2BGR10ui1,               // 1 x unsigned int (2bit alpha, 10bit blue, 10bit green, 10bit red)
+    tfBGRA16us4,                // 1 x unsigned short (blue), 1 x unsigned short (green), 1 x unsigned short (red), 1 x unsigned short (alpha)
+
+    tfDepth16us1,               // 1 x unsigned short (depth)
+    tfDepth24ui1,               // 1 x unsigned int (depth)
+    tfDepth32ui1,               // 1 x unsigned int (depth)
 
     tfS3tcDtx1RGBA,
     tfS3tcDtx3RGBA,
@@ -881,6 +891,12 @@ type
     1: (arr: array[0..3] of Cardinal);
   end;
 
+  TglBitmapMask = packed record
+  case Integer of
+    0: (r, g, b, a: QWord);
+    1: (arr: array[0..3] of QWord);
+  end;
+
   TglBitmapPixelData = packed record
     Data, Range: TglBitmapColorRec;
     Format: TglBitmapFormat;
@@ -902,6 +918,8 @@ type
     function GetHasGreen:     Boolean; virtual; abstract;
     function GetHasBlue:      Boolean; virtual; abstract;
     function GetHasAlpha:     Boolean; virtual; abstract;
+    function GetHasColor:     Boolean; virtual; abstract;
+    function GetIsGrayscale:  Boolean; virtual; abstract;
 
     function GetRGBInverted:  TglBitmapFormat; virtual; abstract;
     function GetWithAlpha:    TglBitmapFormat; virtual; abstract;
@@ -918,6 +936,8 @@ type
     property HasGreen:     Boolean read GetHasGreen;
     property HasBlue:      Boolean read GetHasBlue;
     property HasAlpha:     Boolean read GetHasAlpha;
+    property HasColor:     Boolean read GetHasColor;
+    property IsGrayscale:  Boolean read GetIsGrayscale;
 
     property RGBInverted:  TglBitmapFormat read GetRGBInverted;
     property WithAlpha:    TglBitmapFormat read GetWithAlpha;
@@ -1239,6 +1259,8 @@ function glBitmapPosition(X: Integer = -1; Y: Integer = -1): TglBitmapPixelPosit
 function glBitmapColorRec(const r, g, b, a: Cardinal): TglBitmapColorRec;
 function glBitmapColorRecCmp(const r1, r2: TglBitmapColorRec): Boolean;
 
+function glBitmapCreateTestTexture(const aFormat: TglBitmapFormat): TglBitmap2D;
+
 var
   glBitmapDefaultDeleteTextureOnFree: Boolean;
   glBitmapDefaultFreeDataAfterGenTextures: Boolean;
@@ -1306,6 +1328,8 @@ type
     function GetHasGreen: Boolean; override;
     function GetHasBlue: Boolean; override;
     function GetHasAlpha: Boolean; override;
+    function GetHasColor: Boolean; override;
+    function GetIsGrayscale: Boolean; override;
 
     function GetRGBInverted:  TglBitmapFormat; override;
     function GetWithAlpha:    TglBitmapFormat; override;
@@ -1340,8 +1364,9 @@ type
     function CreateMappingData: Pointer; virtual;
     procedure FreeMappingData(var aMappingData: Pointer); virtual;
 
-    function IsEmpty:  Boolean; virtual;
-    function MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: QWord): Boolean; virtual;
+    function IsEmpty: Boolean; virtual;
+    function MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: QWord): Boolean; virtual; overload;
+    function MaskMatch(const aMask: TglBitmapMask): Boolean; virtual; overload;
 
     procedure PreparePixel(out aPixel: TglBitmapPixelData); virtual;
 
@@ -1350,6 +1375,7 @@ type
     class procedure Init;
     class function Get(const aFormat: TglBitmapFormat): TFormatDescriptor;
     class function GetAlpha(const aFormat: TglBitmapFormat): TFormatDescriptor;
+    class function GetFromMask(const aMask: TglBitmapMask; const aBitCount: Integer = 0): TFormatDescriptor;
     class procedure Clear;
     class procedure Finalize;
   end;
@@ -1358,323 +1384,341 @@ type
   TfdEmpty = class(TFormatDescriptor);
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-  TfdAlpha_UB1 = class(TFormatDescriptor) //1* unsigned byte
+  TfdAlphaUB1 = class(TFormatDescriptor) //1* unsigned byte
+    procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
+    procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+  end;
+
+  TfdLuminanceUB1 = class(TFormatDescriptor) //1* unsigned byte
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
 
-  TfdLuminance_UB1 = class(TFormatDescriptor) //1* unsigned byte
+  TfdUniversalUB1 = class(TFormatDescriptor) //1* unsigned byte
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
 
-  TfdUniversal_UB1 = class(TFormatDescriptor) //1* unsigned byte
+  TfdLuminanceAlphaUB2 = class(TfdLuminanceUB1) //2* unsigned byte
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
 
-  TfdLuminanceAlpha_UB2 = class(TfdLuminance_UB1) //2* unsigned byte
+  TfdRGBub3 = class(TFormatDescriptor) //3* unsigned byte
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
 
-  TfdRGB_UB3 = class(TFormatDescriptor) //3* unsigned byte
+  TfdBGRub3 = class(TFormatDescriptor) //3* unsigned byte (inverse)
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
 
-  TfdBGR_UB3 = class(TFormatDescriptor) //3* unsigned byte (inverse)
+  TfdRGBAub4 = class(TfdRGBub3) //3* unsigned byte
+    procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
+    procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
+  end;
+
+  TfdBGRAub4 = class(TfdBGRub3) //3* unsigned byte (inverse)
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-  TfdAlpha_US1 = class(TFormatDescriptor) //1* unsigned short
+  TfdAlphaUS1 = class(TFormatDescriptor) //1* unsigned short
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
 
-  TfdLuminance_US1 = class(TFormatDescriptor) //1* unsigned short
+  TfdLuminanceUS1 = class(TFormatDescriptor) //1* unsigned short
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
 
-  TfdUniversal_US1 = class(TFormatDescriptor) //1* unsigned short
+  TfdUniversalUS1 = class(TFormatDescriptor) //1* unsigned short
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
 
-  TfdDepth_US1 = class(TFormatDescriptor) //1* unsigned short
+  TfdDepthUS1 = class(TFormatDescriptor) //1* unsigned short
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
 
-  TfdLuminanceAlpha_US2 = class(TfdLuminance_US1) //2* unsigned short
+  TfdLuminanceAlphaUS2 = class(TfdLuminanceUS1) //2* unsigned short
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
 
-  TfdRGB_US3 = class(TFormatDescriptor) //3* unsigned short
+  TfdRGBus3 = class(TFormatDescriptor) //3* unsigned short
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
 
-  TfdBGR_US3 = class(TFormatDescriptor) //3* unsigned short (inverse)
+  TfdBGRus3 = class(TFormatDescriptor) //3* unsigned short (inverse)
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
 
-  TfdRGBA_US4 = class(TfdRGB_US3) //4* unsigned short
+  TfdRGBAus4 = class(TfdRGBus3) //4* unsigned short
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
 
-  TfdARGB_US4 = class(TfdRGB_US3) //4* unsigned short
+  TfdARGBus4 = class(TfdRGBus3) //4* unsigned short
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
 
-  TfdBGRA_US4 = class(TfdBGR_US3) //4* unsigned short (inverse)
+  TfdBGRAus4 = class(TfdBGRus3) //4* unsigned short (inverse)
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
 
-  TfdABGR_US4 = class(TfdBGR_US3) //4* unsigned short (inverse)
+  TfdABGRus4 = class(TfdBGRus3) //4* unsigned short (inverse)
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-  TfdUniversal_UI1 = class(TFormatDescriptor) //1* unsigned int
+  TfdUniversalUI1 = class(TFormatDescriptor) //1* unsigned int
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
 
-  TfdDepth_UI1 = class(TFormatDescriptor) //1* unsigned int
+  TfdDepthUI1 = class(TFormatDescriptor) //1* unsigned int
     procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override;
     procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override;
   end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-  TfdAlpha4 = class(TfdAlpha_UB1)
+  TfdAlpha4ub1 = class(TfdAlphaUB1)
     constructor Create; override;
   end;
 
-  TfdAlpha8 = class(TfdAlpha_UB1)
+  TfdAlpha8ub1 = class(TfdAlphaUB1)
     constructor Create; override;
   end;
 
-  TfdAlpha16 = class(TfdAlpha_US1)
+  TfdAlpha16us1 = class(TfdAlphaUS1)
     constructor Create; override;
   end;
 
-  TfdLuminance4 = class(TfdLuminance_UB1)
+  TfdLuminance4ub1 = class(TfdLuminanceUB1)
     constructor Create; override;
   end;
 
-  TfdLuminance8 = class(TfdLuminance_UB1)
+  TfdLuminance8ub1 = class(TfdLuminanceUB1)
     constructor Create; override;
   end;
 
-  TfdLuminance16 = class(TfdLuminance_US1)
+  TfdLuminance16us1 = class(TfdLuminanceUS1)
     constructor Create; override;
   end;
 
-  TfdLuminance4Alpha4 = class(TfdLuminanceAlpha_UB2)
+  TfdLuminance4Alpha4ub2 = class(TfdLuminanceAlphaUB2)
     constructor Create; override;
   end;
 
-  TfdLuminance6Alpha2 = class(TfdLuminanceAlpha_UB2)
+  TfdLuminance6Alpha2ub2 = class(TfdLuminanceAlphaUB2)
     constructor Create; override;
   end;
 
-  TfdLuminance8Alpha8 = class(TfdLuminanceAlpha_UB2)
+  TfdLuminance8Alpha8ub2 = class(TfdLuminanceAlphaUB2)
     constructor Create; override;
   end;
 
-  TfdLuminance12Alpha4 = class(TfdLuminanceAlpha_US2)
+  TfdLuminance12Alpha4us2 = class(TfdLuminanceAlphaUS2)
     constructor Create; override;
   end;
 
-  TfdLuminance16Alpha16 = class(TfdLuminanceAlpha_US2)
+  TfdLuminance16Alpha16us2 = class(TfdLuminanceAlphaUS2)
     constructor Create; override;
   end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-  TfdR3G3B2 = class(TfdUniversal_UB1)
+  TfdR3G3B2ub1 = class(TfdUniversalUB1)
+    constructor Create; override;
+  end;
+
+  TfdRGBX4us1 = class(TfdUniversalUS1)
     constructor Create; override;
   end;
 
-  TfdRGBX4 = class(TfdUniversal_US1)
+  TfdXRGB4us1 = class(TfdUniversalUS1)
     constructor Create; override;
   end;
 
-  TfdXRGB4 = class(TfdUniversal_US1)
+  TfdR5G6B5us1 = class(TfdUniversalUS1)
     constructor Create; override;
   end;
 
-  TfdR5G6B5 = class(TfdUniversal_US1)
+  TfdRGB5X1us1 = class(TfdUniversalUS1)
     constructor Create; override;
   end;
 
-  TfdRGB5X1 = class(TfdUniversal_US1)
+  TfdX1RGB5us1 = class(TfdUniversalUS1)
     constructor Create; override;
   end;
 
-  TfdX1RGB5 = class(TfdUniversal_US1)
+  TfdRGB8ub3 = class(TfdRGBub3)
     constructor Create; override;
   end;
 
-  TfdRGB8 = class(TfdRGB_UB3)
+  TfdRGBX8ui1 = class(TfdUniversalUI1)
     constructor Create; override;
   end;
 
-  TfdRGBX8 = class(TfdUniversal_UI1)
+  TfdXRGB8ui1 = class(TfdUniversalUI1)
     constructor Create; override;
   end;
 
-  TfdXRGB8 = class(TfdUniversal_UI1)
+  TfdRGB10X2ui1 = class(TfdUniversalUI1)
     constructor Create; override;
   end;
 
-  TfdRGB10X2 = class(TfdUniversal_UI1)
+  TfdX2RGB10ui1 = class(TfdUniversalUI1)
     constructor Create; override;
   end;
 
-  TfdX2RGB10 = class(TfdUniversal_UI1)
+  TfdRGB16us3 = class(TfdRGBus3)
     constructor Create; override;
   end;
 
-  TfdRGB16 = class(TfdRGB_US3)
+  TfdRGBA4us1 = class(TfdUniversalUS1)
     constructor Create; override;
   end;
 
-  TfdRGBA4 = class(TfdUniversal_US1)
+  TfdARGB4us1 = class(TfdUniversalUS1)
     constructor Create; override;
   end;
 
-  TfdARGB4 = class(TfdUniversal_US1)
+  TfdRGB5A1us1 = class(TfdUniversalUS1)
     constructor Create; override;
   end;
 
-  TfdRGB5A1 = class(TfdUniversal_US1)
+  TfdA1RGB5us1 = class(TfdUniversalUS1)
     constructor Create; override;
   end;
 
-  TfdA1RGB5 = class(TfdUniversal_US1)
+  TfdRGBA8ui1 = class(TfdUniversalUI1)
     constructor Create; override;
   end;
 
-  TfdRGBA8 = class(TfdUniversal_UI1)
+  TfdARGB8ui1 = class(TfdUniversalUI1)
     constructor Create; override;
   end;
 
-  TfdARGB8 = class(TfdUniversal_UI1)
+  TfdRGBA8ub4 = class(TfdRGBAub4)
     constructor Create; override;
   end;
 
-  TfdRGB10A2 = class(TfdUniversal_UI1)
+  TfdRGB10A2ui1 = class(TfdUniversalUI1)
     constructor Create; override;
   end;
 
-  TfdA2RGB10 = class(TfdUniversal_UI1)
+  TfdA2RGB10ui1 = class(TfdUniversalUI1)
     constructor Create; override;
   end;
 
-  TfdRGBA16 = class(TfdUniversal_UI1)
+  TfdRGBA16us4 = class(TfdRGBAus4)
     constructor Create; override;
   end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-  TfdBGRX4 = class(TfdUniversal_US1)
+  TfdBGRX4us1 = class(TfdUniversalUS1)
+    constructor Create; override;
+  end;
+
+  TfdXBGR4us1 = class(TfdUniversalUS1)
     constructor Create; override;
   end;
 
-  TfdXBGR4 = class(TfdUniversal_US1)
+  TfdB5G6R5us1 = class(TfdUniversalUS1)
     constructor Create; override;
   end;
 
-  TfdB5G6R5 = class(TfdUniversal_US1)
+  TfdBGR5X1us1 = class(TfdUniversalUS1)
     constructor Create; override;
   end;
 
-  TfdBGR5X1 = class(TfdUniversal_US1)
+  TfdX1BGR5us1 = class(TfdUniversalUS1)
     constructor Create; override;
   end;
 
-  TfdX1BGR5 = class(TfdUniversal_US1)
+  TfdBGR8ub3 = class(TfdBGRub3)
     constructor Create; override;
   end;
 
-  TfdBGR8 = class(TfdBGR_UB3)
+  TfdBGRX8ui1 = class(TfdUniversalUI1)
     constructor Create; override;
   end;
 
-  TfdBGRX8 = class(TfdUniversal_UI1)
+  TfdXBGR8ui1 = class(TfdUniversalUI1)
     constructor Create; override;
   end;
 
-  TfdXBGR8 = class(TfdUniversal_UI1)
+  TfdBGR10X2ui1 = class(TfdUniversalUI1)
     constructor Create; override;
   end;
 
-  TfdBGR10X2 = class(TfdUniversal_UI1)
+  TfdX2BGR10ui1 = class(TfdUniversalUI1)
     constructor Create; override;
   end;
 
-  TfdX2BGR10 = class(TfdUniversal_UI1)
+  TfdBGR16us3 = class(TfdBGRus3)
     constructor Create; override;
   end;
 
-  TfdBGR16 = class(TfdBGR_US3)
+  TfdBGRA4us1 = class(TfdUniversalUS1)
     constructor Create; override;
   end;
 
-  TfdBGRA4 = class(TfdUniversal_US1)
+  TfdABGR4us1 = class(TfdUniversalUS1)
     constructor Create; override;
   end;
 
-  TfdABGR4 = class(TfdUniversal_US1)
+  TfdBGR5A1us1 = class(TfdUniversalUS1)
     constructor Create; override;
   end;
 
-  TfdBGR5A1 = class(TfdUniversal_US1)
+  TfdA1BGR5us1 = class(TfdUniversalUS1)
     constructor Create; override;
   end;
 
-  TfdA1BGR5 = class(TfdUniversal_US1)
+  TfdBGRA8ui1 = class(TfdUniversalUI1)
     constructor Create; override;
   end;
 
-  TfdBGRA8 = class(TfdUniversal_UI1)
+  TfdABGR8ui1 = class(TfdUniversalUI1)
     constructor Create; override;
   end;
 
-  TfdABGR8 = class(TfdUniversal_UI1)
+  TfdBGRA8ub4 = class(TfdBGRAub4)
     constructor Create; override;
   end;
 
-  TfdBGR10A2 = class(TfdUniversal_UI1)
+  TfdBGR10A2ui1 = class(TfdUniversalUI1)
     constructor Create; override;
   end;
 
-  TfdA2BGR10 = class(TfdUniversal_UI1)
+  TfdA2BGR10ui1 = class(TfdUniversalUI1)
     constructor Create; override;
   end;
 
-  TfdBGRA16 = class(TfdBGRA_US4)
+  TfdBGRA16us4 = class(TfdBGRAus4)
     constructor Create; override;
   end;
 
-  TfdDepth16 = class(TfdDepth_US1)
+  TfdDepth16us1 = class(TfdDepthUS1)
     constructor Create; override;
   end;
 
-  TfdDepth24 = class(TfdDepth_UI1)
+  TfdDepth24ui1 = class(TfdDepthUI1)
     constructor Create; override;
   end;
 
-  TfdDepth32 = class(TfdDepth_UI1)
+  TfdDepth32ui1 = class(TfdDepthUI1)
     constructor Create; override;
   end;
 
@@ -1752,73 +1796,73 @@ const
   DEPTH_WEIGHT_G = 0.333333333;
   DEPTH_WEIGHT_B = 0.333333333;
 
-  UNSUPPORTED_FORMAT = 'the given format isn''t supported by this function.';
-
   FORMAT_DESCRIPTOR_CLASSES: array[TglBitmapFormat] of TFormatDescriptorClass = (
     TfdEmpty,
 
-    TfdAlpha4,
-    TfdAlpha8,
-    TfdAlpha16,
-
-    TfdLuminance4,
-    TfdLuminance8,
-    TfdLuminance16,
-
-    TfdLuminance4Alpha4,
-    TfdLuminance6Alpha2,
-    TfdLuminance8Alpha8,
-    TfdLuminance12Alpha4,
-    TfdLuminance16Alpha16,
-
-    TfdR3G3B2,
-    TfdRGBX4,
-    TfdXRGB4,
-    TfdR5G6B5,
-    TfdRGB5X1,
-    TfdX1RGB5,
-    TfdRGB8,
-    TfdRGBX8,
-    TfdXRGB8,
-    TfdRGB10X2,
-    TfdX2RGB10,
-    TfdRGB16,
-
-    TfdRGBA4,
-    TfdARGB4,
-    TfdRGB5A1,
-    TfdA1RGB5,
-    TfdRGBA8,
-    TfdARGB8,
-    TfdRGB10A2,
-    TfdA2RGB10,
-    TfdRGBA16,
-
-    TfdBGRX4,
-    TfdXBGR4,
-    TfdB5G6R5,
-    TfdBGR5X1,
-    TfdX1BGR5,
-    TfdBGR8,
-    TfdBGRX8,
-    TfdXBGR8,
-    TfdBGR10X2,
-    TfdX2BGR10,
-    TfdBGR16,
-
-    TfdBGRA4,
-    TfdABGR4,
-    TfdBGR5A1,
-    TfdA1BGR5,
-    TfdBGRA8,
-    TfdABGR8,
-    TfdBGR10A2,
-    TfdA2BGR10,
-    TfdBGRA16,
-
-    TfdDepth16,
-    TfdDepth24,
-    TfdDepth32,
+    TfdAlpha4ub1,
+    TfdAlpha8ub1,
+    TfdAlpha16us1,
+
+    TfdLuminance4ub1,
+    TfdLuminance8ub1,
+    TfdLuminance16us1,
+
+    TfdLuminance4Alpha4ub2,
+    TfdLuminance6Alpha2ub2,
+    TfdLuminance8Alpha8ub2,
+    TfdLuminance12Alpha4us2,
+    TfdLuminance16Alpha16us2,
+
+    TfdR3G3B2ub1,
+    TfdRGBX4us1,
+    TfdXRGB4us1,
+    TfdR5G6B5us1,
+    TfdRGB5X1us1,
+    TfdX1RGB5us1,
+    TfdRGB8ub3,
+    TfdRGBX8ui1,
+    TfdXRGB8ui1,
+    TfdRGB10X2ui1,
+    TfdX2RGB10ui1,
+    TfdRGB16us3,
+
+    TfdRGBA4us1,
+    TfdARGB4us1,
+    TfdRGB5A1us1,
+    TfdA1RGB5us1,
+    TfdRGBA8ui1,
+    TfdARGB8ui1,
+    TfdRGBA8ub4,
+    TfdRGB10A2ui1,
+    TfdA2RGB10ui1,
+    TfdRGBA16us4,
+
+    TfdBGRX4us1,
+    TfdXBGR4us1,
+    TfdB5G6R5us1,
+    TfdBGR5X1us1,
+    TfdX1BGR5us1,
+    TfdBGR8ub3,
+    TfdBGRX8ui1,
+    TfdXBGR8ui1,
+    TfdBGR10X2ui1,
+    TfdX2BGR10ui1,
+    TfdBGR16us3,
+
+    TfdBGRA4us1,
+    TfdABGR4us1,
+    TfdBGR5A1us1,
+    TfdA1BGR5us1,
+    TfdBGRA8ui1,
+    TfdABGR8ui1,
+    TfdBGRA8ub4,
+    TfdBGR10A2ui1,
+    TfdA2BGR10ui1,
+    TfdBGRA16us4,
+
+    TfdDepth16us1,
+    TfdDepth24ui1,
+    TfdDepth32ui1,
 
     TfdS3tcDtx1RGBA,
     TfdS3tcDtx3RGBA,
@@ -1842,7 +1886,7 @@ begin
 end;
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function glBitmapPosition(X, Y: Integer): TglBitmapPixelPosition;
+function glBitmapPosition(X: Integer; Y: Integer): TglBitmapPixelPosition;
 begin
   result.Fields := [];
 
@@ -1877,6 +1921,52 @@ begin
 end;
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function glBitmapCreateTestTexture(const aFormat: TglBitmapFormat): TglBitmap2D;
+var
+  desc: TFormatDescriptor;
+  p, tmp: PByte;
+  x, y, i: Integer;
+  md: Pointer;
+  px: TglBitmapPixelData;
+begin
+  result := nil;
+  desc := TFormatDescriptor.Get(aFormat);
+  if (desc.IsCompressed) or (desc.glFormat = 0) then
+    exit;
+
+  p := GetMem(ceil(25 * desc.PixelSize)); // 5 x 5 pixel
+  md := desc.CreateMappingData;
+  try
+    tmp := p;
+    desc.PreparePixel(px);
+    for y := 0 to 4 do
+      for x := 0 to 4 do begin
+        px.Data := glBitmapColorRec(0, 0, 0, 0);
+        for i := 0 to 3 do begin
+          if ((y < 3) and (y = i)) or
+             ((y = 3) and (i < 3)) or
+             ((y = 4) and (i = 3))
+          then
+            px.Data.arr[i] := Trunc(px.Range.arr[i] / 4 * x)
+          else if ((y < 4) and (i = 3)) or
+                  ((y = 4) and (i < 3))
+          then
+            px.Data.arr[i] := px.Range.arr[i]
+          else
+            px.Data.arr[i] := 0; //px.Range.arr[i];
+        end;
+        desc.Map(px, tmp, md);
+      end;
+  finally
+    desc.FreeMappingData(md);
+  end;
+  result := TglBitmap2D.Create(glBitmapPosition(5, 5), aFormat, p);
+  result.FreeDataOnDestroy       := true;
+  result.FreeDataAfterGenTexture := false;
+  result.SetFilter(GL_NEAREST, GL_NEAREST);
+end;
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 function glBitmapShiftRec(const r, g, b, a: Byte): TShiftRec;
 begin
   result.r := r;
@@ -1891,74 +1981,57 @@ begin
   result := [];
 
   if (aFormat in [
-        //4 bbp
-        tfLuminance4,
-
         //8bpp
-        tfR3G3B2, tfLuminance8,
+        tfAlpha4ub1, tfAlpha8ub1,
+        tfLuminance4ub1, tfLuminance8ub1, tfR3G3B2ub1,
 
         //16bpp
-        tfRGBX4, tfXRGB4, tfRGB5X1, tfX1RGB5, tfR5G6B5, tfRGB5A1, tfA1RGB5, tfRGBA4, tfARGB4,
-        tfBGRX4, tfXBGR4, tfBGR5X1, tfX1BGR5, tfB5G6R5, tfBGR5A1, tfA1BGR5, tfBGRA4, tfABGR4,
+        tfLuminance4Alpha4ub2, tfLuminance6Alpha2ub2, tfLuminance8Alpha8ub2,
+        tfRGBX4us1, tfXRGB4us1, tfRGB5X1us1, tfX1RGB5us1, tfR5G6B5us1, tfRGB5A1us1, tfA1RGB5us1, tfRGBA4us1, tfARGB4us1,
+        tfBGRX4us1, tfXBGR4us1, tfBGR5X1us1, tfX1BGR5us1, tfB5G6R5us1, tfBGR5A1us1, tfA1BGR5us1, tfBGRA4us1, tfABGR4us1,
 
         //24bpp
-        tfBGR8, tfRGB8,
+        tfBGR8ub3, tfRGB8ub3,
 
         //32bpp
-        tfRGB10X2, tfX2RGB10, tfRGB10A2, tfA2RGB10, tfRGBA8, tfARGB8,
-        tfBGR10X2, tfX2BGR10, tfBGR10A2, tfA2BGR10, tfBGRA8, tfABGR8]) then
-    result := result + [ftBMP];
+        tfRGBX8ui1, tfXRGB8ui1, tfRGB10X2ui1, tfX2RGB10ui1, tfRGBA8ui1, tfARGB8ui1, tfRGBA8ub4, tfRGB10A2ui1, tfA2RGB10ui1,
+        tfBGRX8ui1, tfXBGR8ui1, tfBGR10X2ui1, tfX2BGR10ui1, tfBGRA8ui1, tfABGR8ui1, tfBGRA8ub4, tfBGR10A2ui1, tfA2BGR10ui1])
+  then
+    result := result + [ ftBMP ];
 
   if (aFormat in [
-        //8 bpp
-        tfLuminance8, tfAlpha8,
+        //8bbp
+        tfAlpha4ub1, tfAlpha8ub1, tfLuminance4ub1, tfLuminance8ub1,
 
-        //16 bpp
-        tfLuminance16, tfLuminance8Alpha8,
-        tfRGB5X1, tfX1RGB5, tfRGB5A1, tfA1RGB5, tfRGBA4, tfARGB4,
-        tfBGR5X1, tfX1BGR5, tfBGR5A1, tfA1BGR5, tfBGRA4, tfABGR4,
+        //16bbp
+        tfAlpha16us1, tfLuminance16us1,
+        tfLuminance4Alpha4ub2, tfLuminance6Alpha2ub2, tfLuminance8Alpha8ub2,
+        tfX1RGB5us1, tfARGB4us1, tfA1RGB5us1, tfDepth16us1,
 
-        //24 bpp
-        tfRGB8, tfBGR8,
+        //24bbp
+        tfBGR8ub3,
 
-        //32 bpp
-        tfRGB10A2, tfRGBA8, tfBGR10A2, tfBGRA8]) then
+        //32bbp
+        tfX2RGB10ui1, tfARGB8ui1, tfBGRA8ub4, tfA2RGB10ui1,
+        tfDepth24ui1, tfDepth32ui1])
+  then
     result := result + [ftTGA];
 
-  if (aFormat in [
-        //8 bpp
-        tfAlpha8, tfLuminance8, tfLuminance4Alpha4, tfLuminance6Alpha2,
-        tfR3G3B2,
-
-        //16 bpp
-        tfAlpha16, tfLuminance16, tfLuminance8Alpha8, tfLuminance12Alpha4,
-        tfRGBX4, tfXRGB4, tfR5G6B5, tfRGB5X1, tfX1RGB5, tfRGBA4, tfARGB4, tfRGB5A1, tfA1RGB5,
-        tfBGRX4, tfXBGR4, tfB5G6R5, tfBGR5X1, tfX1BGR5, tfBGRA4, tfABGR4, tfBGR5A1, tfA1BGR5,
-
-        //24 bpp
-        tfRGB8, tfBGR8,
-
-        //32 bbp
-        tfLuminance16Alpha16,
-        tfRGBA8, tfRGB10A2,
-        tfBGRA8, tfBGR10A2,
-
-        //compressed
-        tfS3tcDtx1RGBA, tfS3tcDtx3RGBA, tfS3tcDtx5RGBA]) then
+  if not (aFormat in [tfEmpty, tfRGB16us3, tfBGR16us3]) then
     result := result + [ftDDS];
 
-  {$IFDEF GLB_SUPPORT_PNG_WRITE}
+{$IFDEF GLB_SUPPORT_PNG_WRITE}
   if aFormat in [
-      tfAlpha8, tfLuminance8, tfLuminance8Alpha8,
-      tfRGB8, tfRGBA8,
-      tfBGR8, tfBGRA8] then
+      tfAlpha8ub1, tfLuminance8ub1, tfLuminance8Alpha8ub2,
+      tfRGB8ub3, tfRGBA8ui1,
+      tfBGR8ub3, tfBGRA8ui1] then
     result := result + [ftPNG];
-  {$ENDIF}
+{$ENDIF}
 
-  {$IFDEF GLB_SUPPORT_JPEG_WRITE}
-  if aFormat in [tfAlpha8, tfLuminance8, tfRGB8, tfBGR8] then
+{$IFDEF GLB_SUPPORT_JPEG_WRITE}
+  if aFormat in [tfAlpha8ub1, tfLuminance8ub1, tfRGB8ub3, tfBGR8ub3] then
     result := result + [ftJPEG];
-  {$ENDIF}
+{$ENDIF}
 end;
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -2265,7 +2338,7 @@ begin
   result := SDL_AllocRW;
 
   if result = nil then
-    raise EglBitmapException.Create('glBitmapCreateRWops - SDL_AllocRW failed.');
+    raise EglBitmap.Create('glBitmapCreateRWops - SDL_AllocRW failed.');
 
   result^.seek := glBitmapRWseek;
   result^.read := glBitmapRWread;
@@ -2348,14 +2421,14 @@ begin
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure glBitmapGetDefaultFilter(var aMin, aMag: GLenum);
+procedure glBitmapGetDefaultFilter(var aMin, aMag: Cardinal);
 begin
   aMin := glBitmapDefaultFilterMin;
   aMag := glBitmapDefaultFilterMag;
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure glBitmapGetDefaultTextureWrap(var S, T, R: GLenum);
+procedure glBitmapGetDefaultTextureWrap(var S, T, R: Cardinal);
 begin
   S := glBitmapDefaultWrapS;
   T := glBitmapDefaultWrapT;
@@ -2428,6 +2501,23 @@ begin
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function TFormatDescriptor.GetHasColor: Boolean;
+begin
+ result := HasRed or HasGreen or HasAlpha;
+end;
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function TFormatDescriptor.GetIsGrayscale: Boolean;
+var
+  r, g, b: QWord;
+begin
+  r := RedMask;
+  g := GreenMask;
+  b := BlueMask;
+  result := (r = g) and (g = b) and (r > 0);
+end;
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 function TFormatDescriptor.GetRGBInverted: TglBitmapFormat;
 begin
   result := fRGBInverted;
@@ -2544,6 +2634,12 @@ begin
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function TFormatDescriptor.MaskMatch(const aMask: TglBitmapMask): Boolean;
+begin
+  result := MaskMatch(aMask.r, aMask.g, aMask.b, aMask.a);
+end;
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 procedure TFormatDescriptor.PreparePixel(out aPixel: TglBitmapPixelData);
 begin
   FillChar(aPixel{%H-}, SizeOf(aPixel), 0);
@@ -2578,13 +2674,13 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TfdAlpha_UB1////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TfdAlpha_UB1.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+procedure TfdAlphaUB1.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
 begin
   aData^ := aPixel.Data.a;
   inc(aData);
 end;
 
-procedure TfdAlpha_UB1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdAlphaUB1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
 begin
   aPixel.Data.r := 0;
   aPixel.Data.g := 0;
@@ -2596,13 +2692,13 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TfdLuminance_UB1////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TfdLuminance_UB1.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+procedure TfdLuminanceUB1.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
 begin
   aData^ := LuminanceWeight(aPixel);
   inc(aData);
 end;
 
-procedure TfdLuminance_UB1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdLuminanceUB1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
 begin
   aPixel.Data.r := aData^;
   aPixel.Data.g := aData^;
@@ -2614,7 +2710,7 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TfdUniversal_UB1////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TfdUniversal_UB1.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+procedure TfdUniversalUB1.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
 var
   i: Integer;
 begin
@@ -2625,7 +2721,7 @@ begin
   inc(aData);
 end;
 
-procedure TfdUniversal_UB1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdUniversalUB1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
 var
   i: Integer;
 begin
@@ -2637,14 +2733,14 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TfdLuminanceAlpha_UB2///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TfdLuminanceAlpha_UB2.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+procedure TfdLuminanceAlphaUB2.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
 begin
   inherited Map(aPixel, aData, aMapData);
   aData^ := aPixel.Data.a;
   inc(aData);
 end;
 
-procedure TfdLuminanceAlpha_UB2.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdLuminanceAlphaUB2.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
 begin
   inherited Unmap(aData, aPixel, aMapData);
   aPixel.Data.a := aData^;
@@ -2654,23 +2750,23 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TfdRGB_UB3//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TfdRGB_UB3.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+procedure TfdRGBub3.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
 begin
-  aData^ := aPixel.Data.b;
+  aData^ := aPixel.Data.r;
   inc(aData);
   aData^ := aPixel.Data.g;
   inc(aData);
-  aData^ := aPixel.Data.r;
+  aData^ := aPixel.Data.b;
   inc(aData);
 end;
 
-procedure TfdRGB_UB3.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdRGBub3.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
 begin
-  aPixel.Data.b := aData^;
+  aPixel.Data.r := aData^;
   inc(aData);
   aPixel.Data.g := aData^;
   inc(aData);
-  aPixel.Data.r := aData^;
+  aPixel.Data.b := aData^;
   inc(aData);
   aPixel.Data.a := 0;
 end;
@@ -2678,37 +2774,71 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TfdBGR_UB3//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TfdBGR_UB3.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+procedure TfdBGRub3.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
 begin
-  aData^ := aPixel.Data.r;
+  aData^ := aPixel.Data.b;
   inc(aData);
   aData^ := aPixel.Data.g;
   inc(aData);
-  aData^ := aPixel.Data.b;
+  aData^ := aPixel.Data.r;
   inc(aData);
 end;
 
-procedure TfdBGR_UB3.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdBGRub3.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
 begin
-  aPixel.Data.r := aData^;
+  aPixel.Data.b := aData^;
   inc(aData);
   aPixel.Data.g := aData^;
   inc(aData);
-  aPixel.Data.b := aData^;
+  aPixel.Data.r := aData^;
   inc(aData);
   aPixel.Data.a := 0;
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//TfdRGBA_UB4//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TfdRGBAub4.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+begin
+  inherited Map(aPixel, aData, aMapData);
+  aData^ := aPixel.Data.a;
+  inc(aData);
+end;
+
+procedure TfdRGBAub4.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+begin
+  inherited Unmap(aData, aPixel, aMapData);
+  aPixel.Data.a := aData^;
+  inc(aData);
+end;
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//TfdBGRA_UB4//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TfdBGRAub4.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+begin
+  inherited Map(aPixel, aData, aMapData);
+  aData^ := aPixel.Data.a;
+  inc(aData);
+end;
+
+procedure TfdBGRAub4.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+begin
+  inherited Unmap(aData, aPixel, aMapData);
+  aPixel.Data.a := aData^;
+  inc(aData);
+end;
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TfdAlpha_US1////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TfdAlpha_US1.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+procedure TfdAlphaUS1.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
 begin
   PWord(aData)^ := aPixel.Data.a;
   inc(aData, 2);
 end;
 
-procedure TfdAlpha_US1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdAlphaUS1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
 begin
   aPixel.Data.r := 0;
   aPixel.Data.g := 0;
@@ -2720,13 +2850,13 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TfdLuminance_US1////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TfdLuminance_US1.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+procedure TfdLuminanceUS1.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
 begin
   PWord(aData)^ := LuminanceWeight(aPixel);
   inc(aData, 2);
 end;
 
-procedure TfdLuminance_US1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdLuminanceUS1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
 begin
   aPixel.Data.r := PWord(aData)^;
   aPixel.Data.g := PWord(aData)^;
@@ -2738,7 +2868,7 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TfdUniversal_US1////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TfdUniversal_US1.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+procedure TfdUniversalUS1.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
 var
   i: Integer;
 begin
@@ -2749,7 +2879,7 @@ begin
   inc(aData, 2);
 end;
 
-procedure TfdUniversal_US1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdUniversalUS1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
 var
   i: Integer;
 begin
@@ -2761,13 +2891,13 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TfdDepth_US1////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TfdDepth_US1.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+procedure TfdDepthUS1.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
 begin
   PWord(aData)^ := DepthWeight(aPixel);
   inc(aData, 2);
 end;
 
-procedure TfdDepth_US1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdDepthUS1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
 begin
   aPixel.Data.r := PWord(aData)^;
   aPixel.Data.g := PWord(aData)^;
@@ -2779,14 +2909,14 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TfdLuminanceAlpha_US2///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TfdLuminanceAlpha_US2.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+procedure TfdLuminanceAlphaUS2.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
 begin
   inherited Map(aPixel, aData, aMapData);
   PWord(aData)^ := aPixel.Data.a;
   inc(aData, 2);
 end;
 
-procedure TfdLuminanceAlpha_US2.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdLuminanceAlphaUS2.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
 begin
   inherited Unmap(aData, aPixel, aMapData);
   aPixel.Data.a := PWord(aData)^;
@@ -2796,23 +2926,23 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TfdRGB_US3//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TfdRGB_US3.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+procedure TfdRGBus3.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
 begin
-  PWord(aData)^ := aPixel.Data.b;
+  PWord(aData)^ := aPixel.Data.r;
   inc(aData, 2);
   PWord(aData)^ := aPixel.Data.g;
   inc(aData, 2);
-  PWord(aData)^ := aPixel.Data.r;
+  PWord(aData)^ := aPixel.Data.b;
   inc(aData, 2);
 end;
 
-procedure TfdRGB_US3.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdRGBus3.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
 begin
-  aPixel.Data.b := PWord(aData)^;
+  aPixel.Data.r := PWord(aData)^;
   inc(aData, 2);
   aPixel.Data.g := PWord(aData)^;
   inc(aData, 2);
-  aPixel.Data.r := PWord(aData)^;
+  aPixel.Data.b := PWord(aData)^;
   inc(aData, 2);
   aPixel.Data.a := 0;
 end;
@@ -2820,23 +2950,23 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TfdBGR_US3//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TfdBGR_US3.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+procedure TfdBGRus3.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
 begin
-  PWord(aData)^ := aPixel.Data.r;
+  PWord(aData)^ := aPixel.Data.b;
   inc(aData, 2);
   PWord(aData)^ := aPixel.Data.g;
   inc(aData, 2);
-  PWord(aData)^ := aPixel.Data.b;
+  PWord(aData)^ := aPixel.Data.r;
   inc(aData, 2);
 end;
 
-procedure TfdBGR_US3.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdBGRus3.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
 begin
-  aPixel.Data.r := PWord(aData)^;
+  aPixel.Data.b := PWord(aData)^;
   inc(aData, 2);
   aPixel.Data.g := PWord(aData)^;
   inc(aData, 2);
-  aPixel.Data.b := PWord(aData)^;
+  aPixel.Data.r := PWord(aData)^;
   inc(aData, 2);
   aPixel.Data.a := 0;
 end;
@@ -2844,75 +2974,75 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TfdRGBA_US4/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TfdRGBA_US4.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+procedure TfdRGBAus4.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
 begin
+  inherited Map(aPixel, aData, aMapData);
   PWord(aData)^ := aPixel.Data.a;
   inc(aData, 2);
-  inherited Map(aPixel, aData, aMapData);
 end;
 
-procedure TfdRGBA_US4.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdRGBAus4.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
 begin
+  inherited Unmap(aData, aPixel, aMapData);
   aPixel.Data.a := PWord(aData)^;
   inc(aData, 2);
-  inherited Unmap(aData, aPixel, aMapData);
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TfdARGB_US4/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TfdARGB_US4.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+procedure TfdARGBus4.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
 begin
-  inherited Map(aPixel, aData, aMapData);
   PWord(aData)^ := aPixel.Data.a;
   inc(aData, 2);
+  inherited Map(aPixel, aData, aMapData);
 end;
 
-procedure TfdARGB_US4.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdARGBus4.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
 begin
-  inherited Unmap(aData, aPixel, aMapData);
   aPixel.Data.a := PWord(aData)^;
   inc(aData, 2);
+  inherited Unmap(aData, aPixel, aMapData);
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TfdBGRA_US4/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TfdBGRA_US4.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+procedure TfdBGRAus4.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
 begin
+  inherited Map(aPixel, aData, aMapData);
   PWord(aData)^ := aPixel.Data.a;
   inc(aData, 2);
-  inherited Map(aPixel, aData, aMapData);
 end;
 
-procedure TfdBGRA_US4.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdBGRAus4.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
 begin
+  inherited Unmap(aData, aPixel, aMapData);
   aPixel.Data.a := PWord(aData)^;
   inc(aData, 2);
-  inherited Unmap(aData, aPixel, aMapData);
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TfdABGR_US4/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TfdABGR_US4.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+procedure TfdABGRus4.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
 begin
-  inherited Map(aPixel, aData, aMapData);
   PWord(aData)^ := aPixel.Data.a;
   inc(aData, 2);
+  inherited Map(aPixel, aData, aMapData);
 end;
 
-procedure TfdABGR_US4.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdABGRus4.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
 begin
-  inherited Unmap(aData, aPixel, aMapData);
   aPixel.Data.a := PWord(aData)^;
   inc(aData, 2);
+  inherited Unmap(aData, aPixel, aMapData);
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TfdUniversal_UI1////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TfdUniversal_UI1.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+procedure TfdUniversalUI1.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
 var
   i: Integer;
 begin
@@ -2923,7 +3053,7 @@ begin
   inc(aData, 4);
 end;
 
-procedure TfdUniversal_UI1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdUniversalUI1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
 var
   i: Integer;
 begin
@@ -2935,71 +3065,71 @@ end;
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //TfdDepth_UI1////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure TfdDepth_UI1.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
+procedure TfdDepthUI1.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
 begin
   PCardinal(aData)^ := DepthWeight(aPixel);
   inc(aData, 4);
 end;
 
-procedure TfdDepth_UI1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
+procedure TfdDepthUI1.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
 begin
   aPixel.Data.r := PCardinal(aData)^;
   aPixel.Data.g := PCardinal(aData)^;
   aPixel.Data.b := PCardinal(aData)^;
-  aPixel.Data.a := 0;
+  aPixel.Data.a := PCardinal(aData)^;
   inc(aData, 4);
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-constructor TfdAlpha4.Create;
+constructor TfdAlpha4ub1.Create;
 begin
   inherited Create;
   fPixelSize        := 1.0;
-  fFormat           := tfAlpha4;
-  fWithAlpha        := tfAlpha4;
-  fOpenGLFormat     := tfAlpha4;
+  fFormat           := tfAlpha4ub1;
+  fWithAlpha        := tfAlpha4ub1;
+  fOpenGLFormat     := tfAlpha4ub1;
   fRange.a          := $FF;
   fglFormat         := GL_ALPHA;
   fglInternalFormat := GL_ALPHA4;
   fglDataFormat     := GL_UNSIGNED_BYTE;
 end;
 
-constructor TfdAlpha8.Create;
+constructor TfdAlpha8ub1.Create;
 begin
   inherited Create;
   fPixelSize        := 1.0;
-  fFormat           := tfAlpha8;
-  fWithAlpha        := tfAlpha8;
-  fOpenGLFormat     := tfAlpha8;
+  fFormat           := tfAlpha8ub1;
+  fWithAlpha        := tfAlpha8ub1;
+  fOpenGLFormat     := tfAlpha8ub1;
   fRange.a          := $FF;
   fglFormat         := GL_ALPHA;
   fglInternalFormat := GL_ALPHA8;
   fglDataFormat     := GL_UNSIGNED_BYTE;
 end;
 
-constructor TfdAlpha16.Create;
+constructor TfdAlpha16us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfAlpha16;
-  fWithAlpha        := tfAlpha16;
-  fOpenGLFormat     := tfAlpha16;
+  fFormat           := tfAlpha16us1;
+  fWithAlpha        := tfAlpha16us1;
+  fOpenGLFormat     := tfAlpha16us1;
   fRange.a          := $FFFF;
   fglFormat         := GL_ALPHA;
   fglInternalFormat := GL_ALPHA16;
   fglDataFormat     := GL_UNSIGNED_SHORT;
 end;
 
-constructor TfdLuminance4.Create;
+constructor TfdLuminance4ub1.Create;
 begin
   inherited Create;
   fPixelSize        := 1.0;
-  fFormat           := tfLuminance4;
-  fWithAlpha        := tfLuminance4Alpha4;
-  fWithoutAlpha     := tfLuminance4;
-  fOpenGLFormat     := tfLuminance4;
+  fFormat           := tfLuminance4ub1;
+  fWithAlpha        := tfLuminance4Alpha4ub2;
+  fWithoutAlpha     := tfLuminance4ub1;
+  fOpenGLFormat     := tfLuminance4ub1;
   fRange.r          := $FF;
   fRange.g          := $FF;
   fRange.b          := $FF;
@@ -3008,14 +3138,14 @@ begin
   fglDataFormat     := GL_UNSIGNED_BYTE;
 end;
 
-constructor TfdLuminance8.Create;
+constructor TfdLuminance8ub1.Create;
 begin
   inherited Create;
   fPixelSize        := 1.0;
-  fFormat           := tfLuminance8;
-  fWithAlpha        := tfLuminance8Alpha8;
-  fWithoutAlpha     := tfLuminance8;
-  fOpenGLFormat     := tfLuminance8;
+  fFormat           := tfLuminance8ub1;
+  fWithAlpha        := tfLuminance8Alpha8ub2;
+  fWithoutAlpha     := tfLuminance8ub1;
+  fOpenGLFormat     := tfLuminance8ub1;
   fRange.r          := $FF;
   fRange.g          := $FF;
   fRange.b          := $FF;
@@ -3024,14 +3154,14 @@ begin
   fglDataFormat     := GL_UNSIGNED_BYTE;
 end;
 
-constructor TfdLuminance16.Create;
+constructor TfdLuminance16us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfLuminance16;
-  fWithAlpha        := tfLuminance16Alpha16;
-  fWithoutAlpha     := tfLuminance16;
-  fOpenGLFormat     := tfLuminance16;
+  fFormat           := tfLuminance16us1;
+  fWithAlpha        := tfLuminance16Alpha16us2;
+  fWithoutAlpha     := tfLuminance16us1;
+  fOpenGLFormat     := tfLuminance16us1;
   fRange.r          := $FFFF;
   fRange.g          := $FFFF;
   fRange.b          := $FFFF;
@@ -3040,14 +3170,14 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT;
 end;
 
-constructor TfdLuminance4Alpha4.Create;
+constructor TfdLuminance4Alpha4ub2.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfLuminance4Alpha4;
-  fWithAlpha        := tfLuminance4Alpha4;
-  fWithoutAlpha     := tfLuminance4;
-  fOpenGLFormat     := tfLuminance4Alpha4;
+  fFormat           := tfLuminance4Alpha4ub2;
+  fWithAlpha        := tfLuminance4Alpha4ub2;
+  fWithoutAlpha     := tfLuminance4ub1;
+  fOpenGLFormat     := tfLuminance4Alpha4ub2;
   fRange.r          := $FF;
   fRange.g          := $FF;
   fRange.b          := $FF;
@@ -3061,14 +3191,14 @@ begin
   fglDataFormat     := GL_UNSIGNED_BYTE;
 end;
 
-constructor TfdLuminance6Alpha2.Create;
+constructor TfdLuminance6Alpha2ub2.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfLuminance6Alpha2;
-  fWithAlpha        := tfLuminance6Alpha2;
-  fWithoutAlpha     := tfLuminance8;
-  fOpenGLFormat     := tfLuminance6Alpha2;
+  fFormat           := tfLuminance6Alpha2ub2;
+  fWithAlpha        := tfLuminance6Alpha2ub2;
+  fWithoutAlpha     := tfLuminance8ub1;
+  fOpenGLFormat     := tfLuminance6Alpha2ub2;
   fRange.r          := $FF;
   fRange.g          := $FF;
   fRange.b          := $FF;
@@ -3082,14 +3212,14 @@ begin
   fglDataFormat     := GL_UNSIGNED_BYTE;
 end;
 
-constructor TfdLuminance8Alpha8.Create;
+constructor TfdLuminance8Alpha8ub2.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfLuminance8Alpha8;
-  fWithAlpha        := tfLuminance8Alpha8;
-  fWithoutAlpha     := tfLuminance8;
-  fOpenGLFormat     := tfLuminance8Alpha8;
+  fFormat           := tfLuminance8Alpha8ub2;
+  fWithAlpha        := tfLuminance8Alpha8ub2;
+  fWithoutAlpha     := tfLuminance8ub1;
+  fOpenGLFormat     := tfLuminance8Alpha8ub2;
   fRange.r          := $FF;
   fRange.g          := $FF;
   fRange.b          := $FF;
@@ -3103,14 +3233,14 @@ begin
   fglDataFormat     := GL_UNSIGNED_BYTE;
 end;
 
-constructor TfdLuminance12Alpha4.Create;
+constructor TfdLuminance12Alpha4us2.Create;
 begin
   inherited Create;
   fPixelSize        := 4.0;
-  fFormat           := tfLuminance12Alpha4;
-  fWithAlpha        := tfLuminance12Alpha4;
-  fWithoutAlpha     := tfLuminance16;
-  fOpenGLFormat     := tfLuminance12Alpha4;
+  fFormat           := tfLuminance12Alpha4us2;
+  fWithAlpha        := tfLuminance12Alpha4us2;
+  fWithoutAlpha     := tfLuminance16us1;
+  fOpenGLFormat     := tfLuminance12Alpha4us2;
   fRange.r          := $FFFF;
   fRange.g          := $FFFF;
   fRange.b          := $FFFF;
@@ -3124,14 +3254,14 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT;
 end;
 
-constructor TfdLuminance16Alpha16.Create;
+constructor TfdLuminance16Alpha16us2.Create;
 begin
   inherited Create;
   fPixelSize        := 4.0;
-  fFormat           := tfLuminance16Alpha16;
-  fWithAlpha        := tfLuminance16Alpha16;
-  fWithoutAlpha     := tfLuminance16;
-  fOpenGLFormat     := tfLuminance16Alpha16;
+  fFormat           := tfLuminance16Alpha16us2;
+  fWithAlpha        := tfLuminance16Alpha16us2;
+  fWithoutAlpha     := tfLuminance16us1;
+  fOpenGLFormat     := tfLuminance16Alpha16us2;
   fRange.r          := $FFFF;
   fRange.g          := $FFFF;
   fRange.b          := $FFFF;
@@ -3145,18 +3275,18 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT;
 end;
 
-constructor TfdR3G3B2.Create;
+constructor TfdR3G3B2ub1.Create;
 begin
   inherited Create;
   fPixelSize        := 1.0;
-  fFormat           := tfR3G3B2;
-  fWithAlpha        := tfRGBA4;
-  fWithoutAlpha     := tfR3G3B2;
-  fOpenGLFormat     := tfR3G3B2;
+  fFormat           := tfR3G3B2ub1;
+  fWithAlpha        := tfRGBA4us1;
+  fWithoutAlpha     := tfR3G3B2ub1;
+  fOpenGLFormat     := tfR3G3B2ub1;
   fRGBInverted      := tfEmpty;
   fRange.r          := $07;
   fRange.g          := $07;
-  fRange.b          := $04;
+  fRange.b          := $03;
   fShift.r          := 5;
   fShift.g          := 2;
   fShift.b          := 0;
@@ -3165,15 +3295,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_BYTE_3_3_2;
 end;
 
-constructor TfdRGBX4.Create;
+constructor TfdRGBX4us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfRGBX4;
-  fWithAlpha        := tfRGBA4;
-  fWithoutAlpha     := tfRGBX4;
-  fOpenGLFormat     := tfRGBX4;
-  fRGBInverted      := tfBGRX4;
+  fFormat           := tfRGBX4us1;
+  fWithAlpha        := tfRGBA4us1;
+  fWithoutAlpha     := tfRGBX4us1;
+  fOpenGLFormat     := tfRGBX4us1;
+  fRGBInverted      := tfBGRX4us1;
   fRange.r          := $0F;
   fRange.g          := $0F;
   fRange.b          := $0F;
@@ -3186,15 +3316,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT_4_4_4_4;
 end;
 
-constructor TfdXRGB4.Create;
+constructor TfdXRGB4us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfXRGB4;
-  fWithAlpha        := tfARGB4;
-  fWithoutAlpha     := tfXRGB4;
-  fOpenGLFormat     := tfXRGB4;
-  fRGBInverted      := tfXBGR4;
+  fFormat           := tfXRGB4us1;
+  fWithAlpha        := tfARGB4us1;
+  fWithoutAlpha     := tfXRGB4us1;
+  fOpenGLFormat     := tfXRGB4us1;
+  fRGBInverted      := tfXBGR4us1;
   fRange.r          := $0F;
   fRange.g          := $0F;
   fRange.b          := $0F;
@@ -3206,15 +3336,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT_4_4_4_4_REV;
 end;
 
-constructor TfdR5G6B5.Create;
+constructor TfdR5G6B5us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfR5G6B5;
-  fWithAlpha        := tfRGB5A1;
-  fWithoutAlpha     := tfR5G6B5;
-  fOpenGLFormat     := tfR5G6B5;
-  fRGBInverted      := tfB5G6R5;
+  fFormat           := tfR5G6B5us1;
+  fWithAlpha        := tfRGB5A1us1;
+  fWithoutAlpha     := tfR5G6B5us1;
+  fOpenGLFormat     := tfR5G6B5us1;
+  fRGBInverted      := tfB5G6R5us1;
   fRange.r          := $1F;
   fRange.g          := $3F;
   fRange.b          := $1F;
@@ -3226,15 +3356,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT_5_6_5;
 end;
 
-constructor TfdRGB5X1.Create;
+constructor TfdRGB5X1us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfRGB5X1;
-  fWithAlpha        := tfRGB5A1;
-  fWithoutAlpha     := tfRGB5X1;
-  fOpenGLFormat     := tfRGB5X1;
-  fRGBInverted      := tfBGR5X1;
+  fFormat           := tfRGB5X1us1;
+  fWithAlpha        := tfRGB5A1us1;
+  fWithoutAlpha     := tfRGB5X1us1;
+  fOpenGLFormat     := tfRGB5X1us1;
+  fRGBInverted      := tfBGR5X1us1;
   fRange.r          := $1F;
   fRange.g          := $1F;
   fRange.b          := $1F;
@@ -3246,15 +3376,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT_5_5_5_1;
 end;
 
-constructor TfdX1RGB5.Create;
+constructor TfdX1RGB5us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfX1RGB5;
-  fWithAlpha        := tfA1RGB5;
-  fWithoutAlpha     := tfX1RGB5;
-  fOpenGLFormat     := tfX1RGB5;
-  fRGBInverted      := tfX1BGR5;
+  fFormat           := tfX1RGB5us1;
+  fWithAlpha        := tfA1RGB5us1;
+  fWithoutAlpha     := tfX1RGB5us1;
+  fOpenGLFormat     := tfX1RGB5us1;
+  fRGBInverted      := tfX1BGR5us1;
   fRange.r          := $1F;
   fRange.g          := $1F;
   fRange.b          := $1F;
@@ -3266,35 +3396,35 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT_1_5_5_5_REV;
 end;
 
-constructor TfdRGB8.Create;
+constructor TfdRGB8ub3.Create;
 begin
   inherited Create;
   fPixelSize        := 3.0;
-  fFormat           := tfRGB8;
-  fWithAlpha        := tfRGBA8;
-  fWithoutAlpha     := tfRGB8;
-  fOpenGLFormat     := tfRGB8;
-  fRGBInverted      := tfBGR8;
+  fFormat           := tfRGB8ub3;
+  fWithAlpha        := tfRGBA8ub4;
+  fWithoutAlpha     := tfRGB8ub3;
+  fOpenGLFormat     := tfRGB8ub3;
+  fRGBInverted      := tfBGR8ub3;
   fRange.r          := $FF;
   fRange.g          := $FF;
   fRange.b          := $FF;
-  fShift.r          := 16;
+  fShift.r          :=  0;
   fShift.g          :=  8;
-  fShift.b          :=  0;
-  fglFormat         := GL_BGR;    // reverse byte order to match little endianess
-  fglInternalFormat := GL_RGB8;   // as if u interpret the 3 bytes as unsigned integer
+  fShift.b          := 16;
+  fglFormat         := GL_RGB;
+  fglInternalFormat := GL_RGB8;
   fglDataFormat     := GL_UNSIGNED_BYTE;
 end;
 
-constructor TfdRGBX8.Create;
+constructor TfdRGBX8ui1.Create;
 begin
   inherited Create;
   fPixelSize        := 4.0;
-  fFormat           := tfRGBX8;
-  fWithAlpha        := tfRGBA8;
-  fWithoutAlpha     := tfRGBX8;
-  fOpenGLFormat     := tfRGB8;
-  fRGBInverted      := tfBGRX8;
+  fFormat           := tfRGBX8ui1;
+  fWithAlpha        := tfRGBA8ui1;
+  fWithoutAlpha     := tfRGBX8ui1;
+  fOpenGLFormat     := tfRGB8ub3;
+  fRGBInverted      := tfBGRX8ui1;
   fRange.r          := $FF;
   fRange.g          := $FF;
   fRange.b          := $FF;
@@ -3306,15 +3436,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_INT_8_8_8_8;
 end;
 
-constructor TfdXRGB8.Create;
+constructor TfdXRGB8ui1.Create;
 begin
   inherited Create;
   fPixelSize        := 4.0;
-  fFormat           := tfXRGB8;
-  fWithAlpha        := tfXRGB8;
-  fWithoutAlpha     := tfXRGB8;
-  fOpenGLFormat     := tfRGB8;
-  fRGBInverted      := tfXBGR8;
+  fFormat           := tfXRGB8ui1;
+  fWithAlpha        := tfXRGB8ui1;
+  fWithoutAlpha     := tfXRGB8ui1;
+  fOpenGLFormat     := tfRGB8ub3;
+  fRGBInverted      := tfXBGR8ui1;
   fRange.r          := $FF;
   fRange.g          := $FF;
   fRange.b          := $FF;
@@ -3326,15 +3456,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_INT_8_8_8_8_REV;
 end;
 
-constructor TfdRGB10X2.Create;
+constructor TfdRGB10X2ui1.Create;
 begin
   inherited Create;
-  fPixelSize        := 3.0;
-  fFormat           := tfRGB10X2;
-  fWithAlpha        := tfRGB10A2;
-  fWithoutAlpha     := tfRGB10X2;
-  fOpenGLFormat     := tfRGB10X2;
-  fRGBInverted      := tfBGR10X2;
+  fPixelSize        := 4.0;
+  fFormat           := tfRGB10X2ui1;
+  fWithAlpha        := tfRGB10A2ui1;
+  fWithoutAlpha     := tfRGB10X2ui1;
+  fOpenGLFormat     := tfRGB10X2ui1;
+  fRGBInverted      := tfBGR10X2ui1;
   fRange.r          := $03FF;
   fRange.g          := $03FF;
   fRange.b          := $03FF;
@@ -3346,15 +3476,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_INT_10_10_10_2;
 end;
 
-constructor TfdX2RGB10.Create;
+constructor TfdX2RGB10ui1.Create;
 begin
   inherited Create;
-  fPixelSize        := 3.0;
-  fFormat           := tfX2RGB10;
-  fWithAlpha        := tfA2RGB10;
-  fWithoutAlpha     := tfX2RGB10;
-  fOpenGLFormat     := tfX2RGB10;
-  fRGBInverted      := tfX2BGR10;
+  fPixelSize        := 4.0;
+  fFormat           := tfX2RGB10ui1;
+  fWithAlpha        := tfA2RGB10ui1;
+  fWithoutAlpha     := tfX2RGB10ui1;
+  fOpenGLFormat     := tfX2RGB10ui1;
+  fRGBInverted      := tfX2BGR10ui1;
   fRange.r          := $03FF;
   fRange.g          := $03FF;
   fRange.b          := $03FF;
@@ -3366,35 +3496,35 @@ begin
   fglDataFormat     := GL_UNSIGNED_INT_2_10_10_10_REV;
 end;
 
-constructor TfdRGB16.Create;
+constructor TfdRGB16us3.Create;
 begin
   inherited Create;
   fPixelSize        := 6.0;
-  fFormat           := tfRGB16;
-  fWithAlpha        := tfRGBA16;
-  fWithoutAlpha     := tfRGB16;
-  fOpenGLFormat     := tfRGB16;
-  fRGBInverted      := tfBGR16;
+  fFormat           := tfRGB16us3;
+  fWithAlpha        := tfRGBA16us4;
+  fWithoutAlpha     := tfRGB16us3;
+  fOpenGLFormat     := tfRGB16us3;
+  fRGBInverted      := tfBGR16us3;
   fRange.r          := $FFFF;
   fRange.g          := $FFFF;
   fRange.b          := $FFFF;
-  fShift.r          := 32;
+  fShift.r          :=  0;
   fShift.g          := 16;
-  fShift.b          :=  0;
-  fglFormat         := GL_BGR;     // reverse byte order to match little endianess
-  fglInternalFormat := GL_RGB16;   // as if u interpret the 3 bytes as unsigned integer
+  fShift.b          := 32;
+  fglFormat         := GL_RGB;
+  fglInternalFormat := GL_RGB16;
   fglDataFormat     := GL_UNSIGNED_SHORT;
 end;
 
-constructor TfdRGBA4.Create;
+constructor TfdRGBA4us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfRGBA4;
-  fWithAlpha        := tfRGBA4;
-  fWithoutAlpha     := tfRGBX4;
-  fOpenGLFormat     := tfRGBA4;
-  fRGBInverted      := tfBGRA4;
+  fFormat           := tfRGBA4us1;
+  fWithAlpha        := tfRGBA4us1;
+  fWithoutAlpha     := tfRGBX4us1;
+  fOpenGLFormat     := tfRGBA4us1;
+  fRGBInverted      := tfBGRA4us1;
   fRange.r          := $0F;
   fRange.g          := $0F;
   fRange.b          := $0F;
@@ -3408,15 +3538,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT_4_4_4_4;
 end;
 
-constructor TfdARGB4.Create;
+constructor TfdARGB4us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfARGB4;
-  fWithAlpha        := tfARGB4;
-  fWithoutAlpha     := tfXRGB4;
-  fOpenGLFormat     := tfARGB4;
-  fRGBInverted      := tfABGR4;
+  fFormat           := tfARGB4us1;
+  fWithAlpha        := tfARGB4us1;
+  fWithoutAlpha     := tfXRGB4us1;
+  fOpenGLFormat     := tfARGB4us1;
+  fRGBInverted      := tfABGR4us1;
   fRange.r          := $0F;
   fRange.g          := $0F;
   fRange.b          := $0F;
@@ -3430,15 +3560,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT_4_4_4_4_REV;
 end;
 
-constructor TfdRGB5A1.Create;
+constructor TfdRGB5A1us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfRGB5A1;
-  fWithAlpha        := tfRGB5A1;
-  fWithoutAlpha     := tfRGB5X1;
-  fOpenGLFormat     := tfRGB5A1;
-  fRGBInverted      := tfBGR5A1;
+  fFormat           := tfRGB5A1us1;
+  fWithAlpha        := tfRGB5A1us1;
+  fWithoutAlpha     := tfRGB5X1us1;
+  fOpenGLFormat     := tfRGB5A1us1;
+  fRGBInverted      := tfBGR5A1us1;
   fRange.r          := $1F;
   fRange.g          := $1F;
   fRange.b          := $1F;
@@ -3452,15 +3582,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT_5_5_5_1;
 end;
 
-constructor TfdA1RGB5.Create;
+constructor TfdA1RGB5us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfA1RGB5;
-  fWithAlpha        := tfA1RGB5;
-  fWithoutAlpha     := tfX1RGB5;
-  fOpenGLFormat     := tfA1RGB5;
-  fRGBInverted      := tfA1BGR5;
+  fFormat           := tfA1RGB5us1;
+  fWithAlpha        := tfA1RGB5us1;
+  fWithoutAlpha     := tfX1RGB5us1;
+  fOpenGLFormat     := tfA1RGB5us1;
+  fRGBInverted      := tfA1BGR5us1;
   fRange.r          := $1F;
   fRange.g          := $1F;
   fRange.b          := $1F;
@@ -3474,15 +3604,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT_1_5_5_5_REV;
 end;
 
-constructor TfdRGBA8.Create;
+constructor TfdRGBA8ui1.Create;
 begin
   inherited Create;
   fPixelSize        := 4.0;
-  fFormat           := tfRGBA8;
-  fWithAlpha        := tfRGBA8;
-  fWithoutAlpha     := tfRGB8;
-  fOpenGLFormat     := tfRGBA8;
-  fRGBInverted      := tfBGRA8;
+  fFormat           := tfRGBA8ui1;
+  fWithAlpha        := tfRGBA8ui1;
+  fWithoutAlpha     := tfRGBX8ui1;
+  fOpenGLFormat     := tfRGBA8ui1;
+  fRGBInverted      := tfBGRA8ui1;
   fRange.r          := $FF;
   fRange.g          := $FF;
   fRange.b          := $FF;
@@ -3496,15 +3626,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_INT_8_8_8_8;
 end;
 
-constructor TfdARGB8.Create;
+constructor TfdARGB8ui1.Create;
 begin
   inherited Create;
   fPixelSize        := 4.0;
-  fFormat           := tfARGB8;
-  fWithAlpha        := tfARGB8;
-  fWithoutAlpha     := tfRGB8;
-  fOpenGLFormat     := tfARGB8;
-  fRGBInverted      := tfABGR8;
+  fFormat           := tfARGB8ui1;
+  fWithAlpha        := tfARGB8ui1;
+  fWithoutAlpha     := tfXRGB8ui1;
+  fOpenGLFormat     := tfARGB8ui1;
+  fRGBInverted      := tfABGR8ui1;
   fRange.r          := $FF;
   fRange.g          := $FF;
   fRange.b          := $FF;
@@ -3518,15 +3648,37 @@ begin
   fglDataFormat     := GL_UNSIGNED_INT_8_8_8_8_REV;
 end;
 
-constructor TfdRGB10A2.Create;
+constructor TfdRGBA8ub4.Create;
 begin
   inherited Create;
-  fPixelSize        := 3.0;
-  fFormat           := tfRGB10A2;
-  fWithAlpha        := tfRGB10A2;
-  fWithoutAlpha     := tfRGB10X2;
-  fOpenGLFormat     := tfRGB10A2;
-  fRGBInverted      := tfBGR10A2;
+  fPixelSize        := 4.0;
+  fFormat           := tfRGBA8ub4;
+  fWithAlpha        := tfRGBA8ub4;
+  fWithoutAlpha     := tfRGB8ub3;
+  fOpenGLFormat     := tfRGBA8ub4;
+  fRGBInverted      := tfBGRA8ub4;
+  fRange.r          := $FF;
+  fRange.g          := $FF;
+  fRange.b          := $FF;
+  fRange.a          := $FF;
+  fShift.r          :=  0;
+  fShift.g          :=  8;
+  fShift.b          := 16;
+  fShift.a          := 24;
+  fglFormat         := GL_RGBA;
+  fglInternalFormat := GL_RGBA8;
+  fglDataFormat     := GL_UNSIGNED_BYTE;
+end;
+
+constructor TfdRGB10A2ui1.Create;
+begin
+  inherited Create;
+  fPixelSize        := 4.0;
+  fFormat           := tfRGB10A2ui1;
+  fWithAlpha        := tfRGB10A2ui1;
+  fWithoutAlpha     := tfRGB10X2ui1;
+  fOpenGLFormat     := tfRGB10A2ui1;
+  fRGBInverted      := tfBGR10A2ui1;
   fRange.r          := $03FF;
   fRange.g          := $03FF;
   fRange.b          := $03FF;
@@ -3540,15 +3692,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_INT_10_10_10_2;
 end;
 
-constructor TfdA2RGB10.Create;
+constructor TfdA2RGB10ui1.Create;
 begin
   inherited Create;
-  fPixelSize        := 3.0;
-  fFormat           := tfA2RGB10;
-  fWithAlpha        := tfA2RGB10;
-  fWithoutAlpha     := tfX2RGB10;
-  fOpenGLFormat     := tfA2RGB10;
-  fRGBInverted      := tfA2BGR10;
+  fPixelSize        := 4.0;
+  fFormat           := tfA2RGB10ui1;
+  fWithAlpha        := tfA2RGB10ui1;
+  fWithoutAlpha     := tfX2RGB10ui1;
+  fOpenGLFormat     := tfA2RGB10ui1;
+  fRGBInverted      := tfA2BGR10ui1;
   fRange.r          := $03FF;
   fRange.g          := $03FF;
   fRange.b          := $03FF;
@@ -3562,40 +3714,40 @@ begin
   fglDataFormat     := GL_UNSIGNED_INT_2_10_10_10_REV;
 end;
 
-constructor TfdRGBA16.Create;
+constructor TfdRGBA16us4.Create;
 begin
   inherited Create;
   fPixelSize        := 8.0;
-  fFormat           := tfRGBA16;
-  fWithAlpha        := tfRGBA16;
-  fWithoutAlpha     := tfRGB16;
-  fOpenGLFormat     := tfRGBA16;
-  fRGBInverted      := tfBGRA16;
+  fFormat           := tfRGBA16us4;
+  fWithAlpha        := tfRGBA16us4;
+  fWithoutAlpha     := tfRGB16us3;
+  fOpenGLFormat     := tfRGBA16us4;
+  fRGBInverted      := tfBGRA16us4;
   fRange.r          := $FFFF;
   fRange.g          := $FFFF;
   fRange.b          := $FFFF;
   fRange.a          := $FFFF;
-  fShift.r          := 48;
-  fShift.g          := 32;
-  fShift.b          := 16;
-  fShift.a          :=  0;
-  fglFormat         := GL_BGRA;     // reverse byte order to match little endianess
-  fglInternalFormat := GL_RGBA16;   // as if u interpret the 3 bytes as unsigned integer
+  fShift.r          :=  0;
+  fShift.g          := 16;
+  fShift.b          := 32;
+  fShift.a          := 48;
+  fglFormat         := GL_RGBA;
+  fglInternalFormat := GL_RGBA16;
   fglDataFormat     := GL_UNSIGNED_SHORT;
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-constructor TfdBGRX4.Create;
+constructor TfdBGRX4us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfBGRX4;
-  fWithAlpha        := tfBGRA4;
-  fWithoutAlpha     := tfBGRX4;
-  fOpenGLFormat     := tfBGRX4;
-  fRGBInverted      := tfRGBX4;
+  fFormat           := tfBGRX4us1;
+  fWithAlpha        := tfBGRA4us1;
+  fWithoutAlpha     := tfBGRX4us1;
+  fOpenGLFormat     := tfBGRX4us1;
+  fRGBInverted      := tfRGBX4us1;
   fRange.r          := $0F;
   fRange.g          := $0F;
   fRange.b          := $0F;
@@ -3607,19 +3759,18 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT_4_4_4_4;
 end;
 
-constructor TfdXBGR4.Create;
+constructor TfdXBGR4us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfXBGR4;
-  fWithAlpha        := tfABGR4;
-  fWithoutAlpha     := tfXBGR4;
-  fOpenGLFormat     := tfXBGR4;
-  fRGBInverted      := tfXRGB4;
+  fFormat           := tfXBGR4us1;
+  fWithAlpha        := tfABGR4us1;
+  fWithoutAlpha     := tfXBGR4us1;
+  fOpenGLFormat     := tfXBGR4us1;
+  fRGBInverted      := tfXRGB4us1;
   fRange.r          := $0F;
   fRange.g          := $0F;
   fRange.b          := $0F;
-  fRange.a          := $0F;
   fShift.r          := 0;
   fShift.g          := 4;
   fShift.b          := 8;
@@ -3628,15 +3779,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT_4_4_4_4_REV;
 end;
 
-constructor TfdB5G6R5.Create;
+constructor TfdB5G6R5us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfB5G6R5;
-  fWithAlpha        := tfBGR5A1;
-  fWithoutAlpha     := tfB5G6R5;
-  fOpenGLFormat     := tfB5G6R5;
-  fRGBInverted      := tfR5G6B5;
+  fFormat           := tfB5G6R5us1;
+  fWithAlpha        := tfBGR5A1us1;
+  fWithoutAlpha     := tfB5G6R5us1;
+  fOpenGLFormat     := tfB5G6R5us1;
+  fRGBInverted      := tfR5G6B5us1;
   fRange.r          := $1F;
   fRange.g          := $3F;
   fRange.b          := $1F;
@@ -3648,15 +3799,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT_5_6_5_REV;
 end;
 
-constructor TfdBGR5X1.Create;
+constructor TfdBGR5X1us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfBGR5X1;
-  fWithAlpha        := tfBGR5A1;
-  fWithoutAlpha     := tfBGR5X1;
-  fOpenGLFormat     := tfBGR5X1;
-  fRGBInverted      := tfRGB5X1;
+  fFormat           := tfBGR5X1us1;
+  fWithAlpha        := tfBGR5A1us1;
+  fWithoutAlpha     := tfBGR5X1us1;
+  fOpenGLFormat     := tfBGR5X1us1;
+  fRGBInverted      := tfRGB5X1us1;
   fRange.r          := $1F;
   fRange.g          := $1F;
   fRange.b          := $1F;
@@ -3668,15 +3819,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT_5_5_5_1;
 end;
 
-constructor TfdX1BGR5.Create;
+constructor TfdX1BGR5us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfX1BGR5;
-  fWithAlpha        := tfA1BGR5;
-  fWithoutAlpha     := tfX1BGR5;
-  fOpenGLFormat     := tfX1BGR5;
-  fRGBInverted      := tfX1RGB5;
+  fFormat           := tfX1BGR5us1;
+  fWithAlpha        := tfA1BGR5us1;
+  fWithoutAlpha     := tfX1BGR5us1;
+  fOpenGLFormat     := tfX1BGR5us1;
+  fRGBInverted      := tfX1RGB5us1;
   fRange.r          := $1F;
   fRange.g          := $1F;
   fRange.b          := $1F;
@@ -3688,35 +3839,35 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT_1_5_5_5_REV;
 end;
 
-constructor TfdBGR8.Create;
+constructor TfdBGR8ub3.Create;
 begin
   inherited Create;
   fPixelSize        := 3.0;
-  fFormat           := tfBGR8;
-  fWithAlpha        := tfBGRA8;
-  fWithoutAlpha     := tfBGR8;
-  fOpenGLFormat     := tfBGR8;
-  fRGBInverted      := tfRGB8;
+  fFormat           := tfBGR8ub3;
+  fWithAlpha        := tfBGRA8ub4;
+  fWithoutAlpha     := tfBGR8ub3;
+  fOpenGLFormat     := tfBGR8ub3;
+  fRGBInverted      := tfRGB8ub3;
   fRange.r          := $FF;
   fRange.g          := $FF;
   fRange.b          := $FF;
-  fShift.r          :=  0;
+  fShift.r          := 16;
   fShift.g          :=  8;
-  fShift.b          := 16;
-  fglFormat         := GL_RGB;      // reverse byte order to match little endianess
-  fglInternalFormat := GL_RGB8;     // as if u interpret the 3 bytes as unsigned integer
+  fShift.b          :=  0;
+  fglFormat         := GL_BGR;
+  fglInternalFormat := GL_RGB8;
   fglDataFormat     := GL_UNSIGNED_BYTE;
 end;
 
-constructor TfdBGRX8.Create;
+constructor TfdBGRX8ui1.Create;
 begin
   inherited Create;
   fPixelSize        := 4.0;
-  fFormat           := tfBGRX8;
-  fWithAlpha        := tfBGRA8;
-  fWithoutAlpha     := tfBGRX8;
-  fOpenGLFormat     := tfBGRX8;
-  fRGBInverted      := tfRGBX8;
+  fFormat           := tfBGRX8ui1;
+  fWithAlpha        := tfBGRA8ui1;
+  fWithoutAlpha     := tfBGRX8ui1;
+  fOpenGLFormat     := tfBGRX8ui1;
+  fRGBInverted      := tfRGBX8ui1;
   fRange.r          := $FF;
   fRange.g          := $FF;
   fRange.b          := $FF;
@@ -3728,15 +3879,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_INT_8_8_8_8;
 end;
 
-constructor TfdXBGR8.Create;
+constructor TfdXBGR8ui1.Create;
 begin
   inherited Create;
   fPixelSize        := 4.0;
-  fFormat           := tfXBGR8;
-  fWithAlpha        := tfABGR8;
-  fWithoutAlpha     := tfXBGR8;
-  fOpenGLFormat     := tfXBGR8;
-  fRGBInverted      := tfXRGB8;
+  fFormat           := tfXBGR8ui1;
+  fWithAlpha        := tfABGR8ui1;
+  fWithoutAlpha     := tfXBGR8ui1;
+  fOpenGLFormat     := tfXBGR8ui1;
+  fRGBInverted      := tfXRGB8ui1;
   fRange.r          := $FF;
   fRange.g          := $FF;
   fRange.b          := $FF;
@@ -3748,15 +3899,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_INT_8_8_8_8_REV;
 end;
 
-constructor TfdBGR10X2.Create;
+constructor TfdBGR10X2ui1.Create;
 begin
   inherited Create;
-  fPixelSize        := 3.0;
-  fFormat           := tfBGR10X2;
-  fWithAlpha        := tfBGR10A2;
-  fWithoutAlpha     := tfBGR10X2;
-  fOpenGLFormat     := tfBGR10X2;
-  fRGBInverted      := tfRGB10X2;
+  fPixelSize        := 4.0;
+  fFormat           := tfBGR10X2ui1;
+  fWithAlpha        := tfBGR10A2ui1;
+  fWithoutAlpha     := tfBGR10X2ui1;
+  fOpenGLFormat     := tfBGR10X2ui1;
+  fRGBInverted      := tfRGB10X2ui1;
   fRange.r          := $03FF;
   fRange.g          := $03FF;
   fRange.b          := $03FF;
@@ -3768,15 +3919,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_INT_10_10_10_2;
 end;
 
-constructor TfdX2BGR10.Create;
+constructor TfdX2BGR10ui1.Create;
 begin
   inherited Create;
-  fPixelSize        := 3.0;
-  fFormat           := tfX2BGR10;
-  fWithAlpha        := tfA2BGR10;
-  fWithoutAlpha     := tfX2BGR10;
-  fOpenGLFormat     := tfX2BGR10;
-  fRGBInverted      := tfX2RGB10;
+  fPixelSize        := 4.0;
+  fFormat           := tfX2BGR10ui1;
+  fWithAlpha        := tfA2BGR10ui1;
+  fWithoutAlpha     := tfX2BGR10ui1;
+  fOpenGLFormat     := tfX2BGR10ui1;
+  fRGBInverted      := tfX2RGB10ui1;
   fRange.r          := $03FF;
   fRange.g          := $03FF;
   fRange.b          := $03FF;
@@ -3788,35 +3939,35 @@ begin
   fglDataFormat     := GL_UNSIGNED_INT_2_10_10_10_REV;
 end;
 
-constructor TfdBGR16.Create;
+constructor TfdBGR16us3.Create;
 begin
   inherited Create;
   fPixelSize        := 6.0;
-  fFormat           := tfBGR16;
-  fWithAlpha        := tfBGRA16;
-  fWithoutAlpha     := tfBGR16;
-  fOpenGLFormat     := tfBGR16;
-  fRGBInverted      := tfRGB16;
+  fFormat           := tfBGR16us3;
+  fWithAlpha        := tfBGRA16us4;
+  fWithoutAlpha     := tfBGR16us3;
+  fOpenGLFormat     := tfBGR16us3;
+  fRGBInverted      := tfRGB16us3;
   fRange.r          := $FFFF;
   fRange.g          := $FFFF;
   fRange.b          := $FFFF;
-  fShift.r          :=  0;
+  fShift.r          := 32;
   fShift.g          := 16;
-  fShift.b          := 32;
-  fglFormat         := GL_RGB;      // reverse byte order to match little endianess
-  fglInternalFormat := GL_RGB16;    // as if u interpret the 3 bytes as unsigned integer
+  fShift.b          :=  0;
+  fglFormat         := GL_BGR;
+  fglInternalFormat := GL_RGB16;
   fglDataFormat     := GL_UNSIGNED_SHORT;
 end;
 
-constructor TfdBGRA4.Create;
+constructor TfdBGRA4us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfBGRA4;
-  fWithAlpha        := tfBGRA4;
-  fWithoutAlpha     := tfBGRX4;
-  fOpenGLFormat     := tfBGRA4;
-  fRGBInverted      := tfRGBA4;
+  fFormat           := tfBGRA4us1;
+  fWithAlpha        := tfBGRA4us1;
+  fWithoutAlpha     := tfBGRX4us1;
+  fOpenGLFormat     := tfBGRA4us1;
+  fRGBInverted      := tfRGBA4us1;
   fRange.r          := $0F;
   fRange.g          := $0F;
   fRange.b          := $0F;
@@ -3830,15 +3981,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT_4_4_4_4;
 end;
 
-constructor TfdABGR4.Create;
+constructor TfdABGR4us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfABGR4;
-  fWithAlpha        := tfABGR4;
-  fWithoutAlpha     := tfXBGR4;
-  fOpenGLFormat     := tfABGR4;
-  fRGBInverted      := tfARGB4;
+  fFormat           := tfABGR4us1;
+  fWithAlpha        := tfABGR4us1;
+  fWithoutAlpha     := tfXBGR4us1;
+  fOpenGLFormat     := tfABGR4us1;
+  fRGBInverted      := tfARGB4us1;
   fRange.r          := $0F;
   fRange.g          := $0F;
   fRange.b          := $0F;
@@ -3852,15 +4003,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT_4_4_4_4_REV;
 end;
 
-constructor TfdBGR5A1.Create;
+constructor TfdBGR5A1us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfBGR5A1;
-  fWithAlpha        := tfBGR5A1;
-  fWithoutAlpha     := tfBGR5X1;
-  fOpenGLFormat     := tfBGR5A1;
-  fRGBInverted      := tfRGB5A1;
+  fFormat           := tfBGR5A1us1;
+  fWithAlpha        := tfBGR5A1us1;
+  fWithoutAlpha     := tfBGR5X1us1;
+  fOpenGLFormat     := tfBGR5A1us1;
+  fRGBInverted      := tfRGB5A1us1;
   fRange.r          := $1F;
   fRange.g          := $1F;
   fRange.b          := $1F;
@@ -3874,15 +4025,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT_5_5_5_1;
 end;
 
-constructor TfdA1BGR5.Create;
+constructor TfdA1BGR5us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfA1BGR5;
-  fWithAlpha        := tfA1BGR5;
-  fWithoutAlpha     := tfX1BGR5;
-  fOpenGLFormat     := tfA1BGR5;
-  fRGBInverted      := tfA1RGB5;
+  fFormat           := tfA1BGR5us1;
+  fWithAlpha        := tfA1BGR5us1;
+  fWithoutAlpha     := tfX1BGR5us1;
+  fOpenGLFormat     := tfA1BGR5us1;
+  fRGBInverted      := tfA1RGB5us1;
   fRange.r          := $1F;
   fRange.g          := $1F;
   fRange.b          := $1F;
@@ -3896,15 +4047,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT_1_5_5_5_REV;
 end;
 
-constructor TfdBGRA8.Create;
+constructor TfdBGRA8ui1.Create;
 begin
   inherited Create;
   fPixelSize        := 4.0;
-  fFormat           := tfBGRA8;
-  fWithAlpha        := tfBGRA8;
-  fWithoutAlpha     := tfBGR8;
-  fOpenGLFormat     := tfBGRA8;
-  fRGBInverted      := tfRGBA8;
+  fFormat           := tfBGRA8ui1;
+  fWithAlpha        := tfBGRA8ui1;
+  fWithoutAlpha     := tfBGRX8ui1;
+  fOpenGLFormat     := tfBGRA8ui1;
+  fRGBInverted      := tfRGBA8ui1;
   fRange.r          := $FF;
   fRange.g          := $FF;
   fRange.b          := $FF;
@@ -3918,15 +4069,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_INT_8_8_8_8;
 end;
 
-constructor TfdABGR8.Create;
+constructor TfdABGR8ui1.Create;
 begin
   inherited Create;
   fPixelSize        := 4.0;
-  fFormat           := tfABGR8;
-  fWithAlpha        := tfABGR8;
-  fWithoutAlpha     := tfBGR8;
-  fOpenGLFormat     := tfABGR8;
-  fRGBInverted      := tfARGB8;
+  fFormat           := tfABGR8ui1;
+  fWithAlpha        := tfABGR8ui1;
+  fWithoutAlpha     := tfXBGR8ui1;
+  fOpenGLFormat     := tfABGR8ui1;
+  fRGBInverted      := tfARGB8ui1;
   fRange.r          := $FF;
   fRange.g          := $FF;
   fRange.b          := $FF;
@@ -3940,15 +4091,37 @@ begin
   fglDataFormat     := GL_UNSIGNED_INT_8_8_8_8_REV;
 end;
 
-constructor TfdBGR10A2.Create;
+constructor TfdBGRA8ub4.Create;
 begin
   inherited Create;
-  fPixelSize        := 3.0;
-  fFormat           := tfBGR10A2;
-  fWithAlpha        := tfBGR10A2;
-  fWithoutAlpha     := tfBGR10X2;
-  fOpenGLFormat     := tfBGR10A2;
-  fRGBInverted      := tfRGB10A2;
+  fPixelSize        := 4.0;
+  fFormat           := tfBGRA8ub4;
+  fWithAlpha        := tfBGRA8ub4;
+  fWithoutAlpha     := tfBGR8ub3;
+  fOpenGLFormat     := tfBGRA8ub4;
+  fRGBInverted      := tfRGBA8ub4;
+  fRange.r          := $FF;
+  fRange.g          := $FF;
+  fRange.b          := $FF;
+  fRange.a          := $FF;
+  fShift.r          := 16;
+  fShift.g          :=  8;
+  fShift.b          :=  0;
+  fShift.a          := 24;
+  fglFormat         := GL_BGRA;
+  fglInternalFormat := GL_RGBA8;
+  fglDataFormat     := GL_UNSIGNED_BYTE;
+end;
+
+constructor TfdBGR10A2ui1.Create;
+begin
+  inherited Create;
+  fPixelSize        := 4.0;
+  fFormat           := tfBGR10A2ui1;
+  fWithAlpha        := tfBGR10A2ui1;
+  fWithoutAlpha     := tfBGR10X2ui1;
+  fOpenGLFormat     := tfBGR10A2ui1;
+  fRGBInverted      := tfRGB10A2ui1;
   fRange.r          := $03FF;
   fRange.g          := $03FF;
   fRange.b          := $03FF;
@@ -3962,15 +4135,15 @@ begin
   fglDataFormat     := GL_UNSIGNED_INT_10_10_10_2;
 end;
 
-constructor TfdA2BGR10.Create;
+constructor TfdA2BGR10ui1.Create;
 begin
   inherited Create;
-  fPixelSize        := 3.0;
-  fFormat           := tfA2BGR10;
-  fWithAlpha        := tfA2BGR10;
-  fWithoutAlpha     := tfX2BGR10;
-  fOpenGLFormat     := tfA2BGR10;
-  fRGBInverted      := tfA2RGB10;
+  fPixelSize        := 4.0;
+  fFormat           := tfA2BGR10ui1;
+  fWithAlpha        := tfA2BGR10ui1;
+  fWithoutAlpha     := tfX2BGR10ui1;
+  fOpenGLFormat     := tfA2BGR10ui1;
+  fRGBInverted      := tfA2RGB10ui1;
   fRange.r          := $03FF;
   fRange.g          := $03FF;
   fRange.b          := $03FF;
@@ -3984,35 +4157,35 @@ begin
   fglDataFormat     := GL_UNSIGNED_INT_2_10_10_10_REV;
 end;
 
-constructor TfdBGRA16.Create;
+constructor TfdBGRA16us4.Create;
 begin
   inherited Create;
   fPixelSize        := 8.0;
-  fFormat           := tfBGRA16;
-  fWithAlpha        := tfBGRA16;
-  fWithoutAlpha     := tfBGR16;
-  fOpenGLFormat     := tfBGRA16;
-  fRGBInverted      := tfRGBA16;
+  fFormat           := tfBGRA16us4;
+  fWithAlpha        := tfBGRA16us4;
+  fWithoutAlpha     := tfBGR16us3;
+  fOpenGLFormat     := tfBGRA16us4;
+  fRGBInverted      := tfRGBA16us4;
   fRange.r          := $FFFF;
   fRange.g          := $FFFF;
   fRange.b          := $FFFF;
   fRange.a          := $FFFF;
-  fShift.r          := 16;
-  fShift.g          := 32;
-  fShift.b          := 48;
-  fShift.a          :=  0;
-  fglFormat         := GL_RGBA;      // reverse byte order to match little endianess
-  fglInternalFormat := GL_RGBA16;    // as if u interpret the 3 bytes as unsigned integer
+  fShift.r          := 32;
+  fShift.g          := 16;
+  fShift.b          :=  0;
+  fShift.a          := 48;
+  fglFormat         := GL_BGRA;
+  fglInternalFormat := GL_RGBA16;
   fglDataFormat     := GL_UNSIGNED_SHORT;
 end;
 
-constructor TfdDepth16.Create;
+constructor TfdDepth16us1.Create;
 begin
   inherited Create;
   fPixelSize        := 2.0;
-  fFormat           := tfDepth16;
-  fWithoutAlpha     := tfDepth16;
-  fOpenGLFormat     := tfDepth16;
+  fFormat           := tfDepth16us1;
+  fWithoutAlpha     := tfDepth16us1;
+  fOpenGLFormat     := tfDepth16us1;
   fRange.r          := $FFFF;
   fRange.g          := $FFFF;
   fRange.b          := $FFFF;
@@ -4022,29 +4195,29 @@ begin
   fglDataFormat     := GL_UNSIGNED_SHORT;
 end;
 
-constructor TfdDepth24.Create;
+constructor TfdDepth24ui1.Create;
 begin
   inherited Create;
-  fPixelSize        := 3.0;
-  fFormat           := tfDepth24;
-  fWithoutAlpha     := tfDepth24;
-  fOpenGLFormat     := tfDepth24;
-  fRange.r          := $FFFFFF;
-  fRange.g          := $FFFFFF;
-  fRange.b          := $FFFFFF;
-  fRange.a          := $FFFFFF;
+  fPixelSize        := 4.0;
+  fFormat           := tfDepth24ui1;
+  fWithoutAlpha     := tfDepth24ui1;
+  fOpenGLFormat     := tfDepth24ui1;
+  fRange.r          := $FFFFFFFF;
+  fRange.g          := $FFFFFFFF;
+  fRange.b          := $FFFFFFFF;
+  fRange.a          := $FFFFFFFF;
   fglFormat         := GL_DEPTH_COMPONENT;
   fglInternalFormat := GL_DEPTH_COMPONENT24;
   fglDataFormat     := GL_UNSIGNED_INT;
 end;
 
-constructor TfdDepth32.Create;
+constructor TfdDepth32ui1.Create;
 begin
   inherited Create;
   fPixelSize        := 4.0;
-  fFormat           := tfDepth32;
-  fWithoutAlpha     := tfDepth32;
-  fOpenGLFormat     := tfDepth32;
+  fFormat           := tfDepth32ui1;
+  fWithoutAlpha     := tfDepth32ui1;
+  fOpenGLFormat     := tfDepth32ui1;
   fRange.r          := $FFFFFFFF;
   fRange.g          := $FFFFFFFF;
   fRange.b          := $FFFFFFFF;
@@ -4073,7 +4246,7 @@ begin
   fFormat           := tfS3tcDtx1RGBA;
   fWithAlpha        := tfS3tcDtx1RGBA;
   fOpenGLFormat     := tfS3tcDtx1RGBA;
-  fUncompressed     := tfRGB5A1;
+  fUncompressed     := tfRGB5A1us1;
   fPixelSize        := 0.5;
   fIsCompressed     := true;
   fglFormat         := GL_COMPRESSED_RGBA;
@@ -4100,7 +4273,7 @@ begin
   fFormat           := tfS3tcDtx3RGBA;
   fWithAlpha        := tfS3tcDtx3RGBA;
   fOpenGLFormat     := tfS3tcDtx3RGBA;
-  fUncompressed     := tfRGBA8;
+  fUncompressed     := tfRGBA8ub4;
   fPixelSize        := 1.0;
   fIsCompressed     := true;
   fglFormat         := GL_COMPRESSED_RGBA;
@@ -4127,7 +4300,7 @@ begin
   fFormat           := tfS3tcDtx3RGBA;
   fWithAlpha        := tfS3tcDtx3RGBA;
   fOpenGLFormat     := tfS3tcDtx3RGBA;
-  fUncompressed     := tfRGBA8;
+  fUncompressed     := tfRGBA8ub4;
   fPixelSize        := 1.0;
   fIsCompressed     := true;
   fglFormat         := GL_COMPRESSED_RGBA;
@@ -4181,6 +4354,32 @@ begin
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+class function TFormatDescriptor.GetFromMask(const aMask: TglBitmapMask; const aBitCount: Integer): TFormatDescriptor;
+var
+  ft: TglBitmapFormat;
+begin
+  // find matching format with OpenGL support
+  for ft := High(TglBitmapFormat) downto Low(TglBitmapFormat) do begin
+    result := Get(ft);
+    if (result.MaskMatch(aMask))      and
+       (result.glFormat <> 0)         and
+       (result.glInternalFormat <> 0) and
+       ((aBitCount = 0) or (aBitCount = 8 * result.PixelSize))
+    then
+      exit;
+  end;
+
+  // find matching format without OpenGL Support
+  for ft := High(TglBitmapFormat) downto Low(TglBitmapFormat) do begin
+    result := Get(ft);
+    if result.MaskMatch(aMask) and ((aBitCount = 0) or (aBitCount = 8 * result.PixelSize)) then
+      exit;
+  end;
+
+  result := FormatDescriptors[tfEmpty];
+end;
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 class procedure TFormatDescriptor.Clear;
 var
   f: TglBitmapFormat;
@@ -4299,114 +4498,55 @@ procedure TbmpColorTableFormat.CreateColorTable;
 var
   i: Integer;
 begin
-  if not (Format in [tfLuminance4, tfLuminance8, tfR3G3B2]) then
-    raise EglBitmap.Create(UNSUPPORTED_FORMAT);
-
-  if (Format = tfLuminance4) then
-    SetLength(fColorTable, 16)
-  else
-    SetLength(fColorTable, 256);
-
-  case Format of
-    tfLuminance4: begin
-      for i := 0 to High(fColorTable) do begin
-        fColorTable[i].r := 16 * i;
-        fColorTable[i].g := 16 * i;
-        fColorTable[i].b := 16 * i;
-        fColorTable[i].a := 0;
-      end;
-    end;
-
-    tfLuminance8: begin
-      for i := 0 to High(fColorTable) do begin
-        fColorTable[i].r := i;
-        fColorTable[i].g := i;
-        fColorTable[i].b := i;
-        fColorTable[i].a := 0;
-      end;
+  SetLength(fColorTable, 256);
+  if (fRange.r = fRange.g) and (fRange.g = fRange.b) and (fRange.r = 0) then begin
+    // alpha
+    for i := 0 to High(fColorTable) do begin
+      fColorTable[i].r := Round(((i shr Shift.a) and Range.a) / Range.a * 255);
+      fColorTable[i].g := Round(((i shr Shift.a) and Range.a) / Range.a * 255);
+      fColorTable[i].b := Round(((i shr Shift.a) and Range.a) / Range.a * 255);
+      fColorTable[i].a := 0;
     end;
-
-    tfR3G3B2: begin
-      for i := 0 to High(fColorTable) do begin
-        fColorTable[i].r := Round(((i shr Shift.r) and Range.r) / Range.r * 255);
-        fColorTable[i].g := Round(((i shr Shift.g) and Range.g) / Range.g * 255);
-        fColorTable[i].b := Round(((i shr Shift.b) and Range.b) / Range.b * 255);
-        fColorTable[i].a := 0;
-      end;
+  end else begin
+    // normal
+    for i := 0 to High(fColorTable) do begin
+      fColorTable[i].r := Round(((i shr Shift.r) and Range.r) / Range.r * 255);
+      fColorTable[i].g := Round(((i shr Shift.g) and Range.g) / Range.g * 255);
+      fColorTable[i].b := Round(((i shr Shift.b) and Range.b) / Range.b * 255);
+      fColorTable[i].a := 0;
     end;
   end;
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 procedure TbmpColorTableFormat.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer);
-var
-  d: Byte;
 begin
-  if not (Format in [tfLuminance4, tfLuminance8, tfR3G3B2]) then
-    raise EglBitmap.Create(UNSUPPORTED_FORMAT);
-
-  case Format of
-    tfLuminance4: begin
-      if (aMapData = nil) then
-        aData^ := 0;
-      d := LuminanceWeight(aPixel) and Range.r;
-      aData^ := aData^ or (d shl (4 - {%H-}PtrUInt(aMapData)));
-      inc(PByte(aMapData), 4);
-      if ({%H-}PtrUInt(aMapData) >= 8) then begin
-        inc(aData);
-        aMapData := nil;
-      end;
-    end;
-
-    tfLuminance8: begin
-      aData^ := LuminanceWeight(aPixel) and Range.r;
-      inc(aData);
-    end;
-
-    tfR3G3B2: begin
-      aData^ := Round(
-        ((aPixel.Data.r and Range.r) shl Shift.r) or
-        ((aPixel.Data.g and Range.g) shl Shift.g) or
-        ((aPixel.Data.b and Range.b) shl Shift.b));
-      inc(aData);
-    end;
-  end;
+  if (fPixelSize <> 1.0) then
+    raise EglBitmapUnsupportedFormat.Create('color table are only supported for 8bit formats');
+  if (fRange.r = fRange.g) and (fRange.g = fRange.b) and (fRange.r = 0) then
+    // alpha
+    aData^ := aPixel.Data.a
+  else
+    // normal
+    aData^ := Round(
+      ((aPixel.Data.r and Range.r) shl Shift.r) or
+      ((aPixel.Data.g and Range.g) shl Shift.g) or
+      ((aPixel.Data.b and Range.b) shl Shift.b));
+  inc(aData);
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 procedure TbmpColorTableFormat.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer);
-var
-  idx: QWord;
-  s: Integer;
-  bits: Byte;
-  f: Single;
 begin
-  s    := Trunc(fPixelSize);
-  f    := fPixelSize - s;
-  bits := Round(8 * f);
-  case s of
-    0: idx :=          (aData^ shr (8 - bits - {%H-}PtrInt(aMapData))) and ((1 shl bits) - 1);
-    1: idx :=           aData^;
-    2: idx :=     PWord(aData)^;
-    4: idx := PCardinal(aData)^;
-    8: idx :=    PQWord(aData)^;
-  else
-    raise EglBitmap.CreateFmt('invalid pixel size: %.3f', [fPixelSize]);
-  end;
-  if (idx >= Length(fColorTable)) then
-    raise EglBitmap.CreateFmt('invalid color index: %d', [idx]);
-  with fColorTable[idx] do begin
+  if (fPixelSize <> 1.0) then
+    raise EglBitmapUnsupportedFormat.Create('color table are only supported for 8bit formats');
+  with fColorTable[aData^] do begin
     aPixel.Data.r := r;
     aPixel.Data.g := g;
     aPixel.Data.b := b;
     aPixel.Data.a := a;
   end;
-  inc(PByte(aMapData), bits);
-  if ({%H-}PtrUInt(aMapData) >= 8) then begin
-    inc(aData, 1);
-    dec(PByte(aMapData), 8);
-  end;
-  inc(aData, s);
+  inc(aData, 1);
 end;
 
 destructor TbmpColorTableFormat.Destroy;
@@ -5094,7 +5234,8 @@ var
   pSource, pData, pTempData: PByte;
   Row, RowSize, TempWidth, TempHeight: Integer;
   IntFormat: TglBitmapFormat;
-  FormatDesc: TFormatDescriptor;
+  fd: TFormatDescriptor;
+  Mask: TglBitmapMask;
 
   function GetRowPointer(Row: Integer): pByte;
   begin
@@ -5106,18 +5247,19 @@ begin
   result := false;
   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;
+      Mask.r := RMask;
+      Mask.g := GMask;
+      Mask.b := BMask;
+      Mask.a := AMask;
+      IntFormat := TFormatDescriptor.GetFromMask(Mask).Format;
       if (IntFormat = tfEmpty) then
-        raise EglBitmapException.Create('AssignFromSurface - Invalid Pixelformat.');
+        raise EglBitmap.Create('AssignFromSurface - Invalid Pixelformat.');
     end;
 
+    fd := TFormatDescriptor.Get(IntFormat);
     TempWidth  := aSurface^.w;
     TempHeight := aSurface^.h;
-    RowSize := FormatDesc.GetSize(TempWidth, 1);
+    RowSize := fd.GetSize(TempWidth, 1);
     GetMem(pData, TempHeight * RowSize);
     try
       pTempData := pData;
@@ -5153,14 +5295,14 @@ var
 begin
   result := false;
   if Assigned(Data) then begin
-    if Format in [tfAlpha8, tfLuminance8Alpha8, tfBGRA8, tfRGBA8] then begin
+    if Format in [tfAlpha8ub1, tfLuminance8Alpha8ub2, tfBGRA8ub4, tfRGBA8ub4] then begin
       aSurface := SDL_CreateRGBSurface(SDL_SWSURFACE, Width, Height, 8, $FF, $FF, $FF, 0);
 
       AlphaInterleave := 0;
       case Format of
-        tfLuminance8Alpha8:
+        tfLuminance8Alpha8ub2:
           AlphaInterleave := 1;
-        tfBGRA8, tfRGBA8:
+        tfBGRA8ub4, tfRGBA8ub4:
           AlphaInterleave := 3;
       end;
 
@@ -5231,17 +5373,17 @@ begin
       aBitmap.Height := Height;
 
       case Format of
-        tfAlpha8, tfLuminance8: begin
+        tfAlpha8ub1, tfLuminance8ub1: begin
           aBitmap.PixelFormat := pf8bit;
           aBitmap.Palette     := CreateGrayPalette;
         end;
-        tfRGB5A1:
+        tfRGB5A1us1:
           aBitmap.PixelFormat := pf15bit;
-        tfR5G6B5:
+        tfR5G6B5us1:
           aBitmap.PixelFormat := pf16bit;
-        tfRGB8, tfBGR8:
+        tfRGB8ub3, tfBGR8ub3:
           aBitmap.PixelFormat := pf24bit;
-        tfRGBA8, tfBGRA8:
+        tfRGBA8ub4, tfBGRA8ub4:
           aBitmap.PixelFormat := pf32bit;
       else
         raise EglBitmap.Create('AssignToBitmap - Invalid Pixelformat.');
@@ -5252,8 +5394,8 @@ begin
         pData := aBitmap.Scanline[Row];
         Move(pSource^, pData^, fRowSize);
         Inc(pSource, fRowSize);
-        if (Format in [tfRGB8, tfRGBA8]) then        // swap RGB(A) to BGR(A)
-          SwapRGB(pData, FileWidth, Format = tfRGBA8);
+        if (Format in [tfRGB8ub3, tfRGBA8ub4]) then        // swap RGB(A) to BGR(A)
+          SwapRGB(pData, FileWidth, Format = tfRGBA8ub4);
       end;
       result := true;
     end;
@@ -5272,15 +5414,15 @@ begin
   if (Assigned(aBitmap)) then begin
     case aBitmap.PixelFormat of
       pf8bit:
-        IntFormat := tfLuminance8;
+        IntFormat := tfLuminance8ub1;
       pf15bit:
-        IntFormat := tfRGB5A1;
+        IntFormat := tfRGB5A1us1;
       pf16bit:
-        IntFormat := tfR5G6B5;
+        IntFormat := tfR5G6B5us1;
       pf24bit:
-        IntFormat := tfBGR8;
+        IntFormat := tfBGR8ub3;
       pf32bit:
-        IntFormat := tfBGRA8;
+        IntFormat := tfBGRA8ub4;
     else
       raise EglBitmap.Create('AssignFromBitmap - Invalid Pixelformat.');
     end;
@@ -5317,7 +5459,7 @@ begin
   result := false;
 
   if Assigned(Data) then begin
-    if (Format in [tfAlpha8, tfLuminance8Alpha8, tfRGBA8, tfBGRA8]) then begin
+    if (Format in [tfAlpha8ub1, tfLuminance8Alpha8ub2, tfRGBA8ub4, tfBGRA8ub4]) then begin
       if Assigned(aBitmap) then begin
         aBitmap.PixelFormat := pf8bit;
         aBitmap.Palette     := CreateGrayPalette;
@@ -5325,9 +5467,9 @@ begin
         aBitmap.Height      := Height;
 
         case Format of
-          tfLuminance8Alpha8:
+          tfLuminance8Alpha8ub2:
             AlphaInterleave := 1;
-          tfRGBA8, tfBGRA8:
+          tfRGBA8ub4, tfBGRA8ub4:
             AlphaInterleave := 3;
           else
             AlphaInterleave := 0;
@@ -5375,6 +5517,9 @@ var
   rid: TRawImageDescription;
   FormatDesc: TFormatDescriptor;
 begin
+  if not Assigned(Data) then
+    raise EglBitmap.Create('no pixel data assigned. load data before save');
+
   result := false;
   if not Assigned(aImage) or (Format = tfEmpty) then
     exit;
@@ -5383,10 +5528,7 @@ begin
     exit;
 
   FillChar(rid{%H-}, SizeOf(rid), 0);
-  if (Format in [
-       tfAlpha4, tfAlpha8, tfAlpha16,
-       tfLuminance4, tfLuminance8, tfLuminance16,
-       tfLuminance4Alpha4, tfLuminance8Alpha8, tfLuminance12Alpha4, tfLuminance16Alpha16]) then
+  if FormatDesc.IsGrayscale then
     rid.Format := ricfGray
   else
     rid.Format := ricfRGBA;
@@ -5414,6 +5556,8 @@ begin
   aImage.DataDescription := rid;
   aImage.CreateData;
 
+  if not Assigned(aImage.PixelData) then
+    raise EglBitmap.Create('error while creating LazIntfImage');
   Move(Data^, aImage.PixelData^, FormatDesc.GetSize(Dimension));
 
   result := true;
@@ -5427,6 +5571,7 @@ var
   ImageData: PByte;
   ImageSize: Integer;
   CanCopy: Boolean;
+  Mask: TglBitmapMask;
 
   procedure CopyConvert;
   var
@@ -5466,17 +5611,15 @@ begin
   result := false;
   if not Assigned(aImage) then
     exit;
-  for f := High(f) downto Low(f) do begin
-    FormatDesc := TFormatDescriptor.Get(f);
-    with aImage.DataDescription do
-      if FormatDesc.MaskMatch(
-        (QWord(1 shl RedPrec  )-1) shl RedShift,
-        (QWord(1 shl GreenPrec)-1) shl GreenShift,
-        (QWord(1 shl BluePrec )-1) shl BlueShift,
-        (QWord(1 shl AlphaPrec)-1) shl AlphaShift) then
-        break;
-  end;
 
+  with aImage.DataDescription do begin
+    Mask.r := (QWord(1 shl RedPrec  )-1) shl RedShift;
+    Mask.g := (QWord(1 shl GreenPrec)-1) shl GreenShift;
+    Mask.b := (QWord(1 shl BluePrec )-1) shl BlueShift;
+    Mask.a := (QWord(1 shl AlphaPrec)-1) shl AlphaShift;
+  end;
+  FormatDesc := TFormatDescriptor.GetFromMask(Mask);
+  f          := FormatDesc.Format;
   if (f = tfEmpty) then
     exit;
 
@@ -6340,13 +6483,13 @@ begin
       // format
       case png_get_color_type(png, png_info) of
         PNG_COLOR_TYPE_GRAY:
-          Format := tfLuminance8;
+          Format := tfLuminance8ub1;
         PNG_COLOR_TYPE_GRAY_ALPHA:
-          Format := tfLuminance8Alpha8;
+          Format := tfLuminance8Alpha8us1;
         PNG_COLOR_TYPE_RGB:
-          Format := tfRGB8;
+          Format := tfRGB8ub3;
         PNG_COLOR_TYPE_RGB_ALPHA:
-          Format := tfRGBA8;
+          Format := tfRGBA8ub4;
         else
           raise EglBitmapException.Create ('LoadPng - Unsupported Colortype found.');
       end;
@@ -6425,13 +6568,13 @@ begin
 
       case Png.Header.ColorType of
         COLOR_GRAYSCALE:
-          PngFormat := tfLuminance8;
+          PngFormat := tfLuminance8ub1;
         COLOR_GRAYSCALEALPHA:
-          PngFormat := tfLuminance8Alpha8;
+          PngFormat := tfLuminance8Alpha8us1;
         COLOR_RGB:
-          PngFormat := tfBGR8;
+          PngFormat := tfBGR8ub3;
         COLOR_RGBALPHA:
-          PngFormat := tfBGRA8;
+          PngFormat := tfBGRA8ub4;
         else
           raise EglBitmapException.Create ('LoadPng - Unsupported Colortype found.');
       end;
@@ -6542,13 +6685,13 @@ begin
 
   try
     case Format of
-      tfAlpha8, tfLuminance8:
+      tfAlpha8ub1, tfLuminance8ub1:
         ColorType := PNG_COLOR_TYPE_GRAY;
-      tfLuminance8Alpha8:
+      tfLuminance8Alpha8us1:
         ColorType := PNG_COLOR_TYPE_GRAY_ALPHA;
-      tfBGR8, tfRGB8:
+      tfBGR8ub3, tfRGB8ub3:
         ColorType := PNG_COLOR_TYPE_RGB;
-      tfBGRA8, tfRGBA8:
+      tfBGRA8ub4, tfRGBA8ub4:
         ColorType := PNG_COLOR_TYPE_RGBA;
       else
         raise EglBitmapUnsupportedFormat.Create(Format);
@@ -6583,7 +6726,7 @@ begin
       // set compression
       png_set_compression_level(png, 6);
 
-      if Format in [tfBGR8, tfBGRA8] then
+      if Format in [tfBGR8ub3, tfBGRA8ub4] 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);
@@ -6617,22 +6760,22 @@ begin
     raise EglBitmapUnsupportedFormat.Create(Format);
 
   case Format of
-    tfAlpha8, tfLuminance8: begin
+    tfAlpha8ub1, tfLuminance8ub1: begin
       ColorType := COLOR_GRAYSCALE;
       PixSize   := 1;
       Alpha     := false;
     end;
-    tfLuminance8Alpha8: begin
+    tfLuminance8Alpha8us1: begin
       ColorType := COLOR_GRAYSCALEALPHA;
       PixSize   := 1;
       Alpha     := true;
     end;
-    tfBGR8, tfRGB8: begin
+    tfBGR8ub3, tfRGB8ub3: begin
       ColorType := COLOR_RGB;
       PixSize   := 3;
       Alpha     := false;
     end;
-    tfBGRA8, tfRGBA8: begin
+    tfBGRA8ub4, tfRGBA8ub4: begin
       ColorType := COLOR_RGBALPHA;
       PixSize   := 3;
       Alpha     := true
@@ -6658,7 +6801,7 @@ begin
       end;
 
       // convert RGB line to BGR
-      if Format in [tfRGB8, tfRGBA8] then begin
+      if Format in [tfRGB8ub3, tfRGBA8ub4] then begin
         pTemp := png.ScanLine[Y];
         for X := 0 to Width -1 do begin
           Temp := pByteArray(pTemp)^[0];
@@ -6948,11 +7091,11 @@ begin
         JCS_GRAYSCALE:
           begin
             jpeg.out_color_space := JCS_GRAYSCALE;
-            IntFormat := tfLuminance8;
+            IntFormat := tfLuminance8ub1;
           end;
         else
           jpeg.out_color_space := JCS_RGB;
-          IntFormat := tfRGB8;
+          IntFormat := tfRGB8ub3;
       end;
 
       // reading image
@@ -7113,11 +7256,11 @@ begin
     jpeg.image_width  := Width;
     jpeg.image_height := Height;
     case Format of
-      tfAlpha8, tfLuminance8: begin
+      tfAlpha8ub1, tfLuminance8ub1: begin
         jpeg.input_components := 1;
         jpeg.in_color_space   := JCS_GRAYSCALE;
       end;
-      tfRGB8, tfBGR8: begin
+      tfRGB8ub3, tfBGR8ub3: begin
         jpeg.input_components := 3;
         jpeg.in_color_space   := JCS_RGB;
       end;
@@ -7128,7 +7271,7 @@ begin
     jpeg_start_compress(@jpeg, true);
     pTemp := Data;
 
-    if Format = tfBGR8 then
+    if Format = tfBGR8ub3 then
       GetMem(pTemp2, fRowSize)
     else
       pTemp2 := pTemp;
@@ -7136,7 +7279,7 @@ begin
     try
       for Row := 0 to jpeg.image_height -1 do begin
         // prepare row
-        if Format = tfBGR8 then
+        if Format = tfBGR8ub3 then
           CopyRow(pTemp2, pTemp)
         else
           pTemp2 := pTemp;
@@ -7147,7 +7290,7 @@ begin
       end;
     finally
       // free memory
-      if Format = tfBGR8 then
+      if Format = tfBGR8ub3 then
         FreeMem(pTemp2);
     end;
     jpeg_finish_compress(@jpeg);
@@ -7172,7 +7315,7 @@ begin
     Jpg := TJPEGImage.Create;
     try
       AssignToBitmap(Bmp);
-      if (Format in [tfAlpha8, tfLuminance8]) then begin
+      if (Format in [tfAlpha8ub1, tfLuminance8ub1]) then begin
         Jpg.Grayscale   := true;
         Jpg.PixelFormat := jf8Bit;
       end;
@@ -7226,7 +7369,7 @@ type
 function TglBitmap.LoadBMP(const aStream: TStream): Boolean;
 
   //////////////////////////////////////////////////////////////////////////////////////////////////
-  function ReadInfo(out aInfo: TBMPInfo; out aMask: TglBitmapColorRec): TglBitmapFormat;
+  function ReadInfo(out aInfo: TBMPInfo; out aMask: TglBitmapMask): TglBitmapFormat;
   begin
     result := tfEmpty;
     aStream.Read(aInfo{%H-}, SizeOf(aInfo));
@@ -7251,10 +7394,10 @@ function TglBitmap.LoadBMP(const aStream: TStream): Boolean;
 
     //get suitable format
     case aInfo.biBitCount of
-       8: result := tfLuminance8;
-      16: result := tfX1RGB5;
-      24: result := tfRGB8;
-      32: result := tfXRGB8;
+       8: result := tfLuminance8ub1;
+      16: result := tfX1RGB5us1;
+      24: result := tfBGR8ub3;
+      32: result := tfXRGB8ui1;
     end;
   end;
 
@@ -7266,7 +7409,7 @@ function TglBitmap.LoadBMP(const aStream: TStream): Boolean;
     result := nil;
     if (aInfo.biBitCount >= 16) then
       exit;
-    aFormat := tfLuminance8;
+    aFormat := tfLuminance8ub1;
     c := aInfo.biClrUsed;
     if (c = 0) then
       c := 1 shl aInfo.biBitCount;
@@ -7274,7 +7417,7 @@ function TglBitmap.LoadBMP(const aStream: TStream): Boolean;
     for i := 0 to c-1 do begin
       aStream.Read(ColorTable[i], SizeOf(TbmpColorTableEnty));
       if (ColorTable[i].r <> ColorTable[i].g) or (ColorTable[i].g <> ColorTable[i].b) then
-        aFormat := tfRGB8;
+        aFormat := tfRGB8ub3;
     end;
 
     result := TbmpColorTableFormat.Create;
@@ -7284,22 +7427,16 @@ function TglBitmap.LoadBMP(const aStream: TStream): Boolean;
   end;
 
   //////////////////////////////////////////////////////////////////////////////////////////////////
-  function CheckBitfields(var aFormat: TglBitmapFormat; const aMask: TglBitmapColorRec;
-    const aInfo: TBMPInfo): TbmpBitfieldFormat;
+  function CheckBitfields(var aFormat: TglBitmapFormat; const aMask: TglBitmapMask; const aInfo: TBMPInfo): TbmpBitfieldFormat;
   var
-    TmpFormat: TglBitmapFormat;
     FormatDesc: TFormatDescriptor;
   begin
     result := nil;
     if (aMask.r <> 0) or (aMask.g <> 0) or (aMask.b <> 0) or (aMask.a <> 0) then begin
-      for TmpFormat := High(TglBitmapFormat) downto Low(TglBitmapFormat) do begin
-        FormatDesc := TFormatDescriptor.Get(TmpFormat);
-        if FormatDesc.MaskMatch(aMask.r, aMask.g, aMask.b, aMask.a) then begin
-          aFormat := FormatDesc.Format;
-          exit;
-        end;
-      end;
-
+      FormatDesc := TFormatDescriptor.GetFromMask(aMask);
+      if (FormatDesc.Format = tfEmpty) then
+        exit;
+      aFormat := FormatDesc.Format;
       if (aMask.a = 0) and TFormatDescriptor.Get(aFormat).HasAlpha then
         aFormat := TFormatDescriptor.Get(aFormat).WithoutAlpha;
       if (aMask.a <> 0) and not TFormatDescriptor.Get(aFormat).HasAlpha then
@@ -7324,7 +7461,7 @@ var
   BmpFormat: TglBitmapFormat;
 
   //records
-  Mask: TglBitmapColorRec;
+  Mask: TglBitmapMask;
   Header: TBMPHeader;
   Info: TBMPInfo;
 
@@ -7472,50 +7609,39 @@ begin
 
   try
     case Format of
-      tfLuminance4: begin
-        Info.biBitCount  := 4;
-        Header.bfSize    := Header.bfSize    + 16 * SizeOf(Cardinal);
-        Header.bfOffBits := Header.bfOffBits + 16 * SizeOf(Cardinal); //16 ColorTable entries
-        Converter := TbmpColorTableFormat.Create;
-        with (Converter as TbmpColorTableFormat) do begin
-          PixelSize := 0.5;
-          Format    := Format;
-          Range     := glBitmapColorRec($F, $F, $F, $0);
-          CreateColorTable;
-        end;
-      end;
-
-      tfR3G3B2, tfLuminance8: begin
+      tfAlpha4ub1, tfAlpha8ub1, tfLuminance4ub1, tfLuminance8ub1, tfR3G3B2ub1:
+      begin
         Info.biBitCount  :=  8;
         Header.bfSize    := Header.bfSize    + 256 * SizeOf(Cardinal);
         Header.bfOffBits := Header.bfOffBits + 256 * SizeOf(Cardinal); //256 ColorTable entries
         Converter := TbmpColorTableFormat.Create;
         with (Converter as TbmpColorTableFormat) do begin
           PixelSize := 1;
-          Format    := Format;
-          if (Format = tfR3G3B2) then begin
-            Range := glBitmapColorRec($7, $7, $3, $0);
-            Shift := glBitmapShiftRec(0, 3, 6, 0);
-          end else
-            Range := glBitmapColorRec($FF, $FF, $FF, $0);
+          Format    := fFormat;
+          Range     := FormatDesc.Range;
+          Shift     := FormatDesc.Shift;
           CreateColorTable;
         end;
       end;
 
-      tfRGBX4, tfXRGB4, tfRGB5X1, tfX1RGB5, tfR5G6B5, tfRGB5A1, tfA1RGB5, tfRGBA4, tfARGB4,
-      tfBGRX4, tfXBGR4, tfBGR5X1, tfX1BGR5, tfB5G6R5, tfBGR5A1, tfA1BGR5, tfBGRA4, tfABGR4: begin
+      tfLuminance4Alpha4ub2, tfLuminance6Alpha2ub2, tfLuminance8Alpha8ub2,
+      tfRGBX4us1, tfXRGB4us1, tfRGB5X1us1, tfX1RGB5us1, tfR5G6B5us1, tfRGB5A1us1, tfA1RGB5us1, tfRGBA4us1, tfARGB4us1,
+      tfBGRX4us1, tfXBGR4us1, tfBGR5X1us1, tfX1BGR5us1, tfB5G6R5us1, tfBGR5A1us1, tfA1BGR5us1, tfBGRA4us1, tfABGR4us1:
+      begin
         Info.biBitCount    := 16;
         Info.biCompression := BMP_COMP_BITFIELDS;
       end;
 
-      tfBGR8, tfRGB8: begin
+      tfBGR8ub3, tfRGB8ub3:
+      begin
         Info.biBitCount := 24;
-        if (Format = tfRGB8) then
-          Converter := TfdBGR8.Create; //use BGR8 Format Descriptor to Swap RGB Values
+        if (Format = tfRGB8ub3) then
+          Converter := TfdBGR8ub3.Create; //use BGR8 Format Descriptor to Swap RGB Values
       end;
 
-      tfRGB10X2, tfX2RGB10, tfRGB10A2, tfA2RGB10, tfRGBA8, tfARGB8,
-      tfBGR10X2, tfX2BGR10, tfBGR10A2, tfA2BGR10, tfBGRA8, tfABGR8: begin
+      tfRGBX8ui1, tfXRGB8ui1, tfRGB10X2ui1, tfX2RGB10ui1, tfRGBA8ui1, tfARGB8ui1, tfRGBA8ub4, tfRGB10A2ui1, tfA2RGB10ui1,
+      tfBGRX8ui1, tfXBGR8ui1, tfBGR10X2ui1, tfX2BGR10ui1, tfBGRA8ui1, tfABGR8ui1, tfBGRA8ub4, tfBGR10A2ui1, tfA2BGR10ui1:
+      begin
         Info.biBitCount    := 32;
         Info.biCompression := BMP_COMP_BITFIELDS;
       end;
@@ -7835,26 +7961,29 @@ begin
       tgaFormat := tfEmpty;
       case Header.Bpp of
          8: if IsGrayFormat then case (Header.ImageDesc and $F) of
-               0: tgaFormat := tfLuminance8;
-               8: tgaFormat := tfAlpha8;
+               0: tgaFormat := tfLuminance8ub1;
+               8: tgaFormat := tfAlpha8ub1;
             end;
 
         16: if IsGrayFormat then case (Header.ImageDesc and $F) of
-               0: tgaFormat := tfLuminance16;
-               8: tgaFormat := tfLuminance8Alpha8;
+               0: tgaFormat := tfLuminance16us1;
+               8: tgaFormat := tfLuminance8Alpha8ub2;
             end else case (Header.ImageDesc and $F) of
-               0: tgaFormat := tfX1RGB5;
-               1: tgaFormat := tfA1RGB5;
-               4: tgaFormat := tfARGB4;
+               0: tgaFormat := tfX1RGB5us1;
+               1: tgaFormat := tfA1RGB5us1;
+               4: tgaFormat := tfARGB4us1;
             end;
 
         24: if not IsGrayFormat then case (Header.ImageDesc and $F) of
-               0: tgaFormat := tfRGB8;
+               0: tgaFormat := tfBGR8ub3;
             end;
 
-        32: if not IsGrayFormat then case (Header.ImageDesc and $F) of
-               2: tgaFormat := tfA2RGB10;
-               8: tgaFormat := tfARGB8;
+        32: if IsGrayFormat then case (Header.ImageDesc and $F) of
+               0: tgaFormat := tfDepth32ui1;
+            end else case (Header.ImageDesc and $F) of
+               0: tgaFormat := tfX2RGB10ui1;
+               2: tgaFormat := tfA2RGB10ui1;
+               8: tgaFormat := tfARGB8ui1;
             end;
       end;
 
@@ -7915,89 +8044,29 @@ end;
 procedure TglBitmap.SaveTGA(const aStream: TStream);
 var
   Header: TTGAHeader;
-  LineSize, Size, x, y: Integer;
-  Pixel: TglBitmapPixelData;
-  LineBuf, SourceData, DestData: PByte;
-  SourceMD, DestMD: Pointer;
+  Size: Integer;
   FormatDesc: TFormatDescriptor;
-  Converter: TFormatDescriptor;
 begin
   if not (ftTGA in FormatGetSupportedFiles(Format)) then
     raise EglBitmapUnsupportedFormat.Create(Format);
 
   //prepare header
+  FormatDesc := TFormatDescriptor.Get(Format);
   FillChar(Header{%H-}, SizeOf(Header), 0);
-
-  //set ImageType
-  if (Format in [tfLuminance8, tfLuminance6Alpha2, tfLuminance4Alpha4, tfAlpha8,
-                 tfLuminance16, tfLuminance12Alpha4, tfLuminance8Alpha8]) then
-    Header.ImageType := TGA_UNCOMPRESSED_GRAY
-  else
-    Header.ImageType := TGA_UNCOMPRESSED_RGB;
-
-  //set BitsPerPixel
-  if (Format in [tfLuminance8, tfLuminance6Alpha2, tfLuminance4Alpha4, tfAlpha8]) then
-    Header.Bpp := 8
-  else if (Format in [tfLuminance16, tfLuminance12Alpha4, tfLuminance8Alpha8,
-                      tfRGB5X1, tfBGR5X1, tfRGB5A1, tfBGR5A1, tfRGBA4, tfBGRA4]) then
-    Header.Bpp := 16
-  else if (Format in [tfBGR8, tfRGB8]) then
-    Header.Bpp := 24
-  else
-    Header.Bpp := 32;
-
-  //set AlphaBitCount
-  case Format of
-    tfRGB5A1, tfBGR5A1:
-      Header.ImageDesc := 1 and $F;
-    tfRGB10A2, tfBGR10A2:
-      Header.ImageDesc := 2 and $F;
-    tfRGBA4, tfBGRA4:
-      Header.ImageDesc := 4 and $F;
-    tfAlpha8, tfLuminance8Alpha8, tfRGBA8, tfBGRA8:
-      Header.ImageDesc := 8 and $F;
-  end;
-
+  Header.ImageDesc := CountSetBits(FormatDesc.Range.a) and $F;
+  Header.Bpp       := Trunc(8 * FormatDesc.PixelSize);
   Header.Width     := Width;
   Header.Height    := Height;
   Header.ImageDesc := Header.ImageDesc or $20; //flip y
+  if FormatDesc.IsGrayscale or (not FormatDesc.IsGrayscale and not FormatDesc.HasRed and FormatDesc.HasAlpha) then
+    Header.ImageType := TGA_UNCOMPRESSED_GRAY
+  else
+    Header.ImageType := TGA_UNCOMPRESSED_RGB;
   aStream.Write(Header, SizeOf(Header));
 
-  // convert RGB(A) to BGR(A)
-  Converter  := nil;
-  FormatDesc := TFormatDescriptor.Get(Format);
-  Size       := FormatDesc.GetSize(Dimension);
-  if Format in [tfRGB5X1, tfRGB5A1, tfRGBA4, tfRGB8, tfRGB10A2, tfRGBA8] then begin
-    if (FormatDesc.RGBInverted = tfEmpty) then
-      raise EglBitmap.Create('inverted RGB format is empty');
-    Converter := TFormatDescriptor.Get(FormatDesc.RGBInverted);
-    if not glBitmapColorRecCmp(Converter.Range, FormatDesc.Range) or
-       (Converter.PixelSize <> FormatDesc.PixelSize) then
-      raise EglBitmap.Create('invalid inverted RGB format');
-  end;
-
-  if Assigned(Converter) then begin
-    LineSize := FormatDesc.GetSize(Width, 1);
-    GetMem(LineBuf, LineSize);
-    SourceMD := FormatDesc.CreateMappingData;
-    DestMD   := Converter.CreateMappingData;
-    try
-      SourceData := Data;
-      for y := 0 to Height-1 do begin
-        DestData := LineBuf;
-        for x := 0 to Width-1 do begin
-          FormatDesc.Unmap(SourceData, Pixel, SourceMD);
-          Converter.Map(Pixel, DestData, DestMD);
-        end;
-        aStream.Write(LineBuf^, LineSize);
-      end;
-    finally
-      FreeMem(LineBuf);
-      FormatDesc.FreeMappingData(SourceMD);
-      FormatDesc.FreeMappingData(DestMD);
-    end;
-  end else
-    aStream.Write(Data^, Size);
+  // write Data
+  Size := FormatDesc.GetSize(Dimension);
+  aStream.Write(Data^, Size);
 end;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -8072,6 +8141,7 @@ var
   var
     fd: TFormatDescriptor;
     i: Integer;
+    Mask: TglBitmapMask;
     Range: TglBitmapColorRec;
     match: Boolean;
   begin
@@ -8084,32 +8154,31 @@ var
           D3DFMT_DXT3: result := tfS3tcDtx3RGBA;
           D3DFMT_DXT5: result := tfS3tcDtx5RGBA;
         end;
-      end else if ((dwFlags and (DDPF_RGB or DDPF_ALPHAPIXELS or DDPF_LUMINANCE)) > 0) then begin
+      end else if ((dwFlags and (DDPF_RGB or DDPF_ALPHAPIXELS or DDPF_LUMINANCE or DDPF_ALPHA)) > 0) then begin
         // prepare masks
         if ((dwFlags and DDPF_LUMINANCE) = 0) then begin
-          Range.r := dwRBitMask;
-          Range.g := dwGBitMask;
-          Range.b := dwBBitMask;
+          Mask.r := dwRBitMask;
+          Mask.g := dwGBitMask;
+          Mask.b := dwBBitMask;
         end else begin
-          Range.r := dwRBitMask;
-          Range.g := dwRBitMask;
-          Range.b := dwRBitMask;
+          Mask.r := dwRBitMask;
+          Mask.g := dwRBitMask;
+          Mask.b := dwRBitMask;
         end;
-        Range.a := dwABitMask;
+        if (dwFlags and DDPF_ALPHAPIXELS > 0) then
+          Mask.a := dwABitMask
+        else
+          Mask.a := 0;;
 
         //find matching format
-        for result := High(TglBitmapFormat) downto Low(TglBitmapFormat) do begin
-          fd := TFormatDescriptor.Get(result);
-          if fd.MaskMatch(Range.r, Range.g, Range.b, Range.a) and
-             (8 * fd.PixelSize = dwRGBBitCount) then
-            exit;
-        end;
+        fd     := TFormatDescriptor.GetFromMask(Mask, dwRGBBitCount);
+        result := fd.Format;
+        if (result <> tfEmpty) then
+          exit;
 
         //find format with same Range
-        for i := 0 to 3 do begin
-          while ((Range.arr[i] and 1) = 0) and (Range.arr[i] > 0) do
-            Range.arr[i] := Range.arr[i] shr 1;
-        end;
+        for i := 0 to 3 do
+          Range.arr[i] := (2 shl CountSetBits(Mask.arr[i])) - 1;
         for result := High(TglBitmapFormat) downto Low(TglBitmapFormat) do begin
           fd := TFormatDescriptor.Get(result);
           match := true;
@@ -8125,9 +8194,9 @@ var
         //no format with same range found -> use default
         if (result = tfEmpty) then begin
           if (dwABitMask > 0) then
-            result := tfRGBA8
+            result := tfRGBA8ui1
           else
-            result := tfRGB8;
+            result := tfRGB8ub3;
         end;
 
         Converter := TbmpBitfieldFormat.Create;
@@ -8272,7 +8341,7 @@ begin
       tfS3tcDtx3RGBA: Header.PixelFormat.dwFourCC := D3DFMT_DXT3;
       tfS3tcDtx5RGBA: Header.PixelFormat.dwFourCC := D3DFMT_DXT5;
     end;
-  end else if (Format in [tfAlpha8, tfAlpha16]) then begin
+  end else if not FormatDesc.HasColor and FormatDesc.HasAlpha then begin
     Header.PixelFormat.dwFlags       := Header.PixelFormat.dwFlags or DDPF_ALPHA;
     Header.PixelFormat.dwRGBBitCount := Round(FormatDesc.PixelSize * 8);
     Header.PixelFormat.dwABitMask    := FormatDesc.AlphaMask;
@@ -9032,32 +9101,32 @@ begin
 
   // Positive X
   Rec.Func := glBitmapNormalMapPosX;
-  LoadFromFunc(SizeRec, glBitmapNormalMapFunc, tfBGR8, @Rec);
+  LoadFromFunc(SizeRec, glBitmapNormalMapFunc, tfBGR8ub3, @Rec);
   GenerateCubeMap(GL_TEXTURE_CUBE_MAP_POSITIVE_X, aTestTextureSize);
 
   // Negative X
   Rec.Func := glBitmapNormalMapNegX;
-  LoadFromFunc(SizeRec, glBitmapNormalMapFunc, tfBGR8, @Rec);
+  LoadFromFunc(SizeRec, glBitmapNormalMapFunc, tfBGR8ub3, @Rec);
   GenerateCubeMap(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, aTestTextureSize);
 
   // Positive Y
   Rec.Func := glBitmapNormalMapPosY;
-  LoadFromFunc(SizeRec, glBitmapNormalMapFunc, tfBGR8, @Rec);
+  LoadFromFunc(SizeRec, glBitmapNormalMapFunc, tfBGR8ub3, @Rec);
   GenerateCubeMap(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, aTestTextureSize);
 
   // Negative Y
   Rec.Func := glBitmapNormalMapNegY;
-  LoadFromFunc(SizeRec, glBitmapNormalMapFunc, tfBGR8, @Rec);
+  LoadFromFunc(SizeRec, glBitmapNormalMapFunc, tfBGR8ub3, @Rec);
   GenerateCubeMap(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, aTestTextureSize);
 
   // Positive Z
   Rec.Func := glBitmapNormalMapPosZ;
-  LoadFromFunc(SizeRec, glBitmapNormalMapFunc, tfBGR8, @Rec);
+  LoadFromFunc(SizeRec, glBitmapNormalMapFunc, tfBGR8ub3, @Rec);
   GenerateCubeMap(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, aTestTextureSize);
 
   // Negative Z
   Rec.Func := glBitmapNormalMapNegZ;
-  LoadFromFunc(SizeRec, glBitmapNormalMapFunc, tfBGR8, @Rec);
+  LoadFromFunc(SizeRec, glBitmapNormalMapFunc, tfBGR8ub3, @Rec);
   GenerateCubeMap(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, aTestTextureSize);
 end;