jvcllaz: Port color component extraction routines in JvJVCLUtils.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@8074 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2021-08-14 22:25:04 +00:00
parent e2cb8dd822
commit 89d246386d

View File

@ -49,7 +49,7 @@ function IconToBitmap2(Ico: HICON; Size: Integer = 32;
TransparentColor: TColor = clNone): TBitmap; TransparentColor: TColor = clNone): TBitmap;
function IconToBitmap3(Ico: HICON; Size: Integer = 32; function IconToBitmap3(Ico: HICON; Size: Integer = 32;
TransparentColor: TColor = clNone): TBitmap; TransparentColor: TColor = clNone): TBitmap;
************)
// bitmap manipulation functions // bitmap manipulation functions
// NOTE: Dest bitmap must be freed by caller! // NOTE: Dest bitmap must be freed by caller!
// get red channel bitmap // get red channel bitmap
@ -58,6 +58,8 @@ procedure GetRBitmap(var Dest: TBitmap; const Source: TBitmap);
procedure GetGBitmap(var Dest: TBitmap; const Source: TBitmap); procedure GetGBitmap(var Dest: TBitmap; const Source: TBitmap);
// get blue channel bitmap // get blue channel bitmap
procedure GetBBitmap(var Dest: TBitmap; const Source: TBitmap); procedure GetBBitmap(var Dest: TBitmap; const Source: TBitmap);
// get grayscale bitmap
procedure GetGrayscaleBitmap(var Dest: TBitmap; const Source: TBitmap);
// get monochrome bitmap // get monochrome bitmap
procedure GetMonochromeBitmap(var Dest: TBitmap; const Source: TBitmap); procedure GetMonochromeBitmap(var Dest: TBitmap; const Source: TBitmap);
// get hue bitmap (h part of hsv) // get hue bitmap (h part of hsv)
@ -67,6 +69,7 @@ procedure GetSaturationBitmap(var Dest: TBitmap; const Source: TBitmap);
// get value bitmap (V part of HSV) // get value bitmap (V part of HSV)
procedure GetValueBitmap(var Dest: TBitmap; const Source: TBitmap); procedure GetValueBitmap(var Dest: TBitmap; const Source: TBitmap);
(*************** NOT CONVERTED
// hides / shows the a forms caption area // hides / shows the a forms caption area
procedure HideFormCaption(FormHandle: THandle; Hide: Boolean); procedure HideFormCaption(FormHandle: THandle; Hide: Boolean);
@ -866,7 +869,7 @@ function Scale96ToForm(ASize: Integer): Integer;
implementation implementation
uses uses
sysutils, LCLIntf, GraphType, GraphUtil, Math, sysutils, LCLIntf, GraphType, GraphUtil, FPImage, IntfGraphics, Math,
{$IFDEF MSWINDOWS} {$IFDEF MSWINDOWS}
CommCtrl, CommCtrl,
{$ENDIF} {$ENDIF}
@ -1155,79 +1158,98 @@ begin
end; end;
{$ENDIF MSWINDOWS} {$ENDIF MSWINDOWS}
*****************)
type type
TGetXBitmapMode =(gxRed, gxGreen, gxBlue, gxHue, gxSaturation, gxValue); TGetXBitmapMode =(gxRed, gxGreen, gxBlue, gxHue, gxSaturation, gxValue, gxGrayscale);
procedure GetXBitmap(var Dest: TBitmap; const Source: TBitmap; Mode: TGetXBitmapMode); procedure GetXBitmap(var Dest: TBitmap; const Source: TBitmap; Mode: TGetXBitmapMode);
var var
I, J, H, S, V: Integer; img: TLazIntfImage;
{$IFDEF CLR} clr: TFPColor;
Line: array of TJvRGBTriple; i, j: Integer;
{$ELSE} h, s, v: Double;
Line: PJvRGBArray;
{$ENDIF CLR}
begin begin
if not Assigned(Dest) then if not Assigned(Dest) then
Dest := TBitmap.Create; Dest := TBitmap.Create;
Dest.Assign(Source); img := Source.CreateIntfImage;
Dest.PixelFormat := pf24bit; try
for J := Dest.Height - 1 downto 0 do
begin
{$IFDEF CLR}
Marshal.PtrToStructure(Dest.ScanLine[J], Line);
{$ELSE}
Line := Dest.ScanLine[J];
{$ENDIF CLR}
case Mode of case Mode of
gxRed: gxRed:
for I := Dest.Width - 1 downto 0 do for j := 0 to img.Height-1 do
begin for i := 0 to img.Width-1 do
Line[I].rgbGreen := 0;
Line[I].rgbBlue := 0;
end;
gxGreen:
for I := Dest.Width - 1 downto 0 do
begin
Line[I].rgbRed := 0;
Line[I].rgbBlue := 0;
end;
gxBlue:
for I := Dest.Width - 1 downto 0 do
begin
Line[I].rgbRed := 0;
Line[I].rgbGreen := 0;
end;
gxHue:
for I := Dest.Width - 1 downto 0 do
with Line[I] do
begin begin
RGBToHSV(rgbRed, rgbGreen, rgbBlue, H, S, V); clr := img.Colors[i, j];
rgbRed := H; clr.Green := 0;
rgbGreen := H; clr.Blue := 0;
rgbBlue := H; img.Colors[i, j] := clr;
end;
gxGreen:
for j := 0 to img.Height-1 do
for i := 0 to img.Width-1 do
begin
clr := img.Colors[i, j];
clr.Red := 0;
clr.Blue := 0;
img.Colors[i, j] := clr;
end;
gxBlue:
for j := 0 to img.Height-1 do
for i := 0 to img.Width-1 do
begin
clr := img.Colors[i, j];
clr.Red := 0;
clr.Green := 0;
img.Colors[i, j] := clr;
end;
gxHue:
for j := 0 to img.Height-1 do
for i := 0 to img.Width-1 do
begin
clr := img.Colors[i, j];
ColorToHSV(FPColorToTColor(clr), h, s, v);
clr.Red := round(h*65535);
clr.Green := clr.Red;
clr.Blue := clr.Red;
img.Colors[i, j] := clr;
end; end;
gxSaturation: gxSaturation:
for I := Dest.Width - 1 downto 0 do for j := 0 to img.Height-1 do
with Line[I] do for i := 0 to img.Width-1 do
begin begin
RGBToHSV(rgbRed, rgbGreen, rgbBlue, H, S, V); clr := img.Colors[i, j];
rgbRed := S; ColorToHSV(FPColorToTColor(clr), h, s, v);
rgbGreen := S; clr.Red := round(s*65535);
rgbBlue := S; clr.Green := clr.Red;
clr.Blue := clr.Red;
img.Colors[i, j] := clr;
end; end;
gxValue: gxValue:
for I := Dest.Width - 1 downto 0 do for j := 0 to img.Height-1 do
with Line[I] do for i := 0 to img.Width-1 do
begin begin
RGBToHSV(rgbRed, rgbGreen, rgbBlue, H, S, V); clr := img.Colors[i, j];
rgbRed := V; ColorToHSV(FPColorToTColor(clr), h, s, v);
rgbGreen := V; clr.Red := round(v*65535);
rgbBlue := V; clr.Green := clr.Red;
clr.Blue := clr.Red;
img.Colors[i, j] := clr;
end;
gxGrayscale:
for j := 0 to img.Height-1 do
for i := 0 to img.Width-1 do
begin
clr := img.Colors[i, j];
clr.Red := (Int64(clr.Red) + clr.Green + clr.Blue) div 3;
clr.Green := clr.Red;
clr.Blue := clr.Red;
img.Colors[i, j] := clr;
end; end;
end; end;
Dest.LoadFromIntfImage(img);
finally
img.Free;
end; end;
Dest.PixelFormat := Source.PixelFormat;
end; end;
procedure GetRBitmap(var Dest: TBitmap; const Source: TBitmap); procedure GetRBitmap(var Dest: TBitmap; const Source: TBitmap);
@ -1245,6 +1267,11 @@ begin
GetXBitmap(Dest, Source, gxGreen); GetXBitmap(Dest, Source, gxGreen);
end; end;
procedure GetGrayscaleBitmap(var Dest: TBitmap; const Source: TBitmap);
begin
GetXBitmap(Dest, source, gxGrayscale);
end;
procedure GetMonochromeBitmap(var Dest: TBitmap; const Source: TBitmap); procedure GetMonochromeBitmap(var Dest: TBitmap; const Source: TBitmap);
begin begin
if not Assigned(Dest) then if not Assigned(Dest) then
@ -1268,7 +1295,7 @@ begin
GetXBitmap(Dest, Source, gxValue); GetXBitmap(Dest, Source, gxValue);
end; end;
(******************* NOT CONVERTED ****
{ (rb) Duplicate of JvAppUtils.AppTaskbarIcons } { (rb) Duplicate of JvAppUtils.AppTaskbarIcons }
procedure HideFormCaption(FormHandle: THandle; Hide: Boolean); procedure HideFormCaption(FormHandle: THandle; Hide: Boolean);