unit BitmapProcessing;
interface
uses
Winapi.Windows,
Vcl.Graphics;
procedure HelligkeitNormal( Bitmap: TBitmap;
Const Original: TBitmap; Value: integer; IgnoreWhite: Boolean );
procedure HelligkeitParallel( Bitmap: TBitmap;
Const Original: TBitmap; Value: integer; IgnoreWhite: Boolean );
implementation
uses
System.Threading;
type
PRGBTripleArray = ^TRGBTripleArray;
TRGBTripleArray =
array [0 .. 4096]
of TRGBTriple;
procedure HelligkeitNormal( Bitmap: TBitmap;
Const Original: TBitmap; Value: integer; IgnoreWhite: Boolean );
var
x, y: integer;
Quelle, Ziel: PRGBTripleArray;
n: byte;
ar:
array [0 .. 255]
of byte;
LIdx: integer;
begin
Bitmap.Assign( Original );
n := abs( Value );
if Value > 0
then
for x := 0
to 255
do
if integer( x + n ) > 255
then
ar[x] := 255
else
ar[x] := x + n
else
for x := 0
to 255
do
if integer( x - n ) < 0
then
ar[x] := 0
else
ar[x] := x - n;
for y := 0
to Bitmap.Height - 1
do
begin
Ziel := Bitmap.Scanline[y];
Quelle := Original.Scanline[y];
for LIdx := 0
to Bitmap.Width - 1
do
begin
if not IgnoreWhite
or ( ( Quelle[LIdx].rgbtBlue <> 255 )
or ( Quelle[LIdx].rgbtGreen <> 255 )
or ( Ziel[LIdx].rgbtGreen <> 255 ) )
then
begin
Ziel[LIdx].rgbtBlue := ar[Quelle[LIdx].rgbtBlue];
Ziel[LIdx].rgbtRed := ar[Quelle[LIdx].rgbtRed];
Ziel[LIdx].rgbtGreen := ar[Quelle[LIdx].rgbtGreen];
end;
end;
end;
end;
procedure HelligkeitParallel( Bitmap: TBitmap;
Const Original: TBitmap; Value: integer; IgnoreWhite: Boolean );
var
// x,
y: integer;
Quelle, Ziel: PRGBTripleArray;
n: byte;
ar:
array [0 .. 255]
of byte;
// LIdx: integer;
begin
Bitmap.Assign( Original );
n := abs( Value );
if Value > 0
then
// for x := 0 to 255 do
TParallel.&
For( 0, 255,
procedure( x: integer )
begin
if integer( x + n ) > 255
then
ar[x] := 255
else
ar[x] := x + n
end )
else
// for x := 0 to 255 do
TParallel.&
For( 0, 255,
procedure( x: integer )
begin
if integer( x - n ) < 0
then
ar[x] := 0
else
ar[x] := x - n
end );
for y := 0
to Bitmap.Height - 1
do
begin
Ziel := Bitmap.Scanline[y];
Quelle := Original.Scanline[y];
// for LIdx := 0 to Bitmap.Width - 1 do
TParallel.&
For( 0, Bitmap.Width - 1,
procedure( LIdx: integer )
begin
if not IgnoreWhite
or ( ( Quelle[LIdx].rgbtBlue <> 255 )
or ( Quelle[LIdx].rgbtGreen <> 255 )
or ( Ziel[LIdx].rgbtGreen <> 255 ) )
then
begin
Ziel[LIdx].rgbtBlue := ar[Quelle[LIdx].rgbtBlue];
Ziel[LIdx].rgbtRed := ar[Quelle[LIdx].rgbtRed];
Ziel[LIdx].rgbtGreen := ar[Quelle[LIdx].rgbtGreen];
end;
end );
end;
end;
end.