sdlPremultiplyAlpha function

bool sdlPremultiplyAlpha(
  1. int width,
  2. int height,
  3. int srcFormat,
  4. Pointer<NativeType> src,
  5. int srcPitch,
  6. int dstFormat,
  7. Pointer<NativeType> dst,
  8. int dstPitch,
  9. bool linear,
)

Premultiply the alpha on a block of pixels.

This is safe to use with src == dst, but not for other overlapping areas.

\param width the width of the block to convert, in pixels. \param height the height of the block to convert, in pixels. \param src_format an SDL_PixelFormat value of the src pixels format. \param src a pointer to the source pixels. \param src_pitch the pitch of the source pixels, in bytes. \param dst_format an SDL_PixelFormat value of the dst pixels format. \param dst a pointer to be filled in with premultiplied pixel data. \param dst_pitch the pitch of the destination pixels, in bytes. \param linear true to convert from sRGB to linear space for the alpha multiplication, false to do multiplication in sRGB space. \returns true on success or false on failure; call SDL_GetError() for more information.

\since This function is available since SDL 3.1.3.

extern SDL_DECLSPEC bool SDLCALL SDL_PremultiplyAlpha(int width, int height, SDL_PixelFormat src_format, const void *src, int src_pitch, SDL_PixelFormat dst_format, void *dst, int dst_pitch, bool linear)

Implementation

bool sdlPremultiplyAlpha(
    int width,
    int height,
    int srcFormat,
    Pointer<NativeType> src,
    int srcPitch,
    int dstFormat,
    Pointer<NativeType> dst,
    int dstPitch,
    bool linear) {
  final sdlPremultiplyAlphaLookupFunction = libSdl3.lookupFunction<
      Uint8 Function(
          Int32 width,
          Int32 height,
          Int32 srcFormat,
          Pointer<NativeType> src,
          Int32 srcPitch,
          Int32 dstFormat,
          Pointer<NativeType> dst,
          Int32 dstPitch,
          Uint8 linear),
      int Function(
          int width,
          int height,
          int srcFormat,
          Pointer<NativeType> src,
          int srcPitch,
          int dstFormat,
          Pointer<NativeType> dst,
          int dstPitch,
          int linear)>('SDL_PremultiplyAlpha');
  return sdlPremultiplyAlphaLookupFunction(width, height, srcFormat, src,
          srcPitch, dstFormat, dst, dstPitch, linear ? 1 : 0) ==
      1;
}