Yes, images are rendered at runtime with math params. How much bigger should be rendered image to effective resample it to wanted size? For example if final size will be 1600x1200, render area should be lets say +10%?
Also I have another problem. I have these two procedures (extracted from ImageE program based on GR32 1.5).
Delphi-Quellcode:
procedure GreyScaleDilation(Bitmap: TBitmap32);
var
i, j: Integer;
D, S: PColor32;
dst: TBitmap32;
b, r, g, max: Byte;
sz: array of Integer;
sznr: Integer;
begin
dst := TBitmap32.Create;
dst.SetSize(Bitmap.Width, Bitmap.Height);
// init;
S := @Bitmap.Bits[0];
sznr := Bitmap.Width * Bitmap.Height;
sz := nil;
SetLength(sz, sznr);
for i := 0 to sznr - 1 do
begin
b := (S^ and $FF);
g := (S^ shr 8) and $FF;
r := (S^ shr 16) and $FF;
max := Round((b + g + r) div 3);
sz[i] := max;
Inc(S);
end;
D := @dst.Bits[0];
for j := 1 to Bitmap.Height - 1 do
begin
for i := 1 to Bitmap.Width - 1 do
begin
max := sz[(j * (Bitmap.Width - 1)) + i];
if (sz[(j * (Bitmap.Width - 1)) + i - 1] > max) then
max := sz[(j * (Bitmap.Width - 1)) + i - 1];
if (sz[(j * (Bitmap.Width - 1)) + i + 1] > max) then
max := sz[(j * (Bitmap.Width - 1)) + i + 1];
if (sz[((j - 1) * (Bitmap.Width - 1)) + i] > max) then
max := sz[((j - 1) * (Bitmap.Width - 1)) + i];
if (sz[((j + 1) * (Bitmap.Width - 1)) + i] > max) then
max := sz[((j + 1) * (Bitmap.Width - 1)) + i];
if (sz[((j - 1) * (Bitmap.Width - 1)) + i - 1] > max) then
max := sz[((j - 1) * (Bitmap.Width - 1)) + i - 1];
if (sz[((j + 1) * (Bitmap.Width - 1)) + i - 1] > max) then
max := sz[((j + 1) * (Bitmap.Width - 1)) + i - 1];
if (sz[((j - 1) * (Bitmap.Width - 1)) + i + 1] > max) then
max := sz[((j - 1) * (Bitmap.Width - 1)) + i + 1];
if (sz[((j + 1) * (Bitmap.Width - 1)) + i + 1] > max) then
max := sz[((j + 1) * (Bitmap.Width - 1)) + i + 1];
// if max>$ff then max:=$ff;
D^ := $FF000000 + max shl 16 + max shl 8 + max;
Inc(D);
end;
end;
Bitmap.Assign(dst);
Bitmap.Changed;
end;
procedure GreyScaleErosion(Bitmap: TBitmap32);
var
i, j: Integer;
D, S: PColor32;
dst: TBitmap32;
b, r, g, min: Byte;
sz: array of Integer;
sznr: Integer;
begin
dst := TBitmap32.Create;
dst.SetSize(Bitmap.Width, Bitmap.Height);
// init;
S := @Bitmap.Bits[0];
sznr := Bitmap.Width * Bitmap.Height;
sz := nil;
SetLength(sz, sznr);
for i := 0 to sznr - 1 do
begin
b := (S^ and $FF);
g := (S^ shr 8) and $FF;
r := (S^ shr 16) and $FF;
min := Round((b + g + r) div 3);
sz[i] := min;
Inc(S);
end;
D := @dst.Bits[0];
for j := 1 to Bitmap.Height - 1 do
begin
for i := 1 to Bitmap.Width - 1 do
begin
min := sz[(j * (Bitmap.Width - 1)) + i];
if (sz[(j * (Bitmap.Width - 1)) + i - 1] < min) then
min := sz[(j * (Bitmap.Width - 1)) + i - 1];
if (sz[(j * (Bitmap.Width - 1)) + i + 1] < min) then
min := sz[(j * (Bitmap.Width - 1)) + i + 1];
if (sz[((j - 1) * (Bitmap.Width - 1)) + i] < min) then
min := sz[((j - 1) * (Bitmap.Width - 1)) + i];
if (sz[((j + 1) * (Bitmap.Width - 1)) + i] < min) then
min := sz[((j + 1) * (Bitmap.Width - 1)) + i];
if (sz[((j - 1) * (Bitmap.Width - 1)) + i - 1] < min) then
min := sz[((j - 1) * (Bitmap.Width - 1)) + i - 1];
if (sz[((j + 1) * (Bitmap.Width - 1)) + i - 1] < min) then
min := sz[((j + 1) * (Bitmap.Width - 1)) + i - 1];
if (sz[((j - 1) * (Bitmap.Width - 1)) + i + 1] < min) then
min := sz[((j - 1) * (Bitmap.Width - 1)) + i + 1];
if (sz[((j + 1) * (Bitmap.Width - 1)) + i + 1] < min) then
min := sz[((j + 1) * (Bitmap.Width - 1)) + i + 1];
// if max>$ff then max:=$ff;
D^ := $FF000000 + min shl 16 + min shl 8 + min;
Inc(D);
end;
end;
Bitmap.Assign(dst);
Bitmap.Changed;
end;
Something is wrong with algorithms and I can't fix it. Processed image has black lines on bottom. Could you cast a glance on this code?