2021-03-17 18:32:51 +01:00
|
|
|
/*
|
|
|
|
* FloatImg from tTh - 2021
|
|
|
|
*/
|
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() */
|
|
|
|
|
2020-10-26 16:19:51 +01: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-28 21:08:59 +02: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 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;
|
|
|
|
}
|
2021-04-23 11:08:05 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
int file_type_from_name(char *name)
|
|
|
|
{
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, name);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!strcasecmp(name, "pnm" )) return FILE_TYPE_PNM;
|
|
|
|
if (!strcasecmp(name, "fimg")) return FILE_TYPE_FIMG;
|
|
|
|
if (!strcasecmp(name, "tga" )) return FILE_TYPE_TGA;
|
|
|
|
if (!strcasecmp(name, "png" )) return FILE_TYPE_PNG;
|
|
|
|
if (!strcasecmp(name, "tiff")) return FILE_TYPE_TIFF;
|
|
|
|
if (!strcasecmp(name, "tif" )) return FILE_TYPE_TIFF;
|
|
|
|
if (!strcasecmp(name, "fits")) return FILE_TYPE_FITS;
|
|
|
|
if (!strcasecmp(name, "exr")) return FILE_TYPE_EXR;
|
|
|
|
|
2019-09-16 12:28:47 +02:00
|
|
|
return -1;
|
|
|
|
}
|
2021-04-25 12:51:01 +02:00
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
/*
|
|
|
|
* /!\ return 4 on success
|
|
|
|
*/
|
2021-04-28 00:21:45 +02:00
|
|
|
int parse_rectangle(char *str, FimgArea51 *r, int notused)
|
2021-04-25 12:51:01 +02:00
|
|
|
{
|
|
|
|
int x, y, w, h, foo;
|
|
|
|
|
|
|
|
if (verbosity)
|
|
|
|
fprintf(stderr, "parsing %s\n", str);
|
|
|
|
|
|
|
|
foo = sscanf(str, "%d,%d,%d,%d", &w, &h, &x, &y);
|
|
|
|
if (4 == foo) {
|
|
|
|
r->x = x, r->y = y, r->w = w, r->h = h;
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-09-16 12:28:47 +02:00
|
|
|
/* --------------------------------------------------------------------- */
|
2019-10-30 15:49:53 +01:00
|
|
|
int format_from_extension(char *fname)
|
|
|
|
{
|
|
|
|
char *cptr;
|
|
|
|
|
2021-04-23 11:08:05 +02:00
|
|
|
#if DEBUG_LEVEL
|
|
|
|
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, fname);
|
|
|
|
#endif
|
|
|
|
|
2019-10-30 15:49:53 +01:00
|
|
|
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
|
2021-04-23 11:08:05 +02:00
|
|
|
fprintf(stderr, "\t[%s] --> [%s]\n", fname, cptr);
|
2019-10-30 15:49:53 +01:00
|
|
|
#endif
|
|
|
|
|
2021-04-23 11:08:05 +02:00
|
|
|
return file_type_from_name(cptr+1);
|
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
char * extension_from_format(int fmt)
|
|
|
|
{
|
2019-10-30 15:49:53 +01:00
|
|
|
|
2021-04-23 11:08:05 +02:00
|
|
|
switch (fmt) {
|
|
|
|
case FILE_TYPE_FIMG: return ".fimg"; break;
|
|
|
|
case FILE_TYPE_PNM: return ".pnm"; break;
|
|
|
|
case FILE_TYPE_PNG: return ".png"; break;
|
|
|
|
case FILE_TYPE_TIFF: return ".tiff"; break;
|
|
|
|
case FILE_TYPE_FITS: return ".fits"; break;
|
|
|
|
case FILE_TYPE_TGA: return ".tga"; break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "%s: bad %d fmt type\n", __func__, fmt);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "???";
|
2019-10-30 15:49:53 +01:00
|
|
|
}
|
|
|
|
/* --------------------------------------------------------------------- */
|