FloatImg/contrib/fimg2povhf.c

117 lines
2.5 KiB
C
Raw Normal View History

2022-01-08 17:48:18 +01:00
/*
* convertir une image flottante en champ d'altitude
*
* nouveau 64 ernest renan - 20220108
*/
#include <stdio.h>
2022-01-08 21:51:31 +01:00
#include <stdlib.h>
2022-01-08 17:48:18 +01:00
#include <math.h>
#include "tthimage.h"
#include "floatimg.h"
int verbosity;
/* ------------------------------------------------------------------ */
int This_is_the_real_conversion(FloatImg *fimg, Image_Desc *hf, int k)
{
int foo;
float minmax[6];
2022-01-08 21:51:31 +01:00
int x, y, h;
float rgb[6], cumul;
float maxi;
2022-01-08 17:48:18 +01:00
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %p %d )\n", __func__, fimg, hf, k);
#endif
foo = fimg_get_minmax_rgb(fimg, minmax);
2022-01-08 21:51:31 +01:00
// fimg_print_minmax(minmax, "source");
maxi = 0.0;
for (y=0; y<fimg->height; y++) {
for (x=0; x<fimg->width; x++) {
foo = fimg_get_rgb(fimg, x, y, rgb);
/* non-magic nuabmer spotted */
cumul = 1.732 * (rgb[1] + rgb[3] + rgb[5]);
if (cumul > maxi) maxi = cumul;
h = (int)cumul;
foo = Image_hf15_plot(hf, x, y, h);
}
}
fprintf(stderr, "--- the critical maximum is %f\n", maxi);
2022-01-08 17:48:18 +01:00
return FULL_NUCKED;
}
/* ------------------------------------------------------------------ */
int Convertir_Fimg_to_Povhf(char *fimgname, char *hfname, int k)
{
FloatImg fimg;
Image_Desc *hf;
int wid, hei;
int foo;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %s %s %d )\n", __func__, fimgname, hfname, k);
#endif
foo = fimg_create_from_dump(fimgname, &fimg);
fprintf(stderr, "load of %s --> %d\n", fimgname, foo);
if (foo) {
return foo;
}
wid = fimg.width; hei = fimg.height; // nice alias
2022-01-08 21:51:31 +01:00
fprintf(stderr, " source picture size %dx%d\n", wid, hei);
2022-01-08 17:48:18 +01:00
hf = Image_alloc(wid, hei, IMAGE_RGB);
fprintf(stderr, "hf alloc -> %p\n", hf);
if (NULL == hf) {
return NULL_POINTER;
}
foo = This_is_the_real_conversion(&fimg, hf, k);
fprintf(stderr, "real conversion -> %d\n", foo);
2022-01-08 21:51:31 +01:00
foo = Image_TGA_save(hfname, hf, 0);
fprintf(stderr, "export as tga -> %d\n", foo);
2022-01-08 17:48:18 +01:00
return FULL_NUCKED;
}
/* ------------------------------------------------------------------ */
2022-01-08 21:51:31 +01:00
void help(int nu)
{
printf("usage :\n");
printf("\t$ fimg2povhf src.fimg dst.tga\n");
}
/* ------------------------------------------------------------------ */
2022-01-08 17:48:18 +01:00
int main(int argc, char *argv[])
{
int foo;
verbosity = 1;
2022-01-08 21:51:31 +01:00
// printf("%s: argc = %d\n", argv[0], argc);
2022-01-08 17:48:18 +01:00
2022-01-08 21:51:31 +01:00
if (3 != argc) {
help(0);
exit(0);
}
if (verbosity > 1) {
Image_print_version(3);
fimg_print_version(3);
}
2022-01-08 17:48:18 +01:00
2022-01-08 21:51:31 +01:00
foo = Convertir_Fimg_to_Povhf(argv[1], argv[2], 0);
2022-01-08 17:48:18 +01:00
fprintf(stderr, "retour conversion was %d\n", foo);
2022-01-08 21:51:31 +01:00
fprintf(stderr, "end\n\n");
2022-01-08 17:48:18 +01:00
return 0;
}
/* ------------------------------------------------------------------ */