SRL Archive - Help

Speeding up GetColor;


Eduard

2012-12-28 17:03:53

Hello Guys,

I'm experimenting with a huge project that i'm coding. Before I'm releasing anything I would like to experiment with SRL/SCAR and it's coding efficiency a bit.

I currently (for fun purphoses) wrote a bitmap creator that creates a bitmap from the client, read's it pixel by pixel(on purphose) and creates a negative effect and then writes it to the debug window.

program DrawNegativeClient;

var
x, y: integer;
ClientHeight, ClientWidth: integer;
BitmapClient: integer;

const
Savepath = 'C:\Users\Eduard\Desktop\MyBitmap.bmp';


procedure GetClientRes;

begin
//SetDesktopAsClient;
GetClientDimensions(ClientWidth,ClientHeight);
writeln('Height: '+inttostr(ClientHeight)+' Width: '+inttostr(ClientWidth)+'');
end;

procedure CreateBitmapFromScreen;

begin
BitmapClient:= CreateBitmap(ClientWidth,ClientHeight);
end;

procedure BitmapToDebugCanvas;
var
MyDebugCanvas: TCanvas;

begin
DisplayDebugImgWindow((ClientWidth),(ClientHeight));
DrawBitmapDebugImg(BitmapClient);
end;

procedure PixelOutputNegative;

var
R,G,B,NegativePixel, PixelFromScreen: integer;

begin
NegativePixel:= 0;
PixelFromScreen:= GetColor(x,y);
ColorToRGB(PixelFromScreen,R,G,B);
NegativePixel:= RGBToColor((255-R),(255-G),(255-B));
FastSetPixel(BitmapClient,x,y,NegativePixel);
end;

procedure RegisterEveryPixelOnScreen;

begin
y:= 0;
repeat
x:= 0;
while(x <= (ClientWidth - 1)) do
begin
PixelOutputNegative;
x:= x + 1;
end;
y:= y + 1;
until(y >= (ClientHeight-1))
end;



begin
ClearDebug;
GetClientRes;
CreateBitmapFromScreen;
RegisterEveryPixelOnScreen;
BitmapToDebugCanvas;
SaveBitmap(BitmapClient,SavePath);
FreeBitmap(BitmapClient);
end.


So, the psuedo working of the script is the following:

- GetClientDimension
- Scan the whole screen scanning the X-as first. Then when the Max X width is given do + Y. Actually scanning every pixel on the screen.
- Whilst reading the screen, convert the pixel to RGB and write the RGB to a color modifying the RGB colors by doing 255-R/G/B etc. Creating a negative effect.
- When done reading the client dimensions save file to bitmap


Problems:

It's quite slow. I would like to know how to fasten up the GetColor(x,y) process manually. Can it be faster?

Thanks,

Eduard

Eduard

2012-12-28 17:07:49

http://puu.sh/1GvkG for an example/

masterBB

2012-12-28 17:09:03

Freeze and UnFreeze.

Eduard

2012-12-28 17:09:31

Please elaborate? Freeze the client?

Eduard

2012-12-28 17:13:07

Ahh nvm, I didn't knew you mentioned functions

masterBB

2012-12-28 17:13:46

Everytime you use GetColor, it will get the color from the client.

Freeze;

youLoop;

Unfreeze;

might speed it up cause it freezes the client and copies it as a bitmap into simbas memory. Not requiring to bitblit every pixel.

edit:
Try not to double post ;)

Eduard

2012-12-28 17:16:01

Thanks, have you got any other suggestions to speed it up?

Wizzup?

2012-12-28 17:20:11

http://docs.villavu.com/simba/scriptref/colourfinding.html?#getcolors

E: Also: http://docs.villavu.com/simba/scriptref/bitmaps.html#invertbitmap

masterBB

2012-12-28 17:23:11

program DrawNegativeClient;

var
x, y: integer;
ClientHeight, ClientWidth: integer;
BitmapClient: integer;

const
Savepath = 'C:\Users\Eduard\Desktop\MyBitmap.bmp';


procedure GetClientRes;

begin
//SetDesktopAsClient;
GetClientDimensions(ClientWidth,ClientHeight);
writeln('Height: '+inttostr(ClientHeight)+' Width: '+inttostr(ClientWidth)+'');
end;

procedure CreateBitmapFromScreen;

begin
BitmapClient := BitmapFromClient(0, 0, ClientWidth-1, ClientHeight-1);
end;

procedure BitmapToDebugCanvas;
var
MyDebugCanvas: TCanvas;

begin
DisplayDebugImgWindow((ClientWidth),(ClientHeight));
DrawBitmapDebugImg(BitmapClient);
end;

begin
ClearDebug;
GetClientRes;
CreateBitmapFromScreen;
InvertBitmap(BitmapClient);
BitmapToDebugCanvas;
SaveBitmap(BitmapClient,SavePath);
FreeBitmap(BitmapClient);
end.

Eduard

2012-12-28 17:28:47

Thanks a lot guys,
Wizzup, do you have the source code of InvertBitmap?

Brandon

2012-12-28 17:44:23

Doing this in Simba itself will NEVER be fast enough. Consider writing a DLL.

Assuming the client is 765 x 553 in size and using RGBA format, this will take:

423045 iterations + other calculations you make such as shifting bytes left and right to switch from BGRA to RGBA. It's also interpreted.. Also remember that in Simba's internals, it will do these iterations as well.

You're roughly doing: 846k iterations + calculations.

masterBB

2012-12-28 17:46:42

From: Eduard
Thanks a lot guys,
Wizzup, do you have the source code of InvertBitmap?


https://github.com/MerlijnWajer/Simba/blob/master/Units/MMLCore/bitmaps.pas#L1351