deps: zlib-1.2.3 -> 1.2.8; libpng-1.4.0 -> 1.6.12
[sdk] / deps / libpng-1.6.12 / pngwio.c
similarity index 62%
rename from deps/libpng-1.4.0/pngwio.c
rename to deps/libpng-1.6.12/pngwio.c
index f4d995b..1b525f9 100644 (file)
@@ -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.6.9 [February 6, 2014]
+ * Copyright (c) 1998-2014 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.)
  *
  * 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
  */
 
 void /* PRIVATE */
-png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
+png_write_data(png_structrp 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_constcast(png_bytep,data),
+         length);
+
    else
       png_error(png_ptr, "Call to NULL write function");
 }
@@ -45,70 +47,19 @@ png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  * write_data function and use it at run time with png_set_write_fn(), rather
  * 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");
-}
-#else
-/* This is the model-independent version. Since the standard I/O library
- * can't handle far buffers in the medium and small models, we have to copy
- * the data.
- */
-
-#define NEAR_BUF_SIZE 1024
-#define MIN(a,b) (a <= b ? a : b)
 
-void PNGAPI
-png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
-{
-   png_uint_32 check;
-   png_byte *near_data;  /* Needs to be "png_byte *" instead of "png_bytep" */
-   png_FILE_p io_ptr;
+   check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
 
-   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;
-
-         else
-            check += err;
-
-         data += written;
-         remaining -= written;
-      }
-      while (remaining != 0);
-   }
    if (check != length)
       png_error(png_ptr, "Write Error");
 }
-
-#endif
 #endif
 
 /* This function is called to output any data pending writing (normally
@@ -117,23 +68,25 @@ png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  */
 #ifdef PNG_WRITE_FLUSH_SUPPORTED
 void /* PRIVATE */
-png_flush(png_structp png_ptr)
+png_flush(png_structrp png_ptr)
 {
    if (png_ptr->output_flush_fn != NULL)
       (*(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));
+
+   io_ptr = png_voidcast(png_FILE_p, (png_ptr->io_ptr));
    fflush(io_ptr);
 }
-#endif
+#  endif
 #endif
 
 /* This function allows the application to supply new output functions for
@@ -155,7 +108,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
@@ -166,8 +119,8 @@ png_default_flush(png_structp png_ptr)
  *                 *FILE structure.
  */
 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_set_write_fn(png_structrp png_ptr, png_voidp io_ptr,
+    png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
 {
    if (png_ptr == NULL)
       return;
@@ -185,57 +138,31 @@ 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
+#else
+   PNG_UNUSED(output_flush_fn)
 #endif /* PNG_WRITE_FLUSH_SUPPORTED */
 
+#ifdef PNG_READ_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");
    }
+#endif
 }
-
-#ifdef USE_FAR_KEYWORD
-#ifdef _MSC_VER
-void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check)
-{
-   void *near_ptr;
-   void FAR *far_ptr;
-   FP_OFF(near_ptr) = FP_OFF(ptr);
-   far_ptr = (void FAR *)near_ptr;
-
-   if (check != 0)
-      if (FP_SEG(ptr) != FP_SEG(far_ptr))
-         png_error(png_ptr, "segment lost in conversion");
-
-   return(near_ptr);
-}
-#  else
-void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check)
-{
-   void *near_ptr;
-   void FAR *far_ptr;
-   near_ptr = (void FAR *)ptr;
-   far_ptr = (void FAR *)near_ptr;
-
-   if (check != 0)
-      if (far_ptr != ptr)
-         png_error(png_ptr, "segment lost in conversion");
-
-   return(near_ptr);
-}
-#   endif
-#   endif
 #endif /* PNG_WRITE_SUPPORTED */