Skip to content

Commit

Permalink
TSimbaImage tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Nov 19, 2023
1 parent 5cf0520 commit 17b94a1
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 202 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
procedure _ClearPixelA(const X, Y: Integer; const Alpha: Byte); inline;
procedure _SetPixelAntialias(const X, Y: Integer; const Alpha: Byte); inline;
begin
if (X >= 0) and (Y >= 0) and (X < FWidth) and (Y < FHeight) then
FData[Y*FWidth+X].A := 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// https://zingl.github.io/bresenham.js
// Requires _SetPixelAntialias(const X, Y: Integer; const Alpha: Byte);

procedure _DrawEllipseAA(x0, y0, x1, y1: Integer; Thickness: Single);
procedure _EllipseAntialias(x0, y0, x1, y1: Integer; Thickness: Single);
var
a,b,b1: Integer;
a2,b2: Single;
Expand Down Expand Up @@ -76,10 +77,10 @@ begin
i := 255*err/ed;

Alpha := Byte(Round(i));
_SetPixelA(x0,y0, Alpha);
_SetPixelA(x0,y1, Alpha);
_SetPixelA(x1,y0, Alpha);
_SetPixelA(x1,y1, Alpha);
_SetPixelAntialias(x0,y0, Alpha);
_SetPixelAntialias(x0,y1, Alpha);
_SetPixelAntialias(x1,y0, Alpha);
_SetPixelAntialias(x1,y1, Alpha);

if (err+dy+a < dx) then
begin
Expand All @@ -95,10 +96,10 @@ begin

while (i < Thickness) and (2*i <= x0+x1) do
begin
_SetPixelA(Round(i), y0, 0);
_SetPixelA(Round(x0+x1-i), y0, 0);
_SetPixelA(Round(i), y1, 0);
_SetPixelA(Round(x0+x1-i), y1, 0);
_SetPixelAntialias(Round(i), y0, 0);
_SetPixelAntialias(Round(x0+x1-i), y0, 0);
_SetPixelAntialias(Round(i), y1, 0);
_SetPixelAntialias(Round(x0+x1-i), y1, 0);

i += 1.0;
end;
Expand All @@ -114,10 +115,10 @@ begin
ed += 2*ed*i*i/(4*ed*ed+i*i);

Alpha := Byte(Round(255-255*e2/ed));
_SetPixelA(Round(Thickness), y0, Alpha);
_SetPixelA(Round(x0+x1-Thickness), y0, Alpha);
_SetPixelA(Round(Thickness), y1, Alpha);
_SetPixelA(Round(x0+x1-Thickness), y1, Alpha);
_SetPixelAntialias(Round(Thickness), y0, Alpha);
_SetPixelAntialias(Round(x0+x1-Thickness), y0, Alpha);
_SetPixelAntialias(Round(Thickness), y1, Alpha);
_SetPixelAntialias(Round(x0+x1-Thickness), y1, Alpha);

if (e2+dy2+a2 < dx2) then
Break;
Expand All @@ -139,13 +140,13 @@ begin
begin
Alpha := Byte(Round(255*4*err/b1));

_SetPixelA(x0, y0, Alpha);
_SetPixelA(x1, y0, Alpha);
_SetPixelAntialias(x0, y0, Alpha);
_SetPixelAntialias(x1, y0, Alpha);

y0 += 1;

_SetPixelA(x0, y1, Alpha);
_SetPixelA(x1, y1, Alpha);
_SetPixelAntialias(x0, y1, Alpha);
_SetPixelAntialias(x1, y1, Alpha);

y1 -= 1;
dy += a;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// https://zingl.github.io/bresenham.js
// Requires _SetPixelAntialias(const X, Y: Integer; const Alpha: Byte);

procedure _DrawLineAA(x0, y0, x1, y1: Integer; Thickness: Single);
procedure _LineAntialias(x0, y0, x1, y1: Integer; Thickness: Single);
var
dx, dy, err: Integer;
e2, x2, y2: Integer;
Expand All @@ -22,7 +23,7 @@ begin
Thickness := (Thickness + 1) / 2;
while True do
begin
_SetPixelA(x0, y0, Round(Max(0, 255 * (Abs(err-dx+dy)/ed-Thickness+1))));
_SetPixelAntialias(x0, y0, Round(Max(0, 255 * (Abs(err-dx+dy)/ed-Thickness+1))));

e2 := err;
x2 := x0;
Expand All @@ -33,7 +34,7 @@ begin
while (e2 < ed*Thickness) and ((y1 <> y2) or (dx > dy)) do
begin
y2 += sy;
_SetPixelA(x0, y2, Round(Max(0, 255 * (Abs(e2)/ed-Thickness+1))));
_SetPixelAntialias(x0, y2, Round(Max(0, 255 * (Abs(e2)/ed-Thickness+1))));
e2 += dx;
end;
if (x0 = x1) then
Expand All @@ -50,7 +51,7 @@ begin
while (e2 < ed*Thickness) and ((x1 <> x2) or (dx < dy)) do
begin
x2 += sx;
_SetPixelA(x2, y0, Round(Max(0, 255 * (Abs(e2)/ed-Thickness+1))));
_SetPixelAntialias(x2, y0, Round(Max(0, 255 * (Abs(e2)/ed-Thickness+1))));
e2 += dy;
end;
if (y0 = y1) then
Expand Down
6 changes: 0 additions & 6 deletions Source/image/setpixel.inc

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
procedure _SetPixelA(const X, Y: Integer; const Alpha: Byte); inline;
procedure _SetPixelAntialias(const X, Y: Integer; const Alpha: Byte); inline;
var
Pixel: PColorBGRA;
APlus1, APlus1Inv: UInt32;
Expand Down
Loading

0 comments on commit 17b94a1

Please sign in to comment.