Replace fabs with fabsf in image resource thread and minor cleanup 27/24127/1
authorAndrew Cox <andrew.cox@partner.samsung.com>
Tue, 10 Jun 2014 13:18:06 +0000 (14:18 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Tue, 8 Jul 2014 14:47:46 +0000 (15:47 +0100)
Change-Id: Ided0913dfced233e224d04a6d3de8e6ea9001a78
Signed-off-by: Andrew Cox <andrew.cox@partner.samsung.com>
platform-abstractions/slp/resource-loader/resource-thread-image.cpp

index 60b0426..6e32b46 100755 (executable)
@@ -527,7 +527,6 @@ bool ResourceThreadImage::ConvertStreamToBitmap(const ResourceType& resourceType
         }
         else if( loadedWidth != desiredWidth || loadedHeight != desiredHeight )
         {
-          const Vector2 loadedDims( loadedWidth, loadedHeight );
           const Vector2 desiredDims( desiredWidth, desiredHeight );
 
           // Scale the desired rectangle back to fit inside the rectangle of the loaded bitmap:
@@ -536,15 +535,16 @@ bool ResourceThreadImage::ConvertStreamToBitmap(const ResourceType& resourceType
           const Vector2 scaledByWidth = desiredDims * widthsRatio;
           const float heightsRatio = loadedHeight / float(desiredHeight);
           const Vector2 scaledByHeight = desiredDims * heightsRatio;
-          const bool trimTopAndBottom = scaledByWidth.LengthSquared() < scaledByHeight.LengthSquared();
+          // Trim top and bottom if the area of the horizontally-fitted candidate is less, else trim the sides:
+          const bool trimTopAndBottom = scaledByWidth.width * scaledByWidth.height < scaledByHeight.width * scaledByHeight.height;
           const Vector2 scaledDims = trimTopAndBottom ? scaledByWidth : scaledByHeight;
 
           // Work out how many pixels to trim from top and bottom, and left and right:
           // (We only ever do one dimension)
-          const unsigned scanlinesToTrim = trimTopAndBottom ? fabs( (scaledDims.y - loadedDims.y) * 0.5f ) : 0;
-          const unsigned columnsToTrim = trimTopAndBottom ? 0 : fabs( (scaledDims.x - loadedDims.x) * 0.5f );
+          const unsigned scanlinesToTrim = trimTopAndBottom ? fabsf( (scaledDims.y - loadedHeight) * 0.5f ) : 0;
+          const unsigned columnsToTrim = trimTopAndBottom ? 0 : fabsf( (scaledDims.x - loadedWidth) * 0.5f );
 
-          DALI_LOG_INFO( mLogFilter, Debug::Concise, "ImageAttributes::ScaleToFill - Bitmap, desired(%f, %f), loaded(%f,%f), cut_target(%f, %f), trimmed(%u, %u), vertical = %s.\n", desiredDims.x, desiredDims.y, loadedDims.x, loadedDims.y, scaledDims.x, scaledDims.y, columnsToTrim, scanlinesToTrim, trimTopAndBottom ? "true" : "false" );
+          DALI_LOG_INFO( mLogFilter, Debug::Concise, "ImageAttributes::ScaleToFill - Bitmap, desired(%f, %f), loaded(%u,%u), cut_target(%f, %f), trimmed(%u, %u), vertical = %s.\n", desiredDims.x, desiredDims.y, loadedWidth, loadedHeight, scaledDims.x, scaledDims.y, columnsToTrim, scanlinesToTrim, trimTopAndBottom ? "true" : "false" );
 
           // Make a new bitmap with the central part of the loaded one if required:
           if( scanlinesToTrim > 0 || columnsToTrim > 0 ) ///@ToDo: Make this test a bit fuzzy (allow say a 5% difference).