Index: SDL_image-1.2.10/IMG_png.c =================================================================== --- SDL_image-1.2.10.orig/IMG_png.c +++ SDL_image-1.2.10/IMG_png.c @@ -80,8 +80,6 @@ static struct { void (*png_destroy_read_struct) (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr); png_uint_32 (*png_get_IHDR) (png_structp png_ptr, png_infop info_ptr, png_uint_32 *width, png_uint_32 *height, int *bit_depth, int *color_type, int *interlace_method, int *compression_method, int *filter_method); png_voidp (*png_get_io_ptr) (png_structp png_ptr); - png_uint_32 (*png_get_tRNS) (png_structp png_ptr, png_infop info_ptr, png_bytep *trans, int *num_trans, png_color_16p *trans_values); - png_uint_32 (*png_get_valid) (png_structp png_ptr, png_infop info_ptr, png_uint_32 flag); void (*png_read_image) (png_structp png_ptr, png_bytepp image); void (*png_read_info) (png_structp png_ptr, png_infop info_ptr); void (*png_read_update_info) (png_structp png_ptr, png_infop info_ptr); @@ -90,7 +88,21 @@ static struct { void (*png_set_packing) (png_structp png_ptr); void (*png_set_read_fn) (png_structp png_ptr, png_voidp io_ptr, png_rw_ptr read_data_fn); void (*png_set_strip_16) (png_structp png_ptr); + jmp_buf * (*png_set_longjmp_fn) (png_structp png_ptr, png_longjmp_ptr longjmp_fn, size_t jmp_buf_size); + +#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 5 + png_uint_32 (*png_get_tRNS) (png_const_structp png_ptr, png_infop info_ptr, png_bytep *trans, int *num_trans, png_color_16p *trans_values); + png_uint_32 (*png_get_valid) (png_const_structp png_ptr, png_const_infop info_ptr, png_uint_32 flag); + int (*png_sig_cmp) (png_const_bytep sig, png_size_t start, png_size_t num_to_check); + png_byte (*png_get_channels) (png_const_structp png_ptr, png_const_infop info_ptr); + png_uint_32 (*png_get_PLTE) (png_const_structp png_ptr, png_const_infop info_ptr, png_colorp *palette, int *num_palette); +#else + png_uint_32 (*png_get_tRNS) (png_structp png_ptr, png_infop info_ptr, png_bytep *trans, int *num_trans, png_color_16p *trans_values); + png_uint_32 (*png_get_valid) (png_structp png_ptr, png_infop info_ptr, png_uint_32 flag); int (*png_sig_cmp) (png_bytep sig, png_size_t start, png_size_t num_to_check); + png_byte (*png_get_channels) (png_structp png_ptr, png_infop info_ptr); + png_uint_32 (*png_get_PLTE) (png_structp png_ptr, png_infop info_ptr, png_colorp *palette, int *num_palette); +#endif } lib; #ifdef LOAD_PNG_DYNAMIC @@ -136,20 +148,6 @@ int IMG_InitPNG() SDL_UnloadObject(lib.handle); return -1; } - lib.png_get_tRNS = - (png_uint_32 (*) (png_structp, png_infop, png_bytep *, int *, png_color_16p *)) - SDL_LoadFunction(lib.handle, "png_get_tRNS"); - if ( lib.png_get_tRNS == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } - lib.png_get_valid = - (png_uint_32 (*) (png_structp, png_infop, png_uint_32)) - SDL_LoadFunction(lib.handle, "png_get_valid"); - if ( lib.png_get_valid == NULL ) { - SDL_UnloadObject(lib.handle); - return -1; - } lib.png_read_image = (void (*) (png_structp, png_bytepp)) SDL_LoadFunction(lib.handle, "png_read_image"); @@ -206,6 +204,64 @@ int IMG_InitPNG() SDL_UnloadObject(lib.handle); return -1; } + lib.png_set_longjmp_fn = + (jmp_buf * (*) (png_structp png_ptr, png_longjmp_ptr longjmp_fn, size_t jmp_buf_size)) + SDL_LoadFunction(lib.handle, "png_set_longjmp_fn"); + if ( lib.png_set_longjmp_fn == NULL ) { + SDL_UnloadObject(lib.handle); + return -1; + } +#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 5 + lib.png_get_tRNS = + (png_uint_32 (*) (png_const_structp, png_infop, png_bytep *, int *, png_color_16p *)) + SDL_LoadFunction(lib.handle, "png_get_tRNS"); + if ( lib.png_get_tRNS == NULL ) { + SDL_UnloadObject(lib.handle); + return -1; + } + lib.png_get_valid = + (png_uint_32 (*) (png_const_structp, png_const_infop, png_uint_32)) + SDL_LoadFunction(lib.handle, "png_get_valid"); + if ( lib.png_get_valid == NULL ) { + SDL_UnloadObject(lib.handle); + return -1; + } + lib.png_sig_cmp = + (int (*) (png_const_bytep, png_size_t, png_size_t)) + SDL_LoadFunction(lib.handle, "png_sig_cmp"); + if ( lib.png_sig_cmp == NULL ) { + SDL_UnloadObject(lib.handle); + return -1; + } + lib.png_get_channels = + (png_byte (*) (png_const_structp, png_const_infop)) + SDL_LoadFunction(lib.handle, "png_get_channels"); + if ( lib.png_get_channels == NULL ) { + SDL_UnloadObject(lib.handle); + return -1; + } + lib.png_get_PLTE = + (png_uint_32 (*) (png_const_structp png_ptr, png_const_infop info_ptr, png_colorp *palette, int *num_palette)) + SDL_LoadFunction(lib.handle, "png_get_PLTE"); + if ( lib.png_get_PLTE == NULL ) { + SDL_UnloadObject(lib.handle); + return -1; + } +#else + lib.png_get_tRNS = + (png_uint_32 (*) (png_structp, png_infop, png_bytep *, int *, png_color_16p *)) + SDL_LoadFunction(lib.handle, "png_get_tRNS"); + if ( lib.png_get_tRNS == NULL ) { + SDL_UnloadObject(lib.handle); + return -1; + } + lib.png_get_valid = + (png_uint_32 (*) (png_structp, png_infop, png_uint_32)) + SDL_LoadFunction(lib.handle, "png_get_valid"); + if ( lib.png_get_valid == NULL ) { + SDL_UnloadObject(lib.handle); + return -1; + } lib.png_sig_cmp = (int (*) (png_bytep, png_size_t, png_size_t)) SDL_LoadFunction(lib.handle, "png_sig_cmp"); @@ -213,6 +269,21 @@ int IMG_InitPNG() SDL_UnloadObject(lib.handle); return -1; } + lib.png_get_channels = + (png_byte (*) (png_structp, png_infop)) + SDL_LoadFunction(lib.handle, "png_get_channels"); + if ( lib.png_get_channels == NULL ) { + SDL_UnloadObject(lib.handle); + return -1; + } + lib.png_get_PLTE = + (png_uint_32 (*) (png_structp png_ptr, png_infop info_ptr, png_colorp *palette, int *num_palette)) + SDL_LoadFunction(lib.handle, "png_get_PLTE"); + if ( lib.png_get_PLTE == NULL ) { + SDL_UnloadObject(lib.handle); + return -1; + } +#endif } ++lib.loaded; @@ -248,6 +319,9 @@ int IMG_InitPNG() lib.png_set_read_fn = png_set_read_fn; lib.png_set_strip_16 = png_set_strip_16; lib.png_sig_cmp = png_sig_cmp; + lib.png_get_channels = png_get_channels; + lib.png_get_PLTE = png_get_PLTE; + lib.png_set_longjmp_fn = png_set_longjmp_fn; } ++lib.loaded; @@ -303,6 +377,8 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *s png_structp png_ptr; png_infop info_ptr; png_uint_32 width, height; + png_colorp png_palette; + int png_num_palette; int bit_depth, color_type, interlace_type; Uint32 Rmask; Uint32 Gmask; @@ -347,7 +423,7 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *s * the normal method of doing things with libpng). REQUIRED unless you * set up your own error handlers in png_create_read_struct() earlier. */ - if ( setjmp(png_ptr->jmpbuf) ) { + if ( setjmp(*lib.png_set_longjmp_fn(png_ptr, longjmp, sizeof(jmp_buf))) ) { error = "Error reading the PNG file."; goto done; } @@ -416,9 +492,9 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *s Rmask = 0x000000FF; Gmask = 0x0000FF00; Bmask = 0x00FF0000; - Amask = (info_ptr->channels == 4) ? 0xFF000000 : 0; + Amask = (lib.png_get_channels(png_ptr, info_ptr) == 4) ? 0xFF000000 : 0; } else { - int s = (info_ptr->channels == 4) ? 0 : 8; + int s = (lib.png_get_channels(png_ptr, info_ptr) == 4) ? 0 : 8; Rmask = 0xFF000000 >> s; Gmask = 0x00FF0000 >> s; Bmask = 0x0000FF00 >> s; @@ -426,7 +502,7 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *s } } surface = SDL_AllocSurface(SDL_SWSURFACE, width, height, - bit_depth*info_ptr->channels, Rmask,Gmask,Bmask,Amask); + bit_depth*lib.png_get_channels(png_ptr, info_ptr), Rmask,Gmask,Bmask,Amask); if ( surface == NULL ) { error = "Out of memory"; goto done; @@ -467,6 +543,8 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *s /* Load the palette, if any */ palette = surface->format->palette; if ( palette ) { + lib.png_get_PLTE(png_ptr, info_ptr, &png_palette, &png_num_palette); + if(color_type == PNG_COLOR_TYPE_GRAY) { palette->ncolors = 256; for(i = 0; i < 256; i++) { @@ -474,12 +552,12 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *s palette->colors[i].g = i; palette->colors[i].b = i; } - } else if (info_ptr->num_palette > 0 ) { - palette->ncolors = info_ptr->num_palette; - for( i=0; inum_palette; ++i ) { - palette->colors[i].b = info_ptr->palette[i].blue; - palette->colors[i].g = info_ptr->palette[i].green; - palette->colors[i].r = info_ptr->palette[i].red; + } else if (png_num_palette > 0 ) { + palette->ncolors = png_num_palette; + for( i=0; icolors[i].b = png_palette[i].blue; + palette->colors[i].g = png_palette[i].green; + palette->colors[i].r = png_palette[i].red; } } }