From fbd39cdcdf663075a0137e89958553f91145ed8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Sun, 30 Sep 2018 14:40:27 +0200 Subject: [PATCH] Fix average color computation --- general.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/general.hpp b/general.hpp index 3731171..b0bf033 100644 --- a/general.hpp +++ b/general.hpp @@ -463,6 +463,7 @@ unsigned char computeAverageColor(const unsigned char *texture, int16_t excludeC uint32_t sumS = 0; uint32_t sumV = 0; uint32_t pixels = texture[0] * texture[1]; + uint32_t count = 0; for (uint16_t i = 0; i < pixels; ++i) { @@ -476,9 +477,10 @@ unsigned char computeAverageColor(const unsigned char *texture, int16_t excludeC sumH += h; sumS += s; sumV += v; + count++; } - return encodeHSV(sumH / pixels,sumS / pixels, sumV / pixels); + return encodeHSV(sumH / count,sumS / count, sumV / count); } #endif