FloatImg/funcs/utils.c

69 lines
1.5 KiB
C
Raw Normal View History

2019-08-28 21:08:59 +02:00
#include <stdio.h>
2019-10-30 15:49:53 +01:00
#include <string.h>
2019-08-28 21:08:59 +02:00
#include "../floatimg.h"
extern int verbosity; /* must be declared around main() */
/* --------------------------------------------------------------------- */
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 12:28:47 +02: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-30 15:49:53 +01:00
int format_from_extension(char *fname)
{
char *cptr;
cptr = rindex(fname, '.');
if (NULL==cptr) {
2019-11-07 11:56:19 +01:00
fprintf(stderr, "No dot in %s\n", fname);
2019-10-30 15:49:53 +01:00
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;
2020-07-23 19:08:17 +02:00
if (!strcasecmp(cptr, ".tga")) return FILE_TYPE_TGA;
2019-10-30 15:49:53 +01:00
if (!strcasecmp(cptr, ".png")) return FILE_TYPE_PNG;
2020-03-23 13:01:56 +01:00
if (!strcasecmp(cptr, ".tiff")) return FILE_TYPE_TIFF;
2020-07-23 19:08:17 +02:00
if (!strcasecmp(cptr, ".fits")) return FILE_TYPE_FITS;
2019-10-30 15:49:53 +01:00
return -1;
}
/* --------------------------------------------------------------------- */