MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / SDL_UpdateTextureYUV

Function SDL_UpdateTextureYUV

deps/SDL2/src/render/SDL_render.c:1430–1474  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1428
1429#if SDL_HAVE_YUV
1430static int
1431SDL_UpdateTextureYUV(SDL_Texture * texture, const SDL_Rect * rect,
1432 const void *pixels, int pitch)
1433{
1434 SDL_Texture *native = texture->native;
1435 SDL_Rect full_rect;
1436
1437 if (SDL_SW_UpdateYUVTexture(texture->yuv, rect, pixels, pitch) < 0) {
1438 return -1;
1439 }
1440
1441 full_rect.x = 0;
1442 full_rect.y = 0;
1443 full_rect.w = texture->w;
1444 full_rect.h = texture->h;
1445 rect = &full_rect;
1446
1447 if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
1448 /* We can lock the texture and copy to it */
1449 void *native_pixels = NULL;
1450 int native_pitch = 0;
1451
1452 if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
1453 return -1;
1454 }
1455 SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
1456 rect->w, rect->h, native_pixels, native_pitch);
1457 SDL_UnlockTexture(native);
1458 } else {
1459 /* Use a temporary buffer for updating */
1460 const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
1461 const size_t alloclen = rect->h * temp_pitch;
1462 if (alloclen > 0) {
1463 void *temp_pixels = SDL_malloc(alloclen);
1464 if (!temp_pixels) {
1465 return SDL_OutOfMemory();
1466 }
1467 SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
1468 rect->w, rect->h, temp_pixels, temp_pitch);
1469 SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch);
1470 SDL_free(temp_pixels);
1471 }
1472 }
1473 return 0;
1474}
1475#endif /* SDL_HAVE_YUV */
1476
1477static int

Callers 1

SDL_UpdateTextureFunction · 0.85

Calls 7

SDL_SW_UpdateYUVTextureFunction · 0.85
SDL_LockTextureFunction · 0.85
SDL_SW_CopyYUVToRGBFunction · 0.85
SDL_UnlockTextureFunction · 0.85
SDL_mallocFunction · 0.85
SDL_UpdateTextureFunction · 0.85
SDL_freeFunction · 0.85

Tested by

no test coverage detected