FloatImg/funcs/thermocolor.c

68 lines
1.4 KiB
C
Raw Permalink Normal View History

2024-03-21 04:44:06 +11:00
/*
* FLOATIMG
* fabriquer une pseudo-image thermique
*
* new: Wed Mar 20 16:55:09 UTC 2024 dans ma maison du Gers
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "../floatimg.h"
extern int verbosity;
/* --------------------------------------------------------------------- */
2024-03-27 18:50:17 +11:00
/*
* parameter k in not used, but may be in the futur.
*/
2024-03-21 04:44:06 +11:00
int fimg_auto_thermique(FloatImg *src, FloatImg *dst, int k)
{
// int x, y, off;
int idx, surface;
float seuil, gray;
double graymean;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, src, dst, k);
#endif
if (0!=k) {
2024-03-27 18:50:17 +11:00
fprintf(stderr, "%s: k must be 0, was %d\n", __func__, k);
2024-03-21 04:44:06 +11:00
}
surface = src->width * src->height;
2024-03-27 18:50:17 +11:00
// fprintf(stderr, "surface = %d\n", surface);
2024-03-21 04:44:06 +11:00
graymean = 0.0;
for (idx=0; idx<surface; idx++) {
gray = src->R[idx] + src->G[idx] + src->B[idx];
graymean += (double)gray;
}
seuil = (float) (graymean / surface);
// fprintf(stderr, "graymean = %f seuil = %f\n", graymean, seuil);
2024-03-27 18:50:17 +11:00
/*
* please, explain this number brotching
*/
2024-03-21 04:44:06 +11:00
for (idx=0; idx<surface; idx++) {
gray = src->R[idx] + src->G[idx] + src->B[idx];
if (gray > seuil) {
dst->R[idx] = gray - seuil;
dst->B[idx] = seuil / 8.0;
}
else {
dst->G[idx] = gray;
dst->B[idx] = seuil / 8.0;
}
}
return 0;
}
/* --------------------------------------------------------------------- */