+// activate to enable Lazarus TPortableNetworkGraphic support
+// if you enable this pngImage and libPNG will be ignored
+{$DEFINE GLB_LAZ_PNG}
+
// activate to enable png support with the unit pngimage -> http://pngdelphi.sourceforge.net/
// if you enable pngimage the libPNG will be ignored
{.$DEFINE GLB_PNGIMAGE}
+// activate to enable Lazarus TJPEGImage support
+// if you enable this delphi jpegs and libJPEG will be ignored
+{$DEFINE GLB_LAZ_JPEG}
+
// if you enable delphi jpegs the libJPEG will be ignored
{.$DEFINE GLB_DELPHI_JPEG}
{$MESSAGE warn 'SDL_image won''t work without SDL. SDL will be activated.'}
{$DEFINE GLB_SDL}
{$ENDIF}
+
+ {$IFDEF GLB_LAZ_PNG}
+ {$MESSAGE warn 'The Lazarus TPortableNetworkGraphics will be ignored because you are using SDL_image.'}
+ {$undef GLB_LAZ_PNG}
+ {$ENDIF}
+
{$IFDEF GLB_PNGIMAGE}
{$MESSAGE warn 'The unit pngimage will be ignored because you are using SDL_image.'}
{$undef GLB_PNGIMAGE}
{$ENDIF}
+
+ {$IFDEF GLB_LAZ_JPEG}
+ {$MESSAGE warn 'The Lazarus TJPEGImage will be ignored because you are using SDL_image.'}
+ {$undef GLB_LAZ_JPEG}
+ {$ENDIF}
+
{$IFDEF GLB_DELPHI_JPEG}
{$MESSAGE warn 'The unit JPEG will be ignored because you are using SDL_image.'}
{$undef GLB_DELPHI_JPEG}
{$ENDIF}
+
{$IFDEF GLB_LIB_PNG}
{$MESSAGE warn 'The library libPNG will be ignored because you are using SDL_image.'}
{$undef GLB_LIB_PNG}
{$ENDIF}
+
{$IFDEF GLB_LIB_JPEG}
{$MESSAGE warn 'The library libJPEG will be ignored because you are using SDL_image.'}
{$undef GLB_LIB_JPEG}
{$DEFINE GLB_SUPPORT_JPEG_READ}
{$ENDIF}
+// Lazarus TPortableNetworkGraphic
+{$IFDEF GLB_LAZ_PNG}
+ {$IFNDEF GLB_LAZARUS}
+ {$MESSAGE warn 'Lazarus TPortableNetworkGraphic won''t work without Lazarus. Lazarus will be activated.'}
+ {$DEFINE GLB_LAZARUS}
+ {$ENDIF}
+
+ {$IFDEF GLB_PNGIMAGE}
+ {$MESSAGE warn 'The pngimage will be ignored if you are using Lazarus TPortableNetworkGraphic.'}
+ {$undef GLB_PNGIMAGE}
+ {$ENDIF}
+
+ {$IFDEF GLB_LIB_PNG}
+ {$MESSAGE warn 'The library libPNG will be ignored if you are using Lazarus TPortableNetworkGraphic.'}
+ {$undef GLB_LIB_PNG}
+ {$ENDIF}
+
+ {$DEFINE GLB_SUPPORT_PNG_READ}
+ {$DEFINE GLB_SUPPORT_PNG_WRITE}
+{$ENDIF}
+
// PNG Image
{$IFDEF GLB_PNGIMAGE}
{$IFDEF GLB_LIB_PNG}
{$DEFINE GLB_SUPPORT_PNG_WRITE}
{$ENDIF}
+// Lazarus TJPEGImage
+{$IFDEF GLB_LAZ_JPEG}
+ {$IFNDEF GLB_LAZARUS}
+ {$MESSAGE warn 'Lazarus TJPEGImage won''t work without Lazarus. Lazarus will be activated.'}
+ {$DEFINE GLB_LAZARUS}
+ {$ENDIF}
+
+ {$IFDEF GLB_DELPHI_JPEG}
+ {$MESSAGE warn 'The Delphi JPEGImage will be ignored if you are using the Lazarus TJPEGImage.'}
+ {$undef GLB_DELPHI_JPEG}
+ {$ENDIF}
+
+ {$IFDEF GLB_LIB_JPEG}
+ {$MESSAGE warn 'The library libJPEG will be ignored if you are using the Lazarus TJPEGImage.'}
+ {$undef GLB_LIB_JPEG}
+ {$ENDIF}
+
+ {$DEFINE GLB_SUPPORT_JPEG_READ}
+ {$DEFINE GLB_SUPPORT_JPEG_WRITE}
+{$ENDIF}
+
// JPEG Image
{$IFDEF GLB_DELPHI_JPEG}
{$IFDEF GLB_LIB_JPEG}
interface
uses
- {$IFNDEF GLB_NATIVE_OGL} dglOpenGL, {$ENDIF}
+ {$IFNDEF GLB_NATIVE_OGL} dglOpenGL, {$ENDIF}
{$IF DEFINED(GLB_WIN) AND
- DEFINED(GLB_NATIVE_OGL)} windows, {$IFEND}
+ DEFINED(GLB_NATIVE_OGL)} windows, {$IFEND}
- {$IFDEF GLB_SDL} SDL, {$ENDIF}
- {$IFDEF GLB_LAZARUS} IntfGraphics, GraphType, {$ENDIF}
- {$IFDEF GLB_DELPHI} Dialogs, Graphics, {$ENDIF}
+ {$IFDEF GLB_SDL} SDL, {$ENDIF}
+ {$IFDEF GLB_LAZARUS} IntfGraphics, GraphType, Graphics, {$ENDIF}
+ {$IFDEF GLB_DELPHI} Dialogs, Graphics, {$ENDIF}
- {$IFDEF GLB_SDL_IMAGE} SDL_image, {$ENDIF}
- {$IFDEF GLB_PNGIMAGE} pngimage, {$ENDIF}
- {$IFDEF GLB_LIB_PNG} libPNG, {$ENDIF}
- {$IFDEF GLB_DELPHI_JPEG} JPEG, {$ENDIF}
- {$IFDEF GLB_LIB_JPEG} libJPEG, {$ENDIF}
+ {$IFDEF GLB_SDL_IMAGE} SDL_image, {$ENDIF}
+ {$IFDEF GLB_PNGIMAGE} pngimage, {$ENDIF}
+ {$IFDEF GLB_LIB_PNG} libPNG, {$ENDIF}
+ {$IFDEF GLB_DELPHI_JPEG} JPEG, {$ENDIF}
+ {$IFDEF GLB_LIB_JPEG} libJPEG, {$ENDIF}
Classes, SysUtils;
end;
{$IFDEF GLB_SUPPORT_PNG_READ}
-{$IF DEFINED(GLB_SDL_IMAGE)}
+{$IF DEFINED(GLB_LAZ_PNG)}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//PNG/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TglBitmap.LoadPNG(const aStream: TStream): Boolean;
var
+ png: TPortableNetworkGraphic;
+ intf: TLazIntfImage;
+ StreamPos: Int64;
+begin
+ result := true;
+ StreamPos := aStream.Position;
+ png := TPortableNetworkGraphic.Create;
+ try try
+ png.LoadFromStream(aStream);
+ intf := png.CreateIntfImage;
+ try try
+ AssignFromLazIntfImage(intf);
+ except
+ result := false;
+ aStream.Position := StreamPos;
+ exit;
+ end;
+ finally
+ intf.Free;
+ end;
+ except
+ result := false;
+ aStream.Position := StreamPos;
+ exit;
+ end;
+ finally
+ png.Free;
+ end;
+end;
+
+{$ELSEIF DEFINED(GLB_SDL_IMAGE)}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function TglBitmap.LoadPNG(const aStream: TStream): Boolean;
+var
Surface: PSDL_Surface;
RWops: PSDL_RWops;
begin
end;
{$ENDIF}
-{$IF DEFINED(GLB_LIB_PNG)}
+{$IF DEFINED(GLB_LAZ_PNG)}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap.SavePNG(const aStream: TStream);
+var
+ png: TPortableNetworkGraphic;
+ intf: TLazIntfImage;
+begin
+ png := TPortableNetworkGraphic.Create;
+ intf := TLazIntfImage.Create(0, 0);
+ try
+ if not AssignToLazIntfImage(intf) then
+ raise EglBitmap.Create('unable to create LazIntfImage from glBitmap');
+ png.LoadFromIntfImage(intf);
+ png.SaveToStream(aStream);
+ finally
+ png.Free;
+ intf.Free;
+ end;
+end;
+
+{$ELSEIF DEFINED(GLB_LIB_PNG)}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TglBitmap.SavePNG(const aStream: TStream);
var
{$ENDIF}
{$IFDEF GLB_SUPPORT_JPEG_READ}
-{$IF DEFINED(GLB_SDL_IMAGE)}
+{$IF DEFINED(GLB_LAZ_JPEG)}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function TglBitmap.LoadJPEG(const aStream: TStream): Boolean;
+var
+ jpeg: TJPEGImage;
+ intf: TLazIntfImage;
+ StreamPos: Int64;
+begin
+ result := true;
+ StreamPos := aStream.Position;
+ jpeg := TJPEGImage.Create;
+ try try
+ jpeg.LoadFromStream(aStream);
+ intf := TLazIntfImage.Create(0, 0);
+ try try
+ intf.LoadFromBitmap(jpeg.BitmapHandle, jpeg.MaskHandle);
+ AssignFromLazIntfImage(intf);
+ except
+ result := false;
+ aStream.Position := StreamPos;
+ exit;
+ end;
+ finally
+ intf.Free;
+ end;
+ except
+ result := false;
+ aStream.Position := StreamPos;
+ exit;
+ end;
+ finally
+ jpeg.Free;
+ end;
+end;
+
+{$ELSEIF DEFINED(GLB_SDL_IMAGE)}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function TglBitmap.LoadJPEG(const aStream: TStream): Boolean;
var
{$ENDIF}
{$IFDEF GLB_SUPPORT_JPEG_WRITE}
-{$IF DEFINED(GLB_LIB_JPEG)}
+{$IF DEFINED(GLB_LAZ_JPEG)}
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap.SaveJPEG(const aStream: TStream);
+var
+ jpeg: TJPEGImage;
+ intf: TLazIntfImage;
+begin
+ jpeg := TJPEGImage.Create;
+ intf := TLazIntfImage.Create(0, 0);
+ try
+ if not AssignToLazIntfImage(intf) then
+ raise EglBitmap.Create('unable to create LazIntfImage from glBitmap');
+ jpeg.LoadFromIntfImage(intf);
+ jpeg.SaveToStream(aStream);
+ finally
+ intf.Free;
+ jpeg.Free;
+ end;
+end;
+
+{$ELSEIF DEFINED(GLB_LIB_JPEG)}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
procedure TglBitmap.SaveJPEG(const aStream: TStream);
var