summaryrefslogtreecommitdiff
path: root/gdk
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2022-05-08 13:53:04 -0400
committerMatthias Clasen <mclasen@redhat.com>2022-05-13 09:30:46 -0400
commitf33c5218364377ac41a6bbaf36e1a8a98412a368 (patch)
tree37ff8503e05f2eec4411e9e356c402644ec92c7f /gdk
parent122fa679a8a15610e0a3164bdf2e4ad1702f3fb1 (diff)
downloadgtk+-f33c5218364377ac41a6bbaf36e1a8a98412a368.tar.gz
Fixes for gdk_memory_texture_new_subtexture
There were several mistakes here. The width of subtextures was set to the width of the main texture, the data size wasn't properly calculated, and the preconditions were inverted. Yay us!
Diffstat (limited to 'gdk')
-rw-r--r--gdk/gdkmemorytexture.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/gdk/gdkmemorytexture.c b/gdk/gdkmemorytexture.c
index c9aecd5cea..e241ebd0a3 100644
--- a/gdk/gdkmemorytexture.c
+++ b/gdk/gdkmemorytexture.c
@@ -178,19 +178,19 @@ gdk_memory_texture_new_subtexture (GdkMemoryTexture *source,
GBytes *bytes;
g_return_val_if_fail (GDK_IS_MEMORY_TEXTURE (source), NULL);
- g_return_val_if_fail (x < 0 || x >= GDK_TEXTURE (source)->width, NULL);
- g_return_val_if_fail (y < 0 || y >= GDK_TEXTURE (source)->height, NULL);
- g_return_val_if_fail (width <= 0 || x + width > GDK_TEXTURE (source)->width, NULL);
- g_return_val_if_fail (height <= 0 || y + height > GDK_TEXTURE (source)->height, NULL);
+ g_return_val_if_fail (x >= 0 || x < GDK_TEXTURE (source)->width, NULL);
+ g_return_val_if_fail (y >= 0 || y < GDK_TEXTURE (source)->height, NULL);
+ g_return_val_if_fail (width > 0 || x + width <= GDK_TEXTURE (source)->width, NULL);
+ g_return_val_if_fail (height > 0 || y + height <= GDK_TEXTURE (source)->height, NULL);
texture = GDK_TEXTURE (source);
bpp = gdk_memory_format_bytes_per_pixel (texture->format);
offset = y * source->stride + x * bpp;
- size = source->stride * (height - 1) + x * bpp;
+ size = source->stride * (height - 1) + width * bpp;
bytes = g_bytes_new_from_bytes (source->bytes, offset, size);
- result = gdk_memory_texture_new (texture->width,
- texture->height,
+ result = gdk_memory_texture_new (width,
+ height,
texture->format,
bytes,
source->stride);