From d37b710c0b9d0fb581bda72178d8dd17a735643c Mon Sep 17 00:00:00 2001 From: Heeyong Song Date: Tue, 8 Aug 2017 11:50:47 +0900 Subject: [PATCH] Change CalculateDesiredDimensions() to consider the image aspect ratio Change-Id: I24b047c183c30b30c35a8962a85a7bc3f5a1f36b --- .../portable/image-operations.cpp | 34 ++++++++++++++++++++-- .../tizen/image-loaders/loader-jpeg-turbo.cpp | 9 ++---- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/platform-abstractions/portable/image-operations.cpp b/platform-abstractions/portable/image-operations.cpp index e8c47d6..2c5da3b 100644 --- a/platform-abstractions/portable/image-operations.cpp +++ b/platform-abstractions/portable/image-operations.cpp @@ -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 diff --git a/platform-abstractions/tizen/image-loaders/loader-jpeg-turbo.cpp b/platform-abstractions/tizen/image-loaders/loader-jpeg-turbo.cpp index 1fdf3ff..e2c06a7 100755 --- a/platform-abstractions/tizen/image-loaders/loader-jpeg-turbo.cpp +++ b/platform-abstractions/tizen/image-loaders/loader-jpeg-turbo.cpp @@ -20,6 +20,7 @@ #include #include "platform-capabilities.h" #include "image-operations.h" +#include // EXTERNAL HEADERS #include @@ -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; -- 2.7.4