| @@ -227,10 +227,10 @@ unit glBitmap; | |||||
| // activate to enable build-in OpenGL support with dynamically linked methods | // activate to enable build-in OpenGL support with dynamically linked methods | ||||
| // use dglOpenGL.pas if not enabled | // use dglOpenGL.pas if not enabled | ||||
| {$DEFINE GLB_NATIVE_OGL_DYNAMIC} | |||||
| {.$DEFINE GLB_NATIVE_OGL_DYNAMIC} | |||||
| // activate to enable the support for SDL_surfaces | // activate to enable the support for SDL_surfaces | ||||
| {.$DEFINE GLB_SDL} | |||||
| {$DEFINE GLB_SDL} | |||||
| // activate to enable the support for TBitmap from Delphi (not lazarus) | // activate to enable the support for TBitmap from Delphi (not lazarus) | ||||
| {.$DEFINE GLB_DELPHI} | {.$DEFINE GLB_DELPHI} | ||||
| @@ -239,7 +239,7 @@ unit glBitmap; | |||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| // activate to enable the support of SDL_image to load files. (READ ONLY) | // activate to enable the support of SDL_image to load files. (READ ONLY) | ||||
| // If you enable SDL_image all other libraries will be ignored! | // If you enable SDL_image all other libraries will be ignored! | ||||
| {.$DEFINE GLB_SDL_IMAGE} | |||||
| {$DEFINE GLB_SDL_IMAGE} | |||||
| // activate to enable png support with the unit pngimage. You can download it from http://pngdelphi.sourceforge.net/ | // activate to enable png support with the unit pngimage. You can download it from http://pngdelphi.sourceforge.net/ | ||||
| // if you enable pngimage the libPNG will be ignored | // if you enable pngimage the libPNG will be ignored | ||||
| @@ -681,7 +681,7 @@ type | |||||
| EglBitmapException = class(Exception); | EglBitmapException = class(Exception); | ||||
| EglBitmapSizeToLargeException = class(EglBitmapException); | EglBitmapSizeToLargeException = class(EglBitmapException); | ||||
| EglBitmapNonPowerOfTwoException = class(EglBitmapException); | EglBitmapNonPowerOfTwoException = class(EglBitmapException); | ||||
| EglBitmapUnsupportedFormatFormat = class(EglBitmapException); | |||||
| EglBitmapUnsupportedFormat = class(EglBitmapException); | |||||
| //////////////////////////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| TglBitmapFormat = ( | TglBitmapFormat = ( | ||||
| @@ -977,14 +977,12 @@ type | |||||
| constructor Create(const aInstance: Cardinal; const aResourceID: Integer; const aResType: PChar); overload; | constructor Create(const aInstance: Cardinal; const aResourceID: Integer; const aResType: PChar); overload; | ||||
| {$ENDIF} | {$ENDIF} | ||||
| private | private | ||||
| {$IFDEF GLB_SUPPORT_PNG_READ} | |||||
| function LoadPNG(const aStream: TStream): Boolean; virtual; | |||||
| procedure SavePNG(const aStream: TStream); virtual; | |||||
| {$ENDIF} | |||||
| {$IFDEF GLB_SUPPORT_JPEG_READ} | |||||
| function LoadJPEG(const aStream: TStream): Boolean; virtual; | |||||
| procedure SaveJPEG(const aStream: TStream); virtual; | |||||
| {$ENDIF} | |||||
| {$IFDEF GLB_SUPPORT_PNG_READ} function LoadPNG(const aStream: TStream): Boolean; virtual; {$ENDIF} | |||||
| {$ifdef GLB_SUPPORT_PNG_WRITE} procedure SavePNG(const aStream: TStream); virtual; {$ENDIF} | |||||
| {$IFDEF GLB_SUPPORT_JPEG_READ} function LoadJPEG(const aStream: TStream): Boolean; virtual; {$ENDIF} | |||||
| {$IFDEF GLB_SUPPORT_JPEG_WRITE} procedure SaveJPEG(const aStream: TStream); virtual; {$ENDIF} | |||||
| function LoadBMP(const aStream: TStream): Boolean; virtual; | function LoadBMP(const aStream: TStream): Boolean; virtual; | ||||
| procedure SaveBMP(const aStream: TStream); virtual; | procedure SaveBMP(const aStream: TStream); virtual; | ||||
| @@ -1140,10 +1138,10 @@ type | |||||
| TFormatDescriptor = class(TObject) | TFormatDescriptor = class(TObject) | ||||
| private | private | ||||
| function GetRedMask: UInt64; | |||||
| function GetGreenMask: UInt64; | |||||
| function GetBlueMask: UInt64; | |||||
| function GetAlphaMask: UInt64; | |||||
| function GetRedMask: QWord; | |||||
| function GetGreenMask: QWord; | |||||
| function GetBlueMask: QWord; | |||||
| function GetAlphaMask: QWord; | |||||
| protected | protected | ||||
| fFormat: TglBitmapFormat; | fFormat: TglBitmapFormat; | ||||
| fWithAlpha: TglBitmapFormat; | fWithAlpha: TglBitmapFormat; | ||||
| @@ -1177,10 +1175,10 @@ type | |||||
| property Range: TglBitmapColorRec read fRange; | property Range: TglBitmapColorRec read fRange; | ||||
| property Shift: TShiftRec read fShift; | property Shift: TShiftRec read fShift; | ||||
| property RedMask: UInt64 read GetRedMask; | |||||
| property GreenMask: UInt64 read GetGreenMask; | |||||
| property BlueMask: UInt64 read GetBlueMask; | |||||
| property AlphaMask: UInt64 read GetAlphaMask; | |||||
| property RedMask: QWord read GetRedMask; | |||||
| property GreenMask: QWord read GetGreenMask; | |||||
| property BlueMask: QWord read GetBlueMask; | |||||
| property AlphaMask: QWord read GetAlphaMask; | |||||
| procedure Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); virtual; abstract; | procedure 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; | procedure Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); virtual; abstract; | ||||
| @@ -1193,7 +1191,7 @@ type | |||||
| function IsEmpty: Boolean; virtual; | function IsEmpty: Boolean; virtual; | ||||
| function HasAlpha: Boolean; virtual; | function HasAlpha: Boolean; virtual; | ||||
| function MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: UInt64): Boolean; virtual; | |||||
| function MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: QWord): Boolean; virtual; | |||||
| procedure PreparePixel(out aPixel: TglBitmapPixelData); virtual; | procedure PreparePixel(out aPixel: TglBitmapPixelData); virtual; | ||||
| @@ -1532,17 +1530,17 @@ type | |||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| TbmpBitfieldFormat = class(TFormatDescriptor) | TbmpBitfieldFormat = class(TFormatDescriptor) | ||||
| private | private | ||||
| procedure SetRedMask (const aValue: UInt64); | |||||
| procedure SetGreenMask(const aValue: UInt64); | |||||
| procedure SetBlueMask (const aValue: UInt64); | |||||
| procedure SetAlphaMask(const aValue: UInt64); | |||||
| procedure SetRedMask (const aValue: QWord); | |||||
| procedure SetGreenMask(const aValue: QWord); | |||||
| procedure SetBlueMask (const aValue: QWord); | |||||
| procedure SetAlphaMask(const aValue: QWord); | |||||
| procedure Update(aMask: UInt64; out aRange: Cardinal; out aShift: Byte); | |||||
| procedure Update(aMask: QWord; out aRange: Cardinal; out aShift: Byte); | |||||
| public | public | ||||
| property RedMask: UInt64 read GetRedMask write SetRedMask; | |||||
| property GreenMask: UInt64 read GetGreenMask write SetGreenMask; | |||||
| property BlueMask: UInt64 read GetBlueMask write SetBlueMask; | |||||
| property AlphaMask: UInt64 read GetAlphaMask write SetAlphaMask; | |||||
| property RedMask: QWord read GetRedMask write SetRedMask; | |||||
| property GreenMask: QWord read GetGreenMask write SetGreenMask; | |||||
| property BlueMask: QWord read GetBlueMask write SetBlueMask; | |||||
| property AlphaMask: QWord read GetAlphaMask write SetAlphaMask; | |||||
| property PixelSize: Single read fPixelSize write fPixelSize; | property PixelSize: Single read fPixelSize write fPixelSize; | ||||
| @@ -1803,7 +1801,7 @@ begin | |||||
| end; | end; | ||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| function GetTopMostBit(aBitSet: UInt64): Integer; | |||||
| function GetTopMostBit(aBitSet: QWord): Integer; | |||||
| begin | begin | ||||
| result := 0; | result := 0; | ||||
| while aBitSet > 0 do begin | while aBitSet > 0 do begin | ||||
| @@ -1813,7 +1811,7 @@ begin | |||||
| end; | end; | ||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| function CountSetBits(aBitSet: UInt64): Integer; | |||||
| function CountSetBits(aBitSet: QWord): Integer; | |||||
| begin | begin | ||||
| result := 0; | result := 0; | ||||
| while aBitSet > 0 do begin | while aBitSet > 0 do begin | ||||
| @@ -2126,8 +2124,10 @@ end; | |||||
| {$ENDIF} | {$ENDIF} | ||||
| *) | *) | ||||
| (* TODO GLB_SDL_IMAGE | |||||
| {$IFDEF GLB_SDL_IMAGE} | {$IFDEF GLB_SDL_IMAGE} | ||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| // SDL Image Helper ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| function glBitmapRWseek(context: PSDL_RWops; offset: Integer; whence: Integer): Integer; cdecl; | function glBitmapRWseek(context: PSDL_RWops; offset: Integer; whence: Integer): Integer; cdecl; | ||||
| begin | begin | ||||
| result := TStream(context^.unknown.data1).Seek(offset, whence); | result := TStream(context^.unknown.data1).Seek(offset, whence); | ||||
| @@ -2162,7 +2162,6 @@ begin | |||||
| result^.unknown.data1 := Stream; | result^.unknown.data1 := Stream; | ||||
| end; | end; | ||||
| {$ENDIF} | {$ENDIF} | ||||
| *) | |||||
| (* TODO LoadFuncs | (* TODO LoadFuncs | ||||
| function LoadTexture(Filename: String; var Texture: Cardinal{$IFDEF GLB_DELPHI}; LoadFromRes : Boolean; Instance: Cardinal{$ENDIF}): Boolean; | function LoadTexture(Filename: String; var Texture: Cardinal{$IFDEF GLB_DELPHI}; LoadFromRes : Boolean; Instance: Cardinal{$ENDIF}): Boolean; | ||||
| @@ -2366,25 +2365,25 @@ end; | |||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| //TglBitmapFormatDescriptor/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //TglBitmapFormatDescriptor/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| function TFormatDescriptor.GetRedMask: UInt64; | |||||
| function TFormatDescriptor.GetRedMask: QWord; | |||||
| begin | begin | ||||
| result := fRange.r shl fShift.r; | result := fRange.r shl fShift.r; | ||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| function TFormatDescriptor.GetGreenMask: UInt64; | |||||
| function TFormatDescriptor.GetGreenMask: QWord; | |||||
| begin | begin | ||||
| result := fRange.g shl fShift.g; | result := fRange.g shl fShift.g; | ||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| function TFormatDescriptor.GetBlueMask: UInt64; | |||||
| function TFormatDescriptor.GetBlueMask: QWord; | |||||
| begin | begin | ||||
| result := fRange.b shl fShift.b; | result := fRange.b shl fShift.b; | ||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| function TFormatDescriptor.GetAlphaMask: UInt64; | |||||
| function TFormatDescriptor.GetAlphaMask: QWord; | |||||
| begin | begin | ||||
| result := fRange.a shl fShift.a; | result := fRange.a shl fShift.a; | ||||
| end; | end; | ||||
| @@ -2447,7 +2446,7 @@ begin | |||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| function TFormatDescriptor.MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: UInt64): Boolean; | |||||
| function TFormatDescriptor.MaskMatch(const aRedMask, aGreenMask, aBlueMask, aAlphaMask: QWord): Boolean; | |||||
| begin | begin | ||||
| result := false; | result := false; | ||||
| @@ -3781,31 +3780,31 @@ end; | |||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| //TBitfieldFormat///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | //TBitfieldFormat///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TbmpBitfieldFormat.SetRedMask(const aValue: UInt64); | |||||
| procedure TbmpBitfieldFormat.SetRedMask(const aValue: QWord); | |||||
| begin | begin | ||||
| Update(aValue, fRange.r, fShift.r); | Update(aValue, fRange.r, fShift.r); | ||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TbmpBitfieldFormat.SetGreenMask(const aValue: UInt64); | |||||
| procedure TbmpBitfieldFormat.SetGreenMask(const aValue: QWord); | |||||
| begin | begin | ||||
| Update(aValue, fRange.g, fShift.g); | Update(aValue, fRange.g, fShift.g); | ||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TbmpBitfieldFormat.SetBlueMask(const aValue: UInt64); | |||||
| procedure TbmpBitfieldFormat.SetBlueMask(const aValue: QWord); | |||||
| begin | begin | ||||
| Update(aValue, fRange.b, fShift.b); | Update(aValue, fRange.b, fShift.b); | ||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TbmpBitfieldFormat.SetAlphaMask(const aValue: UInt64); | |||||
| procedure TbmpBitfieldFormat.SetAlphaMask(const aValue: QWord); | |||||
| begin | begin | ||||
| Update(aValue, fRange.a, fShift.a); | Update(aValue, fRange.a, fShift.a); | ||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TbmpBitfieldFormat.Update(aMask: UInt64; out aRange: Cardinal; out | |||||
| procedure TbmpBitfieldFormat.Update(aMask: QWord; out aRange: Cardinal; out | |||||
| aShift: Byte); | aShift: Byte); | ||||
| begin | begin | ||||
| aShift := 0; | aShift := 0; | ||||
| @@ -3829,10 +3828,8 @@ end; | |||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TbmpBitfieldFormat.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); | procedure TbmpBitfieldFormat.Map(const aPixel: TglBitmapPixelData; var aData: PByte; var aMapData: Pointer); | ||||
| var | var | ||||
| data: UInt64; | |||||
| data: QWord; | |||||
| s: Integer; | s: Integer; | ||||
| type | |||||
| PUInt64 = ^UInt64; | |||||
| begin | begin | ||||
| data := | data := | ||||
| ((aPixel.Data.r and fRange.r) shl fShift.r) or | ((aPixel.Data.r and fRange.r) shl fShift.r) or | ||||
| @@ -3844,7 +3841,7 @@ begin | |||||
| 1: aData^ := data; | 1: aData^ := data; | ||||
| 2: PWord(aData)^ := data; | 2: PWord(aData)^ := data; | ||||
| 4: PCardinal(aData)^ := data; | 4: PCardinal(aData)^ := data; | ||||
| 8: PUInt64(aData)^ := data; | |||||
| 8: PQWord(aData)^ := data; | |||||
| else | else | ||||
| raise EglBitmapException.CreateFmt('invalid pixel size: %.1f', [fPixelSize]); | raise EglBitmapException.CreateFmt('invalid pixel size: %.1f', [fPixelSize]); | ||||
| end; | end; | ||||
| @@ -3854,17 +3851,15 @@ end; | |||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TbmpBitfieldFormat.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); | procedure TbmpBitfieldFormat.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); | ||||
| var | var | ||||
| data: UInt64; | |||||
| data: QWord; | |||||
| s, i: Integer; | s, i: Integer; | ||||
| type | |||||
| PUInt64 = ^UInt64; | |||||
| begin | begin | ||||
| s := Round(fPixelSize); | s := Round(fPixelSize); | ||||
| case s of | case s of | ||||
| 1: data := aData^; | 1: data := aData^; | ||||
| 2: data := PWord(aData)^; | 2: data := PWord(aData)^; | ||||
| 4: data := PCardinal(aData)^; | 4: data := PCardinal(aData)^; | ||||
| 8: data := PUInt64(aData)^; | |||||
| 8: data := PQWord(aData)^; | |||||
| else | else | ||||
| raise EglBitmapException.CreateFmt('invalid pixel size: %.1f', [fPixelSize]); | raise EglBitmapException.CreateFmt('invalid pixel size: %.1f', [fPixelSize]); | ||||
| end; | end; | ||||
| @@ -3956,10 +3951,8 @@ end; | |||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TbmpColorTableFormat.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); | procedure TbmpColorTableFormat.Unmap(var aData: PByte; out aPixel: TglBitmapPixelData; var aMapData: Pointer); | ||||
| type | |||||
| PUInt64 = ^UInt64; | |||||
| var | var | ||||
| idx: UInt64; | |||||
| idx: QWord; | |||||
| s: Integer; | s: Integer; | ||||
| bits: Byte; | bits: Byte; | ||||
| f: Single; | f: Single; | ||||
| @@ -3972,7 +3965,7 @@ begin | |||||
| 1: idx := aData^; | 1: idx := aData^; | ||||
| 2: idx := PWord(aData)^; | 2: idx := PWord(aData)^; | ||||
| 4: idx := PCardinal(aData)^; | 4: idx := PCardinal(aData)^; | ||||
| 8: idx := PUInt64(aData)^; | |||||
| 8: idx := PQWord(aData)^; | |||||
| else | else | ||||
| raise EglBitmapException.CreateFmt('invalid pixel size: %.3f', [fPixelSize]); | raise EglBitmapException.CreateFmt('invalid pixel size: %.3f', [fPixelSize]); | ||||
| end; | end; | ||||
| @@ -4227,7 +4220,7 @@ begin | |||||
| if fFormat = aValue then | if fFormat = aValue then | ||||
| exit; | exit; | ||||
| if TFormatDescriptor.Get(Format).PixelSize <> TFormatDescriptor.Get(aValue).PixelSize then | if TFormatDescriptor.Get(Format).PixelSize <> TFormatDescriptor.Get(aValue).PixelSize then | ||||
| raise EglBitmapUnsupportedFormatFormat.Create('SetInternalFormat - ' + UNSUPPORTED_FORMAT); | |||||
| raise EglBitmapUnsupportedFormat.Create('SetFormat'); | |||||
| SetDataPointer(Data, aValue, Width, Height); | SetDataPointer(Data, aValue, Width, Height); | ||||
| end; | end; | ||||
| @@ -4603,42 +4596,37 @@ var | |||||
| Row, RowSize: Integer; | Row, RowSize: Integer; | ||||
| SourceData, TmpData: PByte; | SourceData, TmpData: PByte; | ||||
| TempDepth: Integer; | TempDepth: Integer; | ||||
| Pix: TglBitmapPixelData; | |||||
| FormatDesc: TglBitmapFormatDescriptor; | |||||
| FormatDesc: TFormatDescriptor; | |||||
| function GetRowPointer(Row: Integer): pByte; | function GetRowPointer(Row: Integer): pByte; | ||||
| begin | begin | ||||
| result := Surface.pixels; | |||||
| result := aSurface.pixels; | |||||
| Inc(result, Row * RowSize); | Inc(result, Row * RowSize); | ||||
| end; | end; | ||||
| begin | begin | ||||
| result := false; | result := false; | ||||
| (* TODO | |||||
| if not FormatIsUncompressed(InternalFormat) then | |||||
| raise EglBitmapUnsupportedInternalFormat.Create('AssignToSurface - ' + UNSUPPORTED_INTERNAL_FORMAT); | |||||
| *) | |||||
| FormatDesc := TFormatDescriptor.Get(Format); | |||||
| if FormatDesc.IsCompressed then | |||||
| raise EglBitmapUnsupportedFormat.Create('AssignToSurface'); | |||||
| FormatDesc := FORMAT_DESCRIPTORS[Format]; | |||||
| if Assigned(Data) then begin | if Assigned(Data) then begin | ||||
| case Trunc(FormatDesc.GetSize) of | |||||
| case Trunc(FormatDesc.PixelSize) of | |||||
| 1: TempDepth := 8; | 1: TempDepth := 8; | ||||
| 2: TempDepth := 16; | 2: TempDepth := 16; | ||||
| 3: TempDepth := 24; | 3: TempDepth := 24; | ||||
| 4: TempDepth := 32; | 4: TempDepth := 32; | ||||
| else | else | ||||
| raise EglBitmapException.Create('AssignToSurface - ' + UNSUPPORTED_INTERNAL_FORMAT); | |||||
| raise EglBitmapUnsupportedFormat.Create('AssignToSurface'); | |||||
| end; | end; | ||||
| FormatDesc.PreparePixel(Pix); | |||||
| with Pix.PixelDesc do | |||||
| Surface := SDL_CreateRGBSurface(SDL_SWSURFACE, Width, Height, TempDepth, | |||||
| RedRange shl RedShift, GreenRange shl GreenShift, BlueRange shl BlueShift, AlphaRange shl AlphaShift); | |||||
| aSurface := SDL_CreateRGBSurface(SDL_SWSURFACE, Width, Height, TempDepth, | |||||
| FormatDesc.RedMask, FormatDesc.GreenMask, FormatDesc.BlueMask, FormatDesc.AlphaMask); | |||||
| SourceData := Data; | SourceData := Data; | ||||
| RowSize := Ceil(FileWidth * FormatDesc.GetSize); | |||||
| RowSize := FormatDesc.GetSize(FileWidth, 1); | |||||
| for Row := 0 to FileHeight -1 do begin | |||||
| for Row := 0 to FileHeight-1 do begin | |||||
| TmpData := GetRowPointer(Row); | TmpData := GetRowPointer(Row); | ||||
| if Assigned(TmpData) then begin | if Assigned(TmpData) then begin | ||||
| Move(SourceData^, TmpData^, RowSize); | Move(SourceData^, TmpData^, RowSize); | ||||
| @@ -4654,34 +4642,31 @@ function TglBitmap.AssignFromSurface(const aSurface: PSDL_Surface): Boolean; | |||||
| var | var | ||||
| pSource, pData, pTempData: PByte; | pSource, pData, pTempData: PByte; | ||||
| Row, RowSize, TempWidth, TempHeight: Integer; | Row, RowSize, TempWidth, TempHeight: Integer; | ||||
| IntFormat, f: TglBitmapInternalFormat; | |||||
| FormatDesc: TglBitmapFormatDescriptor; | |||||
| IntFormat: TglBitmapFormat; | |||||
| FormatDesc: TFormatDescriptor; | |||||
| function GetRowPointer(Row: Integer): pByte; | function GetRowPointer(Row: Integer): pByte; | ||||
| begin | begin | ||||
| result := Surface^.pixels; | |||||
| result := aSurface^.pixels; | |||||
| Inc(result, Row * RowSize); | Inc(result, Row * RowSize); | ||||
| end; | end; | ||||
| begin | begin | ||||
| result := false; | result := false; | ||||
| if (Assigned(Surface)) then begin | |||||
| with Surface^.format^ do begin | |||||
| IntFormat := tfEmpty; | |||||
| for f := Low(f) to High(f) do begin | |||||
| if FORMAT_DESCRIPTORS[f].MaskMatch(RMask, GMask, BMask, AMask) then begin | |||||
| IntFormat := f; | |||||
| if (Assigned(aSurface)) then begin | |||||
| with aSurface^.format^ do begin | |||||
| for IntFormat := High(TglBitmapFormat) to Low(TglBitmapFormat) do begin | |||||
| FormatDesc := TFormatDescriptor.Get(IntFormat); | |||||
| if (FormatDesc.MaskMatch(RMask, GMask, BMask, AMask)) then | |||||
| break; | break; | ||||
| end; | |||||
| end; | end; | ||||
| if (IntFormat = tfEmpty) then | if (IntFormat = tfEmpty) then | ||||
| raise EglBitmapException.Create('AssignFromSurface - Invalid Pixelformat.'); | raise EglBitmapException.Create('AssignFromSurface - Invalid Pixelformat.'); | ||||
| end; | end; | ||||
| FormatDesc := FORMAT_DESCRIPTORS[IntFormat]; | |||||
| TempWidth := Surface^.w; | |||||
| TempHeight := Surface^.h; | |||||
| RowSize := Trunc(TempWidth * FormatDesc.GetSize); | |||||
| TempWidth := aSurface^.w; | |||||
| TempHeight := aSurface^.h; | |||||
| RowSize := FormatDesc.GetSize(TempWidth, 1); | |||||
| GetMem(pData, TempHeight * RowSize); | GetMem(pData, TempHeight * RowSize); | ||||
| try | try | ||||
| pTempData := pData; | pTempData := pData; | ||||
| @@ -4721,9 +4706,9 @@ begin | |||||
| AlphaInterleave := 0; | AlphaInterleave := 0; | ||||
| case Format of | case Format of | ||||
| ifLuminance8Alpha8: | |||||
| tfLuminance8Alpha8: | |||||
| AlphaInterleave := 1; | AlphaInterleave := 1; | ||||
| ifBGRA8, ifRGBA8: | |||||
| tfBGRA8, tfRGBA8: | |||||
| AlphaInterleave := 3; | AlphaInterleave := 3; | ||||
| end; | end; | ||||
| @@ -4745,14 +4730,14 @@ begin | |||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| function TglBitmap.AddAlphaFromSurface(const aSurface: PSDL_Surface; const aFunc: TglBitmapFunction; const aArgs: PtrInt): Boolean; | |||||
| function TglBitmap.AddAlphaFromSurface(const aSurface: PSDL_Surface; const aFunc: TglBitmapFunction = nil; const aArgs: Pointer = nil): Boolean; | |||||
| var | var | ||||
| bmp: TglBitmap2D; | bmp: TglBitmap2D; | ||||
| begin | begin | ||||
| bmp := TglBitmap2D.Create; | bmp := TglBitmap2D.Create; | ||||
| try | try | ||||
| bmp.AssignFromSurface(Surface); | |||||
| result := AddAlphaFromGlBitmap(bmp, Func, CustomData); | |||||
| bmp.AssignFromSurface(aSurface); | |||||
| result := AddAlphaFromGlBitmap(bmp, aFunc, aArgs); | |||||
| finally | finally | ||||
| bmp.Free; | bmp.Free; | ||||
| end; | end; | ||||
| @@ -5147,7 +5132,7 @@ begin | |||||
| FormatDesc := TFormatDescriptor.Get(Format); | FormatDesc := TFormatDescriptor.Get(Format); | ||||
| if Assigned(Data) then begin | if Assigned(Data) then begin | ||||
| if FormatDesc.IsCompressed or not FormatDesc.HasAlpha then | if FormatDesc.IsCompressed or not FormatDesc.HasAlpha then | ||||
| raise EglBitmapUnsupportedFormatFormat.Create('RemoveAlpha - ' + UNSUPPORTED_FORMAT); | |||||
| raise EglBitmapUnsupportedFormat.Create('RemoveAlpha'); | |||||
| result := ConvertTo(FormatDesc.WithoutAlpha); | result := ConvertTo(FormatDesc.WithoutAlpha); | ||||
| end; | end; | ||||
| end; | end; | ||||
| @@ -5522,7 +5507,7 @@ begin | |||||
| Surface := IMG_LoadPNG_RW(RWops); | Surface := IMG_LoadPNG_RW(RWops); | ||||
| try | try | ||||
| AssignFromSurface(Surface); | AssignFromSurface(Surface); | ||||
| Rresult := true; | |||||
| result := true; | |||||
| finally | finally | ||||
| SDL_FreeSurface(Surface); | SDL_FreeSurface(Surface); | ||||
| end; | end; | ||||
| @@ -5922,40 +5907,6 @@ type | |||||
| DestBuffer: array [1..4096] of byte; | DestBuffer: array [1..4096] of byte; | ||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| { | |||||
| procedure glBitmap_libJPEG_error_exit(cinfo: j_common_ptr); cdecl; | |||||
| var | |||||
| Msg: String; | |||||
| begin | |||||
| SetLength(Msg, 256); | |||||
| cinfo^.err^.format_message(cinfo, pChar(Msg)); | |||||
| Writeln('ERROR [' + IntToStr(cinfo^.err^.msg_code) + '] ' + Msg); | |||||
| cinfo^.global_state := 0; | |||||
| jpeg_abort(cinfo); | |||||
| end; | |||||
| } | |||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| { | |||||
| procedure glBitmap_libJPEG_output_message(cinfo: j_common_ptr); cdecl; | |||||
| var | |||||
| Msg: String; | |||||
| begin | |||||
| SetLength(Msg, 256); | |||||
| cinfo^.err^.format_message(cinfo, pChar(Msg)); | |||||
| Writeln('OUTPUT [' + IntToStr(cinfo^.err^.msg_code) + '] ' + Msg); | |||||
| cinfo^.global_state := 0; | |||||
| end; | |||||
| } | |||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| { | |||||
| procedure glBitmap_libJPEG_init_source(cinfo: j_decompress_ptr); cdecl; | |||||
| begin | |||||
| end; | |||||
| } | |||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| function glBitmap_libJPEG_fill_input_buffer(cinfo: j_decompress_ptr): boolean; cdecl; | function glBitmap_libJPEG_fill_input_buffer(cinfo: j_decompress_ptr): boolean; cdecl; | ||||
| var | var | ||||
| @@ -5997,20 +5948,6 @@ begin | |||||
| end; | end; | ||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| { | |||||
| procedure glBitmap_libJPEG_term_source(cinfo: j_decompress_ptr); cdecl; | |||||
| begin | |||||
| end; | |||||
| } | |||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |||||
| { | |||||
| procedure glBitmap_libJPEG_init_destination(cinfo: j_compress_ptr); cdecl; | |||||
| begin | |||||
| end; | |||||
| } | |||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| function glBitmap_libJPEG_empty_output_buffer(cinfo: j_compress_ptr): boolean; cdecl; | function glBitmap_libJPEG_empty_output_buffer(cinfo: j_compress_ptr): boolean; cdecl; | ||||
| var | var | ||||
| @@ -6062,7 +5999,7 @@ var | |||||
| begin | begin | ||||
| result := false; | result := false; | ||||
| RWops := glBitmapCreateRWops(Stream); | |||||
| RWops := glBitmapCreateRWops(aStream); | |||||
| try | try | ||||
| if IMG_isJPG(RWops) > 0 then begin | if IMG_isJPG(RWops) > 0 then begin | ||||
| Surface := IMG_LoadJPG_RW(RWops); | Surface := IMG_LoadJPG_RW(RWops); | ||||
| @@ -6622,7 +6559,7 @@ var | |||||
| begin | begin | ||||
| if not (ftBMP in FormatGetSupportedFiles(Format)) then | if not (ftBMP in FormatGetSupportedFiles(Format)) then | ||||
| raise EglBitmapUnsupportedFormatFormat.Create('SaveBMP - ' + UNSUPPORTED_FORMAT); | |||||
| raise EglBitmapUnsupportedFormat.Create('SaveBMP'); | |||||
| Converter := nil; | Converter := nil; | ||||
| FormatDesc := TFormatDescriptor.Get(Format); | FormatDesc := TFormatDescriptor.Get(Format); | ||||
| @@ -6687,7 +6624,7 @@ begin | |||||
| Info.biCompression := BMP_COMP_BITFIELDS; | Info.biCompression := BMP_COMP_BITFIELDS; | ||||
| end; | end; | ||||
| else | else | ||||
| raise EglBitmapUnsupportedFormatFormat.Create('SaveBMP - ' + UNSUPPORTED_FORMAT); | |||||
| raise EglBitmapUnsupportedFormat.Create('SaveBMP - ' + UNSUPPORTED_FORMAT); | |||||
| end; | end; | ||||
| Info.biXPelsPerMeter := 2835; | Info.biXPelsPerMeter := 2835; | ||||
| Info.biYPelsPerMeter := 2835; | Info.biYPelsPerMeter := 2835; | ||||
| @@ -6804,7 +6741,7 @@ const | |||||
| function TglBitmap.LoadTGA(const aStream: TStream): Boolean; | function TglBitmap.LoadTGA(const aStream: TStream): Boolean; | ||||
| var | var | ||||
| Header: TTGAHeader; | Header: TTGAHeader; | ||||
| ImageData: PByte; | |||||
| ImageData: System.PByte; | |||||
| StartPosition: Int64; | StartPosition: Int64; | ||||
| PixelSize, LineSize: Integer; | PixelSize, LineSize: Integer; | ||||
| tgaFormat: TglBitmapFormat; | tgaFormat: TglBitmapFormat; | ||||
| @@ -6822,7 +6759,7 @@ const | |||||
| procedure ReadUncompressed; | procedure ReadUncompressed; | ||||
| var | var | ||||
| i, j: Integer; | i, j: Integer; | ||||
| buf, tmp1, tmp2: PByte; | |||||
| buf, tmp1, tmp2: System.PByte; | |||||
| begin | begin | ||||
| buf := nil; | buf := nil; | ||||
| if (Counter.X.dir < 0) then | if (Counter.X.dir < 0) then | ||||
| @@ -6856,7 +6793,7 @@ const | |||||
| ///////////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////////// | ||||
| var | var | ||||
| TmpData: PByte; | |||||
| TmpData: System.PByte; | |||||
| LinePixelsRead: Integer; | LinePixelsRead: Integer; | ||||
| procedure CheckLine; | procedure CheckLine; | ||||
| begin | begin | ||||
| @@ -7083,7 +7020,7 @@ var | |||||
| Converter: TFormatDescriptor; | Converter: TFormatDescriptor; | ||||
| begin | begin | ||||
| if not (ftTGA in FormatGetSupportedFiles(Format)) then | if not (ftTGA in FormatGetSupportedFiles(Format)) then | ||||
| raise EglBitmapUnsupportedFormatFormat.Create('SaveTGA - ' + UNSUPPORTED_FORMAT); | |||||
| raise EglBitmapUnsupportedFormat.Create('SaveTGA'); | |||||
| //prepare header | //prepare header | ||||
| FillChar(Header{%H-}, SizeOf(Header), 0); | FillChar(Header{%H-}, SizeOf(Header), 0); | ||||
| @@ -7296,7 +7233,7 @@ var | |||||
| var | var | ||||
| StreamPos: Int64; | StreamPos: Int64; | ||||
| x, y, LineSize, RowSize, Magic: Cardinal; | x, y, LineSize, RowSize, Magic: Cardinal; | ||||
| NewImage, TmpData, RowData, SrcData: PByte; | |||||
| NewImage, TmpData, RowData, SrcData: System.PByte; | |||||
| SourceMD, DestMD: Pointer; | SourceMD, DestMD: Pointer; | ||||
| Pixel: TglBitmapPixelData; | Pixel: TglBitmapPixelData; | ||||
| ddsFormat: TglBitmapFormat; | ddsFormat: TglBitmapFormat; | ||||
| @@ -7399,7 +7336,7 @@ var | |||||
| FormatDesc: TFormatDescriptor; | FormatDesc: TFormatDescriptor; | ||||
| begin | begin | ||||
| if not (ftDDS in FormatGetSupportedFiles(Format)) then | if not (ftDDS in FormatGetSupportedFiles(Format)) then | ||||
| raise EglBitmapUnsupportedFormatFormat.Create('SaveDDS - ' + UNSUPPORTED_FORMAT); | |||||
| raise EglBitmapUnsupportedFormat.Create('SaveDDS'); | |||||
| FormatDesc := TFormatDescriptor.Get(Format); | FormatDesc := TFormatDescriptor.Get(Format); | ||||
| @@ -7542,7 +7479,7 @@ var | |||||
| begin | begin | ||||
| FormatDesc := TFormatDescriptor.Get(Format); | FormatDesc := TFormatDescriptor.Get(Format); | ||||
| if FormatDesc.IsCompressed then | if FormatDesc.IsCompressed then | ||||
| raise EglBitmapUnsupportedFormatFormat.Create('TglBitmap2D.GrabScreen - ' + UNSUPPORTED_FORMAT); | |||||
| raise EglBitmapUnsupportedFormat.Create('TglBitmap2D.GrabScreen'); | |||||
| w := aRight - aLeft; | w := aRight - aLeft; | ||||
| h := aBottom - aTop; | h := aBottom - aTop; | ||||