SRL Archive - Help and Support

Needing to CopyBitmap, why?


bonsai

2014-08-25 17:07:59

I was playing with some bitmap stuff and found I needed to do a CopyBitmap before processing. I also found some older code on the site that did it that way.

Didn't work (or worked on rare occasion?):

bmp := BitmapFromString(...);
greyBmp := GreyScaleBitmap(bmp, ...);

Works:

bmp := BitmapFromString(...);
copiedBmp := CopyBitmap(bmp, ...);
greyBmp := GreyScaleBitmap(copiedBmp, ...);

Why?

Enslaved

2014-08-28 20:08:04

pointer logic I think, that or by Calling bmp := bmpfromsting, you load the bitmap into locked memory or whatever

bonsai

2014-08-28 20:12:38

I saw some more weird behavior yesterday. It seems like the debug window paints a black screen sometimes. So I'm not all that sure the copy thing was what was fixing it.

The graphic operations are so heavy I don't want to be copying things I don't need to.

Brandon

2014-08-28 20:46:00

Problem is on your end..

Does not work (must be ran multiple times first.. before it works..):


Procedure Show(Bmp: Integer);
var
W, H: Integer;
Begin
ClearDebugImg;
GetBitmapSize(Bmp, W, H);
DrawBitmapDebugImg(Bmp);
DisplayDebugImgWindow(W, H);
End;

var
Bmp, GreyBmp: Integer;
begin
Bmp := BitmapFromString(100, 100, 'meJzt1sEJg0AQBdByth+ryc0q' +
'cksH6SGQJrymgBQxETao7BqIh4hL3vBO47LCZ0ZMfSQAAAAAAAAAA' +
'AAAAIC/1/URz3hEpPO7cznHWLeYny6r6KdreVXRLB7lWr6uITtklS' +
'+sq4704L7Jqh6D77Oampfn3IxhfkVDfp3V8rbJqW9yE+stW921qbr' +
'7tqxu13KoPp08PlltzWrnHczNRnfwd1nlT9NYp6E8Vgzb8W39Z8gn' +
'6/4YxWpzvORxX9nx5oZqn6xS9YvV3EQBAAAAAAAAAAAAAAAAAA15A' +
'UG7Uxs=');

GreyBmp := GreyScaleBitmap(Bmp);
FreeBitmap(Bmp);
Show(GreyBmp);
FreeBitmap(GreyBmp);
end.



Works (Everytime..):

Procedure Show(Bmp: Integer);
var
W, H: Integer;
Begin
ClearDebugImg;
GetBitmapSize(Bmp, W, H);
DisplayDebugImgWindow(W, H);
DrawBitmapDebugImg(Bmp);
End;

var
Bmp, GreyBmp: Integer;
begin
Bmp := BitmapFromString(100, 100, 'meJzt1sEJg0AQBdByth+ryc0q' +
'cksH6SGQJrymgBQxETao7BqIh4hL3vBO47LCZ0ZMfSQAAAAAAAAAA' +
'AAAAIC/1/URz3hEpPO7cznHWLeYny6r6KdreVXRLB7lWr6uITtklS' +
'+sq4704L7Jqh6D77Oampfn3IxhfkVDfp3V8rbJqW9yE+stW921qbr' +
'7tqxu13KoPp08PlltzWrnHczNRnfwd1nlT9NYp6E8Vgzb8W39Z8gn' +
'6/4YxWpzvORxX9nx5oZqn6xS9YvV3EQBAAAAAAAAAAAAAAAAAA15A' +
'UG7Uxs=');

GreyBmp := GreyScaleBitmap(Bmp);
FreeBitmap(Bmp);
Show(GreyBmp);
FreeBitmap(GreyBmp);
end.




WHY? Well.. it's simple. The first example draws BEFORE the window is displayed.. The second example draws AFTER the window is displayed.
In WinAPI, WM_PAINT is NOT processed until the window is on the screen at least once. After that, all subsequent messages are processed..
Simba's Debug Window uses WinAPI under the hood for Windows and X-Windows for Linux. These rules apply to both.


If it's happening for processing as well and not DRAWING, then there's an internal state delay going on somewhere..

I tested processing (and drawing).. both work fine:


Procedure Show(Bmp: Integer);
var
W, H: Integer;
Begin
ClearDebugImg;
GetBitmapSize(Bmp, W, H);
DisplayDebugImgWindow(W, H);
DrawBitmapDebugImg(Bmp);
End;

var
I, J: Integer;
Bmp, GreyBmp: Integer;
begin
Bmp := BitmapFromString(100, 100, 'meJzt1sEJg0AQBdByth+ryc0q' +
'cksH6SGQJrymgBQxETao7BqIh4hL3vBO47LCZ0ZMfSQAAAAAAAAAA' +
'AAAAIC/1/URz3hEpPO7cznHWLeYny6r6KdreVXRLB7lWr6uITtklS' +
'+sq4704L7Jqh6D77Oampfn3IxhfkVDfp3V8rbJqW9yE+stW921qbr' +
'7tqxu13KoPp08PlltzWrnHczNRnfwd1nlT9NYp6E8Vgzb8W39Z8gn' +
'6/4YxWpzvORxX9nx5oZqn6xS9YvV3EQBAAAAAAAAAAAAAAAAAA15A' +
'UG7Uxs=');

GreyBmp := GreyScaleBitmap(Bmp);
FreeBitmap(Bmp);

For I := 0 To 99 do
For J := 0 To 99 do
begin
if (FastGetPixel(GreyBmp, J, I) <> 10263708) then //that's the grey colour.. I'll just print the white text..
writeln(FastGetPixel(GreyBmp, J, I));
end;

Show(GreyBmp);
FreeBitmap(GreyBmp);
end.


So.. I guess you made the mistake in the first example? Or is there a specific case where this isn't working for you?

If you prefer speed over convenience, write your own greyscale that modifies the given bitmap rather than copying and then greying like Simba's internal GreyScaleBitmap function. You'll have to do testing though because the internal one is a native function and the lape one could possibly be slower if you write it yourself within a script and not a plugin..

I'd say it'll probably be faster though.

bonsai

2014-08-29 02:41:38

Thanks! Makes sense.

I did it that way initially and have been copy/pasting it.

I thought I was being good by giving it all of it's info before telling it to show the window.