forked from tTh/FloatImg
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;
|
||||
|
||||
27
lib/t.c
27
lib/t.c
@@ -55,7 +55,7 @@ int essai_interpolate(int k)
|
||||
FloatImg A, B, C;
|
||||
int foo, idx;
|
||||
char ligne[200];
|
||||
float fval;
|
||||
float fval, minmax[6];
|
||||
|
||||
foo = fimg_create(&A, WI, HI, FIMG_TYPE_RGB);
|
||||
if (foo) {
|
||||
@@ -176,6 +176,29 @@ return 0;
|
||||
|
||||
#undef TAILLE
|
||||
|
||||
/* ---------------------------------------------------------------- */
|
||||
int essai_get_values(char *fname)
|
||||
{
|
||||
int foo;
|
||||
FloatImg dessin;
|
||||
float vals[6];
|
||||
|
||||
foo = fimg_create_from_dump(fname, &dessin);
|
||||
if (foo) {
|
||||
fprintf(stderr, "in %s, error %d loading '%s'\n",
|
||||
__func__, foo, fname);
|
||||
return foo;
|
||||
}
|
||||
|
||||
fimg_get_minmax_rgb(&dessin, vals);
|
||||
|
||||
for (foo=0; foo<6; foo++) {
|
||||
fprintf(stderr, "%7d %17.6g\n", foo, vals[foo]);
|
||||
}
|
||||
|
||||
|
||||
return -1;
|
||||
}
|
||||
/* ---------------------------------------------------------------- */
|
||||
|
||||
int essai_contraste(char *fname)
|
||||
@@ -250,7 +273,7 @@ if (verbosity) fimg_print_version(0);
|
||||
// foo = essai_clone_et_copy(0);
|
||||
// fprintf(stderr, "retour essai clone'n'copy -> %d\n", foo);
|
||||
|
||||
foo = essai_interpolate(0);
|
||||
foo = essai_get_values("quux.fimg");
|
||||
fprintf(stderr, "retour essai interpolate -> %d\n", foo);
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user