Change CalculateDesiredDimensions() to consider the image aspect ratio 38/142938/2
authorHeeyong Song <heeyong.song@samsung.com>
Tue, 8 Aug 2017 02:50:47 +0000 (11:50 +0900)
committerHeeyong Song <heeyong.song@samsung.com>
Mon, 14 Aug 2017 00:46:23 +0000 (00:46 +0000)
Change-Id: I24b047c183c30b30c35a8962a85a7bc3f5a1f36b

platform-abstractions/portable/image-operations.cpp
platform-abstractions/tizen/image-loaders/loader-jpeg-turbo.cpp

index e8c47d6..2c5da3b 100644 (file)
@@ -454,13 +454,43 @@ ImageDimensions CalculateDesiredDimensions( unsigned int bitmapWidth, unsigned i
   // If no dimensions have been requested, default to the source ones:
   if( requestedWidth == 0 && requestedHeight == 0 )
   {
-    return ImageDimensions( std::min( bitmapWidth, maxSize ), std::min( bitmapHeight, maxSize ) );
+    if( bitmapWidth <= maxSize && bitmapHeight <= maxSize )
+    {
+      return ImageDimensions( bitmapWidth, bitmapHeight );
+    }
+    else
+    {
+      // Calculate the size from the max texture size and the source image aspect ratio
+      if( bitmapWidth > bitmapHeight )
+      {
+        return ImageDimensions( maxSize, bitmapHeight * maxSize / static_cast< float >( bitmapWidth ) + 0.5f );
+      }
+      else
+      {
+        return ImageDimensions( bitmapWidth * maxSize / static_cast< float >( bitmapHeight ) + 0.5f, maxSize );
+      }
+    }
   }
 
   // If both dimensions have values requested, use them both:
   if( requestedWidth != 0 && requestedHeight != 0 )
   {
-    return ImageDimensions( std::min( requestedWidth, maxSize ), std::min( requestedHeight, maxSize ) );
+    if( requestedWidth <= maxSize && requestedWidth <= maxSize )
+    {
+      return ImageDimensions( requestedWidth, requestedHeight );
+    }
+    else
+    {
+      // Calculate the size from the max texture size and the source image aspect ratio
+      if( requestedWidth > requestedHeight )
+      {
+        return ImageDimensions( maxSize, requestedHeight * maxSize / static_cast< float >( requestedWidth ) + 0.5f );
+      }
+      else
+      {
+        return ImageDimensions( requestedWidth * maxSize / static_cast< float >( requestedHeight ) + 0.5f, maxSize );
+      }
+    }
   }
 
   // Only one of the dimensions has been requested. Calculate the other from
index 1fdf3ff..e2c06a7 100755 (executable)
@@ -20,6 +20,7 @@
 #include <dali/integration-api/bitmap.h>
 #include "platform-capabilities.h"
 #include "image-operations.h"
+#include <image-loading.h>
 
 // EXTERNAL HEADERS
 #include <libexif/exif-data.h>
@@ -171,10 +172,6 @@ namespace
     unsigned char * const mTjMem;
   };
 
-  // Workaround to avoid exceeding the maximum texture size
-  const int MAX_TEXTURE_WIDTH  = 4096;
-  const int MAX_TEXTURE_HEIGHT = 4096;
-
 } // namespace
 bool JpegFlipV( RGB888Type *buffer, int width, int height );
 bool JpegFlipH( RGB888Type *buffer, int width, int height );
@@ -843,8 +840,8 @@ bool TransformSize( int requiredWidth, int requiredHeight,
       // Continue downscaling to below maximum texture size (if possible)
       scaleFactorIndex = i;
 
-      if( TJSCALED(postXformImageWidth,  (factors[i])) < MAX_TEXTURE_WIDTH &&
-          TJSCALED(postXformImageHeight, (factors[i])) < MAX_TEXTURE_HEIGHT )
+      if( TJSCALED(postXformImageWidth,  (factors[i])) < static_cast< int >( Dali::GetMaxTextureSize() ) &&
+          TJSCALED(postXformImageHeight, (factors[i])) < static_cast< int >( Dali::GetMaxTextureSize() ) )
       {
         // Current scale-factor downscales to below maximum texture size
         break;