diff options
author | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-08-01 21:10:03 +0300 |
---|---|---|
committer | Konstantinos Sideris <sideris.konstantin@gmail.com> | 2018-08-01 21:10:03 +0300 |
commit | b5b5faa5eceba4c5ad0508cc0c079e6bad73b025 (patch) | |
tree | cf20ce75dc864f1a12d24574f894c69125ca4057 /src/Utils.h | |
parent | Add install instructions for macOS (#395) (diff) | |
download | nheko-b5b5faa5eceba4c5ad0508cc0c079e6bad73b025.tar.xz |
Consider the scale ratio when scaling down images
fixes #393
Diffstat (limited to 'src/Utils.h')
-rw-r--r-- | src/Utils.h | 28 |
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> |