Direct memory access?

Hi there,

is there a way to access a bitmap directly in memory? I know about canvas.pixels but thats way too slow for me.

Well, i think i can get the address of the bitmap via:
pointer:=adr(bitmap); ,
but i dont know how to access the memory afterwards. I'm pretty new at Delphi and tried kinda:
mem[segment:offset]:=x; ,
which i found out, is not defined - although the way i need.

I'm pretty unexperienced with pointers either, although i know the segment is the hi-word of the pointer.

I'd appreciate any help, thanks.


Comments

  • : Hi there,
    :
    : is there a way to access a bitmap directly in memory? I know about canvas.pixels but thats way too slow for me.
    :
    : Well, i think i can get the address of the bitmap via:
    : pointer:=adr(bitmap); ,
    : but i dont know how to access the memory afterwards. I'm pretty new at Delphi and tried kinda:
    : mem[segment:offset]:=x; ,
    : which i found out, is not defined - although the way i need.
    :
    : I'm pretty unexperienced with pointers either, although i know the segment is the hi-word of the pointer.
    :
    : I'd appreciate any help, thanks.
    :

    Learn about tbitmap.scanline

    It returns a pointer to a row of pixel data. It is pretty fast. I used it in a few of my submissions(image averaging, alpha blending, asm animation...). They should help you learn how to use it.


  • : : Hi there,
    : :
    : : is there a way to access a bitmap directly in memory? I know about canvas.pixels but thats way too slow for me.
    : :
    : : Well, i think i can get the address of the bitmap via:
    : : pointer:=adr(bitmap); ,
    : : but i dont know how to access the memory afterwards. I'm pretty new at Delphi and tried kinda:
    : : mem[segment:offset]:=x; ,
    : : which i found out, is not defined - although the way i need.
    : :
    : : I'm pretty unexperienced with pointers either, although i know the segment is the hi-word of the pointer.
    : :
    : : I'd appreciate any help, thanks.
    : :
    :
    : Learn about tbitmap.scanline
    :
    : It returns a pointer to a row of pixel data. It is pretty fast. I used it in a few of my submissions(image averaging, alpha blending, asm animation...). They should help you learn how to use it.
    :
    :
    : before you can use the TBitmap.Scanline pointer set TBitmap.pixelFormat to pf24bit, now Scanline points to an array of BGR (not RGB) structures BGR = record b,g,r: byte end;
    and set TBitmap.handleType to bmDIB (I'm not sure about handletype but I'm sure you can find anything you need in delphi help (VCL help).

  • : :
    : : Learn about tbitmap.scanline
    : :
    : : It returns a pointer to a row of pixel data. It is pretty fast. I used it in a few of my submissions(image averaging, alpha blending, asm animation...). They should help you learn how to use it.
    : :
    : :
    : : before you can use the TBitmap.Scanline pointer set TBitmap.pixelFormat to pf24bit, now Scanline points to an array of BGR (not RGB) structures BGR = record b,g,r: byte end;
    : and set TBitmap.handleType to bmDIB (I'm not sure about handletype but I'm sure you can find anything you need in delphi help (VCL help).

    Thanks for the replies.
    I am aware of the functions Scanline and Pixelformat although. Scanline would be more useful than Pixels, because it spares the calculation of the offset for each pixel, which contains at least one multiplication.
    But it still requires a buffer before i can apply it to the bitmap, which costs time.
    Isn't there a way which makes linear access to the bitmap possible? I wonder why i can get the pointer to the bitmap although theres no way to use it then.

    so far

  • : : :
    : : : Learn about tbitmap.scanline
    : : :
    : : : It returns a pointer to a row of pixel data. It is pretty fast. I used it in a few of my submissions(image averaging, alpha blending, asm animation...). They should help you learn how to use it.
    : : :
    : : :
    : : : before you can use the TBitmap.Scanline pointer set TBitmap.pixelFormat to pf24bit, now Scanline points to an array of BGR (not RGB) structures BGR = record b,g,r: byte end;
    : : and set TBitmap.handleType to bmDIB (I'm not sure about handletype but I'm sure you can find anything you need in delphi help (VCL help).
    :
    : Thanks for the replies.
    : I am aware of the functions Scanline and Pixelformat although. Scanline would be more useful than Pixels, because it spares the calculation of the offset for each pixel, which contains at least one multiplication.
    : But it still requires a buffer before i can apply it to the bitmap, which costs time.
    : Isn't there a way which makes linear access to the bitmap possible? I wonder why i can get the pointer to the bitmap although theres no way to use it then.
    :
    : so far
    :
    :
    Ok,
    type
    TBGR = record R,G,B end;//note that I asume that we have a 24bit bitmap, also note that the order of rgb bytes is reversed (BGR)
    PRGB = ^TGBR;
    var
    RGB: PRGB;

    RGB = someBitmap.scanline[0];//we now have a direct pointer to bitmap memory
    RGB^.R = 255;//set the first pixel in the first row to maximum color(white)
    RGB^.G = 255;
    RGB^.B = 255;
    inc(RGB); //now we have a pointer to the second pixel in the first row
    //if you would call someCanvas.Draw(0,0,someBitmap); you would see changes made by this code(Pixel[0,0] = 255,255,255;

    NOTE: you can do also this delta := Scanline[1]-Scanline[0];
    and you don't event have to call scanline anymore;
    scanlines are ALWAYS DWORD aligned! so you can't do the inc(RGB) and go trought the whole bitmap (in some cases, you can if, bitmap.width*3 mod 4 = 0:)
  • thats great, thanks, i'll try that

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories