forked from tTh/FloatImg
80 lines
1.9 KiB
C
80 lines
1.9 KiB
C
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "../floatimg.h"
|
|
|
|
extern int verbosity; /* must be declared around main() */
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
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]);
|
|
|
|
}
|
|
/* --------------------------------------------------------------------- */
|
|
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;
|
|
}
|
|
/* --------------------------------------------------------------------- */
|
|
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;
|
|
}
|
|
/* --------------------------------------------------------------------- */
|
|
int format_from_extension(char *fname)
|
|
{
|
|
char *cptr;
|
|
|
|
cptr = rindex(fname, '.');
|
|
if (NULL==cptr) {
|
|
fprintf(stderr, "No dot in %s\n", fname);
|
|
return -1;
|
|
}
|
|
|
|
#if DEBUG_LEVEL
|
|
fprintf(stderr, "[%s] --> [%s]\n", fname, cptr);
|
|
#endif
|
|
|
|
if (!strcasecmp(cptr, ".pnm" )) return FILE_TYPE_PNM;
|
|
if (!strcasecmp(cptr, ".fimg")) return FILE_TYPE_FIMG;
|
|
if (!strcasecmp(cptr, ".tga" )) return FILE_TYPE_TGA;
|
|
if (!strcasecmp(cptr, ".png" )) return FILE_TYPE_PNG;
|
|
if (!strcasecmp(cptr, ".tiff")) return FILE_TYPE_TIFF;
|
|
if (!strcasecmp(cptr, ".tif" )) return FILE_TYPE_TIFF;
|
|
if (!strcasecmp(cptr, ".fits")) return FILE_TYPE_FITS;
|
|
|
|
return -1;
|
|
}
|
|
/* --------------------------------------------------------------------- */
|