ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

pngwio.c
Go to the documentation of this file.
00001 
00002 /* pngwio.c - functions for data output
00003  *
00004  * Last changed in libpng 1.5.0 [January 6, 2011]
00005  * Copyright (c) 1998-2011 Glenn Randers-Pehrson
00006  * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
00007  * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
00008  *
00009  * This code is released under the libpng license.
00010  * For conditions of distribution and use, see the disclaimer
00011  * and license in png.h
00012  *
00013  * This file provides a location for all output.  Users who need
00014  * special handling are expected to write functions that have the same
00015  * arguments as these and perform similar functions, but that possibly
00016  * use different output methods.  Note that you shouldn't change these
00017  * functions, but rather write replacement functions and then change
00018  * them at run time with png_set_write_fn(...).
00019  */
00020 
00021 #include "pngpriv.h"
00022 
00023 #ifdef PNG_WRITE_SUPPORTED
00024 
00025 /* Write the data to whatever output you are using.  The default routine
00026  * writes to a file pointer.  Note that this routine sometimes gets called
00027  * with very small lengths, so you should implement some kind of simple
00028  * buffering if you are using unbuffered writes.  This should never be asked
00029  * to write more than 64K on a 16 bit machine.
00030  */
00031 
00032 void /* PRIVATE */
00033 png_write_data(png_structp png_ptr, png_const_bytep data, png_size_t length)
00034 {
00035    /* NOTE: write_data_fn must not change the buffer! */
00036    if (png_ptr->write_data_fn != NULL )
00037       (*(png_ptr->write_data_fn))(png_ptr, (png_bytep)data, length);
00038 
00039    else
00040       png_error(png_ptr, "Call to NULL write function");
00041 }
00042 
00043 #ifdef PNG_STDIO_SUPPORTED
00044 /* This is the function that does the actual writing of data.  If you are
00045  * not writing to a standard C stream, you should create a replacement
00046  * write_data function and use it at run time with png_set_write_fn(), rather
00047  * than changing the library.
00048  */
00049 #ifndef USE_FAR_KEYWORD
00050 void PNGCBAPI
00051 png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
00052 {
00053    png_size_t check;
00054 
00055    if (png_ptr == NULL)
00056       return;
00057 
00058    check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
00059 
00060    if (check != length)
00061       png_error(png_ptr, "Write Error");
00062 }
00063 #else
00064 /* This is the model-independent version. Since the standard I/O library
00065  * can't handle far buffers in the medium and small models, we have to copy
00066  * the data.
00067  */
00068 
00069 #define NEAR_BUF_SIZE 1024
00070 #define MIN(a,b) (a <= b ? a : b)
00071 
00072 void PNGCBAPI
00073 png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
00074 {
00075    png_uint_32 check;
00076    png_byte *near_data;  /* Needs to be "png_byte *" instead of "png_bytep" */
00077    png_FILE_p io_ptr;
00078 
00079    if (png_ptr == NULL)
00080       return;
00081 
00082    /* Check if data really is near. If so, use usual code. */
00083    near_data = (png_byte *)CVT_PTR_NOCHECK(data);
00084    io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
00085 
00086    if ((png_bytep)near_data == data)
00087    {
00088       check = fwrite(near_data, 1, length, io_ptr);
00089    }
00090 
00091    else
00092    {
00093       png_byte buf[NEAR_BUF_SIZE];
00094       png_size_t written, remaining, err;
00095       check = 0;
00096       remaining = length;
00097 
00098       do
00099       {
00100          written = MIN(NEAR_BUF_SIZE, remaining);
00101          png_memcpy(buf, data, written); /* Copy far buffer to near buffer */
00102          err = fwrite(buf, 1, written, io_ptr);
00103 
00104          if (err != written)
00105             break;
00106 
00107          else
00108             check += err;
00109 
00110          data += written;
00111          remaining -= written;
00112       }
00113       while (remaining != 0);
00114    }
00115 
00116    if (check != length)
00117       png_error(png_ptr, "Write Error");
00118 }
00119 
00120 #endif
00121 #endif
00122 
00123 /* This function is called to output any data pending writing (normally
00124  * to disk).  After png_flush is called, there should be no data pending
00125  * writing in any buffers.
00126  */
00127 #ifdef PNG_WRITE_FLUSH_SUPPORTED
00128 void /* PRIVATE */
00129 png_flush(png_structp png_ptr)
00130 {
00131    if (png_ptr->output_flush_fn != NULL)
00132       (*(png_ptr->output_flush_fn))(png_ptr);
00133 }
00134 
00135 #  ifdef PNG_STDIO_SUPPORTED
00136 void PNGCBAPI
00137 png_default_flush(png_structp png_ptr)
00138 {
00139    png_FILE_p io_ptr;
00140 
00141    if (png_ptr == NULL)
00142       return;
00143 
00144    io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
00145    fflush(io_ptr);
00146 }
00147 #  endif
00148 #endif
00149 
00150 /* This function allows the application to supply new output functions for
00151  * libpng if standard C streams aren't being used.
00152  *
00153  * This function takes as its arguments:
00154  * png_ptr       - pointer to a png output data structure
00155  * io_ptr        - pointer to user supplied structure containing info about
00156  *                 the output functions.  May be NULL.
00157  * write_data_fn - pointer to a new output function that takes as its
00158  *                 arguments a pointer to a png_struct, a pointer to
00159  *                 data to be written, and a 32-bit unsigned int that is
00160  *                 the number of bytes to be written.  The new write
00161  *                 function should call png_error(png_ptr, "Error msg")
00162  *                 to exit and output any fatal error messages.  May be
00163  *                 NULL, in which case libpng's default function will
00164  *                 be used.
00165  * flush_data_fn - pointer to a new flush function that takes as its
00166  *                 arguments a pointer to a png_struct.  After a call to
00167  *                 the flush function, there should be no data in any buffers
00168  *                 or pending transmission.  If the output method doesn't do
00169  *                 any buffering of output, a function prototype must still be
00170  *                 supplied although it doesn't have to do anything.  If
00171  *                 PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile
00172  *                 time, output_flush_fn will be ignored, although it must be
00173  *                 supplied for compatibility.  May be NULL, in which case
00174  *                 libpng's default function will be used, if
00175  *                 PNG_WRITE_FLUSH_SUPPORTED is defined.  This is not
00176  *                 a good idea if io_ptr does not point to a standard
00177  *                 *FILE structure.
00178  */
00179 void PNGAPI
00180 png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
00181     png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
00182 {
00183    if (png_ptr == NULL)
00184       return;
00185 
00186    png_ptr->io_ptr = io_ptr;
00187 
00188 #ifdef PNG_STDIO_SUPPORTED
00189    if (write_data_fn != NULL)
00190       png_ptr->write_data_fn = write_data_fn;
00191 
00192    else
00193       png_ptr->write_data_fn = png_default_write_data;
00194 #else
00195    png_ptr->write_data_fn = write_data_fn;
00196 #endif
00197 
00198 #ifdef PNG_WRITE_FLUSH_SUPPORTED
00199 #  ifdef PNG_STDIO_SUPPORTED
00200 
00201    if (output_flush_fn != NULL)
00202       png_ptr->output_flush_fn = output_flush_fn;
00203 
00204    else
00205       png_ptr->output_flush_fn = png_default_flush;
00206 
00207 #  else
00208    png_ptr->output_flush_fn = output_flush_fn;
00209 #  endif
00210 #endif /* PNG_WRITE_FLUSH_SUPPORTED */
00211 
00212    /* It is an error to read while writing a png file */
00213    if (png_ptr->read_data_fn != NULL)
00214    {
00215       png_ptr->read_data_fn = NULL;
00216 
00217       png_warning(png_ptr,
00218           "Can't set both read_data_fn and write_data_fn in the"
00219           " same structure");
00220    }
00221 }
00222 
00223 #ifdef USE_FAR_KEYWORD
00224 #  ifdef _MSC_VER
00225 void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check)
00226 {
00227    void *near_ptr;
00228    void FAR *far_ptr;
00229    FP_OFF(near_ptr) = FP_OFF(ptr);
00230    far_ptr = (void FAR *)near_ptr;
00231 
00232    if (check != 0)
00233       if (FP_SEG(ptr) != FP_SEG(far_ptr))
00234          png_error(png_ptr, "segment lost in conversion");
00235 
00236    return(near_ptr);
00237 }
00238 #  else
00239 void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check)
00240 {
00241    void *near_ptr;
00242    void FAR *far_ptr;
00243    near_ptr = (void FAR *)ptr;
00244    far_ptr = (void FAR *)near_ptr;
00245 
00246    if (check != 0)
00247       if (far_ptr != ptr)
00248          png_error(png_ptr, "segment lost in conversion");
00249 
00250    return(near_ptr);
00251 }
00252 #  endif
00253 #endif
00254 #endif /* PNG_WRITE_SUPPORTED */

Generated on Sun May 27 2012 04:19:32 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.