SRL Archive - Help and Support

AutoColor Dirt


nielsie95

2007-04-07 11:20:03

What is the best way to AutoColor dirt?

I'm trying to AutoGrab the DirtColor above the Lumbridge Swamp (next to Draynor). The SRL-function doesn't work there or it gets the wrong color. I have tried a couple of things, but this is my latest try:


function FindDirt: integer;
var Dirt, Dirt2, Dirt3, Dirt4, Dirt5, Dirt6, Dirt7, Dirt8, Tol: integer;
begin

Dirt := BitmapFromString(10, 3, 'z78DA333330313732321B52240' +
'0CF242437');
Dirt2 := BitmapFromString(11, 4, 'z78DA3331357632343719F124' +
'0001533809');
Dirt3 := BitmapFromString(11, 3, 'z78DA3331363635343019E224' +
'003E5B2731');
Dirt4 := BitmapFromString(25, 1, 'z78DA337636723634351E6424' +
'00B72620EA');
Dirt5 := BitmapFromString(27, 1, 'z78DA3331333637B43019C424' +
'00A5952170');
Dirt6 := BitmapFromString(22, 1, 'z78DA33713131323436195012' +
'0033DB1BAD');
Dirt7 := BitmapFromString(18, 1, 'z78DA33B33475353235A30B09' +
'0008A117A1');
Dirt8 := BitmapFromString(22, 1, 'z78DA333333753432361B5012' +
'004E531C1B');

repeat
Result := AutoColorThis(Dirt4, Tol, 628 -Tol, 64 -Tol, 675 +Tol, 104 +Tol)
if Result < 1 then
Result := AutoColorThis(Dirt5, Tol, 628 -Tol, 64 -Tol, 675 +Tol, 104 +Tol)
if Result < 1 then
Result := AutoColorThis(Dirt6, Tol, 628 -Tol, 64 -Tol, 675 +Tol, 104 +Tol)
if Result < 1 then
Result := AutoColorThis(Dirt , Tol, 628 -Tol, 64 -Tol, 675 +Tol, 104 +Tol)
if Result < 1 then
Result := AutoColorThis(Dirt2, Tol, 628 -Tol, 64 -Tol, 675 +Tol, 104 +Tol)
if Result < 1 then
Result := AutoColorThis(Dirt3, Tol, 628 -Tol, 64 -Tol, 675 +Tol, 104 +Tol)
if Result < 1 then
Result := AutoColorThis(Dirt8, Tol, 628 -Tol, 64 -Tol, 675 +Tol, 104 +Tol)
if Result < 1 then
Result := AutoColorThis(Dirt7, Tol, 628 -Tol, 64 -Tol, 675 +Tol, 104 +Tol)
if Result < 1 then Tol := Tol +2
if Result < 500000 then Result := 0;
if Result > 3000000 then Result := 0;
until ((Result > 1) or (Tol > 60))
if Result < 1 then
begin
WriteLn('DirtRoadColor NOT found!');
WriteLn('Terminating script..');
TerminateScript;
end

WriteLn('DirtColor = '+IntToStr(Result)+' Found at a Tol of '+IntToStr(Tol));

FreeBitmap(Dirt);
FreeBitmap(Dirt2);
FreeBitmap(Dirt3);
FreeBitmap(Dirt4);
FreeBitmap(Dirt5);
FreeBitmap(Dirt6);
FreeBitmap(Dirt7);
FreeBitmap(Dirt8);
end;

^ This will most of the time grab the right color at the Yews, but next to the Draynor Bank (where the Dirt begins) it will most of the time grab the wrong color. However, next to the bank, SRL FindDirtRoadColor works like 65% of the time (not if the color is too dark or too light :p).

So now my question: What is the best way to get the right color at both of those places?

WhiteShadow

2007-04-07 12:47:42

Brute force.

rgb, or hsl. Personally, right now I find HSL better.

I think Avaphi and Lorax both made a tutorial on it. ;D

Boreas

2007-04-07 17:59:35

HSL
program symbol;
{.include srl/srl.scar}
{.include DoorProfiles.scar}
var SymbolBackgroundColor,t,f:integer;
tmpTPA1: array of tpoint;
tmpAOTPA: array of array of tpoint;

function GetSymbolBackgroundColor:integer;
var
TmpBmp,lilbmp,MyX,MyY:integer;
MyColor,tx,ty: integer;
MyCanvas:tcanvas;
TmpBool:boolean;
MyH,MyS,MyL:extended;
begin
TmpBmp:= BitmapFromString(100,90,'');
lilbmp:=bitmapfromstring(2,2,' ');
MyCanvas:=GetBitmapCanvas(TmpBmp)

CopyCanvas(GetClientCanvas,MyCanvas,598,39,698,129,0,0,100,90)
for MyY:=0 to 99 do
begin
for MyX:=0 to 89 do
begin
MyColor:= MyCanvas.pixels[MyX,MyY];
ColortoHSL(MyColor,MyH,MyS,MyL);
if MyS <40.0 then
begin
if MyL > 65.0 then
begin
if MyH<60.0 then
begin
if MyL<100.0then
begin
if MyH>0.0 then
begin
FastDrawClear(lilbmp,MyColor);
if FindBitmapIn(lilbmp,tx,ty,mmx1,mmy1,mmx2,mmy2) then
begin

// tmpTPA1:=GetPixelsD(MyColor,mmx1,mmy1,mmx2,mmy2,0);
// tmpAOTPA:=SplitTPA(tmpTPA1);

// writeln(inttostr(getarraylength(tmpAOTPA)));
TmpBool:=true;
//mmouse(tx,ty,0,0);
end;
end;
end;
end;
end;
end;
if TmpBool then break;
end;
if TmpBool then break;
end;
if TmpBool then result:=MyColor;
end;
Var DebugCanvas,BmpCanvas:TCanvas;
procedure AddArray (WhichTPA:array of tpoint; WhichColor:integer);
var parray, arraylength:integer;
begin
arraylength:=getarraylength(whichtpa);
for parray:=0 to arraylength-1 do
bmpcanvas.pixels[whichtpa[parray].x-576+5,whichtpa[parray].y-9+5]:=WhichColor;
Copycanvas(BmpCanvas,DebugCanvas,0,0,150,157,5,5,155,162)
end;


procedure StartMiniMapDebug;
Var bmpBlankMap:integer;
begin {
bmpBlankMap:= LoadBitmap(apppath+'test.bmp');
DisplayDebugImgWindow(160,167) //to show the canvas
DebugCanvas:=getdebugcanvas //gets the referance to the debug image and stores in that varaible
BmpCanvas:=GetBitmapCanvas(bmpBlankMap)//gets the regerance to the bmp and stores in that variable
BlankMapCanvas:=GetBitmapCanvas(bmpBlankMap);
Copycanvas(BmpCanvas,DebugCanvas,0,0,150,157,5,5,155,162)
FreeBitmap(bmpBlankMap);

}
bmpBlankMap:= LoadBitmap(apppath+'test.bmp');
DisplayDebugImgWindow(160,167) //to show the canvas
DebugCanvas:=getdebugcanvas //gets the referance to the debug image and stores in that varaible
BmpCanvas:=GetBitmapCanvas(bmpBlankMap)//gets the regerance to the bmp and stores in that variable
Copycanvas(BmpCanvas,DebugCanvas,0,0,150,157,5,5,155,162)

end;

var tmptpa2:array of tpoint;
begin
setupsrl; activateclient;
t:=getsystemtime;
SymbolBackgroundColor:=GetSymbolBackgroundColor;
writeln(inttostr(SymbolBackgroundColor));
if SymbolBackgroundColor=0 then writeln('there are no symbols on the minimap');
writeln(inttostr(getsystemtime-t)+'ms');

if SymbolBackgroundColor<>0 then
begin
tmpTPA1:=GetPixelsD(SymbolBackgroundColor,mmx1,mmy1,mmx2,mmy2,0);
tmpAOTPA:=SplitTPA(tmpTPA1);
setarraylength(tmptpa2,2);
tmptpa2:= RearrangeTPA(tmpAOTPA[0],0,1,true,true);
writeln(inttostr(getcolor(tmptpa2[0].x-1,tmptpa2[0].y)));
tmpTPA1:=GetPixelsD(getcolor(tmptpa2[0].x-1,tmptpa2[0].y),mmx1,mmy1,mmx2,mmy2,0);
tmpAOTPA:=SplitTPA(tmpTPA1);
writeln(inttostr(getarraylength(tmpaotpa[2])));
writeln(inttostr(getsystemtime-t)+'ms');

StartMiniMapDebug;
for f:= 0 to getarraylength(tmpAOTPA)-1 do
begin

//cleardebug;
writeln('press f12');
repeat
wait(30);
until isfkeydown(12);
//StartMiniMapDebug;
//writeln(tPtArrayToStr(myAOTPA[f]));

writeln('press f11');
repeat
wait(30);
until isfkeydown(11);


AddArray(tmpAOTPA[f],16777215);


end;
end;

end.

RGB
program ladder;

const
floorcolor=6776943;


function HowManyAround(HalfWidth,ParX,ParY,TheColor:integer;WhichCanvas:tcanvas):integer;
var MyX,MyY,MyColor,TmpResult:integer;
begin
for MyY:=ParY-(HalfWidth) to ParY+(HalfWidth) do
begin
for MyX:=ParX-(HalfWidth) to ParX+(HalfWidth) do
begin
MyColor:=WhichCanvas.pixels[MyX,MyY];
if MyColor=TheColor then
TmpResult:=TmpResult+1;
end;
end;
result:=TmpResult;
end;



function GetLadderColor(TheFloorColor:integer):integer;
var
TmpBmp,MyX,MyY:integer;
MyColor,TmpInt: integer;
MyCanvas:tcanvas;
TmpBool:boolean;

begin
TmpBmp:= BitmapFromString(100,90,'');
MyCanvas:=GetBitmapCanvas(TmpBmp)

CopyCanvas(GetClientCanvas,MyCanvas,598,39,698,129,0,0,100,90)
for MyY:=0 to 99 do
begin
for MyX:=0 to 89 do
begin
MyColor:= MyCanvas.pixels[MyX,MyY];
if not(MyColor=78673)then
if ((MyColor/256) / 256) <20 then
begin
if ((MyColor/256) mod 256) <65 then
begin
if ((MyColor/256) mod 256) >15 then
begin
if (MyColor mod 256) < 105 then
begin
if (MyColor mod 256) > 60 then
begin
TmpInt:=HowManyAround(4,MyX,MyY,TheFloorColor,MyCanvas);
if TmpInt>30 then
begin
if TmpInt<100 then
TmpBool:=true;
end;

end;
end;
end;
end;
end;
if TmpBool then break;
end;
if TmpBool then break;
end;
if TmpBool then result:=MyColor;
end;
var TheLadderColor,t:integer;
begin
t:=getsystemtime;
TheLadderColor:=GetLadderColor(FloorColor);
writeln(inttostr(TheLadderColor));
writeln(inttostr(getsystemtime-t)+'ms');
end.

Basically, get a bunch of samples, and get the HSL/RGB values, then get the ranges. Then use stacked if statements with the max/mins of the components. Notice I started with the smallest max, or the biggest min first, this means it eliminates things quicker without wasting time.

BTW, both of those have something after the stacked ifs, to eliminate other stuff that falls in the same range. For example on the symbol color, it was picking up wall color, but since walls aren't 2 pixels thick, I made a bitmap 2x2 pixels of the color to make sure.

nielsie95

2007-04-09 03:29:20

Thanks Boreas! I now got it working using a modified GetLadderColor :). Thanks again :)

Boreas

2007-04-09 09:19:50

Np :D