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
This commit is contained in:
Omar Emara 2022-10-24 12:15:22 +02:00
parent 365cce4750
commit 0584a88046
Notes: blender-bot 2023-02-14 11:08:33 +01:00
Referenced by issue #102008, Realtime compositor: images will be shrinked at X axis, when they are wider than ~2000px or so
1 changed files with 10 additions and 0 deletions

View File

@ -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;