[Tizen] Make jpg loader scale-up decode allow. 76/307476/1 accepted/tizen/8.0/unified/20240311.164636 accepted/tizen/8.0/unified/20240313.143448
authorEunki, Hong <eunkiki.hong@samsung.com>
Fri, 8 Mar 2024 05:27:41 +0000 (14:27 +0900)
committerEunki, Hong <eunkiki.hong@samsung.com>
Mon, 11 Mar 2024 02:26:12 +0000 (11:26 +0900)
There was some bug when we want to load jpg image as x2 scaled.
(Since 2/1 scale is tjGetScalingFactors()[0] value, and we were ignore 0 value until now.)

And also, scaling factor doesn't mean "downscale" anymore for now.
Let we remain some comments, and change some values

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: Ib917dfad68da5fa05d61f6ce3e2a1c5b25dd612f

dali/internal/imaging/common/loader-jpeg-turbo.cpp

index 5bf488daaf0bc263870fbc5c7aba14e68245be45..86daa1f6553d3a2839ba6c19f779e04bd9d68802 100644 (file)
@@ -1200,7 +1200,7 @@ bool TransformSize(int requiredWidth, int requiredHeight, FittingMode::Type fitt
     // Internal jpeg downscaling is the same as our BOX_X sampling modes so only
     // apply it if the application requested one of those:
     // (use a switch case here so this code will fail to compile if other modes are added)
-    bool downscale = true;
+    bool useTurboJpegScaleFactor = true;
     switch(samplingMode)
     {
       case SamplingMode::BOX:
@@ -1208,26 +1208,30 @@ bool TransformSize(int requiredWidth, int requiredHeight, FittingMode::Type fitt
       case SamplingMode::BOX_THEN_LINEAR:
       case SamplingMode::DONT_CARE:
       {
-        downscale = true;
+        useTurboJpegScaleFactor = true;
         break;
       }
       case SamplingMode::NO_FILTER:
       case SamplingMode::NEAREST:
       case SamplingMode::LINEAR:
       {
-        downscale = false;
+        useTurboJpegScaleFactor = false;
         break;
       }
     }
 
-    int scaleFactorIndex(0);
-    if(downscale)
+    int scaleFactorIndex(-1);
+    int fittedScaledWidth(postXformImageWidth);
+    int fittedScaledHeight(postXformImageHeight);
+    if(useTurboJpegScaleFactor)
     {
       // Find nearest supported scaling factor (factors are in sequential order, getting smaller)
-      for(int i = 1; i < numFactors; ++i)
+      for(int i = 0; i < numFactors; ++i)
       {
-        bool widthLessRequired  = TJSCALED(postXformImageWidth, factors[i]) < requiredWidth;
-        bool heightLessRequired = TJSCALED(postXformImageHeight, factors[i]) < requiredHeight;
+        int  scaledWidth        = TJSCALED(postXformImageWidth, factors[i]);
+        int  scaledHeight       = TJSCALED(postXformImageHeight, factors[i]);
+        bool widthLessRequired  = scaledWidth < requiredWidth;
+        bool heightLessRequired = scaledHeight < requiredHeight;
         // If either scaled dimension is smaller than the desired one, we were done at the last iteration
         if((fittingMode == FittingMode::SCALE_TO_FILL) && (widthLessRequired || heightLessRequired))
         {
@@ -1249,31 +1253,41 @@ bool TransformSize(int requiredWidth, int requiredHeight, FittingMode::Type fitt
           break;
         }
         // This factor stays is within our fitting mode constraint so remember it:
-        scaleFactorIndex = i;
+        scaleFactorIndex   = i;
+        fittedScaledWidth  = scaledWidth;
+        fittedScaledHeight = scaledHeight;
       }
     }
 
+    const int maxTextureSize = static_cast<int>(Dali::GetMaxTextureSize());
+
     // Regardless of requested size, downscale to avoid exceeding the maximum texture size:
-    for(int i = scaleFactorIndex; i < numFactors; ++i)
+    if(fittedScaledWidth >= maxTextureSize ||
+       fittedScaledHeight >= maxTextureSize)
     {
-      // Continue downscaling to below maximum texture size (if possible)
-      scaleFactorIndex = i;
-
-      if(TJSCALED(postXformImageWidth, (factors[i])) < static_cast<int>(Dali::GetMaxTextureSize()) &&
-         TJSCALED(postXformImageHeight, (factors[i])) < static_cast<int>(Dali::GetMaxTextureSize()))
+      for(int i = scaleFactorIndex + 1; i < numFactors; ++i)
       {
-        // Current scale-factor downscales to below maximum texture size
-        break;
+        // Continue downscaling to below maximum texture size (if possible)
+        scaleFactorIndex   = i;
+        fittedScaledWidth  = TJSCALED(postXformImageWidth, factors[i]);
+        fittedScaledHeight = TJSCALED(postXformImageHeight, factors[i]);
+
+        if(fittedScaledWidth < maxTextureSize &&
+           fittedScaledHeight < maxTextureSize)
+        {
+          // Current scale-factor downscales to below maximum texture size
+          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]));
-      postXformImageWidth  = TJSCALED(postXformImageWidth, (factors[scaleFactorIndex]));
-      postXformImageHeight = TJSCALED(postXformImageHeight, (factors[scaleFactorIndex]));
+      postXformImageWidth  = fittedScaledWidth;
+      postXformImageHeight = fittedScaledHeight;
     }
   }