Simba Code:
program new;
// HERE BE DRAGONS
procedure FilterUpTextByCharacteristics(bmp: TMufasaBitmap);
var
x,y: Integer;
begin
{ Filter 2
This performs a `simple' filter.
What we are doing here is simple checking that if Colour[x,y] is part
of the uptext, then so must Colour[x+1,y+1], or Colour[x+1,y+1] is a shadow.
if it is neither, we can safely remove it.
XXX: This causes the previously mentioned fuckup.
}
for y := 0 to bmp.Height - 2 do
for x := 0 to bmp.Width - 2 do
begin
if bmp.fastgetpixel(x,y) = clPurple then
continue;
if bmp.fastgetpixel(x,y) = clBlack then
continue;
if (bmp.fastgetpixel(x,y) <> bmp.fastgetpixel(x+1,y+1)) and
(bmp.fastgetpixel(x+1,y+1) <> clpurple) then
bmp.fastsetpixel(x,y,{clAqua}0);
end;
{
Remove false shadow. (A shadow isn't larger than 1 pixel. So if x, y is
shadow, thex x+1, y+1 can't be shadow. If it is, we can safely remove it.
(As well as x+2, y+2, etc).
The tricky part of the algorithm is that it starts at the bottom,
removing shadow point x,y if x-1,y-1 is also shadow.
}
for y := bmp.Height - 1 downto 1 do
for x := bmp.Width - 1 downto 1 do
begin
if bmp.fastgetpixel(x,y) <> clPurple then
continue;
if bmp.fastgetpixel(x,y) = bmp.fastgetpixel(x-1,y-1) then
begin
bmp.fastsetpixel(x,y,clSilver);
continue;
end;
if bmp.fastgetpixel(x-1,y-1) = 0 then
bmp.fastsetpixel(x,y,clSilver);
end;
// Now we do another filter, with uptext chars identity 1 and 2.
for y := bmp.Height - 2 downto 0 do
for x := bmp.Width - 2 downto 0 do
begin
if bmp.fastgetpixel(x,y) = clPurple then
continue;
if bmp.fastgetpixel(x,y) = clBlack then
continue;
// identity 1
if (bmp.fastgetpixel(x,y) = bmp.fastgetpixel(x+1,y+1) ) then
continue;
// identity 2
if bmp.fastgetpixel(x+1,y+1) <> clPurple then
begin
bmp.fastsetpixel(x,y,0); // 0 was clOlive
continue;
end;
// If we make it to here, it means the pixel is part of the uptext.
end;
end;
procedure SortATPAFromFirstPointY(var a: T2DPointArray; const From: TPoint);
var
i, l: Integer;
DistArr: TIntegerArray;
begin
l := High(a);
if (l < 0) then Exit;
SetLength(DistArr, l + 1);
for i := 0 to l do
DistArr[i] := Round(Sqr(From.y - a[i][0].y));
QuickATPASort(DistArr, a, 0, l, True);
end;
procedure SortATPAFromFirstPointX(var a: T2DPointArray; const From: TPoint);
var
i, l: Integer;
DistArr: TIntegerArray;
begin
l := High(a);
if (l < 0) then Exit;
SetLength(DistArr, l + 1);
for i := 0 to l do
DistArr[i] := Round(Sqr(From.x - a[i][0].x));
QuickATPASort(DistArr, a, 0, l, True);
end;
var
bmp, bmp2: integer;
w, h: integer;
cts: integer;
i: integer;
s: String;
P, P2: TPointArray;
ATPA: Array of TPointArray;
ATPATemp: Array of TPointArray;
t,t2:integer;
Colors: TIntegerArray;
target: Integer;
begin
target := GetImageTarget;
// LoadFont('SmallCharsNS', True); // If we want to use shadows
bmp := LoadBitmap('chooseopt5.bmp'); // Bitmap to search on
SetTargetBitmap(bmp);
GetClientDimensions(w, h);
Writeln('Size: ' + inttostr(w) + ', ' + inttostr(h));
cts := GetToleranceSpeed;
SetColorToleranceSpeed(1);
SetLength(P, 0);
SetLength(P2, 0);
// I forgot which colours these are. You'll need each of the colours here.
{FindColorsTolerance(P, 7901592, 0, 0, w-1, h-1, 15);
P2 := CombineTPA(P, P2); // Don't forget to combine.
FindColorsTolerance(P, 3765443, 0, 0, w-1, h-1, 15);
P2 := CombineTPA(P, P2);
}
Colors := [14210562, 14803165, 1865668, 8560553, 317398];//Object Blue, Player White, Item Orange, Action Tan, NPC Yellow
SetLength(ATPA, Length(Colors));
for i := 0 to High(Colors) do
FindColorsTolerance(ATPA[i], Colors[i], 0, 0, w-1, h-1, 50);
P2 := MergeATPA(ATPA);
// Shadows
FindColorsTolerance(P, 460291, 0, 0, w-1, h-1, 30);
// Reset CTS
SetColorToleranceSpeed(cts);
// Copy of the bitmap, blank
bmp2 := CreateBitmap(w+1, h+1);
// Clear it
FastDrawClear(bmp2, 0);
DrawTPABitmap(bmp2, P2, clRed);
DrawTPABitmap(bmp2, P, clPurple);
// this takes a lot of time, but will be in simba/plugin
t := gettickcount;
ocr_FilterUpTextByCharacteristics(GetMufasaBitmap(bmp2));
t2 := gettickcount;
writeln('Time: ' + inttostr(t2-t));
// Draw something nice.
DisplayDebugImgWindow(w, h);
DrawBitmapDebugImg(bmp2);
DisplayDebugImgWindow(w, h);
SaveBitmap(bmp2, 'test.bmp');
settargetbitmap(bmp2); // new target for findcolorstolerance.
// we need to reset the client properly afterwards.
// comment this for shadow
findcolorstolerance(P, clRed, 0, 0, w-1,h-1, 0);
// uncomment this for shadow
//findcolorstolerance(P, clPurple, 0, 0, w-1,h-1, 0);
t := gettickcount;
ATPA := SplitTPAEx(P, 15, 2);
//SortATPAFromFirstPoint(ATPA, Point(0,0));
SortATPAFromFirstPointY(ATPA, Point(w/2, 0));
for i := 0 to high(ATPA) do
begin
P := ATPA[i];
ATPATemp := SplitTPAEx(P, 1, 10); // the 1 used to be 2, make it 2 if you
// experience problems with spacing
//SortTPAFrom(P, Point(0, 0));
// SortATPAFromFirstPoint(ATPATemp, P[0]);
SortATPAFromFirstPointX(ATPATemp, Point(0, 0));
DrawATPABitmap(bmp2, ATPATemp); // split draw
s := GetTextATPA(ATPATemp, 4, 'SmallChars'); // note that this is no shadow atm
// if you want to do it for shadow,
writeln(IntToStr(P[0].x) + ', ' + IntToStr(P[0].y) + ' : ' + s);
setlength(atpatemp,0);
setlength(p,0);
end;
t2 := gettickcount;
writeln('Time: ' + inttostr(t2-t));
SaveBitmap(bmp2, 'test_split.bmp');
SetImageTarget(target);
//SetDesktopAsClient;
FreeBitmap(bmp);
FreeBitmap(bmp2);
end.