fix a critical precision issue

This commit is contained in:
tth 2019-09-28 23:45:51 +02:00
parent 98043bbe0c
commit 252d5c62e0
1 changed files with 8 additions and 5 deletions

View File

@ -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; idx<surface; idx++) {
means[0] += head->R[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;
}