counting negative values

This commit is contained in:
tth 2019-09-25 09:21:00 +02:00
parent d294102ca4
commit 54269cc007
3 changed files with 28 additions and 1 deletions

View File

@ -79,6 +79,7 @@ int fimg_to_gray(FloatImg *head);
void fimg_add_cste(FloatImg *fi, float value);
void fimg_mul_cste(FloatImg *fi, float value);
void fimg_drand48(FloatImg *fi, float kmul);
int fimg_count_negativ(FloatImg *fi);
/* various funcs modules */
int fimg_load_from_png(char *filename, FloatImg *fimg);

View File

@ -108,6 +108,27 @@ for (idx=0; idx<nbre; idx++) {
}
}
/* ---------------------------------------------------------------- */
int fimg_count_negativ(FloatImg *fi)
{
int nbre, idx;
int count;
if (fi->type != FIMG_TYPE_RGB) {
fprintf(stderr, "%s : type %d invalide\n",
__func__, fi->type);
return -1;
}
nbre = fi->width * fi->height * fi->type;
count = 0;
for (idx=0; idx<nbre; idx++) {
if (fi->R[idx] < 0.0) count++;
}
return count;
}
/* ---------------------------------------------------------------- */
void fimg_mul_cste(FloatImg *fi, float value)
{
int nbre, idx;

View File

@ -33,6 +33,11 @@ for (foo=0; foo<4; foo++)
fvalue = fimg_get_maxvalue(fimg);
printf("max value %f\n", fvalue);
foo = fimg_count_negativ(fimg);
if (foo) {
fprintf(stderr, "%d negative values\n", foo);
}
return 0;
}
/* --------------------------------------------------------------------- */