istereo2
diff libs/libpng/pngwio.c @ 2:81d35769f546
added the tunnel effect source
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 19 Sep 2015 05:51:51 +0300 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/libpng/pngwio.c Sat Sep 19 05:51:51 2015 +0300 1.3 @@ -0,0 +1,234 @@ 1.4 + 1.5 +/* pngwio.c - functions for data output 1.6 + * 1.7 + * Last changed in libpng 1.2.30 [August 15, 2008] 1.8 + * For conditions of distribution and use, see copyright notice in png.h 1.9 + * Copyright (c) 1998-2008 Glenn Randers-Pehrson 1.10 + * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 1.11 + * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 1.12 + * 1.13 + * This file provides a location for all output. Users who need 1.14 + * special handling are expected to write functions that have the same 1.15 + * arguments as these and perform similar functions, but that possibly 1.16 + * use different output methods. Note that you shouldn't change these 1.17 + * functions, but rather write replacement functions and then change 1.18 + * them at run time with png_set_write_fn(...). 1.19 + */ 1.20 + 1.21 +#define PNG_INTERNAL 1.22 +#include "png.h" 1.23 +#ifdef PNG_WRITE_SUPPORTED 1.24 + 1.25 +/* Write the data to whatever output you are using. The default routine 1.26 + writes to a file pointer. Note that this routine sometimes gets called 1.27 + with very small lengths, so you should implement some kind of simple 1.28 + buffering if you are using unbuffered writes. This should never be asked 1.29 + to write more than 64K on a 16 bit machine. */ 1.30 + 1.31 +void /* PRIVATE */ 1.32 +png_write_data(png_structp png_ptr, png_bytep data, png_size_t length) 1.33 +{ 1.34 + if (png_ptr->write_data_fn != NULL ) 1.35 + (*(png_ptr->write_data_fn))(png_ptr, data, length); 1.36 + else 1.37 + png_error(png_ptr, "Call to NULL write function"); 1.38 +} 1.39 + 1.40 +#if !defined(PNG_NO_STDIO) 1.41 +/* This is the function that does the actual writing of data. If you are 1.42 + not writing to a standard C stream, you should create a replacement 1.43 + write_data function and use it at run time with png_set_write_fn(), rather 1.44 + than changing the library. */ 1.45 +#ifndef USE_FAR_KEYWORD 1.46 +void PNGAPI 1.47 +png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) 1.48 +{ 1.49 + png_uint_32 check; 1.50 + 1.51 + if (png_ptr == NULL) return; 1.52 +#if defined(_WIN32_WCE) 1.53 + if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) ) 1.54 + check = 0; 1.55 +#else 1.56 + check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr)); 1.57 +#endif 1.58 + if (check != length) 1.59 + png_error(png_ptr, "Write Error"); 1.60 +} 1.61 +#else 1.62 +/* this is the model-independent version. Since the standard I/O library 1.63 + can't handle far buffers in the medium and small models, we have to copy 1.64 + the data. 1.65 +*/ 1.66 + 1.67 +#define NEAR_BUF_SIZE 1024 1.68 +#define MIN(a,b) (a <= b ? a : b) 1.69 + 1.70 +void PNGAPI 1.71 +png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length) 1.72 +{ 1.73 + png_uint_32 check; 1.74 + png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */ 1.75 + png_FILE_p io_ptr; 1.76 + 1.77 + if (png_ptr == NULL) return; 1.78 + /* Check if data really is near. If so, use usual code. */ 1.79 + near_data = (png_byte *)CVT_PTR_NOCHECK(data); 1.80 + io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr); 1.81 + if ((png_bytep)near_data == data) 1.82 + { 1.83 +#if defined(_WIN32_WCE) 1.84 + if ( !WriteFile(io_ptr, near_data, length, &check, NULL) ) 1.85 + check = 0; 1.86 +#else 1.87 + check = fwrite(near_data, 1, length, io_ptr); 1.88 +#endif 1.89 + } 1.90 + else 1.91 + { 1.92 + png_byte buf[NEAR_BUF_SIZE]; 1.93 + png_size_t written, remaining, err; 1.94 + check = 0; 1.95 + remaining = length; 1.96 + do 1.97 + { 1.98 + written = MIN(NEAR_BUF_SIZE, remaining); 1.99 + png_memcpy(buf, data, written); /* copy far buffer to near buffer */ 1.100 +#if defined(_WIN32_WCE) 1.101 + if ( !WriteFile(io_ptr, buf, written, &err, NULL) ) 1.102 + err = 0; 1.103 +#else 1.104 + err = fwrite(buf, 1, written, io_ptr); 1.105 +#endif 1.106 + if (err != written) 1.107 + break; 1.108 + else 1.109 + check += err; 1.110 + data += written; 1.111 + remaining -= written; 1.112 + } 1.113 + while (remaining != 0); 1.114 + } 1.115 + if (check != length) 1.116 + png_error(png_ptr, "Write Error"); 1.117 +} 1.118 + 1.119 +#endif 1.120 +#endif 1.121 + 1.122 +/* This function is called to output any data pending writing (normally 1.123 + to disk). After png_flush is called, there should be no data pending 1.124 + writing in any buffers. */ 1.125 +#if defined(PNG_WRITE_FLUSH_SUPPORTED) 1.126 +void /* PRIVATE */ 1.127 +png_flush(png_structp png_ptr) 1.128 +{ 1.129 + if (png_ptr->output_flush_fn != NULL) 1.130 + (*(png_ptr->output_flush_fn))(png_ptr); 1.131 +} 1.132 + 1.133 +#if !defined(PNG_NO_STDIO) 1.134 +void PNGAPI 1.135 +png_default_flush(png_structp png_ptr) 1.136 +{ 1.137 +#if !defined(_WIN32_WCE) 1.138 + png_FILE_p io_ptr; 1.139 +#endif 1.140 + if (png_ptr == NULL) return; 1.141 +#if !defined(_WIN32_WCE) 1.142 + io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr)); 1.143 + if (io_ptr != NULL) 1.144 + fflush(io_ptr); 1.145 +#endif 1.146 +} 1.147 +#endif 1.148 +#endif 1.149 + 1.150 +/* This function allows the application to supply new output functions for 1.151 + libpng if standard C streams aren't being used. 1.152 + 1.153 + This function takes as its arguments: 1.154 + png_ptr - pointer to a png output data structure 1.155 + io_ptr - pointer to user supplied structure containing info about 1.156 + the output functions. May be NULL. 1.157 + write_data_fn - pointer to a new output function that takes as its 1.158 + arguments a pointer to a png_struct, a pointer to 1.159 + data to be written, and a 32-bit unsigned int that is 1.160 + the number of bytes to be written. The new write 1.161 + function should call png_error(png_ptr, "Error msg") 1.162 + to exit and output any fatal error messages. 1.163 + flush_data_fn - pointer to a new flush function that takes as its 1.164 + arguments a pointer to a png_struct. After a call to 1.165 + the flush function, there should be no data in any buffers 1.166 + or pending transmission. If the output method doesn't do 1.167 + any buffering of ouput, a function prototype must still be 1.168 + supplied although it doesn't have to do anything. If 1.169 + PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile 1.170 + time, output_flush_fn will be ignored, although it must be 1.171 + supplied for compatibility. */ 1.172 +void PNGAPI 1.173 +png_set_write_fn(png_structp png_ptr, png_voidp io_ptr, 1.174 + png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn) 1.175 +{ 1.176 + if (png_ptr == NULL) return; 1.177 + png_ptr->io_ptr = io_ptr; 1.178 + 1.179 +#if !defined(PNG_NO_STDIO) 1.180 + if (write_data_fn != NULL) 1.181 + png_ptr->write_data_fn = write_data_fn; 1.182 + else 1.183 + png_ptr->write_data_fn = png_default_write_data; 1.184 +#else 1.185 + png_ptr->write_data_fn = write_data_fn; 1.186 +#endif 1.187 + 1.188 +#if defined(PNG_WRITE_FLUSH_SUPPORTED) 1.189 +#if !defined(PNG_NO_STDIO) 1.190 + if (output_flush_fn != NULL) 1.191 + png_ptr->output_flush_fn = output_flush_fn; 1.192 + else 1.193 + png_ptr->output_flush_fn = png_default_flush; 1.194 +#else 1.195 + png_ptr->output_flush_fn = output_flush_fn; 1.196 +#endif 1.197 +#endif /* PNG_WRITE_FLUSH_SUPPORTED */ 1.198 + 1.199 + /* It is an error to read while writing a png file */ 1.200 + if (png_ptr->read_data_fn != NULL) 1.201 + { 1.202 + png_ptr->read_data_fn = NULL; 1.203 + png_warning(png_ptr, 1.204 + "Attempted to set both read_data_fn and write_data_fn in"); 1.205 + png_warning(png_ptr, 1.206 + "the same structure. Resetting read_data_fn to NULL."); 1.207 + } 1.208 +} 1.209 + 1.210 +#if defined(USE_FAR_KEYWORD) 1.211 +#if defined(_MSC_VER) 1.212 +void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check) 1.213 +{ 1.214 + void *near_ptr; 1.215 + void FAR *far_ptr; 1.216 + FP_OFF(near_ptr) = FP_OFF(ptr); 1.217 + far_ptr = (void FAR *)near_ptr; 1.218 + if (check != 0) 1.219 + if (FP_SEG(ptr) != FP_SEG(far_ptr)) 1.220 + png_error(png_ptr, "segment lost in conversion"); 1.221 + return(near_ptr); 1.222 +} 1.223 +# else 1.224 +void *png_far_to_near(png_structp png_ptr, png_voidp ptr, int check) 1.225 +{ 1.226 + void *near_ptr; 1.227 + void FAR *far_ptr; 1.228 + near_ptr = (void FAR *)ptr; 1.229 + far_ptr = (void FAR *)near_ptr; 1.230 + if (check != 0) 1.231 + if (far_ptr != ptr) 1.232 + png_error(png_ptr, "segment lost in conversion"); 1.233 + return(near_ptr); 1.234 +} 1.235 +# endif 1.236 +# endif 1.237 +#endif /* PNG_WRITE_SUPPORTED */