diff options
author | Sylvain Becker <sylvain.becker@gmail.com> | 2021-01-27 10:54:49 +0100 |
---|---|---|
committer | Sylvain Becker <sylvain.becker@gmail.com> | 2021-01-27 10:54:49 +0100 |
commit | 454cc052aa069f4ad7a6fb0dd985d5810873f5c8 (patch) | |
tree | 074d15d08e4f3191d08d60f4aebf225a156c40a2 | |
parent | 4951009f9dd8af946f99f298b4fa1dbf9cf580ee (diff) | |
download | sdl-454cc052aa069f4ad7a6fb0dd985d5810873f5c8.tar.gz |
SDL_Update{YUV,NV}Texture: also intersect rect with texture dimension
-rw-r--r-- | src/render/SDL_render.c | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index 139845f1e..9a6f8f2c8 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -1692,7 +1692,7 @@ int SDL_UpdateYUVTexture(SDL_Texture * texture, const SDL_Rect * rect, { #if SDL_HAVE_YUV SDL_Renderer *renderer; - SDL_Rect full_rect; + SDL_Rect real_rect; CHECK_TEXTURE_MAGIC(texture, -1); @@ -1720,20 +1720,20 @@ int SDL_UpdateYUVTexture(SDL_Texture * texture, const SDL_Rect * rect, return SDL_SetError("Texture format must by YV12 or IYUV"); } - if (!rect) { - full_rect.x = 0; - full_rect.y = 0; - full_rect.w = texture->w; - full_rect.h = texture->h; - rect = &full_rect; + real_rect.x = 0; + real_rect.y = 0; + real_rect.w = texture->w; + real_rect.h = texture->h; + if (rect) { + SDL_IntersectRect(rect, &real_rect, &real_rect); } - if (!rect->w || !rect->h) { + if (real_rect.w == 0 || real_rect.h == 0) { return 0; /* nothing to do. */ } if (texture->yuv) { - return SDL_UpdateTextureYUVPlanar(texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch); + return SDL_UpdateTextureYUVPlanar(texture, &real_rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch); } else { SDL_assert(!texture->native); renderer = texture->renderer; @@ -1742,7 +1742,7 @@ int SDL_UpdateYUVTexture(SDL_Texture * texture, const SDL_Rect * rect, if (FlushRenderCommandsIfTextureNeeded(texture) < 0) { return -1; } - return renderer->UpdateTextureYUV(renderer, texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch); + return renderer->UpdateTextureYUV(renderer, texture, &real_rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch); } else { return SDL_Unsupported(); } @@ -1758,7 +1758,7 @@ int SDL_UpdateNVTexture(SDL_Texture * texture, const SDL_Rect * rect, { #if SDL_HAVE_YUV SDL_Renderer *renderer; - SDL_Rect full_rect; + SDL_Rect real_rect; CHECK_TEXTURE_MAGIC(texture, -1); @@ -1780,20 +1780,20 @@ int SDL_UpdateNVTexture(SDL_Texture * texture, const SDL_Rect * rect, return SDL_SetError("Texture format must by NV12 or NV21"); } - if (!rect) { - full_rect.x = 0; - full_rect.y = 0; - full_rect.w = texture->w; - full_rect.h = texture->h; - rect = &full_rect; + real_rect.x = 0; + real_rect.y = 0; + real_rect.w = texture->w; + real_rect.h = texture->h; + if (rect) { + SDL_IntersectRect(rect, &real_rect, &real_rect); } - if (!rect->w || !rect->h) { + if (real_rect.w == 0 || real_rect.h == 0) { return 0; /* nothing to do. */ } if (texture->yuv) { - return SDL_UpdateTextureNVPlanar(texture, rect, Yplane, Ypitch, UVplane, UVpitch); + return SDL_UpdateTextureNVPlanar(texture, &real_rect, Yplane, Ypitch, UVplane, UVpitch); } else { SDL_assert(!texture->native); renderer = texture->renderer; @@ -1802,7 +1802,7 @@ int SDL_UpdateNVTexture(SDL_Texture * texture, const SDL_Rect * rect, if (FlushRenderCommandsIfTextureNeeded(texture) < 0) { return -1; } - return renderer->UpdateTextureNV(renderer, texture, rect, Yplane, Ypitch, UVplane, UVpitch); + return renderer->UpdateTextureNV(renderer, texture, &real_rect, Yplane, Ypitch, UVplane, UVpitch); } else { return SDL_Unsupported(); } |