unit
SepiaThread;
interface
uses
Classes, SysUtils, Windows, Graphics;
type
TSepiaThread =
class
(TThread)
private
EBmp: Graphics
.
TBitmap
protected
procedure
UpdatePrb;
procedure
Execute; override;
function
BmpToSepia(
const
Bmp: TBitmap; Depth:
Integer
):
Boolean
;
public
constructor
Create(bmpBitmap: Graphics
.
TBitmap);
end
;
implementation
uses
MainForm;
constructor
TSepiaThread
.
Create(bmpBitmap: Graphics
.
TBitmap);
begin
EBmp := bmpBitmap;
inherited
Create(
False
);
end
;
procedure
TFirstThread
.
UpdatePrb;
begin
Main
.
ProgressBar
.
StepIt;
end
;
function
TFirstThread
.
BmpToSepia(
const
Bmp: TBitmap; Depth:
Integer
):
Boolean
;
var
Color,Color2:
LongInt
;
r,g,b,rr,gg:
Byte
;
h,w:
Integer
;
begin
for
h :=
0
to
Bmp
.
Height
do
begin
Filters
.
ProgressBar
.
StepIt;
Filters
.
ProgressBar
.
Update;
for
w :=
0
to
Bmp
.
Width
do
begin
Color := ColorToRGB(Bmp
.
Canvas
.
Pixels[w,h]);
r := GetRValue(Color);
g := GetGValue(Color);
b := GetBValue(Color);
Color2 := (r + g + b)
div
3
;
Bmp
.
Canvas
.
Pixels[w,h] := RGB(Color2,Color2,Color2);
Color := ColorToRGB(Bmp
.
Canvas
.
Pixels[w,h]);
r := GetRValue(Color);
g := GetGValue(Color);
b := GetBValue(Color);
rr := r + (Depth*
2
);
gg := g + Depth;
if
rr <= ((Depth*
2
)-
1
)
then
rr :=
255
;
if
gg <= (Depth-
1
)
then
gg :=
255
;
Bmp
.
Canvas
.
Pixels[w,h] := RGB(rr,gg,b);
end
;
end
;
Result :=
True
;
end
;
procedure
TFirstThread
.
Execute;
var
c:
Integer
;
begin
FreeOnTerminate :=
True
;
BmpToSepia(EBmp,
20
);
end
;
end
.