From 8b6eb86f956a7a02bcf4c456ea3a3c5fe25a9639 Mon Sep 17 00:00:00 2001 From: Andrew Cox Date: Tue, 10 Jun 2014 14:18:06 +0100 Subject: [PATCH] Replace fabs with fabsf in image resource thread and minor cleanup Change-Id: Ided0913dfced233e224d04a6d3de8e6ea9001a78 Signed-off-by: Andrew Cox --- .../slp/resource-loader/resource-thread-image.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/platform-abstractions/slp/resource-loader/resource-thread-image.cpp b/platform-abstractions/slp/resource-loader/resource-thread-image.cpp index 60b0426..6e32b46 100755 --- a/platform-abstractions/slp/resource-loader/resource-thread-image.cpp +++ b/platform-abstractions/slp/resource-loader/resource-thread-image.cpp @@ -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). -- 2.7.4