From b5b5faa5eceba4c5ad0508cc0c079e6bad73b025 Mon Sep 17 00:00:00 2001 From: Konstantinos Sideris Date: Wed, 1 Aug 2018 21:10:03 +0300 Subject: Consider the scale ratio when scaling down images fixes #393 --- src/Utils.h | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) (limited to 'src/Utils.h') diff --git a/src/Utils.h b/src/Utils.h index 7132f2ab..7f544835 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -116,32 +116,8 @@ createDescriptionInfo(const Event &event, const QString &localUser, const QStrin } //! Scale down an image to fit to the given width & height limitations. -template -ImageType -scaleDown(uint64_t max_width, uint64_t max_height, const ImageType &source) -{ - if (source.isNull()) - return QPixmap(); - - auto width_ratio = (double)max_width / (double)source.width(); - auto height_ratio = (double)max_height / (double)source.height(); - - auto min_aspect_ratio = std::min(width_ratio, height_ratio); - - int final_width = 0; - int final_height = 0; - - if (min_aspect_ratio > 1) { - final_width = source.width(); - final_height = source.height(); - } else { - final_width = source.width() * min_aspect_ratio; - final_height = source.height() * min_aspect_ratio; - } - - return source.scaled( - final_width, final_height, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); -} +QPixmap +scaleDown(uint64_t maxWidth, uint64_t maxHeight, const QPixmap &source); //! Delete items in a container based on a predicate. template -- cgit 1.5.1