diff options
author | Omar Emara <mail@OmarEmara.dev> | 2022-10-24 13:15:22 +0300 |
---|---|---|
committer | Omar Emara <mail@OmarEmara.dev> | 2022-10-24 13:15:22 +0300 |
commit | 0584a88046d2a2c069e056e52b37907cd70db8c7 (patch) | |
tree | 2da046013e4b80396aa8456219ae828577ba758b /source/blender/imbuf | |
parent | 365cce4750906f428b15aabae18f1fd12788f7a8 (diff) |
Fix T102008: Images are stretched when texture limit is enabled
Currently, if an image exceed the texture limit setup by the user or the
GPU backend, it will be scaled down to satisfy the limit. However,
scaling happens independently per axis, that means the aspect ratio of
the image will not be maintained.
This patch corrects the smaller size to maintain the aspect ratio.
Differential Revision: https://developer.blender.org/D16327
Reviews By: Clement Foucault
Diffstat (limited to 'source/blender/imbuf')
-rw-r--r-- | source/blender/imbuf/intern/util_gpu.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/source/blender/imbuf/intern/util_gpu.c b/source/blender/imbuf/intern/util_gpu.c index 5ed6b2b9843..35cdefbaaeb 100644 --- a/source/blender/imbuf/intern/util_gpu.c +++ b/source/blender/imbuf/intern/util_gpu.c @@ -301,6 +301,16 @@ GPUTexture *IMB_create_gpu_texture(const char *name, int size[2] = {GPU_texture_size_with_limit(ibuf->x), GPU_texture_size_with_limit(ibuf->y)}; bool do_rescale = (ibuf->x != size[0]) || (ibuf->y != size[1]); + /* Correct the smaller size to maintain the original aspect ratio of the image. */ + if (do_rescale && ibuf->x != ibuf->y) { + if (size[0] > size[1]) { + size[1] = (int)(ibuf->y * ((float)size[0] / ibuf->x)); + } + else { + size[0] = (int)(ibuf->x * ((float)size[1] / ibuf->y)); + } + } + #ifdef WITH_DDS if (ibuf->ftype == IMB_FTYPE_DDS) { eGPUTextureFormat compressed_format; |