Subversion Repositories Kolibri OS

Rev

Rev 1897 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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