summary refs log tree commit diff
path: root/src/Utils.h
diff options
context:
space:
mode:
authorKonstantinos Sideris <sideris.konstantin@gmail.com>2018-08-01 21:10:03 +0300
committerKonstantinos Sideris <sideris.konstantin@gmail.com>2018-08-01 21:10:03 +0300
commitb5b5faa5eceba4c5ad0508cc0c079e6bad73b025 (patch)
treecf20ce75dc864f1a12d24574f894c69125ca4057 /src/Utils.h
parentAdd install instructions for macOS (#395) (diff)
downloadnheko-b5b5faa5eceba4c5ad0508cc0c079e6bad73b025.tar.xz
Consider the scale ratio when scaling down images
fixes #393
Diffstat (limited to 'src/Utils.h')
-rw-r--r--src/Utils.h28
1 files changed, 2 insertions, 26 deletions
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<class ImageType>
-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<typename ContainerT, typename PredicateT>