From 87ff87d9ae3c6e92ec6a935360b5d231e5070edd Mon Sep 17 00:00:00 2001 From: Gres Date: Fri, 11 Apr 2014 22:52:03 +0400 Subject: [PATCH] Check available memory and correct scale factor on windows --- ImageProcessing.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ImageProcessing.cpp b/ImageProcessing.cpp index 7bcca35..6b55e20 100644 --- a/ImageProcessing.cpp +++ b/ImageProcessing.cpp @@ -1,9 +1,25 @@ +#include + #include #include #include "ImageProcessing.h" +#ifdef WIN32 +#include +qint64 getFreeMemory () +{ + MEMORYSTATUSEX statex; + statex.dwLength = sizeof (statex); + if (GlobalMemoryStatusEx (&statex)) + { + return statex.ullAvailPhys; + } + return -1; +} +#endif + Pix *convertImage(const QImage& image) { PIX *pix; @@ -111,6 +127,14 @@ Pix *prepareImage(const QImage &image, int preferredScale) float maxScaleY = MAX_INT16 / double (gray->h); float scaleY = std::min (float (preferredScale), maxScaleY); float scale = std::min (scaleX, scaleY); + +#ifdef WIN32 + qint64 availableMemory = getFreeMemory () * 0.95; + qint32 actualSize = gray->w * gray->h * gray->d / 8; + float maxScaleMemory = float (availableMemory) / actualSize; + scale = std::min (scale, maxScaleMemory); +#endif + scaled = pixScale (gray, scale, scale); } Q_ASSERT (scaled != NULL);