better handling of file extenstions

This commit is contained in:
tth 2021-04-23 11:08:05 +02:00
parent dcc1ff35cb
commit 0478bae6a3
3 changed files with 52 additions and 15 deletions

View File

@ -1,6 +1,9 @@
#---------------------------------------------------------------
COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=0
# Please, use the 'Gloabl.makefile' system !
COPT = -Wall -fpic -g -no-pie -DDEBUG_LEVEL=1
DEPS = ../floatimg.h Makefile
OBJS = fimg-png.o fimg-tiff.o misc-plots.o filtrage.o utils.o \

View File

@ -639,7 +639,7 @@ return 0;
int essai_mire(char *outname, int notused)
{
FloatImg fimg;
int re;
int re, foo;
fimg_create(&fimg, 1280, 960, FIMG_TYPE_RGB);
@ -647,9 +647,10 @@ re = fimg_test_pattern(&fimg, 9, 1.0);
if (re) {
fprintf(stderr, "fimg_test_pattern -> %d\n", re);
}
fimg_export_picture(&fimg, "mire.pnm", 0);
foo = fimg_export_picture(&fimg, "mire.pnm", 0);
fprintf(stderr, "in %s, export give a %d value\n", __func__, foo);
return -1;
return 0;
}
/* --------------------------------------------------------------------- */
int essai_rampes(void)

View File

@ -49,6 +49,25 @@ if (1 == foo) {
*dptr = value;
return 1;
}
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;
return -1;
}
/* --------------------------------------------------------------------- */
@ -56,6 +75,10 @@ int format_from_extension(char *fname)
{
char *cptr;
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( '%s' )\n", __func__, fname);
#endif
cptr = rindex(fname, '.');
if (NULL==cptr) {
fprintf(stderr, "No dot in %s\n", fname);
@ -63,18 +86,28 @@ if (NULL==cptr) {
}
#if DEBUG_LEVEL
fprintf(stderr, "[%s] --> [%s]\n", fname, cptr);
fprintf(stderr, "\t[%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;
if (!strcasecmp(cptr, ".exr")) return FILE_TYPE_EXR;
return -1;
return file_type_from_name(cptr+1);
}
/* --------------------------------------------------------------------- */
char * extension_from_format(int fmt)
{
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 "???";
}
/* --------------------------------------------------------------------- */