$NetBSD: patch-ai,v 1.1 2006/04/19 19:21:28 wiz Exp $ --- src/readPNG.c.orig 2000-12-08 19:00:45.000000000 +0100 +++ src/readPNG.c @@ -35,8 +35,8 @@ unsigned char * ReadPNG(FILE *infile,int unsigned char *pixmap; unsigned char *p; png_byte *q; - png_struct *png_ptr; - png_info *info_ptr; + png_structp png_ptr; + png_infop info_ptr; double screen_gamma; png_byte *png_pixels=NULL, **row_pointers=NULL; int i, j; @@ -60,14 +60,16 @@ unsigned char * ReadPNG(FILE *infile,int rewind(infile); /* allocate the structures */ - png_ptr = (png_struct *)calloc(1,sizeof(png_struct)); - if(!png_ptr) - return 0; - - info_ptr = (png_info *)calloc(1,sizeof(png_info)); - if(!info_ptr) { - free(png_ptr); - return 0; + png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, + NULL, NULL, NULL); + if (!png_ptr) + return (0); + + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) { + png_destroy_read_struct(&png_ptr, (png_infopp)NULL, + (png_infopp)NULL); + return (0); } /* Establish the setjmp return context for png_error to use. */ @@ -76,24 +78,18 @@ unsigned char * ReadPNG(FILE *infile,int if (mMosaicSrcTrace) { fprintf(stderr, "\n!!!libpng read error!!!\n"); } - png_read_destroy(png_ptr, info_ptr, (png_info *)0); + png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); if(png_pixels != NULL) free((char *)png_pixels); if(row_pointers != NULL) free((png_byte **)row_pointers); - free((char *)png_ptr); - free((char *)info_ptr); return 0; } /* SWP -- Hopefully to fix cores on bad PNG files */ /*####png_set_message_fn(png_ptr,png_get_msg_ptr(png_ptr),NULL,NULL); */ - /* initialize the structures */ - png_info_init(info_ptr); - png_read_init(png_ptr); - /* set up the input control */ png_init_io(png_ptr, infile); @@ -283,10 +279,7 @@ pixmap, since I don't do anything with i } free((png_byte **)row_pointers); /* clean up after the read, and free any memory allocated */ - png_read_destroy(png_ptr, info_ptr, (png_info *)0); -/* free the structures */ - free((char *)png_ptr); - free((char *)info_ptr); + png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL); return pixmap; } #endif