From a0875ea9091f08bb30fb8c693e8a35ba55aace44 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 4 Sep 2003 21:24:20 +0000 Subject: [PATCH] eliminate the global variables --- libs/image/png.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/libs/image/png.c b/libs/image/png.c index 48246108e..d71549c57 100644 --- a/libs/image/png.c +++ b/libs/image/png.c @@ -54,21 +54,16 @@ typedef unsigned char uch; typedef unsigned short ush; typedef unsigned long ulg; -static png_structp png_ptr = NULL; -static png_infop info_ptr = NULL; -static QFile *pngfile = NULL; - -char tmpBuffer[8192]; - /* Qread wrapper for libpng */ static void -user_read_data (png_structp png_ptr, png_bytep data, png_size_t length) { - Qread (pngfile, data, length); +user_read_data (png_structp png_ptr, png_bytep data, png_size_t length) +{ + Qread ((QFile *) png_get_io_ptr (png_ptr), data, length); } /* Basicly taken from the libpng example rpng-x */ static int -readpng_init (QFile *infile) +readpng_init (QFile *infile, png_structp *png_ptr, png_infop *info_ptr) { uch sig[8]; @@ -79,31 +74,30 @@ readpng_init (QFile *infile) return (1); } - png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - if (!png_ptr) + *png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!*png_ptr) return (2); /* Out of memory! */ - info_ptr = png_create_info_struct (png_ptr); - if (!info_ptr) { - png_destroy_read_struct (&png_ptr, NULL, NULL); + *info_ptr = png_create_info_struct (*png_ptr); + if (!*info_ptr) { + png_destroy_read_struct (png_ptr, NULL, NULL); return (3); /* Out of memory! */ } /* setjmp() must be called in every function that calls a PNG-reading * libpng function */ - if (setjmp(png_jmpbuf(png_ptr))) { - png_destroy_read_struct (&png_ptr, &info_ptr, NULL); + if (setjmp(png_jmpbuf(*png_ptr))) { + png_destroy_read_struct (png_ptr, info_ptr, NULL); return (4); } - pngfile = infile; - png_set_read_fn (png_ptr, tmpBuffer, user_read_data); + png_set_read_fn (*png_ptr, infile, user_read_data); /* Is png_set_sig_bytes needed? */ - png_set_sig_bytes (png_ptr, 8); /* We allready read the 8 signiture bytes */ + png_set_sig_bytes (*png_ptr, 8); // We allready read the 8 signiture bytes - png_read_info (png_ptr, info_ptr); /* read all png info upto the image data */ + png_read_info (*png_ptr, *info_ptr);//read all png info upto the image data return (0); } @@ -113,13 +107,15 @@ tex_t * LoadPNG (QFile *infile) { double gamma; + png_structp png_ptr = NULL; + png_infop info_ptr = NULL; png_uint_32 i, rowbytes; png_bytepp row_pointers = NULL; png_uint_32 width, height; int bit_depth, color_type; tex_t *tex; - if (readpng_init(infile) != 0) + if (readpng_init(infile, &png_ptr, &info_ptr) != 0) return (NULL); png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, NULL, NULL, NULL);