SDL_Update{YUV,NV}Texture: also intersect rect with texture dimension
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index 139845f..9a6f8f2 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();
}