Imported from pngcrush-1.6.3.tar

This commit is contained in:
Glenn Randers-Pehrson
2006-03-30 19:43:31 -06:00
parent ebc4c9db72
commit 0f03cc5fe4
24 changed files with 792 additions and 1012 deletions

View File

@@ -1,5 +1,11 @@
Change log: Change log:
Version 1.6.3 (built with libpng-1.2.9beta11 and zlib-1.2.3)
Fixed documentation of iTXt input (Shlomi Tal).
Removed #define PNG_INTERNAL and provided prototypes for some
internal libpng functions that are duplicated in pngcrush.c
Version 1.6.2 (built with libpng-1.2.8 and zlib-1.2.3) Version 1.6.2 (built with libpng-1.2.8 and zlib-1.2.3)
Fixed bug with "PNG_ROWBYTES" usage, introduced in version 1.6.0. Fixed bug with "PNG_ROWBYTES" usage, introduced in version 1.6.0.

565
example.c
View File

@@ -1,565 +0,0 @@
/* example.c -- usage example of the zlib compression library
* Copyright (C) 1995-2004 Jean-loup Gailly.
* For conditions of distribution and use, see copyright notice in zlib.h
*/
/* @(#) $Id$ */
#include <stdio.h>
#include "zlib.h"
#ifdef STDC
# include <string.h>
# include <stdlib.h>
#endif
#if defined(VMS) || defined(RISCOS)
# define TESTFILE "foo-gz"
#else
# define TESTFILE "foo.gz"
#endif
#define CHECK_ERR(err, msg) { \
if (err != Z_OK) { \
fprintf(stderr, "%s error: %d\n", msg, err); \
exit(1); \
} \
}
const char hello[] = "hello, hello!";
/* "hello world" would be more standard, but the repeated "hello"
* stresses the compression code better, sorry...
*/
const char dictionary[] = "hello";
uLong dictId; /* Adler32 value of the dictionary */
void test_compress OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
void test_gzio OF((const char *fname,
Byte *uncompr, uLong uncomprLen));
void test_deflate OF((Byte *compr, uLong comprLen));
void test_inflate OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
void test_large_deflate OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
void test_large_inflate OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
void test_flush OF((Byte *compr, uLong *comprLen));
void test_sync OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
void test_dict_deflate OF((Byte *compr, uLong comprLen));
void test_dict_inflate OF((Byte *compr, uLong comprLen,
Byte *uncompr, uLong uncomprLen));
int main OF((int argc, char *argv[]));
/* ===========================================================================
* Test compress() and uncompress()
*/
void test_compress(compr, comprLen, uncompr, uncomprLen)
Byte *compr, *uncompr;
uLong comprLen, uncomprLen;
{
int err;
uLong len = (uLong)strlen(hello)+1;
err = compress(compr, &comprLen, (const Bytef*)hello, len);
CHECK_ERR(err, "compress");
strcpy((char*)uncompr, "garbage");
err = uncompress(uncompr, &uncomprLen, compr, comprLen);
CHECK_ERR(err, "uncompress");
if (strcmp((char*)uncompr, hello)) {
fprintf(stderr, "bad uncompress\n");
exit(1);
} else {
printf("uncompress(): %s\n", (char *)uncompr);
}
}
/* ===========================================================================
* Test read/write of .gz files
*/
void test_gzio(fname, uncompr, uncomprLen)
const char *fname; /* compressed file name */
Byte *uncompr;
uLong uncomprLen;
{
#ifdef NO_GZCOMPRESS
fprintf(stderr, "NO_GZCOMPRESS -- gz* functions cannot compress\n");
#else
int err;
int len = (int)strlen(hello)+1;
gzFile file;
z_off_t pos;
file = gzopen(fname, "wb");
if (file == NULL) {
fprintf(stderr, "gzopen error\n");
exit(1);
}
gzputc(file, 'h');
if (gzputs(file, "ello") != 4) {
fprintf(stderr, "gzputs err: %s\n", gzerror(file, &err));
exit(1);
}
if (gzprintf(file, ", %s!", "hello") != 8) {
fprintf(stderr, "gzprintf err: %s\n", gzerror(file, &err));
exit(1);
}
gzseek(file, 1L, SEEK_CUR); /* add one zero byte */
gzclose(file);
file = gzopen(fname, "rb");
if (file == NULL) {
fprintf(stderr, "gzopen error\n");
exit(1);
}
strcpy((char*)uncompr, "garbage");
if (gzread(file, uncompr, (unsigned)uncomprLen) != len) {
fprintf(stderr, "gzread err: %s\n", gzerror(file, &err));
exit(1);
}
if (strcmp((char*)uncompr, hello)) {
fprintf(stderr, "bad gzread: %s\n", (char*)uncompr);
exit(1);
} else {
printf("gzread(): %s\n", (char*)uncompr);
}
pos = gzseek(file, -8L, SEEK_CUR);
if (pos != 6 || gztell(file) != pos) {
fprintf(stderr, "gzseek error, pos=%ld, gztell=%ld\n",
(long)pos, (long)gztell(file));
exit(1);
}
if (gzgetc(file) != ' ') {
fprintf(stderr, "gzgetc error\n");
exit(1);
}
if (gzungetc(' ', file) != ' ') {
fprintf(stderr, "gzungetc error\n");
exit(1);
}
gzgets(file, (char*)uncompr, (int)uncomprLen);
if (strlen((char*)uncompr) != 7) { /* " hello!" */
fprintf(stderr, "gzgets err after gzseek: %s\n", gzerror(file, &err));
exit(1);
}
if (strcmp((char*)uncompr, hello + 6)) {
fprintf(stderr, "bad gzgets after gzseek\n");
exit(1);
} else {
printf("gzgets() after gzseek: %s\n", (char*)uncompr);
}
gzclose(file);
#endif
}
/* ===========================================================================
* Test deflate() with small buffers
*/
void test_deflate(compr, comprLen)
Byte *compr;
uLong comprLen;
{
z_stream c_stream; /* compression stream */
int err;
uLong len = (uLong)strlen(hello)+1;
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
CHECK_ERR(err, "deflateInit");
c_stream.next_in = (Bytef*)hello;
c_stream.next_out = compr;
while (c_stream.total_in != len && c_stream.total_out < comprLen) {
c_stream.avail_in = c_stream.avail_out = 1; /* force small buffers */
err = deflate(&c_stream, Z_NO_FLUSH);
CHECK_ERR(err, "deflate");
}
/* Finish the stream, still forcing small buffers: */
for (;;) {
c_stream.avail_out = 1;
err = deflate(&c_stream, Z_FINISH);
if (err == Z_STREAM_END) break;
CHECK_ERR(err, "deflate");
}
err = deflateEnd(&c_stream);
CHECK_ERR(err, "deflateEnd");
}
/* ===========================================================================
* Test inflate() with small buffers
*/
void test_inflate(compr, comprLen, uncompr, uncomprLen)
Byte *compr, *uncompr;
uLong comprLen, uncomprLen;
{
int err;
z_stream d_stream; /* decompression stream */
strcpy((char*)uncompr, "garbage");
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
d_stream.next_in = compr;
d_stream.avail_in = 0;
d_stream.next_out = uncompr;
err = inflateInit(&d_stream);
CHECK_ERR(err, "inflateInit");
while (d_stream.total_out < uncomprLen && d_stream.total_in < comprLen) {
d_stream.avail_in = d_stream.avail_out = 1; /* force small buffers */
err = inflate(&d_stream, Z_NO_FLUSH);
if (err == Z_STREAM_END) break;
CHECK_ERR(err, "inflate");
}
err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd");
if (strcmp((char*)uncompr, hello)) {
fprintf(stderr, "bad inflate\n");
exit(1);
} else {
printf("inflate(): %s\n", (char *)uncompr);
}
}
/* ===========================================================================
* Test deflate() with large buffers and dynamic change of compression level
*/
void test_large_deflate(compr, comprLen, uncompr, uncomprLen)
Byte *compr, *uncompr;
uLong comprLen, uncomprLen;
{
z_stream c_stream; /* compression stream */
int err;
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
err = deflateInit(&c_stream, Z_BEST_SPEED);
CHECK_ERR(err, "deflateInit");
c_stream.next_out = compr;
c_stream.avail_out = (uInt)comprLen;
/* At this point, uncompr is still mostly zeroes, so it should compress
* very well:
*/
c_stream.next_in = uncompr;
c_stream.avail_in = (uInt)uncomprLen;
err = deflate(&c_stream, Z_NO_FLUSH);
CHECK_ERR(err, "deflate");
if (c_stream.avail_in != 0) {
fprintf(stderr, "deflate not greedy\n");
exit(1);
}
/* Feed in already compressed data and switch to no compression: */
deflateParams(&c_stream, Z_NO_COMPRESSION, Z_DEFAULT_STRATEGY);
c_stream.next_in = compr;
c_stream.avail_in = (uInt)comprLen/2;
err = deflate(&c_stream, Z_NO_FLUSH);
CHECK_ERR(err, "deflate");
/* Switch back to compressing mode: */
deflateParams(&c_stream, Z_BEST_COMPRESSION, Z_FILTERED);
c_stream.next_in = uncompr;
c_stream.avail_in = (uInt)uncomprLen;
err = deflate(&c_stream, Z_NO_FLUSH);
CHECK_ERR(err, "deflate");
err = deflate(&c_stream, Z_FINISH);
if (err != Z_STREAM_END) {
fprintf(stderr, "deflate should report Z_STREAM_END\n");
exit(1);
}
err = deflateEnd(&c_stream);
CHECK_ERR(err, "deflateEnd");
}
/* ===========================================================================
* Test inflate() with large buffers
*/
void test_large_inflate(compr, comprLen, uncompr, uncomprLen)
Byte *compr, *uncompr;
uLong comprLen, uncomprLen;
{
int err;
z_stream d_stream; /* decompression stream */
strcpy((char*)uncompr, "garbage");
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
d_stream.next_in = compr;
d_stream.avail_in = (uInt)comprLen;
err = inflateInit(&d_stream);
CHECK_ERR(err, "inflateInit");
for (;;) {
d_stream.next_out = uncompr; /* discard the output */
d_stream.avail_out = (uInt)uncomprLen;
err = inflate(&d_stream, Z_NO_FLUSH);
if (err == Z_STREAM_END) break;
CHECK_ERR(err, "large inflate");
}
err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd");
if (d_stream.total_out != 2*uncomprLen + comprLen/2) {
fprintf(stderr, "bad large inflate: %ld\n", d_stream.total_out);
exit(1);
} else {
printf("large_inflate(): OK\n");
}
}
/* ===========================================================================
* Test deflate() with full flush
*/
void test_flush(compr, comprLen)
Byte *compr;
uLong *comprLen;
{
z_stream c_stream; /* compression stream */
int err;
uInt len = (uInt)strlen(hello)+1;
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
err = deflateInit(&c_stream, Z_DEFAULT_COMPRESSION);
CHECK_ERR(err, "deflateInit");
c_stream.next_in = (Bytef*)hello;
c_stream.next_out = compr;
c_stream.avail_in = 3;
c_stream.avail_out = (uInt)*comprLen;
err = deflate(&c_stream, Z_FULL_FLUSH);
CHECK_ERR(err, "deflate");
compr[3]++; /* force an error in first compressed block */
c_stream.avail_in = len - 3;
err = deflate(&c_stream, Z_FINISH);
if (err != Z_STREAM_END) {
CHECK_ERR(err, "deflate");
}
err = deflateEnd(&c_stream);
CHECK_ERR(err, "deflateEnd");
*comprLen = c_stream.total_out;
}
/* ===========================================================================
* Test inflateSync()
*/
void test_sync(compr, comprLen, uncompr, uncomprLen)
Byte *compr, *uncompr;
uLong comprLen, uncomprLen;
{
int err;
z_stream d_stream; /* decompression stream */
strcpy((char*)uncompr, "garbage");
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
d_stream.next_in = compr;
d_stream.avail_in = 2; /* just read the zlib header */
err = inflateInit(&d_stream);
CHECK_ERR(err, "inflateInit");
d_stream.next_out = uncompr;
d_stream.avail_out = (uInt)uncomprLen;
inflate(&d_stream, Z_NO_FLUSH);
CHECK_ERR(err, "inflate");
d_stream.avail_in = (uInt)comprLen-2; /* read all compressed data */
err = inflateSync(&d_stream); /* but skip the damaged part */
CHECK_ERR(err, "inflateSync");
err = inflate(&d_stream, Z_FINISH);
if (err != Z_DATA_ERROR) {
fprintf(stderr, "inflate should report DATA_ERROR\n");
/* Because of incorrect adler32 */
exit(1);
}
err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd");
printf("after inflateSync(): hel%s\n", (char *)uncompr);
}
/* ===========================================================================
* Test deflate() with preset dictionary
*/
void test_dict_deflate(compr, comprLen)
Byte *compr;
uLong comprLen;
{
z_stream c_stream; /* compression stream */
int err;
c_stream.zalloc = (alloc_func)0;
c_stream.zfree = (free_func)0;
c_stream.opaque = (voidpf)0;
err = deflateInit(&c_stream, Z_BEST_COMPRESSION);
CHECK_ERR(err, "deflateInit");
err = deflateSetDictionary(&c_stream,
(const Bytef*)dictionary, sizeof(dictionary));
CHECK_ERR(err, "deflateSetDictionary");
dictId = c_stream.adler;
c_stream.next_out = compr;
c_stream.avail_out = (uInt)comprLen;
c_stream.next_in = (Bytef*)hello;
c_stream.avail_in = (uInt)strlen(hello)+1;
err = deflate(&c_stream, Z_FINISH);
if (err != Z_STREAM_END) {
fprintf(stderr, "deflate should report Z_STREAM_END\n");
exit(1);
}
err = deflateEnd(&c_stream);
CHECK_ERR(err, "deflateEnd");
}
/* ===========================================================================
* Test inflate() with a preset dictionary
*/
void test_dict_inflate(compr, comprLen, uncompr, uncomprLen)
Byte *compr, *uncompr;
uLong comprLen, uncomprLen;
{
int err;
z_stream d_stream; /* decompression stream */
strcpy((char*)uncompr, "garbage");
d_stream.zalloc = (alloc_func)0;
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;
d_stream.next_in = compr;
d_stream.avail_in = (uInt)comprLen;
err = inflateInit(&d_stream);
CHECK_ERR(err, "inflateInit");
d_stream.next_out = uncompr;
d_stream.avail_out = (uInt)uncomprLen;
for (;;) {
err = inflate(&d_stream, Z_NO_FLUSH);
if (err == Z_STREAM_END) break;
if (err == Z_NEED_DICT) {
if (d_stream.adler != dictId) {
fprintf(stderr, "unexpected dictionary");
exit(1);
}
err = inflateSetDictionary(&d_stream, (const Bytef*)dictionary,
sizeof(dictionary));
}
CHECK_ERR(err, "inflate with dict");
}
err = inflateEnd(&d_stream);
CHECK_ERR(err, "inflateEnd");
if (strcmp((char*)uncompr, hello)) {
fprintf(stderr, "bad inflate with dict\n");
exit(1);
} else {
printf("inflate with dictionary: %s\n", (char *)uncompr);
}
}
/* ===========================================================================
* Usage: example [output.gz [input.gz]]
*/
int main(argc, argv)
int argc;
char *argv[];
{
Byte *compr, *uncompr;
uLong comprLen = 10000*sizeof(int); /* don't overflow on MSDOS */
uLong uncomprLen = comprLen;
static const char* myVersion = ZLIB_VERSION;
if (zlibVersion()[0] != myVersion[0]) {
fprintf(stderr, "incompatible zlib version\n");
exit(1);
} else if (strcmp(zlibVersion(), ZLIB_VERSION) != 0) {
fprintf(stderr, "warning: different zlib version\n");
}
printf("zlib version %s = 0x%04x, compile flags = 0x%lx\n",
ZLIB_VERSION, ZLIB_VERNUM, zlibCompileFlags());
compr = (Byte*)calloc((uInt)comprLen, 1);
uncompr = (Byte*)calloc((uInt)uncomprLen, 1);
/* compr and uncompr are cleared to avoid reading uninitialized
* data and to ensure that uncompr compresses well.
*/
if (compr == Z_NULL || uncompr == Z_NULL) {
printf("out of memory\n");
exit(1);
}
test_compress(compr, comprLen, uncompr, uncomprLen);
test_gzio((argc > 1 ? argv[1] : TESTFILE),
uncompr, uncomprLen);
test_deflate(compr, comprLen);
test_inflate(compr, comprLen, uncompr, uncomprLen);
test_large_deflate(compr, comprLen, uncompr, uncomprLen);
test_large_inflate(compr, comprLen, uncompr, uncomprLen);
test_flush(compr, &comprLen);
test_sync(compr, comprLen, uncompr, uncomprLen);
comprLen = uncomprLen;
test_dict_deflate(compr, comprLen);
test_dict_inflate(compr, comprLen, uncompr, uncomprLen);
free(compr);
free(uncompr);
return 0;
}

35
png.c
View File

@@ -1,9 +1,9 @@
/* png.c - location for general purpose libpng functions /* png.c - location for general purpose libpng functions
* *
* libpng version 1.2.8 - December 3, 2004 * Last changed in libpng 1.2.9 March 22, 2006
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2006 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/ */
@@ -13,7 +13,7 @@
#include "png.h" #include "png.h"
/* Generate a compiler error if there is an old png.h in the search path. */ /* Generate a compiler error if there is an old png.h in the search path. */
typedef version_1_2_8 Your_png_h_is_not_version_1_2_8; typedef version_1_2_9beta11 Your_png_h_is_not_version_1_2_9beta11;
/* Version information for C files. This had better match the version /* Version information for C files. This had better match the version
* string defined in png.h. */ * string defined in png.h. */
@@ -22,9 +22,12 @@ typedef version_1_2_8 Your_png_h_is_not_version_1_2_8;
/* png_libpng_ver was changed to a function in version 1.0.5c */ /* png_libpng_ver was changed to a function in version 1.0.5c */
const char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING; const char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
#ifdef PNG_READ_SUPPORTED
/* png_sig was changed to a function in version 1.0.5c */ /* png_sig was changed to a function in version 1.0.5c */
/* Place to hold the signature string for a PNG file. */ /* Place to hold the signature string for a PNG file. */
const png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10}; const png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
#endif /* PNG_READ_SUPPORTED */
/* Invoke global declarations for constant strings for known chunk types */ /* Invoke global declarations for constant strings for known chunk types */
PNG_IHDR; PNG_IHDR;
@@ -49,6 +52,7 @@ PNG_tIME;
PNG_tRNS; PNG_tRNS;
PNG_zTXt; PNG_zTXt;
#ifdef PNG_READ_SUPPORTED
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* start of interlace block */ /* start of interlace block */
@@ -80,6 +84,7 @@ const int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
const int FARDATA png_pass_dsp_mask[] const int FARDATA png_pass_dsp_mask[]
= {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff}; = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
#endif /* PNG_READ_SUPPORTED */
#endif /* PNG_USE_GLOBAL_ARRAYS */ #endif /* PNG_USE_GLOBAL_ARRAYS */
/* Tells libpng that we have already handled the first "num_bytes" bytes /* Tells libpng that we have already handled the first "num_bytes" bytes
@@ -88,6 +93,7 @@ const int FARDATA png_pass_dsp_mask[]
* or write any of the magic bytes before it starts on the IHDR. * or write any of the magic bytes before it starts on the IHDR.
*/ */
#ifdef PNG_READ_SUPPORTED
void PNGAPI void PNGAPI
png_set_sig_bytes(png_structp png_ptr, int num_bytes) png_set_sig_bytes(png_structp png_ptr, int num_bytes)
{ {
@@ -113,10 +119,10 @@ png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
if (num_to_check > 8) if (num_to_check > 8)
num_to_check = 8; num_to_check = 8;
else if (num_to_check < 1) else if (num_to_check < 1)
return (0); return (-1);
if (start > 7) if (start > 7)
return (0); return (-1);
if (start + num_to_check > 8) if (start + num_to_check > 8)
num_to_check = 8 - start; num_to_check = 8 - start;
@@ -124,6 +130,7 @@ png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check))); return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
} }
#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
/* (Obsolete) function to check signature bytes. It does not allow one /* (Obsolete) function to check signature bytes. It does not allow one
* to check a partial signature. This function might be removed in the * to check a partial signature. This function might be removed in the
* future - use png_sig_cmp(). Returns true (nonzero) if the file is a PNG. * future - use png_sig_cmp(). Returns true (nonzero) if the file is a PNG.
@@ -133,7 +140,10 @@ png_check_sig(png_bytep sig, int num)
{ {
return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num)); return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
} }
#endif
#endif /* PNG_READ_SUPPORTED */
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
/* Function to allocate memory for zlib and clear it to 0. */ /* Function to allocate memory for zlib and clear it to 0. */
#ifdef PNG_1_0_X #ifdef PNG_1_0_X
voidpf PNGAPI voidpf PNGAPI
@@ -279,7 +289,7 @@ png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
* and applications using it are urged to use png_create_info_struct() * and applications using it are urged to use png_create_info_struct()
* instead. * instead.
*/ */
#if defined(PNG_1_0_X) || defined (PNG_1_2_X) #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
#undef png_info_init #undef png_info_init
void PNGAPI void PNGAPI
png_info_init(png_infop info_ptr) png_info_init(png_infop info_ptr)
@@ -592,6 +602,7 @@ png_info_destroy(png_structp png_ptr, png_infop info_ptr)
png_info_init_3(&info_ptr, png_sizeof(png_info)); png_info_init_3(&info_ptr, png_sizeof(png_info));
} }
#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
/* This function returns a pointer to the io_ptr associated with the user /* This function returns a pointer to the io_ptr associated with the user
* functions. The application should free any memory associated with this * functions. The application should free any memory associated with this
@@ -603,6 +614,7 @@ png_get_io_ptr(png_structp png_ptr)
return (png_ptr->io_ptr); return (png_ptr->io_ptr);
} }
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
#if !defined(PNG_NO_STDIO) #if !defined(PNG_NO_STDIO)
/* Initialize the default input/output functions for the PNG file. If you /* Initialize the default input/output functions for the PNG file. If you
* use your own read or write routines, you can call either png_set_read_fn() * use your own read or write routines, you can call either png_set_read_fn()
@@ -675,13 +687,14 @@ png_sig_bytes(void)
return ((png_bytep)"\211\120\116\107\015\012\032\012"); return ((png_bytep)"\211\120\116\107\015\012\032\012");
} }
#endif #endif
#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
png_charp PNGAPI png_charp PNGAPI
png_get_copyright(png_structp png_ptr) png_get_copyright(png_structp png_ptr)
{ {
if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */ if (&png_ptr != NULL) /* silence compiler warning about unused png_ptr */
return ((png_charp) "\n libpng version 1.2.8 - December 3, 2004\n\ return ((png_charp) "\n libpng version 1.2.9beta11 - March 22, 2006\n\
Copyright (c) 1998-2004 Glenn Randers-Pehrson\n\ Copyright (c) 1998-2006 Glenn Randers-Pehrson\n\
Copyright (c) 1996-1997 Andreas Dilger\n\ Copyright (c) 1996-1997 Andreas Dilger\n\
Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n"); Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
return ((png_charp) ""); return ((png_charp) "");
@@ -722,6 +735,7 @@ png_get_header_version(png_structp png_ptr)
return ((png_charp) ""); return ((png_charp) "");
} }
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
int PNGAPI int PNGAPI
png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name) png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
@@ -745,6 +759,7 @@ png_reset_zstream(png_structp png_ptr)
{ {
return (inflateReset(&png_ptr->zstream)); return (inflateReset(&png_ptr->zstream));
} }
#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
/* This function was added to libpng-1.0.7 */ /* This function was added to libpng-1.0.7 */
png_uint_32 PNGAPI png_uint_32 PNGAPI
@@ -755,6 +770,7 @@ png_access_version_number(void)
} }
#if defined(PNG_READ_SUPPORTED)
#if !defined(PNG_1_0_X) #if !defined(PNG_1_0_X)
#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
/* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */ /* GRR: could add this: && defined(PNG_MMX_CODE_SUPPORTED) */
@@ -814,7 +830,9 @@ png_mmx_support(void)
} }
#endif #endif
#endif /* PNG_1_0_X */ #endif /* PNG_1_0_X */
#endif /* PNG_READ_SUPPORTED */
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
#ifdef PNG_SIZE_T #ifdef PNG_SIZE_T
/* Added at libpng version 1.2.6 */ /* Added at libpng version 1.2.6 */
PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size)); PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
@@ -826,3 +844,4 @@ png_convert_size(size_t size)
return ((png_size_t)size); return ((png_size_t)size);
} }
#endif /* PNG_SIZE_T */ #endif /* PNG_SIZE_T */
#endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */

154
png.h
View File

@@ -1,14 +1,15 @@
/* png.h - header file for PNG reference library /* png.h - header file for PNG reference library
* *
* libpng version 1.2.8 - December 3, 2004 * libpng version 1.2.9beta11 - March 22, 2006
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2006 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
* Authors and maintainers: * Authors and maintainers:
* libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat * libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat
* libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger * libpng versions 0.89c, June 1996, through 0.96, May 1997: Andreas Dilger
* libpng versions 0.97, January 1998, through 1.2.8 - December 3, 2004: Glenn * libpng versions 0.97, January 1998, through 1.2.9beta11 - March 22, 2006: Glenn
* See also "Contributing Authors", below. * See also "Contributing Authors", below.
* *
* Note about libpng version numbers: * Note about libpng version numbers:
@@ -111,6 +112,8 @@
* 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5 * 1.2.8rc1-5 13 10208 12.so.0.1.2.8rc1-5
* 1.0.18 10 10018 12.so.0.1.0.18 * 1.0.18 10 10018 12.so.0.1.0.18
* 1.2.8 13 10208 12.so.0.1.2.8 * 1.2.8 13 10208 12.so.0.1.2.8
* 1.2.9beta1-3 13 10209 12.so.0.1.2.9beta1-3
* 1.2.9beta4-11 13 10209 12.so.0.9[.0]
* *
* Henceforth the source version will match the shared-library major * Henceforth the source version will match the shared-library major
* and minor numbers; the shared-library major version number will be * and minor numbers; the shared-library major version number will be
@@ -140,8 +143,8 @@
* If you modify libpng you may insert additional notices immediately following * If you modify libpng you may insert additional notices immediately following
* this sentence. * this sentence.
* *
* libpng versions 1.2.6, August 15, 2004, through 1.2.8, December 3, 2004, are * libpng versions 1.2.6, August 15, 2004, through 1.2.9beta11, March 22, 2006, are
* Copyright (c) 2004 Glenn Randers-Pehrson, and are * Copyright (c) 2004, 2006 Glenn Randers-Pehrson, and are
* distributed according to the same disclaimer and license as libpng-1.2.5 * distributed according to the same disclaimer and license as libpng-1.2.5
* with the following individual added to the list of Contributing Authors: * with the following individual added to the list of Contributing Authors:
* *
@@ -252,13 +255,13 @@
* Y2K compliance in libpng: * Y2K compliance in libpng:
* ========================= * =========================
* *
* December 3, 2004 * March 22, 2006
* *
* Since the PNG Development group is an ad-hoc body, we can't make * Since the PNG Development group is an ad-hoc body, we can't make
* an official declaration. * an official declaration.
* *
* This is your unofficial assurance that libpng from version 0.71 and * This is your unofficial assurance that libpng from version 0.71 and
* upward through 1.2.8 are Y2K compliant. It is my belief that earlier * upward through 1.2.9beta11 are Y2K compliant. It is my belief that earlier
* versions were also Y2K compliant. * versions were also Y2K compliant.
* *
* Libpng only has three year fields. One is a 2-byte unsigned integer * Libpng only has three year fields. One is a 2-byte unsigned integer
@@ -314,9 +317,9 @@
*/ */
/* Version information for png.h - this should match the version in png.c */ /* Version information for png.h - this should match the version in png.c */
#define PNG_LIBPNG_VER_STRING "1.2.8" #define PNG_LIBPNG_VER_STRING "1.2.9beta11"
#define PNG_HEADER_VERSION_STRING \ #define PNG_HEADER_VERSION_STRING \
" libpng version 1.2.8 - December 3, 2004 (header)\n" " libpng version 1.2.9beta11 - March 22, 2006 (header)\n"
#define PNG_LIBPNG_VER_SONUM 0 #define PNG_LIBPNG_VER_SONUM 0
#define PNG_LIBPNG_VER_DLLNUM 13 #define PNG_LIBPNG_VER_DLLNUM 13
@@ -324,11 +327,11 @@
/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */ /* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */
#define PNG_LIBPNG_VER_MAJOR 1 #define PNG_LIBPNG_VER_MAJOR 1
#define PNG_LIBPNG_VER_MINOR 2 #define PNG_LIBPNG_VER_MINOR 2
#define PNG_LIBPNG_VER_RELEASE 8 #define PNG_LIBPNG_VER_RELEASE 9
/* This should match the numeric part of the final component of /* This should match the numeric part of the final component of
* PNG_LIBPNG_VER_STRING, omitting any leading zero: */ * PNG_LIBPNG_VER_STRING, omitting any leading zero: */
#define PNG_LIBPNG_VER_BUILD 0 #define PNG_LIBPNG_VER_BUILD 11
/* Release Status */ /* Release Status */
#define PNG_LIBPNG_BUILD_ALPHA 1 #define PNG_LIBPNG_BUILD_ALPHA 1
@@ -345,14 +348,14 @@
#define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
PNG_LIBPNG_BUILD_PRIVATE */ PNG_LIBPNG_BUILD_PRIVATE */
#define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_BETA
/* Careful here. At one time, Guy wanted to use 082, but that would be octal. /* Careful here. At one time, Guy wanted to use 082, but that would be octal.
* We must not include leading zeros. * We must not include leading zeros.
* Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only * Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only
* version 1.0.0 was mis-numbered 100 instead of 10000). From * version 1.0.0 was mis-numbered 100 instead of 10000). From
* version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release */ * version 1.0.1 it's xxyyzz, where x=major, y=minor, z=release */
#define PNG_LIBPNG_VER 10208 /* 1.2.8 */ #define PNG_LIBPNG_VER 10209 /* 1.2.9 */
#ifndef PNG_VERSION_INFO_ONLY #ifndef PNG_VERSION_INFO_ONLY
/* include the compression library's header */ /* include the compression library's header */
@@ -376,14 +379,14 @@
*/ */
#if defined(PNG_USER_PRIVATEBUILD) #if defined(PNG_USER_PRIVATEBUILD)
# define PNG_LIBPNG_BUILD_TYPE PNG_LIBPNG_BUILD_BASE_TYPE | \ # define PNG_LIBPNG_BUILD_TYPE \
PNG_LIBPNG_BUILD_PRIVATE (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
#else #else
# if defined(PNG_LIBPNG_SPECIALBUILD) # if defined(PNG_LIBPNG_SPECIALBUILD)
# define PNG_LIBPNG_BUILD_TYPE PNG_LIBPNG_BUILD_BASE_TYPE | \ # define PNG_LIBPNG_BUILD_TYPE \
PNG_LIBPNG_BUILD_SPECIAL (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
# else # else
# define PNG_LIBPNG_BUILD_TYPE PNG_LIBPNG_BUILD_BASE_TYPE # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
# endif # endif
#endif #endif
@@ -894,8 +897,10 @@ typedef png_info FAR * FAR * png_infopp;
#define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL) #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
#define PNG_UINT_32_MAX ((png_uint_32)(-1)) #define PNG_UINT_32_MAX ((png_uint_32)(-1))
#define PNG_SIZE_MAX ((png_size_t)(-1)) #define PNG_SIZE_MAX ((png_size_t)(-1))
#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
/* PNG_MAX_UINT is deprecated; use PNG_UINT_31_MAX instead. */ /* PNG_MAX_UINT is deprecated; use PNG_UINT_31_MAX instead. */
#define PNG_MAX_UINT PNG_UINT_31_MAX #define PNG_MAX_UINT PNG_UINT_31_MAX
#endif
/* These describe the color_type field in png_info. */ /* These describe the color_type field in png_info. */
/* color type masks */ /* color type masks */
@@ -1356,7 +1361,7 @@ struct png_struct_def
/* This triggers a compiler error in png.c, if png.c and png.h /* This triggers a compiler error in png.c, if png.c and png.h
* do not agree upon the version number. * do not agree upon the version number.
*/ */
typedef png_structp version_1_2_8; typedef png_structp version_1_2_9beta11;
typedef png_struct FAR * FAR * png_structpp; typedef png_struct FAR * FAR * png_structpp;
@@ -1442,11 +1447,14 @@ extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
extern PNG_EXPORT(png_infop,png_create_info_struct) extern PNG_EXPORT(png_infop,png_create_info_struct)
PNGARG((png_structp png_ptr)); PNGARG((png_structp png_ptr));
#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
/* Initialize the info structure (old interface - DEPRECATED) */ /* Initialize the info structure (old interface - DEPRECATED) */
extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr)); extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
#undef png_info_init #undef png_info_init
#define png_info_init(info_ptr) png_info_init_3(&info_ptr,\ #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
png_sizeof(png_info)); png_sizeof(png_info));
#endif
extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr, extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
png_size_t png_info_struct_size)); png_size_t png_info_struct_size));
@@ -1483,9 +1491,16 @@ extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
#if defined(PNG_READ_EXPAND_SUPPORTED) #if defined(PNG_READ_EXPAND_SUPPORTED)
/* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */ /* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */
extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr)); extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr)); #if !defined(PNG_1_0_X)
extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
png_ptr));
#endif
extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr)); extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr)); extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
/* Deprecated */
extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
#endif
#endif #endif
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
@@ -1606,6 +1621,7 @@ extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
#endif #endif
#endif #endif
#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \ #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
/* Permit or disallow empty PLTE (0: not permitted, 1: permitted) */ /* Permit or disallow empty PLTE (0: not permitted, 1: permitted) */
@@ -1613,6 +1629,7 @@ extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr, extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
int empty_plte_permitted)); int empty_plte_permitted));
#endif #endif
#endif
#if defined(PNG_WRITE_FLUSH_SUPPORTED) #if defined(PNG_WRITE_FLUSH_SUPPORTED)
/* Set how many lines between output flushes - 0 for no flushing */ /* Set how many lines between output flushes - 0 for no flushing */
@@ -2327,11 +2344,12 @@ extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
#ifdef PNG_FLOATING_POINT_SUPPORTED #ifdef PNG_FLOATING_POINT_SUPPORTED
extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr, extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
png_infop info_ptr, int unit, double width, double height)); png_infop info_ptr, int unit, double width, double height));
#endif #else
#ifdef PNG_FIXED_POINT_SUPPORTED #ifdef PNG_FIXED_POINT_SUPPORTED
extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr, extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
png_infop info_ptr, int unit, png_charp swidth, png_charp sheight)); png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
#endif #endif
#endif
#endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */ #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
#if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
@@ -2427,7 +2445,9 @@ extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
#define png_debug2(l, m, p1, p2) #define png_debug2(l, m, p1, p2)
#endif #endif
#if 0
extern PNG_EXPORT(png_bytep,png_sig_bytes) PNGARG((void)); extern PNG_EXPORT(png_bytep,png_sig_bytes) PNGARG((void));
#endif
extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr)); extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr)); extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
@@ -2572,6 +2592,44 @@ extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
#endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */ #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
/* Inline macros to do direct reads of bytes from the input buffer. These
* require that you are using an architecture that uses PNG byte ordering
* (MSB first) and supports unaligned data storage. I think that PowerPC
* in big-endian mode and 680x0 are the only ones that will support this.
* The x86 line of processors definitely do not. The png_get_int_32()
* routine also assumes we are using two's complement format for negative
* values, which is almost certainly true.
*/
#if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
# define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
# define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
# define png_get_int_32(buf) ( *((png_int_32p) (buf)))
#else
extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
#endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
extern PNG_EXPORT(png_uint_32,png_get_uint_31)
PNGARG((png_structp png_ptr, png_bytep buf));
/* No png_get_int_16 -- may be added if there's a real need for it. */
/* Place a 32-bit number into a buffer in PNG byte order (big-endian).
*/
extern PNG_EXPORT(void,png_save_uint_32)
PNGARG((png_bytep buf, png_uint_32 i));
extern PNG_EXPORT(void,png_save_int_32)
PNGARG((png_bytep buf, png_int_32 i));
/* Place a 16-bit number into a buffer in PNG byte order.
* The parameter is declared unsigned int, not png_uint_16,
* just to avoid potential problems on pre-ANSI C compilers.
*/
extern PNG_EXPORT(void,png_save_uint_16)
PNGARG((png_bytep buf, unsigned int i));
/* No png_save_int_16 -- may be added if there's a real need for it. */
/* ************************************************************************* */
/* These next functions are used internally in the code. They generally /* These next functions are used internally in the code. They generally
* shouldn't be used unless you are writing code to add or replace some * shouldn't be used unless you are writing code to add or replace some
* functionality in libpng. More information about most functions can * functionality in libpng. More information about most functions can
@@ -2624,7 +2682,7 @@ extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
#define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */ #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
/* 0x800000L Unused */ /* 0x800000L Unused */
#define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */ #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
/* 0x2000000L unused */ #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
/* 0x4000000L unused */ /* 0x4000000L unused */
/* 0x8000000L unused */ /* 0x8000000L unused */
/* 0x10000000L unused */ /* 0x10000000L unused */
@@ -2708,8 +2766,10 @@ extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
#ifdef PNG_USE_GLOBAL_ARRAYS #ifdef PNG_USE_GLOBAL_ARRAYS
PNG_EXPORT_VAR (const png_byte FARDATA) png_sig[8]; PNG_EXPORT_VAR (const png_byte FARDATA) png_sig[8];
#else #else
#if 0
#define png_sig png_sig_bytes(NULL) #define png_sig png_sig_bytes(NULL)
#endif #endif
#endif
#endif /* PNG_NO_EXTERN */ #endif /* PNG_NO_EXTERN */
/* Constant strings for known chunk types. If you need to add a chunk, /* Constant strings for known chunk types. If you need to add a chunk,
@@ -2762,31 +2822,7 @@ PNG_EXPORT_VAR (const png_byte FARDATA) png_tRNS[5];
PNG_EXPORT_VAR (const png_byte FARDATA) png_zTXt[5]; PNG_EXPORT_VAR (const png_byte FARDATA) png_zTXt[5];
#endif /* PNG_USE_GLOBAL_ARRAYS */ #endif /* PNG_USE_GLOBAL_ARRAYS */
#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
/* Inline macros to do direct reads of bytes from the input buffer. These
* require that you are using an architecture that uses PNG byte ordering
* (MSB first) and supports unaligned data storage. I think that PowerPC
* in big-endian mode and 680x0 are the only ones that will support this.
* The x86 line of processors definitely do not. The png_get_int_32()
* routine also assumes we are using two's complement format for negative
* values, which is almost certainly true.
*/
#if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
# if defined(PNG_pCAL_SUPPORTED) || defined(PNG_oFFs_SUPPORTED)
# define png_get_int_32(buf) ( *((png_int_32p) (buf)))
# endif
# define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
# define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
#else
# if defined(PNG_pCAL_SUPPORTED) || defined(PNG_oFFs_SUPPORTED)
PNG_EXTERN png_int_32 png_get_int_32 PNGARG((png_bytep buf));
# endif
PNG_EXTERN png_uint_32 png_get_uint_32 PNGARG((png_bytep buf));
PNG_EXTERN png_uint_16 png_get_uint_16 PNGARG((png_bytep buf));
#endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
PNG_EXTERN png_uint_32 png_get_uint_31 PNGARG((png_structp png_ptr,
png_bytep buf));
/* Initialize png_ptr struct for reading, and allocate any other memory. /* Initialize png_ptr struct for reading, and allocate any other memory.
* (old interface - DEPRECATED - use png_create_read_struct instead). * (old interface - DEPRECATED - use png_create_read_struct instead).
*/ */
@@ -2794,12 +2830,17 @@ extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
#undef png_read_init #undef png_read_init
#define png_read_init(png_ptr) png_read_init_3(&png_ptr, \ #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
PNG_LIBPNG_VER_STRING, png_sizeof(png_struct)); PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
#endif
extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr, extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
png_const_charp user_png_ver, png_size_t png_struct_size)); png_const_charp user_png_ver, png_size_t png_struct_size));
#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr, extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
png_info_size)); png_info_size));
#endif
#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
/* Initialize png_ptr struct for writing, and allocate any other memory. /* Initialize png_ptr struct for writing, and allocate any other memory.
* (old interface - DEPRECATED - use png_create_write_struct instead). * (old interface - DEPRECATED - use png_create_write_struct instead).
*/ */
@@ -2807,6 +2848,8 @@ extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
#undef png_write_init #undef png_write_init
#define png_write_init(png_ptr) png_write_init_3(&png_ptr, \ #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
PNG_LIBPNG_VER_STRING, png_sizeof(png_struct)); PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
#endif
extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr, extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
png_const_charp user_png_ver, png_size_t png_struct_size)); png_const_charp user_png_ver, png_size_t png_struct_size));
extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr, extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
@@ -2906,23 +2949,6 @@ PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
PNG_EXTERN void png_flush PNGARG((png_structp png_ptr)); PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
#endif #endif
/* Place a 32-bit number into a buffer in PNG byte order (big-endian).
* The only currently known PNG chunks that use signed numbers are
* the ancillary extension chunks, oFFs and pCAL.
*/
PNG_EXTERN void png_save_uint_32 PNGARG((png_bytep buf, png_uint_32 i));
#if defined(PNG_WRITE_pCAL_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
PNG_EXTERN void png_save_int_32 PNGARG((png_bytep buf, png_int_32 i));
#endif
/* Place a 16-bit number into a buffer in PNG byte order.
* The parameter is declared unsigned int, not png_uint_16,
* just to avoid potential problems on pre-ANSI C compilers.
*/
PNG_EXTERN void png_save_uint_16 PNGARG((png_bytep buf, unsigned int i));
/* simple function to write the signature */ /* simple function to write the signature */
PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr)); PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));

View File

@@ -1,9 +1,9 @@
/* pngconf.h - machine configurable file for libpng /* pngconf.h - machine configurable file for libpng
* *
* libpng version 1.2.8 - December 3, 2004 * libpng version 1.2.9beta11 - March 22, 2006
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2005 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/ */
@@ -17,18 +17,23 @@
#ifndef PNGCONF_H #ifndef PNGCONF_H
#define PNGCONF_H #define PNGCONF_H
#include "pngcrush.h"
#define PNG_1_2_X #define PNG_1_2_X
#include "pngcrush.h"
/* /*
* PNG_USER_CONFIG has to be defined on the compiler command line. This * PNG_USER_CONFIG has to be defined on the compiler command line. This
* includes the resource compiler for Windows DLL configurations. * includes the resource compiler for Windows DLL configurations.
*/ */
#ifdef PNG_USER_CONFIG #ifdef PNG_USER_CONFIG
#include "pngusr.h" #include "pngusr.h"
#endif #endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
/* /*
* Added at libpng-1.2.8 * Added at libpng-1.2.8
* *
@@ -455,21 +460,33 @@
*/ */
/* The size of the png_text structure changed in libpng-1.0.6 when /* The size of the png_text structure changed in libpng-1.0.6 when
* iTXt is supported. It is turned off by default, to support old apps * iTXt support was added. iTXt support was turned off by default through
* that malloc the png_text structure instead of calling png_set_text() * libpng-1.2.x, to support old apps that malloc the png_text structure
* and letting libpng malloc it. It will be turned on by default in * instead of calling png_set_text() and letting libpng malloc it. It
* libpng-1.3.0. * was turned on by default in libpng-1.3.0.
*/ */
#ifndef PNG_iTXt_SUPPORTED #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
# if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt) # ifndef PNG_NO_iTXt_SUPPORTED
# define PNG_NO_iTXt_SUPPORTED
# endif
# ifndef PNG_NO_READ_iTXt
# define PNG_NO_READ_iTXt # define PNG_NO_READ_iTXt
# endif # endif
# if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt) # ifndef PNG_NO_WRITE_iTXt
# define PNG_NO_WRITE_iTXt # define PNG_NO_WRITE_iTXt
# endif # endif
#endif #endif
#if !defined(PNG_NO_iTXt_SUPPORTED)
# if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
# define PNG_READ_iTXt
# endif
# if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
# define PNG_WRITE_iTXt
# endif
#endif
/* The following support, added after version 1.0.0, can be turned off here en /* The following support, added after version 1.0.0, can be turned off here en
* masse by defining PNG_LEGACY_SUPPORTED in case you need binary compatibility * masse by defining PNG_LEGACY_SUPPORTED in case you need binary compatibility
* with old applications that require the length of png_struct and png_info * with old applications that require the length of png_struct and png_info
@@ -587,11 +604,13 @@
# endif # endif
#endif #endif
#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
/* Deprecated, will be removed from version 2.0.0. /* Deprecated, will be removed from version 2.0.0.
Use PNG_MNG_FEATURES_SUPPORTED instead. */ Use PNG_MNG_FEATURES_SUPPORTED instead. */
#ifndef PNG_NO_READ_EMPTY_PLTE #ifndef PNG_NO_READ_EMPTY_PLTE
# define PNG_READ_EMPTY_PLTE_SUPPORTED # define PNG_READ_EMPTY_PLTE_SUPPORTED
#endif #endif
#endif
#endif /* PNG_READ_SUPPORTED */ #endif /* PNG_READ_SUPPORTED */
@@ -635,11 +654,15 @@
# endif # endif
#endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */ #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
#if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
!defined(PNG_WRITE_INTERLACING_SUPPORTED)
#define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
encoders, but can cause trouble encoders, but can cause trouble
if left undefined */ if left undefined */
#endif
#if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \ #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
!defined(PNG_WRITE_WEIGHTED_FILTER) && \
defined(PNG_FLOATING_POINT_SUPPORTED) defined(PNG_FLOATING_POINT_SUPPORTED)
# define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
#endif #endif
@@ -648,10 +671,12 @@
# define PNG_WRITE_FLUSH_SUPPORTED # define PNG_WRITE_FLUSH_SUPPORTED
#endif #endif
#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
/* Deprecated, see PNG_MNG_FEATURES_SUPPORTED, above */ /* Deprecated, see PNG_MNG_FEATURES_SUPPORTED, above */
#ifndef PNG_NO_WRITE_EMPTY_PLTE #ifndef PNG_NO_WRITE_EMPTY_PLTE
# define PNG_WRITE_EMPTY_PLTE_SUPPORTED # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
#endif #endif
#endif
#endif /* PNG_WRITE_SUPPORTED */ #endif /* PNG_WRITE_SUPPORTED */
@@ -698,9 +723,14 @@
# ifndef PNG_ASSEMBLER_CODE_SUPPORTED # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
# define PNG_ASSEMBLER_CODE_SUPPORTED # define PNG_ASSEMBLER_CODE_SUPPORTED
# endif # endif
# if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE) && \
defined(__MMX__)
# define PNG_MMX_CODE_SUPPORTED # define PNG_MMX_CODE_SUPPORTED
# endif # endif
# if !defined(PNG_USE_PNGGCCRD) && !defined(PNG_NO_MMX_CODE) && \
defined(__MMX__)
# define PNG_USE_PNGGCCRD
# endif
#endif #endif
/* If you are sure that you don't need thread safety and you are compiling /* If you are sure that you don't need thread safety and you are compiling

View File

@@ -26,7 +26,7 @@
* *
*/ */
#define PNGCRUSH_VERSION "1.6.2" #define PNGCRUSH_VERSION "1.6.3"
/* /*
#define PNGCRUSH_COUNT_COLORS #define PNGCRUSH_COUNT_COLORS
@@ -119,9 +119,40 @@
* then double size & copy if run out of room: still O(n) algorithm. * then double size & copy if run out of room: still O(n) algorithm.
*/ */
#define PNG_INTERNAL
#include "png.h" #include "png.h"
/* internal libpng macros */
#define PNG_IDAT const png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
#define PNG_IHDR const png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
#define PNG_iCCP const png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
#define PNG_IEND const png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
PNG_EXPORT_VAR (const png_byte FARDATA) png_IHDR[5];
PNG_EXPORT_VAR (const png_byte FARDATA) png_IDAT[5];
PNG_EXPORT_VAR (const png_byte FARDATA) png_IEND[5];
PNG_EXPORT_VAR (const png_byte FARDATA) png_iCCP[5];
#define PNG_FLAG_CRC_CRITICAL_USE 0x0400
#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
#define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
#define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
#define PNG_FLAG_CRC_CRITICAL_USE 0x0400
#define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
PNG_FLAG_CRC_ANCILLARY_NOWARN)
#define PNG_PACK 0x0004
#define PNG_DITHER 0x0040
#define PNG_BACKGROUND 0x0080
#define PNG_16_TO_8 0x0400
#define PNG_RGBA 0x0800
#define PNG_EXPAND 0x1000
#define PNG_GAMMA 0x2000
#define PNG_GRAY_TO_RGB 0x4000
#define PNG_FILLER 0x8000L
#define PNG_USER_TRANSFORM 0x100000L
#define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
/* we don't need some of the extra libpng transformations /* we don't need some of the extra libpng transformations
* so they are ifdef'ed out in pngcrush.h, which is included by * so they are ifdef'ed out in pngcrush.h, which is included by
* libpng's pngconf.h which is included by png.h */ * libpng's pngconf.h which is included by png.h */
@@ -397,6 +428,24 @@ int ia;
/* prototypes */ /* prototypes */
static void png_cexcept_error(png_structp png_ptr, png_const_charp msg); static void png_cexcept_error(png_structp png_ptr, png_const_charp msg);
void PNGAPI png_default_read_data(png_structp png_ptr, png_bytep data,
png_size_t length);
void png_read_transform_info(png_structp png_ptr, png_infop info_ptr);
void PNGAPI png_default_write_data(png_structp png_ptr, png_bytep data,
png_size_t length);
void png_reset_crc(png_structp png_ptr);
void png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length);
void png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length);
int png_crc_error(png_structp png_ptr);
int png_crc_finish(png_structp png_ptr, png_uint_32 skip);
png_uint_32 png_get_uint_31(png_structp png_ptr, png_bytep buf);
png_uint_32 png_get_uint_32(png_bytep buf);
void png_save_uint_32(png_bytep buf, png_uint_32 i);
#ifdef PNG_USER_MEM_SUPPORTED #ifdef PNG_USER_MEM_SUPPORTED
png_voidp png_debug_malloc(png_structp png_ptr, png_uint_32 size); png_voidp png_debug_malloc(png_structp png_ptr, png_uint_32 size);
void png_debug_free(png_structp png_ptr, png_voidp ptr); void png_debug_free(png_structp png_ptr, png_voidp ptr);
@@ -454,6 +503,14 @@ png_get_uint_31(png_structp png_ptr, png_bytep buf)
png_error(png_ptr, "PNG unsigned integer out of range.\n"); png_error(png_ptr, "PNG unsigned integer out of range.\n");
return (i); return (i);
} }
void /* PRIVATE */
png_save_uint_32(png_bytep buf, png_uint_32 i)
{
buf[0] = (png_byte)((i >> 24) & 0xff);
buf[1] = (png_byte)((i >> 16) & 0xff);
buf[2] = (png_byte)((i >> 8) & 0xff);
buf[3] = (png_byte)(i & 0xff);
}
/* Reset the CRC variable to 32 bits of 1's. Care must be taken /* Reset the CRC variable to 32 bits of 1's. Care must be taken
* in case CRC is > 32 bits to leave the top bits 0. * in case CRC is > 32 bits to leave the top bits 0.
@@ -493,7 +550,7 @@ png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
void /* PRIVATE */ void /* PRIVATE */
png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length) png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
{ {
png_read_data(png_ptr, buf, length); png_default_read_data(png_ptr, buf, length);
png_calculate_crc(png_ptr, buf, length); png_calculate_crc(png_ptr, buf, length);
} }
@@ -518,7 +575,7 @@ png_crc_error(png_structp png_ptr)
need_crc = 0; need_crc = 0;
} }
png_read_data(png_ptr, crc_bytes, 4); png_default_read_data(png_ptr, crc_bytes, 4);
if (need_crc) if (need_crc)
{ {
@@ -5093,7 +5150,8 @@ struct options_help pngcrush_options[] = {
#endif #endif
#ifdef PNG_iTXt_SUPPORTED #ifdef PNG_iTXt_SUPPORTED
{0, " -itxt b[efore_IDAT]|a[fter_IDAT] \"keyword\" \"text\""}, {0, " -itxt b[efore_IDAT]|a[fter_IDAT] \"keyword\""},
{2, " \"language_code\" \"translated_keyword\" \"text\""},
{2, ""}, {2, ""},
{2, " Uncompressed iTXt chunk to insert (see -text)."}, {2, " Uncompressed iTXt chunk to insert (see -text)."},
{2, ""}, {2, ""},
@@ -5276,7 +5334,8 @@ struct options_help pngcrush_options[] = {
{2, ""}, {2, ""},
#ifdef PNG_iTXt_SUPPORTED #ifdef PNG_iTXt_SUPPORTED
{0, " -zitxt b[efore_IDAT]|a[fter_IDAT] \"keyword\" \"text\""}, {0, " -zitxt b[efore_IDAT]|a[fter_IDAT] \"keyword\""},
{2, " \"language_code\" \"translated_keyword\" \"text\""},
{2, ""}, {2, ""},
{2, " Compressed iTXt chunk to insert (see -text)."}, {2, " Compressed iTXt chunk to insert (see -text)."},
{2, ""}, {2, ""},

View File

@@ -58,7 +58,6 @@
#define PNG_NO_WRITE_tIME #define PNG_NO_WRITE_tIME
#define PNG_NO_INFO_IMAGE #define PNG_NO_INFO_IMAGE
#define PNG_NO_READ_USER_CHUNKS
#define PNG_EASY_ACCESS #define PNG_EASY_ACCESS
#define PNG_NO_READ_DITHER #define PNG_NO_READ_DITHER
#define PNG_NO_READ_EMPTY_PLTE #define PNG_NO_READ_EMPTY_PLTE

View File

@@ -1,9 +1,9 @@
/* pngerror.c - stub functions for i/o and memory allocation /* pngerror.c - stub functions for i/o and memory allocation
* *
* libpng version 1.2.8 - December 3, 2004 * Last changed in libpng 1.2.9 March 22, 2006
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2006 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@@ -16,6 +16,7 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
static void /* PRIVATE */ static void /* PRIVATE */
png_default_error PNGARG((png_structp png_ptr, png_default_error PNGARG((png_structp png_ptr,
png_const_charp error_message)); png_const_charp error_message));
@@ -33,33 +34,37 @@ png_error(png_structp png_ptr, png_const_charp error_message)
{ {
#ifdef PNG_ERROR_NUMBERS_SUPPORTED #ifdef PNG_ERROR_NUMBERS_SUPPORTED
char msg[16]; char msg[16];
if (png_ptr->flags&(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) if (png_ptr != NULL)
{ {
if (*error_message == '#') if (png_ptr->flags&
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
{ {
int offset; if (*error_message == '#')
for (offset=1; offset<15; offset++) {
if (*(error_message+offset) == ' ') int offset;
break; for (offset=1; offset<15; offset++)
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT) if (*(error_message+offset) == ' ')
{ break;
int i; if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
for (i=0; i<offset-1; i++) {
msg[i]=error_message[i+1]; int i;
msg[i]='\0'; for (i=0; i<offset-1; i++)
error_message=msg; msg[i]=error_message[i+1];
} msg[i]='\0';
else error_message=msg;
error_message+=offset; }
} else
else error_message+=offset;
{ }
if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT) else
{ {
msg[0]='0'; if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
msg[1]='\0'; {
error_message=msg; msg[0]='0';
} msg[1]='\0';
error_message=msg;
}
}
} }
} }
#endif #endif
@@ -80,19 +85,23 @@ void PNGAPI
png_warning(png_structp png_ptr, png_const_charp warning_message) png_warning(png_structp png_ptr, png_const_charp warning_message)
{ {
int offset = 0; int offset = 0;
#ifdef PNG_ERROR_NUMBERS_SUPPORTED if (png_ptr != NULL)
if (png_ptr->flags&(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
#endif
{ {
if (*warning_message == '#') #ifdef PNG_ERROR_NUMBERS_SUPPORTED
if (png_ptr->flags&
(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
#endif
{ {
for (offset=1; offset<15; offset++) if (*warning_message == '#')
if (*(warning_message+offset) == ' ') {
break; for (offset=1; offset<15; offset++)
if (*(warning_message+offset) == ' ')
break;
}
} }
if (png_ptr != NULL && png_ptr->warning_fn != NULL)
(*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
} }
if (png_ptr != NULL && png_ptr->warning_fn != NULL)
(*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
else else
png_default_warning(png_ptr, warning_message+offset); png_default_warning(png_ptr, warning_message+offset);
} }
@@ -146,6 +155,8 @@ void PNGAPI
png_chunk_error(png_structp png_ptr, png_const_charp error_message) png_chunk_error(png_structp png_ptr, png_const_charp error_message)
{ {
char msg[18+64]; char msg[18+64];
if (png_ptr == NULL)
png_error(png_ptr, error_message);
png_format_buffer(png_ptr, msg, error_message); png_format_buffer(png_ptr, msg, error_message);
png_error(png_ptr, msg); png_error(png_ptr, msg);
} }
@@ -154,6 +165,8 @@ void PNGAPI
png_chunk_warning(png_structp png_ptr, png_const_charp warning_message) png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
{ {
char msg[18+64]; char msg[18+64];
if (png_ptr == NULL)
png_warning(png_ptr, warning_message);
png_format_buffer(png_ptr, msg, warning_message); png_format_buffer(png_ptr, msg, warning_message);
png_warning(png_ptr, msg); png_warning(png_ptr, msg);
} }
@@ -265,6 +278,8 @@ void PNGAPI
png_set_error_fn(png_structp png_ptr, png_voidp error_ptr, png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warning_fn) png_error_ptr error_fn, png_error_ptr warning_fn)
{ {
if (png_ptr == NULL)
return;
png_ptr->error_ptr = error_ptr; png_ptr->error_ptr = error_ptr;
png_ptr->error_fn = error_fn; png_ptr->error_fn = error_fn;
png_ptr->warning_fn = warning_fn; png_ptr->warning_fn = warning_fn;
@@ -278,6 +293,8 @@ png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
png_voidp PNGAPI png_voidp PNGAPI
png_get_error_ptr(png_structp png_ptr) png_get_error_ptr(png_structp png_ptr)
{ {
if (png_ptr == NULL)
return NULL;
return ((png_voidp)png_ptr->error_ptr); return ((png_voidp)png_ptr->error_ptr);
} }
@@ -293,3 +310,4 @@ png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
} }
} }
#endif #endif
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */

View File

@@ -1,3 +1,4 @@
/* pnggccrd.c - mixed C/assembler version of utilities to read a PNG file /* pnggccrd.c - mixed C/assembler version of utilities to read a PNG file
* *
* For Intel x86 CPU (Pentium-MMX or later) and GNU C compiler. * For Intel x86 CPU (Pentium-MMX or later) and GNU C compiler.
@@ -6,9 +7,9 @@
* and http://www.intel.com/drg/pentiumII/appnotes/923/923.htm * and http://www.intel.com/drg/pentiumII/appnotes/923/923.htm
* for Intel's performance analysis of the MMX vs. non-MMX code. * for Intel's performance analysis of the MMX vs. non-MMX code.
* *
* libpng version 1.2.8 - December 3, 2004 * Last changed in libpng 1.2.9 March 22, 2006
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2006 Glenn Randers-Pehrson
* Copyright (c) 1998, Intel Corporation * Copyright (c) 1998, Intel Corporation
* *
* Based on MSVC code contributed by Nirav Chhatrapati, Intel Corp., 1998. * Based on MSVC code contributed by Nirav Chhatrapati, Intel Corp., 1998.
@@ -255,9 +256,10 @@ static const int FARDATA png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1};
#endif #endif
#if defined(PNG_ASSEMBLER_CODE_SUPPORTED) #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
/* djgpp, Win32, and Cygwin add their own underscores to global variables, /* djgpp, Win32, Cygwin, and OS2 add their own underscores to global variables,
* so define them without: */ * so define them without: */
#if defined(__DJGPP__) || defined(WIN32) || defined(__CYGWIN__) #if defined(__DJGPP__) || defined(WIN32) || defined(__CYGWIN__) || \
defined(__OS2__)
# define _mmx_supported mmx_supported # define _mmx_supported mmx_supported
# define _const4 const4 # define _const4 const4
# define _const6 const6 # define _const6 const6
@@ -1737,6 +1739,7 @@ png_do_read_interlace(png_structp png_ptr)
int dummy_value_c; // fix 'forbidden register spilled' int dummy_value_c; // fix 'forbidden register spilled'
int dummy_value_S; int dummy_value_S;
int dummy_value_D; int dummy_value_D;
int dummy_value_a;
__asm__ __volatile__ ( __asm__ __volatile__ (
"subl $21, %%edi \n\t" "subl $21, %%edi \n\t"
@@ -1744,7 +1747,7 @@ png_do_read_interlace(png_structp png_ptr)
".loop3_pass0: \n\t" ".loop3_pass0: \n\t"
"movd (%%esi), %%mm0 \n\t" // x x x x x 2 1 0 "movd (%%esi), %%mm0 \n\t" // x x x x x 2 1 0
"pand _const4, %%mm0 \n\t" // z z z z z 2 1 0 "pand (%3), %%mm0 \n\t" // z z z z z 2 1 0
"movq %%mm0, %%mm1 \n\t" // z z z z z 2 1 0 "movq %%mm0, %%mm1 \n\t" // z z z z z 2 1 0
"psllq $16, %%mm0 \n\t" // z z z 2 1 0 z z "psllq $16, %%mm0 \n\t" // z z z 2 1 0 z z
"movq %%mm0, %%mm2 \n\t" // z z z 2 1 0 z z "movq %%mm0, %%mm2 \n\t" // z z z 2 1 0 z z
@@ -1769,12 +1772,14 @@ png_do_read_interlace(png_structp png_ptr)
: "=c" (dummy_value_c), // output regs (dummy) : "=c" (dummy_value_c), // output regs (dummy)
"=S" (dummy_value_S), "=S" (dummy_value_S),
"=D" (dummy_value_D) "=D" (dummy_value_D),
"=a" (dummy_value_a)
: "1" (sptr), // esi // input regs : "1" (sptr), // esi // input regs
"2" (dp), // edi "2" (dp), // edi
"0" (width), // ecx "0" (width), // ecx
"rim" (_const4) // %1(?) (0x0000000000FFFFFFLL) "3" (&_const4) // %1(?) (0x0000000000FFFFFFLL)
#if 0 /* %mm0, ..., %mm4 not supported by gcc 2.7.2.3 or egcs 1.1 */ #if 0 /* %mm0, ..., %mm4 not supported by gcc 2.7.2.3 or egcs 1.1 */
: "%mm0", "%mm1", "%mm2" // clobber list : "%mm0", "%mm1", "%mm2" // clobber list
@@ -1787,6 +1792,7 @@ png_do_read_interlace(png_structp png_ptr)
int dummy_value_c; // fix 'forbidden register spilled' int dummy_value_c; // fix 'forbidden register spilled'
int dummy_value_S; int dummy_value_S;
int dummy_value_D; int dummy_value_D;
int dummy_value_a;
__asm__ __volatile__ ( __asm__ __volatile__ (
"subl $9, %%edi \n\t" "subl $9, %%edi \n\t"
@@ -1794,7 +1800,7 @@ png_do_read_interlace(png_structp png_ptr)
".loop3_pass2: \n\t" ".loop3_pass2: \n\t"
"movd (%%esi), %%mm0 \n\t" // x x x x x 2 1 0 "movd (%%esi), %%mm0 \n\t" // x x x x x 2 1 0
"pand _const4, %%mm0 \n\t" // z z z z z 2 1 0 "pand (%3), %%mm0 \n\t" // z z z z z 2 1 0
"movq %%mm0, %%mm1 \n\t" // z z z z z 2 1 0 "movq %%mm0, %%mm1 \n\t" // z z z z z 2 1 0
"psllq $16, %%mm0 \n\t" // z z z 2 1 0 z z "psllq $16, %%mm0 \n\t" // z z z 2 1 0 z z
"movq %%mm0, %%mm2 \n\t" // z z z 2 1 0 z z "movq %%mm0, %%mm2 \n\t" // z z z 2 1 0 z z
@@ -1813,12 +1819,13 @@ png_do_read_interlace(png_structp png_ptr)
: "=c" (dummy_value_c), // output regs (dummy) : "=c" (dummy_value_c), // output regs (dummy)
"=S" (dummy_value_S), "=S" (dummy_value_S),
"=D" (dummy_value_D) "=D" (dummy_value_D),
"=a" (dummy_value_a)
: "1" (sptr), // esi // input regs : "1" (sptr), // esi // input regs
"2" (dp), // edi "2" (dp), // edi
"0" (width), // ecx "0" (width), // ecx
"rim" (_const4) // (0x0000000000FFFFFFLL) "3" (&_const4) // (0x0000000000FFFFFFLL)
#if 0 /* %mm0, ..., %mm2 not supported by gcc 2.7.2.3 or egcs 1.1 */ #if 0 /* %mm0, ..., %mm2 not supported by gcc 2.7.2.3 or egcs 1.1 */
: "%mm0", "%mm1", "%mm2" // clobber list : "%mm0", "%mm1", "%mm2" // clobber list
@@ -1839,6 +1846,8 @@ png_do_read_interlace(png_structp png_ptr)
int dummy_value_c; // fix 'forbidden register spilled' int dummy_value_c; // fix 'forbidden register spilled'
int dummy_value_S; int dummy_value_S;
int dummy_value_D; int dummy_value_D;
int dummy_value_a;
int dummy_value_d;
__asm__ __volatile__ ( __asm__ __volatile__ (
"subl $3, %%esi \n\t" "subl $3, %%esi \n\t"
@@ -1850,14 +1859,14 @@ png_do_read_interlace(png_structp png_ptr)
"movq %%mm0, %%mm1 \n\t" // x x 5 4 3 2 1 0 "movq %%mm0, %%mm1 \n\t" // x x 5 4 3 2 1 0
"movq %%mm0, %%mm2 \n\t" // x x 5 4 3 2 1 0 "movq %%mm0, %%mm2 \n\t" // x x 5 4 3 2 1 0
"psllq $24, %%mm0 \n\t" // 4 3 2 1 0 z z z "psllq $24, %%mm0 \n\t" // 4 3 2 1 0 z z z
"pand _const4, %%mm1 \n\t" // z z z z z 2 1 0 "pand (%3), %%mm1 \n\t" // z z z z z 2 1 0
"psrlq $24, %%mm2 \n\t" // z z z x x 5 4 3 "psrlq $24, %%mm2 \n\t" // z z z x x 5 4 3
"por %%mm1, %%mm0 \n\t" // 4 3 2 1 0 2 1 0 "por %%mm1, %%mm0 \n\t" // 4 3 2 1 0 2 1 0
"movq %%mm2, %%mm3 \n\t" // z z z x x 5 4 3 "movq %%mm2, %%mm3 \n\t" // z z z x x 5 4 3
"psllq $8, %%mm2 \n\t" // z z x x 5 4 3 z "psllq $8, %%mm2 \n\t" // z z x x 5 4 3 z
"movq %%mm0, (%%edi) \n\t" "movq %%mm0, (%%edi) \n\t"
"psrlq $16, %%mm3 \n\t" // z z z z z x x 5 "psrlq $16, %%mm3 \n\t" // z z z z z x x 5
"pand _const6, %%mm3 \n\t" // z z z z z z z 5 "pand (%4), %%mm3 \n\t" // z z z z z z z 5
"por %%mm3, %%mm2 \n\t" // z z x x 5 4 3 5 "por %%mm3, %%mm2 \n\t" // z z x x 5 4 3 5
"subl $6, %%esi \n\t" "subl $6, %%esi \n\t"
"movd %%mm2, 8(%%edi) \n\t" "movd %%mm2, 8(%%edi) \n\t"
@@ -1868,13 +1877,15 @@ png_do_read_interlace(png_structp png_ptr)
: "=c" (dummy_value_c), // output regs (dummy) : "=c" (dummy_value_c), // output regs (dummy)
"=S" (dummy_value_S), "=S" (dummy_value_S),
"=D" (dummy_value_D) "=D" (dummy_value_D),
"=a" (dummy_value_a),
"=d" (dummy_value_d)
: "1" (sptr), // esi // input regs : "1" (sptr), // esi // input regs
"2" (dp), // edi "2" (dp), // edi
"0" (width_mmx), // ecx "0" (width_mmx), // ecx
"rim" (_const4), // 0x0000000000FFFFFFLL "3" (&_const4), // 0x0000000000FFFFFFLL
"rim" (_const6) // 0x00000000000000FFLL "4" (&_const6) // 0x00000000000000FFLL
#if 0 /* %mm0, ..., %mm3 not supported by gcc 2.7.2.3 or egcs 1.1 */ #if 0 /* %mm0, ..., %mm3 not supported by gcc 2.7.2.3 or egcs 1.1 */
: "%mm0", "%mm1" // clobber list : "%mm0", "%mm1" // clobber list
@@ -5339,6 +5350,7 @@ int PNGAPI
png_mmx_support(void) png_mmx_support(void)
{ {
#if defined(PNG_MMX_CODE_SUPPORTED) #if defined(PNG_MMX_CODE_SUPPORTED)
int result;
__asm__ __volatile__ ( __asm__ __volatile__ (
"pushl %%ebx \n\t" // ebx gets clobbered by CPUID instruction "pushl %%ebx \n\t" // ebx gets clobbered by CPUID instruction
"pushl %%ecx \n\t" // so does ecx... "pushl %%ecx \n\t" // so does ecx...
@@ -5380,7 +5392,6 @@ png_mmx_support(void)
"0: \n\t" // .NOT_SUPPORTED: target label for jump instructions "0: \n\t" // .NOT_SUPPORTED: target label for jump instructions
"movl $0, %%eax \n\t" // set return value to 0 "movl $0, %%eax \n\t" // set return value to 0
"1: \n\t" // .RETURN: target label for jump instructions "1: \n\t" // .RETURN: target label for jump instructions
"movl %%eax, _mmx_supported \n\t" // save in global static variable, too
"popl %%edx \n\t" // restore edx "popl %%edx \n\t" // restore edx
"popl %%ecx \n\t" // restore ecx "popl %%ecx \n\t" // restore ecx
"popl %%ebx \n\t" // restore ebx "popl %%ebx \n\t" // restore ebx
@@ -5388,15 +5399,16 @@ png_mmx_support(void)
// "ret \n\t" // DONE: no MMX support // "ret \n\t" // DONE: no MMX support
// (fall through to standard C "ret") // (fall through to standard C "ret")
: // output list (none) : "=a" (result) // output list
: // any variables used on input (none) : // any variables used on input (none)
: "%eax" // clobber list // no clobber list
// , "%ebx", "%ecx", "%edx" // GRR: we handle these manually // , "%ebx", "%ecx", "%edx" // GRR: we handle these manually
// , "memory" // if write to a variable gcc thought was in a reg // , "memory" // if write to a variable gcc thought was in a reg
// , "cc" // "condition codes" (flag bits) // , "cc" // "condition codes" (flag bits)
); );
_mmx_supported = result;
#else #else
_mmx_supported = 0; _mmx_supported = 0;
#endif /* PNG_MMX_CODE_SUPPORTED */ #endif /* PNG_MMX_CODE_SUPPORTED */

View File

@@ -1,9 +1,9 @@
/* pngget.c - retrieval of values from info struct /* pngget.c - retrieval of values from info struct
* *
* libpng 1.2.8 - December 3, 2004 * Last changed in libpng 1.2.9 March 22, 2006
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2006 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/ */
@@ -11,6 +11,8 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
png_uint_32 PNGAPI png_uint_32 PNGAPI
png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag) png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
{ {
@@ -916,6 +918,7 @@ png_get_mmx_rowbytes_threshold (png_structp png_ptr)
return (png_uint_32)(png_ptr? png_ptr->mmx_rowbytes_threshold : 0L); return (png_uint_32)(png_ptr? png_ptr->mmx_rowbytes_threshold : 0L);
} }
#endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */ #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
#endif /* ?PNG_1_0_X */
#ifdef PNG_SET_USER_LIMITS_SUPPORTED #ifdef PNG_SET_USER_LIMITS_SUPPORTED
/* these functions were added to libpng 1.2.6 */ /* these functions were added to libpng 1.2.6 */
@@ -931,4 +934,4 @@ png_get_user_height_max (png_structp png_ptr)
} }
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
#endif /* ?PNG_1_0_X */ #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */

View File

@@ -1,9 +1,9 @@
/* pngmem.c - stub functions for memory allocation /* pngmem.c - stub functions for memory allocation
* *
* libpng version 1.2.8 - December 3, 2004 * Last changed in libpng 1.2.9 March 22, 2006
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2006 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@@ -17,6 +17,8 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
/* Borland DOS special memory handler */ /* Borland DOS special memory handler */
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__) #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
/* if you change this, be sure to change the one in png.h also */ /* if you change this, be sure to change the one in png.h also */
@@ -593,3 +595,4 @@ png_get_mem_ptr(png_structp png_ptr)
return ((png_voidp)png_ptr->mem_ptr); return ((png_voidp)png_ptr->mem_ptr);
} }
#endif /* PNG_USER_MEM_SUPPORTED */ #endif /* PNG_USER_MEM_SUPPORTED */
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */

View File

@@ -1,7 +1,7 @@
/* pngpread.c - read a png file in push mode /* pngpread.c - read a png file in push mode
* *
* libpng version 1.2.8 - December 3, 2004 * Last changed in libpng 1.2.8 - December 3, 2004
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2004 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)

View File

@@ -1,9 +1,9 @@
/* pngread.c - read a PNG file /* pngread.c - read a PNG file
* *
* libpng 1.2.8 - December 3, 2004 * Last changed in libpng 1.2.9 March 22, 2006
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2006 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@@ -14,6 +14,8 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED)
/* Create a PNG structure for reading, and allocate any memory needed. */ /* Create a PNG structure for reading, and allocate any memory needed. */
png_structp PNGAPI png_structp PNGAPI
png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr, png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
@@ -169,10 +171,10 @@ png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
return (png_ptr); return (png_ptr);
} }
#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
/* Initialize PNG structure for reading, and allocate any memory needed. /* Initialize PNG structure for reading, and allocate any memory needed.
This interface is deprecated in favour of the png_create_read_struct(), This interface is deprecated in favour of the png_create_read_struct(),
and it will eventually disappear. */ and it will disappear as of libpng-1.3.0. */
#if defined(PNG_1_0_X) || defined (PNG_1_2_X)
#undef png_read_init #undef png_read_init
void PNGAPI void PNGAPI
png_read_init(png_structp png_ptr) png_read_init(png_structp png_ptr)
@@ -180,7 +182,6 @@ png_read_init(png_structp png_ptr)
/* We only come here via pre-1.0.7-compiled applications */ /* We only come here via pre-1.0.7-compiled applications */
png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0); png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
} }
#endif
void PNGAPI void PNGAPI
png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver, png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
@@ -224,6 +225,7 @@ png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
} }
png_read_init_3(&png_ptr, user_png_ver, png_struct_size); png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
} }
#endif /* PNG_1_0_X || PNG_1_2_X */
void PNGAPI void PNGAPI
png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
@@ -806,7 +808,7 @@ png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
* not called png_set_interlace_handling(), the display_row buffer will * not called png_set_interlace_handling(), the display_row buffer will
* be ignored, so pass NULL to it. * be ignored, so pass NULL to it.
* *
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.2.8 * [*] png_handle_alpha() does not exist yet, as of this version of libpng
*/ */
void PNGAPI void PNGAPI
@@ -856,7 +858,7 @@ png_read_rows(png_structp png_ptr, png_bytepp row,
* only call this function once. If you desire to have an image for * only call this function once. If you desire to have an image for
* each pass of a interlaced image, use png_read_rows() instead. * each pass of a interlaced image, use png_read_rows() instead.
* *
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.2.8 * [*] png_handle_alpha() does not exist yet, as of this version of libpng
*/ */
void PNGAPI void PNGAPI
png_read_image(png_structp png_ptr, png_bytepp image) png_read_image(png_structp png_ptr, png_bytepp image)
@@ -1452,5 +1454,6 @@ png_read_png(png_structp png_ptr, png_infop info_ptr,
/* quiet compiler warnings */ return; /* quiet compiler warnings */ return;
} }
#endif #endif /* PNG_INFO_IMAGE_SUPPORTED */
#endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */ #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
#endif /* PNG_READ_SUPPORTED */

View File

@@ -1,9 +1,9 @@
/* pngrio.c - functions for data input /* pngrio.c - functions for data input
* *
* libpng 1.2.8 - December 3, 2004 * Last changed in libpng 1.2.9 March 22, 2006
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2006 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@@ -18,6 +18,8 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED)
/* Read the data from whatever input you are using. The default routine /* Read the data from whatever input you are using. The default routine
reads from a file pointer. Note that this routine sometimes gets called reads from a file pointer. Note that this routine sometimes gets called
with very small lengths, so you should implement some kind of simple with very small lengths, so you should implement some kind of simple
@@ -67,7 +69,7 @@ png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
#define NEAR_BUF_SIZE 1024 #define NEAR_BUF_SIZE 1024
#define MIN(a,b) (a <= b ? a : b) #define MIN(a,b) (a <= b ? a : b)
static void /* PRIVATE */ static void PNGAPI
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length) png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{ {
int check; int check;
@@ -159,3 +161,4 @@ png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
png_ptr->output_flush_fn = NULL; png_ptr->output_flush_fn = NULL;
#endif #endif
} }
#endif /* PNG_READ_SUPPORTED */

View File

@@ -1,9 +1,9 @@
/* pngrtran.c - transforms the data in a row for PNG readers /* pngrtran.c - transforms the data in a row for PNG readers
* *
* libpng version 1.2.8 - December 3, 2004 * Last changed in libpng 1.2.9 March 22, 2006
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2006 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@@ -16,6 +16,8 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED)
/* Set the action on getting a CRC error for an ancillary or critical chunk. */ /* Set the action on getting a CRC error for an ancillary or critical chunk. */
void PNGAPI void PNGAPI
png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action) png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
@@ -549,7 +551,7 @@ void PNGAPI
png_set_expand(png_structp png_ptr) png_set_expand(png_structp png_ptr)
{ {
png_debug(1, "in png_set_expand\n"); png_debug(1, "in png_set_expand\n");
png_ptr->transformations |= PNG_EXPAND; png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
} }
/* GRR 19990627: the following three functions currently are identical /* GRR 19990627: the following three functions currently are identical
@@ -564,30 +566,47 @@ png_set_expand(png_structp png_ptr)
* *
* More to the point, these functions make it obvious what libpng will be * More to the point, these functions make it obvious what libpng will be
* doing, whereas "expand" can (and does) mean any number of things. * doing, whereas "expand" can (and does) mean any number of things.
*
* GRP 20060307: In libpng-1.4.0, png_set_gray_1_2_4_to_8() was modified
* to expand only the sample depth but not to expand the tRNS to alpha.
*/ */
/* Expand paletted images to RGB. */ /* Expand paletted images to RGB. */
void PNGAPI void PNGAPI
png_set_palette_to_rgb(png_structp png_ptr) png_set_palette_to_rgb(png_structp png_ptr)
{ {
png_debug(1, "in png_set_expand\n"); png_debug(1, "in png_set_palette_to_rgb\n");
png_ptr->transformations |= PNG_EXPAND; png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
} }
#if !defined(PNG_1_0_X)
/* Expand grayscale images of less than 8-bit depth to 8 bits. */ /* Expand grayscale images of less than 8-bit depth to 8 bits. */
void PNGAPI void PNGAPI
png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
{
png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
png_ptr->transformations |= PNG_EXPAND_tRNS;
}
#endif
#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
/* Expand grayscale images of less than 8-bit depth to 8 bits. */
/* Deprecated as of libpng-1.2.9 */
void PNGAPI
png_set_gray_1_2_4_to_8(png_structp png_ptr) png_set_gray_1_2_4_to_8(png_structp png_ptr)
{ {
png_debug(1, "in png_set_expand\n"); png_debug(1, "in png_set_gray_1_2_4_to_8\n");
png_ptr->transformations |= PNG_EXPAND; png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
} }
#endif
/* Expand tRNS chunks to alpha channels. */ /* Expand tRNS chunks to alpha channels. */
void PNGAPI void PNGAPI
png_set_tRNS_to_alpha(png_structp png_ptr) png_set_tRNS_to_alpha(png_structp png_ptr)
{ {
png_debug(1, "in png_set_expand\n"); png_debug(1, "in png_set_expand\n");
png_ptr->transformations |= PNG_EXPAND; png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
} }
#endif /* defined(PNG_READ_EXPAND_SUPPORTED) */ #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
@@ -705,23 +724,41 @@ png_init_read_transformations(png_structp png_ptr)
{ {
if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */ if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
{ {
/* expand background chunk. */ /* expand background and tRNS chunks */
switch (png_ptr->bit_depth) switch (png_ptr->bit_depth)
{ {
case 1: case 1:
png_ptr->background.gray *= (png_uint_16)0xff; png_ptr->background.gray *= (png_uint_16)0xff;
png_ptr->background.red = png_ptr->background.green png_ptr->background.red = png_ptr->background.green
= png_ptr->background.blue = png_ptr->background.gray; = png_ptr->background.blue = png_ptr->background.gray;
if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
{
png_ptr->trans_values.gray *= (png_uint_16)0xff;
png_ptr->trans_values.red = png_ptr->trans_values.green
= png_ptr->trans_values.blue = png_ptr->trans_values.gray;
}
break; break;
case 2: case 2:
png_ptr->background.gray *= (png_uint_16)0x55; png_ptr->background.gray *= (png_uint_16)0x55;
png_ptr->background.red = png_ptr->background.green png_ptr->background.red = png_ptr->background.green
= png_ptr->background.blue = png_ptr->background.gray; = png_ptr->background.blue = png_ptr->background.gray;
if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
{
png_ptr->trans_values.gray *= (png_uint_16)0x55;
png_ptr->trans_values.red = png_ptr->trans_values.green
= png_ptr->trans_values.blue = png_ptr->trans_values.gray;
}
break; break;
case 4: case 4:
png_ptr->background.gray *= (png_uint_16)0x11; png_ptr->background.gray *= (png_uint_16)0x11;
png_ptr->background.red = png_ptr->background.green png_ptr->background.red = png_ptr->background.green
= png_ptr->background.blue = png_ptr->background.gray; = png_ptr->background.blue = png_ptr->background.gray;
if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
{
png_ptr->trans_values.gray *= (png_uint_16)0x11;
png_ptr->trans_values.red = png_ptr->trans_values.green
= png_ptr->trans_values.blue = png_ptr->trans_values.gray;
}
break; break;
case 8: case 8:
case 16: case 16:
@@ -743,7 +780,7 @@ png_init_read_transformations(png_structp png_ptr)
if (png_ptr->transformations & PNG_INVERT_ALPHA) if (png_ptr->transformations & PNG_INVERT_ALPHA)
{ {
#if defined(PNG_READ_EXPAND_SUPPORTED) #if defined(PNG_READ_EXPAND_SUPPORTED)
if (!(png_ptr->transformations & PNG_EXPAND)) if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
#endif #endif
{ {
/* invert the alpha channel (in tRNS) unless the pixels are /* invert the alpha channel (in tRNS) unless the pixels are
@@ -780,7 +817,8 @@ png_init_read_transformations(png_structp png_ptr)
png_ptr->transformations &= (~PNG_GAMMA); png_ptr->transformations &= (~PNG_GAMMA);
} }
if (png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
png_ptr->gamma != 0.0)
{ {
png_build_gamma_table(png_ptr); png_build_gamma_table(png_ptr);
#if defined(PNG_READ_BACKGROUND_SUPPORTED) #if defined(PNG_READ_BACKGROUND_SUPPORTED)
@@ -1042,7 +1080,7 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
{ {
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{ {
if (png_ptr->num_trans) if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA; info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
else else
info_ptr->color_type = PNG_COLOR_TYPE_RGB; info_ptr->color_type = PNG_COLOR_TYPE_RGB;
@@ -1052,7 +1090,12 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
else else
{ {
if (png_ptr->num_trans) if (png_ptr->num_trans)
info_ptr->color_type |= PNG_COLOR_MASK_ALPHA; {
if (png_ptr->transformations & PNG_EXPAND_tRNS)
info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
else
info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
}
if (info_ptr->bit_depth < 8) if (info_ptr->bit_depth < 8)
info_ptr->bit_depth = 8; info_ptr->bit_depth = 8;
info_ptr->num_trans = 0; info_ptr->num_trans = 0;
@@ -1086,6 +1129,16 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
info_ptr->bit_depth = 8; info_ptr->bit_depth = 8;
#endif #endif
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
if (png_ptr->transformations & PNG_GRAY_TO_RGB)
info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
#endif
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
if (png_ptr->transformations & PNG_RGB_TO_GRAY)
info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
#endif
#if defined(PNG_READ_DITHER_SUPPORTED) #if defined(PNG_READ_DITHER_SUPPORTED)
if (png_ptr->transformations & PNG_DITHER) if (png_ptr->transformations & PNG_DITHER)
{ {
@@ -1103,16 +1156,6 @@ png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
info_ptr->bit_depth = 8; info_ptr->bit_depth = 8;
#endif #endif
#if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
if (png_ptr->transformations & PNG_GRAY_TO_RGB)
info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
#endif
#if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
if (png_ptr->transformations & PNG_RGB_TO_GRAY)
info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
#endif
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
info_ptr->channels = 1; info_ptr->channels = 1;
else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR) else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
@@ -1198,7 +1241,7 @@ png_do_read_transformations(png_structp png_ptr)
} }
else else
{ {
if (png_ptr->num_trans) if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1, png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
&(png_ptr->trans_values)); &(png_ptr->trans_values));
else else
@@ -3601,8 +3644,8 @@ png_do_expand_palette(png_row_infop row_info, png_bytep row,
} }
} }
/* If the bit depth < 8, it is expanded to 8. Also, if the /* If the bit depth < 8, it is expanded to 8. Also, if the already
* transparency value is supplied, an alpha channel is built. * expanded transparency value is supplied, an alpha channel is built.
*/ */
void /* PRIVATE */ void /* PRIVATE */
png_do_expand(png_row_infop row_info, png_bytep row, png_do_expand(png_row_infop row_info, png_bytep row,
@@ -3906,210 +3949,208 @@ void /* PRIVATE */
png_build_gamma_table(png_structp png_ptr) png_build_gamma_table(png_structp png_ptr)
{ {
png_debug(1, "in png_build_gamma_table\n"); png_debug(1, "in png_build_gamma_table\n");
if(png_ptr->gamma != 0.0)
if (png_ptr->bit_depth <= 8)
{ {
if (png_ptr->bit_depth <= 8) int i;
{ double g;
int i;
double g;
if (png_ptr->screen_gamma > .000001) if (png_ptr->screen_gamma > .000001)
g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma); g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
else else
g = 1.0; g = 1.0;
png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr, png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
(png_uint_32)256); (png_uint_32)256);
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0, png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
g) * 255.0 + .5); g) * 255.0 + .5);
} }
#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY)) if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
{ {
g = 1.0 / (png_ptr->gamma); g = 1.0 / (png_ptr->gamma);
png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr, png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
(png_uint_32)256); (png_uint_32)256);
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0, png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
g) * 255.0 + .5); g) * 255.0 + .5);
} }
png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr, png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
(png_uint_32)256); (png_uint_32)256);
if(png_ptr->screen_gamma > 0.000001) if(png_ptr->screen_gamma > 0.000001)
g = 1.0 / png_ptr->screen_gamma; g = 1.0 / png_ptr->screen_gamma;
else else
g = png_ptr->gamma; /* probably doing rgb_to_gray */ g = png_ptr->gamma; /* probably doing rgb_to_gray */
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0, png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
g) * 255.0 + .5); g) * 255.0 + .5);
} }
} }
#endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */ #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
} }
else else
{ {
double g; double g;
int i, j, shift, num; int i, j, shift, num;
int sig_bit; int sig_bit;
png_uint_32 ig; png_uint_32 ig;
if (png_ptr->color_type & PNG_COLOR_MASK_COLOR) if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
{ {
sig_bit = (int)png_ptr->sig_bit.red; sig_bit = (int)png_ptr->sig_bit.red;
if ((int)png_ptr->sig_bit.green > sig_bit) if ((int)png_ptr->sig_bit.green > sig_bit)
sig_bit = png_ptr->sig_bit.green; sig_bit = png_ptr->sig_bit.green;
if ((int)png_ptr->sig_bit.blue > sig_bit) if ((int)png_ptr->sig_bit.blue > sig_bit)
sig_bit = png_ptr->sig_bit.blue; sig_bit = png_ptr->sig_bit.blue;
} }
else else
{ {
sig_bit = (int)png_ptr->sig_bit.gray; sig_bit = (int)png_ptr->sig_bit.gray;
} }
if (sig_bit > 0) if (sig_bit > 0)
shift = 16 - sig_bit; shift = 16 - sig_bit;
else else
shift = 0; shift = 0;
if (png_ptr->transformations & PNG_16_TO_8) if (png_ptr->transformations & PNG_16_TO_8)
{ {
if (shift < (16 - PNG_MAX_GAMMA_8)) if (shift < (16 - PNG_MAX_GAMMA_8))
shift = (16 - PNG_MAX_GAMMA_8); shift = (16 - PNG_MAX_GAMMA_8);
} }
if (shift > 8) if (shift > 8)
shift = 8; shift = 8;
if (shift < 0) if (shift < 0)
shift = 0; shift = 0;
png_ptr->gamma_shift = (png_byte)shift; png_ptr->gamma_shift = (png_byte)shift;
num = (1 << (8 - shift)); num = (1 << (8 - shift));
if (png_ptr->screen_gamma > .000001) if (png_ptr->screen_gamma > .000001)
g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma); g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
else else
g = 1.0; g = 1.0;
png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr, png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
(png_uint_32)(num * png_sizeof (png_uint_16p))); (png_uint_32)(num * png_sizeof (png_uint_16p)));
if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND)) if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
{ {
double fin, fout; double fin, fout;
png_uint_32 last, max; png_uint_32 last, max;
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
{ {
png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr, png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)(256 * png_sizeof (png_uint_16))); (png_uint_32)(256 * png_sizeof (png_uint_16)));
} }
g = 1.0 / g; g = 1.0 / g;
last = 0; last = 0;
for (i = 0; i < 256; i++) for (i = 0; i < 256; i++)
{ {
fout = ((double)i + 0.5) / 256.0; fout = ((double)i + 0.5) / 256.0;
fin = pow(fout, g); fin = pow(fout, g);
max = (png_uint_32)(fin * (double)((png_uint_32)num << 8)); max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
while (last <= max) while (last <= max)
{ {
png_ptr->gamma_16_table[(int)(last & (0xff >> shift))] png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
[(int)(last >> (8 - shift))] = (png_uint_16)( [(int)(last >> (8 - shift))] = (png_uint_16)(
(png_uint_16)i | ((png_uint_16)i << 8)); (png_uint_16)i | ((png_uint_16)i << 8));
last++; last++;
} }
} }
while (last < ((png_uint_32)num << 8)) while (last < ((png_uint_32)num << 8))
{ {
png_ptr->gamma_16_table[(int)(last & (0xff >> shift))] png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
[(int)(last >> (8 - shift))] = (png_uint_16)65535L; [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
last++; last++;
} }
} }
else else
{ {
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
{ {
png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr, png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)(256 * png_sizeof (png_uint_16))); (png_uint_32)(256 * png_sizeof (png_uint_16)));
ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4); ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
for (j = 0; j < 256; j++) for (j = 0; j < 256; j++)
{ {
png_ptr->gamma_16_table[i][j] = png_ptr->gamma_16_table[i][j] =
(png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) / (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
65535.0, g) * 65535.0 + .5); 65535.0, g) * 65535.0 + .5);
} }
} }
} }
#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \ #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
defined(PNG_READ_RGB_TO_GRAY_SUPPORTED) defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY)) if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
{ {
g = 1.0 / (png_ptr->gamma); g = 1.0 / (png_ptr->gamma);
png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr, png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
(png_uint_32)(num * png_sizeof (png_uint_16p ))); (png_uint_32)(num * png_sizeof (png_uint_16p )));
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
{ {
png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr, png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)(256 * png_sizeof (png_uint_16))); (png_uint_32)(256 * png_sizeof (png_uint_16)));
ig = (((png_uint_32)i * ig = (((png_uint_32)i *
(png_uint_32)png_gamma_shift[shift]) >> 4); (png_uint_32)png_gamma_shift[shift]) >> 4);
for (j = 0; j < 256; j++) for (j = 0; j < 256; j++)
{ {
png_ptr->gamma_16_to_1[i][j] = png_ptr->gamma_16_to_1[i][j] =
(png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) / (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
65535.0, g) * 65535.0 + .5); 65535.0, g) * 65535.0 + .5);
} }
} }
if(png_ptr->screen_gamma > 0.000001) if(png_ptr->screen_gamma > 0.000001)
g = 1.0 / png_ptr->screen_gamma; g = 1.0 / png_ptr->screen_gamma;
else else
g = png_ptr->gamma; /* probably doing rgb_to_gray */ g = png_ptr->gamma; /* probably doing rgb_to_gray */
png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr, png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
(png_uint_32)(num * png_sizeof (png_uint_16p))); (png_uint_32)(num * png_sizeof (png_uint_16p)));
for (i = 0; i < num; i++) for (i = 0; i < num; i++)
{ {
png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr, png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
(png_uint_32)(256 * png_sizeof (png_uint_16))); (png_uint_32)(256 * png_sizeof (png_uint_16)));
ig = (((png_uint_32)i * ig = (((png_uint_32)i *
(png_uint_32)png_gamma_shift[shift]) >> 4); (png_uint_32)png_gamma_shift[shift]) >> 4);
for (j = 0; j < 256; j++) for (j = 0; j < 256; j++)
{ {
png_ptr->gamma_16_from_1[i][j] = png_ptr->gamma_16_from_1[i][j] =
(png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) / (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
65535.0, g) * 65535.0 + .5); 65535.0, g) * 65535.0 + .5);
} }
} }
} }
#endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */ #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
} }
}
} }
#endif #endif
/* To do: install integer version of png_build_gamma_table here */ /* To do: install integer version of png_build_gamma_table here */
@@ -4175,3 +4216,4 @@ png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
} }
} }
#endif /* PNG_MNG_FEATURES_SUPPORTED */ #endif /* PNG_MNG_FEATURES_SUPPORTED */
#endif /* PNG_READ_SUPPORTED */

View File

@@ -1,8 +1,9 @@
/* pngrutil.c - utilities to read a PNG file /* pngrutil.c - utilities to read a PNG file
* *
* libpng version 1.2.8 - December 3, 2004 * Last changed in libpng 1.2.9 March 22, 2006
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2006 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@@ -13,6 +14,8 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED)
#if defined(_WIN32_WCE) #if defined(_WIN32_WCE)
/* strtod() function is not supported on WindowsCE */ /* strtod() function is not supported on WindowsCE */
# ifdef PNG_FLOATING_POINT_SUPPORTED # ifdef PNG_FLOATING_POINT_SUPPORTED
@@ -37,17 +40,17 @@ __inline double strtod(const char *nptr, char **endptr)
# endif # endif
#endif #endif
png_uint_32 /* PRIVATE */ png_uint_32 PNGAPI
png_get_uint_31(png_structp png_ptr, png_bytep buf) png_get_uint_31(png_structp png_ptr, png_bytep buf)
{ {
png_uint_32 i = png_get_uint_32(buf); png_uint_32 i = png_get_uint_32(buf);
if (i > PNG_UINT_31_MAX) if (i > PNG_UINT_31_MAX)
png_error(png_ptr, "PNG unsigned integer out of range.\n"); png_error(png_ptr, "PNG unsigned integer out of range.");
return (i); return (i);
} }
#ifndef PNG_READ_BIG_ENDIAN_SUPPORTED #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
/* Grab an unsigned 32-bit integer from a buffer in big-endian format. */ /* Grab an unsigned 32-bit integer from a buffer in big-endian format. */
png_uint_32 /* PRIVATE */ png_uint_32 PNGAPI
png_get_uint_32(png_bytep buf) png_get_uint_32(png_bytep buf)
{ {
png_uint_32 i = ((png_uint_32)(*buf) << 24) + png_uint_32 i = ((png_uint_32)(*buf) << 24) +
@@ -58,11 +61,10 @@ png_get_uint_32(png_bytep buf)
return (i); return (i);
} }
#if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_READ_oFFs_SUPPORTED)
/* Grab a signed 32-bit integer from a buffer in big-endian format. The /* Grab a signed 32-bit integer from a buffer in big-endian format. The
* data is stored in the PNG file in two's complement format, and it is * data is stored in the PNG file in two's complement format, and it is
* assumed that the machine format for signed integers is the same. */ * assumed that the machine format for signed integers is the same. */
png_int_32 /* PRIVATE */ png_int_32 PNGAPI
png_get_int_32(png_bytep buf) png_get_int_32(png_bytep buf)
{ {
png_int_32 i = ((png_int_32)(*buf) << 24) + png_int_32 i = ((png_int_32)(*buf) << 24) +
@@ -72,10 +74,9 @@ png_get_int_32(png_bytep buf)
return (i); return (i);
} }
#endif /* PNG_READ_pCAL_SUPPORTED */
/* Grab an unsigned 16-bit integer from a buffer in big-endian format. */ /* Grab an unsigned 16-bit integer from a buffer in big-endian format. */
png_uint_16 /* PRIVATE */ png_uint_16 PNGAPI
png_get_uint_16(png_bytep buf) png_get_uint_16(png_bytep buf)
{ {
png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) + png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
@@ -619,7 +620,7 @@ png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#if defined(PNG_READ_sRGB_SUPPORTED) #if defined(PNG_READ_sRGB_SUPPORTED)
if (info_ptr->valid & PNG_INFO_sRGB) if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
if (PNG_OUT_OF_RANGE(igamma, 45500L, 500)) if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
{ {
png_warning(png_ptr, png_warning(png_ptr,
@@ -777,8 +778,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_crc_read(png_ptr, buf, 4); png_crc_read(png_ptr, buf, 4);
uint_y = png_get_uint_32(buf); uint_y = png_get_uint_32(buf);
if (uint_x > 80000L || uint_y > 80000L || if (uint_x + uint_y > 100000L)
uint_x + uint_y > 100000L)
{ {
png_warning(png_ptr, "Invalid cHRM red point"); png_warning(png_ptr, "Invalid cHRM red point");
png_crc_finish(png_ptr, 16); png_crc_finish(png_ptr, 16);
@@ -793,8 +793,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_crc_read(png_ptr, buf, 4); png_crc_read(png_ptr, buf, 4);
uint_y = png_get_uint_32(buf); uint_y = png_get_uint_32(buf);
if (uint_x > 80000L || uint_y > 80000L || if (uint_x + uint_y > 100000L)
uint_x + uint_y > 100000L)
{ {
png_warning(png_ptr, "Invalid cHRM green point"); png_warning(png_ptr, "Invalid cHRM green point");
png_crc_finish(png_ptr, 8); png_crc_finish(png_ptr, 8);
@@ -809,8 +808,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
png_crc_read(png_ptr, buf, 4); png_crc_read(png_ptr, buf, 4);
uint_y = png_get_uint_32(buf); uint_y = png_get_uint_32(buf);
if (uint_x > 80000L || uint_y > 80000L || if (uint_x + uint_y > 100000L)
uint_x + uint_y > 100000L)
{ {
png_warning(png_ptr, "Invalid cHRM blue point"); png_warning(png_ptr, "Invalid cHRM blue point");
png_crc_finish(png_ptr, 0); png_crc_finish(png_ptr, 0);
@@ -831,7 +829,7 @@ png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#endif #endif
#if defined(PNG_READ_sRGB_SUPPORTED) #if defined(PNG_READ_sRGB_SUPPORTED)
if (info_ptr->valid & PNG_INFO_sRGB) if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
{ {
if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) || if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) || PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
@@ -926,7 +924,7 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED) #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
if ((info_ptr->valid & PNG_INFO_gAMA)) if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
{ {
png_fixed_point igamma; png_fixed_point igamma;
#ifdef PNG_FIXED_POINT_SUPPORTED #ifdef PNG_FIXED_POINT_SUPPORTED
@@ -955,7 +953,7 @@ png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
#ifdef PNG_READ_cHRM_SUPPORTED #ifdef PNG_READ_cHRM_SUPPORTED
#ifdef PNG_FIXED_POINT_SUPPORTED #ifdef PNG_FIXED_POINT_SUPPORTED
if (info_ptr->valid & PNG_INFO_cHRM) if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) || if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) || PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) || PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
@@ -1079,7 +1077,7 @@ png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
if(profile_size > profile_length) if(profile_size > profile_length)
{ {
png_free(png_ptr, chunkdata); png_free(png_ptr, chunkdata);
png_warning(png_ptr, "Ignoring truncated iCCP profile.\n"); png_warning(png_ptr, "Ignoring truncated iCCP profile.");
return; return;
} }
@@ -1160,7 +1158,7 @@ png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
return; return;
} }
new_palette.nentries = (png_uint_32) (data_length / entry_size); new_palette.nentries = (png_int_32) ( data_length / entry_size);
if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX / if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
png_sizeof(png_sPLT_entry))) png_sizeof(png_sPLT_entry)))
{ {
@@ -2170,7 +2168,8 @@ png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
} }
#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
(png_ptr->read_user_chunk_fn != NULL))
{ {
png_unknown_chunk chunk; png_unknown_chunk chunk;
@@ -3122,3 +3121,4 @@ defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
png_ptr->flags |= PNG_FLAG_ROW_INIT; png_ptr->flags |= PNG_FLAG_ROW_INIT;
} }
#endif /* PNG_READ_SUPPORTED */

View File

@@ -1,9 +1,9 @@
/* pngset.c - storage of image information into info struct /* pngset.c - storage of image information into info struct
* *
* libpng 1.2.8 - December 3, 2004 * Last changed in libpng 1.2.9 March 22, 2006
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2006 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *
@@ -16,6 +16,8 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
#if defined(PNG_bKGD_SUPPORTED) #if defined(PNG_bKGD_SUPPORTED)
void PNGAPI void PNGAPI
png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background) png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
@@ -100,6 +102,7 @@ png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
"Ignoring attempt to set negative chromaticity value"); "Ignoring attempt to set negative chromaticity value");
return; return;
} }
#ifdef PNG_FLOATING_POINT_SUPPORTED
if (white_x > (double) PNG_UINT_31_MAX || if (white_x > (double) PNG_UINT_31_MAX ||
white_y > (double) PNG_UINT_31_MAX || white_y > (double) PNG_UINT_31_MAX ||
red_x > (double) PNG_UINT_31_MAX || red_x > (double) PNG_UINT_31_MAX ||
@@ -108,6 +111,16 @@ png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
green_y > (double) PNG_UINT_31_MAX || green_y > (double) PNG_UINT_31_MAX ||
blue_x > (double) PNG_UINT_31_MAX || blue_x > (double) PNG_UINT_31_MAX ||
blue_y > (double) PNG_UINT_31_MAX) blue_y > (double) PNG_UINT_31_MAX)
#else
if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
#endif
{ {
png_warning(png_ptr, png_warning(png_ptr,
"Ignoring attempt to set chromaticity value exceeding 21474.83"); "Ignoring attempt to set chromaticity value exceeding 21474.83");
@@ -209,19 +222,21 @@ png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
png_debug1(1, "in %s storage function\n", "hIST"); png_debug1(1, "in %s storage function\n", "hIST");
if (png_ptr == NULL || info_ptr == NULL) if (png_ptr == NULL || info_ptr == NULL)
return; return;
if (info_ptr->num_palette == 0) if (info_ptr->num_palette <= 0 || info_ptr->num_palette
> PNG_MAX_PALETTE_LENGTH)
{ {
png_warning(png_ptr, png_warning(png_ptr,
"Palette size 0, hIST allocation skipped."); "Invalid palette size, hIST allocation skipped.");
return; return;
} }
#ifdef PNG_FREE_ME_SUPPORTED #ifdef PNG_FREE_ME_SUPPORTED
png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0); png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
#endif #endif
/* Changed from info->num_palette to 256 in version 1.2.1 */ /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in version
1.2.1 */
png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr, png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
(png_uint_32)(256 * png_sizeof (png_uint_16))); (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
if (png_ptr->hist == NULL) if (png_ptr->hist == NULL)
{ {
png_warning(png_ptr, "Insufficient memory for hIST chunk data."); png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
@@ -303,7 +318,7 @@ png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
* 5. The color_type is RGB or RGBA * 5. The color_type is RGB or RGBA
*/ */
if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted) if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
png_warning(png_ptr,"MNG features are not allowed in a PNG datastream\n"); png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
if(filter_type != PNG_FILTER_TYPE_BASE) if(filter_type != PNG_FILTER_TYPE_BASE)
{ {
if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
@@ -517,6 +532,17 @@ png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
if (png_ptr == NULL || info_ptr == NULL) if (png_ptr == NULL || info_ptr == NULL)
return; return;
if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
{
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
png_error(png_ptr, "Invalid palette length");
else
{
png_warning(png_ptr, "Invalid palette length");
return;
}
}
/* /*
* It may not actually be necessary to set png_ptr->palette here; * It may not actually be necessary to set png_ptr->palette here;
* we do it for backward compatibility with the way the png_handle_tRNS * we do it for backward compatibility with the way the png_handle_tRNS
@@ -526,11 +552,13 @@ png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0); png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
#endif #endif
/* Changed in libpng-1.2.1 to allocate 256 instead of num_palette entries, /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead
of num_palette entries,
in case of an invalid PNG file that has too-large sample values. */ in case of an invalid PNG file that has too-large sample values. */
png_ptr->palette = (png_colorp)png_malloc(png_ptr, png_ptr->palette = (png_colorp)png_malloc(png_ptr,
256 * png_sizeof(png_color)); PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
png_memset(png_ptr->palette, 0, 256 * png_sizeof(png_color)); png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
png_sizeof(png_color));
png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color)); png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
info_ptr->palette = png_ptr->palette; info_ptr->palette = png_ptr->palette;
info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette; info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
@@ -890,10 +918,11 @@ png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
#ifdef PNG_FREE_ME_SUPPORTED #ifdef PNG_FREE_ME_SUPPORTED
png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0); png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
#endif #endif
/* Changed from num_trans to 256 in version 1.2.1 */ /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */
png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr, png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
(png_uint_32)256); (png_uint_32)PNG_MAX_PALETTE_LENGTH);
png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans); if (num_trans <= PNG_MAX_PALETTE_LENGTH)
png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
#ifdef PNG_FREE_ME_SUPPORTED #ifdef PNG_FREE_ME_SUPPORTED
info_ptr->free_me |= PNG_FREE_TRNS; info_ptr->free_me |= PNG_FREE_TRNS;
#else #else
@@ -921,6 +950,9 @@ png_set_sPLT(png_structp png_ptr,
png_sPLT_tp np; png_sPLT_tp np;
int i; int i;
if (png_ptr == NULL || info_ptr == NULL)
return;
np = (png_sPLT_tp)png_malloc_warn(png_ptr, np = (png_sPLT_tp)png_malloc_warn(png_ptr,
(info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t)); (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
if (np == NULL) if (np == NULL)
@@ -1023,13 +1055,14 @@ png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
} }
#endif #endif
#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
#if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \ #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED) defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
void PNGAPI void PNGAPI
png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted) png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
{ {
/* This function is deprecated in favor of png_permit_mng_features() /* This function is deprecated in favor of png_permit_mng_features()
and will be removed from libpng-2.0.0 */ and will be removed from libpng-1.3.0 */
png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n"); png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
if (png_ptr == NULL) if (png_ptr == NULL)
return; return;
@@ -1038,6 +1071,7 @@ png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE))); ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
} }
#endif #endif
#endif
#if defined(PNG_MNG_FEATURES_SUPPORTED) #if defined(PNG_MNG_FEATURES_SUPPORTED)
png_uint_32 PNGAPI png_uint_32 PNGAPI
@@ -1059,6 +1093,8 @@ png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
{ {
png_bytep new_list, p; png_bytep new_list, p;
int i, old_num_chunks; int i, old_num_chunks;
if (png_ptr == NULL)
return;
if (num_chunks == 0) if (num_chunks == 0)
{ {
if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE) if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
@@ -1102,6 +1138,8 @@ png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
png_user_chunk_ptr read_user_chunk_fn) png_user_chunk_ptr read_user_chunk_fn)
{ {
png_debug(1, "in png_set_read_user_chunk_fn\n"); png_debug(1, "in png_set_read_user_chunk_fn\n");
if (png_ptr == NULL)
return;
png_ptr->read_user_chunk_fn = read_user_chunk_fn; png_ptr->read_user_chunk_fn = read_user_chunk_fn;
png_ptr->user_chunk_ptr = user_chunk_ptr; png_ptr->user_chunk_ptr = user_chunk_ptr;
} }
@@ -1128,6 +1166,8 @@ png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
void PNGAPI void PNGAPI
png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size) png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
{ {
if (png_ptr == NULL)
return;
if(png_ptr->zbuf) if(png_ptr->zbuf)
png_free(png_ptr, png_ptr->zbuf); png_free(png_ptr, png_ptr->zbuf);
png_ptr->zbuf_size = (png_size_t)size; png_ptr->zbuf_size = (png_size_t)size;
@@ -1154,6 +1194,9 @@ png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
png_uint_32 settable_asm_flags; png_uint_32 settable_asm_flags;
png_uint_32 settable_mmx_flags; png_uint_32 settable_mmx_flags;
if (png_ptr == NULL)
return;
settable_mmx_flags = settable_mmx_flags =
#ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW #ifdef PNG_HAVE_ASSEMBLER_COMBINE_ROW
PNG_ASM_FLAG_MMX_READ_COMBINE_ROW | PNG_ASM_FLAG_MMX_READ_COMBINE_ROW |
@@ -1196,6 +1239,8 @@ png_set_mmx_thresholds (png_structp png_ptr,
png_byte mmx_bitdepth_threshold, png_byte mmx_bitdepth_threshold,
png_uint_32 mmx_rowbytes_threshold) png_uint_32 mmx_rowbytes_threshold)
{ {
if (png_ptr == NULL)
return;
png_ptr->mmx_bitdepth_threshold = mmx_bitdepth_threshold; png_ptr->mmx_bitdepth_threshold = mmx_bitdepth_threshold;
png_ptr->mmx_rowbytes_threshold = mmx_rowbytes_threshold; png_ptr->mmx_rowbytes_threshold = mmx_rowbytes_threshold;
} }
@@ -1217,3 +1262,4 @@ png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
#endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */ #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
#endif /* ?PNG_1_0_X */ #endif /* ?PNG_1_0_X */
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */

View File

@@ -1,7 +1,7 @@
/* pngtest.c - a simple test program to test libpng /* pngtest.c - a simple test program to test libpng
* *
* libpng 1.2.8 - December 3, 2004 * Last changed in libpng 1.2.6 - August 15, 2004
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2004 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
@@ -1551,4 +1551,4 @@ main(int argc, char *argv[])
} }
/* Generate a compiler error if there is an old png.h in the search path. */ /* Generate a compiler error if there is an old png.h in the search path. */
typedef version_1_2_8 your_png_h_is_not_version_1_2_8; typedef version_1_2_9beta11 your_png_h_is_not_version_1_2_9beta11;

View File

@@ -1,9 +1,9 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers) /* pngtrans.c - transforms the data in a row (used by both readers and writers)
* *
* libpng 1.2.8 - December 3, 2004 * Last changed in libpng 1.2.9 March 22, 2006
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2006 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/ */
@@ -11,6 +11,7 @@
#define PNG_INTERNAL #define PNG_INTERNAL
#include "png.h" #include "png.h"
#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED) #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
/* turn on BGR-to-RGB mapping */ /* turn on BGR-to-RGB mapping */
void PNGAPI void PNGAPI
@@ -241,7 +242,7 @@ png_do_swap(png_row_infop row_info, png_bytep row)
#endif #endif
#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED) #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
static png_byte onebppswaptable[256] = { static PNG_CONST png_byte onebppswaptable[256] = {
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8, 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
@@ -276,7 +277,7 @@ static png_byte onebppswaptable[256] = {
0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
}; };
static png_byte twobppswaptable[256] = { static PNG_CONST png_byte twobppswaptable[256] = {
0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0, 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0, 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4, 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
@@ -311,7 +312,7 @@ static png_byte twobppswaptable[256] = {
0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
}; };
static png_byte fourbppswaptable[256] = { static PNG_CONST png_byte fourbppswaptable[256] = {
0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0, 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71, 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
@@ -362,11 +363,11 @@ png_do_packswap(png_row_infop row_info, png_bytep row)
end = row + row_info->rowbytes; end = row + row_info->rowbytes;
if (row_info->bit_depth == 1) if (row_info->bit_depth == 1)
table = onebppswaptable; table = (png_bytep)onebppswaptable;
else if (row_info->bit_depth == 2) else if (row_info->bit_depth == 2)
table = twobppswaptable; table = (png_bytep)twobppswaptable;
else if (row_info->bit_depth == 4) else if (row_info->bit_depth == 4)
table = fourbppswaptable; table = (png_bytep)fourbppswaptable;
else else
return; return;
@@ -648,3 +649,4 @@ png_get_user_transform_ptr(png_structp png_ptr)
return (NULL); return (NULL);
#endif #endif
} }
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */

View File

@@ -1,8 +1,9 @@
/* pngvcrd.c - mixed C/assembler version of utilities to read a PNG file /* pngvcrd.c - mixed C/assembler version of utilities to read a PNG file
* *
* For Intel x86 CPU and Microsoft Visual C++ compiler * For Intel x86 CPU and Microsoft Visual C++ compiler
* *
* libpng version 1.2.8 - December 3, 2004 * Last changed in libpng 1.2.6 - August 15, 2004
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2004 Glenn Randers-Pehrson
* Copyright (c) 1998, Intel Corporation * Copyright (c) 1998, Intel Corporation

View File

@@ -1,9 +1,9 @@
/* pngwio.c - functions for data output /* pngwio.c - functions for data output
* *
* libpng 1.2.8 - December 3, 2004 * Last changed in libpng 1.2.3 - May 21, 2002
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2002 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
* *

View File

@@ -1,9 +1,9 @@
/* pngwrite.c - general routines to write a PNG file /* pngwrite.c - general routines to write a PNG file
* *
* libpng 1.2.8 - December 3, 2004 * Last changed in libpng 1.2.9 March 22, 2006
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2006 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/ */
@@ -26,13 +26,15 @@ void PNGAPI
png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr) png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
{ {
png_debug(1, "in png_write_info_before_PLTE\n"); png_debug(1, "in png_write_info_before_PLTE\n");
if (png_ptr == NULL || info_ptr == NULL)
return;
if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
{ {
png_write_sig(png_ptr); /* write PNG signature */ png_write_sig(png_ptr); /* write PNG signature */
#if defined(PNG_MNG_FEATURES_SUPPORTED) #if defined(PNG_MNG_FEATURES_SUPPORTED)
if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted)) if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
{ {
png_warning(png_ptr,"MNG features are not allowed in a PNG datastream\n"); png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
png_ptr->mng_features_permitted=0; png_ptr->mng_features_permitted=0;
} }
#endif #endif
@@ -128,13 +130,16 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
png_debug(1, "in png_write_info\n"); png_debug(1, "in png_write_info\n");
if (png_ptr == NULL || info_ptr == NULL)
return;
png_write_info_before_PLTE(png_ptr, info_ptr); png_write_info_before_PLTE(png_ptr, info_ptr);
if (info_ptr->valid & PNG_INFO_PLTE) if (info_ptr->valid & PNG_INFO_PLTE)
png_write_PLTE(png_ptr, info_ptr->palette, png_write_PLTE(png_ptr, info_ptr->palette,
(png_uint_32)info_ptr->num_palette); (png_uint_32)info_ptr->num_palette);
else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
png_error(png_ptr, "Valid palette required for paletted images\n"); png_error(png_ptr, "Valid palette required for paletted images");
#if defined(PNG_WRITE_tRNS_SUPPORTED) #if defined(PNG_WRITE_tRNS_SUPPORTED)
if (info_ptr->valid & PNG_INFO_tRNS) if (info_ptr->valid & PNG_INFO_tRNS)
@@ -183,7 +188,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
info_ptr->scal_s_width, info_ptr->scal_s_height); info_ptr->scal_s_width, info_ptr->scal_s_height);
#else #else
png_warning(png_ptr, png_warning(png_ptr,
"png_write_sCAL not supported; sCAL chunk not written.\n"); "png_write_sCAL not supported; sCAL chunk not written.");
#endif #endif
#endif #endif
#endif #endif
@@ -222,7 +227,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
info_ptr->text[i].lang_key, info_ptr->text[i].lang_key,
info_ptr->text[i].text); info_ptr->text[i].text);
#else #else
png_warning(png_ptr, "Unable to write international text\n"); png_warning(png_ptr, "Unable to write international text");
#endif #endif
/* Mark this chunk as written */ /* Mark this chunk as written */
info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
@@ -236,7 +241,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
info_ptr->text[i].text, 0, info_ptr->text[i].text, 0,
info_ptr->text[i].compression); info_ptr->text[i].compression);
#else #else
png_warning(png_ptr, "Unable to write compressed text\n"); png_warning(png_ptr, "Unable to write compressed text");
#endif #endif
/* Mark this chunk as written */ /* Mark this chunk as written */
info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
@@ -249,7 +254,7 @@ png_write_info(png_structp png_ptr, png_infop info_ptr)
info_ptr->text[i].text, info_ptr->text[i].text,
0); 0);
#else #else
png_warning(png_ptr, "Unable to write uncompressed text\n"); png_warning(png_ptr, "Unable to write uncompressed text");
#endif #endif
/* Mark this chunk as written */ /* Mark this chunk as written */
info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
@@ -290,6 +295,8 @@ void PNGAPI
png_write_end(png_structp png_ptr, png_infop info_ptr) png_write_end(png_structp png_ptr, png_infop info_ptr)
{ {
png_debug(1, "in png_write_end\n"); png_debug(1, "in png_write_end\n");
if (png_ptr == NULL)
return;
if (!(png_ptr->mode & PNG_HAVE_IDAT)) if (!(png_ptr->mode & PNG_HAVE_IDAT))
png_error(png_ptr, "No IDATs written into file"); png_error(png_ptr, "No IDATs written into file");
@@ -323,7 +330,7 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
info_ptr->text[i].lang_key, info_ptr->text[i].lang_key,
info_ptr->text[i].text); info_ptr->text[i].text);
#else #else
png_warning(png_ptr, "Unable to write international text\n"); png_warning(png_ptr, "Unable to write international text");
#endif #endif
/* Mark this chunk as written */ /* Mark this chunk as written */
info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
@@ -336,7 +343,7 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
info_ptr->text[i].text, 0, info_ptr->text[i].text, 0,
info_ptr->text[i].compression); info_ptr->text[i].compression);
#else #else
png_warning(png_ptr, "Unable to write compressed text\n"); png_warning(png_ptr, "Unable to write compressed text");
#endif #endif
/* Mark this chunk as written */ /* Mark this chunk as written */
info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
@@ -348,7 +355,7 @@ png_write_end(png_structp png_ptr, png_infop info_ptr)
png_write_tEXt(png_ptr, info_ptr->text[i].key, png_write_tEXt(png_ptr, info_ptr->text[i].key,
info_ptr->text[i].text, 0); info_ptr->text[i].text, 0);
#else #else
png_warning(png_ptr, "Unable to write uncompressed text\n"); png_warning(png_ptr, "Unable to write uncompressed text");
#endif #endif
/* Mark this chunk as written */ /* Mark this chunk as written */
@@ -554,6 +561,8 @@ png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
} }
/* Initialize png_ptr structure, and allocate any memory needed */ /* Initialize png_ptr structure, and allocate any memory needed */
#if defined(PNG_1_0_X) || defined(PNG_1_2_X)
/* Deprecated. */
#undef png_write_init #undef png_write_init
void PNGAPI void PNGAPI
png_write_init(png_structp png_ptr) png_write_init(png_structp png_ptr)
@@ -604,6 +613,7 @@ png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
} }
png_write_init_3(&png_ptr, user_png_ver, png_struct_size); png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
} }
#endif /* PNG_1_0_X || PNG_1_2_X */
void PNGAPI void PNGAPI
@@ -614,7 +624,12 @@ png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
#ifdef PNG_SETJMP_SUPPORTED #ifdef PNG_SETJMP_SUPPORTED
jmp_buf tmp_jmp; /* to save current jump buffer */ jmp_buf tmp_jmp; /* to save current jump buffer */
#endif #endif
int i = 0; int i = 0;
if (png_ptr == NULL)
return;
do do
{ {
if (user_png_ver[i] != png_libpng_ver[i]) if (user_png_ver[i] != png_libpng_ver[i])
@@ -691,6 +706,10 @@ png_write_rows(png_structp png_ptr, png_bytepp row,
png_bytepp rp; /* row pointer */ png_bytepp rp; /* row pointer */
png_debug(1, "in png_write_rows\n"); png_debug(1, "in png_write_rows\n");
if (png_ptr == NULL)
return;
/* loop through the rows */ /* loop through the rows */
for (i = 0, rp = row; i < num_rows; i++, rp++) for (i = 0, rp = row; i < num_rows; i++, rp++)
{ {
@@ -708,6 +727,9 @@ png_write_image(png_structp png_ptr, png_bytepp image)
int pass, num_pass; /* pass variables */ int pass, num_pass; /* pass variables */
png_bytepp rp; /* points to current row */ png_bytepp rp; /* points to current row */
if (png_ptr == NULL)
return;
png_debug(1, "in png_write_image\n"); png_debug(1, "in png_write_image\n");
#if defined(PNG_WRITE_INTERLACING_SUPPORTED) #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
/* intialize interlace handling. If image is not interlaced, /* intialize interlace handling. If image is not interlaced,
@@ -731,8 +753,11 @@ png_write_image(png_structp png_ptr, png_bytepp image)
void PNGAPI void PNGAPI
png_write_row(png_structp png_ptr, png_bytep row) png_write_row(png_structp png_ptr, png_bytep row)
{ {
if (png_ptr == NULL)
return;
png_debug2(1, "in png_write_row (row %ld, pass %d)\n", png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
png_ptr->row_number, png_ptr->pass); png_ptr->row_number, png_ptr->pass);
/* initialize transformations and other stuff if first time */ /* initialize transformations and other stuff if first time */
if (png_ptr->row_number == 0 && png_ptr->pass == 0) if (png_ptr->row_number == 0 && png_ptr->pass == 0)
{ {
@@ -906,6 +931,8 @@ void PNGAPI
png_set_flush(png_structp png_ptr, int nrows) png_set_flush(png_structp png_ptr, int nrows)
{ {
png_debug(1, "in png_set_flush\n"); png_debug(1, "in png_set_flush\n");
if (png_ptr == NULL)
return;
png_ptr->flush_dist = (nrows < 0 ? 0 : nrows); png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
} }
@@ -916,6 +943,8 @@ png_write_flush(png_structp png_ptr)
int wrote_IDAT; int wrote_IDAT;
png_debug(1, "in png_write_flush\n"); png_debug(1, "in png_write_flush\n");
if (png_ptr == NULL)
return;
/* We have already written out all of the data */ /* We have already written out all of the data */
if (png_ptr->row_number >= png_ptr->num_rows) if (png_ptr->row_number >= png_ptr->num_rows)
return; return;
@@ -1092,6 +1121,8 @@ void PNGAPI
png_set_filter(png_structp png_ptr, int method, int filters) png_set_filter(png_structp png_ptr, int method, int filters)
{ {
png_debug(1, "in png_set_filter\n"); png_debug(1, "in png_set_filter\n");
if (png_ptr == NULL)
return;
#if defined(PNG_MNG_FEATURES_SUPPORTED) #if defined(PNG_MNG_FEATURES_SUPPORTED)
if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
(method == PNG_INTRAPIXEL_DIFFERENCING)) (method == PNG_INTRAPIXEL_DIFFERENCING))
@@ -1200,6 +1231,8 @@ png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
int i; int i;
png_debug(1, "in png_set_filter_heuristics\n"); png_debug(1, "in png_set_filter_heuristics\n");
if (png_ptr == NULL)
return;
if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST) if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
{ {
png_warning(png_ptr, "Unknown filter heuristic method"); png_warning(png_ptr, "Unknown filter heuristic method");
@@ -1312,6 +1345,8 @@ void PNGAPI
png_set_compression_level(png_structp png_ptr, int level) png_set_compression_level(png_structp png_ptr, int level)
{ {
png_debug(1, "in png_set_compression_level\n"); png_debug(1, "in png_set_compression_level\n");
if (png_ptr == NULL)
return;
png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL; png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
png_ptr->zlib_level = level; png_ptr->zlib_level = level;
} }
@@ -1320,6 +1355,8 @@ void PNGAPI
png_set_compression_mem_level(png_structp png_ptr, int mem_level) png_set_compression_mem_level(png_structp png_ptr, int mem_level)
{ {
png_debug(1, "in png_set_compression_mem_level\n"); png_debug(1, "in png_set_compression_mem_level\n");
if (png_ptr == NULL)
return;
png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL; png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
png_ptr->zlib_mem_level = mem_level; png_ptr->zlib_mem_level = mem_level;
} }
@@ -1328,6 +1365,8 @@ void PNGAPI
png_set_compression_strategy(png_structp png_ptr, int strategy) png_set_compression_strategy(png_structp png_ptr, int strategy)
{ {
png_debug(1, "in png_set_compression_strategy\n"); png_debug(1, "in png_set_compression_strategy\n");
if (png_ptr == NULL)
return;
png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY; png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
png_ptr->zlib_strategy = strategy; png_ptr->zlib_strategy = strategy;
} }
@@ -1335,6 +1374,8 @@ png_set_compression_strategy(png_structp png_ptr, int strategy)
void PNGAPI void PNGAPI
png_set_compression_window_bits(png_structp png_ptr, int window_bits) png_set_compression_window_bits(png_structp png_ptr, int window_bits)
{ {
if (png_ptr == NULL)
return;
if (window_bits > 15) if (window_bits > 15)
png_warning(png_ptr, "Only compression windows <= 32k supported by PNG"); png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
else if (window_bits < 8) else if (window_bits < 8)
@@ -1355,6 +1396,8 @@ void PNGAPI
png_set_compression_method(png_structp png_ptr, int method) png_set_compression_method(png_structp png_ptr, int method)
{ {
png_debug(1, "in png_set_compression_method\n"); png_debug(1, "in png_set_compression_method\n");
if (png_ptr == NULL)
return;
if (method != 8) if (method != 8)
png_warning(png_ptr, "Only compression method 8 is supported by PNG"); png_warning(png_ptr, "Only compression method 8 is supported by PNG");
png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD; png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
@@ -1364,6 +1407,8 @@ png_set_compression_method(png_structp png_ptr, int method)
void PNGAPI void PNGAPI
png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn) png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
{ {
if (png_ptr == NULL)
return;
png_ptr->write_row_fn = write_row_fn; png_ptr->write_row_fn = write_row_fn;
} }
@@ -1373,6 +1418,8 @@ png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
write_user_transform_fn) write_user_transform_fn)
{ {
png_debug(1, "in png_set_write_user_transform_fn\n"); png_debug(1, "in png_set_write_user_transform_fn\n");
if (png_ptr == NULL)
return;
png_ptr->transformations |= PNG_USER_TRANSFORM; png_ptr->transformations |= PNG_USER_TRANSFORM;
png_ptr->write_user_transform_fn = write_user_transform_fn; png_ptr->write_user_transform_fn = write_user_transform_fn;
} }
@@ -1384,6 +1431,8 @@ void PNGAPI
png_write_png(png_structp png_ptr, png_infop info_ptr, png_write_png(png_structp png_ptr, png_infop info_ptr,
int transforms, voidp params) int transforms, voidp params)
{ {
if (png_ptr == NULL || info_ptr == NULL)
return;
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
/* invert the alpha channel from opacity to transparency */ /* invert the alpha channel from opacity to transparency */
if (transforms & PNG_TRANSFORM_INVERT_ALPHA) if (transforms & PNG_TRANSFORM_INVERT_ALPHA)

View File

@@ -1,9 +1,9 @@
/* pngwtran.c - transforms the data in a row for PNG writers /* pngwtran.c - transforms the data in a row for PNG writers
* *
* libpng version 1.2.8 - December 3, 2004 * Last changed in libpng 1.2.9 March 22, 2006
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2006 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/ */
@@ -60,14 +60,14 @@ png_do_write_transformations(png_structp png_ptr)
png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1, png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
&(png_ptr->shift)); &(png_ptr->shift));
#endif #endif
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
if (png_ptr->transformations & PNG_INVERT_ALPHA)
png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
if (png_ptr->transformations & PNG_SWAP_ALPHA) if (png_ptr->transformations & PNG_SWAP_ALPHA)
png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1); png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif #endif
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
if (png_ptr->transformations & PNG_INVERT_ALPHA)
png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#if defined(PNG_WRITE_BGR_SUPPORTED) #if defined(PNG_WRITE_BGR_SUPPORTED)
if (png_ptr->transformations & PNG_BGR) if (png_ptr->transformations & PNG_BGR)
png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1); png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
@@ -439,9 +439,12 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
png_uint_32 row_width = row_info->width; png_uint_32 row_width = row_info->width;
for (i = 0, sp = dp = row; i < row_width; i++) for (i = 0, sp = dp = row; i < row_width; i++)
{ {
/* does nothing
*(dp++) = *(sp++); *(dp++) = *(sp++);
*(dp++) = *(sp++); *(dp++) = *(sp++);
*(dp++) = *(sp++); *(dp++) = *(sp++);
*/
sp+=3; dp = sp;
*(dp++) = (png_byte)(255 - *(sp++)); *(dp++) = (png_byte)(255 - *(sp++));
} }
} }
@@ -454,12 +457,15 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
for (i = 0, sp = dp = row; i < row_width; i++) for (i = 0, sp = dp = row; i < row_width; i++)
{ {
/* does nothing
*(dp++) = *(sp++); *(dp++) = *(sp++);
*(dp++) = *(sp++); *(dp++) = *(sp++);
*(dp++) = *(sp++); *(dp++) = *(sp++);
*(dp++) = *(sp++); *(dp++) = *(sp++);
*(dp++) = *(sp++); *(dp++) = *(sp++);
*(dp++) = *(sp++); *(dp++) = *(sp++);
*/
sp+=6; dp = sp;
*(dp++) = (png_byte)(255 - *(sp++)); *(dp++) = (png_byte)(255 - *(sp++));
*(dp++) = (png_byte)(255 - *(sp++)); *(dp++) = (png_byte)(255 - *(sp++));
} }
@@ -489,8 +495,11 @@ png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
for (i = 0, sp = dp = row; i < row_width; i++) for (i = 0, sp = dp = row; i < row_width; i++)
{ {
/* does nothing
*(dp++) = *(sp++); *(dp++) = *(sp++);
*(dp++) = *(sp++); *(dp++) = *(sp++);
*/
sp+=2; dp = sp;
*(dp++) = (png_byte)(255 - *(sp++)); *(dp++) = (png_byte)(255 - *(sp++));
*(dp++) = (png_byte)(255 - *(sp++)); *(dp++) = (png_byte)(255 - *(sp++));
} }

View File

@@ -1,9 +1,9 @@
/* pngwutil.c - utilities to write a PNG file /* pngwutil.c - utilities to write a PNG file
* *
* libpng version 1.2.8 - December 3, 2004 * Last changed in libpng 1.2.9 March 22, 2006
* For conditions of distribution and use, see copyright notice in png.h * For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1998-2004 Glenn Randers-Pehrson * Copyright (c) 1998-2006 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*/ */
@@ -16,7 +16,7 @@
* with unsigned numbers for convenience, although one supported * with unsigned numbers for convenience, although one supported
* ancillary chunk uses signed (two's complement) numbers. * ancillary chunk uses signed (two's complement) numbers.
*/ */
void /* PRIVATE */ void PNGAPI
png_save_uint_32(png_bytep buf, png_uint_32 i) png_save_uint_32(png_bytep buf, png_uint_32 i)
{ {
buf[0] = (png_byte)((i >> 24) & 0xff); buf[0] = (png_byte)((i >> 24) & 0xff);
@@ -25,12 +25,11 @@ png_save_uint_32(png_bytep buf, png_uint_32 i)
buf[3] = (png_byte)(i & 0xff); buf[3] = (png_byte)(i & 0xff);
} }
#if defined(PNG_WRITE_pCAL_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
/* The png_save_int_32 function assumes integers are stored in two's /* The png_save_int_32 function assumes integers are stored in two's
* complement format. If this isn't the case, then this routine needs to * complement format. If this isn't the case, then this routine needs to
* be modified to write data in two's complement format. * be modified to write data in two's complement format.
*/ */
void /* PRIVATE */ void PNGAPI
png_save_int_32(png_bytep buf, png_int_32 i) png_save_int_32(png_bytep buf, png_int_32 i)
{ {
buf[0] = (png_byte)((i >> 24) & 0xff); buf[0] = (png_byte)((i >> 24) & 0xff);
@@ -38,13 +37,12 @@ png_save_int_32(png_bytep buf, png_int_32 i)
buf[2] = (png_byte)((i >> 8) & 0xff); buf[2] = (png_byte)((i >> 8) & 0xff);
buf[3] = (png_byte)(i & 0xff); buf[3] = (png_byte)(i & 0xff);
} }
#endif
/* Place a 16-bit number into a buffer in PNG byte order. /* Place a 16-bit number into a buffer in PNG byte order.
* The parameter is declared unsigned int, not png_uint_16, * The parameter is declared unsigned int, not png_uint_16,
* just to avoid potential problems on pre-ANSI C compilers. * just to avoid potential problems on pre-ANSI C compilers.
*/ */
void /* PRIVATE */ void PNGAPI
png_save_uint_16(png_bytep buf, unsigned int i) png_save_uint_16(png_bytep buf, unsigned int i)
{ {
buf[0] = (png_byte)((i >> 8) & 0xff); buf[0] = (png_byte)((i >> 8) & 0xff);
@@ -161,9 +159,11 @@ png_text_compress(png_structp png_ptr,
{ {
int ret; int ret;
comp->num_output_ptr = comp->max_output_ptr = 0; comp->num_output_ptr = 0;
comp->max_output_ptr = 0;
comp->output_ptr = NULL; comp->output_ptr = NULL;
comp->input = NULL; comp->input = NULL;
comp->input_len = 0;
/* we may just want to pass the text right through */ /* we may just want to pass the text right through */
if (compression == PNG_TEXT_COMPRESSION_NONE) if (compression == PNG_TEXT_COMPRESSION_NONE)
@@ -730,6 +730,13 @@ png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
compression_state comp; compression_state comp;
png_debug(1, "in png_write_iCCP\n"); png_debug(1, "in png_write_iCCP\n");
comp.num_output_ptr = 0;
comp.max_output_ptr = 0;
comp.output_ptr = NULL;
comp.input = NULL;
comp.input_len = 0;
if (name == NULL || (name_len = png_check_keyword(png_ptr, name, if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
&new_name)) == 0) &new_name)) == 0)
{ {
@@ -930,8 +937,7 @@ png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
itemp = (png_uint_32)(white_y * 100000.0 + 0.5); itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
png_save_uint_32(buf + 4, itemp); png_save_uint_32(buf + 4, itemp);
if (red_x < 0 || red_x > 0.8 || red_y < 0 || red_y > 0.8 || if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
red_x + red_y > 1.0)
{ {
png_warning(png_ptr, "Invalid cHRM red point specified"); png_warning(png_ptr, "Invalid cHRM red point specified");
return; return;
@@ -941,8 +947,7 @@ png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
itemp = (png_uint_32)(red_y * 100000.0 + 0.5); itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
png_save_uint_32(buf + 12, itemp); png_save_uint_32(buf + 12, itemp);
if (green_x < 0 || green_x > 0.8 || green_y < 0 || green_y > 0.8 || if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
green_x + green_y > 1.0)
{ {
png_warning(png_ptr, "Invalid cHRM green point specified"); png_warning(png_ptr, "Invalid cHRM green point specified");
return; return;
@@ -952,8 +957,7 @@ png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
itemp = (png_uint_32)(green_y * 100000.0 + 0.5); itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
png_save_uint_32(buf + 20, itemp); png_save_uint_32(buf + 20, itemp);
if (blue_x < 0 || blue_x > 0.8 || blue_y < 0 || blue_y > 0.8 || if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
blue_x + blue_y > 1.0)
{ {
png_warning(png_ptr, "Invalid cHRM blue point specified"); png_warning(png_ptr, "Invalid cHRM blue point specified");
return; return;
@@ -991,7 +995,7 @@ png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
png_save_uint_32(buf, (png_uint_32)white_x); png_save_uint_32(buf, (png_uint_32)white_x);
png_save_uint_32(buf + 4, (png_uint_32)white_y); png_save_uint_32(buf + 4, (png_uint_32)white_y);
if (red_x > 80000L || red_y > 80000L || red_x + red_y > 100000L) if (red_x + red_y > 100000L)
{ {
png_warning(png_ptr, "Invalid cHRM fixed red point specified"); png_warning(png_ptr, "Invalid cHRM fixed red point specified");
return; return;
@@ -999,7 +1003,7 @@ png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
png_save_uint_32(buf + 8, (png_uint_32)red_x); png_save_uint_32(buf + 8, (png_uint_32)red_x);
png_save_uint_32(buf + 12, (png_uint_32)red_y); png_save_uint_32(buf + 12, (png_uint_32)red_y);
if (green_x > 80000L || green_y > 80000L || green_x + green_y > 100000L) if (green_x + green_y > 100000L)
{ {
png_warning(png_ptr, "Invalid fixed cHRM green point specified"); png_warning(png_ptr, "Invalid fixed cHRM green point specified");
return; return;
@@ -1007,7 +1011,7 @@ png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
png_save_uint_32(buf + 16, (png_uint_32)green_x); png_save_uint_32(buf + 16, (png_uint_32)green_x);
png_save_uint_32(buf + 20, (png_uint_32)green_y); png_save_uint_32(buf + 20, (png_uint_32)green_y);
if (blue_x > 80000L || blue_y > 80000L || blue_x + blue_y > 100000L) if (blue_x + blue_y > 100000L)
{ {
png_warning(png_ptr, "Invalid fixed cHRM blue point specified"); png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
return; return;
@@ -1344,6 +1348,12 @@ png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
png_debug(1, "in png_write_zTXt\n"); png_debug(1, "in png_write_zTXt\n");
comp.num_output_ptr = 0;
comp.max_output_ptr = 0;
comp.output_ptr = NULL;
comp.input = NULL;
comp.input_len = 0;
if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0) if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
{ {
png_warning(png_ptr, "Empty keyword in zTXt chunk"); png_warning(png_ptr, "Empty keyword in zTXt chunk");
@@ -1397,6 +1407,11 @@ png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
png_debug(1, "in png_write_iTXt\n"); png_debug(1, "in png_write_iTXt\n");
comp.num_output_ptr = 0;
comp.max_output_ptr = 0;
comp.output_ptr = NULL;
comp.input = NULL;
if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0) if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
{ {
png_warning(png_ptr, "Empty keyword in iTXt chunk"); png_warning(png_ptr, "Empty keyword in iTXt chunk");
@@ -1559,7 +1574,7 @@ png_write_sCAL(png_structp png_ptr, int unit, double width,double height)
#endif #endif
png_size_t total_len; png_size_t total_len;
char wbuf[32], hbuf[32]; char wbuf[32], hbuf[32];
png_byte bunit = unit; png_byte bunit = (png_byte)unit;
png_debug(1, "in png_write_sCAL\n"); png_debug(1, "in png_write_sCAL\n");