If you point us to C based example we might be able to help you translate it to Pascal.
If you point us to C based example we might be able to help you translate it to Pascal.
Uint32 getpixel(SDL_Surface *surface, int num)
{/*pxl direct read access*//**1.0**/
int bpp = surface->format->BytesPerPixel;
/* P est l'adresse du pixel à retrouver*/
uint8_t *p = (uint8_t *)surface->pixels + num * bpp;
switch(bpp) {
case 1:
return *p;
case 2:
return *(Uint16 *)p;
case 3:
if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
return p[0] << 16 | p[1] << 8 | p[2];
else
return p[0] | p[1] << 8 | p[2] << 16;
case 4:
return *(Uint32 *)p;
default:
return 0;
}
}
best i could find for now... most other get_rgb sources i found were not reading from the screen i believe this is. this looks like it returns rgb if im understanding this.
Last edited by siv@; 10-01-2015 at 07:34 AM. Reason: update
I can't test this code, but it seems something like:
edit: If you have the pixel, you can try this functionCode:function getpixel(surface: SDL_Surface; num: integer): cardinal; var bpp: integer; p: PByte; begin bpp := surface.format.BytesPerPixel; p := pointer(surface.pixels + num * bpp); case bpp of 1: result := p^; 2: result := PWord(p)^; 3: begin if (SDL_BYTEORDER = SDL_BIG_ENDIAN) result := p[0] shl 16 or p[1] shl 8 or p[2] else result := p[0] or p[1] shl 8 or p[2] shl 16; end; 4: result := PCardinal(p)^; default: result := 0; end; end;
http://www.libsdl.org/release/SDL-1....sdlgetrgb.html
or
http://www.libsdl.org/release/SDL-1....dlgetrgba.html
Last edited by User137; 10-01-2015 at 11:08 AM.
I had trouble compiling this didnt like sdl_surface, wanted psdl_surface, so i tried that but on the bpp := line it stops compiling said invalid types got psdl_surface expected longint so I think the translation is right the original code or the variables for the pascal headers im using are a bit different the the c version no idea. Thanks for the translation. I think im going to have to use sdl1 I cant figure out how to get the pixel for getrgb or getrgba. If i figure it out some how I will post my results here.
Sdl surfaces are hardware excelerated and not easy to do pixel access perhaps this will provide a better option http://www.programmersranch.com/2014...l-drawing.html
Bookmarks