From 252d5c62e0cfa814ceda925e2529e590da06288a Mon Sep 17 00:00:00 2001 From: tth Date: Sat, 28 Sep 2019 23:45:51 +0200 Subject: [PATCH] fix a critical precision issue --- lib/fimg-math.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/fimg-math.c b/lib/fimg-math.c index 873f322..61fab7b 100644 --- a/lib/fimg-math.c +++ b/lib/fimg-math.c @@ -47,21 +47,24 @@ return maxval; int fimg_meanvalues(FloatImg *head, float means[4]) { int idx, surface; +double accus[4]; surface = head->width * head->height; if (surface < 1) return -1; -memset(means, 0, 4*sizeof(float)); +memset(accus, 0, 4*sizeof(double)); for (idx=0; idxR[idx]; + accus[0] += head->R[idx]; if (head->type > 2) { - means[1] += head->G[idx]; - means[2] += head->B[idx]; + accus[1] += head->G[idx]; + accus[2] += head->B[idx]; } } -for (idx=0; idx<4; idx++) means[idx] /= (float)surface; +for (idx=0; idx<4; idx++) { + means[idx] = (float)(accus[idx]/(double)surface); + } return 0; }