From 8b8a4ade7f33c7809f6d3e76154527bc1492e356 Mon Sep 17 00:00:00 2001 From: Bergmann89 Date: Tue, 9 Dec 2014 21:23:52 +0100 Subject: [PATCH] * refactored format descriptors --- glBitmap.pas | 1729 +++++++++++++++++++++++----------------------------------- 1 file changed, 682 insertions(+), 1047 deletions(-) diff --git a/glBitmap.pas b/glBitmap.pas index f5ba747..bde9922 100644 --- a/glBitmap.pas +++ b/glBitmap.pas @@ -885,53 +885,80 @@ type end; //////////////////////////////////////////////////////////////////////////////////////////////////// - TglBitmapColorRec = packed record + TglBitmapRec4ui = packed record case Integer of 0: (r, g, b, a: Cardinal); 1: (arr: array[0..3] of Cardinal); end; - TglBitmapMask = packed record + TglBitmapRec4ub = 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; + 0: (r, g, b, a: Byte); + 1: (arr: array[0..3] of Byte); end; - PglBitmapPixelData = ^TglBitmapPixelData; -//////////////////////////////////////////////////////////////////////////////////////////////////// - TglBitmapPixelPositionFields = set of (ffX, ffY); - TglBitmapPixelPosition = record - Fields : TglBitmapPixelPositionFields; - X : Word; - Y : Word; + TglBitmapRec4ul = packed record + case Integer of + 0: (r, g, b, a: QWord); + 1: (arr: array[0..3] of QWord); end; TglBitmapFormatDescriptor = class(TObject) + strict private + // cached properties + fBytesPerPixel: Single; + fChannelCount: Integer; + fMask: TglBitmapRec4ul; + fRange: TglBitmapRec4ui; + + function GetHasRed: Boolean; + function GetHasGreen: Boolean; + function GetHasBlue: Boolean; + function GetHasAlpha: Boolean; + function GetHasColor: Boolean; + function GetIsGrayscale: Boolean; protected - function GetIsCompressed: Boolean; virtual; abstract; - function GetHasRed: Boolean; virtual; abstract; - 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; - function GetWithoutAlpha: TglBitmapFormat; virtual; abstract; - function GetOpenGLFormat: TglBitmapFormat; virtual; abstract; - function GetUncompressed: TglBitmapFormat; virtual; abstract; - - function GetglDataFormat: GLenum; virtual; abstract; - function GetglFormat: GLenum; virtual; abstract; - function GetglInternalFormat: GLenum; virtual; abstract; + fFormat: TglBitmapFormat; + fWithAlpha: TglBitmapFormat; + fWithoutAlpha: TglBitmapFormat; + fOpenGLFormat: TglBitmapFormat; + fRGBInverted: TglBitmapFormat; + fUncompressed: TglBitmapFormat; + + fBitsPerPixel: Integer; + fIsCompressed: Boolean; + + fPrecision: TglBitmapRec4ub; + fShift: TglBitmapRec4ub; + + fglFormat: GLenum; + fglInternalFormat: GLenum; + fglDataFormat: GLenum; + + procedure SetValues; virtual; + procedure CalcValues; public - property IsCompressed: Boolean read GetIsCompressed; + property Format: TglBitmapFormat read fFormat; + property ChannelCount: Integer read fChannelCount; + property IsCompressed: Boolean read fIsCompressed; + property BitsPerPixel: Integer read fBitsPerPixel; + property BytesPerPixel: Single read fBytesPerPixel; + + property Precision: TglBitmapRec4ub read fPrecision; + property Shift: TglBitmapRec4ub read fShift; + property Range: TglBitmapRec4ui read fRange; + property Mask: TglBitmapRec4ul read fMask; + + property RGBInverted: TglBitmapFormat read fRGBInverted; + property WithAlpha: TglBitmapFormat read fWithAlpha; + property WithoutAlpha: TglBitmapFormat read fWithAlpha; + property OpenGLFormat: TglBitmapFormat read fOpenGLFormat; + property Uncompressed: TglBitmapFormat read fUncompressed; + + property glFormat: GLenum read fglFormat; + property glInternalFormat: GLenum read fglInternalFormat; + property glDataFormat: GLenum read fglDataFormat; + property HasRed: Boolean read GetHasRed; property HasGreen: Boolean read GetHasGreen; property HasBlue: Boolean read GetHasBlue; @@ -939,20 +966,27 @@ type property HasColor: Boolean read GetHasColor; property IsGrayscale: Boolean read GetIsGrayscale; - property RGBInverted: TglBitmapFormat read GetRGBInverted; - property WithAlpha: TglBitmapFormat read GetWithAlpha; - property WithoutAlpha: TglBitmapFormat read GetWithoutAlpha; - property OpenGLFormat: TglBitmapFormat read GetOpenGLFormat; - property Uncompressed: TglBitmapFormat read GetUncompressed; - - property glFormat: GLenum read GetglFormat; - property glInternalFormat: GLenum read GetglInternalFormat; - property glDataFormat: GLenum read GetglDataFormat; + constructor Create; public class function GetByFormat(const aInternalFormat: GLenum): TglBitmapFormatDescriptor; end; //////////////////////////////////////////////////////////////////////////////////////////////////// + TglBitmapPixelData = packed record + Data: TglBitmapRec4ui; + Range: TglBitmapRec4ui; + Format: TglBitmapFormat; + end; + PglBitmapPixelData = ^TglBitmapPixelData; + + TglBitmapPixelPositionFields = set of (ffX, ffY); + TglBitmapPixelPosition = record + Fields : TglBitmapPixelPositionFields; + X : Word; + Y : Word; + end; + +//////////////////////////////////////////////////////////////////////////////////////////////////// TglBitmap = class; TglBitmapFunctionRec = record Sender: TglBitmap; @@ -1256,8 +1290,10 @@ procedure glBitmapGetDefaultFilter(var aMin, aMag: Cardinal); procedure glBitmapGetDefaultTextureWrap(var S, T, R: Cardinal); function glBitmapPosition(X: Integer = -1; Y: Integer = -1): TglBitmapPixelPosition; -function glBitmapColorRec(const r, g, b, a: Cardinal): TglBitmapColorRec; -function glBitmapColorRecCmp(const r1, r2: TglBitmapColorRec): Boolean; +function glBitmapRec4ub(const r, g, b, a: Byte): TglBitmapRec4ub; +function glBitmapRec4ui(const r, g, b, a: Cardinal): TglBitmapRec4ui; +function glBitmapRec4ul(const r, g, b, a: QWord): TglBitmapRec4ul; +function glBitmapRec4uiCompare(const r1, r2: TglBitmapRec4ui): Boolean; function glBitmapCreateTestTexture(const aFormat: TglBitmapFormat): TglBitmap2D; @@ -1293,68 +1329,8 @@ type {$ENDIF} //////////////////////////////////////////////////////////////////////////////////////////////////// - TShiftRec = packed record - case Integer of - 0: (r, g, b, a: Byte); - 1: (arr: array[0..3] of Byte); - end; - TFormatDescriptor = class(TglBitmapFormatDescriptor) - private - function GetRedMask: QWord; - function GetGreenMask: QWord; - function GetBlueMask: QWord; - function GetAlphaMask: QWord; - protected - fFormat: TglBitmapFormat; - fWithAlpha: TglBitmapFormat; - fWithoutAlpha: TglBitmapFormat; - fOpenGLFormat: TglBitmapFormat; - fRGBInverted: TglBitmapFormat; - fUncompressed: TglBitmapFormat; - - fPixelSize: Single; - fIsCompressed: Boolean; - - fRange: TglBitmapColorRec; - fShift: TShiftRec; - - fglFormat: GLenum; - fglInternalFormat: GLenum; - fglDataFormat: GLenum; - - function GetIsCompressed: Boolean; override; - function GetHasRed: Boolean; override; - 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; - function GetWithoutAlpha: TglBitmapFormat; override; - function GetOpenGLFormat: TglBitmapFormat; override; - function GetUncompressed: TglBitmapFormat; override; - - function GetglFormat: GLenum; override; - function GetglInternalFormat: GLenum; override; - function GetglDataFormat: GLenum; override; - - function GetComponents: Integer; virtual; public - property Format: TglBitmapFormat read fFormat; - property Components: Integer read GetComponents; - property PixelSize: Single read fPixelSize; - - property Range: TglBitmapColorRec read fRange; - property Shift: TShiftRec read fShift; - - property RedMask: QWord read GetRedMask; - property GreenMask: QWord read GetGreenMask; - property BlueMask: QWord read GetBlueMask; - property AlphaMask: QWord read GetAlphaMask; - procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); virtual; abstract; procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); virtual; abstract; @@ -1365,17 +1341,14 @@ type procedure FreeMappingData(var aMappingData: Pointer); virtual; function IsEmpty: Boolean; virtual; - function MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: QWord): Boolean; virtual; overload; - function MaskMatch(const aMask: TglBitmapMask): Boolean; virtual; overload; + function MaskMatch(const aMask: TglBitmapRec4ul): Boolean; virtual; procedure PreparePixel(out aPixel: TglBitmapPixelData); virtual; - - constructor Create; virtual; public 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 function GetFromMask(const aMask: TglBitmapRec4ul; const aBitCount: Integer = 0): TFormatDescriptor; class procedure Clear; class procedure Finalize; end; @@ -1493,270 +1466,258 @@ type ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TfdAlpha4ub1 = class(TfdAlphaUB1) - constructor Create; override; + procedure SetValues; override; end; TfdAlpha8ub1 = class(TfdAlphaUB1) - constructor Create; override; + procedure SetValues; override; end; TfdAlpha16us1 = class(TfdAlphaUS1) - constructor Create; override; + procedure SetValues; override; end; TfdLuminance4ub1 = class(TfdLuminanceUB1) - constructor Create; override; + procedure SetValues; override; end; TfdLuminance8ub1 = class(TfdLuminanceUB1) - constructor Create; override; + procedure SetValues; override; end; TfdLuminance16us1 = class(TfdLuminanceUS1) - constructor Create; override; + procedure SetValues; override; end; TfdLuminance4Alpha4ub2 = class(TfdLuminanceAlphaUB2) - constructor Create; override; + procedure SetValues; override; end; TfdLuminance6Alpha2ub2 = class(TfdLuminanceAlphaUB2) - constructor Create; override; + procedure SetValues; override; end; TfdLuminance8Alpha8ub2 = class(TfdLuminanceAlphaUB2) - constructor Create; override; + procedure SetValues; override; end; TfdLuminance12Alpha4us2 = class(TfdLuminanceAlphaUS2) - constructor Create; override; + procedure SetValues; override; end; TfdLuminance16Alpha16us2 = class(TfdLuminanceAlphaUS2) - constructor Create; override; + procedure SetValues; override; end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TfdR3G3B2ub1 = class(TfdUniversalUB1) - constructor Create; override; + procedure SetValues; override; end; TfdRGBX4us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdXRGB4us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdR5G6B5us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdRGB5X1us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdX1RGB5us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdRGB8ub3 = class(TfdRGBub3) - constructor Create; override; + procedure SetValues; override; end; TfdRGBX8ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdXRGB8ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdRGB10X2ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdX2RGB10ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdRGB16us3 = class(TfdRGBus3) - constructor Create; override; + procedure SetValues; override; end; TfdRGBA4us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdARGB4us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdRGB5A1us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdA1RGB5us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdRGBA8ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdARGB8ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdRGBA8ub4 = class(TfdRGBAub4) - constructor Create; override; + procedure SetValues; override; end; TfdRGB10A2ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdA2RGB10ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdRGBA16us4 = class(TfdRGBAus4) - constructor Create; override; + procedure SetValues; override; end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TfdBGRX4us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdXBGR4us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdB5G6R5us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdBGR5X1us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdX1BGR5us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdBGR8ub3 = class(TfdBGRub3) - constructor Create; override; + procedure SetValues; override; end; TfdBGRX8ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdXBGR8ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdBGR10X2ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdX2BGR10ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdBGR16us3 = class(TfdBGRus3) - constructor Create; override; + procedure SetValues; override; end; TfdBGRA4us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdABGR4us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdBGR5A1us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdA1BGR5us1 = class(TfdUniversalUS1) - constructor Create; override; + procedure SetValues; override; end; TfdBGRA8ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdABGR8ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdBGRA8ub4 = class(TfdBGRAub4) - constructor Create; override; + procedure SetValues; override; end; TfdBGR10A2ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdA2BGR10ui1 = class(TfdUniversalUI1) - constructor Create; override; + procedure SetValues; override; end; TfdBGRA16us4 = class(TfdBGRAus4) - constructor Create; override; + procedure SetValues; override; end; TfdDepth16us1 = class(TfdDepthUS1) - constructor Create; override; + procedure SetValues; override; end; TfdDepth24ui1 = class(TfdDepthUI1) - constructor Create; override; + procedure SetValues; override; end; TfdDepth32ui1 = class(TfdDepthUI1) - constructor Create; override; + procedure SetValues; override; end; TfdS3tcDtx1RGBA = class(TFormatDescriptor) procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override; procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override; - constructor Create; override; + procedure SetValues; override; end; TfdS3tcDtx3RGBA = class(TFormatDescriptor) procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override; procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override; - constructor Create; override; + procedure SetValues; override; end; TfdS3tcDtx5RGBA = class(TFormatDescriptor) procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override; procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); override; - constructor Create; override; + procedure SetValues; override; end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// TbmpBitfieldFormat = class(TFormatDescriptor) - private - procedure SetRedMask (const aValue: QWord); - procedure SetGreenMask(const aValue: QWord); - procedure SetBlueMask (const aValue: QWord); - procedure SetAlphaMask(const aValue: QWord); - - procedure Update(aMask: QWord; out aRange: Cardinal; out aShift: Byte); public - property RedMask: QWord read GetRedMask write SetRedMask; - property GreenMask: QWord read GetGreenMask write SetGreenMask; - property BlueMask: QWord read GetBlueMask write SetBlueMask; - property AlphaMask: QWord read GetAlphaMask write SetAlphaMask; - - property PixelSize: Single read fPixelSize write fPixelSize; - + procedure SetValues(const aBPP: Integer; aMask: TglBitmapRec4ul); overload; + procedure SetValues(const aBBP: Integer; const aPrec, aShift: TglBitmapRec4ub); overload; 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; @@ -1768,14 +1729,16 @@ type TbmpColorTable = array of TbmpColorTableEnty; TbmpColorTableFormat = class(TFormatDescriptor) private + fBitsPerPixel: Integer; fColorTable: TbmpColorTable; + protected + procedure SetValues; override; overload; public - property PixelSize: Single read fPixelSize write fPixelSize; - property ColorTable: TbmpColorTable read fColorTable write fColorTable; - property Range: TglBitmapColorRec read fRange write fRange; - property Shift: TShiftRec read fShift write fShift; - property Format: TglBitmapFormat read fFormat write fFormat; + property ColorTable: TbmpColorTable read fColorTable write fColorTable; + property BitsPerPixel: Integer read fBitsPerPixel write fBitsPerPixel; + procedure SetValues(const aFormat: TglBitmapFormat; const aBPP: Integer; const aPrec, aShift: TglBitmapRec4ub); overload; + procedure CalcValues; procedure CreateColorTable; procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); override; @@ -1900,7 +1863,7 @@ begin end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function glBitmapColorRec(const r, g, b, a: Cardinal): TglBitmapColorRec; +function glBitmapRec4ub(const r, g, b, a: Byte): TglBitmapRec4ub; begin result.r := r; result.g := g; @@ -1909,7 +1872,25 @@ begin end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function glBitmapColorRecCmp(const r1, r2: TglBitmapColorRec): Boolean; +function glBitmapRec4ui(const r, g, b, a: Cardinal): TglBitmapRec4ui; +begin + result.r := r; + result.g := g; + result.b := b; + result.a := a; +end; + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +function glBitmapRec4ul(const r, g, b, a: QWord): TglBitmapRec4ul; +begin + result.r := r; + result.g := g; + result.b := b; + result.a := a; +end; + +///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +function glBitmapRec4uiCompare(const r1, r2: TglBitmapRec4ui): Boolean; var i: Integer; begin @@ -1934,14 +1915,14 @@ begin if (desc.IsCompressed) or (desc.glFormat = 0) then exit; - p := GetMem(ceil(25 * desc.PixelSize)); // 5 x 5 pixel + p := GetMem(ceil(25 * desc.BytesPerPixel)); // 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); + px.Data := glBitmapRec4ui(0, 0, 0, 0); for i := 0 to 3 do begin if ((y < 3) and (y = i)) or ((y = 3) and (i < 3)) or @@ -1960,6 +1941,7 @@ begin finally desc.FreeMappingData(md); end; + result := TglBitmap2D.Create(glBitmapPosition(5, 5), aFormat, p); result.FreeDataOnDestroy := true; result.FreeDataAfterGenTexture := false; @@ -1967,7 +1949,7 @@ begin end; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function glBitmapShiftRec(const r, g, b, a: Byte): TShiftRec; +function glBitmapShiftRec(const r, g, b, a: Byte): TglBitmapRec4ub; begin result.r := r; result.g := g; @@ -2447,136 +2429,6 @@ end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TFormatDescriptor/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetRedMask: QWord; -begin - result := fRange.r shl fShift.r; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetGreenMask: QWord; -begin - result := fRange.g shl fShift.g; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetBlueMask: QWord; -begin - result := fRange.b shl fShift.b; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetAlphaMask: QWord; -begin - result := fRange.a shl fShift.a; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetIsCompressed: Boolean; -begin - result := fIsCompressed; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetHasRed: Boolean; -begin - result := (fRange.r > 0); -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetHasGreen: Boolean; -begin - result := (fRange.g > 0); -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetHasBlue: Boolean; -begin - result := (fRange.b > 0); -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetHasAlpha: Boolean; -begin - result := (fRange.a > 0); -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; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetWithAlpha: TglBitmapFormat; -begin - result := fWithAlpha; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetWithoutAlpha: TglBitmapFormat; -begin - result := fWithoutAlpha; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetOpenGLFormat: TglBitmapFormat; -begin - result := fOpenGLFormat; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetUncompressed: TglBitmapFormat; -begin - result := fUncompressed; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetglFormat: GLenum; -begin - result := fglFormat; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetglInternalFormat: GLenum; -begin - result := fglInternalFormat; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetglDataFormat: GLenum; -begin - result := fglDataFormat; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.GetComponents: Integer; -var - i: Integer; -begin - result := 0; - for i := 0 to 3 do - if (fRange.arr[i] > 0) then - inc(result); -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function TFormatDescriptor.GetSize(const aSize: TglBitmapPixelPosition): Integer; var w, h: Integer; @@ -2595,7 +2447,7 @@ begin result := 0; if (aWidth <= 0) or (aHeight <= 0) then exit; - result := Ceil(aWidth * aHeight * fPixelSize); + result := Ceil(aWidth * aHeight * BytesPerPixel); end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2617,58 +2469,28 @@ begin end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -function TFormatDescriptor.MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: QWord): Boolean; +function TFormatDescriptor.MaskMatch(const aMask: TglBitmapRec4ul): Boolean; +var + i: Integer; + m: TglBitmapRec4ul; begin result := false; - if (aRedMask = 0) and (aGreenMask = 0) and (aBlueMask = 0) and (aAlphaMask = 0) then + if (aMask.r = 0) and (aMask.g = 0) and (aMask.b = 0) and (aMask.a = 0) then raise EglBitmap.Create('FormatCheckFormat - All Masks are 0'); - if (aRedMask <> RedMask) then - exit; - if (aGreenMask <> GreenMask) then - exit; - if (aBlueMask <> BlueMask) then - exit; - if (aAlphaMask <> AlphaMask) then - exit; + m := Mask; + for i := 0 to 3 do + if (aMask.arr[i] <> m.arr[i]) then + exit; result := true; 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); - aPixel.Data := fRange; - aPixel.Range := fRange; + aPixel.Data := Range; aPixel.Format := fFormat; -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -constructor TFormatDescriptor.Create; -begin - inherited Create; - - fFormat := tfEmpty; - fWithAlpha := tfEmpty; - fWithoutAlpha := tfEmpty; - fOpenGLFormat := tfEmpty; - fRGBInverted := tfEmpty; - fUncompressed := tfEmpty; - - fPixelSize := 0.0; - fIsCompressed := false; - - fglFormat := 0; - fglInternalFormat := 0; - fglDataFormat := 0; - - FillChar(fRange, 0, SizeOf(fRange)); - FillChar(fShift, 0, SizeOf(fShift)); + aPixel.Range := Range; end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2716,8 +2538,8 @@ var begin aData^ := 0; for i := 0 to 3 do - if (fRange.arr[i] > 0) then - aData^ := aData^ or ((aPixel.Data.arr[i] and fRange.arr[i]) shl fShift.arr[i]); + if (Range.arr[i] > 0) then + aData^ := aData^ or ((aPixel.Data.arr[i] and Range.arr[i]) shl fShift.arr[i]); inc(aData); end; @@ -2726,7 +2548,7 @@ var i: Integer; begin for i := 0 to 3 do - aPixel.Data.arr[i] := (aData^ shr fShift.arr[i]) and fRange.arr[i]; + aPixel.Data.arr[i] := (aData^ shr fShift.arr[i]) and Range.arr[i]; inc(aData); end; @@ -2874,8 +2696,8 @@ var begin PWord(aData)^ := 0; for i := 0 to 3 do - if (fRange.arr[i] > 0) then - PWord(aData)^ := PWord(aData)^ or ((aPixel.Data.arr[i] and fRange.arr[i]) shl fShift.arr[i]); + if (Range.arr[i] > 0) then + PWord(aData)^ := PWord(aData)^ or ((aPixel.Data.arr[i] and Range.arr[i]) shl fShift.arr[i]); inc(aData, 2); end; @@ -2884,7 +2706,7 @@ var i: Integer; begin for i := 0 to 3 do - aPixel.Data.arr[i] := (PWord(aData)^ shr fShift.arr[i]) and fRange.arr[i]; + aPixel.Data.arr[i] := (PWord(aData)^ shr fShift.arr[i]) and Range.arr[i]; inc(aData, 2); end; @@ -3048,8 +2870,8 @@ var begin PCardinal(aData)^ := 0; for i := 0 to 3 do - if (fRange.arr[i] > 0) then - PCardinal(aData)^ := PCardinal(aData)^ or ((aPixel.Data.arr[i] and fRange.arr[i]) shl fShift.arr[i]); + if (Range.arr[i] > 0) then + PCardinal(aData)^ := PCardinal(aData)^ or ((aPixel.Data.arr[i] and Range.arr[i]) shl fShift.arr[i]); inc(aData, 4); end; @@ -3058,7 +2880,7 @@ var i: Integer; begin for i := 0 to 3 do - aPixel.Data.arr[i] := (PCardinal(aData)^ shr fShift.arr[i]) and fRange.arr[i]; + aPixel.Data.arr[i] := (PCardinal(aData)^ shr fShift.arr[i]) and Range.arr[i]; inc(aData, 2); end; @@ -3083,654 +2905,515 @@ end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -constructor TfdAlpha4ub1.Create; +procedure TfdAlpha4ub1.SetValues; begin - inherited Create; - fPixelSize := 1.0; + inherited SetValues; + fBitsPerPixel := 8; fFormat := tfAlpha4ub1; fWithAlpha := tfAlpha4ub1; fOpenGLFormat := tfAlpha4ub1; - fRange.a := $FF; + fPrecision := glBitmapRec4ub(0, 0, 0, 8); + fShift := glBitmapRec4ub(0, 0, 0, 0); fglFormat := GL_ALPHA; fglInternalFormat := GL_ALPHA4; fglDataFormat := GL_UNSIGNED_BYTE; end; -constructor TfdAlpha8ub1.Create; +procedure TfdAlpha8ub1.SetValues; begin - inherited Create; - fPixelSize := 1.0; + inherited SetValues; + fBitsPerPixel := 8; fFormat := tfAlpha8ub1; fWithAlpha := tfAlpha8ub1; fOpenGLFormat := tfAlpha8ub1; - fRange.a := $FF; + fPrecision := glBitmapRec4ub(0, 0, 0, 8); + fShift := glBitmapRec4ub(0, 0, 0, 0); fglFormat := GL_ALPHA; fglInternalFormat := GL_ALPHA8; fglDataFormat := GL_UNSIGNED_BYTE; end; -constructor TfdAlpha16us1.Create; +procedure TfdAlpha16us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfAlpha16us1; fWithAlpha := tfAlpha16us1; fOpenGLFormat := tfAlpha16us1; - fRange.a := $FFFF; + fPrecision := glBitmapRec4ub(0, 0, 0, 16); + fShift := glBitmapRec4ub(0, 0, 0, 0); fglFormat := GL_ALPHA; fglInternalFormat := GL_ALPHA16; fglDataFormat := GL_UNSIGNED_SHORT; end; -constructor TfdLuminance4ub1.Create; +procedure TfdLuminance4ub1.SetValues; begin - inherited Create; - fPixelSize := 1.0; + inherited SetValues; + fBitsPerPixel := 8; fFormat := tfLuminance4ub1; fWithAlpha := tfLuminance4Alpha4ub2; fWithoutAlpha := tfLuminance4ub1; fOpenGLFormat := tfLuminance4ub1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; + fPrecision := glBitmapRec4ub(8, 8, 8, 0); + fShift := glBitmapRec4ub(0, 0, 0, 0); fglFormat := GL_LUMINANCE; fglInternalFormat := GL_LUMINANCE4; fglDataFormat := GL_UNSIGNED_BYTE; end; -constructor TfdLuminance8ub1.Create; +procedure TfdLuminance8ub1.SetValues; begin - inherited Create; - fPixelSize := 1.0; + inherited SetValues; + fBitsPerPixel := 8; fFormat := tfLuminance8ub1; fWithAlpha := tfLuminance8Alpha8ub2; fWithoutAlpha := tfLuminance8ub1; fOpenGLFormat := tfLuminance8ub1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; + fPrecision := glBitmapRec4ub(8, 8, 8, 0); + fShift := glBitmapRec4ub(0, 0, 0, 0); fglFormat := GL_LUMINANCE; fglInternalFormat := GL_LUMINANCE8; fglDataFormat := GL_UNSIGNED_BYTE; end; -constructor TfdLuminance16us1.Create; +procedure TfdLuminance16us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfLuminance16us1; fWithAlpha := tfLuminance16Alpha16us2; fWithoutAlpha := tfLuminance16us1; fOpenGLFormat := tfLuminance16us1; - fRange.r := $FFFF; - fRange.g := $FFFF; - fRange.b := $FFFF; + fPrecision := glBitmapRec4ub(16, 16, 16, 0); + fShift := glBitmapRec4ub( 0, 0, 0, 0); fglFormat := GL_LUMINANCE; fglInternalFormat := GL_LUMINANCE16; fglDataFormat := GL_UNSIGNED_SHORT; end; -constructor TfdLuminance4Alpha4ub2.Create; +procedure TfdLuminance4Alpha4ub2.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfLuminance4Alpha4ub2; fWithAlpha := tfLuminance4Alpha4ub2; fWithoutAlpha := tfLuminance4ub1; fOpenGLFormat := tfLuminance4Alpha4ub2; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fRange.a := $FF; - fShift.r := 0; - fShift.g := 0; - fShift.b := 0; - fShift.a := 8; + fPrecision := glBitmapRec4ub(8, 8, 8, 8); + fShift := glBitmapRec4ub(0, 0, 0, 8); fglFormat := GL_LUMINANCE_ALPHA; fglInternalFormat := GL_LUMINANCE4_ALPHA4; fglDataFormat := GL_UNSIGNED_BYTE; end; -constructor TfdLuminance6Alpha2ub2.Create; +procedure TfdLuminance6Alpha2ub2.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfLuminance6Alpha2ub2; fWithAlpha := tfLuminance6Alpha2ub2; fWithoutAlpha := tfLuminance8ub1; fOpenGLFormat := tfLuminance6Alpha2ub2; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fRange.a := $FF; - fShift.r := 0; - fShift.g := 0; - fShift.b := 0; - fShift.a := 8; + fPrecision := glBitmapRec4ub(8, 8, 8, 8); + fShift := glBitmapRec4ub(0, 0, 0, 8); fglFormat := GL_LUMINANCE_ALPHA; fglInternalFormat := GL_LUMINANCE6_ALPHA2; fglDataFormat := GL_UNSIGNED_BYTE; end; -constructor TfdLuminance8Alpha8ub2.Create; +procedure TfdLuminance8Alpha8ub2.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfLuminance8Alpha8ub2; fWithAlpha := tfLuminance8Alpha8ub2; fWithoutAlpha := tfLuminance8ub1; fOpenGLFormat := tfLuminance8Alpha8ub2; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fRange.a := $FF; - fShift.r := 0; - fShift.g := 0; - fShift.b := 0; - fShift.a := 8; + fPrecision := glBitmapRec4ub(8, 8, 8, 8); + fShift := glBitmapRec4ub(0, 0, 0, 8); fglFormat := GL_LUMINANCE_ALPHA; fglInternalFormat := GL_LUMINANCE8_ALPHA8; fglDataFormat := GL_UNSIGNED_BYTE; end; -constructor TfdLuminance12Alpha4us2.Create; +procedure TfdLuminance12Alpha4us2.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfLuminance12Alpha4us2; fWithAlpha := tfLuminance12Alpha4us2; fWithoutAlpha := tfLuminance16us1; fOpenGLFormat := tfLuminance12Alpha4us2; - fRange.r := $FFFF; - fRange.g := $FFFF; - fRange.b := $FFFF; - fRange.a := $FFFF; - fShift.r := 0; - fShift.g := 0; - fShift.b := 0; - fShift.a := 16; + fPrecision := glBitmapRec4ub(16, 16, 16, 16); + fShift := glBitmapRec4ub( 0, 0, 0, 16); fglFormat := GL_LUMINANCE_ALPHA; fglInternalFormat := GL_LUMINANCE12_ALPHA4; fglDataFormat := GL_UNSIGNED_SHORT; end; -constructor TfdLuminance16Alpha16us2.Create; +procedure TfdLuminance16Alpha16us2.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfLuminance16Alpha16us2; fWithAlpha := tfLuminance16Alpha16us2; fWithoutAlpha := tfLuminance16us1; fOpenGLFormat := tfLuminance16Alpha16us2; - fRange.r := $FFFF; - fRange.g := $FFFF; - fRange.b := $FFFF; - fRange.a := $FFFF; - fShift.r := 0; - fShift.g := 0; - fShift.b := 0; - fShift.a := 16; + fPrecision := glBitmapRec4ub(16, 16, 16, 16); + fShift := glBitmapRec4ub( 0, 0, 0, 16); fglFormat := GL_LUMINANCE_ALPHA; fglInternalFormat := GL_LUMINANCE16_ALPHA16; fglDataFormat := GL_UNSIGNED_SHORT; end; -constructor TfdR3G3B2ub1.Create; +procedure TfdR3G3B2ub1.SetValues; begin - inherited Create; - fPixelSize := 1.0; + inherited SetValues; + fBitsPerPixel := 8; fFormat := tfR3G3B2ub1; fWithAlpha := tfRGBA4us1; fWithoutAlpha := tfR3G3B2ub1; fOpenGLFormat := tfR3G3B2ub1; fRGBInverted := tfEmpty; - fRange.r := $07; - fRange.g := $07; - fRange.b := $03; - fShift.r := 5; - fShift.g := 2; - fShift.b := 0; + fPrecision := glBitmapRec4ub(3, 3, 2, 0); + fShift := glBitmapRec4ub(5, 2, 0, 0); fglFormat := GL_RGB; fglInternalFormat := GL_R3_G3_B2; fglDataFormat := GL_UNSIGNED_BYTE_3_3_2; end; -constructor TfdRGBX4us1.Create; +procedure TfdRGBX4us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfRGBX4us1; fWithAlpha := tfRGBA4us1; fWithoutAlpha := tfRGBX4us1; fOpenGLFormat := tfRGBX4us1; fRGBInverted := tfBGRX4us1; - fRange.r := $0F; - fRange.g := $0F; - fRange.b := $0F; - fRange.a := $00; - fShift.r := 12; - fShift.g := 8; - fShift.b := 4; + fPrecision := glBitmapRec4ub( 4, 4, 4, 0); + fShift := glBitmapRec4ub(12, 8, 4, 0); fglFormat := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB4; fglDataFormat := GL_UNSIGNED_SHORT_4_4_4_4; end; -constructor TfdXRGB4us1.Create; +procedure TfdXRGB4us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfXRGB4us1; fWithAlpha := tfARGB4us1; fWithoutAlpha := tfXRGB4us1; fOpenGLFormat := tfXRGB4us1; fRGBInverted := tfXBGR4us1; - fRange.r := $0F; - fRange.g := $0F; - fRange.b := $0F; - fShift.r := 8; - fShift.g := 4; - fShift.b := 0; + fPrecision := glBitmapRec4ub(4, 4, 4, 0); + fShift := glBitmapRec4ub(8, 4, 0, 0); fglFormat := GL_BGRA; fglInternalFormat := GL_RGB4; fglDataFormat := GL_UNSIGNED_SHORT_4_4_4_4_REV; end; -constructor TfdR5G6B5us1.Create; +procedure TfdR5G6B5us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfR5G6B5us1; fWithAlpha := tfRGB5A1us1; fWithoutAlpha := tfR5G6B5us1; fOpenGLFormat := tfR5G6B5us1; fRGBInverted := tfB5G6R5us1; - fRange.r := $1F; - fRange.g := $3F; - fRange.b := $1F; - fShift.r := 11; - fShift.g := 5; - fShift.b := 0; + fPrecision := glBitmapRec4ub( 5, 6, 5, 0); + fShift := glBitmapRec4ub(11, 5, 0, 0); fglFormat := GL_RGB; fglInternalFormat := GL_RGB565; fglDataFormat := GL_UNSIGNED_SHORT_5_6_5; end; -constructor TfdRGB5X1us1.Create; +procedure TfdRGB5X1us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfRGB5X1us1; fWithAlpha := tfRGB5A1us1; fWithoutAlpha := tfRGB5X1us1; fOpenGLFormat := tfRGB5X1us1; fRGBInverted := tfBGR5X1us1; - fRange.r := $1F; - fRange.g := $1F; - fRange.b := $1F; - fShift.r := 11; - fShift.g := 6; - fShift.b := 1; + fPrecision := glBitmapRec4ub( 5, 5, 5, 0); + fShift := glBitmapRec4ub(11, 6, 1, 0); fglFormat := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB5; fglDataFormat := GL_UNSIGNED_SHORT_5_5_5_1; end; -constructor TfdX1RGB5us1.Create; +procedure TfdX1RGB5us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfX1RGB5us1; fWithAlpha := tfA1RGB5us1; fWithoutAlpha := tfX1RGB5us1; fOpenGLFormat := tfX1RGB5us1; fRGBInverted := tfX1BGR5us1; - fRange.r := $1F; - fRange.g := $1F; - fRange.b := $1F; - fShift.r := 10; - fShift.g := 5; - fShift.b := 0; + fPrecision := glBitmapRec4ub( 5, 5, 5, 0); + fShift := glBitmapRec4ub(10, 5, 0, 0); fglFormat := GL_BGRA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB5; fglDataFormat := GL_UNSIGNED_SHORT_1_5_5_5_REV; end; -constructor TfdRGB8ub3.Create; +procedure TfdRGB8ub3.SetValues; begin - inherited Create; - fPixelSize := 3.0; + inherited SetValues; + fBitsPerPixel := 24; fFormat := tfRGB8ub3; fWithAlpha := tfRGBA8ub4; fWithoutAlpha := tfRGB8ub3; fOpenGLFormat := tfRGB8ub3; fRGBInverted := tfBGR8ub3; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fShift.r := 0; - fShift.g := 8; - fShift.b := 16; + fPrecision := glBitmapRec4ub(8, 8, 8, 0); + fShift := glBitmapRec4ub(0, 8, 16, 0); fglFormat := GL_RGB; fglInternalFormat := GL_RGB8; fglDataFormat := GL_UNSIGNED_BYTE; end; -constructor TfdRGBX8ui1.Create; +procedure TfdRGBX8ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfRGBX8ui1; fWithAlpha := tfRGBA8ui1; fWithoutAlpha := tfRGBX8ui1; fOpenGLFormat := tfRGB8ub3; fRGBInverted := tfBGRX8ui1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fShift.r := 24; - fShift.g := 16; - fShift.b := 8; + fPrecision := glBitmapRec4ub( 8, 8, 8, 0); + fShift := glBitmapRec4ub(24, 16, 8, 0); fglFormat := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB8; fglDataFormat := GL_UNSIGNED_INT_8_8_8_8; end; -constructor TfdXRGB8ui1.Create; +procedure TfdXRGB8ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfXRGB8ui1; fWithAlpha := tfXRGB8ui1; fWithoutAlpha := tfXRGB8ui1; fOpenGLFormat := tfRGB8ub3; fRGBInverted := tfXBGR8ui1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fShift.r := 16; - fShift.g := 8; - fShift.b := 0; + fPrecision := glBitmapRec4ub( 8, 8, 8, 0); + fShift := glBitmapRec4ub(16, 8, 0, 0); fglFormat := GL_BGRA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB8; fglDataFormat := GL_UNSIGNED_INT_8_8_8_8_REV; end; -constructor TfdRGB10X2ui1.Create; +procedure TfdRGB10X2ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfRGB10X2ui1; fWithAlpha := tfRGB10A2ui1; fWithoutAlpha := tfRGB10X2ui1; fOpenGLFormat := tfRGB10X2ui1; fRGBInverted := tfBGR10X2ui1; - fRange.r := $03FF; - fRange.g := $03FF; - fRange.b := $03FF; - fShift.r := 22; - fShift.g := 12; - fShift.b := 2; + fPrecision := glBitmapRec4ub(10, 10, 10, 0); + fShift := glBitmapRec4ub(22, 12, 2, 0); fglFormat := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB10; fglDataFormat := GL_UNSIGNED_INT_10_10_10_2; end; -constructor TfdX2RGB10ui1.Create; +procedure TfdX2RGB10ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfX2RGB10ui1; fWithAlpha := tfA2RGB10ui1; fWithoutAlpha := tfX2RGB10ui1; fOpenGLFormat := tfX2RGB10ui1; fRGBInverted := tfX2BGR10ui1; - fRange.r := $03FF; - fRange.g := $03FF; - fRange.b := $03FF; - fShift.r := 20; - fShift.g := 10; - fShift.b := 0; + fPrecision := glBitmapRec4ub(10, 10, 10, 0); + fShift := glBitmapRec4ub(20, 10, 0, 0); fglFormat := GL_BGRA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB10; fglDataFormat := GL_UNSIGNED_INT_2_10_10_10_REV; end; -constructor TfdRGB16us3.Create; +procedure TfdRGB16us3.SetValues; begin - inherited Create; - fPixelSize := 6.0; + inherited SetValues; + fBitsPerPixel := 48; fFormat := tfRGB16us3; fWithAlpha := tfRGBA16us4; fWithoutAlpha := tfRGB16us3; fOpenGLFormat := tfRGB16us3; fRGBInverted := tfBGR16us3; - fRange.r := $FFFF; - fRange.g := $FFFF; - fRange.b := $FFFF; - fShift.r := 0; - fShift.g := 16; - fShift.b := 32; + fPrecision := glBitmapRec4ub(16, 16, 16, 0); + fShift := glBitmapRec4ub( 0, 16, 32, 0); fglFormat := GL_RGB; fglInternalFormat := GL_RGB16; fglDataFormat := GL_UNSIGNED_SHORT; end; -constructor TfdRGBA4us1.Create; +procedure TfdRGBA4us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfRGBA4us1; fWithAlpha := tfRGBA4us1; fWithoutAlpha := tfRGBX4us1; fOpenGLFormat := tfRGBA4us1; fRGBInverted := tfBGRA4us1; - fRange.r := $0F; - fRange.g := $0F; - fRange.b := $0F; - fRange.a := $0F; - fShift.r := 12; - fShift.g := 8; - fShift.b := 4; - fShift.a := 0; + fPrecision := glBitmapRec4ub( 4, 4, 4, 4); + fShift := glBitmapRec4ub(12, 8, 4, 0); fglFormat := GL_RGBA; fglInternalFormat := GL_RGBA4; fglDataFormat := GL_UNSIGNED_SHORT_4_4_4_4; end; -constructor TfdARGB4us1.Create; +procedure TfdARGB4us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfARGB4us1; fWithAlpha := tfARGB4us1; fWithoutAlpha := tfXRGB4us1; fOpenGLFormat := tfARGB4us1; fRGBInverted := tfABGR4us1; - fRange.r := $0F; - fRange.g := $0F; - fRange.b := $0F; - fRange.a := $0F; - fShift.r := 8; - fShift.g := 4; - fShift.b := 0; - fShift.a := 12; + fPrecision := glBitmapRec4ub( 4, 4, 4, 4); + fShift := glBitmapRec4ub( 8, 4, 0, 12); fglFormat := GL_BGRA; fglInternalFormat := GL_RGBA4; fglDataFormat := GL_UNSIGNED_SHORT_4_4_4_4_REV; end; -constructor TfdRGB5A1us1.Create; +procedure TfdRGB5A1us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfRGB5A1us1; fWithAlpha := tfRGB5A1us1; fWithoutAlpha := tfRGB5X1us1; fOpenGLFormat := tfRGB5A1us1; fRGBInverted := tfBGR5A1us1; - fRange.r := $1F; - fRange.g := $1F; - fRange.b := $1F; - fRange.a := $01; - fShift.r := 11; - fShift.g := 6; - fShift.b := 1; - fShift.a := 0; + fPrecision := glBitmapRec4ub( 5, 5, 5, 1); + fShift := glBitmapRec4ub(11, 6, 1, 0); fglFormat := GL_RGBA; fglInternalFormat := GL_RGB5_A1; fglDataFormat := GL_UNSIGNED_SHORT_5_5_5_1; end; -constructor TfdA1RGB5us1.Create; +procedure TfdA1RGB5us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfA1RGB5us1; fWithAlpha := tfA1RGB5us1; fWithoutAlpha := tfX1RGB5us1; fOpenGLFormat := tfA1RGB5us1; fRGBInverted := tfA1BGR5us1; - fRange.r := $1F; - fRange.g := $1F; - fRange.b := $1F; - fRange.a := $01; - fShift.r := 10; - fShift.g := 5; - fShift.b := 0; - fShift.a := 15; + fPrecision := glBitmapRec4ub( 5, 5, 5, 1); + fShift := glBitmapRec4ub(10, 5, 0, 15); fglFormat := GL_BGRA; fglInternalFormat := GL_RGB5_A1; fglDataFormat := GL_UNSIGNED_SHORT_1_5_5_5_REV; end; -constructor TfdRGBA8ui1.Create; +procedure TfdRGBA8ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfRGBA8ui1; fWithAlpha := tfRGBA8ui1; fWithoutAlpha := tfRGBX8ui1; fOpenGLFormat := tfRGBA8ui1; fRGBInverted := tfBGRA8ui1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fRange.a := $FF; - fShift.r := 24; - fShift.g := 16; - fShift.b := 8; - fShift.a := 0; + fPrecision := glBitmapRec4ub( 8, 8, 8, 8); + fShift := glBitmapRec4ub(24, 16, 8, 0); fglFormat := GL_RGBA; fglInternalFormat := GL_RGBA8; fglDataFormat := GL_UNSIGNED_INT_8_8_8_8; end; -constructor TfdARGB8ui1.Create; +procedure TfdARGB8ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfARGB8ui1; fWithAlpha := tfARGB8ui1; fWithoutAlpha := tfXRGB8ui1; fOpenGLFormat := tfARGB8ui1; fRGBInverted := tfABGR8ui1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fRange.a := $FF; - fShift.r := 16; - fShift.g := 8; - fShift.b := 0; - fShift.a := 24; + fPrecision := glBitmapRec4ub( 8, 8, 8, 8); + fShift := glBitmapRec4ub(16, 8, 0, 24); fglFormat := GL_BGRA; fglInternalFormat := GL_RGBA8; fglDataFormat := GL_UNSIGNED_INT_8_8_8_8_REV; end; -constructor TfdRGBA8ub4.Create; +procedure TfdRGBA8ub4.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; 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; + fPrecision := glBitmapRec4ub( 8, 8, 8, 8); + fShift := glBitmapRec4ub( 0, 8, 16, 24); fglFormat := GL_RGBA; fglInternalFormat := GL_RGBA8; fglDataFormat := GL_UNSIGNED_BYTE; end; -constructor TfdRGB10A2ui1.Create; +procedure TfdRGB10A2ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfRGB10A2ui1; fWithAlpha := tfRGB10A2ui1; fWithoutAlpha := tfRGB10X2ui1; fOpenGLFormat := tfRGB10A2ui1; fRGBInverted := tfBGR10A2ui1; - fRange.r := $03FF; - fRange.g := $03FF; - fRange.b := $03FF; - fRange.a := $0003; - fShift.r := 22; - fShift.g := 12; - fShift.b := 2; - fShift.a := 0; + fPrecision := glBitmapRec4ub(10, 10, 10, 2); + fShift := glBitmapRec4ub(22, 12, 2, 0); fglFormat := GL_RGBA; fglInternalFormat := GL_RGB10_A2; fglDataFormat := GL_UNSIGNED_INT_10_10_10_2; end; -constructor TfdA2RGB10ui1.Create; +procedure TfdA2RGB10ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfA2RGB10ui1; fWithAlpha := tfA2RGB10ui1; fWithoutAlpha := tfX2RGB10ui1; fOpenGLFormat := tfA2RGB10ui1; fRGBInverted := tfA2BGR10ui1; - fRange.r := $03FF; - fRange.g := $03FF; - fRange.b := $03FF; - fRange.a := $0003; - fShift.r := 20; - fShift.g := 10; - fShift.b := 0; - fShift.a := 30; + fPrecision := glBitmapRec4ub(10, 10, 10, 2); + fShift := glBitmapRec4ub(20, 10, 0, 30); fglFormat := GL_BGRA; fglInternalFormat := GL_RGB10_A2; fglDataFormat := GL_UNSIGNED_INT_2_10_10_10_REV; end; -constructor TfdRGBA16us4.Create; +procedure TfdRGBA16us4.SetValues; begin - inherited Create; - fPixelSize := 8.0; + inherited SetValues; + fBitsPerPixel := 64; fFormat := tfRGBA16us4; fWithAlpha := tfRGBA16us4; fWithoutAlpha := tfRGB16us3; fOpenGLFormat := tfRGBA16us4; fRGBInverted := tfBGRA16us4; - fRange.r := $FFFF; - fRange.g := $FFFF; - fRange.b := $FFFF; - fRange.a := $FFFF; - fShift.r := 0; - fShift.g := 16; - fShift.b := 32; - fShift.a := 48; + fPrecision := glBitmapRec4ub(16, 16, 16, 16); + fShift := glBitmapRec4ub( 0, 16, 32, 48); fglFormat := GL_RGBA; fglInternalFormat := GL_RGBA16; fglDataFormat := GL_UNSIGNED_SHORT; @@ -3739,489 +3422,379 @@ end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -constructor TfdBGRX4us1.Create; +procedure TfdBGRX4us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfBGRX4us1; fWithAlpha := tfBGRA4us1; fWithoutAlpha := tfBGRX4us1; fOpenGLFormat := tfBGRX4us1; fRGBInverted := tfRGBX4us1; - fRange.r := $0F; - fRange.g := $0F; - fRange.b := $0F; - fShift.r := 4; - fShift.g := 8; - fShift.b := 12; + fPrecision := glBitmapRec4ub( 4, 4, 4, 0); + fShift := glBitmapRec4ub( 4, 8, 12, 0); fglFormat := GL_BGRA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB4; fglDataFormat := GL_UNSIGNED_SHORT_4_4_4_4; end; -constructor TfdXBGR4us1.Create; +procedure TfdXBGR4us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfXBGR4us1; fWithAlpha := tfABGR4us1; fWithoutAlpha := tfXBGR4us1; fOpenGLFormat := tfXBGR4us1; fRGBInverted := tfXRGB4us1; - fRange.r := $0F; - fRange.g := $0F; - fRange.b := $0F; - fShift.r := 0; - fShift.g := 4; - fShift.b := 8; + fPrecision := glBitmapRec4ub( 4, 4, 4, 0); + fShift := glBitmapRec4ub( 0, 4, 8, 0); fglFormat := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB4; fglDataFormat := GL_UNSIGNED_SHORT_4_4_4_4_REV; end; -constructor TfdB5G6R5us1.Create; +procedure TfdB5G6R5us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfB5G6R5us1; fWithAlpha := tfBGR5A1us1; fWithoutAlpha := tfB5G6R5us1; fOpenGLFormat := tfB5G6R5us1; fRGBInverted := tfR5G6B5us1; - fRange.r := $1F; - fRange.g := $3F; - fRange.b := $1F; - fShift.r := 0; - fShift.g := 5; - fShift.b := 11; + fPrecision := glBitmapRec4ub( 5, 6, 5, 0); + fShift := glBitmapRec4ub( 0, 5, 11, 0); fglFormat := GL_RGB; fglInternalFormat := GL_RGB565; fglDataFormat := GL_UNSIGNED_SHORT_5_6_5_REV; end; -constructor TfdBGR5X1us1.Create; +procedure TfdBGR5X1us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfBGR5X1us1; fWithAlpha := tfBGR5A1us1; fWithoutAlpha := tfBGR5X1us1; fOpenGLFormat := tfBGR5X1us1; fRGBInverted := tfRGB5X1us1; - fRange.r := $1F; - fRange.g := $1F; - fRange.b := $1F; - fShift.r := 1; - fShift.g := 6; - fShift.b := 11; + fPrecision := glBitmapRec4ub( 5, 5, 5, 0); + fShift := glBitmapRec4ub( 1, 6, 11, 0); fglFormat := GL_BGRA; fglInternalFormat := GL_RGB5; fglDataFormat := GL_UNSIGNED_SHORT_5_5_5_1; end; -constructor TfdX1BGR5us1.Create; +procedure TfdX1BGR5us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfX1BGR5us1; fWithAlpha := tfA1BGR5us1; fWithoutAlpha := tfX1BGR5us1; fOpenGLFormat := tfX1BGR5us1; fRGBInverted := tfX1RGB5us1; - fRange.r := $1F; - fRange.g := $1F; - fRange.b := $1F; - fShift.r := 0; - fShift.g := 5; - fShift.b := 10; + fPrecision := glBitmapRec4ub( 5, 5, 5, 0); + fShift := glBitmapRec4ub( 0, 5, 10, 0); fglFormat := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB5; fglDataFormat := GL_UNSIGNED_SHORT_1_5_5_5_REV; end; -constructor TfdBGR8ub3.Create; +procedure TfdBGR8ub3.SetValues; begin - inherited Create; - fPixelSize := 3.0; + inherited SetValues; + fBitsPerPixel := 24; fFormat := tfBGR8ub3; fWithAlpha := tfBGRA8ub4; fWithoutAlpha := tfBGR8ub3; fOpenGLFormat := tfBGR8ub3; fRGBInverted := tfRGB8ub3; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fShift.r := 16; - fShift.g := 8; - fShift.b := 0; + fPrecision := glBitmapRec4ub( 8, 8, 8, 0); + fShift := glBitmapRec4ub(16, 8, 0, 0); fglFormat := GL_BGR; fglInternalFormat := GL_RGB8; fglDataFormat := GL_UNSIGNED_BYTE; end; -constructor TfdBGRX8ui1.Create; +procedure TfdBGRX8ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfBGRX8ui1; fWithAlpha := tfBGRA8ui1; fWithoutAlpha := tfBGRX8ui1; fOpenGLFormat := tfBGRX8ui1; fRGBInverted := tfRGBX8ui1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fShift.r := 8; - fShift.g := 16; - fShift.b := 24; + fPrecision := glBitmapRec4ub( 8, 8, 8, 0); + fShift := glBitmapRec4ub( 8, 16, 24, 0); fglFormat := GL_BGRA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB8; fglDataFormat := GL_UNSIGNED_INT_8_8_8_8; end; -constructor TfdXBGR8ui1.Create; +procedure TfdXBGR8ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfXBGR8ui1; fWithAlpha := tfABGR8ui1; fWithoutAlpha := tfXBGR8ui1; fOpenGLFormat := tfXBGR8ui1; fRGBInverted := tfXRGB8ui1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fShift.r := 0; - fShift.g := 8; - fShift.b := 16; + fPrecision := glBitmapRec4ub( 8, 8, 8, 0); + fShift := glBitmapRec4ub( 0, 8, 16, 0); fglFormat := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB8; fglDataFormat := GL_UNSIGNED_INT_8_8_8_8_REV; end; -constructor TfdBGR10X2ui1.Create; +procedure TfdBGR10X2ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfBGR10X2ui1; fWithAlpha := tfBGR10A2ui1; fWithoutAlpha := tfBGR10X2ui1; fOpenGLFormat := tfBGR10X2ui1; fRGBInverted := tfRGB10X2ui1; - fRange.r := $03FF; - fRange.g := $03FF; - fRange.b := $03FF; - fShift.r := 2; - fShift.g := 12; - fShift.b := 22; + fPrecision := glBitmapRec4ub(10, 10, 10, 0); + fShift := glBitmapRec4ub( 2, 12, 22, 0); fglFormat := GL_BGRA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB10; fglDataFormat := GL_UNSIGNED_INT_10_10_10_2; end; -constructor TfdX2BGR10ui1.Create; +procedure TfdX2BGR10ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfX2BGR10ui1; fWithAlpha := tfA2BGR10ui1; fWithoutAlpha := tfX2BGR10ui1; fOpenGLFormat := tfX2BGR10ui1; fRGBInverted := tfX2RGB10ui1; - fRange.r := $03FF; - fRange.g := $03FF; - fRange.b := $03FF; - fShift.r := 0; - fShift.g := 10; - fShift.b := 20; + fPrecision := glBitmapRec4ub(10, 10, 10, 0); + fShift := glBitmapRec4ub( 0, 10, 20, 0); fglFormat := GL_RGBA; //GL_INVALID_OPERATION if not GL_BGRA or GL_RGBA fglInternalFormat := GL_RGB10; fglDataFormat := GL_UNSIGNED_INT_2_10_10_10_REV; end; -constructor TfdBGR16us3.Create; +procedure TfdBGR16us3.SetValues; begin - inherited Create; - fPixelSize := 6.0; + inherited SetValues; + fBitsPerPixel := 48; fFormat := tfBGR16us3; fWithAlpha := tfBGRA16us4; fWithoutAlpha := tfBGR16us3; fOpenGLFormat := tfBGR16us3; fRGBInverted := tfRGB16us3; - fRange.r := $FFFF; - fRange.g := $FFFF; - fRange.b := $FFFF; - fShift.r := 32; - fShift.g := 16; - fShift.b := 0; + fPrecision := glBitmapRec4ub(16, 16, 16, 0); + fShift := glBitmapRec4ub(32, 16, 0, 0); fglFormat := GL_BGR; fglInternalFormat := GL_RGB16; fglDataFormat := GL_UNSIGNED_SHORT; end; -constructor TfdBGRA4us1.Create; +procedure TfdBGRA4us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfBGRA4us1; fWithAlpha := tfBGRA4us1; fWithoutAlpha := tfBGRX4us1; fOpenGLFormat := tfBGRA4us1; fRGBInverted := tfRGBA4us1; - fRange.r := $0F; - fRange.g := $0F; - fRange.b := $0F; - fRange.a := $0F; - fShift.r := 4; - fShift.g := 8; - fShift.b := 12; - fShift.a := 0; + fPrecision := glBitmapRec4ub( 4, 4, 4, 4); + fShift := glBitmapRec4ub( 4, 8, 12, 0); fglFormat := GL_BGRA; fglInternalFormat := GL_RGBA4; fglDataFormat := GL_UNSIGNED_SHORT_4_4_4_4; end; -constructor TfdABGR4us1.Create; +procedure TfdABGR4us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfABGR4us1; fWithAlpha := tfABGR4us1; fWithoutAlpha := tfXBGR4us1; fOpenGLFormat := tfABGR4us1; fRGBInverted := tfARGB4us1; - fRange.r := $0F; - fRange.g := $0F; - fRange.b := $0F; - fRange.a := $0F; - fShift.r := 0; - fShift.g := 4; - fShift.b := 8; - fShift.a := 12; + fPrecision := glBitmapRec4ub( 4, 4, 4, 4); + fShift := glBitmapRec4ub( 0, 4, 8, 12); fglFormat := GL_RGBA; fglInternalFormat := GL_RGBA4; fglDataFormat := GL_UNSIGNED_SHORT_4_4_4_4_REV; end; -constructor TfdBGR5A1us1.Create; +procedure TfdBGR5A1us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfBGR5A1us1; fWithAlpha := tfBGR5A1us1; fWithoutAlpha := tfBGR5X1us1; fOpenGLFormat := tfBGR5A1us1; fRGBInverted := tfRGB5A1us1; - fRange.r := $1F; - fRange.g := $1F; - fRange.b := $1F; - fRange.a := $01; - fShift.r := 1; - fShift.g := 6; - fShift.b := 11; - fShift.a := 0; + fPrecision := glBitmapRec4ub( 5, 5, 5, 1); + fShift := glBitmapRec4ub( 1, 6, 11, 0); fglFormat := GL_BGRA; fglInternalFormat := GL_RGB5_A1; fglDataFormat := GL_UNSIGNED_SHORT_5_5_5_1; end; -constructor TfdA1BGR5us1.Create; +procedure TfdA1BGR5us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfA1BGR5us1; fWithAlpha := tfA1BGR5us1; fWithoutAlpha := tfX1BGR5us1; fOpenGLFormat := tfA1BGR5us1; fRGBInverted := tfA1RGB5us1; - fRange.r := $1F; - fRange.g := $1F; - fRange.b := $1F; - fRange.a := $01; - fShift.r := 0; - fShift.g := 5; - fShift.b := 10; - fShift.a := 15; + fPrecision := glBitmapRec4ub( 5, 5, 5, 1); + fShift := glBitmapRec4ub( 0, 5, 10, 15); fglFormat := GL_RGBA; fglInternalFormat := GL_RGB5_A1; fglDataFormat := GL_UNSIGNED_SHORT_1_5_5_5_REV; end; -constructor TfdBGRA8ui1.Create; +procedure TfdBGRA8ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfBGRA8ui1; fWithAlpha := tfBGRA8ui1; fWithoutAlpha := tfBGRX8ui1; fOpenGLFormat := tfBGRA8ui1; fRGBInverted := tfRGBA8ui1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fRange.a := $FF; - fShift.r := 8; - fShift.g := 16; - fShift.b := 24; - fShift.a := 0; + fPrecision := glBitmapRec4ub( 8, 8, 8, 8); + fShift := glBitmapRec4ub( 8, 16, 24, 0); fglFormat := GL_BGRA; fglInternalFormat := GL_RGBA8; fglDataFormat := GL_UNSIGNED_INT_8_8_8_8; end; -constructor TfdABGR8ui1.Create; +procedure TfdABGR8ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfABGR8ui1; fWithAlpha := tfABGR8ui1; fWithoutAlpha := tfXBGR8ui1; fOpenGLFormat := tfABGR8ui1; fRGBInverted := tfARGB8ui1; - fRange.r := $FF; - fRange.g := $FF; - fRange.b := $FF; - fRange.a := $FF; - fShift.r := 0; - fShift.g := 8; - fShift.b := 16; - fShift.a := 24; + fPrecision := glBitmapRec4ub( 8, 8, 8, 8); + fShift := glBitmapRec4ub( 0, 8, 16, 24); fglFormat := GL_RGBA; fglInternalFormat := GL_RGBA8; fglDataFormat := GL_UNSIGNED_INT_8_8_8_8_REV; end; -constructor TfdBGRA8ub4.Create; +procedure TfdBGRA8ub4.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; 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; + fPrecision := glBitmapRec4ub( 8, 8, 8, 8); + fShift := glBitmapRec4ub(16, 8, 0, 24); fglFormat := GL_BGRA; fglInternalFormat := GL_RGBA8; fglDataFormat := GL_UNSIGNED_BYTE; end; -constructor TfdBGR10A2ui1.Create; +procedure TfdBGR10A2ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfBGR10A2ui1; fWithAlpha := tfBGR10A2ui1; fWithoutAlpha := tfBGR10X2ui1; fOpenGLFormat := tfBGR10A2ui1; fRGBInverted := tfRGB10A2ui1; - fRange.r := $03FF; - fRange.g := $03FF; - fRange.b := $03FF; - fRange.a := $0003; - fShift.r := 2; - fShift.g := 12; - fShift.b := 22; - fShift.a := 0; + fPrecision := glBitmapRec4ub(10, 10, 10, 2); + fShift := glBitmapRec4ub( 2, 12, 22, 0); fglFormat := GL_BGRA; fglInternalFormat := GL_RGB10_A2; fglDataFormat := GL_UNSIGNED_INT_10_10_10_2; end; -constructor TfdA2BGR10ui1.Create; +procedure TfdA2BGR10ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfA2BGR10ui1; fWithAlpha := tfA2BGR10ui1; fWithoutAlpha := tfX2BGR10ui1; fOpenGLFormat := tfA2BGR10ui1; fRGBInverted := tfA2RGB10ui1; - fRange.r := $03FF; - fRange.g := $03FF; - fRange.b := $03FF; - fRange.a := $0003; - fShift.r := 0; - fShift.g := 10; - fShift.b := 20; - fShift.a := 30; + fPrecision := glBitmapRec4ub(10, 10, 10, 2); + fShift := glBitmapRec4ub( 0, 10, 20, 30); fglFormat := GL_RGBA; fglInternalFormat := GL_RGB10_A2; fglDataFormat := GL_UNSIGNED_INT_2_10_10_10_REV; end; -constructor TfdBGRA16us4.Create; +procedure TfdBGRA16us4.SetValues; begin - inherited Create; - fPixelSize := 8.0; + inherited SetValues; + fBitsPerPixel := 64; fFormat := tfBGRA16us4; fWithAlpha := tfBGRA16us4; fWithoutAlpha := tfBGR16us3; fOpenGLFormat := tfBGRA16us4; fRGBInverted := tfRGBA16us4; - fRange.r := $FFFF; - fRange.g := $FFFF; - fRange.b := $FFFF; - fRange.a := $FFFF; - fShift.r := 32; - fShift.g := 16; - fShift.b := 0; - fShift.a := 48; + fPrecision := glBitmapRec4ub(16, 16, 16, 16); + fShift := glBitmapRec4ub(32, 16, 0, 48); fglFormat := GL_BGRA; fglInternalFormat := GL_RGBA16; fglDataFormat := GL_UNSIGNED_SHORT; end; -constructor TfdDepth16us1.Create; +procedure TfdDepth16us1.SetValues; begin - inherited Create; - fPixelSize := 2.0; + inherited SetValues; + fBitsPerPixel := 16; fFormat := tfDepth16us1; fWithoutAlpha := tfDepth16us1; fOpenGLFormat := tfDepth16us1; - fRange.r := $FFFF; - fRange.g := $FFFF; - fRange.b := $FFFF; - fRange.a := $FFFF; + fPrecision := glBitmapRec4ub(16, 16, 16, 16); + fShift := glBitmapRec4ub( 0, 0, 0, 0); fglFormat := GL_DEPTH_COMPONENT; fglInternalFormat := GL_DEPTH_COMPONENT16; fglDataFormat := GL_UNSIGNED_SHORT; end; -constructor TfdDepth24ui1.Create; +procedure TfdDepth24ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfDepth24ui1; fWithoutAlpha := tfDepth24ui1; fOpenGLFormat := tfDepth24ui1; - fRange.r := $FFFFFFFF; - fRange.g := $FFFFFFFF; - fRange.b := $FFFFFFFF; - fRange.a := $FFFFFFFF; + fPrecision := glBitmapRec4ub(32, 32, 32, 32); + fShift := glBitmapRec4ub( 0, 0, 0, 0); fglFormat := GL_DEPTH_COMPONENT; fglInternalFormat := GL_DEPTH_COMPONENT24; fglDataFormat := GL_UNSIGNED_INT; end; -constructor TfdDepth32ui1.Create; +procedure TfdDepth32ui1.SetValues; begin - inherited Create; - fPixelSize := 4.0; + inherited SetValues; + fBitsPerPixel := 32; fFormat := tfDepth32ui1; fWithoutAlpha := tfDepth32ui1; fOpenGLFormat := tfDepth32ui1; - fRange.r := $FFFFFFFF; - fRange.g := $FFFFFFFF; - fRange.b := $FFFFFFFF; - fRange.a := $FFFFFFFF; + fPrecision := glBitmapRec4ub(32, 32, 32, 32); + fShift := glBitmapRec4ub( 0, 0, 0, 0); fglFormat := GL_DEPTH_COMPONENT; fglInternalFormat := GL_DEPTH_COMPONENT32; fglDataFormat := GL_UNSIGNED_INT; @@ -4240,14 +3813,14 @@ begin raise EglBitmap.Create('mapping for compressed formats is not supported'); end; -constructor TfdS3tcDtx1RGBA.Create; +procedure TfdS3tcDtx1RGBA.SetValues; begin - inherited Create; + inherited SetValues; fFormat := tfS3tcDtx1RGBA; fWithAlpha := tfS3tcDtx1RGBA; fOpenGLFormat := tfS3tcDtx1RGBA; fUncompressed := tfRGB5A1us1; - fPixelSize := 0.5; + fBitsPerPixel := 4; fIsCompressed := true; fglFormat := GL_COMPRESSED_RGBA; fglInternalFormat := GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; @@ -4267,14 +3840,14 @@ begin raise EglBitmap.Create('mapping for compressed formats is not supported'); end; -constructor TfdS3tcDtx3RGBA.Create; +procedure TfdS3tcDtx3RGBA.SetValues; begin - inherited Create; + inherited SetValues; fFormat := tfS3tcDtx3RGBA; fWithAlpha := tfS3tcDtx3RGBA; fOpenGLFormat := tfS3tcDtx3RGBA; fUncompressed := tfRGBA8ub4; - fPixelSize := 1.0; + fBitsPerPixel := 8; fIsCompressed := true; fglFormat := GL_COMPRESSED_RGBA; fglInternalFormat := GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; @@ -4294,14 +3867,14 @@ begin raise EglBitmap.Create('mapping for compressed formats is not supported'); end; -constructor TfdS3tcDtx5RGBA.Create; +procedure TfdS3tcDtx5RGBA.SetValues; begin inherited Create; fFormat := tfS3tcDtx3RGBA; fWithAlpha := tfS3tcDtx3RGBA; fOpenGLFormat := tfS3tcDtx3RGBA; fUncompressed := tfRGBA8ub4; - fPixelSize := 1.0; + fBitsPerPixel := 8; fIsCompressed := true; fglFormat := GL_COMPRESSED_RGBA; fglInternalFormat := GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; @@ -4311,6 +3884,79 @@ end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TglBitmapFormatDescriptor/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +function TglBitmapFormatDescriptor.GetHasRed: Boolean; +begin + result := (fPrecision.r > 0); +end; + +function TglBitmapFormatDescriptor.GetHasGreen: Boolean; +begin + result := (fPrecision.g > 0); +end; + +function TglBitmapFormatDescriptor.GetHasBlue: Boolean; +begin + result := (fPrecision.b > 0); +end; + +function TglBitmapFormatDescriptor.GetHasAlpha: Boolean; +begin + result := (fPrecision.a > 0); +end; + +function TglBitmapFormatDescriptor.GetHasColor: Boolean; +begin + result := HasRed or HasGreen or HasBlue; +end; + +function TglBitmapFormatDescriptor.GetIsGrayscale: Boolean; +begin + result := (Mask.r = Mask.g) and (Mask.g = Mask.b) and (Mask.r > 0); +end; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +procedure TglBitmapFormatDescriptor.SetValues; +begin + fFormat := tfEmpty; + fWithAlpha := tfEmpty; + fWithoutAlpha := tfEmpty; + fOpenGLFormat := tfEmpty; + fRGBInverted := tfEmpty; + fUncompressed := tfEmpty; + + fBitsPerPixel := 0; + fIsCompressed := false; + + fglFormat := 0; + fglInternalFormat := 0; + fglDataFormat := 0; + + FillChar(fPrecision, 0, SizeOf(fPrecision)); + FillChar(fShift, 0, SizeOf(fShift)); +end; + +procedure TglBitmapFormatDescriptor.CalcValues; +var + i: Integer; +begin + fBytesPerPixel := fBitsPerPixel / 8; + fChannelCount := 0; + for i := 0 to 3 do begin + if (fPrecision.arr[i] > 0) then + inc(fChannelCount); + fRange.arr[i] := (1 shl fPrecision.arr[i]) - 1; + fMask.arr[i] := fRange.arr[i] shl fShift.arr[i]; + end; +end; + +constructor TglBitmapFormatDescriptor.Create; +begin + inherited Create; + SetValues; + CalcValues; +end; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// class function TglBitmapFormatDescriptor.GetByFormat(const aInternalFormat: GLenum): TglBitmapFormatDescriptor; var f: TglBitmapFormat; @@ -4354,7 +4000,7 @@ begin end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -class function TFormatDescriptor.GetFromMask(const aMask: TglBitmapMask; const aBitCount: Integer): TFormatDescriptor; +class function TFormatDescriptor.GetFromMask(const aMask: TglBitmapRec4ul; const aBitCount: Integer): TFormatDescriptor; var ft: TglBitmapFormat; begin @@ -4364,7 +4010,7 @@ begin if (result.MaskMatch(aMask)) and (result.glFormat <> 0) and (result.glInternalFormat <> 0) and - ((aBitCount = 0) or (aBitCount = 8 * result.PixelSize)) + ((aBitCount = 0) or (aBitCount = result.BitsPerPixel)) then exit; end; @@ -4372,7 +4018,7 @@ begin // 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 + if result.MaskMatch(aMask) and ((aBitCount = 0) or (aBitCount = result.BitsPerPixel)) then exit; end; @@ -4403,103 +4049,102 @@ end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TBitfieldFormat///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TbmpBitfieldFormat.SetRedMask(const aValue: QWord); -begin - Update(aValue, fRange.r, fShift.r); -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TbmpBitfieldFormat.SetGreenMask(const aValue: QWord); -begin - Update(aValue, fRange.g, fShift.g); -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TbmpBitfieldFormat.SetBlueMask(const aValue: QWord); -begin - Update(aValue, fRange.b, fShift.b); -end; - -////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TbmpBitfieldFormat.SetAlphaMask(const aValue: QWord); +procedure TbmpBitfieldFormat.SetValues(const aBPP: Integer; aMask: TglBitmapRec4ul); +var + i: Integer; begin - Update(aValue, fRange.a, fShift.a); + for i := 0 to 3 do begin + fShift.arr[i] := 0; + while (aMask.arr[i] > 0) and (aMask.arr[i] and 1 > 0) do begin + aMask.arr[i] := aMask.arr[i] shr 1; + inc(fShift.arr[i]); + end; + fPrecision.arr[i] := CountSetBits(aMask.arr[i]); + end; + CalcValues; end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -procedure TbmpBitfieldFormat.Update(aMask: QWord; out aRange: Cardinal; out - aShift: Byte); +procedure TbmpBitfieldFormat.SetValues(const aBBP: Integer; const aPrec, aShift: TglBitmapRec4ub); begin - aShift := 0; - aRange := 0; - if (aMask = 0) then - exit; - while (aMask > 0) and ((aMask and 1) = 0) do begin - inc(aShift); - aMask := aMask shr 1; - end; - aRange := 1; - while (aMask > 0) do begin - aRange := aRange shl 1; - aMask := aMask shr 1; - end; - dec(aRange); - - fPixelSize := Round(GetTopMostBit(RedMask or GreenMask or BlueMask or AlphaMask) / 8); + fBitsPerPixel := aBBP; + fPrecision := aPrec; + fShift := aShift; + CalcValues; end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TbmpBitfieldFormat.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); var data: QWord; - s: Integer; begin data := - ((aPixel.Data.r and fRange.r) shl fShift.r) or - ((aPixel.Data.g and fRange.g) shl fShift.g) or - ((aPixel.Data.b and fRange.b) shl fShift.b) or - ((aPixel.Data.a and fRange.a) shl fShift.a); - s := Round(fPixelSize); - case s of - 1: aData^ := data; - 2: PWord(aData)^ := data; - 4: PCardinal(aData)^ := data; - 8: PQWord(aData)^ := data; + ((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) or + ((aPixel.Data.a and Range.a) shl Shift.a); + case BitsPerPixel of + 8: aData^ := data; + 16: PWord(aData)^ := data; + 32: PCardinal(aData)^ := data; + 64: PQWord(aData)^ := data; else - raise EglBitmap.CreateFmt('invalid pixel size: %.1f', [fPixelSize]); + raise EglBitmap.CreateFmt('invalid pixel size: %d', [BitsPerPixel]); end; - inc(aData, s); + inc(aData, Round(BytesPerPixel)); end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TbmpBitfieldFormat.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); var data: QWord; - s, i: Integer; -begin - s := Round(fPixelSize); - case s of - 1: data := aData^; - 2: data := PWord(aData)^; - 4: data := PCardinal(aData)^; - 8: data := PQWord(aData)^; + i: Integer; +begin + case BitsPerPixel of + 8: data := aData^; + 16: data := PWord(aData)^; + 32: data := PCardinal(aData)^; + 64: data := PQWord(aData)^; else - raise EglBitmap.CreateFmt('invalid pixel size: %.1f', [fPixelSize]); + raise EglBitmap.CreateFmt('invalid pixel size: %d', [BitsPerPixel]); end; for i := 0 to 3 do - aPixel.Data.arr[i] := (data shr fShift.arr[i]) and fRange.arr[i]; - inc(aData, s); + aPixel.Data.arr[i] := (data shr fShift.arr[i]) and Range.arr[i]; + inc(aData, Round(BytesPerPixel)); end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TColorTableFormat/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +procedure TbmpColorTableFormat.SetValues; +begin + inherited SetValues; + fShift := glBitmapRec4ub(8, 8, 8, 0); +end; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +procedure TbmpColorTableFormat.SetValues(const aFormat: TglBitmapFormat; const aBPP: Integer; const aPrec, aShift: TglBitmapRec4ub); +begin + fFormat := aFormat; + fBitsPerPixel := aBPP; + fPrecision := aPrec; + fShift := aShift; + CalcValues; +end; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +procedure TbmpColorTableFormat.CalcValues; +begin + inherited CalcValues; +end; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TbmpColorTableFormat.CreateColorTable; var i: Integer; begin SetLength(fColorTable, 256); - if (fRange.r = fRange.g) and (fRange.g = fRange.b) and (fRange.r = 0) then begin + if not HasColor 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); @@ -4521,9 +4166,9 @@ end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TbmpColorTableFormat.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); begin - if (fPixelSize <> 1.0) then + if (BitsPerPixel <> 8) 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 + if not HasColor then // alpha aData^ := aPixel.Data.a else @@ -4538,7 +4183,7 @@ end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// procedure TbmpColorTableFormat.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); begin - if (fPixelSize <> 1.0) then + if (BitsPerPixel <> 8) then raise EglBitmapUnsupportedFormat.Create('color table are only supported for 8bit formats'); with fColorTable[aData^] do begin aPixel.Data.r := r; @@ -4797,7 +4442,7 @@ procedure TglBitmap.SetFormat(const aValue: TglBitmapFormat); begin if fFormat = aValue then exit; - if TFormatDescriptor.Get(Format).PixelSize <> TFormatDescriptor.Get(aValue).PixelSize then + if TFormatDescriptor.Get(Format).BitsPerPixel <> TFormatDescriptor.Get(aValue).BitsPerPixel then raise EglBitmapUnsupportedFormat.Create(Format); SetDataPointer(fData, aValue, Width, Height); //be careful, Data could be freed by this method end; @@ -4914,7 +4559,7 @@ begin fDimension.Y := aHeight; end; - s := TFormatDescriptor.Get(aFormat).PixelSize; + s := TFormatDescriptor.Get(aFormat).BytesPerPixel; fFormat := aFormat; fPixelSize := Ceil(s); fRowSize := Ceil(s * aWidth); @@ -5120,7 +4765,7 @@ begin raise EglBitmapUnsupportedFormat.Create('compressed formats are not supported: ', DestFD.Format); // inkompatible Formats so CreateTemp - if (SourceFD.PixelSize <> DestFD.PixelSize) then + if (SourceFD.BitsPerPixel <> DestFD.BitsPerPixel) then aCreateTemp := true; // Values @@ -5535,12 +5180,12 @@ begin rid.Width := Width; rid.Height := Height; - rid.Depth := CountSetBits(FormatDesc.RedMask or FormatDesc.GreenMask or FormatDesc.BlueMask or FormatDesc.AlphaMask); + rid.Depth := FormatDesc.BitsPerPixel; rid.BitOrder := riboBitsInOrder; rid.ByteOrder := riboLSBFirst; rid.LineOrder := riloTopToBottom; rid.LineEnd := rileTight; - rid.BitsPerPixel := Round(8 * FormatDesc.PixelSize); + rid.BitsPerPixel := FormatDesc.BitsPerPixel; rid.RedPrec := CountSetBits(FormatDesc.Range.r); rid.GreenPrec := CountSetBits(FormatDesc.Range.g); rid.BluePrec := CountSetBits(FormatDesc.Range.b); @@ -5571,30 +5216,35 @@ var ImageData: PByte; ImageSize: Integer; CanCopy: Boolean; - Mask: TglBitmapMask; + Mask: TglBitmapRec4ul; procedure CopyConvert; var bfFormat: TbmpBitfieldFormat; pSourceLine, pDestLine: PByte; pSourceMD, pDestMD: Pointer; + Shift, Prec: TglBitmapRec4ub; x, y: Integer; pixel: TglBitmapPixelData; begin bfFormat := TbmpBitfieldFormat.Create; with aImage.DataDescription do begin - bfFormat.RedMask := ((1 shl RedPrec) - 1) shl RedShift; - bfFormat.GreenMask := ((1 shl GreenPrec) - 1) shl GreenShift; - bfFormat.BlueMask := ((1 shl BluePrec) - 1) shl BlueShift; - bfFormat.AlphaMask := ((1 shl AlphaPrec) - 1) shl AlphaShift; - bfFormat.PixelSize := BitsPerPixel / 8; + Prec.r := RedPrec; + Prec.g := GreenPrec; + Prec.b := BluePrec; + Prec.a := AlphaPrec; + Shift.r := RedShift; + Shift.g := GreenShift; + Shift.b := BlueShift; + Shift.a := AlphaShift; + bfFormat.SetValues(BitsPerPixel, Prec, Shift); end; pSourceMD := bfFormat.CreateMappingData; pDestMD := FormatDesc.CreateMappingData; try for y := 0 to aImage.Height-1 do begin pSourceLine := aImage.PixelData + y {%H-}* aImage.DataDescription.BytesPerLine; - pDestLine := ImageData + y * Round(FormatDesc.PixelSize * aImage.Width); + pDestLine := ImageData + y * Round(FormatDesc.BytesPerPixel * aImage.Width); for x := 0 to aImage.Width-1 do begin bfFormat.Unmap(pSourceLine, pixel, pSourceMD); FormatDesc.Map(pixel, pDestLine, pDestMD); @@ -5624,7 +5274,7 @@ begin exit; CanCopy := - (Round(FormatDesc.PixelSize * 8) = aImage.DataDescription.Depth) and + (FormatDesc.BitsPerPixel = aImage.DataDescription.Depth) and (aImage.DataDescription.BitsPerPixel = aImage.DataDescription.Depth); ImageSize := FormatDesc.GetSize(aImage.Width, aImage.Height); @@ -6015,11 +5665,7 @@ var function DataIsIdentical: Boolean; begin - result := - (SourceFD.RedMask = DestFD.RedMask) and - (SourceFD.GreenMask = DestFD.GreenMask) and - (SourceFD.BlueMask = DestFD.BlueMask) and - (SourceFD.AlphaMask = DestFD.AlphaMask); + result := SourceFD.MaskMatch(DestFD.Mask); end; function CanCopyDirect: Boolean; @@ -7369,7 +7015,7 @@ type function TglBitmap.LoadBMP(const aStream: TStream): Boolean; ////////////////////////////////////////////////////////////////////////////////////////////////// - function ReadInfo(out aInfo: TBMPInfo; out aMask: TglBitmapMask): TglBitmapFormat; + function ReadInfo(out aInfo: TBMPInfo; out aMask: TglBitmapRec4ul): TglBitmapFormat; begin result := tfEmpty; aStream.Read(aInfo{%H-}, SizeOf(aInfo)); @@ -7421,13 +7067,13 @@ function TglBitmap.LoadBMP(const aStream: TStream): Boolean; end; result := TbmpColorTableFormat.Create; - result.PixelSize := aInfo.biBitCount / 8; - result.ColorTable := ColorTable; - result.Range := glBitmapColorRec($FF, $FF, $FF, $00); + result.BitsPerPixel := aInfo.biBitCount; + result.ColorTable := ColorTable; + result.CalcValues; end; ////////////////////////////////////////////////////////////////////////////////////////////////// - function CheckBitfields(var aFormat: TglBitmapFormat; const aMask: TglBitmapMask; const aInfo: TBMPInfo): TbmpBitfieldFormat; + function CheckBitfields(var aFormat: TglBitmapFormat; const aMask: TglBitmapRec4ul; const aInfo: TBMPInfo): TbmpBitfieldFormat; var FormatDesc: TFormatDescriptor; begin @@ -7443,11 +7089,7 @@ function TglBitmap.LoadBMP(const aStream: TStream): Boolean; aFormat := TFormatDescriptor.Get(aFormat).WithAlpha; result := TbmpBitfieldFormat.Create; - result.PixelSize := aInfo.biBitCount / 8; - result.RedMask := aMask.r; - result.GreenMask := aMask.g; - result.BlueMask := aMask.b; - result.AlphaMask := aMask.a; + result.SetValues(aInfo.biBitCount, aMask); end; end; @@ -7461,7 +7103,7 @@ var BmpFormat: TglBitmapFormat; //records - Mask: TglBitmapMask; + Mask: TglBitmapRec4ul; Header: TBMPHeader; Info: TBMPInfo; @@ -7507,7 +7149,7 @@ begin if (BmpFormat <> tfEmpty) then begin FormatDesc := TFormatDescriptor.Get(BmpFormat); rbLineSize := Round(Info.biWidth * Info.biBitCount / 8); //ReadBuffer LineSize - wbLineSize := Trunc(Info.biWidth * FormatDesc.PixelSize); + wbLineSize := Trunc(Info.biWidth * FormatDesc.BytesPerPixel); Padding := (((Info.biWidth * Info.biBitCount + 31) and - 32) shr 3) - rbLineSize; //get Memory @@ -7616,10 +7258,7 @@ begin Header.bfOffBits := Header.bfOffBits + 256 * SizeOf(Cardinal); //256 ColorTable entries Converter := TbmpColorTableFormat.Create; with (Converter as TbmpColorTableFormat) do begin - PixelSize := 1; - Format := fFormat; - Range := FormatDesc.Range; - Shift := FormatDesc.Shift; + SetValues(fFormat, 1, FormatDesc.Precision, FormatDesc.Shift); CreateColorTable; end; end; @@ -7656,10 +7295,10 @@ begin Header.bfSize := Header.bfSize + 4 * SizeOf(Cardinal); Header.bfOffBits := Header.bfOffBits + 4 * SizeOf(Cardinal); - RedMask := FormatDesc.RedMask; - GreenMask := FormatDesc.GreenMask; - BlueMask := FormatDesc.BlueMask; - AlphaMask := FormatDesc.AlphaMask; + RedMask := FormatDesc.Mask.r; + GreenMask := FormatDesc.Mask.g; + BlueMask := FormatDesc.Mask.b; + AlphaMask := FormatDesc.Mask.a; end; // headers @@ -7681,7 +7320,7 @@ begin end; // image data - rbLineSize := Round(Info.biWidth * FormatDesc.PixelSize); + rbLineSize := Round(Info.biWidth * FormatDesc.BytesPerPixel); wbLineSize := Round(Info.biWidth * Info.biBitCount / 8); Padding := GetLineWidth - wbLineSize; PaddingBuff := 0; @@ -8054,7 +7693,7 @@ begin FormatDesc := TFormatDescriptor.Get(Format); FillChar(Header{%H-}, SizeOf(Header), 0); Header.ImageDesc := CountSetBits(FormatDesc.Range.a) and $F; - Header.Bpp := Trunc(8 * FormatDesc.PixelSize); + Header.Bpp := FormatDesc.BitsPerPixel; Header.Width := Width; Header.Height := Height; Header.ImageDesc := Header.ImageDesc or $20; //flip y @@ -8141,8 +7780,8 @@ var var fd: TFormatDescriptor; i: Integer; - Mask: TglBitmapMask; - Range: TglBitmapColorRec; + Mask: TglBitmapRec4ul; + Range: TglBitmapRec4ui; match: Boolean; begin result := tfEmpty; @@ -8200,11 +7839,7 @@ var end; Converter := TbmpBitfieldFormat.Create; - Converter.RedMask := dwRBitMask; - Converter.GreenMask := dwGBitMask; - Converter.BlueMask := dwBBitMask; - Converter.AlphaMask := dwABitMask; - Converter.PixelSize := dwRGBBitCount / 8; + Converter.SetValues(dwRGBBitCount, glBitmapRec4ul(dwRBitMask, dwGBitMask, dwBBitMask, dwABitMask)); end; end; end; @@ -8249,7 +7884,7 @@ begin raise EglBitmap.Create('LoadDDS - unsupported Pixelformat found.'); FormatDesc := TFormatDescriptor.Get(ddsFormat); - LineSize := Trunc(Header.dwWidth * FormatDesc.PixelSize); + LineSize := Trunc(Header.dwWidth * FormatDesc.BytesPerPixel); GetMem(NewImage, Header.dwHeight * LineSize); try TmpData := NewImage; @@ -8343,20 +7978,20 @@ begin end; 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; - end else if (FormatDesc.RedMask = FormatDesc.GreenMask) and (FormatDesc.GreenMask = FormatDesc.BlueMask) then begin + Header.PixelFormat.dwRGBBitCount := FormatDesc.BitsPerPixel; + Header.PixelFormat.dwABitMask := FormatDesc.Mask.a; + end else if FormatDesc.IsGrayscale then begin Header.PixelFormat.dwFlags := Header.PixelFormat.dwFlags or DDPF_LUMINANCE; - Header.PixelFormat.dwRGBBitCount := Round(FormatDesc.PixelSize * 8); - Header.PixelFormat.dwRBitMask := FormatDesc.RedMask; - Header.PixelFormat.dwABitMask := FormatDesc.AlphaMask; + Header.PixelFormat.dwRGBBitCount := FormatDesc.BitsPerPixel; + Header.PixelFormat.dwRBitMask := FormatDesc.Mask.r; + Header.PixelFormat.dwABitMask := FormatDesc.Mask.a; end else begin Header.PixelFormat.dwFlags := Header.PixelFormat.dwFlags or DDPF_RGB; - Header.PixelFormat.dwRGBBitCount := Round(FormatDesc.PixelSize * 8); - Header.PixelFormat.dwRBitMask := FormatDesc.RedMask; - Header.PixelFormat.dwGBitMask := FormatDesc.GreenMask; - Header.PixelFormat.dwBBitMask := FormatDesc.BlueMask; - Header.PixelFormat.dwABitMask := FormatDesc.AlphaMask; + Header.PixelFormat.dwRGBBitCount := FormatDesc.BitsPerPixel; + Header.PixelFormat.dwRBitMask := FormatDesc.Mask.r; + Header.PixelFormat.dwGBitMask := FormatDesc.Mask.g; + Header.PixelFormat.dwBBitMask := FormatDesc.Mask.b; + Header.PixelFormat.dwABitMask := FormatDesc.Mask.a; end; if (FormatDesc.HasAlpha) then @@ -8498,7 +8133,7 @@ begin // Assigning Data if Assigned(Data) then begin SetLength(fLines, GetHeight); - LineWidth := Trunc(GetWidth * TFormatDescriptor.Get(Format).PixelSize); + LineWidth := Trunc(GetWidth * TFormatDescriptor.Get(Format).BytesPerPixel); for Idx := 0 to GetHeight-1 do begin fLines[Idx] := Data; @@ -8524,7 +8159,7 @@ begin raise EglBitmap.Create('compressed formats not supported by video adapter'); glCompressedTexImage2D(aTarget, 0, FormatDesc.glInternalFormat, Width, Height, 0, FormatDesc.GetSize(fDimension), Data) end else if aBuildWithGlu then begin - gluBuild2DMipmaps(aTarget, FormatDesc.Components, Width, Height, + gluBuild2DMipmaps(aTarget, FormatDesc.ChannelCount, Width, Height, FormatDesc.glFormat, FormatDesc.glDataFormat, Data) end else begin glTexImage2D(aTarget, 0, FormatDesc.glInternalFormat, Width, Height, 0, -- 2.1.4