media/libpng/pngrio.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libpng/pngrio.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,120 @@
     1.4 +
     1.5 +/* pngrio.c - functions for data input
     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 input.  Users who need
    1.17 + * special handling are expected to write a function that has the same
    1.18 + * arguments as this and performs a similar function, but that possibly
    1.19 + * has a different input method.  Note that you shouldn't change this
    1.20 + * function, but rather write a replacement function and then make
    1.21 + * libpng use it at run time with png_set_read_fn(...).
    1.22 + */
    1.23 +
    1.24 +#include "pngpriv.h"
    1.25 +
    1.26 +#ifdef PNG_READ_SUPPORTED
    1.27 +
    1.28 +/* Read the data from whatever input you are using.  The default routine
    1.29 + * reads from 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 reads.  This should never be asked
    1.32 + * to read more then 64K on a 16 bit machine.
    1.33 + */
    1.34 +void /* PRIVATE */
    1.35 +png_read_data(png_structrp png_ptr, png_bytep data, png_size_t length)
    1.36 +{
    1.37 +   png_debug1(4, "reading %d bytes", (int)length);
    1.38 +
    1.39 +   if (png_ptr->read_data_fn != NULL)
    1.40 +      (*(png_ptr->read_data_fn))(png_ptr, data, length);
    1.41 +
    1.42 +   else
    1.43 +      png_error(png_ptr, "Call to NULL read function");
    1.44 +}
    1.45 +
    1.46 +#ifdef PNG_STDIO_SUPPORTED
    1.47 +/* This is the function that does the actual reading of data.  If you are
    1.48 + * not reading from a standard C stream, you should create a replacement
    1.49 + * read_data function and use it at run time with png_set_read_fn(), rather
    1.50 + * than changing the library.
    1.51 + */
    1.52 +void PNGCBAPI
    1.53 +png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
    1.54 +{
    1.55 +   png_size_t check;
    1.56 +
    1.57 +   if (png_ptr == NULL)
    1.58 +      return;
    1.59 +
    1.60 +   /* fread() returns 0 on error, so it is OK to store this in a png_size_t
    1.61 +    * instead of an int, which is what fread() actually returns.
    1.62 +    */
    1.63 +   check = fread(data, 1, length, png_voidcast(png_FILE_p, png_ptr->io_ptr));
    1.64 +
    1.65 +   if (check != length)
    1.66 +      png_error(png_ptr, "Read Error");
    1.67 +}
    1.68 +#endif
    1.69 +
    1.70 +/* This function allows the application to supply a new input function
    1.71 + * for libpng if standard C streams aren't being used.
    1.72 + *
    1.73 + * This function takes as its arguments:
    1.74 + *
    1.75 + * png_ptr      - pointer to a png input data structure
    1.76 + *
    1.77 + * io_ptr       - pointer to user supplied structure containing info about
    1.78 + *                the input functions.  May be NULL.
    1.79 + *
    1.80 + * read_data_fn - pointer to a new input function that takes as its
    1.81 + *                arguments a pointer to a png_struct, a pointer to
    1.82 + *                a location where input data can be stored, and a 32-bit
    1.83 + *                unsigned int that is the number of bytes to be read.
    1.84 + *                To exit and output any fatal error messages the new write
    1.85 + *                function should call png_error(png_ptr, "Error msg").
    1.86 + *                May be NULL, in which case libpng's default function will
    1.87 + *                be used.
    1.88 + */
    1.89 +void PNGAPI
    1.90 +png_set_read_fn(png_structrp png_ptr, png_voidp io_ptr,
    1.91 +   png_rw_ptr read_data_fn)
    1.92 +{
    1.93 +   if (png_ptr == NULL)
    1.94 +      return;
    1.95 +
    1.96 +   png_ptr->io_ptr = io_ptr;
    1.97 +
    1.98 +#ifdef PNG_STDIO_SUPPORTED
    1.99 +   if (read_data_fn != NULL)
   1.100 +      png_ptr->read_data_fn = read_data_fn;
   1.101 +
   1.102 +   else
   1.103 +      png_ptr->read_data_fn = png_default_read_data;
   1.104 +#else
   1.105 +   png_ptr->read_data_fn = read_data_fn;
   1.106 +#endif
   1.107 +
   1.108 +#ifdef PNG_WRITE_SUPPORTED
   1.109 +   /* It is an error to write to a read device */
   1.110 +   if (png_ptr->write_data_fn != NULL)
   1.111 +   {
   1.112 +      png_ptr->write_data_fn = NULL;
   1.113 +      png_warning(png_ptr,
   1.114 +          "Can't set both read_data_fn and write_data_fn in the"
   1.115 +          " same structure");
   1.116 +   }
   1.117 +#endif
   1.118 +
   1.119 +#ifdef PNG_WRITE_FLUSH_SUPPORTED
   1.120 +   png_ptr->output_flush_fn = NULL;
   1.121 +#endif
   1.122 +}
   1.123 +#endif /* PNG_READ_SUPPORTED */

mercurial