summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/corelib/fpg_imgfmt_png.pas130
-rw-r--r--src/corelib/gdi/fpgui_toolkit.lpk8
-rw-r--r--src/corelib/gdi/fpgui_toolkit.pas4
-rw-r--r--src/corelib/x11/fpgui_toolkit.lpk6
-rw-r--r--src/corelib/x11/fpgui_toolkit.pas2
5 files changed, 144 insertions, 6 deletions
diff --git a/src/corelib/fpg_imgfmt_png.pas b/src/corelib/fpg_imgfmt_png.pas
new file mode 100644
index 00000000..e4a46a7d
--- /dev/null
+++ b/src/corelib/fpg_imgfmt_png.pas
@@ -0,0 +1,130 @@
+{
+ fpGUI - Free Pascal GUI Toolkit
+
+ Copyright (C) 2006 - 2012 See the file AUTHORS.txt, included in this
+ distribution, for details of the copyright.
+
+ See the file COPYING.modifiedLGPL, included in this distribution,
+ for details about redistributing fpGUI.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+ Description:
+ PNG image loading using the Free Pascal library: fcl-image
+}
+
+unit fpg_imgfmt_png;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+ SysUtils,
+ Classes,
+ fpg_base,
+ fpg_main,
+ FPImage,
+ FPReadPNG;
+
+function LoadImage_PNG(const AFileName: TfpgString): TfpgImage;
+function LoadImage_PNGcrop(const AMaxWidth, AMaxHeight: integer; const AFileName: TfpgString): TfpgImage;
+
+
+implementation
+
+uses
+ fpg_utils;
+
+function LoadImage_PNG(const AFileName: TfpgString): TfpgImage;
+var
+ i, j: integer;
+ colorA: TFPColor; // struct Red, Green, Blue, Alpha: word
+ colorB: TfpgColor; // ONE long 32-bit-word
+ imga: TFPCustomImage;
+ imgb: TfpgImage;
+ xlocal, ylocal: integer;
+begin
+ Result := nil;
+ if not fpgFileExists(AFileName) then
+ Exit; //==>
+
+ imga := TFPMemoryImage.Create(0, 0);
+ try
+ imga.LoadFromFile(AFileName, TFPReaderPNG.Create); // auto size image
+ except
+ imga := nil;
+ imgb := nil;
+ end;
+ if imga <> nil then
+ begin
+ xlocal := imga.Width;
+ ylocal := imga.Height;
+ imgb := TfpgImage.Create;
+ imgb.AllocateImage(32, xlocal, ylocal); // 32=colordepth
+ for i := 0 to ylocal - 1 do
+ for j := 0 to xlocal - 1 do
+ begin
+ colorA := imga.Colors[j, i];
+ colorB := (colorA.Blue shr 8) or (colorA.Green and $FF00) or ((colorA.Red and $FF00) shl 8);
+ imgb.Colors[j, i] := colorB;
+ end;
+ imgb.UpdateImage;
+ end;
+ imga.Free;
+ Result := imgb;
+end;
+
+function LoadImage_PNGcrop(const AMaxWidth, AMaxHeight: integer; const AFileName: TfpgString): TfpgImage;
+var
+ i, j: integer;
+ colorA: TFPColor; // struct Red, Green, Blue, Alpha: word
+ colorB: TfpgColor; // ONE long 32-bit-word
+ imga: TFPCustomImage;
+ imgb: TfpgImage;
+ xlocal, ylocal: integer;
+begin
+ Result := nil;
+ if not fpgFileExists(AFileName) then
+ Exit; //==>
+
+ // Maximum image size of AMaxWidth by AMaxHeight.
+ // Actual image imga.Width (AMaxWidth) and imga.Height (AMaxHeight).
+ // Calculated to fit the image within required size: xlocal, ylocal
+ imga := TFPMemoryImage.Create(0, 0);
+ try
+ imga.LoadFromFile(AFileName, TFPReaderPNG.Create); // auto size image
+ except
+ imga := nil;
+ imgb := nil;
+ end;
+ if imga <> nil then
+ begin
+ if imga.Width > AMaxWidth then
+ xlocal := AMaxWidth
+ else
+ xlocal := imga.Width;
+ if imga.Height > AMaxHeight then
+ ylocal := AMaxHeight
+ else
+ ylocal := imga.Height;
+ imgb := TfpgImage.Create;
+ imgb.AllocateImage(32, xlocal, ylocal); // 32=colordepth
+ for i := 0 to ylocal - 1 do
+ for j := 0 to xlocal - 1 do
+ begin
+ colorA := imga.Colors[j, i];
+ colorB := (colorA.Blue shr 8) or (colorA.Green and $FF00) or ((colorA.Red and $FF00) shl 8);
+ imgb.Colors[j, i] := colorB;
+ end;
+ imgb.UpdateImage;
+ end;
+ imga.Free;
+ Result := imgb;
+end;
+
+
+end.
+
diff --git a/src/corelib/gdi/fpgui_toolkit.lpk b/src/corelib/gdi/fpgui_toolkit.lpk
index 946d234a..d6a28998 100644
--- a/src/corelib/gdi/fpgui_toolkit.lpk
+++ b/src/corelib/gdi/fpgui_toolkit.lpk
@@ -31,7 +31,7 @@
<Description Value="fpGUI Toolkit"/>
<License Value="LGPL 2 with static linking exception."/>
<Version Minor="8" Build="0"/>
- <Files Count="88">
+ <Files Count="89">
<Item1>
<Filename Value="..\stdimages.inc"/>
<Type Value="Include"/>
@@ -384,6 +384,10 @@
<Filename Value="..\..\gui\fpg_readonly.pas"/>
<UnitName Value="fpg_readonly"/>
</Item88>
+ <Item89>
+ <Filename Value="..\fpg_imgfmt_png.pas"/>
+ <UnitName Value="fpg_imgfmt_png"/>
+ </Item89>
</Files>
<LazDoc Paths="..\..\..\docs\xml\corelib;..\..\..\docs\xml\corelib\x11;..\..\..\docs\xml\corelib\gdi;..\..\..\docs\xml\gui"/>
<RequiredPkgs Count="1">
@@ -400,4 +404,4 @@
<IgnoreBinaries Value="False"/>
</PublishOptions>
</Package>
-</CONFIG>
+</CONFIG> \ No newline at end of file
diff --git a/src/corelib/gdi/fpgui_toolkit.pas b/src/corelib/gdi/fpgui_toolkit.pas
index 7ec7e35c..1fef2442 100644
--- a/src/corelib/gdi/fpgui_toolkit.pas
+++ b/src/corelib/gdi/fpgui_toolkit.pas
@@ -20,8 +20,8 @@ uses
fpg_extgraphics, fpg_ColorMapping, fpg_ColorWheel, fpg_interface,
fpg_editbtn, fpg_imgfmt_jpg, fpg_imgutils, fpg_OLEDragDrop,
fpg_stylemanager, fpg_style_win2k, fpg_style_motif, fpg_style_clearlooks,
- fpg_style_bluecurve, fpg_style_bitmap, fpg_readonly;
+ fpg_style_bluecurve, fpg_style_bitmap, fpg_readonly, fpg_imgfmt_png;
implementation
-end.
+end. \ No newline at end of file
diff --git a/src/corelib/x11/fpgui_toolkit.lpk b/src/corelib/x11/fpgui_toolkit.lpk
index 7a18d789..46614518 100644
--- a/src/corelib/x11/fpgui_toolkit.lpk
+++ b/src/corelib/x11/fpgui_toolkit.lpk
@@ -31,7 +31,7 @@
<License Value="LGPL 2 with static linking exception.
"/>
<Version Minor="8"/>
- <Files Count="91">
+ <Files Count="92">
<Item1>
<Filename Value="../stdimages.inc"/>
<Type Value="Include"/>
@@ -396,6 +396,10 @@
<Filename Value="../../gui/fpg_readonly.pas"/>
<UnitName Value="fpg_readonly"/>
</Item91>
+ <Item92>
+ <Filename Value="../fpg_imgfmt_png.pas"/>
+ <UnitName Value="fpg_imgfmt_png"/>
+ </Item92>
</Files>
<LazDoc Paths="../../../docs/xml/corelib/;../../../docs/xml/corelib/x11/;../../../docs/xml/corelib/gdi/;../../../docs/xml/gui/"/>
<RequiredPkgs Count="1">
diff --git a/src/corelib/x11/fpgui_toolkit.pas b/src/corelib/x11/fpgui_toolkit.pas
index 8c66a9a3..b2a4b774 100644
--- a/src/corelib/x11/fpgui_toolkit.pas
+++ b/src/corelib/x11/fpgui_toolkit.pas
@@ -19,7 +19,7 @@ uses
fpg_hint, fpg_spinedit, fpg_extgraphics, fpg_ColorMapping, fpg_ColorWheel,
fpg_interface, fpg_editbtn, fpg_imgfmt_jpg, fpg_imgutils, fpg_stylemanager,
fpg_style_win2k, fpg_style_motif, fpg_style_clearlooks, fpg_style_bluecurve,
- fpg_style_bitmap, fpg_readonly;
+ fpg_style_bitmap, fpg_readonly, fpg_imgfmt_png;
implementation