FloatImg/funcs/equalize.c

99 lines
2.4 KiB
C
Raw Normal View History

2020-04-11 23:18:33 +02:00
/*
* FLOATIMG
2020-08-13 07:25:55 +02:00
* egalisation dynamique approximative
2020-04-11 23:18:33 +02:00
* #coronamaison Thu 09 Apr 2020 03:37:10 PM CEST
*/
#include <stdio.h>
#include <string.h>
2021-05-17 22:38:56 +02:00
#include <stdint.h>
#include <sys/time.h>
2020-04-11 23:18:33 +02:00
#include "../floatimg.h"
extern int verbosity;
/* --------------------------------------------------------------------- */
2022-09-14 12:01:33 +02:00
/* new func: Wed 14 Sep 2022 11:28:04 AM CEST
*/
2022-09-19 11:17:24 +02:00
int fimg_equalize(FloatImg *src, double vmax)
2022-09-14 12:01:33 +02:00
{
2022-09-19 11:17:24 +02:00
float mm[6];
double maxi, coef;
2022-09-14 12:01:33 +02:00
int foo;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %f )\n", __func__, src, vmax);
#endif
memset(mm, 0, 6*sizeof(float));
foo = fimg_get_minmax_rgb(src, mm);
if (foo) {
fprintf(stderr, "%s: err %d get_minmax\n", __func__, foo);
return foo;
}
2022-09-19 11:17:24 +02:00
maxi = mm[1] > mm[3] ? (double)mm[1] : (double)mm[3];
maxi = maxi > mm[5] ? maxi : (double)mm[5];
2022-09-14 12:01:33 +02:00
coef = vmax / maxi;
if (verbosity) {
fprintf(stderr, "maximums %.3f %.3f %.3f %.3f\n",
mm[1], mm[3], mm[5], maxi);
fprintf(stderr, "vmax %f maxi %f multcoef = %g\n", vmax, maxi, coef);
}
2022-09-19 11:17:24 +02:00
foo = fimg_mul_cste(src, (float)coef);
2022-09-14 12:01:33 +02:00
if (foo) {
fprintf(stderr, "%s: err %d mul_cste\n", __func__, foo);
return foo;
}
return 0;
}
/* --------------------------------------------------------------------- */
/*
*
* - wtf is this "void *vptr" thing ?
*/
2020-08-13 07:25:55 +02:00
int fimg_equalize_compute(FloatImg *src, void *vptr, float vmax)
2020-04-11 23:18:33 +02:00
{
float minmax[6];
int foo;
2020-08-13 07:25:55 +02:00
float dr, dg, db;
2020-04-11 23:18:33 +02:00
#if DEBUG_LEVEL
2020-10-09 01:26:07 +02:00
fprintf(stderr, ">>> %s ( %p %p %f )\n", __func__, src, vptr, vmax);
2020-04-11 23:18:33 +02:00
#endif
2020-08-13 07:25:55 +02:00
memset(minmax, 0, 6*sizeof(float));
2020-04-11 23:18:33 +02:00
foo = fimg_get_minmax_rgb(src, minmax);
2020-08-13 07:25:55 +02:00
if (foo) {
fprintf(stderr, "err %d get minmax in %s\n", foo, __func__);
return foo;
}
2022-07-06 10:27:55 +02:00
fprintf(stderr, "vptr is %p vmax is %f\n", vptr, vmax);
2020-08-13 07:25:55 +02:00
dr = minmax[1] - minmax[0];
dg = minmax[3] - minmax[2];
db = minmax[5] - minmax[4];
2020-10-09 01:26:07 +02:00
printf("Rmin %12.4g max %12.4g delta %12.4g\n", minmax[0], minmax[1], dr);
printf("Gmin %12.4g max %12.4g delta %12.4g\n", minmax[2], minmax[3], dg);
printf("Bmin %12.4g max %12.4g delta %12.4g\n", minmax[4], minmax[5], db);
2020-04-11 23:18:33 +02:00
if ( (minmax[0]<0.0) || (minmax[2]<0.0) || (minmax[4]<0.0) ) {
fprintf(stderr, "%s: negative value ?\n", __func__);
return -4;
}
2022-07-06 10:27:55 +02:00
fprintf(stderr, "deltas %12.4g %12.4g %12.4g\n", dr, dg, db);
2020-08-13 07:25:55 +02:00
2020-04-11 23:18:33 +02:00
return 0;
}
/* --------------------------------------------------------------------- */
/* --------------------------------------------------------------------- */
/* --------------------------------------------------------------------- */