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.
Bookmarks