Results 1 to 10 of 12

Thread: TBItmap scanline

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #8
    I'd consider optimizing that down to a few less operations...

    Code:
    procedure SetScanLinePixel(x,y:integer; c:longword; var surface:TBitmap);
    type
    	pRGBTriple=^tRGBTriple;
    	pWord=^word;
    var
    	p:pRGBTriple;
    begin
    	{ this typecast makes X add by multiples of 3 }
    	p:=pRGBTriple(surface.scanline[y])+x;
    	word(p^.g):=c and $0000FFFF;
    	p^.r:=(c shr 16) and $000000FF;
    end;
    Probably why NOBODY uses 24 bit bitmap formats -- I'd REALLY recommend upping to RGBA/32 bit format even if you aren't going to use the alpha channel, just for the speed boost, lesser code, etc, etc... Just not having pixels end up breaking qword boundaries would be a huge speedup.

    Assuming built from RGBQuad instead of triple:
    Code:
    procedure SetScanLinePixel(x,y:integer; c:longword; var surface:TBitmap);
    type
    	pLongWord=^longWord;
    var
    	p:pLongWord;
    begin
    	p:=pLongWord(surface.scanline[y])+x;
    	p^:=c;
    end;
    3 byte per pixel graphics sucks... slow, painfully bad math... there's a reason you rarely see anyone use it.

    Mind you, the above works in FPC, no clue if delphi allows for that type of pointer math.
    Last edited by deathshadow; 25-09-2011 at 01:01 PM.
    The accessibility of a website from time to time must be refreshed with the blood of designers and owners. It is its natural manure

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •