2019-03-03 16:22:55 +01:00
|
|
|
/*
|
|
|
|
* FIMGSTATS
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2021-05-20 09:31:28 +02:00
|
|
|
#include <stdint.h>
|
2019-03-03 16:22:55 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "../floatimg.h"
|
|
|
|
|
|
|
|
int verbosity; /* global */
|
|
|
|
int make_csv;
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
2022-03-10 17:25:19 +01:00
|
|
|
int machinable(FloatImg *fimg)
|
|
|
|
{
|
|
|
|
float vals[6];
|
|
|
|
float means[4];
|
|
|
|
|
|
|
|
if (verbosity) {
|
|
|
|
fprintf(stderr, "%s numbers from %p :\n", __func__, fimg);
|
|
|
|
}
|
|
|
|
|
|
|
|
fimg_meanvalues(fimg, means);
|
|
|
|
fimg_get_minmax_rgb(fimg, vals);
|
2022-03-10 18:04:50 +01:00
|
|
|
printf( "%.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f\n",
|
2022-03-10 17:25:19 +01:00
|
|
|
vals[0], means[0], vals[1],
|
|
|
|
vals[2], means[1], vals[3],
|
|
|
|
vals[4], means[2], vals[5]);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
int various_numbers(FloatImg *fimg)
|
2019-03-03 16:22:55 +01:00
|
|
|
{
|
|
|
|
float moyennes[4];
|
|
|
|
int foo;
|
2020-03-02 14:51:34 +01:00
|
|
|
float vals[6];
|
2019-03-03 16:22:55 +01:00
|
|
|
|
2020-03-02 14:51:34 +01:00
|
|
|
if (verbosity) {
|
2022-03-10 17:25:19 +01:00
|
|
|
fprintf(stderr, "%s numbers from %p :\n", __func__, fimg);
|
2020-03-02 14:51:34 +01:00
|
|
|
}
|
2019-03-03 16:22:55 +01:00
|
|
|
|
|
|
|
fimg_printhead(fimg);
|
|
|
|
fprintf(stderr, "surface %d\n", fimg->width * fimg->height);
|
|
|
|
|
|
|
|
fimg_meanvalues(fimg, moyennes);
|
|
|
|
fprintf(stderr, "mean values:\n");
|
|
|
|
for (foo=0; foo<4; foo++)
|
|
|
|
printf(" %c %14.6f\n", "RGBA"[foo], moyennes[foo]);
|
|
|
|
|
2019-09-25 09:21:00 +02:00
|
|
|
foo = fimg_count_negativ(fimg);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "%d negative values\n", foo);
|
|
|
|
}
|
2019-03-03 16:22:55 +01:00
|
|
|
|
2020-03-02 14:51:34 +01:00
|
|
|
foo = fimg_get_minmax_rgb(fimg, vals);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "%s: err %d on fimg_get_minmax_rgb\n",
|
|
|
|
__func__, foo);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
|
2023-06-29 14:14:47 +02:00
|
|
|
printf("Rmin %12.6g Rmax %12.6g delta %12.6g\n",
|
2020-08-04 22:07:40 +02:00
|
|
|
vals[0], vals[1], vals[1]-vals[0]);
|
2023-06-29 14:14:47 +02:00
|
|
|
printf("Gmin %12.6g Gmax %12.6g %12.6g\n",
|
2020-08-04 22:07:40 +02:00
|
|
|
vals[2], vals[3], vals[3]-vals[2]);
|
2023-06-29 14:14:47 +02:00
|
|
|
printf("Bmin %12.6g Bmax %12.6g %12.6g\n",
|
2020-08-04 22:07:40 +02:00
|
|
|
vals[4], vals[5], vals[5]-vals[4]);
|
2020-03-02 14:51:34 +01:00
|
|
|
|
2019-03-03 16:22:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
int various_numbers_from_file(char *fname, int k)
|
|
|
|
{
|
|
|
|
FloatImg fimg;
|
|
|
|
int foo;
|
|
|
|
|
2022-03-10 17:25:19 +01:00
|
|
|
if (verbosity) {
|
|
|
|
fprintf(stderr, "------ numbers from '%s' :\n", fname);
|
|
|
|
}
|
2019-03-03 16:22:55 +01:00
|
|
|
|
|
|
|
foo = fimg_create_from_dump(fname, &fimg);
|
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "create fimg from '%s' -> %d\n", fname, foo);
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2022-03-10 17:25:19 +01:00
|
|
|
if (k) {
|
|
|
|
foo = machinable(&fimg);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
foo = various_numbers(&fimg);
|
|
|
|
}
|
2019-03-03 16:22:55 +01:00
|
|
|
fimg_destroy(&fimg);
|
2022-03-10 17:25:19 +01:00
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "%s: got a %d\n", __func__, foo);
|
|
|
|
return foo;
|
|
|
|
}
|
2019-03-03 16:22:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
static void help(int k)
|
|
|
|
{
|
|
|
|
fputs( "usage : fimgstats [options] file.fimg\n"
|
|
|
|
"\t-c\tmake a machinable csv\n"
|
|
|
|
"\t-v\tincrease verbosity\n"
|
|
|
|
, stderr);
|
2022-05-14 20:49:59 +02:00
|
|
|
if (k) {
|
|
|
|
fimg_print_version(k);
|
|
|
|
}
|
2019-03-03 16:22:55 +01:00
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int foo, opt;
|
2022-03-10 17:25:19 +01:00
|
|
|
int do_machinable = 0;
|
2019-03-03 16:22:55 +01:00
|
|
|
extern char *optarg;
|
|
|
|
extern int optind, opterr, optopt;
|
|
|
|
|
|
|
|
if (argc == 1) {
|
|
|
|
foo = fimg_print_version(1); help(0);
|
|
|
|
exit(0);
|
|
|
|
}
|
2020-03-02 14:51:34 +01:00
|
|
|
|
2022-03-10 17:25:19 +01:00
|
|
|
while ((opt = getopt(argc, argv, "chmv")) != -1) {
|
2019-03-03 16:22:55 +01:00
|
|
|
switch(opt) {
|
|
|
|
case 'c': make_csv++; break;
|
|
|
|
case 'v': verbosity++; break;
|
2022-03-10 17:25:19 +01:00
|
|
|
case 'm': do_machinable = 1; break;
|
2020-06-18 23:43:41 +02:00
|
|
|
case 'h': /* tombe dedans */
|
2019-03-03 16:22:55 +01:00
|
|
|
default: help(1); exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-18 23:43:41 +02:00
|
|
|
if (NULL==argv[optind]) {
|
|
|
|
fprintf(stderr, "optind %d is wtf\n", optind);
|
|
|
|
return 1;
|
|
|
|
}
|
2022-03-10 17:25:19 +01:00
|
|
|
foo = various_numbers_from_file(argv[optind], do_machinable);
|
2019-07-16 00:19:59 +02:00
|
|
|
if (foo) {
|
|
|
|
fprintf(stderr, "got a %d ?\n", foo);
|
|
|
|
}
|
2019-03-03 16:22:55 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|