Results 1 to 10 of 12

Thread: TBItmap scanline

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    There's not really a way you can do that
    Peregrinus, expectavi pedes meos in cymbalis
    Nullus norvegicorum sole urinat

  2. #2
    You need to use canvas instead of scanline if you want to do that. I would suggest calculating the scanline offset manually instead of using the scanline property. Just be sure to check it's pixelFormat

    Really,
    Code:
    p:=pointer(longword(bmp.canvas)+desiredScanLine*bmp.width*4);
    Should do the trick. Is that REALLY so much harder than calling scanline? I doubt it.

    Oh, and I REALLY suggest using longword instead of integer on these types of operations, you never know when the sign bit is going to mess with you.

    honestly, the mere existance of the scanline method in tbitmap is probably why I stopped using it -- it makes image loads take longer setting up all those pointers.
    Last edited by deathshadow; 12-07-2011 at 04:17 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

  3. #3
    thanks , but i changed the direction
    i mean it was just my attempt to create a game from scratch (frame buffer) , instead of VCL i used API and CreateDIBSection (much easier) , but even i use assembly code for ploting pixels , i failed to make a smooth sprite movment .

    now i am using SDL
    Last edited by AirPas; 13-07-2011 at 08:58 AM.

  4. #4
    hi again

    could some one correct me , i've tryed to make a procedure that plot a given pixel ( x ,y , color) into TBitmap class

    Code:
    procedure SetScanLinePixel(x,y,c : integer; var _bmp : TBitmap);
    type
      pRGBTripleArray = ^TRGBTripleArray;
      TRGBTripleArray = array[0..32768-1] of TRGBTriple;
    var
      raw : pRGBTripleArray;
    begin
      raw := _bmp.ScanLine[y];
      raw[x].rgbtBlue  := ( c and $ff);
      raw[x].rgbtGreen := ( c shl 8 ) and $ff;
      raw[x].rgbtRed:= ( c shl 16) and $ff; //error :constant expression violates subrange bounds 
    end;
    i don't understand the last compiler error ,

  5. #5
    Disable the compiler's range check error in project options or use {$R-} flag at top of your unit. Also change "c" to be Cardinal and change "shl" to "shr".
    Last edited by LP; 20-09-2011 at 04:27 PM.

  6. #6
    @Lifepower : thanks , i also didn't swap the color
    so this is the correct code

    Code:
    procedure SetScanLinePixel(x,y: integer; c : cardinal; var _bmp : TBitmap);
    type
      pRGBTripleArray = ^TRGBTripleArray;
      TRGBTripleArray = array[0..32768-1] of TRGBTriple;
    var
      raw : pRGBTripleArray;
    begin
      raw := _bmp.ScanLine[y];
      raw[x].rgbtRed    :=  ( c and $ff);  
      raw[x].rgbtGreen :=   ( c shr 8 ) and $ff;
      raw[x].rgbtBlue   :=  ( c shr 16) and $ff;  
    end;
    Last edited by AirPas; 21-09-2011 at 08:50 AM.

  7. #7
    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
  •