sdlxUpdateYuvTexture function render

bool sdlxUpdateYuvTexture(
  1. Pointer<SdlTexture> texture, {
  2. SdlxRect? rect,
  3. List<int>? yplane,
  4. List<int>? uplane,
  5. List<int>? vplane,
})

Update a rectangle within a planar YV12 or IYUV texture with new pixel data.

You can use SDL_UpdateTexture() as long as your pixel data is a contiguous block of Y and U/V planes in the proper order, but this function is available if your pixel data is not contiguous.

\param texture the texture to update. \param rect a pointer to the rectangle of pixels to update, or NULL to update the entire texture. \param Yplane the raw pixel data for the Y plane. \param Ypitch the number of bytes between rows of pixel data for the Y plane. \param Uplane the raw pixel data for the U plane. \param Upitch the number of bytes between rows of pixel data for the U plane. \param Vplane the raw pixel data for the V plane. \param Vpitch the number of bytes between rows of pixel data for the V plane. \returns true on success or false on failure; call SDL_GetError() for more information.

\threadsafety This function should only be called on the main thread.

\since This function is available since SDL 3.2.0.

\sa SDL_UpdateNVTexture \sa SDL_UpdateTexture

extern SDL_DECLSPEC bool SDLCALL SDL_UpdateYUVTexture(SDL_Texture *texture, const SDL_Rect *rect, const Uint8 *Yplane, int Ypitch, const Uint8 *Uplane, int Upitch, const Uint8 *Vplane, int Vpitch)

Implementation

bool sdlxUpdateYuvTexture(
  Pointer<SdlTexture> texture, {
  SdlxRect? rect,
  List<int>? yplane,
  List<int>? uplane,
  List<int>? vplane,
}) {
  Pointer<SdlRect> rectPointer = nullptr;
  Pointer<Uint8> yplanePointer = nullptr;
  var yplanePitch = 0;
  Pointer<Uint8> uplanePointer = nullptr;
  var uplanePitch = 0;
  Pointer<Uint8> vplanePointer = nullptr;
  var vplanePitch = 0;
  if (rect != null) {
    rectPointer = rect.calloc();
  }
  if (yplane != null) {
    yplanePointer = calloc<Uint8>(yplane.length);
    for (var i = 0; i < yplane.length; i++) {
      yplanePointer[i] = yplane[i];
    }
    yplanePitch = yplane.length;
  }
  if (uplane != null) {
    uplanePointer = calloc<Uint8>(uplane.length);
    for (var i = 0; i < uplane.length; i++) {
      uplanePointer[i] = uplane[i];
    }
    uplanePitch = uplane.length;
  }
  if (vplane != null) {
    vplanePointer = calloc<Uint8>(vplane.length);
    for (var i = 0; i < vplane.length; i++) {
      vplanePointer[i] = vplane[i];
    }
    vplanePitch = vplane.length;
  }
  final result = sdlUpdateYuvTexture(
    texture,
    rectPointer,
    yplanePointer,
    yplanePitch,
    uplanePointer,
    uplanePitch,
    vplanePointer,
    vplanePitch,
  );
  if (rectPointer != nullptr) {
    rectPointer.callocFree();
  }
  if (yplanePointer != nullptr) {
    yplanePointer.callocFree();
  }
  if (uplanePointer != nullptr) {
    uplanePointer.callocFree();
  }
  if (vplanePointer != nullptr) {
    vplanePointer.callocFree();
  }
  return result;
}