Update to fs2_open 3.7.0.
Partial changelog at http://www.hard-light.net/forums/index.php?topic=85435.0
This commit is contained in:
parent
bcf3f5f5d7
commit
d4d8e2f898
7 changed files with 30 additions and 539 deletions
|
@ -1,8 +1,8 @@
|
|||
# $NetBSD: Makefile,v 1.7 2012/11/13 20:41:14 othyro Exp $
|
||||
# $NetBSD: Makefile,v 1.8 2013/09/08 20:21:09 yhardy Exp $
|
||||
#
|
||||
|
||||
PKGNAME= fs2_open-3.6.12
|
||||
DISTNAME= fs2_open_3_6_12_src
|
||||
PKGNAME= fs2_open-3.7.0
|
||||
DISTNAME= fs2_open_3_7_0_src
|
||||
CATEGORIES= games
|
||||
MASTER_SITES= http://swc.fs2downloads.com/builds/
|
||||
EXTRACT_SUFX= .tgz
|
||||
|
@ -11,9 +11,11 @@ MAINTAINER= pkgsrc-users@NetBSD.org
|
|||
HOMEPAGE= http://scp.indiegames.us/
|
||||
COMMENT= Freespace 2 source code project
|
||||
|
||||
WRKSRC= ${WRKDIR}/fs2_open_3_7_0
|
||||
|
||||
GNU_CONFIGURE= yes
|
||||
USE_LANGUAGES= c c++
|
||||
USE_TOOLS+= aclocal autoconf automake
|
||||
USE_TOOLS+= aclocal autoconf automake pkg-config
|
||||
|
||||
INSTALLATION_DIRS= bin
|
||||
|
||||
|
@ -22,7 +24,7 @@ pre-configure:
|
|||
aclocal; automake -a --foreign -i; autoconf
|
||||
|
||||
do-install:
|
||||
${INSTALL_PROGRAM} ${WRKSRC}/code/fs2_open_r ${DESTDIR}${PREFIX}/bin/fs2_open
|
||||
${INSTALL_PROGRAM} ${WRKSRC}/code/fs2_open_3.7.0 ${DESTDIR}${PREFIX}/bin/fs2_open
|
||||
|
||||
.include "../../audio/libvorbis/buildlink3.mk"
|
||||
.include "../../audio/openal/buildlink3.mk"
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
$NetBSD: distinfo,v 1.4 2011/08/04 05:12:18 yhardy Exp $
|
||||
$NetBSD: distinfo,v 1.5 2013/09/08 20:21:09 yhardy Exp $
|
||||
|
||||
SHA1 (fs2_open_3_6_12_src.tgz) = cc051fb95f36417b99aa7e6c34b8dc4b6a9669c2
|
||||
RMD160 (fs2_open_3_6_12_src.tgz) = 1842a4efe1517ac0298bb0f5b5db89330c623b78
|
||||
Size (fs2_open_3_6_12_src.tgz) = 7416654 bytes
|
||||
SHA1 (patch-aa) = bb3dbca3d892b46ab7fcfaf2d20ea7e1e567c691
|
||||
SHA1 (fs2_open_3_7_0_src.tgz) = 44fc74780d04a25925e3a2c734bb4a9778ae9fda
|
||||
RMD160 (fs2_open_3_7_0_src.tgz) = 65a16cf8b96c9c87fb78f3d12a4f51602c14ac31
|
||||
Size (fs2_open_3_7_0_src.tgz) = 9368939 bytes
|
||||
SHA1 (patch-aa) = 4991706153d66f1073022f8b55e4b7daa7d50450
|
||||
SHA1 (patch-ab) = 4918aa3c488d11fa1132b1659bb7931ddf61669e
|
||||
SHA1 (patch-ac) = df7e619c2b8dfef70090149206e64f7b0db35a5f
|
||||
SHA1 (patch-ad) = a1c99397bd934224abb8466bbe2bf165a8b7401a
|
||||
SHA1 (patch-ae) = 276293d4fb38e4c7042bff30be83f1da1c597516
|
||||
SHA1 (patch-af) = 940f4d3f2c7277501b3711219c15e049d10a9b2a
|
||||
|
|
|
@ -1,35 +1,23 @@
|
|||
$NetBSD: patch-aa,v 1.3 2010/11/17 08:03:41 yhardy Exp $
|
||||
$NetBSD: patch-aa,v 1.4 2013/09/08 20:21:09 yhardy Exp $
|
||||
|
||||
--- ./configure.ac.orig 2010-07-01 17:51:52.000000000 +0200
|
||||
+++ ./configure.ac 2010-11-16 11:53:26.000000000 +0200
|
||||
@@ -155,6 +155,21 @@
|
||||
D_LDFLAGS="$D_LDFLAGS -lobjc -fPIC -Wl,-noprebind"
|
||||
D_CFLAGS="$D_CFLAGS -DLUA_USE_MACOSX"
|
||||
--- configure.ac.orig 2013-09-01 03:48:53.000000000 +0200
|
||||
+++ configure.ac 2013-09-08 21:33:47.000000000 +0200
|
||||
@@ -164,6 +164,18 @@
|
||||
LDFLAGS="$LDFLAGS -L/usr/local/lib"
|
||||
CPPFLAGS="$CPPFLAGS -I/usr/local/include"
|
||||
;;
|
||||
+ *-*-dragonfly*)
|
||||
+ # dragonfly bsd
|
||||
+ echo "Using Unix defines (for $host_os)"
|
||||
+ fs2_os_unix="yes"
|
||||
+ ;;
|
||||
+ *-*-freebsd*)
|
||||
+ # freebsd
|
||||
+ echo "Using Unix defines (for $host_os)"
|
||||
+ fs2_os_unix="yes"
|
||||
+ ;;
|
||||
+ *-*-netbsd*)
|
||||
+ # netbsd
|
||||
+ echo "Using Unix defines (for $host_os)"
|
||||
+ fs2_os_unix="yes"
|
||||
+ ;;
|
||||
+ *-*-dragonfly*)
|
||||
+ # dragonfly bsd
|
||||
+ echo "Using Unix defines (for $host_os)"
|
||||
+ fs2_os_bsd="yes"
|
||||
+ D_CFLAGS="$D_CFLAGS -DLUA_USE_LINUX"
|
||||
+ ;;
|
||||
+ *-*-netbsd*)
|
||||
+ # netbsd
|
||||
+ echo "Using Unix defines (for $host_os)"
|
||||
+ fs2_os_bsd="yes"
|
||||
+ D_CFLAGS="$D_CFLAGS -DLUA_USE_LINUX"
|
||||
+ ;;
|
||||
*)
|
||||
# Unknown
|
||||
echo "fs2_open does not support $host_cpu-$host_os"
|
||||
@@ -451,7 +466,7 @@
|
||||
|
||||
|
||||
dnl The makefiles we create
|
||||
-AC_OUTPUT([Makefile libjpeg/Makefile lua/Makefile code/Makefile])
|
||||
+AC_OUTPUT([Makefile code/Makefile])
|
||||
|
||||
|
||||
echo
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
$NetBSD: patch-ac,v 1.3 2010/11/17 08:03:41 yhardy Exp $
|
||||
|
||||
--- ./code/jpgutils/jpgutils.cpp.orig 2010-11-16 11:53:45.000000000 +0200
|
||||
+++ ./code/jpgutils/jpgutils.cpp 2010-11-16 11:53:54.000000000 +0200
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <string.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
-#include "../../libjpeg/jpeglib.h"
|
||||
+#include "jpeglib.h"
|
||||
|
||||
#undef LOCAL // fix from a jpeg header, pstypes.h will define it again
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
$NetBSD: patch-ad,v 1.1 2010/11/17 08:03:41 yhardy Exp $
|
||||
|
||||
--- ./code/Makefile.am.orig 2010-11-16 11:49:48.000000000 +0200
|
||||
+++ ./code/Makefile.am 2010-11-16 11:51:23.000000000 +0200
|
||||
@@ -818,10 +818,10 @@
|
||||
fs2_open_INF_r_SOURCES = \
|
||||
${FS2OPEN_SOURCES}
|
||||
|
||||
-fs2_open_d_LDADD = libcode.a ../libjpeg/libjpeg.a ../lua/liblua.a
|
||||
-fs2_open_r_LDADD = libcode.a ../libjpeg/libjpeg.a ../lua/liblua.a
|
||||
-fs2_open_INF_d_LDADD = libcode.a ../libjpeg/libjpeg.a ../lua/liblua.a
|
||||
-fs2_open_INF_r_LDADD = libcode.a ../libjpeg/libjpeg.a ../lua/liblua.a
|
||||
+fs2_open_d_LDADD = libcode.a -ljpeg -llua
|
||||
+fs2_open_r_LDADD = libcode.a -ljpeg -llua
|
||||
+fs2_open_INF_d_LDADD = libcode.a -ljpeg -llua
|
||||
+fs2_open_INF_r_LDADD = libcode.a -ljpeg -llua
|
||||
|
||||
##
|
||||
## End MAIN binary
|
||||
@@ -853,10 +853,10 @@
|
||||
wxFRED2_INF_r_SOURCES = \
|
||||
${wxFRED_SOURCES}
|
||||
|
||||
-wxFRED2_d_LDADD = libcode.a ../libjpeg/libjpeg.a
|
||||
-wxFRED2_r_LDADD = libcode.a ../libjpeg/libjpeg.a
|
||||
-wxFRED2_INF_d_LDADD = libcode.a ../libjpeg/libjpeg.a
|
||||
-wxFRED2_INF_r_LDADD = libcode.a ../libjpeg/libjpeg.a
|
||||
+wxFRED2_d_LDADD = libcode.a -ljpeg
|
||||
+wxFRED2_r_LDADD = libcode.a -ljpeg
|
||||
+wxFRED2_INF_d_LDADD = libcode.a -ljpeg
|
||||
+wxFRED2_INF_r_LDADD = libcode.a -ljpeg
|
||||
|
||||
##
|
||||
## End wxFRED2 binary
|
|
@ -1,13 +0,0 @@
|
|||
$NetBSD: patch-ae,v 1.1 2010/11/17 08:03:41 yhardy Exp $
|
||||
|
||||
--- ./Makefile.am.orig 2010-11-16 11:49:41.000000000 +0200
|
||||
+++ ./Makefile.am 2010-11-16 11:50:09.000000000 +0200
|
||||
@@ -2,7 +2,7 @@
|
||||
#
|
||||
# This file uses GNU Automake to generate makefiles
|
||||
|
||||
-SUBDIRS = libjpeg lua code
|
||||
+SUBDIRS = code
|
||||
|
||||
|
||||
EXTRA_DIST = \
|
|
@ -1,435 +0,0 @@
|
|||
$NetBSD: patch-af,v 1.1 2011/08/04 05:12:18 yhardy Exp $
|
||||
|
||||
Patch from fs2open svn revision 7352
|
||||
|
||||
--- code/pngutils/pngutils.cpp 2010/06/17 19:46:46 6221
|
||||
+++ code/pngutils/pngutils.cpp 2011/07/17 05:46:14 7352
|
||||
@@ -1,219 +1,209 @@
|
||||
-#include <stdio.h>
|
||||
-#include <string.h>
|
||||
-
|
||||
-#include "png.h"
|
||||
-
|
||||
-#include "globalincs/pstypes.h"
|
||||
-#include "pngutils/pngutils.h"
|
||||
-#include "cfile/cfile.h"
|
||||
-#include "bmpman/bmpman.h"
|
||||
-#include "palman/palman.h"
|
||||
-#include "graphics/2d.h"
|
||||
-
|
||||
-CFILE *png_file = NULL;
|
||||
-
|
||||
-//copy/pasted from libpng
|
||||
-void png_scp_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
-{
|
||||
- png_size_t check;
|
||||
-
|
||||
- if (png_ptr == NULL)
|
||||
- return;
|
||||
- /* fread() returns 0 on error, so it is OK to store this in a png_size_t
|
||||
- * instead of an int, which is what fread() actually returns.
|
||||
- */
|
||||
- check = (png_size_t)cfread(data, (png_size_t)1, length, png_file);
|
||||
- if (check != length)
|
||||
- png_error(png_ptr, "Read Error");
|
||||
-
|
||||
- /*
|
||||
- //debug for dumping data read
|
||||
- if (length <= 16) {
|
||||
- for(i = 0; i < length; i++)
|
||||
- mprintf(("%02x", data[i]));
|
||||
- mprintf(("\n"));
|
||||
- }
|
||||
- */
|
||||
-}
|
||||
-
|
||||
-// Reads header information from the PNG file into the bitmap pointer
|
||||
-//
|
||||
-// filename - name of the PNG bitmap file
|
||||
-// w - (output) width of the bitmap
|
||||
-// h - (output) height of the bitmap
|
||||
-// bpp - (output) bits per pixel of the bitmap
|
||||
-//
|
||||
-// returns - PNG_ERROR_NONE if successful, otherwise error code
|
||||
-//
|
||||
-int png_read_header(char *real_filename, CFILE *img_cfp, int *w, int *h, int *bpp, ubyte *palette)
|
||||
-{
|
||||
- char filename[MAX_FILENAME_LEN];
|
||||
- png_infop info_ptr;
|
||||
- png_structp png_ptr;
|
||||
-
|
||||
- png_file = NULL;
|
||||
-
|
||||
- //mprintf(("png_read_header: %s\n", real_filename));
|
||||
-
|
||||
- if (img_cfp == NULL) {
|
||||
- strcpy_s( filename, real_filename );
|
||||
-
|
||||
- char *p = strchr( filename, '.' );
|
||||
-
|
||||
- if ( p )
|
||||
- *p = 0;
|
||||
-
|
||||
- strcat_s( filename, ".png" );
|
||||
-
|
||||
- png_file = cfopen( filename , "rb" );
|
||||
-
|
||||
- if ( !png_file ) {
|
||||
- return PNG_ERROR_READING;
|
||||
- }
|
||||
- } else {
|
||||
- png_file = img_cfp;
|
||||
- }
|
||||
-
|
||||
- Assert( png_file != NULL );
|
||||
-
|
||||
- if (png_file == NULL)
|
||||
- return PNG_ERROR_READING;
|
||||
-
|
||||
- /* Create and initialize the png_struct with the desired error handler
|
||||
- * functions. If you want to use the default stderr and longjump method,
|
||||
- * you can supply NULL for the last three parameters. We also supply the
|
||||
- * the compiler header file version, so that we know if the application
|
||||
- * was compiled with a compatible version of the library. REQUIRED
|
||||
- */
|
||||
- png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
-
|
||||
- if (png_ptr == NULL)
|
||||
- {
|
||||
- mprintf(("png_read_header: error creating read struct\n"));
|
||||
- cfclose(png_file);
|
||||
- return PNG_ERROR_READING;
|
||||
- }
|
||||
-
|
||||
- /* Allocate/initialize the memory for image information. REQUIRED. */
|
||||
- info_ptr = png_create_info_struct(png_ptr);
|
||||
- if (info_ptr == NULL)
|
||||
- {
|
||||
- mprintf(("png_read_header: error creating info struct\n"));
|
||||
- cfclose(png_file);
|
||||
- png_destroy_read_struct(&png_ptr, NULL, NULL);
|
||||
- return PNG_ERROR_READING;
|
||||
- }
|
||||
-
|
||||
- if (setjmp(png_jmpbuf(png_ptr)))
|
||||
- {
|
||||
- mprintf(("png_read_header: something went wrong\n"));
|
||||
- /* Free all of the memory associated with the png_ptr and info_ptr */
|
||||
- png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
- cfclose(png_file);
|
||||
- /* If we get here, we had a problem reading the file */
|
||||
- return PNG_ERROR_READING;
|
||||
- }
|
||||
-
|
||||
- png_set_read_fn(png_ptr, &png_file, png_scp_read_data);
|
||||
-
|
||||
- png_read_info(png_ptr, info_ptr);
|
||||
-
|
||||
- if (w) *w = info_ptr->width;
|
||||
- if (h) *h = info_ptr->height;
|
||||
- //this turns out to be near useless, but meh
|
||||
- if (bpp) *bpp = (info_ptr->pixel_depth);
|
||||
-
|
||||
- if (img_cfp == NULL) {
|
||||
- cfclose(png_file);
|
||||
- png_file = NULL;
|
||||
- }
|
||||
-
|
||||
- png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
-
|
||||
- return PNG_ERROR_NONE;
|
||||
-}
|
||||
-
|
||||
-// Loads a PNG image
|
||||
-//
|
||||
-// filename - name of the targa file to load
|
||||
-// image_data - allocated storage for the bitmap
|
||||
-//
|
||||
-// returns - true if succesful, false otherwise
|
||||
-//
|
||||
-int png_read_bitmap(char *real_filename, ubyte *image_data, ubyte *bpp, int dest_size, int cf_type)
|
||||
-{
|
||||
- char filename[MAX_FILENAME_LEN];
|
||||
- png_infop info_ptr;
|
||||
- png_structp png_ptr;
|
||||
- png_bytepp row_pointers;
|
||||
- unsigned int i, len;
|
||||
-
|
||||
- png_file = NULL;
|
||||
-
|
||||
- //mprintf(("png_read_bitmap: %s\n", real_filename));
|
||||
-
|
||||
- strcpy_s( filename, real_filename );
|
||||
- char *p = strchr( filename, '.' );
|
||||
- if ( p ) *p = 0;
|
||||
- strcat_s( filename, ".png" );
|
||||
-
|
||||
- png_file = cfopen(filename, "rb", CFILE_NORMAL, cf_type);
|
||||
-
|
||||
- if (png_file == NULL)
|
||||
- return PNG_ERROR_READING;
|
||||
-
|
||||
- /* Create and initialize the png_struct with the desired error handler
|
||||
- * functions. If you want to use the default stderr and longjump method,
|
||||
- * you can supply NULL for the last three parameters. We also supply the
|
||||
- * the compiler header file version, so that we know if the application
|
||||
- * was compiled with a compatible version of the library. REQUIRED
|
||||
- */
|
||||
- png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
-
|
||||
- if (png_ptr == NULL)
|
||||
- {
|
||||
- mprintf(("png_read_bitmap: png_ptr went wrong\n"));
|
||||
- cfclose(png_file);
|
||||
- return PNG_ERROR_READING;
|
||||
- }
|
||||
-
|
||||
- /* Allocate/initialize the memory for image information. REQUIRED. */
|
||||
- info_ptr = png_create_info_struct(png_ptr);
|
||||
- if (info_ptr == NULL)
|
||||
- {
|
||||
- mprintf(("png_read_bitmap: info_ptr went wrong\n"));
|
||||
- cfclose(png_file);
|
||||
- png_destroy_read_struct(&png_ptr, NULL, NULL);
|
||||
- return PNG_ERROR_READING;
|
||||
- }
|
||||
-
|
||||
- if (setjmp(png_jmpbuf(png_ptr)))
|
||||
- {
|
||||
- mprintf(("png_read_bitmap: something went wrong\n"));
|
||||
- /* Free all of the memory associated with the png_ptr and info_ptr */
|
||||
- png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
- cfclose(png_file);
|
||||
- /* If we get here, we had a problem reading the file */
|
||||
- return PNG_ERROR_READING;
|
||||
- }
|
||||
-
|
||||
- png_set_read_fn(png_ptr, &png_file, png_scp_read_data);
|
||||
-
|
||||
- png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_BGR | PNG_TRANSFORM_EXPAND, NULL);
|
||||
- len = png_get_rowbytes(png_ptr, info_ptr);
|
||||
-
|
||||
- row_pointers = png_get_rows(png_ptr, info_ptr);
|
||||
-
|
||||
- if(bpp)
|
||||
- *bpp = (ubyte)(len / info_ptr->width) << 3;
|
||||
-
|
||||
- //copy row data to image
|
||||
- for(i = 0; i < info_ptr->height; i++) {
|
||||
- memcpy(&image_data[i * len], row_pointers[i], len);
|
||||
- }
|
||||
-
|
||||
- png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
- cfclose(png_file);
|
||||
-
|
||||
- return PNG_ERROR_NONE;
|
||||
-}
|
||||
+#include <stdio.h>
|
||||
+#include <string.h>
|
||||
+
|
||||
+#include "png.h"
|
||||
+
|
||||
+#include "globalincs/pstypes.h"
|
||||
+#include "pngutils/pngutils.h"
|
||||
+#include "cfile/cfile.h"
|
||||
+#include "bmpman/bmpman.h"
|
||||
+#include "palman/palman.h"
|
||||
+#include "graphics/2d.h"
|
||||
+
|
||||
+CFILE *png_file = NULL;
|
||||
+
|
||||
+//copy/pasted from libpng
|
||||
+void png_scp_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
|
||||
+{
|
||||
+ png_size_t check;
|
||||
+
|
||||
+ if (png_ptr == NULL)
|
||||
+ return;
|
||||
+ /* fread() returns 0 on error, so it is OK to store this in a png_size_t
|
||||
+ * instead of an int, which is what fread() actually returns.
|
||||
+ */
|
||||
+ check = (png_size_t)cfread(data, (png_size_t)1, length, png_file);
|
||||
+ if (check != length)
|
||||
+ png_error(png_ptr, "Read Error");
|
||||
+}
|
||||
+
|
||||
+// Reads header information from the PNG file into the bitmap pointer
|
||||
+//
|
||||
+// filename - name of the PNG bitmap file
|
||||
+// w - (output) width of the bitmap
|
||||
+// h - (output) height of the bitmap
|
||||
+// bpp - (output) bits per pixel of the bitmap
|
||||
+//
|
||||
+// returns - PNG_ERROR_NONE if successful, otherwise error code
|
||||
+//
|
||||
+int png_read_header(char *real_filename, CFILE *img_cfp, int *w, int *h, int *bpp, ubyte *palette)
|
||||
+{
|
||||
+ char filename[MAX_FILENAME_LEN];
|
||||
+ png_infop info_ptr;
|
||||
+ png_structp png_ptr;
|
||||
+
|
||||
+ png_file = NULL;
|
||||
+
|
||||
+ //mprintf(("png_read_header: %s\n", real_filename));
|
||||
+
|
||||
+ if (img_cfp == NULL) {
|
||||
+ strcpy_s( filename, real_filename );
|
||||
+
|
||||
+ char *p = strchr( filename, '.' );
|
||||
+
|
||||
+ if ( p )
|
||||
+ *p = 0;
|
||||
+
|
||||
+ strcat_s( filename, ".png" );
|
||||
+
|
||||
+ png_file = cfopen( filename , "rb" );
|
||||
+
|
||||
+ if ( !png_file ) {
|
||||
+ return PNG_ERROR_READING;
|
||||
+ }
|
||||
+ } else {
|
||||
+ png_file = img_cfp;
|
||||
+ }
|
||||
+
|
||||
+ Assert( png_file != NULL );
|
||||
+
|
||||
+ if (png_file == NULL)
|
||||
+ return PNG_ERROR_READING;
|
||||
+
|
||||
+ /* Create and initialize the png_struct with the desired error handler
|
||||
+ * functions. If you want to use the default stderr and longjump method,
|
||||
+ * you can supply NULL for the last three parameters. We also supply the
|
||||
+ * the compiler header file version, so that we know if the application
|
||||
+ * was compiled with a compatible version of the library. REQUIRED
|
||||
+ */
|
||||
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
+
|
||||
+ if (png_ptr == NULL)
|
||||
+ {
|
||||
+ mprintf(("png_read_header: error creating read struct\n"));
|
||||
+ cfclose(png_file);
|
||||
+ return PNG_ERROR_READING;
|
||||
+ }
|
||||
+
|
||||
+ /* Allocate/initialize the memory for image information. REQUIRED. */
|
||||
+ info_ptr = png_create_info_struct(png_ptr);
|
||||
+ if (info_ptr == NULL)
|
||||
+ {
|
||||
+ mprintf(("png_read_header: error creating info struct\n"));
|
||||
+ cfclose(png_file);
|
||||
+ png_destroy_read_struct(&png_ptr, NULL, NULL);
|
||||
+ return PNG_ERROR_READING;
|
||||
+ }
|
||||
+
|
||||
+ if (setjmp(png_jmpbuf(png_ptr)))
|
||||
+ {
|
||||
+ mprintf(("png_read_header: something went wrong\n"));
|
||||
+ /* Free all of the memory associated with the png_ptr and info_ptr */
|
||||
+ png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
+ cfclose(png_file);
|
||||
+ /* If we get here, we had a problem reading the file */
|
||||
+ return PNG_ERROR_READING;
|
||||
+ }
|
||||
+
|
||||
+ png_set_read_fn(png_ptr, &png_file, png_scp_read_data);
|
||||
+
|
||||
+ png_read_info(png_ptr, info_ptr);
|
||||
+
|
||||
+ if (w) *w = png_get_image_width(png_ptr, info_ptr);
|
||||
+ if (h) *h = png_get_image_height(png_ptr, info_ptr);
|
||||
+ // this turns out to be near useless, but meh
|
||||
+ if (bpp) *bpp = (png_get_channels(png_ptr, info_ptr) * png_get_bit_depth(png_ptr, info_ptr));
|
||||
+
|
||||
+ if (img_cfp == NULL) {
|
||||
+ cfclose(png_file);
|
||||
+ png_file = NULL;
|
||||
+ }
|
||||
+
|
||||
+ png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
+
|
||||
+ return PNG_ERROR_NONE;
|
||||
+}
|
||||
+
|
||||
+// Loads a PNG image
|
||||
+//
|
||||
+// filename - name of the targa file to load
|
||||
+// image_data - allocated storage for the bitmap
|
||||
+//
|
||||
+// returns - true if succesful, false otherwise
|
||||
+//
|
||||
+int png_read_bitmap(char *real_filename, ubyte *image_data, ubyte *bpp, int dest_size, int cf_type)
|
||||
+{
|
||||
+ char filename[MAX_FILENAME_LEN];
|
||||
+ png_infop info_ptr;
|
||||
+ png_structp png_ptr;
|
||||
+ png_bytepp row_pointers;
|
||||
+ unsigned int i, len;
|
||||
+
|
||||
+ png_file = NULL;
|
||||
+
|
||||
+ strcpy_s( filename, real_filename );
|
||||
+ char *p = strchr( filename, '.' );
|
||||
+ if ( p ) *p = 0;
|
||||
+ strcat_s( filename, ".png" );
|
||||
+
|
||||
+ png_file = cfopen(filename, "rb", CFILE_NORMAL, cf_type);
|
||||
+
|
||||
+ if (png_file == NULL)
|
||||
+ return PNG_ERROR_READING;
|
||||
+
|
||||
+ /* Create and initialize the png_struct with the desired error handler
|
||||
+ * functions. If you want to use the default stderr and longjump method,
|
||||
+ * you can supply NULL for the last three parameters. We also supply the
|
||||
+ * the compiler header file version, so that we know if the application
|
||||
+ * was compiled with a compatible version of the library. REQUIRED
|
||||
+ */
|
||||
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
+
|
||||
+ if (png_ptr == NULL)
|
||||
+ {
|
||||
+ mprintf(("png_read_bitmap: png_ptr went wrong\n"));
|
||||
+ cfclose(png_file);
|
||||
+ return PNG_ERROR_READING;
|
||||
+ }
|
||||
+
|
||||
+ /* Allocate/initialize the memory for image information. REQUIRED. */
|
||||
+ info_ptr = png_create_info_struct(png_ptr);
|
||||
+ if (info_ptr == NULL)
|
||||
+ {
|
||||
+ mprintf(("png_read_bitmap: info_ptr went wrong\n"));
|
||||
+ cfclose(png_file);
|
||||
+ png_destroy_read_struct(&png_ptr, NULL, NULL);
|
||||
+ return PNG_ERROR_READING;
|
||||
+ }
|
||||
+
|
||||
+ if (setjmp(png_jmpbuf(png_ptr)))
|
||||
+ {
|
||||
+ mprintf(("png_read_bitmap: something went wrong\n"));
|
||||
+ /* Free all of the memory associated with the png_ptr and info_ptr */
|
||||
+ png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
+ cfclose(png_file);
|
||||
+ /* If we get here, we had a problem reading the file */
|
||||
+ return PNG_ERROR_READING;
|
||||
+ }
|
||||
+
|
||||
+ png_set_read_fn(png_ptr, &png_file, png_scp_read_data);
|
||||
+
|
||||
+ png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_BGR | PNG_TRANSFORM_EXPAND, NULL);
|
||||
+ len = png_get_rowbytes(png_ptr, info_ptr);
|
||||
+
|
||||
+ row_pointers = png_get_rows(png_ptr, info_ptr);
|
||||
+
|
||||
+ if(bpp)
|
||||
+ *bpp = (ubyte)(len / png_get_image_width(png_ptr, info_ptr)) << 3;
|
||||
+
|
||||
+ //copy row data to image
|
||||
+ unsigned int height = png_get_image_height(png_ptr, info_ptr);
|
||||
+ for (i = 0; i < height; i++) {
|
||||
+ memcpy(&image_data[i * len], row_pointers[i], len);
|
||||
+ }
|
||||
+
|
||||
+ png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
+ cfclose(png_file);
|
||||
+
|
||||
+ return PNG_ERROR_NONE;
|
||||
+}
|
Loading…
Reference in a new issue