summaryrefslogtreecommitdiff
path: root/wx+/image_tools.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <daniel@wili.li>2014-04-18 17:15:39 +0200
committerDaniel Wilhelm <daniel@wili.li>2014-04-18 17:15:39 +0200
commitd2854834e18443876c8f75e0a7f3b88d1d549fc4 (patch)
treee967b628081e50abc7c34cd264e6586271c7e728 /wx+/image_tools.h
parent4.1 (diff)
downloadFreeFileSync-d2854834e18443876c8f75e0a7f3b88d1d549fc4.tar.gz
FreeFileSync-d2854834e18443876c8f75e0a7f3b88d1d549fc4.tar.bz2
FreeFileSync-d2854834e18443876c8f75e0a7f3b88d1d549fc4.zip
4.2
Diffstat (limited to 'wx+/image_tools.h')
-rw-r--r--wx+/image_tools.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/wx+/image_tools.h b/wx+/image_tools.h
index e78e7ced..23a363df 100644
--- a/wx+/image_tools.h
+++ b/wx+/image_tools.h
@@ -10,7 +10,7 @@
#include <numeric>
#include <wx/bitmap.h>
#include <wx/dcmemory.h>
-
+#include <zen/basic_math.h>
namespace zen
{
@@ -64,7 +64,8 @@ double getAvgBrightness(const wxImage& img)
{
const int pixelCount = img.GetWidth() * img.GetHeight();
auto pixBegin = img.GetData();
- if (pixBegin)
+
+ if (pixelCount > 0 && pixBegin)
{
auto pixEnd = pixBegin + 3 * pixelCount; //RGB
@@ -77,9 +78,9 @@ double getAvgBrightness(const wxImage& img)
for (auto iter = pixBegin; iter != pixEnd; ++iter)
dividend += *iter * static_cast<double>(alphaFirst[(iter - pixBegin) / 3]);
- const int divisor = 3.0 * std::accumulate(alphaFirst, alphaFirst + pixelCount, 0.0);
+ const double divisor = 3.0 * std::accumulate(alphaFirst, alphaFirst + pixelCount, 0.0);
- return dividend / divisor;
+ return numeric::isNull(divisor) ? 0 : dividend / divisor;
}
else
return std::accumulate(pixBegin, pixEnd, 0.0) / (3.0 * pixelCount);
bgstack15