Re: Optimize this code

"tonypaulday" <[email protected]> Fri, 22 Aug 2003 15:57:18 -0000
Newsgroups gmane.comp.lang.delphi.programming
Message-ID <[email protected]>
Sorry for the delay....

with DIB you can basically just treat it as an array which is a damn
site faster to access though the pixels property and when you are
finished copy that whole array....


ie an example first set up a bitmapinfo record something like....


procedure SetUpBitmapInfo;
begin
BitmapInfo.bmiHeader.bisize := sizeof(TBitmapInfoHeader);
BitmapInfo.bmiHeader.biHeight := ClientHeight;
BitmapInfo.bmiHeader.biWidth := ClientWidth;
BitmapInfo.bmiHeader.biPlanes := 1;

{$IfDef 32BIT}
    BitmapInfo.bmiHeader.biBitCount := 32;
{$ELSE}
    BitmapInfo.bmiHeader.biBitCount := 24; {Makes things v. much
quicker on some displays}
{$ENDIF}

BitmapInfo.bmiHeader.biCompression := BI_RGB;
BitmapInfo.bmiHeader.bisizeImage := 0;
BitmapInfo.bmiHeader.biXPelsPerMeter := 0;
BitmapInfo.bmiHeader.biYPelsPerMeter := 0;
BitmapInfo.bmiHeader.biclrUsed := 0;
BitmapInfo.bmiHeader.biclrImportant := 0;

end;


and to load a canvas into an DIB array you would use GetDIBits

eg something like....

GetDIBits(Canvas.Handle, ImgHeight.Picture.Bitmap.Handle, 0, 256,
@GroundArray[0], BitmapInfo, DIB_RGB_COLORS);

and to set it back you would use something SETDIBits

eg.....

SetDIBitsToDevice(Canvas.Handle, 0, 0, ClientWidth, ClientHeight, 0,
0, 0, ClientHeight, @BitsArray[0], BitmapInfo, DIB_RGB_COLORS);

sorry it's just a quick note..... if you want to see these calls in
context I could Email you a little example app where I use them.

HTH

Tony

--- In [email protected], DK <dread_k1@y...> wrote:
> If this code is what you mean, then the delta time between my old
proc with this proc is insignificant. When I use this unit (with my
old proc.) to process 85kB file in 24 bit bitmap 800x600, the average
time required is 2600 ms (run on Duron 750, WinXP Pro, 256 MB) and
when I use this proc the average time is about 2600 ms too. I think
it's mainly because it still use pixels to access the color twice.
Does the use of scanline will make bigger improvement? In this unit
the color info is not accessed simultaneously in a row so I wonder if
scanline can reduce the  required time, isn't it? I don't know how to
use DIB. Any example on how to use DIB will be appreciated so much.
>  
> procedure TStegoStream.SetBit(Value: Integer);
> var Pos : integer;
> begin
>   Pos := ColorPos * 8 + BitPos;
>   Value := (Value and 1) Shl Pos;
>   BMP.Canvas.Pixels[X, Y] := (BMP.Canvas.Pixels[X, Y] and not (1 shl
Pos) or Value);
>   NextBit;
> end;
> Forgive my horrible English
>  
> Regards,
> DK
> 
>  Yahoo! Biztools
> - Promote your business from just $5 a month!
> 
> [Non-text portions of this message have been removed]


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
Printer at Myinks.com. Free s/h on orders $50 or more to the US & Canada. http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/l.m7sD/LIdGAA/qnsNAA/i7folB/TM
---------------------------------------------------------------------~->

Delphi VCL Top Sites!
http://www.sandbrooksoftware.com/TS/TS2/Components.shtml
---------------------------------------------------------------
Unsubscribe:[email protected]
List owner:[email protected]
--------------------------------------------------------------- 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/