File vulture-png15.patch of Package vultures
--- vulture-2.3.67.orig/vulture/vulture_gfl.cpp 2011-04-04 20:23:52.000000000 +0200
+++ vulture-2.3.67/vulture/vulture_gfl.cpp 2013-01-08 23:07:13.000000000 +0100
@@ -21,12 +21,25 @@
#define PNG_BYTES_TO_CHECK 4
+#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 4
+struct readbuff {char *buff; unsigned int len;};
+#endif
static void vulture_png_read_callback(png_structp png_ptr, png_bytep area, png_size_t size)
{
+#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 4
+ unsigned int readlen;
+ struct readbuff *readfrom = (struct readbuff *)png_get_io_ptr(png_ptr);
+ readlen = (readfrom->len > size) ? size : readfrom->len;
+ memcpy(area, readfrom->buff, readlen);
+ size = readlen;
+ readfrom->len -= readlen;
+ readfrom->buff += readlen;
+#else
char *mem = (char *)png_ptr->io_ptr;
memcpy(area, mem, size);
png_ptr->io_ptr = (mem + size);
+#endif
}
/*--------------------------------------------------------------------------
@@ -44,6 +57,9 @@
int bit_depth, color_type, row;
png_bytep * row_pointers = NULL;
SDL_Surface *img, *convert;
+#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 4
+ struct readbuff readfrom;
+#endif
/* vulture_load_surface converts everything to screen format for faster blitting
* so we can't continue if we don't have a screen yet */
@@ -54,6 +70,11 @@
if (!srcbuf)
return NULL;
+#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 4
+ if (buflen < PNG_BYTES_TO_CHECK)
+ return NULL;
+#endif
+
img = NULL;
/* memory region must contain a png file */
@@ -71,10 +92,21 @@
goto out;
/* Set up error handling */
+#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 4
+ if (setjmp(png_jmpbuf(png_ptr)))
+#else
if (setjmp(png_ptr->jmpbuf))
+#endif
goto out;
+#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 4
+ readfrom.buff = (char *)srcbuf;
+ readfrom.len = buflen;
+
+ png_set_read_fn(png_ptr, &readfrom, vulture_png_read_callback);
+#else
png_set_read_fn(png_ptr, (char *)srcbuf, vulture_png_read_callback);
+#endif
/* Read PNG header info */
png_read_info(png_ptr, info_ptr);
@@ -93,7 +125,14 @@
/* add an opaque alpha channel to anything that doesn't have one yet */
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
+#if PNG_LIBPNG_VER_MAJOR >= 1 && PNG_LIBPNG_VER_MINOR >= 4
+ if (png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_RGB ||
+ png_get_color_type(png_ptr, info_ptr) == PNG_COLOR_TYPE_GRAY)
+ png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER);
+#else
+ png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
+#endif
/* get the component mask for the surface */
if ( SDL_BYTEORDER == SDL_LIL_ENDIAN )