type
pByteQuad = ^ByteQuad;
ByteQuad = array[0..3] of byte;
procedure XRay(Src : TBitmap; Dest : TBitmap);
var
X,Y : integer;
pPix : pByteQuad;
COEF : array[0..255] of byte;
begin
if Src.PixelFormat <> pf32bit then
begin
Src.PixelFormat := pf32Bit;
Dest.PixelFormat := pf32Bit;
end;
Dest.Assign(Src);
{ PreCalculs }
for X := 0 to 255 do
COEF[X] := byte( round(X * (X*0.00390625)) );
pPix := Dest.ScanLine[Dest.Height-1];
{ l'effet de scanline necessite de connaitre le numero
de ligne sur laquelle on travaille, afin d'eviter des
calcul complexe a partir du pointeur pPix...
on double boucle Y,X :) }
for Y := 0 to Dest.Height-1 do
for X := 0 to Dest.Width-1 do
begin
case (Y and $1) of
0: pPix^[1] := not pPix^[1];
1: pPix^[1] := COEF[not pPix^[1]];
end;
pPix^[0] := COEF[pPix^[1]];
pPix^[2] := COEF[pPix^[1]];
inc(pPix);
end;
end;
{ version avec pré-calculs externes }
type
pByteQuad = ^ByteQuad;
ByteQuad = array[0..3] of byte;
{ ... }
var
precalc_XRayCOEF : array[0..255] of byte;
{ ... }
procedure XRay(Src : TBitmap; Dest : TBitmap);
var
X,Y : integer;
pPix : pByteQuad;
begin
if Src.PixelFormat <> pf32bit then
begin
Src.PixelFormat := pf32Bit;
Dest.PixelFormat := pf32Bit;
end;
Dest.Assign(Src);
pPix := Dest.ScanLine[Dest.Height-1];
for Y := 0 to Dest.Height-1 do
for X := 0 to Dest.Width-1 do
begin
case (Y and $1) of
0: pPix^[1] := not pPix^[1];
1: pPix^[1] := precalc_XRayCOEF[not pPix^[1]];
end;
pPix^[0] := precalc_XRayCOEF[pPix^[1]];
pPix^[2] := precalc_XRayCOEF[pPix^[1]];
inc(pPix);
end;
end;
{ ... }
var init_X : integer;
initialization
for init_X := 0 to 255 do
precalc_XRayCOEF[init_X] := byte( round(init_X * (init_X*0.00390625)) );