|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
/*
|
|
|
|
|
* Lecture des images PNG |
|
|
|
|
* L'ecriture est en chantier :} |
|
|
|
|
* ---------------------- |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
@ -13,29 +13,14 @@ |
|
|
|
|
|
|
|
|
|
extern int verbosity; |
|
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */ |
|
|
|
|
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 |
|
|
|
|
* RGB (3x8bits) PNG files |
|
|
|
|
* |
|
|
|
|
* Attention : certains fichiers, tels que ceux |
|
|
|
|
* produits par ImageMagick ne sont pas lisibles |
|
|
|
|
* par cette fonction :( |
|
|
|
|
*/ |
|
|
|
|
int fimg_create_from_png(char *filename, FloatImg *fimg) |
|
|
|
|
{ |
|
|
|
@ -57,31 +42,27 @@ png_init(NULL, NULL); /* this is VITAL ! */ |
|
|
|
|
foo = png_open_file_read(&png, filename); |
|
|
|
|
if (PNG_NO_ERROR != foo) { |
|
|
|
|
fprintf(stderr, "%s :\n\topen_file '%s' = %d %s\n", __func__, |
|
|
|
|
filename, foo, pngerr2str(foo)); |
|
|
|
|
filename, foo, png_error_string(foo)); |
|
|
|
|
png_close_file(&png); |
|
|
|
|
return foo; |
|
|
|
|
} |
|
|
|
|
#if DEBUG_LEVEL > 1 |
|
|
|
|
fprintf(stderr, "%s opened\n", filename); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
datasize = png.width * png.height * png.bpp; |
|
|
|
|
if (verbosity) { |
|
|
|
|
printf("----------- %s ---------\n", filename); |
|
|
|
|
png_print_info(&png); puts(""); |
|
|
|
|
fflush(stdout); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ( 3 != png.bpp ) { |
|
|
|
|
/* I don't really understand this part of the code */ |
|
|
|
|
fprintf(stderr, "bpp format %d of '%s' not supported\n", |
|
|
|
|
png.color_type, filename); |
|
|
|
|
return -21; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#if DEBUG_LEVEL |
|
|
|
|
printf("\t%s is %d x %d\n", filename, png.width, png.height); |
|
|
|
|
printf("\tdatalen %d\n", png.png_datalen); |
|
|
|
|
printf("\tcolor type %d\n", png.color_type); |
|
|
|
|
printf("\tbyte/pixel %d\n", png.bpp); |
|
|
|
|
printf("\tdatasize %d\n", datasize); |
|
|
|
|
puts(""); png_print_info(&png); puts(""); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
datasize = png.width * png.height * png.bpp; |
|
|
|
|
datas = malloc(datasize); |
|
|
|
|
if (NULL==datas) { |
|
|
|
|
fprintf(stderr, "%s : fatal memory failure\n", __func__); |
|
|
|
@ -95,10 +76,12 @@ if (foo) { |
|
|
|
|
exit(1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* I GET AN 'Unknown file error' HERE, WHY ???*/ |
|
|
|
|
foo = png_get_data(&png, datas); |
|
|
|
|
if (PNG_NO_ERROR != foo) { |
|
|
|
|
fprintf(stderr, "error in '%s' :\n\tpng_get_data -> %d = %s\n", |
|
|
|
|
__func__, foo, pngerr2str(foo)); |
|
|
|
|
fprintf(stderr, "err in '%s:%s' :\n\tpng_get_data -> %d = %s\n\n", |
|
|
|
|
__FILE__, __func__, foo, png_error_string(foo)); |
|
|
|
|
png_close_file(&png); |
|
|
|
|
return foo; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|