adding fimg_get_minmax_rgb function
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <float.h> /* for FLT_MAX */
|
||||
#include <math.h>
|
||||
|
||||
#include "../floatimg.h"
|
||||
@@ -44,6 +45,45 @@ switch (head->type) {
|
||||
return maxval;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
/*
|
||||
* mmval[0] <- min(R) mmval[1] <- max(R)
|
||||
*/
|
||||
int fimg_get_minmax_rgb(FloatImg *head, float mmvals[6])
|
||||
{
|
||||
int idx, surface;
|
||||
float fval;
|
||||
|
||||
if (head->type != FIMG_TYPE_RGB) {
|
||||
fprintf(stderr, "%s : type %d invalide\n",
|
||||
__func__, head->type);
|
||||
return -2;
|
||||
}
|
||||
|
||||
surface = head->width * head->height;
|
||||
mmvals[0] = FLT_MAX; mmvals[1] = -FLT_MAX;
|
||||
mmvals[2] = FLT_MAX; mmvals[3] = -FLT_MAX;
|
||||
mmvals[4] = FLT_MAX; mmvals[5] = -FLT_MAX;
|
||||
|
||||
for (idx=0; idx<surface; idx++) {
|
||||
fval = head->R[idx];
|
||||
if (fval < mmvals[0]) mmvals[0] = fval;
|
||||
else if (fval > mmvals[1]) mmvals[1] = fval;
|
||||
fval = head->G[idx];
|
||||
if (fval < mmvals[2]) mmvals[2] = fval;
|
||||
else if (fval > mmvals[3]) mmvals[3] = fval;
|
||||
fval = head->B[idx];
|
||||
if (fval < mmvals[4]) mmvals[4] = fval;
|
||||
else if (fval > mmvals[5]) mmvals[5] = fval;
|
||||
}
|
||||
#if 0
|
||||
for (foo=0; foo<6; foo++) {
|
||||
fprintf(stderr, "%3d %g\n", foo, mmvals[foo]);
|
||||
}
|
||||
#endif
|
||||
|
||||
return -0;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
int fimg_meanvalues(FloatImg *head, float means[4])
|
||||
{
|
||||
int idx, surface;
|
||||
|
||||
Reference in New Issue
Block a user