SRL Archive - OSR Help

Handling bitmaps in a plugin?


marpis

2011-01-09 14:00:16

How do I use GetPixel with Lazarus? I want to have this function in a plugin:
function G_MakeColorBoxEx(bmp, x1, y1: integer): Array of Integer;  //[0]=Red [1]=Green [2]=Blue
var
x, y: integer;
R, G, B: integer;
begin
SetLength(Result, 3);

for x := x1 to (x1 + 4) do
for y := y1 to (y1 + 4) do
begin
try
ColorToRGB(FastGetPixel(bmp, x, y), R, G, B); // <--- How is this done in a plugin?
Result[0] := Result[0] + R;
Result[1] := Result[1] + G;
Result[2] := Result[2] + B;
except
//writeln('ColorToRGB exception: '+inttostr(x)+', '+inttostr(y));
end;
end;
end;

And I really want the bmp parameter to be an integer, so I can first call
CopyClientCanvas()
in Simba and input that bitmap into the function above.

Wizzup?

2011-01-09 14:01:14

Pass the TMufasaBitmap. Then use FastGetPixel.

GetMufasaBitmap(bmp) returns the TMufasaBitmap.

E:
program new;

function G_MakeColorBoxEx(bmp: TMufasaBitmap; x1, y1: integer): Array of Integer; //[0]=Red [1]=Green [2]=Blue
var
x, y: integer;
R, G, B: integer;
begin
SetLength(Result, 3);

for x := x1 to (x1 + 4) do
for y := y1 to (y1 + 5) do
begin
try
ColorToRGB(bmp.FastGetPixel(x, y), R, G, B);
Result[0] := Result[0] + R;
Result[1] := Result[1] + G;
Result[2] := Result[2] + B;
except
//writeln('ColorToRGB exception: '+inttostr(x)+', '+inttostr(y));
end;
end;
end;

var
bmp, w, h: Integer;
mbmp: TMufasaBitmap;

begin
bmp := CreateBitmap(10, 10);
mbmp := GetMufasaBitmap(bmp);

GetClientDimensions(w,h);

mbmp.CopyClientToBitmap(GetTClient.IOManager, True, 0, 0, 0, 0, w-1, h-1);

G_MakeColorBoxEx(mbmp, 42, 42);
end.

You'll need to include parts of the MML in your plugin. (You should anyway)

marpis

2011-01-09 14:13:17

I dont understand.
I want the G_MakeColorBox to be in my plugin, how can I use type TMufasaBitmap and function FastGetPixel inside the plugin?

Also, what's the x parameter in ReadFileString?

Wizzup?

2011-01-09 14:31:32

From: marpis
I dont understand.
I want the G_MakeColorBox to be in my plugin, how can I use type TMufasaBitmap and function FastGetPixel inside the plugin?


Where is your plugin source? I'll add it.
Anyway, passing a pointer of the TMufasaBitmap is perfectly valid and there's no reason you can't call FastGetPixel on it.

Also, what's the x parameter in ReadFileString?


http://docs.villavu.com/simba/scriptref/files.html#readfilestring

Gu3st...

2011-01-09 14:31:36

From: marpis
Also, what's the x parameter in ReadFileString?
How much of the file to read. IE FileSize() would read everything inside the specific file, while 2 would read the first 2 bytes(?).