ここから先のDIB画像処理で使用する関数や型の定義から始めましょう。なお、Windows.pasで定義されているTRGBTripleなどはフィールドの識別子が長いので使用しません。
type
PRGB24 = ^TRGB24;
TRGB24 = packed record
B: Byte;
G: Byte;
R: Byte;
end;
TLine24 = array[0..MaxInt div SizeOf(TRGB24) -1]of TRGB24;
PLine24 = ^TLine24;
TCacheLines = array[0..MaxInt div SizeOf(Pointer) -1]of Pointer;
PCacheLines = ^TCacheLines;
TOperator3 = array[-1..1, -1..1]of Integer;
TMatrix3 = array[-1..1, -1..1]of TRGB24;
TLineMatrix3 = array[-1..1]of PLine24;
//関数
function MakeOperator3(X: array of Integer): TOperator3;
function GetCacheLines(Source: TBitmap): PCacheLines;
procedure CopyDIB(Source, Dest: TBitmap);
implementation
resourcestring
EMes_InvalidGraphic = 'ビットマップが不正です。';
function MakeOperator3(X: array of Integer): TOperator3;
// オペレーターを作成
var
I, MX, MY, Count: Integer;
begin
FillChar(Result, SizeOf(Result), 0);
Count := High(X);
if Count = -1 then Exit;
I := 0;
for MX := -1 to 1 do
for MY := -1 to 1 do
begin
Result[MX, MY] := X[I];
Inc(I);
if I > Count then Break;
end;
end;
function GetCacheLines(Source: TBitmap): PCacheLines;
// ビットマップのスキャンラインをキャッシュする
var
Y: Integer;
begin
if (Source = nil) or Source.Empty then
raise EInvalidGraphicOperation.CreateRes(@EMes_InvalidGraphic);
with Source do
begin
GetMem(Result, SizeOf(Pointer) * Height);
try
for Y := 0 to Height -1 do
Result^[Y] := ScanLine[Y];
except
FreeMem(Result);
raise;
end;
end;
end;
procedure CopyDIB(Source, Dest: TBitmap);
// DIBをコピーする
var
Y, Bytes: Integer;
begin
if (Source = nil) or Source.Empty or (Dest = nil) then
raise EInvalidGraphicOperation.CreateRes(@EMes_InvalidGraphic);
Source.PixelFormat := pf24bit;
Dest.PixelFormat := pf24bit;
Dest.Width := Source.Width;
Dest.Height := Source.Height;
Bytes := BytesPerScanline(Source.Width, 24, 32);
for Y := 0 to Source.Height -1 do
Move(Source.ScanLine[Y]^, Dest.ScanLine[Y]^, Bytes);
end;
|