better display of error messages

This commit is contained in:
tth 2019-09-09 17:26:32 +02:00
parent ec56f998c2
commit 6176744de8
1 changed files with 27 additions and 3 deletions

View File

@ -10,6 +10,25 @@
#include "../floatimg.h"
/* --------------------------------------------------------------------- */
static char *pngerr2str(int code)
{
switch (code) {
case 1: return "Done";
case 0: return "No error";
case -1: return "File error";
case -2: return "Header error";
case -3: return "IO error";
case -4: return "EOF error";
case -5: return "CRC error";
case -6: return "Memory error";
case -7: return "Zlib error";
case -8: return "Unknow filter";
case -9: return "Not supported";
case -10: return "Wrong arguments";
}
return "*unknow*";
}
/* --------------------------------------------------------------------- */
/*
* warning : this func has been tested only with
@ -26,12 +45,16 @@ int datasize;
fprintf(stderr, ">>> %-25s ( '%s' %p )\n", __func__, filename, fimg);
#endif
/* We MUSTclear the fimg destination header first */
memset(fimg, 0, sizeof(FloatImg));
memset(&png, 0, sizeof(png_t));
png_init(NULL, NULL); /* this is VITAL ! */
foo = png_open_file_read(&png, filename);
if (PNG_NO_ERROR != foo) {
fprintf(stderr, "%s open_file '%s' -> %d\n", __func__, filename, foo);
fprintf(stderr, "%s :\n\topen_file '%s' = %d %s\n", __func__,
filename, foo, pngerr2str(foo));
return foo;
}
#if DEBUG_LEVEL > 1
@ -70,8 +93,8 @@ if (foo) {
foo = png_get_data(&png, datas);
if (PNG_NO_ERROR != foo) {
fprintf(stderr, "error in '%s' : read png -> %d\n",
__func__, foo);
fprintf(stderr, "error in '%s' : read png -> %d %s\n",
__func__, foo, pngerr2str(foo));
return foo;
}
@ -138,6 +161,7 @@ if (PNG_NO_ERROR != foo) {
__func__, foo);
return foo;
}
ptr = datas;
for (idx=0; idx<png.width * png.height; idx++) {
fimg->R[idx] = (float)*ptr++;