SRL Archive - SRL Archives

UpdateIn - For your autocolor needs


n3ss3s

2007-11-23 09:33:50

While my internet once again wasn't working, I whipped up a simple autocolor procedure.

It finds all the colors Color in the box formed by x1, y1, x2, y2 within the tolerance MaxTol.

After it has got the TPA, it goes through the points, and sorts out the color that had the smallest tolerance to Color and updates it.

Now it works without user input tolerance!

Enjoy ;)


Procedure UpdateIn(Var Color: Integer; x1, y1, x2, y2: Integer);
Var
OldColor, tmpHandle, bmp, L, I, TempTol, NewC, T, W, H, MaxTol, CTS: Integer;
TPA: TPointArray;
Begin
//If Not LoggedIn Then Exit;
CTS := GetColorToleranceSpeed;
If Not CTS = 2 Then ColorToleranceSpeed(2);
MaxTol := Round(Distance(x1, y1, x2, y2) * 1.5);
SetColorSpeed2Modifiers(0.3, Distance(x1, y1, x2, y2) * 0.02);
OldColor := Color;
tmpHandle := GetClientWindowHandle;
bmp := BitmapFromString2(False, '');
CopyClientToBitmap(bmp, x1, y1, x2, y2);
SetTargetBitmap(bmp);
GetBitmapSize(bmp, W, H);
FindColorsTolerance(TPA, OldColor, 0, 0, W, H, MaxTol);
Try
TempTol := iAbs(Color - GetColor(TPA[High(TPA)].x, TPA[High(TPA)].y));
Except
Writeln('No instances of the color Color found.');
SetClientWindowHandle(tmpHandle);
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Exit;
End;
L := High(TPA);
For I := 0 To L Do
Begin
T := iAbs(Color - GetColor(TPA[i].x, TPA[i].y));
If T < TempTol Then
Begin
TempTol := T;
NewC := I;
End;
End;
If NewC <> 0 Then
Begin
Color := GetColor(TPA[NewC].x, TPA[NewC].y);
If FindColor(W, H, Color, x1, y1, x2, y2) Then
MoveMouse(W, H);
Writeln('---<UpdateIn>---');
Writeln('Old: '+IntToStr(OldColor));
Writeln('New: '+IntToStr(Color));
Writeln('----------------');
End Else
Begin
Writeln('Color could not be updated.');
End;
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.2, 0.2);
SetClientWindowHandle(tmpHandle);
End;

JuKKa

2007-11-23 09:35:34

N3ss3s are u addicted?

Anyways GJ!

n3ss3s

2007-11-23 09:39:10

N3ss3s are u addicted?


Was that a question?

Just wait till I get the 128*128 so I can steal the Hopelessly Addicted from Rik :p

(Hopelessly Addicted is one of those big avys - the guy with a laptop in bath :p )

R0b0t1

2007-11-23 18:55:42

Nice.


And: OMG! It contains TPA's… What a surprise… :)

n3ss3s

2007-11-24 03:05:31

Yeah, now Im making a DoorOpen: Boolean with TPA:s included :)

LordGregGreg

2007-11-24 03:34:23

nice and simple, i like it, should solve most outocoling issues.

however… why bother having a max tolerance? you could make ure tpa have all the points in the box… and then sort.

oh, but that could take a while…

hmm, so why not have a set default max tolerance? (trying to get rid of a variable here to make it simpler)

hmm, well, in a small box, you basically could take in all the points witout much of a issue.. but a larger box would cause problems, and you would need to limit the tolerance.

so why not remove the tolerance variable and dynamically create it based upon the box size?

you could easily whip up a calulcation for the area of the box, and then use that to determine a nice tolerance.

tolerance = 250 - (area * scalarConstant);

(assuming that max tolerance is 255, i forgot) but this would generate a linera function to inversly corelate your area and tolerance.

depending on how it all plays out in real time, you may want to make it quadratic, somethign like tolerance = 250 - (area * area * scalarConstant);

n3ss3s

2007-11-24 03:42:11

O.o

*silence*

Doesn't sound bad at all, I'll try to do that after I get DoorOpen: Boolean done…

EDIT: Okay, DoorOpen works now in MS Paint, —> Rs

LordGregGreg

2007-11-24 04:08:13

From: n3ss3s
O.o

*silence*

Doesn't sound bad at all, I'll try to do that after I get DoorOpen: Boolean done…

EDIT: Okay, DoorOpen works now in MS Paint, —> Rs

good good :D

and yeah, its really a decent bit of work and a bit of testing really just to make one varable "smart", but i figured that this thing is really a "simplifing" method. Obviously, if you have special cases that wont work with this, you woudl make you own customized method, this one will probably be used by peopel who may not really want to even understand it, and therefore, removing one of the varables not only makes it simpler to use (and type, lol) but also prevents them from screwing it up.

anyhows, i dont know how much free time you have, lol, but it could be cool

Hugolord

2007-11-24 04:08:28

woah your making tonnes of stuff these days n3ss3s thanks =D

n3ss3s

2007-11-24 04:11:09

No prob hugo.

Greg, I got time more than enough :)

Released DoorOpen, its in the SRL New Functions.

Now, I'll start working on that tol shit :)

EDIT: I think I'll use HSL and find how much does Luminance change every 5 pixels…

n3ss3s

2007-11-24 04:25:15

*BUMP*

WOAH, Already ready!

Now it works without user input tolerance!