From 178139049e8b853b9df7fbb3ecd5b0916a067c3e Mon Sep 17 00:00:00 2001 From: "Eunki, Hong" Date: Mon, 11 Mar 2024 10:31:38 +0900 Subject: [PATCH] Minor fix about jpeg downscale under max texture size Let we consider that two cases also downscale works well when - Mark as we don't use jpeg scale factor, and double-scaled image size is less then max texture size. (For this case, we were try to decode image as double-scaled. and then downscale as half) - 1/8 scaled size of image is also less then max texture size (For this case, we should try to downscale as much as we can. But we didn't) Change-Id: I861e40c8e01872e133bcee90f13466effaa83f47 Signed-off-by: Eunki, Hong --- dali/internal/imaging/common/loader-jpeg-turbo.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/dali/internal/imaging/common/loader-jpeg-turbo.cpp b/dali/internal/imaging/common/loader-jpeg-turbo.cpp index 1f8b274..86daa1f 100644 --- a/dali/internal/imaging/common/loader-jpeg-turbo.cpp +++ b/dali/internal/imaging/common/loader-jpeg-turbo.cpp @@ -1259,31 +1259,30 @@ bool TransformSize(int requiredWidth, int requiredHeight, FittingMode::Type fitt } } + const int maxTextureSize = static_cast(Dali::GetMaxTextureSize()); + // Regardless of requested size, downscale to avoid exceeding the maximum texture size: - if(scaleFactorIndex == -1 || - (fittedScaledWidth >= static_cast(Dali::GetMaxTextureSize()) || - fittedScaledHeight >= static_cast(Dali::GetMaxTextureSize()))) + if(fittedScaledWidth >= maxTextureSize || + fittedScaledHeight >= maxTextureSize) { for(int i = scaleFactorIndex + 1; i < numFactors; ++i) { // Continue downscaling to below maximum texture size (if possible) - int scaledWidth = TJSCALED(postXformImageWidth, factors[i]); - int scaledHeight = TJSCALED(postXformImageHeight, factors[i]); + scaleFactorIndex = i; + fittedScaledWidth = TJSCALED(postXformImageWidth, factors[i]); + fittedScaledHeight = TJSCALED(postXformImageHeight, factors[i]); - if(scaledWidth < static_cast(Dali::GetMaxTextureSize()) && - scaledHeight < static_cast(Dali::GetMaxTextureSize())) + if(fittedScaledWidth < maxTextureSize && + fittedScaledHeight < maxTextureSize) { // Current scale-factor downscales to below maximum texture size - scaleFactorIndex = i; - fittedScaledWidth = scaledWidth; - fittedScaledHeight = scaledHeight; break; } } } // We have finally chosen the scale-factor, return width/height values - if(scaleFactorIndex >= 0) + if(scaleFactorIndex >= 0 && scaleFactorIndex < numFactors) { preXformImageWidth = TJSCALED(preXformImageWidth, (factors[scaleFactorIndex])); preXformImageHeight = TJSCALED(preXformImageHeight, (factors[scaleFactorIndex])); -- 2.7.4