Results 1 to 7 of 7

Thread: SDL2 Help geting rgb colors

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    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

Tags for this Thread

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
  •