SRL Archive - OSR Help

PixelShift


NKN

2012-04-25 21:08:00

How do you use it? I picked up M34tcode's new Pixelshift, cause it's more accurate, but I don't know how to use it.

Here's what I got:
function GetColArr (Box : TBox) : T2DIntegerArray;
var
x,y : Integer;
begin
SetArrayLength(Result,box.X2-box.X1);
for x := 0 to box.X2-box.X1-1 do
begin
SetArrayLength(Result[x],box.Y2-box.Y1);
for y := 0 to box.Y2-box.Y1-1 do
begin
Result[x][y] := GetColor(x+box.X1,y+box.Y1);
end;
end;
end;

function ValidatePixels(Box : TBox; OrigCols : T2DIntegerArray; BoolArr : array of TBoolArray; Tolerance : Integer):Boolean;
var
X,Y : Integer;
NewCols : T2DIntegerArray;
begin
NewCols := GetColArr(Box);
for X := 0 to Box.X2 - Box.X1-1 do
for Y := 0 to Box.Y2 - Box.Y1-1 do
begin
if not BoolArr[x][y] then
continue;
boolArr[x][y] := SimilarColors(origCols[x][y],NewCols[x][y],Tolerance);
Result := True
end;
end;

function InitBoolArr(Width,Height : Integer) : array of TBoolArray;
var x,y : Integer;
begin
SetArrayLength(Result,Width);
for x := 0 to Width-1 do
begin
SetArrayLength(Result[x],Height);
for Y := 0 to Height-1 do
begin
Result[x][y] := True;
end;
end;
end;

function countBools(BoolArr : Array of TBoolArray; CountTrues : Boolean) : Integer;
var
X,Y,W,H,C : Integer;
begin
W := GetArrayLength(BoolArr);
H := GetArrayLength(BoolArr[0]);
For X := 0 to W-1 do
for Y := 0 to H-2 do
if BoolArr[X][Y] = CountTrues then
Inc(C);
Result := C;
end;

function CalcNonStaticPixelCount(Box : TBox; ShiftInterval, Repetitions, Tolerance : Integer) : Integer;
var
I,X,Y : Integer;
T,TT : LongInt;
OrigColArr : T2DIntegerArray;
BoolArr : array of TBoolArray;
begin
OrigColArr := GetColArr(Box);
BoolArr := initBoolArr(Box.X2-Box.X1,Box.Y2-Box.Y1);
MarkTime(T);
MarkTime(TT);
for I := 0 to Repetitions-1 do
begin
if (TimeFromMark(T) > (Repetitions*ShiftInterval)) then
begin
srl_Warn('CalcNonStaticPixelCount','Completed only ' + IntToStr(I) + ' of '
+ IntToStr(Repetitions) + '. Try increasing the interval',1);
break;
end;
if (I > 0) then
writeln('CalcNonStaticPixelCount: Iteration ' + IntToStr(I) + ' took '
+ FloatToStr(TimeFromMark(TT)/1000.0) + ' seconds to complete.');
MarkTime(TT);
wait(Max(0,ShiftInterval-TimeFromMark(TT)));
validatePixels(Box,OrigColArr,BoolArr,Tolerance);
SMART_ClearCanvas;
for x := 0 to box.x2-box.x1-1 do
for y := 0 to box.y2-box.y1-1 do
if boolArr[x][y] then
SMART_DrawDot(false,Point(x+box.x1,box.y1+y),clRed);
end;
Result := countBools(BoolArr,False);
end;

Abu

2012-04-27 00:47:49

From what is looks like you do


//so basically like this:
CalcNonStaticPixelCount(PlayerBox, 4000, 80, 250)

So it runs for a maximum of 4 seconds and checks 80 times in that 4 seconds. And if I'm correct the tolerance is the tolerance for pixels.

I think so anyway.

Le Jingle

2012-04-27 01:08:38

I picked up a little understanding browsing through the mime antirandoms include.
Can't say enough to explain it, but I get the idea of how to use it. Or so I think.

Daniel

2012-04-27 03:49:14

All PixelShift does is count the number of pixels that change over a given time. SRL's one only checks it twice, once at the beginning and once at the end, comparing the two. While m34tc0de's one checks it several times during the time you specify.

Abu

2012-04-27 14:52:08

From: Daniel
All PixelShift does is count the number of pixels that change over a given time. SRL's one only checks it twice, once at the beginning and once at the end, comparing the two. While m34tc0de's one checks it several times during the time you specify.


He wants to know how to use it. Good explanation though :p

Anyway, after reading over it I think you just use it like a normal PixelShift function, filling it out the way I stated above.