diff --git a/doc/COMPILING.txt b/doc/COMPILING.txt index a5c3c0f4..271c656a 100644 --- a/doc/COMPILING.txt +++ b/doc/COMPILING.txt @@ -125,7 +125,7 @@ Zlib: Libpng Requires: Zlib http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/l/li/libpng/ - libpng-1.0.23.tar.gz + libpng-1.4.2.tar.gz (Before June 2010, we were using libpng-1.0.23.tar.gz) Uncompress in temporary directory ./configure make diff --git a/src/fileformats.c b/src/fileformats.c index 433935f1..daed68fc 100644 --- a/src/fileformats.c +++ b/src/fileformats.c @@ -27,6 +27,19 @@ #ifndef __no_pnglib__ #include +#if (PNG_LIBPNG_VER_MAJOR <= 1) && (PNG_LIBPNG_VER_MINOR < 4) + // Compatibility layer to allow us to use libng 1.4 or any older one. + + // This function is renamed in 1.4 + #define png_set_expand_gray_1_2_4_to_8(x) png_set_gray_1_2_4_to_8(x) + + // Wrappers that are mandatory in 1.4. Older version allowed direct access. + #define png_get_rowbytes(png_ptr,info_ptr) ((info_ptr)->rowbytes) + #define png_get_image_width(png_ptr,info_ptr) ((info_ptr)->width) + #define png_get_image_height(png_ptr,info_ptr) ((info_ptr)->height) + #define png_get_bit_depth(png_ptr,info_ptr) ((info_ptr)->bit_depth) + #define png_get_color_type(png_ptr,info_ptr) ((info_ptr)->color_type) +#endif #endif #include @@ -3371,8 +3384,8 @@ void Load_PNG(T_IO_Context * context) // Load file information png_read_info(png_ptr, info_ptr); - color_type = info_ptr->color_type; - bit_depth = info_ptr->bit_depth; + color_type = png_get_color_type(png_ptr,info_ptr); + bit_depth = png_get_bit_depth(png_ptr,info_ptr); // If it's any supported file // (Note: As of writing this, this test covers every possible @@ -3425,9 +3438,9 @@ void Load_PNG(T_IO_Context * context) } } if (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_RGB_ALPHA) - Pre_load(context,info_ptr->width,info_ptr->height,File_length_file(file),FORMAT_PNG,PIXEL_SIMPLE,1); + Pre_load(context,png_get_image_width(png_ptr,info_ptr),png_get_image_height(png_ptr,info_ptr),File_length_file(file),FORMAT_PNG,PIXEL_SIMPLE,1); else - Pre_load(context, info_ptr->width,info_ptr->height,File_length_file(file),FORMAT_PNG,context->Ratio,0); + Pre_load(context,png_get_image_width(png_ptr,info_ptr),png_get_image_height(png_ptr,info_ptr),File_length_file(file),FORMAT_PNG,context->Ratio,0); if (File_error==0) { @@ -3535,8 +3548,8 @@ void Load_PNG(T_IO_Context * context) } } - context->Width=info_ptr->width; - context->Height=info_ptr->height; + context->Width=png_get_image_width(png_ptr,info_ptr); + context->Height=png_get_image_height(png_ptr,info_ptr); png_set_interlace_handling(png_ptr); png_read_update_info(png_ptr, info_ptr); @@ -3556,7 +3569,7 @@ void Load_PNG(T_IO_Context * context) // 8bpp for (y=0; yHeight; y++) - Row_pointers[y] = (png_byte*) malloc(info_ptr->rowbytes); + Row_pointers[y] = (png_byte*) malloc(png_get_rowbytes(png_ptr,info_ptr)); row_pointers_allocated = 1; png_read_image(png_ptr, Row_pointers); @@ -3575,7 +3588,7 @@ void Load_PNG(T_IO_Context * context) // It's a preview // Unfortunately we need to allocate loads of memory for (y=0; yHeight; y++) - Row_pointers[y] = (png_byte*) malloc(info_ptr->rowbytes); + Row_pointers[y] = (png_byte*) malloc(png_get_rowbytes(png_ptr,info_ptr)); row_pointers_allocated = 1; png_read_image(png_ptr, Row_pointers); @@ -3674,9 +3687,15 @@ void Save_PNG(T_IO_Context * context) { // Commentaires texte PNG // Cette partie est optionnelle - png_text text_ptr[2] = { - {-1, "Software", "Grafx2", 6}, - {-1, "Title", NULL, 0} + #ifdef PNG_iTXt_SUPPORTED + png_text text_ptr[2] = { + {-1, "Software", "Grafx2", 6, 0, NULL, NULL}, + {-1, "Title", NULL, 0, 0, NULL, NULL} + #else + png_text text_ptr[2] = { + {-1, "Software", "Grafx2", 6}, + {-1, "Title", NULL, 0} + #endif }; int nb_text_chunks=1; if (context->Comment[0])