Properly support png15

Obtained from:	Fedora
This commit is contained in:
Antoine Brodin 2014-12-24 11:46:53 +00:00
parent 41ea03c24c
commit cacce64a6c
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=375430
2 changed files with 55 additions and 22 deletions

View file

@ -13,7 +13,7 @@ COMMENT= Shufflepuck Cafe Clone
LICENSE= GPLv2
LIB_DEPENDS= libjpeg.so:${PORTSDIR}/graphics/jpeg \
libpng15.so:${PORTSDIR}/graphics/png \
libpng.so:${PORTSDIR}/graphics/png \
libvorbis.so:${PORTSDIR}/audio/libvorbis \
libfreetype.so:${PORTSDIR}/print/freetype2

View file

@ -1,18 +1,6 @@
--- png.c.orig 2002-11-08 11:50:29.000000000 +0100
+++ png.c 2012-04-30 06:40:16.000000000 +0200
@@ -10,9 +10,10 @@
#define MACOS
#endif
#include <png.h>
+#include <pngpriv.h>
/* png code */
-static void png_read_data(png_structp ctx, png_bytep area, png_size_t size)
+static void local_png_read_data(png_structp ctx, png_bytep area, png_size_t size)
{
SDL_RWops *src;
@@ -74,13 +75,13 @@
--- png.c.orig 2002-11-08 10:50:29 UTC
+++ png.c
@@ -74,7 +74,7 @@ SDL_Surface *loadPNG(Uint8 * data, Uint3
* the normal method of doing things with libpng). REQUIRED unless you
* set up your own error handlers in png_create_read_struct() earlier.
*/
@ -21,10 +9,55 @@
SDL_SetError("Error reading the PNG file.");
goto done;
}
@@ -142,9 +142,9 @@ SDL_Surface *loadPNG(Uint8 * data, Uint3
Rmask = 0x000000FF;
Gmask = 0x0000FF00;
Bmask = 0x00FF0000;
- Amask = (info_ptr->channels == 4) ? 0xFF000000 : 0;
+ Amask = (png_get_channels(png_ptr, info_ptr) == 4) ? 0xFF000000 : 0;
} else {
- int s = (info_ptr->channels == 4) ? 0 : 8;
+ int s = (png_get_channels(png_ptr, info_ptr) == 4) ? 0 : 8;
Rmask = 0xFF000000 >> s;
Gmask = 0x00FF0000 >> s;
Bmask = 0x0000FF00 >> s;
@@ -152,7 +152,7 @@ SDL_Surface *loadPNG(Uint8 * data, Uint3
}
}
surface = SDL_AllocSurface(SDL_SWSURFACE, width, height,
- bit_depth * info_ptr->channels, Rmask, Gmask,
+ bit_depth * png_get_channels(png_ptr, info_ptr), Rmask, Gmask,
Bmask, Amask);
if (surface == NULL) {
SDL_SetError("Out of memory");
@@ -188,6 +188,11 @@ SDL_Surface *loadPNG(Uint8 * data, Uint3
png_read_end(png_ptr, info_ptr);
/* Set up the input control */
- png_set_read_fn(png_ptr, src, png_read_data);
+ png_set_read_fn(png_ptr, src, local_png_read_data);
/* Read PNG header info */
png_read_info(png_ptr, info_ptr);
/* Load the palette, if any */
+
+ png_uint_32 pnum_palette;
+ png_colorp ppalette;
+ png_get_PLTE(png_ptr, info_ptr, &ppalette, &pnum_palette);
+
palette = surface->format->palette;
if (palette) {
if (color_type == PNG_COLOR_TYPE_GRAY) {
@@ -197,12 +202,12 @@ SDL_Surface *loadPNG(Uint8 * data, Uint3
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; i < info_ptr->num_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 ( pnum_palette > 0) {
+ palette->ncolors = pnum_palette;
+ for (i = 0; i < pnum_palette; ++i) {
+ palette->colors[i].b = ppalette[i].blue;
+ palette->colors[i].g = ppalette[i].green;
+ palette->colors[i].r = ppalette[i].red;
}
}
}