summaryrefslogtreecommitdiff
path: root/src/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/fpg_imgutils.pas110
-rw-r--r--src/corelib/gdi/fpgui_toolkit.lpk7
-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, 123 insertions, 6 deletions
diff --git a/src/corelib/fpg_imgutils.pas b/src/corelib/fpg_imgutils.pas
new file mode 100644
index 00000000..afb4d4fe
--- /dev/null
+++ b/src/corelib/fpg_imgutils.pas
@@ -0,0 +1,110 @@
+{
+ fpGUI - Free Pascal GUI Toolkit
+
+ Copyright (C) 2006 - 2010 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:
+ Some handly image manipulation functions to use with TfpgImage class.
+ Included is a gray color conversion matrix.
+}
+
+unit fpg_imgutils;
+
+{$mode objfpc}{$H+}
+
+{ TODO : Make the conversion matrix a plugable architecture. Similar to the
+ interpolation handling in TfpgCanvas. }
+
+interface
+
+uses
+ fpg_base,
+ fpg_main;
+
+type
+ TGrayConvMatrix = record
+ red: single;
+ green: single;
+ blue: single;
+ end;
+
+var
+ GrayConvMatrix: TGrayConvMatrix;
+ GrayBrightness: Boolean;
+ GrayBrightnessPercentage: integer;
+
+const
+ GCM_NTSC: TGrayConvMatrix = (red:0.299; green:0.587; blue:0.114); // NTSC method
+ GCM_Mathematical: TGrayConvMatrix = (red:0.334; green:0.333; blue:0.333); // Intensity method
+ GCM_Photoshop: TGrayConvMatrix = (red:0.212671; green:0.715160; blue:0.072169); // Y of YUV from B/W TV's
+
+
+procedure fpgApplyGreyFilter(var AImg: TfpgImage);
+function fpgCalculateGray(const AFrom: TfpgColor; const ABrighter: boolean = False; const APercent: integer = 0): TfpgColor;
+
+
+implementation
+
+
+procedure fpgApplyGreyFilter(var AImg: TfpgImage);
+var
+ x, y: integer;
+ c: TfpgColor;
+begin
+ for x := 0 to AImg.Width-1 do
+ begin
+ for y := 0 to AImg.Height-1 do
+ begin
+ c := AImg.Colors[x, y];
+ AImg.Colors[x, y] := fpgCalculateGray(c, GrayBrightness, GrayBrightnessPercentage);
+ end;
+ end;
+ AImg.UpdateImage;
+end;
+
+
+{ AFrom is the original color we want to change
+ ABrighter = True goes to direction of White. False goes to direction of Black
+ APercent = 0 zero is straight conversion to gray. 100% is pure black or
+ white, depending on ABrighter value. }
+function fpgCalculateGray(const AFrom: TfpgColor; const ABrighter: boolean = False; const APercent: integer = 0): TfpgColor;
+var
+ g: integer;
+ rgb: TFPColor;
+begin
+ with GrayConvMatrix do
+ begin
+ rgb := fpgColorToFPColor(AFrom);
+ g := round(red*rgb.red + green*rgb.green + blue*rgb.blue);
+
+ if ABrighter then
+ g := trunc(255 - ((255 - g) * (100 - APercent) / 100))
+ else
+ g := trunc(g * (100 - APercent) / 100);
+
+ if (g < 0) then g := 0;
+ if (g > 255) then g := 255;
+
+ rgb.Red := g;
+ rgb.Green := g;
+ rgb.Blue := g;
+ end;
+ Result := FPColorTofpgColor(rgb);
+end;
+
+
+initialization
+ GrayConvMatrix := GCM_NTSC;
+ GrayBrightness := True;
+ GrayBrightnessPercentage := 20;
+
+end.
+
diff --git a/src/corelib/gdi/fpgui_toolkit.lpk b/src/corelib/gdi/fpgui_toolkit.lpk
index 127b315f..c989269e 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="7"/>
- <Files Count="78">
+ <Files Count="79">
<Item1>
<Filename Value="..\stdimages.inc"/>
<Type Value="Include"/>
@@ -344,6 +344,9 @@
<Filename Value="..\..\gui\inputquerydialog.inc"/>
<Type Value="Include"/>
</Item78>
+ <Item79>
+ <Filename Value="..\fpg_imgutils.pas"/>
+ </Item79>
</Files>
<LazDoc Paths="..\..\..\docs\xml\corelib\;..\..\..\docs\xml\corelib\x11\;..\..\..\docs\xml\corelib\gdi\;..\..\..\docs\xml\gui\"/>
<RequiredPkgs Count="1">
@@ -360,4 +363,4 @@
<IgnoreBinaries Value="False"/>
</PublishOptions>
</Package>
-</CONFIG> \ No newline at end of file
+</CONFIG>
diff --git a/src/corelib/gdi/fpgui_toolkit.pas b/src/corelib/gdi/fpgui_toolkit.pas
index 0ec7907a..2e3e81b6 100644
--- a/src/corelib/gdi/fpgui_toolkit.pas
+++ b/src/corelib/gdi/fpgui_toolkit.pas
@@ -1,4 +1,4 @@
-{ This file was automatically created by Lazarus. Do not edit!
+{ This file was automatically created by Lazarus. do not edit!
This source is only used to compile and install the package.
}
@@ -18,7 +18,7 @@ uses
fpg_radiobutton, fpg_scrollbar, fpg_style, fpg_tab, fpg_trackbar, fpg_tree,
fpgui_db, fpg_gdi, fpg_impl, fpg_splitter, fpg_hint, fpg_spinedit,
fpg_extgraphics, fpg_ColorMapping, fpg_ColorWheel, fpg_interface,
- fpg_editbtn, fpg_imgfmt_jpg;
+ fpg_editbtn, fpg_imgfmt_jpg, fpg_imgutils;
implementation
diff --git a/src/corelib/x11/fpgui_toolkit.lpk b/src/corelib/x11/fpgui_toolkit.lpk
index 1e2bd934..de52e851 100644
--- a/src/corelib/x11/fpgui_toolkit.lpk
+++ b/src/corelib/x11/fpgui_toolkit.lpk
@@ -32,7 +32,7 @@
<License Value="LGPL 2 with static linking exception.
"/>
<Version Minor="7"/>
- <Files Count="82">
+ <Files Count="83">
<Item1>
<Filename Value="../stdimages.inc"/>
<Type Value="Include"/>
@@ -361,6 +361,10 @@
<Filename Value="../../gui/inputquerydialog.inc"/>
<Type Value="Include"/>
</Item82>
+ <Item83>
+ <Filename Value="../fpg_imgutils.pas"/>
+ <UnitName Value="fpg_imgutils"/>
+ </Item83>
</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 9373d818..f9ea7c1d 100644
--- a/src/corelib/x11/fpgui_toolkit.pas
+++ b/src/corelib/x11/fpgui_toolkit.pas
@@ -17,7 +17,7 @@ uses
fpg_mru, fpg_panel, fpg_popupcalendar, fpg_progressbar, fpg_radiobutton,
fpg_scrollbar, fpg_style, fpg_tab, fpg_trackbar, fpg_tree, fpgui_db, fpg_splitter,
fpg_hint, fpg_spinedit, fpg_extgraphics, fpg_ColorMapping, fpg_ColorWheel,
- fpg_interface, fpg_editbtn, fpg_imgfmt_jpg;
+ fpg_interface, fpg_editbtn, fpg_imgfmt_jpg, fpg_imgutils;
implementation