[DINPUT]
[reactos.git] / reactos / dll / 3rdparty / libpng / pngwio.c
index 513a71a..95ffb34 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.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.)
  *
  * 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_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
@@ -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 */