2021-03-18 04:32:51 +11:00
|
|
|
/*
|
|
|
|
* FloatImg from tTh - 2021
|
|
|
|
*/
|
2019-08-29 06:08:59 +11:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2019-10-31 01:49:53 +11:00
|
|
|
#include <string.h>
|
2019-08-29 06:08:59 +11:00
|
|
|
|
|
|
|
#include "../floatimg.h"
|
|
|
|
|
|
|
|
extern int verbosity; /* must be declared around main() */
|
|
|
|
|
2020-10-27 02:19:51 +11:00
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
void fimg_print_minmax(float minmax[6], char *titre)
|
|
|
|
{
|
|
|
|
|
|
|
|
fprintf(stderr, "\t\tminmax %s\n", titre);
|
|
|
|
fprintf(stderr, "red\t\t%10f %10f\n", minmax[0], minmax[1]);
|
|
|
|
fprintf(stderr, "green\t\t%10f %10f\n", minmax[2], minmax[3]);
|
|
|
|
fprintf(stderr, "blue\t\t%10f %10f\n", minmax[4], minmax[5]);
|
|
|
|
}
|
2019-08-29 06:08:59 +11:00
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
int parse_WxH(char *str, int *pw, int *ph)
|
|
|
|
{
|
|
|
|
// char *ptr;
|
|
|
|
int foo, w, h;
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( '%s' %p %p )\n", __func__,
|
|
|
|
str, pw, ph);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
foo = sscanf(str, "%dx%d", &w, &h);
|
|
|
|
if (2 != foo) {
|
|
|
|
fprintf(stderr, "%s : arg '%s' is invalid\n", __func__, str);
|
|
|
|
return foo;
|
|
|
|
}
|
|
|
|
*pw = w; *ph = h;
|
|
|
|
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
2019-09-16 21:28:47 +11:00
|
|
|
int parse_double(char *str, double *dptr)
|
|
|
|
{
|
|
|
|
double value;
|
|
|
|
int foo;
|
|
|
|
|
|
|
|
foo = sscanf(str, "%lf", &value);
|
|
|
|
if (1 == foo) {
|
|
|
|
*dptr = value;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
2019-10-31 01:49:53 +11:00
|
|
|
int format_from_extension(char *fname)
|
|
|
|
{
|
|
|
|
char *cptr;
|
|
|
|
|
|
|
|
cptr = rindex(fname, '.');
|
|
|
|
if (NULL==cptr) {
|
2019-11-07 21:56:19 +11:00
|
|
|
fprintf(stderr, "No dot in %s\n", fname);
|
2019-10-31 01:49:53 +11:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, "[%s] --> [%s]\n", fname, cptr);
|
|
|
|
#endif
|
|
|
|
|
2020-08-24 02:21:10 +11:00
|
|
|
if (!strcasecmp(cptr, ".pnm" )) return FILE_TYPE_PNM;
|
2019-10-31 01:49:53 +11:00
|
|
|
if (!strcasecmp(cptr, ".fimg")) return FILE_TYPE_FIMG;
|
2020-08-24 02:21:10 +11:00
|
|
|
if (!strcasecmp(cptr, ".tga" )) return FILE_TYPE_TGA;
|
|
|
|
if (!strcasecmp(cptr, ".png" )) return FILE_TYPE_PNG;
|
2020-03-23 23:01:56 +11:00
|
|
|
if (!strcasecmp(cptr, ".tiff")) return FILE_TYPE_TIFF;
|
2020-08-24 02:21:10 +11:00
|
|
|
if (!strcasecmp(cptr, ".tif" )) return FILE_TYPE_TIFF;
|
2020-07-24 04:08:17 +11:00
|
|
|
if (!strcasecmp(cptr, ".fits")) return FILE_TYPE_FITS;
|
2019-10-31 01:49:53 +11:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|