diff --git a/README.html b/README.html
index a1ec1de0a..9c8fb43d8 100644
--- a/README.html
+++ b/README.html
@@ -249,7 +249,7 @@ data/widgets/*.xml XML files with dialogs
tinyxml
diff --git a/third_party/loadpng/CHANGES.txt b/third_party/loadpng/CHANGES.txt
index 2ce835bda..bc44d3b6d 100644
--- a/third_party/loadpng/CHANGES.txt
+++ b/third_party/loadpng/CHANGES.txt
@@ -164,6 +164,5 @@
Released: version 1.5.
-------- January 2012 -------
-
-7 David Capello: Updated for libpng 1.5.7
+From December 2007, loadpng lives in the Allegro repository.
+This file is no longer updated.
diff --git a/third_party/loadpng/LICENSE.txt b/third_party/loadpng/LICENSE.txt
new file mode 100644
index 000000000..af62ca56f
--- /dev/null
+++ b/third_party/loadpng/LICENSE.txt
@@ -0,0 +1,21 @@
+Copyright (C) 1999-2012 Peter Wang
+
+This software is provided 'as-is', without any express or implied
+warranty. In no event will the authors be held liable for any damages
+arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose,
+including commercial applications, and to alter it and redistribute it
+freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+
diff --git a/third_party/loadpng/README.txt b/third_party/loadpng/README.txt
index 600581793..be6116ff1 100644
--- a/third_party/loadpng/README.txt
+++ b/third_party/loadpng/README.txt
@@ -4,8 +4,8 @@
This wrapper is mostly a copy and paste job from example.c in the
libpng docs, stripping out the useless transformations and making it
-use Allegro BITMAP and PALETTE structures. It is placed in the public
-domain.
+use Allegro BITMAP and PALETTE structures. It is released under the
+terms of the zlib license. See LICENSE.txt for more information.
Requirements:
diff --git a/third_party/loadpng/loadpng.c b/third_party/loadpng/loadpng.c
index 9a93bbefd..2cc8fe6ff 100644
--- a/third_party/loadpng/loadpng.c
+++ b/third_party/loadpng/loadpng.c
@@ -1,7 +1,5 @@
/* loadpng, Allegro wrapper routines for libpng
* by Peter Wang (tjaden@users.sf.net).
- *
- * This file is hereby placed in the public domain.
*/
@@ -43,6 +41,15 @@ static double get_gamma(void)
+static void user_error_fn(png_structp png_ptr, png_const_charp message)
+{
+ jmp_buf *jmpbuf = (jmp_buf *)png_get_error_ptr(png_ptr);
+ (void)message;
+ longjmp(*jmpbuf, 1);
+}
+
+
+
/* read_data:
* Custom read function to use Allegro packfile routines,
* rather than C streams (so we can read from datafiles!)
@@ -90,7 +97,7 @@ static BITMAP *really_load_png(png_structp png_ptr, png_infop info_ptr, RGB *pal
int tRNS_to_alpha = FALSE;
int number_passes, pass;
- ASSERT(png_ptr && info_ptr && pal);
+ ASSERT(png_ptr && info_ptr);
/* The call to png_read_info() gives us all of the information from the
* PNG file before the first IDAT (image data chunk).
@@ -244,6 +251,7 @@ BITMAP *load_png(AL_CONST char *filename, RGB *pal)
*/
BITMAP *load_png_pf(PACKFILE *fp, RGB *pal)
{
+ jmp_buf jmpbuf;
BITMAP *bmp;
png_structp png_ptr;
png_infop info_ptr;
@@ -273,16 +281,14 @@ BITMAP *load_png_pf(PACKFILE *fp, RGB *pal)
return NULL;
}
- /* Set error handling if you are using the setjmp/longjmp method (this is
- * the normal method of doing things with libpng). REQUIRED unless you
- * set up your own error handlers in the png_create_read_struct() earlier.
- */
- if (setjmp(png_jmpbuf(png_ptr))) {
+ /* Set error handling. */
+ if (setjmp(jmpbuf)) {
/* Free all of the memory associated with the png_ptr and info_ptr */
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
/* If we get here, we had a problem reading the file */
return NULL;
}
+ png_set_error_fn(png_ptr, jmpbuf, user_error_fn, NULL);
/* Use Allegro packfile routines. */
png_set_read_fn(png_ptr, fp, (png_rw_ptr)read_data);
@@ -340,6 +346,7 @@ static int check_if_png_memory(AL_CONST void *buffer)
*/
BITMAP *load_memory_png(AL_CONST void *buffer, int bufsize, RGB *pal)
{
+ jmp_buf jmpbuf;
MEMORY_READER_STATE memory_reader_state;
BITMAP *bmp;
png_structp png_ptr;
@@ -369,16 +376,14 @@ BITMAP *load_memory_png(AL_CONST void *buffer, int bufsize, RGB *pal)
return NULL;
}
- /* Set error handling if you are using the setjmp/longjmp method (this is
- * the normal method of doing things with libpng). REQUIRED unless you
- * set up your own error handlers in the png_create_read_struct() earlier.
- */
- if (setjmp(png_jmpbuf(png_ptr))) {
+ /* Set error handling. */
+ if (setjmp(jmpbuf)) {
/* Free all of the memory associated with the png_ptr and info_ptr */
png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
/* If we get here, we had a problem reading the file */
return NULL;
}
+ png_set_error_fn(png_ptr, jmpbuf, user_error_fn, NULL);
/* Set up the reader state. */
memory_reader_state.buffer = (unsigned char *)buffer;
diff --git a/third_party/loadpng/loadpng.h b/third_party/loadpng/loadpng.h
index ddc70d63c..1099b54fc 100644
--- a/third_party/loadpng/loadpng.h
+++ b/third_party/loadpng/loadpng.h
@@ -1,5 +1,4 @@
/* loadpng.h */
-/* This file is hereby placed in the public domain. */
#ifndef _included_loadpng_h_
#define _included_loadpng_h_
@@ -8,6 +7,25 @@ extern "C" {
#endif
+#if (defined LOADPNG_DYNAMIC) && (defined ALLEGRO_WINDOWS)
+ #ifdef LOADPNG_SRC_BUILD
+ #define _APNG_DLL __declspec(dllexport)
+ #else
+ #define _APNG_DLL __declspec(dllimport)
+ #endif /* ALLEGRO_GL_SRC_BUILD */
+#else
+ #define _APNG_DLL
+#endif /* (defined LOADPNG_DYNAMIC) && (defined ALLEGRO_WINDOWS) */
+
+#define APNG_VAR(type, name) extern _APNG_DLL type name
+
+#if (defined LOADPNG_DYNAMIC) && (defined ALLEGRO_WINDOWS)
+ #define APNG_FUNC(type, name, args) extern _APNG_DLL type __cdecl name args
+#else
+ #define APNG_FUNC(type, name, args) extern type name args
+#endif /* (defined LOADPNG_DYNAMIC) && (defined ALLEGRO_WINDOWS) */
+
+
/* Overkill :-) */
#define LOADPNG_VERSION 1
@@ -27,37 +45,37 @@ extern "C" {
*
* Otherwise, the value of _png_screen_gamma is taken as-is.
*/
-extern double _png_screen_gamma;
+APNG_VAR(double, _png_screen_gamma);
/* Choose zlib compression level for saving file.
* Default is Z_BEST_COMPRESSION.
*/
-extern int _png_compression_level;
+APNG_VAR(int, _png_compression_level);
/* Load a PNG from disk. */
-extern BITMAP *load_png(AL_CONST char *filename, RGB *pal);
+APNG_FUNC(BITMAP *, load_png, (AL_CONST char *filename, RGB *pal));
/* Load a PNG from some place. */
-extern BITMAP *load_png_pf(PACKFILE *fp, RGB *pal);
+APNG_FUNC(BITMAP *, load_png_pf, (PACKFILE *fp, RGB *pal));
/* Load a PNG from memory. */
-extern BITMAP *load_memory_png(AL_CONST void *buffer, int buffer_size, RGB *pal);
+APNG_FUNC(BITMAP *, load_memory_png, (AL_CONST void *buffer, int buffer_size, RGB *pal));
/* Save a bitmap to disk in PNG format. */
-extern int save_png(AL_CONST char *filename, BITMAP *bmp, AL_CONST RGB *pal);
+APNG_FUNC(int, save_png, (AL_CONST char *filename, BITMAP *bmp, AL_CONST RGB *pal));
/* Adds `PNG' to Allegro's internal file type table.
* You can then just use load_bitmap and save_bitmap as usual.
*/
-extern void register_png_file_type(void);
+APNG_FUNC(void, register_png_file_type, (void));
/* Register an datafile type ID with Allegro, so that when an object
* with that type ID is encountered while loading a datafile, that
* object will be loaded as a PNG file.
*/
-extern void register_png_datafile_object(int id);
+APNG_FUNC(void, register_png_datafile_object, (int id));
/* This is supposed to resemble jpgalleg_init in JPGalleg 2.0, just in
* case you are lazier than lazy. It contains these 3 lines of code:
@@ -65,7 +83,7 @@ extern void register_png_datafile_object(int id);
* register_png_file_type();
* return 0;
*/
-extern int loadpng_init(void);
+APNG_FUNC(int, loadpng_init, (void));
#ifdef __cplusplus
diff --git a/third_party/loadpng/regpng.c b/third_party/loadpng/regpng.c
index e861a6c0c..8038b8ef8 100644
--- a/third_party/loadpng/regpng.c
+++ b/third_party/loadpng/regpng.c
@@ -1,7 +1,5 @@
/* loadpng, Allegro wrapper routines for libpng
* by Peter Wang (tjaden@users.sf.net).
- *
- * This file is hereby placed in the public domain.
*/
diff --git a/third_party/loadpng/savepng.c b/third_party/loadpng/savepng.c
index 76eb0969c..3593592e3 100644
--- a/third_party/loadpng/savepng.c
+++ b/third_party/loadpng/savepng.c
@@ -1,17 +1,23 @@
/* loadpng, Allegro wrapper routines for libpng
* by Peter Wang (tjaden@users.sf.net).
- *
- * This file is hereby placed in the public domain.
*/
#include
-#include
#include
#include "loadpng.h"
+static void user_error_fn(png_structp png_ptr, png_const_charp message)
+{
+ jmp_buf *jmpbuf = (jmp_buf *)png_get_error_ptr(png_ptr);
+ (void)message;
+ longjmp(*jmpbuf, 1);
+}
+
+
+
/* write_data:
* Custom write function to use Allegro packfile routines,
* rather than C streams.
@@ -166,6 +172,7 @@ static int save_rgba(png_structp png_ptr, BITMAP *bmp)
*/
static int really_save_png(PACKFILE *fp, BITMAP *bmp, AL_CONST RGB *pal)
{
+ jmp_buf jmpbuf;
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
int depth;
@@ -189,10 +196,11 @@ static int really_save_png(PACKFILE *fp, BITMAP *bmp, AL_CONST RGB *pal)
goto Error;
/* Set error handling. */
- if (setjmp(png_jmpbuf(png_ptr))) {
+ if (setjmp(jmpbuf)) {
/* If we get here, we had a problem reading the file. */
goto Error;
}
+ png_set_error_fn(png_ptr, jmpbuf, user_error_fn, NULL);
/* Use packfile routines. */
png_set_write_fn(png_ptr, fp, (png_rw_ptr)write_data, flush_data);