mirror of
https://github.com/aseprite/aseprite.git
synced 2024-12-26 09:19:27 +00:00
Update loadpng code from its latest version from Allegro SVN repository (new license: zlib).
This commit is contained in:
parent
ec2ae4c261
commit
0ac28c69f0
@ -249,7 +249,7 @@ data/widgets/*.xml XML files with dialogs</pre>
|
||||
<div class="library">
|
||||
loadpng
|
||||
| <a href="http://tjaden.strangesoft.net/loadpng/">homepage</a>
|
||||
| <a href="http://en.wikipedia.org/wiki/Public_domain">license</a>
|
||||
| <a href="docs/licenses/ZLIB.txt">license</a>
|
||||
</div>
|
||||
<div class="library">
|
||||
tinyxml
|
||||
|
5
third_party/loadpng/CHANGES.txt
vendored
5
third_party/loadpng/CHANGES.txt
vendored
@ -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.
|
||||
|
21
third_party/loadpng/LICENSE.txt
vendored
Normal file
21
third_party/loadpng/LICENSE.txt
vendored
Normal file
@ -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.
|
||||
|
4
third_party/loadpng/README.txt
vendored
4
third_party/loadpng/README.txt
vendored
@ -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:
|
||||
|
31
third_party/loadpng/loadpng.c
vendored
31
third_party/loadpng/loadpng.c
vendored
@ -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;
|
||||
|
38
third_party/loadpng/loadpng.h
vendored
38
third_party/loadpng/loadpng.h
vendored
@ -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
|
||||
|
2
third_party/loadpng/regpng.c
vendored
2
third_party/loadpng/regpng.c
vendored
@ -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.
|
||||
*/
|
||||
|
||||
|
||||
|
16
third_party/loadpng/savepng.c
vendored
16
third_party/loadpng/savepng.c
vendored
@ -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 <png.h>
|
||||
#include <zlib.h>
|
||||
#include <allegro.h>
|
||||
#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);
|
||||
|
Loading…
Reference in New Issue
Block a user