media/libpng/pngwio.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libpng/pngwio.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,168 @@
     1.4 +
     1.5 +/* pngwio.c - functions for data output
     1.6 + *
     1.7 + * Last changed in libpng 1.6.9 [February 6, 2014]
     1.8 + * Copyright (c) 1998-2014 Glenn Randers-Pehrson
     1.9 + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
    1.10 + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
    1.11 + *
    1.12 + * This code is released under the libpng license.
    1.13 + * For conditions of distribution and use, see the disclaimer
    1.14 + * and license in png.h
    1.15 + *
    1.16 + * This file provides a location for all output.  Users who need
    1.17 + * special handling are expected to write functions that have the same
    1.18 + * arguments as these and perform similar functions, but that possibly
    1.19 + * use different output methods.  Note that you shouldn't change these
    1.20 + * functions, but rather write replacement functions and then change
    1.21 + * them at run time with png_set_write_fn(...).
    1.22 + */
    1.23 +
    1.24 +#include "pngpriv.h"
    1.25 +
    1.26 +#ifdef PNG_WRITE_SUPPORTED
    1.27 +
    1.28 +/* Write the data to whatever output you are using.  The default routine
    1.29 + * writes to a file pointer.  Note that this routine sometimes gets called
    1.30 + * with very small lengths, so you should implement some kind of simple
    1.31 + * buffering if you are using unbuffered writes.  This should never be asked
    1.32 + * to write more than 64K on a 16 bit machine.
    1.33 + */
    1.34 +
    1.35 +void /* PRIVATE */
    1.36 +png_write_data(png_structrp png_ptr, png_const_bytep data, png_size_t length)
    1.37 +{
    1.38 +   /* NOTE: write_data_fn must not change the buffer! */
    1.39 +   if (png_ptr->write_data_fn != NULL )
    1.40 +      (*(png_ptr->write_data_fn))(png_ptr, png_constcast(png_bytep,data),
    1.41 +         length);
    1.42 +
    1.43 +   else
    1.44 +      png_error(png_ptr, "Call to NULL write function");
    1.45 +}
    1.46 +
    1.47 +#ifdef PNG_STDIO_SUPPORTED
    1.48 +/* This is the function that does the actual writing of data.  If you are
    1.49 + * not writing to a standard C stream, you should create a replacement
    1.50 + * write_data function and use it at run time with png_set_write_fn(), rather
    1.51 + * than changing the library.
    1.52 + */
    1.53 +void PNGCBAPI
    1.54 +png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
    1.55 +{
    1.56 +   png_size_t check;
    1.57 +
    1.58 +   if (png_ptr == NULL)
    1.59 +      return;
    1.60 +
    1.61 +   check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
    1.62 +
    1.63 +   if (check != length)
    1.64 +      png_error(png_ptr, "Write Error");
    1.65 +}
    1.66 +#endif
    1.67 +
    1.68 +/* This function is called to output any data pending writing (normally
    1.69 + * to disk).  After png_flush is called, there should be no data pending
    1.70 + * writing in any buffers.
    1.71 + */
    1.72 +#ifdef PNG_WRITE_FLUSH_SUPPORTED
    1.73 +void /* PRIVATE */
    1.74 +png_flush(png_structrp png_ptr)
    1.75 +{
    1.76 +   if (png_ptr->output_flush_fn != NULL)
    1.77 +      (*(png_ptr->output_flush_fn))(png_ptr);
    1.78 +}
    1.79 +
    1.80 +#  ifdef PNG_STDIO_SUPPORTED
    1.81 +void PNGCBAPI
    1.82 +png_default_flush(png_structp png_ptr)
    1.83 +{
    1.84 +   png_FILE_p io_ptr;
    1.85 +
    1.86 +   if (png_ptr == NULL)
    1.87 +      return;
    1.88 +
    1.89 +   io_ptr = png_voidcast(png_FILE_p, (png_ptr->io_ptr));
    1.90 +   fflush(io_ptr);
    1.91 +}
    1.92 +#  endif
    1.93 +#endif
    1.94 +
    1.95 +/* This function allows the application to supply new output functions for
    1.96 + * libpng if standard C streams aren't being used.
    1.97 + *
    1.98 + * This function takes as its arguments:
    1.99 + * png_ptr       - pointer to a png output data structure
   1.100 + * io_ptr        - pointer to user supplied structure containing info about
   1.101 + *                 the output functions.  May be NULL.
   1.102 + * write_data_fn - pointer to a new output function that takes as its
   1.103 + *                 arguments a pointer to a png_struct, a pointer to
   1.104 + *                 data to be written, and a 32-bit unsigned int that is
   1.105 + *                 the number of bytes to be written.  The new write
   1.106 + *                 function should call png_error(png_ptr, "Error msg")
   1.107 + *                 to exit and output any fatal error messages.  May be
   1.108 + *                 NULL, in which case libpng's default function will
   1.109 + *                 be used.
   1.110 + * flush_data_fn - pointer to a new flush function that takes as its
   1.111 + *                 arguments a pointer to a png_struct.  After a call to
   1.112 + *                 the flush function, there should be no data in any buffers
   1.113 + *                 or pending transmission.  If the output method doesn't do
   1.114 + *                 any buffering of output, a function prototype must still be
   1.115 + *                 supplied although it doesn't have to do anything.  If
   1.116 + *                 PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile
   1.117 + *                 time, output_flush_fn will be ignored, although it must be
   1.118 + *                 supplied for compatibility.  May be NULL, in which case
   1.119 + *                 libpng's default function will be used, if
   1.120 + *                 PNG_WRITE_FLUSH_SUPPORTED is defined.  This is not
   1.121 + *                 a good idea if io_ptr does not point to a standard
   1.122 + *                 *FILE structure.
   1.123 + */
   1.124 +void PNGAPI
   1.125 +png_set_write_fn(png_structrp png_ptr, png_voidp io_ptr,
   1.126 +    png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
   1.127 +{
   1.128 +   if (png_ptr == NULL)
   1.129 +      return;
   1.130 +
   1.131 +   png_ptr->io_ptr = io_ptr;
   1.132 +
   1.133 +#ifdef PNG_STDIO_SUPPORTED
   1.134 +   if (write_data_fn != NULL)
   1.135 +      png_ptr->write_data_fn = write_data_fn;
   1.136 +
   1.137 +   else
   1.138 +      png_ptr->write_data_fn = png_default_write_data;
   1.139 +#else
   1.140 +   png_ptr->write_data_fn = write_data_fn;
   1.141 +#endif
   1.142 +
   1.143 +#ifdef PNG_WRITE_FLUSH_SUPPORTED
   1.144 +#  ifdef PNG_STDIO_SUPPORTED
   1.145 +
   1.146 +   if (output_flush_fn != NULL)
   1.147 +      png_ptr->output_flush_fn = output_flush_fn;
   1.148 +
   1.149 +   else
   1.150 +      png_ptr->output_flush_fn = png_default_flush;
   1.151 +
   1.152 +#  else
   1.153 +   png_ptr->output_flush_fn = output_flush_fn;
   1.154 +#  endif
   1.155 +#else
   1.156 +   PNG_UNUSED(output_flush_fn)
   1.157 +#endif /* PNG_WRITE_FLUSH_SUPPORTED */
   1.158 +
   1.159 +#ifdef PNG_READ_SUPPORTED
   1.160 +   /* It is an error to read while writing a png file */
   1.161 +   if (png_ptr->read_data_fn != NULL)
   1.162 +   {
   1.163 +      png_ptr->read_data_fn = NULL;
   1.164 +
   1.165 +      png_warning(png_ptr,
   1.166 +          "Can't set both read_data_fn and write_data_fn in the"
   1.167 +          " same structure");
   1.168 +   }
   1.169 +#endif
   1.170 +}
   1.171 +#endif /* PNG_WRITE_SUPPORTED */

mercurial