diff --git a/lib/fimg-math.c b/lib/fimg-math.c index 873f3229..61fab7bd 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; }