annotate lib/libpng/pngwio.c @ 2575:a76d408c5132 tip

DrawTranslucent -> DrawTextureGrayShade Removed old texture drawing stuff
author a.parshin
date Wed, 09 Mar 2016 01:39:52 +0200
parents 6e178010fc29
children
rev   line source
2296
Ritor1
parents:
diff changeset
1
Ritor1
parents:
diff changeset
2 /* pngwio.c - functions for data output
Ritor1
parents:
diff changeset
3 *
Ritor1
parents:
diff changeset
4 * Last changed in libpng 1.6.9 [February 6, 2014]
Ritor1
parents:
diff changeset
5 * Copyright (c) 1998-2014 Glenn Randers-Pehrson
Ritor1
parents:
diff changeset
6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
Ritor1
parents:
diff changeset
7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
Ritor1
parents:
diff changeset
8 *
Ritor1
parents:
diff changeset
9 * This code is released under the libpng license.
Ritor1
parents:
diff changeset
10 * For conditions of distribution and use, see the disclaimer
Ritor1
parents:
diff changeset
11 * and license in png.h
Ritor1
parents:
diff changeset
12 *
Ritor1
parents:
diff changeset
13 * This file provides a location for all output. Users who need
Ritor1
parents:
diff changeset
14 * special handling are expected to write functions that have the same
Ritor1
parents:
diff changeset
15 * arguments as these and perform similar functions, but that possibly
Ritor1
parents:
diff changeset
16 * use different output methods. Note that you shouldn't change these
Ritor1
parents:
diff changeset
17 * functions, but rather write replacement functions and then change
Ritor1
parents:
diff changeset
18 * them at run time with png_set_write_fn(...).
Ritor1
parents:
diff changeset
19 */
Ritor1
parents:
diff changeset
20
Ritor1
parents:
diff changeset
21 #include "pngpriv.h"
Ritor1
parents:
diff changeset
22
Ritor1
parents:
diff changeset
23 #ifdef PNG_WRITE_SUPPORTED
Ritor1
parents:
diff changeset
24
Ritor1
parents:
diff changeset
25 /* Write the data to whatever output you are using. The default routine
Ritor1
parents:
diff changeset
26 * writes to a file pointer. Note that this routine sometimes gets called
Ritor1
parents:
diff changeset
27 * with very small lengths, so you should implement some kind of simple
Ritor1
parents:
diff changeset
28 * buffering if you are using unbuffered writes. This should never be asked
Ritor1
parents:
diff changeset
29 * to write more than 64K on a 16 bit machine.
Ritor1
parents:
diff changeset
30 */
Ritor1
parents:
diff changeset
31
Ritor1
parents:
diff changeset
32 void /* PRIVATE */
Ritor1
parents:
diff changeset
33 png_write_data(png_structrp png_ptr, png_const_bytep data, png_size_t length)
Ritor1
parents:
diff changeset
34 {
Ritor1
parents:
diff changeset
35 /* NOTE: write_data_fn must not change the buffer! */
Ritor1
parents:
diff changeset
36 if (png_ptr->write_data_fn != NULL )
Ritor1
parents:
diff changeset
37 (*(png_ptr->write_data_fn))(png_ptr, png_constcast(png_bytep,data),
Ritor1
parents:
diff changeset
38 length);
Ritor1
parents:
diff changeset
39
Ritor1
parents:
diff changeset
40 else
Ritor1
parents:
diff changeset
41 png_error(png_ptr, "Call to NULL write function");
Ritor1
parents:
diff changeset
42 }
Ritor1
parents:
diff changeset
43
Ritor1
parents:
diff changeset
44 #ifdef PNG_STDIO_SUPPORTED
Ritor1
parents:
diff changeset
45 /* This is the function that does the actual writing of data. If you are
Ritor1
parents:
diff changeset
46 * not writing to a standard C stream, you should create a replacement
Ritor1
parents:
diff changeset
47 * write_data function and use it at run time with png_set_write_fn(), rather
Ritor1
parents:
diff changeset
48 * than changing the library.
Ritor1
parents:
diff changeset
49 */
Ritor1
parents:
diff changeset
50 void PNGCBAPI
Ritor1
parents:
diff changeset
51 png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
Ritor1
parents:
diff changeset
52 {
Ritor1
parents:
diff changeset
53 png_size_t check;
Ritor1
parents:
diff changeset
54
Ritor1
parents:
diff changeset
55 if (png_ptr == NULL)
Ritor1
parents:
diff changeset
56 return;
Ritor1
parents:
diff changeset
57
Ritor1
parents:
diff changeset
58 check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
Ritor1
parents:
diff changeset
59
Ritor1
parents:
diff changeset
60 if (check != length)
Ritor1
parents:
diff changeset
61 png_error(png_ptr, "Write Error");
Ritor1
parents:
diff changeset
62 }
Ritor1
parents:
diff changeset
63 #endif
Ritor1
parents:
diff changeset
64
Ritor1
parents:
diff changeset
65 /* This function is called to output any data pending writing (normally
Ritor1
parents:
diff changeset
66 * to disk). After png_flush is called, there should be no data pending
Ritor1
parents:
diff changeset
67 * writing in any buffers.
Ritor1
parents:
diff changeset
68 */
Ritor1
parents:
diff changeset
69 #ifdef PNG_WRITE_FLUSH_SUPPORTED
Ritor1
parents:
diff changeset
70 void /* PRIVATE */
Ritor1
parents:
diff changeset
71 png_flush(png_structrp png_ptr)
Ritor1
parents:
diff changeset
72 {
Ritor1
parents:
diff changeset
73 if (png_ptr->output_flush_fn != NULL)
Ritor1
parents:
diff changeset
74 (*(png_ptr->output_flush_fn))(png_ptr);
Ritor1
parents:
diff changeset
75 }
Ritor1
parents:
diff changeset
76
Ritor1
parents:
diff changeset
77 # ifdef PNG_STDIO_SUPPORTED
Ritor1
parents:
diff changeset
78 void PNGCBAPI
Ritor1
parents:
diff changeset
79 png_default_flush(png_structp png_ptr)
Ritor1
parents:
diff changeset
80 {
Ritor1
parents:
diff changeset
81 png_FILE_p io_ptr;
Ritor1
parents:
diff changeset
82
Ritor1
parents:
diff changeset
83 if (png_ptr == NULL)
Ritor1
parents:
diff changeset
84 return;
Ritor1
parents:
diff changeset
85
Ritor1
parents:
diff changeset
86 io_ptr = png_voidcast(png_FILE_p, (png_ptr->io_ptr));
Ritor1
parents:
diff changeset
87 fflush(io_ptr);
Ritor1
parents:
diff changeset
88 }
Ritor1
parents:
diff changeset
89 # endif
Ritor1
parents:
diff changeset
90 #endif
Ritor1
parents:
diff changeset
91
Ritor1
parents:
diff changeset
92 /* This function allows the application to supply new output functions for
Ritor1
parents:
diff changeset
93 * libpng if standard C streams aren't being used.
Ritor1
parents:
diff changeset
94 *
Ritor1
parents:
diff changeset
95 * This function takes as its arguments:
Ritor1
parents:
diff changeset
96 * png_ptr - pointer to a png output data structure
Ritor1
parents:
diff changeset
97 * io_ptr - pointer to user supplied structure containing info about
Ritor1
parents:
diff changeset
98 * the output functions. May be NULL.
Ritor1
parents:
diff changeset
99 * write_data_fn - pointer to a new output function that takes as its
Ritor1
parents:
diff changeset
100 * arguments a pointer to a png_struct, a pointer to
Ritor1
parents:
diff changeset
101 * data to be written, and a 32-bit unsigned int that is
Ritor1
parents:
diff changeset
102 * the number of bytes to be written. The new write
Ritor1
parents:
diff changeset
103 * function should call png_error(png_ptr, "Error msg")
Ritor1
parents:
diff changeset
104 * to exit and output any fatal error messages. May be
Ritor1
parents:
diff changeset
105 * NULL, in which case libpng's default function will
Ritor1
parents:
diff changeset
106 * be used.
Ritor1
parents:
diff changeset
107 * flush_data_fn - pointer to a new flush function that takes as its
Ritor1
parents:
diff changeset
108 * arguments a pointer to a png_struct. After a call to
Ritor1
parents:
diff changeset
109 * the flush function, there should be no data in any buffers
Ritor1
parents:
diff changeset
110 * or pending transmission. If the output method doesn't do
Ritor1
parents:
diff changeset
111 * any buffering of output, a function prototype must still be
Ritor1
parents:
diff changeset
112 * supplied although it doesn't have to do anything. If
Ritor1
parents:
diff changeset
113 * PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile
Ritor1
parents:
diff changeset
114 * time, output_flush_fn will be ignored, although it must be
Ritor1
parents:
diff changeset
115 * supplied for compatibility. May be NULL, in which case
Ritor1
parents:
diff changeset
116 * libpng's default function will be used, if
Ritor1
parents:
diff changeset
117 * PNG_WRITE_FLUSH_SUPPORTED is defined. This is not
Ritor1
parents:
diff changeset
118 * a good idea if io_ptr does not point to a standard
Ritor1
parents:
diff changeset
119 * *FILE structure.
Ritor1
parents:
diff changeset
120 */
Ritor1
parents:
diff changeset
121 void PNGAPI
Ritor1
parents:
diff changeset
122 png_set_write_fn(png_structrp png_ptr, png_voidp io_ptr,
Ritor1
parents:
diff changeset
123 png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
Ritor1
parents:
diff changeset
124 {
Ritor1
parents:
diff changeset
125 if (png_ptr == NULL)
Ritor1
parents:
diff changeset
126 return;
Ritor1
parents:
diff changeset
127
Ritor1
parents:
diff changeset
128 png_ptr->io_ptr = io_ptr;
Ritor1
parents:
diff changeset
129
Ritor1
parents:
diff changeset
130 #ifdef PNG_STDIO_SUPPORTED
Ritor1
parents:
diff changeset
131 if (write_data_fn != NULL)
Ritor1
parents:
diff changeset
132 png_ptr->write_data_fn = write_data_fn;
Ritor1
parents:
diff changeset
133
Ritor1
parents:
diff changeset
134 else
Ritor1
parents:
diff changeset
135 png_ptr->write_data_fn = png_default_write_data;
Ritor1
parents:
diff changeset
136 #else
Ritor1
parents:
diff changeset
137 png_ptr->write_data_fn = write_data_fn;
Ritor1
parents:
diff changeset
138 #endif
Ritor1
parents:
diff changeset
139
Ritor1
parents:
diff changeset
140 #ifdef PNG_WRITE_FLUSH_SUPPORTED
Ritor1
parents:
diff changeset
141 # ifdef PNG_STDIO_SUPPORTED
Ritor1
parents:
diff changeset
142
Ritor1
parents:
diff changeset
143 if (output_flush_fn != NULL)
Ritor1
parents:
diff changeset
144 png_ptr->output_flush_fn = output_flush_fn;
Ritor1
parents:
diff changeset
145
Ritor1
parents:
diff changeset
146 else
Ritor1
parents:
diff changeset
147 png_ptr->output_flush_fn = png_default_flush;
Ritor1
parents:
diff changeset
148
Ritor1
parents:
diff changeset
149 # else
Ritor1
parents:
diff changeset
150 png_ptr->output_flush_fn = output_flush_fn;
Ritor1
parents:
diff changeset
151 # endif
Ritor1
parents:
diff changeset
152 #else
Ritor1
parents:
diff changeset
153 PNG_UNUSED(output_flush_fn)
Ritor1
parents:
diff changeset
154 #endif /* PNG_WRITE_FLUSH_SUPPORTED */
Ritor1
parents:
diff changeset
155
Ritor1
parents:
diff changeset
156 #ifdef PNG_READ_SUPPORTED
Ritor1
parents:
diff changeset
157 /* It is an error to read while writing a png file */
Ritor1
parents:
diff changeset
158 if (png_ptr->read_data_fn != NULL)
Ritor1
parents:
diff changeset
159 {
Ritor1
parents:
diff changeset
160 png_ptr->read_data_fn = NULL;
Ritor1
parents:
diff changeset
161
Ritor1
parents:
diff changeset
162 png_warning(png_ptr,
Ritor1
parents:
diff changeset
163 "Can't set both read_data_fn and write_data_fn in the"
Ritor1
parents:
diff changeset
164 " same structure");
Ritor1
parents:
diff changeset
165 }
Ritor1
parents:
diff changeset
166 #endif
Ritor1
parents:
diff changeset
167 }
Ritor1
parents:
diff changeset
168 #endif /* PNG_WRITE_SUPPORTED */