summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/libpng/pngwio.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdparty/libpng/pngwio.c')
-rw-r--r--src/3rdparty/libpng/pngwio.c61
1 files changed, 37 insertions, 24 deletions
diff --git a/src/3rdparty/libpng/pngwio.c b/src/3rdparty/libpng/pngwio.c
index f4d995b..95ffb34 100644
--- a/src/3rdparty/libpng/pngwio.c
+++ b/src/3rdparty/libpng/pngwio.c
@@ -1,8 +1,8 @@
/* pngwio.c - functions for data output
*
- * Last changed in libpng 1.4.0 [January 3, 2010]
- * Copyright (c) 1998-2010 Glenn Randers-Pehrson
+ * Last changed in libpng 1.5.0 [January 6, 2011]
+ * Copyright (c) 1998-2011 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
@@ -18,11 +18,10 @@
* them at run time with png_set_write_fn(...).
*/
-#define PNG_NO_PEDANTIC_WARNINGS
-#include "png.h"
-#ifdef PNG_WRITE_SUPPORTED
#include "pngpriv.h"
+#ifdef PNG_WRITE_SUPPORTED
+
/* Write the data to whatever output you are using. The default routine
* writes to a file pointer. Note that this routine sometimes gets called
* with very small lengths, so you should implement some kind of simple
@@ -31,10 +30,12 @@
*/
void /* PRIVATE */
-png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
+png_write_data(png_structp png_ptr, png_const_bytep data, png_size_t length)
{
+ /* NOTE: write_data_fn must not change the buffer! */
if (png_ptr->write_data_fn != NULL )
- (*(png_ptr->write_data_fn))(png_ptr, data, length);
+ (*(png_ptr->write_data_fn))(png_ptr, (png_bytep)data, length);
+
else
png_error(png_ptr, "Call to NULL write function");
}
@@ -46,14 +47,16 @@ png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
* than changing the library.
*/
#ifndef USE_FAR_KEYWORD
-void PNGAPI
+void PNGCBAPI
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
- png_uint_32 check;
+ png_size_t check;
if (png_ptr == NULL)
return;
+
check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
+
if (check != length)
png_error(png_ptr, "Write Error");
}
@@ -66,7 +69,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
#define NEAR_BUF_SIZE 1024
#define MIN(a,b) (a <= b ? a : b)
-void PNGAPI
+void PNGCBAPI
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
png_uint_32 check;
@@ -75,24 +78,29 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
if (png_ptr == NULL)
return;
+
/* Check if data really is near. If so, use usual code. */
near_data = (png_byte *)CVT_PTR_NOCHECK(data);
io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
+
if ((png_bytep)near_data == data)
{
check = fwrite(near_data, 1, length, io_ptr);
}
+
else
{
png_byte buf[NEAR_BUF_SIZE];
png_size_t written, remaining, err;
check = 0;
remaining = length;
+
do
{
written = MIN(NEAR_BUF_SIZE, remaining);
png_memcpy(buf, data, written); /* Copy far buffer to near buffer */
err = fwrite(buf, 1, written, io_ptr);
+
if (err != written)
break;
@@ -104,6 +112,7 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
}
while (remaining != 0);
}
+
if (check != length)
png_error(png_ptr, "Write Error");
}
@@ -123,17 +132,19 @@ png_flush(png_structp png_ptr)
(*(png_ptr->output_flush_fn))(png_ptr);
}
-#ifdef PNG_STDIO_SUPPORTED
-void PNGAPI
+# ifdef PNG_STDIO_SUPPORTED
+void PNGCBAPI
png_default_flush(png_structp png_ptr)
{
png_FILE_p io_ptr;
+
if (png_ptr == NULL)
return;
+
io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
fflush(io_ptr);
}
-#endif
+# endif
#endif
/* This function allows the application to supply new output functions for
@@ -155,7 +166,7 @@ png_default_flush(png_structp png_ptr)
* arguments a pointer to a png_struct. After a call to
* the flush function, there should be no data in any buffers
* or pending transmission. If the output method doesn't do
- * any buffering of ouput, a function prototype must still be
+ * any buffering of output, a function prototype must still be
* supplied although it doesn't have to do anything. If
* PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile
* time, output_flush_fn will be ignored, although it must be
@@ -167,7 +178,7 @@ png_default_flush(png_structp png_ptr)
*/
void PNGAPI
png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
- png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
+ png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
{
if (png_ptr == NULL)
return;
@@ -185,30 +196,32 @@ png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
#endif
#ifdef PNG_WRITE_FLUSH_SUPPORTED
-#ifdef PNG_STDIO_SUPPORTED
+# ifdef PNG_STDIO_SUPPORTED
+
if (output_flush_fn != NULL)
png_ptr->output_flush_fn = output_flush_fn;
else
png_ptr->output_flush_fn = png_default_flush;
-#else
+
+# else
png_ptr->output_flush_fn = output_flush_fn;
-#endif
+# endif
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
/* It is an error to read while writing a png file */
if (png_ptr->read_data_fn != NULL)
{
png_ptr->read_data_fn = NULL;
+
png_warning(png_ptr,
- "Attempted to set both read_data_fn and write_data_fn in");
- png_warning(png_ptr,
- "the same structure. Resetting read_data_fn to NULL");
+ "Can't set both read_data_fn and write_data_fn in the"
+ " same structure");
}
}
#ifdef USE_FAR_KEYWORD
-#ifdef _MSC_VER
+# ifdef _MSC_VER
void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check)
{
void *near_ptr;
@@ -236,6 +249,6 @@ void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check)
return(near_ptr);
}
-# endif
-# endif
+# endif
+#endif
#endif /* PNG_WRITE_SUPPORTED */