sdlReadSurfacePixel function surface

bool sdlReadSurfacePixel(
  1. Pointer<SdlSurface> surface,
  2. int x,
  3. int y,
  4. Pointer<Uint8> r,
  5. Pointer<Uint8> g,
  6. Pointer<Uint8> b,
  7. Pointer<Uint8> a,
)

Retrieves a single pixel from a surface.

This function prioritizes correctness over speed: it is suitable for unit tests, but is not intended for use in a game engine.

Like SDL_GetRGBA, this uses the entire 0..255 range when converting color components from pixel formats with less than 8 bits per RGB component.

\param surface the surface to read. \param x the horizontal coordinate, 0 <= x < width. \param y the vertical coordinate, 0 <= y < height. \param r a pointer filled in with the red channel, 0-255, or NULL to ignore this channel. \param g a pointer filled in with the green channel, 0-255, or NULL to ignore this channel. \param b a pointer filled in with the blue channel, 0-255, or NULL to ignore this channel. \param a a pointer filled in with the alpha channel, 0-255, or NULL to ignore this channel. \returns true on success or false on failure; call SDL_GetError() for more information.

\threadsafety This function is not thread safe.

\since This function is available since SDL 3.2.0.

extern SDL_DECLSPEC bool SDLCALL SDL_ReadSurfacePixel(SDL_Surface *surface, int x, int y, Uint8 *r, Uint8 *g, Uint8 *b, Uint8 *a)

Implementation

bool sdlReadSurfacePixel(
  Pointer<SdlSurface> surface,
  int x,
  int y,
  Pointer<Uint8> r,
  Pointer<Uint8> g,
  Pointer<Uint8> b,
  Pointer<Uint8> a,
) {
  final sdlReadSurfacePixelLookupFunction = _libSdl
      .lookupFunction<
        Uint8 Function(
          Pointer<SdlSurface> surface,
          Int32 x,
          Int32 y,
          Pointer<Uint8> r,
          Pointer<Uint8> g,
          Pointer<Uint8> b,
          Pointer<Uint8> a,
        ),
        int Function(
          Pointer<SdlSurface> surface,
          int x,
          int y,
          Pointer<Uint8> r,
          Pointer<Uint8> g,
          Pointer<Uint8> b,
          Pointer<Uint8> a,
        )
      >('SDL_ReadSurfacePixel');
  return sdlReadSurfacePixelLookupFunction(surface, x, y, r, g, b, a) == 1;
}