Compare commits

..

3 Commits

Author SHA1 Message Date
tth
f109077b50 experimenting... 2019-09-09 17:27:48 +02:00
tth
6176744de8 better display of error messages 2019-09-09 17:26:32 +02:00
tth
ec56f998c2 ahem, of-by-one error ? 2019-09-09 17:24:31 +02:00
3 changed files with 51 additions and 9 deletions

View File

@ -10,6 +10,25 @@
#include "../floatimg.h" #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 * warning : this func has been tested only with
@ -26,12 +45,16 @@ int datasize;
fprintf(stderr, ">>> %-25s ( '%s' %p )\n", __func__, filename, fimg); fprintf(stderr, ">>> %-25s ( '%s' %p )\n", __func__, filename, fimg);
#endif #endif
/* We MUSTclear the fimg destination header first */
memset(fimg, 0, sizeof(FloatImg));
memset(&png, 0, sizeof(png_t)); memset(&png, 0, sizeof(png_t));
png_init(NULL, NULL); /* this is VITAL ! */ png_init(NULL, NULL); /* this is VITAL ! */
foo = png_open_file_read(&png, filename); foo = png_open_file_read(&png, filename);
if (PNG_NO_ERROR != foo) { 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; return foo;
} }
#if DEBUG_LEVEL > 1 #if DEBUG_LEVEL > 1
@ -70,8 +93,8 @@ if (foo) {
foo = png_get_data(&png, datas); foo = png_get_data(&png, datas);
if (PNG_NO_ERROR != foo) { if (PNG_NO_ERROR != foo) {
fprintf(stderr, "error in '%s' : read png -> %d\n", fprintf(stderr, "error in '%s' : read png -> %d %s\n",
__func__, foo); __func__, foo, pngerr2str(foo));
return foo; return foo;
} }
@ -138,6 +161,7 @@ if (PNG_NO_ERROR != foo) {
__func__, foo); __func__, foo);
return foo; return foo;
} }
ptr = datas; ptr = datas;
for (idx=0; idx<png.width * png.height; idx++) { for (idx=0; idx<png.width * png.height; idx++) {
fimg->R[idx] = (float)*ptr++; fimg->R[idx] = (float)*ptr++;

View File

@ -10,6 +10,12 @@
int verbosity; int verbosity;
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */
static int gray_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef)
{
return -1;
}
/* ---------------------------------------------------------------- */
int fimg_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef) int fimg_interpolate(FloatImg *s1, FloatImg *s2, FloatImg *d, float coef)
{ {
int picsize, idx; int picsize, idx;
@ -31,7 +37,7 @@ if (FIMG_TYPE_RGB != d->type) {
return -9; return -9;
} }
picsize = d->width * d->height * 2; picsize = d->width * d->height * 3;
for (idx=0; idx<picsize; idx++) { for (idx=0; idx<picsize; idx++) {
@ -39,6 +45,6 @@ for (idx=0; idx<picsize; idx++) {
} }
return -1; return 0;
} }
/* ---------------------------------------------------------------- */ /* ---------------------------------------------------------------- */

20
lib/t.c
View File

@ -88,12 +88,24 @@ verbosity = 1;
fimg_print_version(1); fimg_print_version(1);
foo = fimg_create_from_png("/home/tth/TMP/floatimg/s2.png", &dessin); foo = fimg_create_from_png("/home/tth/TMP/floatimg/s1.png", &dessin);
foo = fimg_create_from_png("/home/tth/TMP/floatimg/s1.png", &noise); if (foo) {
fprintf(stderr, "s1 load err %d\n", foo);
exit(1);
}
fimg_describe(&dessin, "s1 dessin");
fimg_to_gray(&dessin);
foo = fimg_create_from_png("/home/tth/TMP/floatimg/s2.png", &noise);
if (foo) {
fprintf(stderr, "s2 load err %d\n", foo);
exit(1);
}
fimg_describe(&noise, "s2 noise");
foo = fimg_create(&result, W, H, 3); foo = fimg_create(&result, W, H, 3);
#define NBRE 42 #define NBRE 20
for (idx=0; idx<NBRE; idx++) { for (idx=0; idx<NBRE; idx++) {
@ -104,7 +116,7 @@ for (idx=0; idx<NBRE; idx++) {
foo = fimg_interpolate(&dessin, &noise, &result, coef); foo = fimg_interpolate(&dessin, &noise, &result, coef);
printf("%6d %9.6f\n", idx, coef); printf("%6d %9.6f\n", idx, coef);
fimg_to_gray(&result); // fimg_to_gray(&result);
sprintf(outname, "/home/tth/TMP/floatimg/%05d.pnm", idx); sprintf(outname, "/home/tth/TMP/floatimg/%05d.pnm", idx);
foo = fimg_save_as_pnm(&result, outname, 0); foo = fimg_save_as_pnm(&result, outname, 0);
} }