Re: Optimize this code
Allan Smith <[email protected]> Mon, 18 Aug 2003 10:59:27 +0100
| Newsgroups | gmane.comp.lang.delphi.programming |
|---|---|
| Message-ID | <[email protected]> |
On Mon, 18 Aug 2003 07:44:17 +0700, dk wrote: >Hi all, >Is there anyone can optimize this code? >I'm making a steganography program based on LSB insertion bit, I think the problem is in the use of property pixels from TCanvas. It's too slow. HEre's the code: > >procedure TStegoStream.SetBit(Value: Integer); >var > NewColor: TColor; > Pos: Integer; > R: PRGBTripleArray; >begin > NewColor := BMP.Canvas.Pixels[X, Y]; > Value := Value and 1; > Pos := ColorPos * 8 + BitPos; > NewColor := NewColor and not(1 shl Pos); > NewColor := NewColor or (Value shl Pos); > BMP.Canvas.Pixels[X, Y] := NewColor; > NextBit; >end; Here's one idea - it should be faster procedure TStegoStream.SetBit(Value: Integer); begin Value := (Value and 1) Shl (ColorPos * 8 + BitPos); BMP.Canvas.Pixels[X, Y] := (BMP.Canvas.Pixels[X, Y] and not Value) or Value; NextBit; end; -- Regards, Allan Smith (Northwood, Middlesex, England) ------------------------ 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/