uses Types, classes,
Vcl.Graphics;
type
TRgbTriple =
packed record
// do not change the order of the fields, do not add any fields
Blue: Byte;
Green: Byte;
Red: Byte;
end;
PRgbTriple =^TRgbTriple;
TRgbTripleArray =
packed array[0..MaxInt
div SizeOf(TRgbTriple) - 1]
of TRgbTriple;
PRgbTripleArray = ^TRgbTripleArray;
procedure CreateSpecialImage(
const InBmp, OutBmp: TBitmap; Threshold: Byte);
implementation
function AddToPtr(
const _Ptr: Pointer; _Offset: NativeInt): Pointer;
inline;
begin
Result := Pointer(NativeInt(_Ptr) + _Offset);
end;
function PtrDiff(
const _Ptr1, _Ptr2: Pointer): NativeInt;
inline;
begin
Result := NativeInt(_Ptr1) - NativeInt(_Ptr2);
end;
procedure CreateSpecialImage(
const InBmp, OutBmp: TBitmap; Threshold: Byte);
var
BytesPerPixel: NativeInt;
InScanLine0: Pointer;
InBytesPerLine: NativeInt;
OutBytesPerLine: NativeInt;
OutScanLine0: Pointer;
InPixel: PRgbTriple;
OutPixel: PRgbTriple;
Pixel: TRgbTriple;
x, y: Integer;
Height, Width : Integer;
begin
Height := inBMP.Height;
Width := inBmp.Width;
OutBmp.Width := Width;
OutBmp.Height := Height;
InBmp.PixelFormat := pf24bit;
OutBmp.PixelFormat := pf24bit;
BytesPerPixel := SizeOf(Pixel);
InScanLine0 := InBmp.ScanLine[0];
InBytesPerLine := NativeInt(InBmp.ScanLine[1]) - NativeInt(InScanLine0);
OutScanLine0 := OutBmp.ScanLine[0];
OutBytesPerLine := NativeInt( OutBmp.ScanLine[1]) - NativeInt(OutScanLine0);
OutPixel := OutScanLine0;
for y := 0
to Height - 1
do begin
for x := 0
to Width - 1
do begin
InPixel := AddToPtr(InScanLine0, InBytesPerLine * y + x * BytesPerPixel);
Pixel := InPixel^;
///
/// doSomething(Pixel);
///
if Pixel.Blue > Threshold
then Pixel.Blue := Threshold;
if Pixel.red > Threshold
then Pixel.red := Threshold;
if Pixel.Green > Threshold
then Pixel.Green := Threshold;
OutPixel := AddToPtr(OutScanLine0, OutBytesPerLine * y + x * BytesPerPixel);
OutPixel^ := Pixel;
end;
end;
end;