Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: third_party/libpng/pngwutil.c

Issue 140074: Updates the PNG library to 1.2.37, enables some functionality for O3D (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/libpng/pngwtran.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* pngwutil.c - utilities to write a PNG file 2 /* pngwutil.c - utilities to write a PNG file
3 * 3 *
4 * Last changed in libpng 1.2.36 [May 7, 2009] 4 * Last changed in libpng 1.2.36 [June 4, 2009]
5 * For conditions of distribution and use, see copyright notice in png.h 5 * For conditions of distribution and use, see copyright notice in png.h
6 * Copyright (c) 1998-2009 Glenn Randers-Pehrson 6 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
9 */ 9 */
10 10
11 #define PNG_INTERNAL 11 #define PNG_INTERNAL
12 #include "png.h" 12 #include "png.h"
13 #ifdef PNG_WRITE_SUPPORTED 13 #ifdef PNG_WRITE_SUPPORTED
14 14
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 * the magic bytes of the signature, or more likely, the PNG stream is 53 * the magic bytes of the signature, or more likely, the PNG stream is
54 * being embedded into another stream and doesn't need its own signature, 54 * being embedded into another stream and doesn't need its own signature,
55 * we should call png_set_sig_bytes() to tell libpng how many of the 55 * we should call png_set_sig_bytes() to tell libpng how many of the
56 * bytes have already been written. 56 * bytes have already been written.
57 */ 57 */
58 void /* PRIVATE */ 58 void /* PRIVATE */
59 png_write_sig(png_structp png_ptr) 59 png_write_sig(png_structp png_ptr)
60 { 60 {
61 png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10}; 61 png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
62 62
63 /* write the rest of the 8 byte signature */ 63 /* Write the rest of the 8 byte signature */
64 png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes], 64 png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
65 (png_size_t)(8 - png_ptr->sig_bytes)); 65 (png_size_t)(8 - png_ptr->sig_bytes));
66 if (png_ptr->sig_bytes < 3) 66 if (png_ptr->sig_bytes < 3)
67 png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE; 67 png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
68 } 68 }
69 69
70 /* Write a PNG chunk all at once. The type is an array of ASCII characters 70 /* Write a PNG chunk all at once. The type is an array of ASCII characters
71 * representing the chunk name. The array must be at least 4 bytes in 71 * representing the chunk name. The array must be at least 4 bytes in
72 * length, and does not need to be null terminated. To be safe, pass the 72 * length, and does not need to be null terminated. To be safe, pass the
73 * pre-defined chunk names here, and if you need a new one, define it 73 * pre-defined chunk names here, and if you need a new one, define it
74 * where the others are defined. The length is the length of the data. 74 * where the others are defined. The length is the length of the data.
75 * All the data must be present. If that is not possible, use the 75 * All the data must be present. If that is not possible, use the
76 * png_write_chunk_start(), png_write_chunk_data(), and png_write_chunk_end() 76 * png_write_chunk_start(), png_write_chunk_data(), and png_write_chunk_end()
77 * functions instead. 77 * functions instead.
78 */ 78 */
79 void PNGAPI 79 void PNGAPI
80 png_write_chunk(png_structp png_ptr, png_bytep chunk_name, 80 png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
81 png_bytep data, png_size_t length) 81 png_bytep data, png_size_t length)
82 { 82 {
83 if (png_ptr == NULL) return; 83 if (png_ptr == NULL)
84 return;
84 png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length); 85 png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
85 png_write_chunk_data(png_ptr, data, (png_size_t)length); 86 png_write_chunk_data(png_ptr, data, (png_size_t)length);
86 png_write_chunk_end(png_ptr); 87 png_write_chunk_end(png_ptr);
87 } 88 }
88 89
89 /* Write the start of a PNG chunk. The type is the chunk type. 90 /* Write the start of a PNG chunk. The type is the chunk type.
90 * The total_length is the sum of the lengths of all the data you will be 91 * The total_length is the sum of the lengths of all the data you will be
91 * passing in png_write_chunk_data(). 92 * passing in png_write_chunk_data().
92 */ 93 */
93 void PNGAPI 94 void PNGAPI
94 png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name, 95 png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
95 png_uint_32 length) 96 png_uint_32 length)
96 { 97 {
97 png_byte buf[8]; 98 png_byte buf[8];
98 99
99 png_debug2(0, "Writing %s chunk, length = %lu", chunk_name, 100 png_debug2(0, "Writing %s chunk, length = %lu", chunk_name,
100 (unsigned long)length); 101 (unsigned long)length);
101 if (png_ptr == NULL) return; 102 if (png_ptr == NULL)
103 return;
102 104
103 /* write the length and the chunk name */ 105 /* Write the length and the chunk name */
104 png_save_uint_32(buf, length); 106 png_save_uint_32(buf, length);
105 png_memcpy(buf + 4, chunk_name, 4); 107 png_memcpy(buf + 4, chunk_name, 4);
106 png_write_data(png_ptr, buf, (png_size_t)8); 108 png_write_data(png_ptr, buf, (png_size_t)8);
107 /* put the chunk name into png_ptr->chunk_name */ 109 /* Put the chunk name into png_ptr->chunk_name */
108 png_memcpy(png_ptr->chunk_name, chunk_name, 4); 110 png_memcpy(png_ptr->chunk_name, chunk_name, 4);
109 /* reset the crc and run it over the chunk name */ 111 /* Reset the crc and run it over the chunk name */
110 png_reset_crc(png_ptr); 112 png_reset_crc(png_ptr);
111 png_calculate_crc(png_ptr, chunk_name, (png_size_t)4); 113 png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
112 } 114 }
113 115
114 /* Write the data of a PNG chunk started with png_write_chunk_start(). 116 /* Write the data of a PNG chunk started with png_write_chunk_start().
115 * Note that multiple calls to this function are allowed, and that the 117 * Note that multiple calls to this function are allowed, and that the
116 * sum of the lengths from these calls *must* add up to the total_length 118 * sum of the lengths from these calls *must* add up to the total_length
117 * given to png_write_chunk_start(). 119 * given to png_write_chunk_start().
118 */ 120 */
119 void PNGAPI 121 void PNGAPI
120 png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length) 122 png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
121 { 123 {
122 /* write the data, and run the CRC over it */ 124 /* Write the data, and run the CRC over it */
123 if (png_ptr == NULL) return; 125 if (png_ptr == NULL)
126 return;
124 if (data != NULL && length > 0) 127 if (data != NULL && length > 0)
125 { 128 {
126 png_write_data(png_ptr, data, length); 129 png_write_data(png_ptr, data, length);
127 /* update the CRC after writing the data, 130 /* Update the CRC after writing the data,
128 * in case that the user I/O routine alters it. 131 * in case that the user I/O routine alters it.
129 */ 132 */
130 png_calculate_crc(png_ptr, data, length); 133 png_calculate_crc(png_ptr, data, length);
131 } 134 }
132 } 135 }
133 136
134 /* Finish a chunk started with png_write_chunk_start(). */ 137 /* Finish a chunk started with png_write_chunk_start(). */
135 void PNGAPI 138 void PNGAPI
136 png_write_chunk_end(png_structp png_ptr) 139 png_write_chunk_end(png_structp png_ptr)
137 { 140 {
138 png_byte buf[4]; 141 png_byte buf[4];
139 142
140 if (png_ptr == NULL) return; 143 if (png_ptr == NULL) return;
141 144
142 /* write the crc in a single operation */ 145 /* Write the crc in a single operation */
143 png_save_uint_32(buf, png_ptr->crc); 146 png_save_uint_32(buf, png_ptr->crc);
144 147
145 png_write_data(png_ptr, buf, (png_size_t)4); 148 png_write_data(png_ptr, buf, (png_size_t)4);
146 } 149 }
147 150
148 #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED) 151 #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
149 /* 152 /* This pair of functions encapsulates the operation of (a) compressing a
150 * This pair of functions encapsulates the operation of (a) compressing a
151 * text string, and (b) issuing it later as a series of chunk data writes. 153 * text string, and (b) issuing it later as a series of chunk data writes.
152 * The compression_state structure is shared context for these functions 154 * The compression_state structure is shared context for these functions
153 * set up by the caller in order to make the whole mess thread-safe. 155 * set up by the caller in order to make the whole mess thread-safe.
154 */ 156 */
155 157
156 typedef struct 158 typedef struct
157 { 159 {
158 char *input; /* the uncompressed input data */ 160 char *input; /* The uncompressed input data */
159 int input_len; /* its length */ 161 int input_len; /* Its length */
160 int num_output_ptr; /* number of output pointers used */ 162 int num_output_ptr; /* Number of output pointers used */
161 int max_output_ptr; /* size of output_ptr */ 163 int max_output_ptr; /* Size of output_ptr */
162 png_charpp output_ptr; /* array of pointers to output */ 164 png_charpp output_ptr; /* Array of pointers to output */
163 } compression_state; 165 } compression_state;
164 166
165 /* compress given text into storage in the png_ptr structure */ 167 /* Compress given text into storage in the png_ptr structure */
166 static int /* PRIVATE */ 168 static int /* PRIVATE */
167 png_text_compress(png_structp png_ptr, 169 png_text_compress(png_structp png_ptr,
168 png_charp text, png_size_t text_len, int compression, 170 png_charp text, png_size_t text_len, int compression,
169 compression_state *comp) 171 compression_state *comp)
170 { 172 {
171 int ret; 173 int ret;
172 174
173 comp->num_output_ptr = 0; 175 comp->num_output_ptr = 0;
174 comp->max_output_ptr = 0; 176 comp->max_output_ptr = 0;
175 comp->output_ptr = NULL; 177 comp->output_ptr = NULL;
176 comp->input = NULL; 178 comp->input = NULL;
177 comp->input_len = 0; 179 comp->input_len = 0;
178 180
179 /* we may just want to pass the text right through */ 181 /* We may just want to pass the text right through */
180 if (compression == PNG_TEXT_COMPRESSION_NONE) 182 if (compression == PNG_TEXT_COMPRESSION_NONE)
181 { 183 {
182 comp->input = text; 184 comp->input = text;
183 comp->input_len = text_len; 185 comp->input_len = text_len;
184 return((int)text_len); 186 return((int)text_len);
185 } 187 }
186 188
187 if (compression >= PNG_TEXT_COMPRESSION_LAST) 189 if (compression >= PNG_TEXT_COMPRESSION_LAST)
188 { 190 {
189 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) 191 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
(...skipping 13 matching lines...) Expand all
203 * 205 *
204 * If we knew the application was well behaved, we could simplify this 206 * If we knew the application was well behaved, we could simplify this
205 * greatly by assuming we can always malloc an output buffer large 207 * greatly by assuming we can always malloc an output buffer large
206 * enough to hold the compressed text ((1001 * text_len / 1000) + 12) 208 * enough to hold the compressed text ((1001 * text_len / 1000) + 12)
207 * and malloc this directly. The only time this would be a bad idea is 209 * and malloc this directly. The only time this would be a bad idea is
208 * if we can't malloc more than 64K and we have 64K of random input 210 * if we can't malloc more than 64K and we have 64K of random input
209 * data, or if the input string is incredibly large (although this 211 * data, or if the input string is incredibly large (although this
210 * wouldn't cause a failure, just a slowdown due to swapping). 212 * wouldn't cause a failure, just a slowdown due to swapping).
211 */ 213 */
212 214
213 /* set up the compression buffers */ 215 /* Set up the compression buffers */
214 png_ptr->zstream.avail_in = (uInt)text_len; 216 png_ptr->zstream.avail_in = (uInt)text_len;
215 png_ptr->zstream.next_in = (Bytef *)text; 217 png_ptr->zstream.next_in = (Bytef *)text;
216 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; 218 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
217 png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf; 219 png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
218 220
219 /* this is the same compression loop as in png_write_row() */ 221 /* This is the same compression loop as in png_write_row() */
220 do 222 do
221 { 223 {
222 /* compress the data */ 224 /* Compress the data */
223 ret = deflate(&png_ptr->zstream, Z_NO_FLUSH); 225 ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
224 if (ret != Z_OK) 226 if (ret != Z_OK)
225 { 227 {
226 /* error */ 228 /* Error */
227 if (png_ptr->zstream.msg != NULL) 229 if (png_ptr->zstream.msg != NULL)
228 png_error(png_ptr, png_ptr->zstream.msg); 230 png_error(png_ptr, png_ptr->zstream.msg);
229 else 231 else
230 png_error(png_ptr, "zlib error"); 232 png_error(png_ptr, "zlib error");
231 } 233 }
232 /* check to see if we need more room */ 234 /* Check to see if we need more room */
233 if (!(png_ptr->zstream.avail_out)) 235 if (!(png_ptr->zstream.avail_out))
234 { 236 {
235 /* make sure the output array has room */ 237 /* Make sure the output array has room */
236 if (comp->num_output_ptr >= comp->max_output_ptr) 238 if (comp->num_output_ptr >= comp->max_output_ptr)
237 { 239 {
238 int old_max; 240 int old_max;
239 241
240 old_max = comp->max_output_ptr; 242 old_max = comp->max_output_ptr;
241 comp->max_output_ptr = comp->num_output_ptr + 4; 243 comp->max_output_ptr = comp->num_output_ptr + 4;
242 if (comp->output_ptr != NULL) 244 if (comp->output_ptr != NULL)
243 { 245 {
244 png_charpp old_ptr; 246 png_charpp old_ptr;
245 247
246 old_ptr = comp->output_ptr; 248 old_ptr = comp->output_ptr;
247 comp->output_ptr = (png_charpp)png_malloc(png_ptr, 249 comp->output_ptr = (png_charpp)png_malloc(png_ptr,
248 (png_uint_32) 250 (png_uint_32)
249 (comp->max_output_ptr * png_sizeof(png_charpp))); 251 (comp->max_output_ptr * png_sizeof(png_charpp)));
250 png_memcpy(comp->output_ptr, old_ptr, old_max 252 png_memcpy(comp->output_ptr, old_ptr, old_max
251 * png_sizeof(png_charp)); 253 * png_sizeof(png_charp));
252 png_free(png_ptr, old_ptr); 254 png_free(png_ptr, old_ptr);
253 } 255 }
254 else 256 else
255 comp->output_ptr = (png_charpp)png_malloc(png_ptr, 257 comp->output_ptr = (png_charpp)png_malloc(png_ptr,
256 (png_uint_32) 258 (png_uint_32)
257 (comp->max_output_ptr * png_sizeof(png_charp))); 259 (comp->max_output_ptr * png_sizeof(png_charp)));
258 } 260 }
259 261
260 /* save the data */ 262 /* Save the data */
261 comp->output_ptr[comp->num_output_ptr] = 263 comp->output_ptr[comp->num_output_ptr] =
262 (png_charp)png_malloc(png_ptr, 264 (png_charp)png_malloc(png_ptr,
263 (png_uint_32)png_ptr->zbuf_size); 265 (png_uint_32)png_ptr->zbuf_size);
264 png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, 266 png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
265 png_ptr->zbuf_size); 267 png_ptr->zbuf_size);
266 comp->num_output_ptr++; 268 comp->num_output_ptr++;
267 269
268 /* and reset the buffer */ 270 /* and reset the buffer */
269 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; 271 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
270 png_ptr->zstream.next_out = png_ptr->zbuf; 272 png_ptr->zstream.next_out = png_ptr->zbuf;
271 } 273 }
272 /* continue until we don't have any more to compress */ 274 /* Continue until we don't have any more to compress */
273 } while (png_ptr->zstream.avail_in); 275 } while (png_ptr->zstream.avail_in);
274 276
275 /* finish the compression */ 277 /* Finish the compression */
276 do 278 do
277 { 279 {
278 /* tell zlib we are finished */ 280 /* Tell zlib we are finished */
279 ret = deflate(&png_ptr->zstream, Z_FINISH); 281 ret = deflate(&png_ptr->zstream, Z_FINISH);
280 282
281 if (ret == Z_OK) 283 if (ret == Z_OK)
282 { 284 {
283 /* check to see if we need more room */ 285 /* Check to see if we need more room */
284 if (!(png_ptr->zstream.avail_out)) 286 if (!(png_ptr->zstream.avail_out))
285 { 287 {
286 /* check to make sure our output array has room */ 288 /* Check to make sure our output array has room */
287 if (comp->num_output_ptr >= comp->max_output_ptr) 289 if (comp->num_output_ptr >= comp->max_output_ptr)
288 { 290 {
289 int old_max; 291 int old_max;
290 292
291 old_max = comp->max_output_ptr; 293 old_max = comp->max_output_ptr;
292 comp->max_output_ptr = comp->num_output_ptr + 4; 294 comp->max_output_ptr = comp->num_output_ptr + 4;
293 if (comp->output_ptr != NULL) 295 if (comp->output_ptr != NULL)
294 { 296 {
295 png_charpp old_ptr; 297 png_charpp old_ptr;
296 298
297 old_ptr = comp->output_ptr; 299 old_ptr = comp->output_ptr;
298 /* This could be optimized to realloc() */ 300 /* This could be optimized to realloc() */
299 comp->output_ptr = (png_charpp)png_malloc(png_ptr, 301 comp->output_ptr = (png_charpp)png_malloc(png_ptr,
300 (png_uint_32)(comp->max_output_ptr * 302 (png_uint_32)(comp->max_output_ptr *
301 png_sizeof(png_charp))); 303 png_sizeof(png_charp)));
302 png_memcpy(comp->output_ptr, old_ptr, 304 png_memcpy(comp->output_ptr, old_ptr,
303 old_max * png_sizeof(png_charp)); 305 old_max * png_sizeof(png_charp));
304 png_free(png_ptr, old_ptr); 306 png_free(png_ptr, old_ptr);
305 } 307 }
306 else 308 else
307 comp->output_ptr = (png_charpp)png_malloc(png_ptr, 309 comp->output_ptr = (png_charpp)png_malloc(png_ptr,
308 (png_uint_32)(comp->max_output_ptr * 310 (png_uint_32)(comp->max_output_ptr *
309 png_sizeof(png_charp))); 311 png_sizeof(png_charp)));
310 } 312 }
311 313
312 /* save off the data */ 314 /* Save the data */
313 comp->output_ptr[comp->num_output_ptr] = 315 comp->output_ptr[comp->num_output_ptr] =
314 (png_charp)png_malloc(png_ptr, 316 (png_charp)png_malloc(png_ptr,
315 (png_uint_32)png_ptr->zbuf_size); 317 (png_uint_32)png_ptr->zbuf_size);
316 png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, 318 png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
317 png_ptr->zbuf_size); 319 png_ptr->zbuf_size);
318 comp->num_output_ptr++; 320 comp->num_output_ptr++;
319 321
320 /* and reset the buffer pointers */ 322 /* and reset the buffer pointers */
321 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; 323 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
322 png_ptr->zstream.next_out = png_ptr->zbuf; 324 png_ptr->zstream.next_out = png_ptr->zbuf;
323 } 325 }
324 } 326 }
325 else if (ret != Z_STREAM_END) 327 else if (ret != Z_STREAM_END)
326 { 328 {
327 /* we got an error */ 329 /* We got an error */
328 if (png_ptr->zstream.msg != NULL) 330 if (png_ptr->zstream.msg != NULL)
329 png_error(png_ptr, png_ptr->zstream.msg); 331 png_error(png_ptr, png_ptr->zstream.msg);
330 else 332 else
331 png_error(png_ptr, "zlib error"); 333 png_error(png_ptr, "zlib error");
332 } 334 }
333 } while (ret != Z_STREAM_END); 335 } while (ret != Z_STREAM_END);
334 336
335 /* text length is number of buffers plus last buffer */ 337 /* Text length is number of buffers plus last buffer */
336 text_len = png_ptr->zbuf_size * comp->num_output_ptr; 338 text_len = png_ptr->zbuf_size * comp->num_output_ptr;
337 if (png_ptr->zstream.avail_out < png_ptr->zbuf_size) 339 if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
338 text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out; 340 text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
339 341
340 return((int)text_len); 342 return((int)text_len);
341 } 343 }
342 344
343 /* ship the compressed text out via chunk writes */ 345 /* Ship the compressed text out via chunk writes */
344 static void /* PRIVATE */ 346 static void /* PRIVATE */
345 png_write_compressed_data_out(png_structp png_ptr, compression_state *comp) 347 png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
346 { 348 {
347 int i; 349 int i;
348 350
349 /* handle the no-compression case */ 351 /* Handle the no-compression case */
350 if (comp->input) 352 if (comp->input)
351 { 353 {
352 png_write_chunk_data(png_ptr, (png_bytep)comp->input, 354 png_write_chunk_data(png_ptr, (png_bytep)comp->input,
353 (png_size_t)comp->input_len); 355 (png_size_t)comp->input_len);
354 return; 356 return;
355 } 357 }
356 358
357 /* write saved output buffers, if any */ 359 /* Write saved output buffers, if any */
358 for (i = 0; i < comp->num_output_ptr; i++) 360 for (i = 0; i < comp->num_output_ptr; i++)
359 { 361 {
360 png_write_chunk_data(png_ptr, (png_bytep)comp->output_ptr[i], 362 png_write_chunk_data(png_ptr, (png_bytep)comp->output_ptr[i],
361 (png_size_t)png_ptr->zbuf_size); 363 (png_size_t)png_ptr->zbuf_size);
362 png_free(png_ptr, comp->output_ptr[i]); 364 png_free(png_ptr, comp->output_ptr[i]);
363 comp->output_ptr[i]=NULL; 365 comp->output_ptr[i]=NULL;
364 } 366 }
365 if (comp->max_output_ptr != 0) 367 if (comp->max_output_ptr != 0)
366 png_free(png_ptr, comp->output_ptr); 368 png_free(png_ptr, comp->output_ptr);
367 comp->output_ptr=NULL; 369 comp->output_ptr=NULL;
368 /* write anything left in zbuf */ 370 /* Write anything left in zbuf */
369 if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size) 371 if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
370 png_write_chunk_data(png_ptr, png_ptr->zbuf, 372 png_write_chunk_data(png_ptr, png_ptr->zbuf,
371 (png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out)); 373 (png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out));
372 374
373 /* reset zlib for another zTXt/iTXt or image data */ 375 /* Reset zlib for another zTXt/iTXt or image data */
374 deflateReset(&png_ptr->zstream); 376 deflateReset(&png_ptr->zstream);
375 png_ptr->zstream.data_type = Z_BINARY; 377 png_ptr->zstream.data_type = Z_BINARY;
376 } 378 }
377 #endif 379 #endif
378 380
379 /* Write the IHDR chunk, and update the png_struct with the necessary 381 /* Write the IHDR chunk, and update the png_struct with the necessary
380 * information. Note that the rest of this code depends upon this 382 * information. Note that the rest of this code depends upon this
381 * information being correct. 383 * information being correct.
382 */ 384 */
383 void /* PRIVATE */ 385 void /* PRIVATE */
384 png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height, 386 png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
385 int bit_depth, int color_type, int compression_type, int filter_type, 387 int bit_depth, int color_type, int compression_type, int filter_type,
386 int interlace_type) 388 int interlace_type)
387 { 389 {
388 #ifdef PNG_USE_LOCAL_ARRAYS 390 #ifdef PNG_USE_LOCAL_ARRAYS
389 PNG_IHDR; 391 PNG_IHDR;
390 #endif 392 #endif
391 int ret; 393 int ret;
392 394
393 png_byte buf[13]; /* buffer to store the IHDR info */ 395 png_byte buf[13]; /* Buffer to store the IHDR info */
394 396
395 png_debug(1, "in png_write_IHDR"); 397 png_debug(1, "in png_write_IHDR");
396 /* Check that we have valid input data from the application info */ 398 /* Check that we have valid input data from the application info */
397 switch (color_type) 399 switch (color_type)
398 { 400 {
399 case PNG_COLOR_TYPE_GRAY: 401 case PNG_COLOR_TYPE_GRAY:
400 switch (bit_depth) 402 switch (bit_depth)
401 { 403 {
402 case 1: 404 case 1:
403 case 2: 405 case 2:
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 if (interlace_type != PNG_INTERLACE_NONE && 471 if (interlace_type != PNG_INTERLACE_NONE &&
470 interlace_type != PNG_INTERLACE_ADAM7) 472 interlace_type != PNG_INTERLACE_ADAM7)
471 { 473 {
472 png_warning(png_ptr, "Invalid interlace type specified"); 474 png_warning(png_ptr, "Invalid interlace type specified");
473 interlace_type = PNG_INTERLACE_ADAM7; 475 interlace_type = PNG_INTERLACE_ADAM7;
474 } 476 }
475 #else 477 #else
476 interlace_type=PNG_INTERLACE_NONE; 478 interlace_type=PNG_INTERLACE_NONE;
477 #endif 479 #endif
478 480
479 /* save off the relevent information */ 481 /* Save the relevent information */
480 png_ptr->bit_depth = (png_byte)bit_depth; 482 png_ptr->bit_depth = (png_byte)bit_depth;
481 png_ptr->color_type = (png_byte)color_type; 483 png_ptr->color_type = (png_byte)color_type;
482 png_ptr->interlaced = (png_byte)interlace_type; 484 png_ptr->interlaced = (png_byte)interlace_type;
483 #if defined(PNG_MNG_FEATURES_SUPPORTED) 485 #if defined(PNG_MNG_FEATURES_SUPPORTED)
484 png_ptr->filter_type = (png_byte)filter_type; 486 png_ptr->filter_type = (png_byte)filter_type;
485 #endif 487 #endif
486 png_ptr->compression_type = (png_byte)compression_type; 488 png_ptr->compression_type = (png_byte)compression_type;
487 png_ptr->width = width; 489 png_ptr->width = width;
488 png_ptr->height = height; 490 png_ptr->height = height;
489 491
490 png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels); 492 png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
491 png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width); 493 png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
492 /* set the usr info, so any transformations can modify it */ 494 /* Set the usr info, so any transformations can modify it */
493 png_ptr->usr_width = png_ptr->width; 495 png_ptr->usr_width = png_ptr->width;
494 png_ptr->usr_bit_depth = png_ptr->bit_depth; 496 png_ptr->usr_bit_depth = png_ptr->bit_depth;
495 png_ptr->usr_channels = png_ptr->channels; 497 png_ptr->usr_channels = png_ptr->channels;
496 498
497 /* pack the header information into the buffer */ 499 /* Pack the header information into the buffer */
498 png_save_uint_32(buf, width); 500 png_save_uint_32(buf, width);
499 png_save_uint_32(buf + 4, height); 501 png_save_uint_32(buf + 4, height);
500 buf[8] = (png_byte)bit_depth; 502 buf[8] = (png_byte)bit_depth;
501 buf[9] = (png_byte)color_type; 503 buf[9] = (png_byte)color_type;
502 buf[10] = (png_byte)compression_type; 504 buf[10] = (png_byte)compression_type;
503 buf[11] = (png_byte)filter_type; 505 buf[11] = (png_byte)filter_type;
504 buf[12] = (png_byte)interlace_type; 506 buf[12] = (png_byte)interlace_type;
505 507
506 /* write the chunk */ 508 /* Write the chunk */
507 png_write_chunk(png_ptr, (png_bytep)png_IHDR, buf, (png_size_t)13); 509 png_write_chunk(png_ptr, (png_bytep)png_IHDR, buf, (png_size_t)13);
508 510
509 /* initialize zlib with PNG info */ 511 /* Initialize zlib with PNG info */
510 png_ptr->zstream.zalloc = png_zalloc; 512 png_ptr->zstream.zalloc = png_zalloc;
511 png_ptr->zstream.zfree = png_zfree; 513 png_ptr->zstream.zfree = png_zfree;
512 png_ptr->zstream.opaque = (voidpf)png_ptr; 514 png_ptr->zstream.opaque = (voidpf)png_ptr;
513 if (!(png_ptr->do_filter)) 515 if (!(png_ptr->do_filter))
514 { 516 {
515 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE || 517 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
516 png_ptr->bit_depth < 8) 518 png_ptr->bit_depth < 8)
517 png_ptr->do_filter = PNG_FILTER_NONE; 519 png_ptr->do_filter = PNG_FILTER_NONE;
518 else 520 else
519 png_ptr->do_filter = PNG_ALL_FILTERS; 521 png_ptr->do_filter = PNG_ALL_FILTERS;
(...skipping 22 matching lines...) Expand all
542 "zlib failed to initialize compressor -- version error"); 544 "zlib failed to initialize compressor -- version error");
543 if (ret == Z_STREAM_ERROR) png_error(png_ptr, 545 if (ret == Z_STREAM_ERROR) png_error(png_ptr,
544 "zlib failed to initialize compressor -- stream error"); 546 "zlib failed to initialize compressor -- stream error");
545 if (ret == Z_MEM_ERROR) png_error(png_ptr, 547 if (ret == Z_MEM_ERROR) png_error(png_ptr,
546 "zlib failed to initialize compressor -- mem error"); 548 "zlib failed to initialize compressor -- mem error");
547 png_error(png_ptr, "zlib failed to initialize compressor"); 549 png_error(png_ptr, "zlib failed to initialize compressor");
548 } 550 }
549 png_ptr->zstream.next_out = png_ptr->zbuf; 551 png_ptr->zstream.next_out = png_ptr->zbuf;
550 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; 552 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
551 /* libpng is not interested in zstream.data_type */ 553 /* libpng is not interested in zstream.data_type */
552 /* set it to a predefined value, to avoid its evaluation inside zlib */ 554 /* Set it to a predefined value, to avoid its evaluation inside zlib */
553 png_ptr->zstream.data_type = Z_BINARY; 555 png_ptr->zstream.data_type = Z_BINARY;
554 556
555 png_ptr->mode = PNG_HAVE_IHDR; 557 png_ptr->mode = PNG_HAVE_IHDR;
556 } 558 }
557 559
558 /* write the palette. We are careful not to trust png_color to be in the 560 /* Write the palette. We are careful not to trust png_color to be in the
559 * correct order for PNG, so people can redefine it to any convenient 561 * correct order for PNG, so people can redefine it to any convenient
560 * structure. 562 * structure.
561 */ 563 */
562 void /* PRIVATE */ 564 void /* PRIVATE */
563 png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal) 565 png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
564 { 566 {
565 #ifdef PNG_USE_LOCAL_ARRAYS 567 #ifdef PNG_USE_LOCAL_ARRAYS
566 PNG_PLTE; 568 PNG_PLTE;
567 #endif 569 #endif
568 png_uint_32 i; 570 png_uint_32 i;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 buf[0] = pal_ptr[i].red; 617 buf[0] = pal_ptr[i].red;
616 buf[1] = pal_ptr[i].green; 618 buf[1] = pal_ptr[i].green;
617 buf[2] = pal_ptr[i].blue; 619 buf[2] = pal_ptr[i].blue;
618 png_write_chunk_data(png_ptr, buf, (png_size_t)3); 620 png_write_chunk_data(png_ptr, buf, (png_size_t)3);
619 } 621 }
620 #endif 622 #endif
621 png_write_chunk_end(png_ptr); 623 png_write_chunk_end(png_ptr);
622 png_ptr->mode |= PNG_HAVE_PLTE; 624 png_ptr->mode |= PNG_HAVE_PLTE;
623 } 625 }
624 626
625 /* write an IDAT chunk */ 627 /* Write an IDAT chunk */
626 void /* PRIVATE */ 628 void /* PRIVATE */
627 png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length) 629 png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
628 { 630 {
629 #ifdef PNG_USE_LOCAL_ARRAYS 631 #ifdef PNG_USE_LOCAL_ARRAYS
630 PNG_IDAT; 632 PNG_IDAT;
631 #endif 633 #endif
632 png_debug(1, "in png_write_IDAT"); 634 png_debug(1, "in png_write_IDAT");
633 635
634 /* Optimize the CMF field in the zlib stream. */ 636 /* Optimize the CMF field in the zlib stream. */
635 /* This hack of the zlib stream is compliant to the stream specification. */ 637 /* This hack of the zlib stream is compliant to the stream specification. */
636 if (!(png_ptr->mode & PNG_HAVE_IDAT) && 638 if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
637 png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE) 639 png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
638 { 640 {
639 unsigned int z_cmf = data[0]; /* zlib compression method and flags */ 641 unsigned int z_cmf = data[0]; /* zlib compression method and flags */
640 if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70) 642 if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
641 { 643 {
642 /* Avoid memory underflows and multiplication overflows. */ 644 /* Avoid memory underflows and multiplication overflows.
643 /* The conditions below are practically always satisfied; 645 *
644 however, they still must be checked. */ 646 * The conditions below are practically always satisfied;
647 * however, they still must be checked.
648 */
645 if (length >= 2 && 649 if (length >= 2 &&
646 png_ptr->height < 16384 && png_ptr->width < 16384) 650 png_ptr->height < 16384 && png_ptr->width < 16384)
647 { 651 {
648 png_uint_32 uncompressed_idat_size = png_ptr->height * 652 png_uint_32 uncompressed_idat_size = png_ptr->height *
649 ((png_ptr->width * 653 ((png_ptr->width *
650 png_ptr->channels * png_ptr->bit_depth + 15) >> 3); 654 png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
651 unsigned int z_cinfo = z_cmf >> 4; 655 unsigned int z_cinfo = z_cmf >> 4;
652 unsigned int half_z_window_size = 1 << (z_cinfo + 7); 656 unsigned int half_z_window_size = 1 << (z_cinfo + 7);
653 while (uncompressed_idat_size <= half_z_window_size && 657 while (uncompressed_idat_size <= half_z_window_size &&
654 half_z_window_size >= 256) 658 half_z_window_size >= 256)
(...skipping 12 matching lines...) Expand all
667 } 671 }
668 else 672 else
669 png_error(png_ptr, 673 png_error(png_ptr,
670 "Invalid zlib compression method or flags in IDAT"); 674 "Invalid zlib compression method or flags in IDAT");
671 } 675 }
672 676
673 png_write_chunk(png_ptr, (png_bytep)png_IDAT, data, length); 677 png_write_chunk(png_ptr, (png_bytep)png_IDAT, data, length);
674 png_ptr->mode |= PNG_HAVE_IDAT; 678 png_ptr->mode |= PNG_HAVE_IDAT;
675 } 679 }
676 680
677 /* write an IEND chunk */ 681 /* Write an IEND chunk */
678 void /* PRIVATE */ 682 void /* PRIVATE */
679 png_write_IEND(png_structp png_ptr) 683 png_write_IEND(png_structp png_ptr)
680 { 684 {
681 #ifdef PNG_USE_LOCAL_ARRAYS 685 #ifdef PNG_USE_LOCAL_ARRAYS
682 PNG_IEND; 686 PNG_IEND;
683 #endif 687 #endif
684 png_debug(1, "in png_write_IEND"); 688 png_debug(1, "in png_write_IEND");
685 png_write_chunk(png_ptr, (png_bytep)png_IEND, png_bytep_NULL, 689 png_write_chunk(png_ptr, (png_bytep)png_IEND, png_bytep_NULL,
686 (png_size_t)0); 690 (png_size_t)0);
687 png_ptr->mode |= PNG_HAVE_IEND; 691 png_ptr->mode |= PNG_HAVE_IEND;
688 } 692 }
689 693
690 #if defined(PNG_WRITE_gAMA_SUPPORTED) 694 #if defined(PNG_WRITE_gAMA_SUPPORTED)
691 /* write a gAMA chunk */ 695 /* Write a gAMA chunk */
692 #ifdef PNG_FLOATING_POINT_SUPPORTED 696 #ifdef PNG_FLOATING_POINT_SUPPORTED
693 void /* PRIVATE */ 697 void /* PRIVATE */
694 png_write_gAMA(png_structp png_ptr, double file_gamma) 698 png_write_gAMA(png_structp png_ptr, double file_gamma)
695 { 699 {
696 #ifdef PNG_USE_LOCAL_ARRAYS 700 #ifdef PNG_USE_LOCAL_ARRAYS
697 PNG_gAMA; 701 PNG_gAMA;
698 #endif 702 #endif
699 png_uint_32 igamma; 703 png_uint_32 igamma;
700 png_byte buf[4]; 704 png_byte buf[4];
701 705
(...skipping 15 matching lines...) Expand all
717 721
718 png_debug(1, "in png_write_gAMA"); 722 png_debug(1, "in png_write_gAMA");
719 /* file_gamma is saved in 1/100,000ths */ 723 /* file_gamma is saved in 1/100,000ths */
720 png_save_uint_32(buf, (png_uint_32)file_gamma); 724 png_save_uint_32(buf, (png_uint_32)file_gamma);
721 png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4); 725 png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4);
722 } 726 }
723 #endif 727 #endif
724 #endif 728 #endif
725 729
726 #if defined(PNG_WRITE_sRGB_SUPPORTED) 730 #if defined(PNG_WRITE_sRGB_SUPPORTED)
727 /* write a sRGB chunk */ 731 /* Write a sRGB chunk */
728 void /* PRIVATE */ 732 void /* PRIVATE */
729 png_write_sRGB(png_structp png_ptr, int srgb_intent) 733 png_write_sRGB(png_structp png_ptr, int srgb_intent)
730 { 734 {
731 #ifdef PNG_USE_LOCAL_ARRAYS 735 #ifdef PNG_USE_LOCAL_ARRAYS
732 PNG_sRGB; 736 PNG_sRGB;
733 #endif 737 #endif
734 png_byte buf[1]; 738 png_byte buf[1];
735 739
736 png_debug(1, "in png_write_sRGB"); 740 png_debug(1, "in png_write_sRGB");
737 if (srgb_intent >= PNG_sRGB_INTENT_LAST) 741 if (srgb_intent >= PNG_sRGB_INTENT_LAST)
738 png_warning(png_ptr, 742 png_warning(png_ptr,
739 "Invalid sRGB rendering intent specified"); 743 "Invalid sRGB rendering intent specified");
740 buf[0]=(png_byte)srgb_intent; 744 buf[0]=(png_byte)srgb_intent;
741 png_write_chunk(png_ptr, (png_bytep)png_sRGB, buf, (png_size_t)1); 745 png_write_chunk(png_ptr, (png_bytep)png_sRGB, buf, (png_size_t)1);
742 } 746 }
743 #endif 747 #endif
744 748
745 #if defined(PNG_WRITE_iCCP_SUPPORTED) 749 #if defined(PNG_WRITE_iCCP_SUPPORTED)
746 /* write an iCCP chunk */ 750 /* Write an iCCP chunk */
747 void /* PRIVATE */ 751 void /* PRIVATE */
748 png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type, 752 png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
749 png_charp profile, int profile_len) 753 png_charp profile, int profile_len)
750 { 754 {
751 #ifdef PNG_USE_LOCAL_ARRAYS 755 #ifdef PNG_USE_LOCAL_ARRAYS
752 PNG_iCCP; 756 PNG_iCCP;
753 #endif 757 #endif
754 png_size_t name_len; 758 png_size_t name_len;
755 png_charp new_name; 759 png_charp new_name;
756 compression_state comp; 760 compression_state comp;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 { 797 {
794 png_warning(png_ptr, 798 png_warning(png_ptr,
795 "Truncating profile to actual length in iCCP chunk"); 799 "Truncating profile to actual length in iCCP chunk");
796 profile_len = embedded_profile_len; 800 profile_len = embedded_profile_len;
797 } 801 }
798 802
799 if (profile_len) 803 if (profile_len)
800 profile_len = png_text_compress(png_ptr, profile, 804 profile_len = png_text_compress(png_ptr, profile,
801 (png_size_t)profile_len, PNG_COMPRESSION_TYPE_BASE, &comp); 805 (png_size_t)profile_len, PNG_COMPRESSION_TYPE_BASE, &comp);
802 806
803 /* make sure we include the NULL after the name and the compression type */ 807 /* Make sure we include the NULL after the name and the compression type */
804 png_write_chunk_start(png_ptr, (png_bytep)png_iCCP, 808 png_write_chunk_start(png_ptr, (png_bytep)png_iCCP,
805 (png_uint_32)(name_len + profile_len + 2)); 809 (png_uint_32)(name_len + profile_len + 2));
806 new_name[name_len + 1] = 0x00; 810 new_name[name_len + 1] = 0x00;
807 png_write_chunk_data(png_ptr, (png_bytep)new_name, 811 png_write_chunk_data(png_ptr, (png_bytep)new_name,
808 (png_size_t)(name_len + 2)); 812 (png_size_t)(name_len + 2));
809 813
810 if (profile_len) 814 if (profile_len)
811 png_write_compressed_data_out(png_ptr, &comp); 815 png_write_compressed_data_out(png_ptr, &comp);
812 816
813 png_write_chunk_end(png_ptr); 817 png_write_chunk_end(png_ptr);
814 png_free(png_ptr, new_name); 818 png_free(png_ptr, new_name);
815 } 819 }
816 #endif 820 #endif
817 821
818 #if defined(PNG_WRITE_sPLT_SUPPORTED) 822 #if defined(PNG_WRITE_sPLT_SUPPORTED)
819 /* write a sPLT chunk */ 823 /* Write a sPLT chunk */
820 void /* PRIVATE */ 824 void /* PRIVATE */
821 png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette) 825 png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
822 { 826 {
823 #ifdef PNG_USE_LOCAL_ARRAYS 827 #ifdef PNG_USE_LOCAL_ARRAYS
824 PNG_sPLT; 828 PNG_sPLT;
825 #endif 829 #endif
826 png_size_t name_len; 830 png_size_t name_len;
827 png_charp new_name; 831 png_charp new_name;
828 png_byte entrybuf[10]; 832 png_byte entrybuf[10];
829 int entry_size = (spalette->depth == 8 ? 6 : 10); 833 int entry_size = (spalette->depth == 8 ? 6 : 10);
830 int palette_size = entry_size * spalette->nentries; 834 int palette_size = entry_size * spalette->nentries;
831 png_sPLT_entryp ep; 835 png_sPLT_entryp ep;
832 #ifdef PNG_NO_POINTER_INDEXING 836 #ifdef PNG_NO_POINTER_INDEXING
833 int i; 837 int i;
834 #endif 838 #endif
835 839
836 png_debug(1, "in png_write_sPLT"); 840 png_debug(1, "in png_write_sPLT");
837 if ((name_len = png_check_keyword(png_ptr, 841 if ((name_len = png_check_keyword(png_ptr,spalette->name, &new_name))==0)
838 spalette->name, &new_name))==0) 842 return;
839 return;
840 843
841 /* make sure we include the NULL after the name */ 844 /* Make sure we include the NULL after the name */
842 png_write_chunk_start(png_ptr, (png_bytep)png_sPLT, 845 png_write_chunk_start(png_ptr, (png_bytep)png_sPLT,
843 (png_uint_32)(name_len + 2 + palette_size)); 846 (png_uint_32)(name_len + 2 + palette_size));
844 png_write_chunk_data(png_ptr, (png_bytep)new_name, 847 png_write_chunk_data(png_ptr, (png_bytep)new_name,
845 (png_size_t)(name_len + 1)); 848 (png_size_t)(name_len + 1));
846 png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, (png_size_t)1); 849 png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, (png_size_t)1);
847 850
848 /* loop through each palette entry, writing appropriately */ 851 /* Loop through each palette entry, writing appropriately */
849 #ifndef PNG_NO_POINTER_INDEXING 852 #ifndef PNG_NO_POINTER_INDEXING
850 for (ep = spalette->entries; ep<spalette->entries + spalette->nentries; ep++) 853 for (ep = spalette->entries; ep<spalette->entries + spalette->nentries; ep++)
851 { 854 {
852 if (spalette->depth == 8) 855 if (spalette->depth == 8)
853 { 856 {
854 entrybuf[0] = (png_byte)ep->red; 857 entrybuf[0] = (png_byte)ep->red;
855 entrybuf[1] = (png_byte)ep->green; 858 entrybuf[1] = (png_byte)ep->green;
856 entrybuf[2] = (png_byte)ep->blue; 859 entrybuf[2] = (png_byte)ep->blue;
857 entrybuf[3] = (png_byte)ep->alpha; 860 entrybuf[3] = (png_byte)ep->alpha;
858 png_save_uint_16(entrybuf + 4, ep->frequency); 861 png_save_uint_16(entrybuf + 4, ep->frequency);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size); 893 png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
891 } 894 }
892 #endif 895 #endif
893 896
894 png_write_chunk_end(png_ptr); 897 png_write_chunk_end(png_ptr);
895 png_free(png_ptr, new_name); 898 png_free(png_ptr, new_name);
896 } 899 }
897 #endif 900 #endif
898 901
899 #if defined(PNG_WRITE_sBIT_SUPPORTED) 902 #if defined(PNG_WRITE_sBIT_SUPPORTED)
900 /* write the sBIT chunk */ 903 /* Write the sBIT chunk */
901 void /* PRIVATE */ 904 void /* PRIVATE */
902 png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type) 905 png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
903 { 906 {
904 #ifdef PNG_USE_LOCAL_ARRAYS 907 #ifdef PNG_USE_LOCAL_ARRAYS
905 PNG_sBIT; 908 PNG_sBIT;
906 #endif 909 #endif
907 png_byte buf[4]; 910 png_byte buf[4];
908 png_size_t size; 911 png_size_t size;
909 912
910 png_debug(1, "in png_write_sBIT"); 913 png_debug(1, "in png_write_sBIT");
911 /* make sure we don't depend upon the order of PNG_COLOR_8 */ 914 /* Make sure we don't depend upon the order of PNG_COLOR_8 */
912 if (color_type & PNG_COLOR_MASK_COLOR) 915 if (color_type & PNG_COLOR_MASK_COLOR)
913 { 916 {
914 png_byte maxbits; 917 png_byte maxbits;
915 918
916 maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 : 919 maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
917 png_ptr->usr_bit_depth); 920 png_ptr->usr_bit_depth);
918 if (sbit->red == 0 || sbit->red > maxbits || 921 if (sbit->red == 0 || sbit->red > maxbits ||
919 sbit->green == 0 || sbit->green > maxbits || 922 sbit->green == 0 || sbit->green > maxbits ||
920 sbit->blue == 0 || sbit->blue > maxbits) 923 sbit->blue == 0 || sbit->blue > maxbits)
921 { 924 {
(...skipping 24 matching lines...) Expand all
946 return; 949 return;
947 } 950 }
948 buf[size++] = sbit->alpha; 951 buf[size++] = sbit->alpha;
949 } 952 }
950 953
951 png_write_chunk(png_ptr, (png_bytep)png_sBIT, buf, size); 954 png_write_chunk(png_ptr, (png_bytep)png_sBIT, buf, size);
952 } 955 }
953 #endif 956 #endif
954 957
955 #if defined(PNG_WRITE_cHRM_SUPPORTED) 958 #if defined(PNG_WRITE_cHRM_SUPPORTED)
956 /* write the cHRM chunk */ 959 /* Write the cHRM chunk */
957 #ifdef PNG_FLOATING_POINT_SUPPORTED 960 #ifdef PNG_FLOATING_POINT_SUPPORTED
958 void /* PRIVATE */ 961 void /* PRIVATE */
959 png_write_cHRM(png_structp png_ptr, double white_x, double white_y, 962 png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
960 double red_x, double red_y, double green_x, double green_y, 963 double red_x, double red_y, double green_x, double green_y,
961 double blue_x, double blue_y) 964 double blue_x, double blue_y)
962 { 965 {
963 #ifdef PNG_USE_LOCAL_ARRAYS 966 #ifdef PNG_USE_LOCAL_ARRAYS
964 PNG_cHRM; 967 PNG_cHRM;
965 #endif 968 #endif
966 png_byte buf[32]; 969 png_byte buf[32];
(...skipping 10 matching lines...) Expand all
977 int_green_x = (png_uint_32)(green_x * 100000.0 + 0.5); 980 int_green_x = (png_uint_32)(green_x * 100000.0 + 0.5);
978 int_green_y = (png_uint_32)(green_y * 100000.0 + 0.5); 981 int_green_y = (png_uint_32)(green_y * 100000.0 + 0.5);
979 int_blue_x = (png_uint_32)(blue_x * 100000.0 + 0.5); 982 int_blue_x = (png_uint_32)(blue_x * 100000.0 + 0.5);
980 int_blue_y = (png_uint_32)(blue_y * 100000.0 + 0.5); 983 int_blue_y = (png_uint_32)(blue_y * 100000.0 + 0.5);
981 984
982 #if !defined(PNG_NO_CHECK_cHRM) 985 #if !defined(PNG_NO_CHECK_cHRM)
983 if (png_check_cHRM_fixed(png_ptr, int_white_x, int_white_y, 986 if (png_check_cHRM_fixed(png_ptr, int_white_x, int_white_y,
984 int_red_x, int_red_y, int_green_x, int_green_y, int_blue_x, int_blue_y)) 987 int_red_x, int_red_y, int_green_x, int_green_y, int_blue_x, int_blue_y))
985 #endif 988 #endif
986 { 989 {
987 /* each value is saved in 1/100,000ths */ 990 /* Each value is saved in 1/100,000ths */
988 991
989 png_save_uint_32(buf, int_white_x); 992 png_save_uint_32(buf, int_white_x);
990 png_save_uint_32(buf + 4, int_white_y); 993 png_save_uint_32(buf + 4, int_white_y);
991 994
992 png_save_uint_32(buf + 8, int_red_x); 995 png_save_uint_32(buf + 8, int_red_x);
993 png_save_uint_32(buf + 12, int_red_y); 996 png_save_uint_32(buf + 12, int_red_y);
994 997
995 png_save_uint_32(buf + 16, int_green_x); 998 png_save_uint_32(buf + 16, int_green_x);
996 png_save_uint_32(buf + 20, int_green_y); 999 png_save_uint_32(buf + 20, int_green_y);
997 1000
998 png_save_uint_32(buf + 24, int_blue_x); 1001 png_save_uint_32(buf + 24, int_blue_x);
999 png_save_uint_32(buf + 28, int_blue_y); 1002 png_save_uint_32(buf + 28, int_blue_y);
1000 1003
1001 png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32); 1004 png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32);
1002 } 1005 }
1003 } 1006 }
1004 #endif 1007 #endif
1005 #ifdef PNG_FIXED_POINT_SUPPORTED 1008 #ifdef PNG_FIXED_POINT_SUPPORTED
1006 void /* PRIVATE */ 1009 void /* PRIVATE */
1007 png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x, 1010 png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
1008 png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y, 1011 png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
1009 png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x, 1012 png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
1010 png_fixed_point blue_y) 1013 png_fixed_point blue_y)
1011 { 1014 {
1012 #ifdef PNG_USE_LOCAL_ARRAYS 1015 #ifdef PNG_USE_LOCAL_ARRAYS
1013 PNG_cHRM; 1016 PNG_cHRM;
1014 #endif 1017 #endif
1015 png_byte buf[32]; 1018 png_byte buf[32];
1016 1019
1017 png_debug(1, "in png_write_cHRM"); 1020 png_debug(1, "in png_write_cHRM");
1018 /* each value is saved in 1/100,000ths */ 1021 /* Each value is saved in 1/100,000ths */
1019 #if !defined(PNG_NO_CHECK_cHRM) 1022 #if !defined(PNG_NO_CHECK_cHRM)
1020 if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y, 1023 if (png_check_cHRM_fixed(png_ptr, white_x, white_y, red_x, red_y,
1021 green_x, green_y, blue_x, blue_y)) 1024 green_x, green_y, blue_x, blue_y))
1022 #endif 1025 #endif
1023 { 1026 {
1024 png_save_uint_32(buf, (png_uint_32)white_x); 1027 png_save_uint_32(buf, (png_uint_32)white_x);
1025 png_save_uint_32(buf + 4, (png_uint_32)white_y); 1028 png_save_uint_32(buf + 4, (png_uint_32)white_y);
1026 1029
1027 png_save_uint_32(buf + 8, (png_uint_32)red_x); 1030 png_save_uint_32(buf + 8, (png_uint_32)red_x);
1028 png_save_uint_32(buf + 12, (png_uint_32)red_y); 1031 png_save_uint_32(buf + 12, (png_uint_32)red_y);
1029 1032
1030 png_save_uint_32(buf + 16, (png_uint_32)green_x); 1033 png_save_uint_32(buf + 16, (png_uint_32)green_x);
1031 png_save_uint_32(buf + 20, (png_uint_32)green_y); 1034 png_save_uint_32(buf + 20, (png_uint_32)green_y);
1032 1035
1033 png_save_uint_32(buf + 24, (png_uint_32)blue_x); 1036 png_save_uint_32(buf + 24, (png_uint_32)blue_x);
1034 png_save_uint_32(buf + 28, (png_uint_32)blue_y); 1037 png_save_uint_32(buf + 28, (png_uint_32)blue_y);
1035 1038
1036 png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32); 1039 png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32);
1037 } 1040 }
1038 } 1041 }
1039 #endif 1042 #endif
1040 #endif 1043 #endif
1041 1044
1042 #if defined(PNG_WRITE_tRNS_SUPPORTED) 1045 #if defined(PNG_WRITE_tRNS_SUPPORTED)
1043 /* write the tRNS chunk */ 1046 /* Write the tRNS chunk */
1044 void /* PRIVATE */ 1047 void /* PRIVATE */
1045 png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran, 1048 png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
1046 int num_trans, int color_type) 1049 int num_trans, int color_type)
1047 { 1050 {
1048 #ifdef PNG_USE_LOCAL_ARRAYS 1051 #ifdef PNG_USE_LOCAL_ARRAYS
1049 PNG_tRNS; 1052 PNG_tRNS;
1050 #endif 1053 #endif
1051 png_byte buf[6]; 1054 png_byte buf[6];
1052 1055
1053 png_debug(1, "in png_write_tRNS"); 1056 png_debug(1, "in png_write_tRNS");
1054 if (color_type == PNG_COLOR_TYPE_PALETTE) 1057 if (color_type == PNG_COLOR_TYPE_PALETTE)
1055 { 1058 {
1056 if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette) 1059 if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
1057 { 1060 {
1058 png_warning(png_ptr, "Invalid number of transparent colors specified"); 1061 png_warning(png_ptr, "Invalid number of transparent colors specified");
1059 return; 1062 return;
1060 } 1063 }
1061 /* write the chunk out as it is */ 1064 /* Write the chunk out as it is */
1062 png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans, 1065 png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans,
1063 (png_size_t)num_trans); 1066 (png_size_t)num_trans);
1064 } 1067 }
1065 else if (color_type == PNG_COLOR_TYPE_GRAY) 1068 else if (color_type == PNG_COLOR_TYPE_GRAY)
1066 { 1069 {
1067 /* one 16 bit value */ 1070 /* One 16 bit value */
1068 if (tran->gray >= (1 << png_ptr->bit_depth)) 1071 if (tran->gray >= (1 << png_ptr->bit_depth))
1069 { 1072 {
1070 png_warning(png_ptr, 1073 png_warning(png_ptr,
1071 "Ignoring attempt to write tRNS chunk out-of-range for bit_depth"); 1074 "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
1072 return; 1075 return;
1073 } 1076 }
1074 png_save_uint_16(buf, tran->gray); 1077 png_save_uint_16(buf, tran->gray);
1075 png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)2); 1078 png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)2);
1076 } 1079 }
1077 else if (color_type == PNG_COLOR_TYPE_RGB) 1080 else if (color_type == PNG_COLOR_TYPE_RGB)
1078 { 1081 {
1079 /* three 16 bit values */ 1082 /* Three 16 bit values */
1080 png_save_uint_16(buf, tran->red); 1083 png_save_uint_16(buf, tran->red);
1081 png_save_uint_16(buf + 2, tran->green); 1084 png_save_uint_16(buf + 2, tran->green);
1082 png_save_uint_16(buf + 4, tran->blue); 1085 png_save_uint_16(buf + 4, tran->blue);
1083 if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) 1086 if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
1084 { 1087 {
1085 png_warning(png_ptr, 1088 png_warning(png_ptr,
1086 "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8"); 1089 "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
1087 return; 1090 return;
1088 } 1091 }
1089 png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)6); 1092 png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)6);
1090 } 1093 }
1091 else 1094 else
1092 { 1095 {
1093 png_warning(png_ptr, "Can't write tRNS with an alpha channel"); 1096 png_warning(png_ptr, "Can't write tRNS with an alpha channel");
1094 } 1097 }
1095 } 1098 }
1096 #endif 1099 #endif
1097 1100
1098 #if defined(PNG_WRITE_bKGD_SUPPORTED) 1101 #if defined(PNG_WRITE_bKGD_SUPPORTED)
1099 /* write the background chunk */ 1102 /* Write the background chunk */
1100 void /* PRIVATE */ 1103 void /* PRIVATE */
1101 png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type) 1104 png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
1102 { 1105 {
1103 #ifdef PNG_USE_LOCAL_ARRAYS 1106 #ifdef PNG_USE_LOCAL_ARRAYS
1104 PNG_bKGD; 1107 PNG_bKGD;
1105 #endif 1108 #endif
1106 png_byte buf[6]; 1109 png_byte buf[6];
1107 1110
1108 png_debug(1, "in png_write_bKGD"); 1111 png_debug(1, "in png_write_bKGD");
1109 if (color_type == PNG_COLOR_TYPE_PALETTE) 1112 if (color_type == PNG_COLOR_TYPE_PALETTE)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 "Ignoring attempt to write bKGD chunk out-of-range for bit_depth"); 1145 "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
1143 return; 1146 return;
1144 } 1147 }
1145 png_save_uint_16(buf, back->gray); 1148 png_save_uint_16(buf, back->gray);
1146 png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)2); 1149 png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)2);
1147 } 1150 }
1148 } 1151 }
1149 #endif 1152 #endif
1150 1153
1151 #if defined(PNG_WRITE_hIST_SUPPORTED) 1154 #if defined(PNG_WRITE_hIST_SUPPORTED)
1152 /* write the histogram */ 1155 /* Write the histogram */
1153 void /* PRIVATE */ 1156 void /* PRIVATE */
1154 png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist) 1157 png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
1155 { 1158 {
1156 #ifdef PNG_USE_LOCAL_ARRAYS 1159 #ifdef PNG_USE_LOCAL_ARRAYS
1157 PNG_hIST; 1160 PNG_hIST;
1158 #endif 1161 #endif
1159 int i; 1162 int i;
1160 png_byte buf[3]; 1163 png_byte buf[3];
1161 1164
1162 png_debug(1, "in png_write_hIST"); 1165 png_debug(1, "in png_write_hIST");
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 *dp = '\0'; 1245 *dp = '\0';
1243 1246
1244 /* Remove any trailing white space. */ 1247 /* Remove any trailing white space. */
1245 kp = *new_key + key_len - 1; 1248 kp = *new_key + key_len - 1;
1246 if (*kp == ' ') 1249 if (*kp == ' ')
1247 { 1250 {
1248 png_warning(png_ptr, "trailing spaces removed from keyword"); 1251 png_warning(png_ptr, "trailing spaces removed from keyword");
1249 1252
1250 while (*kp == ' ') 1253 while (*kp == ' ')
1251 { 1254 {
1252 *(kp--) = '\0'; 1255 *(kp--) = '\0';
1253 key_len--; 1256 key_len--;
1254 } 1257 }
1255 } 1258 }
1256 1259
1257 /* Remove any leading white space. */ 1260 /* Remove any leading white space. */
1258 kp = *new_key; 1261 kp = *new_key;
1259 if (*kp == ' ') 1262 if (*kp == ' ')
1260 { 1263 {
1261 png_warning(png_ptr, "leading spaces removed from keyword"); 1264 png_warning(png_ptr, "leading spaces removed from keyword");
1262 1265
1263 while (*kp == ' ') 1266 while (*kp == ' ')
1264 { 1267 {
1265 kp++; 1268 kp++;
1266 key_len--; 1269 key_len--;
1267 } 1270 }
1268 } 1271 }
1269 1272
1270 png_debug1(2, "Checking for multiple internal spaces in '%s'", kp); 1273 png_debug1(2, "Checking for multiple internal spaces in '%s'", kp);
1271 1274
1272 /* Remove multiple internal spaces. */ 1275 /* Remove multiple internal spaces. */
1273 for (kflag = 0, dp = *new_key; *kp != '\0'; kp++) 1276 for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
1274 { 1277 {
1275 if (*kp == ' ' && kflag == 0) 1278 if (*kp == ' ' && kflag == 0)
1276 { 1279 {
(...skipping 27 matching lines...) Expand all
1304 png_warning(png_ptr, "keyword length must be 1 - 79 characters"); 1307 png_warning(png_ptr, "keyword length must be 1 - 79 characters");
1305 (*new_key)[79] = '\0'; 1308 (*new_key)[79] = '\0';
1306 key_len = 79; 1309 key_len = 79;
1307 } 1310 }
1308 1311
1309 return (key_len); 1312 return (key_len);
1310 } 1313 }
1311 #endif 1314 #endif
1312 1315
1313 #if defined(PNG_WRITE_tEXt_SUPPORTED) 1316 #if defined(PNG_WRITE_tEXt_SUPPORTED)
1314 /* write a tEXt chunk */ 1317 /* Write a tEXt chunk */
1315 void /* PRIVATE */ 1318 void /* PRIVATE */
1316 png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text, 1319 png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
1317 png_size_t text_len) 1320 png_size_t text_len)
1318 { 1321 {
1319 #ifdef PNG_USE_LOCAL_ARRAYS 1322 #ifdef PNG_USE_LOCAL_ARRAYS
1320 PNG_tEXt; 1323 PNG_tEXt;
1321 #endif 1324 #endif
1322 png_size_t key_len; 1325 png_size_t key_len;
1323 png_charp new_key; 1326 png_charp new_key;
1324 1327
1325 png_debug(1, "in png_write_tEXt"); 1328 png_debug(1, "in png_write_tEXt");
1326 if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0) 1329 if ((key_len = png_check_keyword(png_ptr, key, &new_key))==0)
1327 return; 1330 return;
1328 1331
1329 if (text == NULL || *text == '\0') 1332 if (text == NULL || *text == '\0')
1330 text_len = 0; 1333 text_len = 0;
1331 else 1334 else
1332 text_len = png_strlen(text); 1335 text_len = png_strlen(text);
1333 1336
1334 /* make sure we include the 0 after the key */ 1337 /* Make sure we include the 0 after the key */
1335 png_write_chunk_start(png_ptr, (png_bytep)png_tEXt, 1338 png_write_chunk_start(png_ptr, (png_bytep)png_tEXt,
1336 (png_uint_32)(key_len + text_len + 1)); 1339 (png_uint_32)(key_len + text_len + 1));
1337 /* 1340 /*
1338 * We leave it to the application to meet PNG-1.0 requirements on the 1341 * We leave it to the application to meet PNG-1.0 requirements on the
1339 * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of 1342 * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of
1340 * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them. 1343 * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them.
1341 * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. 1344 * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG.
1342 */ 1345 */
1343 png_write_chunk_data(png_ptr, (png_bytep)new_key, 1346 png_write_chunk_data(png_ptr, (png_bytep)new_key,
1344 (png_size_t)(key_len + 1)); 1347 (png_size_t)(key_len + 1));
1345 if (text_len) 1348 if (text_len)
1346 png_write_chunk_data(png_ptr, (png_bytep)text, (png_size_t)text_len); 1349 png_write_chunk_data(png_ptr, (png_bytep)text, (png_size_t)text_len);
1347 1350
1348 png_write_chunk_end(png_ptr); 1351 png_write_chunk_end(png_ptr);
1349 png_free(png_ptr, new_key); 1352 png_free(png_ptr, new_key);
1350 } 1353 }
1351 #endif 1354 #endif
1352 1355
1353 #if defined(PNG_WRITE_zTXt_SUPPORTED) 1356 #if defined(PNG_WRITE_zTXt_SUPPORTED)
1354 /* write a compressed text chunk */ 1357 /* Write a compressed text chunk */
1355 void /* PRIVATE */ 1358 void /* PRIVATE */
1356 png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text, 1359 png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
1357 png_size_t text_len, int compression) 1360 png_size_t text_len, int compression)
1358 { 1361 {
1359 #ifdef PNG_USE_LOCAL_ARRAYS 1362 #ifdef PNG_USE_LOCAL_ARRAYS
1360 PNG_zTXt; 1363 PNG_zTXt;
1361 #endif 1364 #endif
1362 png_size_t key_len; 1365 png_size_t key_len;
1363 char buf[1]; 1366 char buf[1];
1364 png_charp new_key; 1367 png_charp new_key;
(...skipping 15 matching lines...) Expand all
1380 1383
1381 if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE) 1384 if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
1382 { 1385 {
1383 png_write_tEXt(png_ptr, new_key, text, (png_size_t)0); 1386 png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
1384 png_free(png_ptr, new_key); 1387 png_free(png_ptr, new_key);
1385 return; 1388 return;
1386 } 1389 }
1387 1390
1388 text_len = png_strlen(text); 1391 text_len = png_strlen(text);
1389 1392
1390 /* compute the compressed data; do it now for the length */ 1393 /* Compute the compressed data; do it now for the length */
1391 text_len = png_text_compress(png_ptr, text, text_len, compression, 1394 text_len = png_text_compress(png_ptr, text, text_len, compression,
1392 &comp); 1395 &comp);
1393 1396
1394 /* write start of chunk */ 1397 /* Write start of chunk */
1395 png_write_chunk_start(png_ptr, (png_bytep)png_zTXt, 1398 png_write_chunk_start(png_ptr, (png_bytep)png_zTXt,
1396 (png_uint_32)(key_len+text_len + 2)); 1399 (png_uint_32)(key_len+text_len + 2));
1397 /* write key */ 1400 /* Write key */
1398 png_write_chunk_data(png_ptr, (png_bytep)new_key, 1401 png_write_chunk_data(png_ptr, (png_bytep)new_key,
1399 (png_size_t)(key_len + 1)); 1402 (png_size_t)(key_len + 1));
1400 png_free(png_ptr, new_key); 1403 png_free(png_ptr, new_key);
1401 1404
1402 buf[0] = (png_byte)compression; 1405 buf[0] = (png_byte)compression;
1403 /* write compression */ 1406 /* Write compression */
1404 png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1); 1407 png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
1405 /* write the compressed data */ 1408 /* Write the compressed data */
1406 png_write_compressed_data_out(png_ptr, &comp); 1409 png_write_compressed_data_out(png_ptr, &comp);
1407 1410
1408 /* close the chunk */ 1411 /* Close the chunk */
1409 png_write_chunk_end(png_ptr); 1412 png_write_chunk_end(png_ptr);
1410 } 1413 }
1411 #endif 1414 #endif
1412 1415
1413 #if defined(PNG_WRITE_iTXt_SUPPORTED) 1416 #if defined(PNG_WRITE_iTXt_SUPPORTED)
1414 /* write an iTXt chunk */ 1417 /* Write an iTXt chunk */
1415 void /* PRIVATE */ 1418 void /* PRIVATE */
1416 png_write_iTXt(png_structp png_ptr, int compression, png_charp key, 1419 png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
1417 png_charp lang, png_charp lang_key, png_charp text) 1420 png_charp lang, png_charp lang_key, png_charp text)
1418 { 1421 {
1419 #ifdef PNG_USE_LOCAL_ARRAYS 1422 #ifdef PNG_USE_LOCAL_ARRAYS
1420 PNG_iTXt; 1423 PNG_iTXt;
1421 #endif 1424 #endif
1422 png_size_t lang_len, key_len, lang_key_len, text_len; 1425 png_size_t lang_len, key_len, lang_key_len, text_len;
1423 png_charp new_lang; 1426 png_charp new_lang;
1424 png_charp new_key = NULL; 1427 png_charp new_key = NULL;
(...skipping 11 matching lines...) Expand all
1436 return; 1439 return;
1437 1440
1438 if ((lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0) 1441 if ((lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
1439 { 1442 {
1440 png_warning(png_ptr, "Empty language field in iTXt chunk"); 1443 png_warning(png_ptr, "Empty language field in iTXt chunk");
1441 new_lang = NULL; 1444 new_lang = NULL;
1442 lang_len = 0; 1445 lang_len = 0;
1443 } 1446 }
1444 1447
1445 if (lang_key == NULL) 1448 if (lang_key == NULL)
1446 lang_key_len = 0; 1449 lang_key_len = 0;
1447 else 1450 else
1448 lang_key_len = png_strlen(lang_key); 1451 lang_key_len = png_strlen(lang_key);
1449 1452
1450 if (text == NULL) 1453 if (text == NULL)
1451 text_len = 0; 1454 text_len = 0;
1452 else 1455 else
1453 text_len = png_strlen(text); 1456 text_len = png_strlen(text);
1454 1457
1455 /* compute the compressed data; do it now for the length */ 1458 /* Compute the compressed data; do it now for the length */
1456 text_len = png_text_compress(png_ptr, text, text_len, compression-2, 1459 text_len = png_text_compress(png_ptr, text, text_len, compression-2,
1457 &comp); 1460 &comp);
1458 1461
1459 1462
1460 /* make sure we include the compression flag, the compression byte, 1463 /* Make sure we include the compression flag, the compression byte,
1461 * and the NULs after the key, lang, and lang_key parts */ 1464 * and the NULs after the key, lang, and lang_key parts */
1462 1465
1463 png_write_chunk_start(png_ptr, (png_bytep)png_iTXt, 1466 png_write_chunk_start(png_ptr, (png_bytep)png_iTXt,
1464 (png_uint_32)( 1467 (png_uint_32)(
1465 5 /* comp byte, comp flag, terminators for key, lang and lang_key */ 1468 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
1466 + key_len 1469 + key_len
1467 + lang_len 1470 + lang_len
1468 + lang_key_len 1471 + lang_key_len
1469 + text_len)); 1472 + text_len));
1470 1473
1471 /* 1474 /* We leave it to the application to meet PNG-1.0 requirements on the
1472 * We leave it to the application to meet PNG-1.0 requirements on the
1473 * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of 1475 * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of
1474 * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them. 1476 * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them.
1475 * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. 1477 * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG.
1476 */ 1478 */
1477 png_write_chunk_data(png_ptr, (png_bytep)new_key, 1479 png_write_chunk_data(png_ptr, (png_bytep)new_key,
1478 (png_size_t)(key_len + 1)); 1480 (png_size_t)(key_len + 1));
1479 1481
1480 /* set the compression flag */ 1482 /* Set the compression flag */
1481 if (compression == PNG_ITXT_COMPRESSION_NONE || \ 1483 if (compression == PNG_ITXT_COMPRESSION_NONE || \
1482 compression == PNG_TEXT_COMPRESSION_NONE) 1484 compression == PNG_TEXT_COMPRESSION_NONE)
1483 cbuf[0] = 0; 1485 cbuf[0] = 0;
1484 else /* compression == PNG_ITXT_COMPRESSION_zTXt */ 1486 else /* compression == PNG_ITXT_COMPRESSION_zTXt */
1485 cbuf[0] = 1; 1487 cbuf[0] = 1;
1486 /* set the compression method */ 1488 /* Set the compression method */
1487 cbuf[1] = 0; 1489 cbuf[1] = 0;
1488 png_write_chunk_data(png_ptr, cbuf, (png_size_t)2); 1490 png_write_chunk_data(png_ptr, cbuf, (png_size_t)2);
1489 1491
1490 cbuf[0] = 0; 1492 cbuf[0] = 0;
1491 png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), 1493 png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf),
1492 (png_size_t)(lang_len + 1)); 1494 (png_size_t)(lang_len + 1));
1493 png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), 1495 png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf),
1494 (png_size_t)(lang_key_len + 1)); 1496 (png_size_t)(lang_key_len + 1));
1495 png_write_compressed_data_out(png_ptr, &comp); 1497 png_write_compressed_data_out(png_ptr, &comp);
1496 1498
1497 png_write_chunk_end(png_ptr); 1499 png_write_chunk_end(png_ptr);
1498 png_free(png_ptr, new_key); 1500 png_free(png_ptr, new_key);
1499 png_free(png_ptr, new_lang); 1501 png_free(png_ptr, new_lang);
1500 } 1502 }
1501 #endif 1503 #endif
1502 1504
1503 #if defined(PNG_WRITE_oFFs_SUPPORTED) 1505 #if defined(PNG_WRITE_oFFs_SUPPORTED)
1504 /* write the oFFs chunk */ 1506 /* Write the oFFs chunk */
1505 void /* PRIVATE */ 1507 void /* PRIVATE */
1506 png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset, 1508 png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
1507 int unit_type) 1509 int unit_type)
1508 { 1510 {
1509 #ifdef PNG_USE_LOCAL_ARRAYS 1511 #ifdef PNG_USE_LOCAL_ARRAYS
1510 PNG_oFFs; 1512 PNG_oFFs;
1511 #endif 1513 #endif
1512 png_byte buf[9]; 1514 png_byte buf[9];
1513 1515
1514 png_debug(1, "in png_write_oFFs"); 1516 png_debug(1, "in png_write_oFFs");
1515 if (unit_type >= PNG_OFFSET_LAST) 1517 if (unit_type >= PNG_OFFSET_LAST)
1516 png_warning(png_ptr, "Unrecognized unit type for oFFs chunk"); 1518 png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
1517 1519
1518 png_save_int_32(buf, x_offset); 1520 png_save_int_32(buf, x_offset);
1519 png_save_int_32(buf + 4, y_offset); 1521 png_save_int_32(buf + 4, y_offset);
1520 buf[8] = (png_byte)unit_type; 1522 buf[8] = (png_byte)unit_type;
1521 1523
1522 png_write_chunk(png_ptr, (png_bytep)png_oFFs, buf, (png_size_t)9); 1524 png_write_chunk(png_ptr, (png_bytep)png_oFFs, buf, (png_size_t)9);
1523 } 1525 }
1524 #endif 1526 #endif
1525 #if defined(PNG_WRITE_pCAL_SUPPORTED) 1527 #if defined(PNG_WRITE_pCAL_SUPPORTED)
1526 /* write the pCAL chunk (described in the PNG extensions document) */ 1528 /* Write the pCAL chunk (described in the PNG extensions document) */
1527 void /* PRIVATE */ 1529 void /* PRIVATE */
1528 png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, 1530 png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
1529 png_int_32 X1, int type, int nparams, png_charp units, png_charpp params) 1531 png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
1530 { 1532 {
1531 #ifdef PNG_USE_LOCAL_ARRAYS 1533 #ifdef PNG_USE_LOCAL_ARRAYS
1532 PNG_pCAL; 1534 PNG_pCAL;
1533 #endif 1535 #endif
1534 png_size_t purpose_len, units_len, total_len; 1536 png_size_t purpose_len, units_len, total_len;
1535 png_uint_32p params_len; 1537 png_uint_32p params_len;
1536 png_byte buf[10]; 1538 png_byte buf[10];
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1578 png_write_chunk_data(png_ptr, (png_bytep)params[i], 1580 png_write_chunk_data(png_ptr, (png_bytep)params[i],
1579 (png_size_t)params_len[i]); 1581 (png_size_t)params_len[i]);
1580 } 1582 }
1581 1583
1582 png_free(png_ptr, params_len); 1584 png_free(png_ptr, params_len);
1583 png_write_chunk_end(png_ptr); 1585 png_write_chunk_end(png_ptr);
1584 } 1586 }
1585 #endif 1587 #endif
1586 1588
1587 #if defined(PNG_WRITE_sCAL_SUPPORTED) 1589 #if defined(PNG_WRITE_sCAL_SUPPORTED)
1588 /* write the sCAL chunk */ 1590 /* Write the sCAL chunk */
1589 #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO) 1591 #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
1590 void /* PRIVATE */ 1592 void /* PRIVATE */
1591 png_write_sCAL(png_structp png_ptr, int unit, double width, double height) 1593 png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
1592 { 1594 {
1593 #ifdef PNG_USE_LOCAL_ARRAYS 1595 #ifdef PNG_USE_LOCAL_ARRAYS
1594 PNG_sCAL; 1596 PNG_sCAL;
1595 #endif 1597 #endif
1596 char buf[64]; 1598 char buf[64];
1597 png_size_t total_len; 1599 png_size_t total_len;
1598 1600
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 wlen = png_strlen(width); 1643 wlen = png_strlen(width);
1642 hlen = png_strlen(height); 1644 hlen = png_strlen(height);
1643 total_len = wlen + hlen + 2; 1645 total_len = wlen + hlen + 2;
1644 if (total_len > 64) 1646 if (total_len > 64)
1645 { 1647 {
1646 png_warning(png_ptr, "Can't write sCAL (buffer too small)"); 1648 png_warning(png_ptr, "Can't write sCAL (buffer too small)");
1647 return; 1649 return;
1648 } 1650 }
1649 1651
1650 buf[0] = (png_byte)unit; 1652 buf[0] = (png_byte)unit;
1651 png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */ 1653 png_memcpy(buf + 1, width, wlen + 1); /* Append the '\0' here */
1652 png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */ 1654 png_memcpy(buf + wlen + 2, height, hlen); /* Do NOT append the '\0' here */
1653 1655
1654 png_debug1(3, "sCAL total length = %u", (unsigned int)total_len); 1656 png_debug1(3, "sCAL total length = %u", (unsigned int)total_len);
1655 png_write_chunk(png_ptr, (png_bytep)png_sCAL, buf, total_len); 1657 png_write_chunk(png_ptr, (png_bytep)png_sCAL, buf, total_len);
1656 } 1658 }
1657 #endif 1659 #endif
1658 #endif 1660 #endif
1659 #endif 1661 #endif
1660 1662
1661 #if defined(PNG_WRITE_pHYs_SUPPORTED) 1663 #if defined(PNG_WRITE_pHYs_SUPPORTED)
1662 /* write the pHYs chunk */ 1664 /* Write the pHYs chunk */
1663 void /* PRIVATE */ 1665 void /* PRIVATE */
1664 png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit, 1666 png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
1665 png_uint_32 y_pixels_per_unit, 1667 png_uint_32 y_pixels_per_unit,
1666 int unit_type) 1668 int unit_type)
1667 { 1669 {
1668 #ifdef PNG_USE_LOCAL_ARRAYS 1670 #ifdef PNG_USE_LOCAL_ARRAYS
1669 PNG_pHYs; 1671 PNG_pHYs;
1670 #endif 1672 #endif
1671 png_byte buf[9]; 1673 png_byte buf[9];
1672 1674
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1707 buf[2] = mod_time->month; 1709 buf[2] = mod_time->month;
1708 buf[3] = mod_time->day; 1710 buf[3] = mod_time->day;
1709 buf[4] = mod_time->hour; 1711 buf[4] = mod_time->hour;
1710 buf[5] = mod_time->minute; 1712 buf[5] = mod_time->minute;
1711 buf[6] = mod_time->second; 1713 buf[6] = mod_time->second;
1712 1714
1713 png_write_chunk(png_ptr, (png_bytep)png_tIME, buf, (png_size_t)7); 1715 png_write_chunk(png_ptr, (png_bytep)png_tIME, buf, (png_size_t)7);
1714 } 1716 }
1715 #endif 1717 #endif
1716 1718
1717 /* initializes the row writing capability of libpng */ 1719 /* Initializes the row writing capability of libpng */
1718 void /* PRIVATE */ 1720 void /* PRIVATE */
1719 png_write_start_row(png_structp png_ptr) 1721 png_write_start_row(png_structp png_ptr)
1720 { 1722 {
1721 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1723 #ifdef PNG_WRITE_INTERLACING_SUPPORTED
1722 #ifdef PNG_USE_LOCAL_ARRAYS 1724 #ifdef PNG_USE_LOCAL_ARRAYS
1723 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 1725 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
1724 1726
1725 /* start of interlace block */ 1727 /* Start of interlace block */
1726 int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; 1728 int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
1727 1729
1728 /* offset to next interlace block */ 1730 /* Offset to next interlace block */
1729 int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 1731 int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
1730 1732
1731 /* start of interlace block in the y direction */ 1733 /* Start of interlace block in the y direction */
1732 int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; 1734 int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
1733 1735
1734 /* offset to next interlace block in the y direction */ 1736 /* Offset to next interlace block in the y direction */
1735 int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; 1737 int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
1736 #endif 1738 #endif
1737 #endif 1739 #endif
1738 1740
1739 png_size_t buf_size; 1741 png_size_t buf_size;
1740 1742
1741 png_debug(1, "in png_write_start_row"); 1743 png_debug(1, "in png_write_start_row");
1742 buf_size = (png_size_t)(PNG_ROWBYTES( 1744 buf_size = (png_size_t)(PNG_ROWBYTES(
1743 png_ptr->usr_channels*png_ptr->usr_bit_depth, png_ptr->width) + 1); 1745 png_ptr->usr_channels*png_ptr->usr_bit_depth, png_ptr->width) + 1);
1744 1746
1745 /* set up row buffer */ 1747 /* Set up row buffer */
1746 png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, 1748 png_ptr->row_buf = (png_bytep)png_malloc(png_ptr,
1747 (png_uint_32)buf_size); 1749 (png_uint_32)buf_size);
1748 png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE; 1750 png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
1749 1751
1750 #ifndef PNG_NO_WRITE_FILTER 1752 #ifndef PNG_NO_WRITE_FILTER
1751 /* set up filtering buffer, if using this filter */ 1753 /* Set up filtering buffer, if using this filter */
1752 if (png_ptr->do_filter & PNG_FILTER_SUB) 1754 if (png_ptr->do_filter & PNG_FILTER_SUB)
1753 { 1755 {
1754 png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, 1756 png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
1755 (png_uint_32)(png_ptr->rowbytes + 1)); 1757 (png_uint_32)(png_ptr->rowbytes + 1));
1756 png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; 1758 png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
1757 } 1759 }
1758 1760
1759 /* We only need to keep the previous row if we are using one of these. */ 1761 /* We only need to keep the previous row if we are using one of these. */
1760 if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) 1762 if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
1761 { 1763 {
1762 /* set up previous row buffer */ 1764 /* Set up previous row buffer */
1763 png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, 1765 png_ptr->prev_row = (png_bytep)png_malloc(png_ptr,
1764 (png_uint_32)buf_size); 1766 (png_uint_32)buf_size);
1765 png_memset(png_ptr->prev_row, 0, buf_size); 1767 png_memset(png_ptr->prev_row, 0, buf_size);
1766 1768
1767 if (png_ptr->do_filter & PNG_FILTER_UP) 1769 if (png_ptr->do_filter & PNG_FILTER_UP)
1768 { 1770 {
1769 png_ptr->up_row = (png_bytep)png_malloc(png_ptr, 1771 png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
1770 (png_uint_32)(png_ptr->rowbytes + 1)); 1772 (png_uint_32)(png_ptr->rowbytes + 1));
1771 png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; 1773 png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
1772 } 1774 }
1773 1775
1774 if (png_ptr->do_filter & PNG_FILTER_AVG) 1776 if (png_ptr->do_filter & PNG_FILTER_AVG)
1775 { 1777 {
1776 png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, 1778 png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
1777 (png_uint_32)(png_ptr->rowbytes + 1)); 1779 (png_uint_32)(png_ptr->rowbytes + 1));
1778 png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; 1780 png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
1779 } 1781 }
1780 1782
1781 if (png_ptr->do_filter & PNG_FILTER_PAETH) 1783 if (png_ptr->do_filter & PNG_FILTER_PAETH)
1782 { 1784 {
1783 png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, 1785 png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
1784 (png_uint_32)(png_ptr->rowbytes + 1)); 1786 (png_uint_32)(png_ptr->rowbytes + 1));
1785 png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; 1787 png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
1786 } 1788 }
1787 } 1789 }
1788 #endif /* PNG_NO_WRITE_FILTER */ 1790 #endif /* PNG_NO_WRITE_FILTER */
1789 1791
1790 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1792 #ifdef PNG_WRITE_INTERLACING_SUPPORTED
1791 /* if interlaced, we need to set up width and height of pass */ 1793 /* If interlaced, we need to set up width and height of pass */
1792 if (png_ptr->interlaced) 1794 if (png_ptr->interlaced)
1793 { 1795 {
1794 if (!(png_ptr->transformations & PNG_INTERLACE)) 1796 if (!(png_ptr->transformations & PNG_INTERLACE))
1795 { 1797 {
1796 png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - 1798 png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
1797 png_pass_ystart[0]) / png_pass_yinc[0]; 1799 png_pass_ystart[0]) / png_pass_yinc[0];
1798 png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 - 1800 png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
1799 png_pass_start[0]) / png_pass_inc[0]; 1801 png_pass_start[0]) / png_pass_inc[0];
1800 } 1802 }
1801 else 1803 else
(...skipping 11 matching lines...) Expand all
1813 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; 1815 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
1814 png_ptr->zstream.next_out = png_ptr->zbuf; 1816 png_ptr->zstream.next_out = png_ptr->zbuf;
1815 } 1817 }
1816 1818
1817 /* Internal use only. Called when finished processing a row of data. */ 1819 /* Internal use only. Called when finished processing a row of data. */
1818 void /* PRIVATE */ 1820 void /* PRIVATE */
1819 png_write_finish_row(png_structp png_ptr) 1821 png_write_finish_row(png_structp png_ptr)
1820 { 1822 {
1821 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1823 #ifdef PNG_WRITE_INTERLACING_SUPPORTED
1822 #ifdef PNG_USE_LOCAL_ARRAYS 1824 #ifdef PNG_USE_LOCAL_ARRAYS
1823 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 1825 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
1824 1826
1825 /* start of interlace block */ 1827 /* Start of interlace block */
1826 int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; 1828 int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
1827 1829
1828 /* offset to next interlace block */ 1830 /* Offset to next interlace block */
1829 int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 1831 int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
1830 1832
1831 /* start of interlace block in the y direction */ 1833 /* Start of interlace block in the y direction */
1832 int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; 1834 int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
1833 1835
1834 /* offset to next interlace block in the y direction */ 1836 /* Offset to next interlace block in the y direction */
1835 int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; 1837 int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
1836 #endif 1838 #endif
1837 #endif 1839 #endif
1838 1840
1839 int ret; 1841 int ret;
1840 1842
1841 png_debug(1, "in png_write_finish_row"); 1843 png_debug(1, "in png_write_finish_row");
1842 /* next row */ 1844 /* Next row */
1843 png_ptr->row_number++; 1845 png_ptr->row_number++;
1844 1846
1845 /* see if we are done */ 1847 /* See if we are done */
1846 if (png_ptr->row_number < png_ptr->num_rows) 1848 if (png_ptr->row_number < png_ptr->num_rows)
1847 return; 1849 return;
1848 1850
1849 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1851 #ifdef PNG_WRITE_INTERLACING_SUPPORTED
1850 /* if interlaced, go to next pass */ 1852 /* If interlaced, go to next pass */
1851 if (png_ptr->interlaced) 1853 if (png_ptr->interlaced)
1852 { 1854 {
1853 png_ptr->row_number = 0; 1855 png_ptr->row_number = 0;
1854 if (png_ptr->transformations & PNG_INTERLACE) 1856 if (png_ptr->transformations & PNG_INTERLACE)
1855 { 1857 {
1856 png_ptr->pass++; 1858 png_ptr->pass++;
1857 } 1859 }
1858 else 1860 else
1859 { 1861 {
1860 /* loop until we find a non-zero width or height pass */ 1862 /* Loop until we find a non-zero width or height pass */
1861 do 1863 do
1862 { 1864 {
1863 png_ptr->pass++; 1865 png_ptr->pass++;
1864 if (png_ptr->pass >= 7) 1866 if (png_ptr->pass >= 7)
1865 break; 1867 break;
1866 png_ptr->usr_width = (png_ptr->width + 1868 png_ptr->usr_width = (png_ptr->width +
1867 png_pass_inc[png_ptr->pass] - 1 - 1869 png_pass_inc[png_ptr->pass] - 1 -
1868 png_pass_start[png_ptr->pass]) / 1870 png_pass_start[png_ptr->pass]) /
1869 png_pass_inc[png_ptr->pass]; 1871 png_pass_inc[png_ptr->pass];
1870 png_ptr->num_rows = (png_ptr->height + 1872 png_ptr->num_rows = (png_ptr->height +
1871 png_pass_yinc[png_ptr->pass] - 1 - 1873 png_pass_yinc[png_ptr->pass] - 1 -
1872 png_pass_ystart[png_ptr->pass]) / 1874 png_pass_ystart[png_ptr->pass]) /
1873 png_pass_yinc[png_ptr->pass]; 1875 png_pass_yinc[png_ptr->pass];
1874 if (png_ptr->transformations & PNG_INTERLACE) 1876 if (png_ptr->transformations & PNG_INTERLACE)
1875 break; 1877 break;
1876 } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0); 1878 } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
1877 1879
1878 } 1880 }
1879 1881
1880 /* reset the row above the image for the next pass */ 1882 /* Reset the row above the image for the next pass */
1881 if (png_ptr->pass < 7) 1883 if (png_ptr->pass < 7)
1882 { 1884 {
1883 if (png_ptr->prev_row != NULL) 1885 if (png_ptr->prev_row != NULL)
1884 png_memset(png_ptr->prev_row, 0, 1886 png_memset(png_ptr->prev_row, 0,
1885 (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels* 1887 (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
1886 png_ptr->usr_bit_depth, png_ptr->width)) + 1); 1888 png_ptr->usr_bit_depth, png_ptr->width)) + 1);
1887 return; 1889 return;
1888 } 1890 }
1889 } 1891 }
1890 #endif 1892 #endif
1891 1893
1892 /* if we get here, we've just written the last row, so we need 1894 /* If we get here, we've just written the last row, so we need
1893 to flush the compressor */ 1895 to flush the compressor */
1894 do 1896 do
1895 { 1897 {
1896 /* tell the compressor we are done */ 1898 /* Tell the compressor we are done */
1897 ret = deflate(&png_ptr->zstream, Z_FINISH); 1899 ret = deflate(&png_ptr->zstream, Z_FINISH);
1898 /* check for an error */ 1900 /* Check for an error */
1899 if (ret == Z_OK) 1901 if (ret == Z_OK)
1900 { 1902 {
1901 /* check to see if we need more room */ 1903 /* Check to see if we need more room */
1902 if (!(png_ptr->zstream.avail_out)) 1904 if (!(png_ptr->zstream.avail_out))
1903 { 1905 {
1904 png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); 1906 png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
1905 png_ptr->zstream.next_out = png_ptr->zbuf; 1907 png_ptr->zstream.next_out = png_ptr->zbuf;
1906 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; 1908 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
1907 } 1909 }
1908 } 1910 }
1909 else if (ret != Z_STREAM_END) 1911 else if (ret != Z_STREAM_END)
1910 { 1912 {
1911 if (png_ptr->zstream.msg != NULL) 1913 if (png_ptr->zstream.msg != NULL)
1912 png_error(png_ptr, png_ptr->zstream.msg); 1914 png_error(png_ptr, png_ptr->zstream.msg);
1913 else 1915 else
1914 png_error(png_ptr, "zlib error"); 1916 png_error(png_ptr, "zlib error");
1915 } 1917 }
1916 } while (ret != Z_STREAM_END); 1918 } while (ret != Z_STREAM_END);
1917 1919
1918 /* write any extra space */ 1920 /* Write any extra space */
1919 if (png_ptr->zstream.avail_out < png_ptr->zbuf_size) 1921 if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
1920 { 1922 {
1921 png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size - 1923 png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
1922 png_ptr->zstream.avail_out); 1924 png_ptr->zstream.avail_out);
1923 } 1925 }
1924 1926
1925 deflateReset(&png_ptr->zstream); 1927 deflateReset(&png_ptr->zstream);
1926 png_ptr->zstream.data_type = Z_BINARY; 1928 png_ptr->zstream.data_type = Z_BINARY;
1927 } 1929 }
1928 1930
1929 #if defined(PNG_WRITE_INTERLACING_SUPPORTED) 1931 #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
1930 /* Pick out the correct pixels for the interlace pass. 1932 /* Pick out the correct pixels for the interlace pass.
1931 * The basic idea here is to go through the row with a source 1933 * The basic idea here is to go through the row with a source
1932 * pointer and a destination pointer (sp and dp), and copy the 1934 * pointer and a destination pointer (sp and dp), and copy the
1933 * correct pixels for the pass. As the row gets compacted, 1935 * correct pixels for the pass. As the row gets compacted,
1934 * sp will always be >= dp, so we should never overwrite anything. 1936 * sp will always be >= dp, so we should never overwrite anything.
1935 * See the default: case for the easiest code to understand. 1937 * See the default: case for the easiest code to understand.
1936 */ 1938 */
1937 void /* PRIVATE */ 1939 void /* PRIVATE */
1938 png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass) 1940 png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
1939 { 1941 {
1940 #ifdef PNG_USE_LOCAL_ARRAYS 1942 #ifdef PNG_USE_LOCAL_ARRAYS
1941 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 1943 /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */
1942 1944
1943 /* start of interlace block */ 1945 /* Start of interlace block */
1944 int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; 1946 int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
1945 1947
1946 /* offset to next interlace block */ 1948 /* Offset to next interlace block */
1947 int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 1949 int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
1948 #endif 1950 #endif
1949 1951
1950 png_debug(1, "in png_do_write_interlace"); 1952 png_debug(1, "in png_do_write_interlace");
1951 /* we don't have to do anything on the last pass (6) */ 1953 /* We don't have to do anything on the last pass (6) */
1952 #if defined(PNG_USELESS_TESTS_SUPPORTED) 1954 #if defined(PNG_USELESS_TESTS_SUPPORTED)
1953 if (row != NULL && row_info != NULL && pass < 6) 1955 if (row != NULL && row_info != NULL && pass < 6)
1954 #else 1956 #else
1955 if (pass < 6) 1957 if (pass < 6)
1956 #endif 1958 #endif
1957 { 1959 {
1958 /* each pixel depth is handled separately */ 1960 /* Each pixel depth is handled separately */
1959 switch (row_info->pixel_depth) 1961 switch (row_info->pixel_depth)
1960 { 1962 {
1961 case 1: 1963 case 1:
1962 { 1964 {
1963 png_bytep sp; 1965 png_bytep sp;
1964 png_bytep dp; 1966 png_bytep dp;
1965 int shift; 1967 int shift;
1966 int d; 1968 int d;
1967 int value; 1969 int value;
1968 png_uint_32 i; 1970 png_uint_32 i;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
2059 break; 2061 break;
2060 } 2062 }
2061 default: 2063 default:
2062 { 2064 {
2063 png_bytep sp; 2065 png_bytep sp;
2064 png_bytep dp; 2066 png_bytep dp;
2065 png_uint_32 i; 2067 png_uint_32 i;
2066 png_uint_32 row_width = row_info->width; 2068 png_uint_32 row_width = row_info->width;
2067 png_size_t pixel_bytes; 2069 png_size_t pixel_bytes;
2068 2070
2069 /* start at the beginning */ 2071 /* Start at the beginning */
2070 dp = row; 2072 dp = row;
2071 /* find out how many bytes each pixel takes up */ 2073 /* Find out how many bytes each pixel takes up */
2072 pixel_bytes = (row_info->pixel_depth >> 3); 2074 pixel_bytes = (row_info->pixel_depth >> 3);
2073 /* loop through the row, only looking at the pixels that 2075 /* Loop through the row, only looking at the pixels that
2074 matter */ 2076 matter */
2075 for (i = png_pass_start[pass]; i < row_width; 2077 for (i = png_pass_start[pass]; i < row_width;
2076 i += png_pass_inc[pass]) 2078 i += png_pass_inc[pass])
2077 { 2079 {
2078 /* find out where the original pixel is */ 2080 /* Find out where the original pixel is */
2079 sp = row + (png_size_t)i * pixel_bytes; 2081 sp = row + (png_size_t)i * pixel_bytes;
2080 /* move the pixel */ 2082 /* Move the pixel */
2081 if (dp != sp) 2083 if (dp != sp)
2082 png_memcpy(dp, sp, pixel_bytes); 2084 png_memcpy(dp, sp, pixel_bytes);
2083 /* next pixel */ 2085 /* Next pixel */
2084 dp += pixel_bytes; 2086 dp += pixel_bytes;
2085 } 2087 }
2086 break; 2088 break;
2087 } 2089 }
2088 } 2090 }
2089 /* set new row width */ 2091 /* Set new row width */
2090 row_info->width = (row_info->width + 2092 row_info->width = (row_info->width +
2091 png_pass_inc[pass] - 1 - 2093 png_pass_inc[pass] - 1 -
2092 png_pass_start[pass]) / 2094 png_pass_start[pass]) /
2093 png_pass_inc[pass]; 2095 png_pass_inc[pass];
2094 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, 2096 row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
2095 row_info->width); 2097 row_info->width);
2096 } 2098 }
2097 } 2099 }
2098 #endif 2100 #endif
2099 2101
(...skipping 12 matching lines...) Expand all
2112 #ifndef PNG_NO_WRITE_FILTER 2114 #ifndef PNG_NO_WRITE_FILTER
2113 png_bytep prev_row, row_buf; 2115 png_bytep prev_row, row_buf;
2114 png_uint_32 mins, bpp; 2116 png_uint_32 mins, bpp;
2115 png_byte filter_to_do = png_ptr->do_filter; 2117 png_byte filter_to_do = png_ptr->do_filter;
2116 png_uint_32 row_bytes = row_info->rowbytes; 2118 png_uint_32 row_bytes = row_info->rowbytes;
2117 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 2119 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
2118 int num_p_filters = (int)png_ptr->num_prev_filters; 2120 int num_p_filters = (int)png_ptr->num_prev_filters;
2119 #endif 2121 #endif
2120 2122
2121 png_debug(1, "in png_write_find_filter"); 2123 png_debug(1, "in png_write_find_filter");
2122 /* find out how many bytes offset each pixel is */ 2124 /* Find out how many bytes offset each pixel is */
2123 bpp = (row_info->pixel_depth + 7) >> 3; 2125 bpp = (row_info->pixel_depth + 7) >> 3;
2124 2126
2125 prev_row = png_ptr->prev_row; 2127 prev_row = png_ptr->prev_row;
2126 #endif 2128 #endif
2127 best_row = png_ptr->row_buf; 2129 best_row = png_ptr->row_buf;
2128 #ifndef PNG_NO_WRITE_FILTER 2130 #ifndef PNG_NO_WRITE_FILTER
2129 row_buf = best_row; 2131 row_buf = best_row;
2130 mins = PNG_MAXSUM; 2132 mins = PNG_MAXSUM;
2131 2133
2132 /* The prediction method we use is to find which method provides the 2134 /* The prediction method we use is to find which method provides the
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
2199 2201
2200 if (sumhi > PNG_HIMASK) 2202 if (sumhi > PNG_HIMASK)
2201 sum = PNG_MAXSUM; 2203 sum = PNG_MAXSUM;
2202 else 2204 else
2203 sum = (sumhi << PNG_HISHIFT) + sumlo; 2205 sum = (sumhi << PNG_HISHIFT) + sumlo;
2204 } 2206 }
2205 #endif 2207 #endif
2206 mins = sum; 2208 mins = sum;
2207 } 2209 }
2208 2210
2209 /* sub filter */ 2211 /* Sub filter */
2210 if (filter_to_do == PNG_FILTER_SUB) 2212 if (filter_to_do == PNG_FILTER_SUB)
2211 /* it's the only filter so no testing is needed */ 2213 /* It's the only filter so no testing is needed */
2212 { 2214 {
2213 png_bytep rp, lp, dp; 2215 png_bytep rp, lp, dp;
2214 png_uint_32 i; 2216 png_uint_32 i;
2215 for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp; 2217 for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
2216 i++, rp++, dp++) 2218 i++, rp++, dp++)
2217 { 2219 {
2218 *dp = *rp; 2220 *dp = *rp;
2219 } 2221 }
2220 for (lp = row_buf + 1; i < row_bytes; 2222 for (lp = row_buf + 1; i < row_bytes;
2221 i++, rp++, lp++, dp++) 2223 i++, rp++, lp++, dp++)
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
2316 } 2318 }
2317 #endif 2319 #endif
2318 2320
2319 if (sum < mins) 2321 if (sum < mins)
2320 { 2322 {
2321 mins = sum; 2323 mins = sum;
2322 best_row = png_ptr->sub_row; 2324 best_row = png_ptr->sub_row;
2323 } 2325 }
2324 } 2326 }
2325 2327
2326 /* up filter */ 2328 /* Up filter */
2327 if (filter_to_do == PNG_FILTER_UP) 2329 if (filter_to_do == PNG_FILTER_UP)
2328 { 2330 {
2329 png_bytep rp, dp, pp; 2331 png_bytep rp, dp, pp;
2330 png_uint_32 i; 2332 png_uint_32 i;
2331 2333
2332 for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1, 2334 for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
2333 pp = prev_row + 1; i < row_bytes; 2335 pp = prev_row + 1; i < row_bytes;
2334 i++, rp++, pp++, dp++) 2336 i++, rp++, pp++, dp++)
2335 { 2337 {
2336 *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff); 2338 *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
2419 } 2421 }
2420 #endif 2422 #endif
2421 2423
2422 if (sum < mins) 2424 if (sum < mins)
2423 { 2425 {
2424 mins = sum; 2426 mins = sum;
2425 best_row = png_ptr->up_row; 2427 best_row = png_ptr->up_row;
2426 } 2428 }
2427 } 2429 }
2428 2430
2429 /* avg filter */ 2431 /* Avg filter */
2430 if (filter_to_do == PNG_FILTER_AVG) 2432 if (filter_to_do == PNG_FILTER_AVG)
2431 { 2433 {
2432 png_bytep rp, dp, pp, lp; 2434 png_bytep rp, dp, pp, lp;
2433 png_uint_32 i; 2435 png_uint_32 i;
2434 for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1, 2436 for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
2435 pp = prev_row + 1; i < bpp; i++) 2437 pp = prev_row + 1; i < bpp; i++)
2436 { 2438 {
2437 *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff); 2439 *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
2438 } 2440 }
2439 for (lp = row_buf + 1; i < row_bytes; i++) 2441 for (lp = row_buf + 1; i < row_bytes; i++)
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
2722 #endif /* PNG_NO_WRITE_FILTER */ 2724 #endif /* PNG_NO_WRITE_FILTER */
2723 } 2725 }
2724 2726
2725 2727
2726 /* Do the actual writing of a previously filtered row. */ 2728 /* Do the actual writing of a previously filtered row. */
2727 void /* PRIVATE */ 2729 void /* PRIVATE */
2728 png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row) 2730 png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
2729 { 2731 {
2730 png_debug(1, "in png_write_filtered_row"); 2732 png_debug(1, "in png_write_filtered_row");
2731 png_debug1(2, "filter = %d", filtered_row[0]); 2733 png_debug1(2, "filter = %d", filtered_row[0]);
2732 /* set up the zlib input buffer */ 2734 /* Set up the zlib input buffer */
2733 2735
2734 png_ptr->zstream.next_in = filtered_row; 2736 png_ptr->zstream.next_in = filtered_row;
2735 png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1; 2737 png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
2736 /* repeat until we have compressed all the data */ 2738 /* Repeat until we have compressed all the data */
2737 do 2739 do
2738 { 2740 {
2739 int ret; /* return of zlib */ 2741 int ret; /* Return of zlib */
2740 2742
2741 /* compress the data */ 2743 /* Compress the data */
2742 ret = deflate(&png_ptr->zstream, Z_NO_FLUSH); 2744 ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
2743 /* check for compression errors */ 2745 /* Check for compression errors */
2744 if (ret != Z_OK) 2746 if (ret != Z_OK)
2745 { 2747 {
2746 if (png_ptr->zstream.msg != NULL) 2748 if (png_ptr->zstream.msg != NULL)
2747 png_error(png_ptr, png_ptr->zstream.msg); 2749 png_error(png_ptr, png_ptr->zstream.msg);
2748 else 2750 else
2749 png_error(png_ptr, "zlib error"); 2751 png_error(png_ptr, "zlib error");
2750 } 2752 }
2751 2753
2752 /* see if it is time to write another IDAT */ 2754 /* See if it is time to write another IDAT */
2753 if (!(png_ptr->zstream.avail_out)) 2755 if (!(png_ptr->zstream.avail_out))
2754 { 2756 {
2755 /* write the IDAT and reset the zlib output buffer */ 2757 /* Write the IDAT and reset the zlib output buffer */
2756 png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size); 2758 png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
2757 png_ptr->zstream.next_out = png_ptr->zbuf; 2759 png_ptr->zstream.next_out = png_ptr->zbuf;
2758 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; 2760 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
2759 } 2761 }
2760 /* repeat until all data has been compressed */ 2762 /* Repeat until all data has been compressed */
2761 } while (png_ptr->zstream.avail_in); 2763 } while (png_ptr->zstream.avail_in);
2762 2764
2763 /* swap the current and previous rows */ 2765 /* Swap the current and previous rows */
2764 if (png_ptr->prev_row != NULL) 2766 if (png_ptr->prev_row != NULL)
2765 { 2767 {
2766 png_bytep tptr; 2768 png_bytep tptr;
2767 2769
2768 tptr = png_ptr->prev_row; 2770 tptr = png_ptr->prev_row;
2769 png_ptr->prev_row = png_ptr->row_buf; 2771 png_ptr->prev_row = png_ptr->row_buf;
2770 png_ptr->row_buf = tptr; 2772 png_ptr->row_buf = tptr;
2771 } 2773 }
2772 2774
2773 /* finish row - updates counters and flushes zlib if last row */ 2775 /* Finish row - updates counters and flushes zlib if last row */
2774 png_write_finish_row(png_ptr); 2776 png_write_finish_row(png_ptr);
2775 2777
2776 #if defined(PNG_WRITE_FLUSH_SUPPORTED) 2778 #if defined(PNG_WRITE_FLUSH_SUPPORTED)
2777 png_ptr->flush_rows++; 2779 png_ptr->flush_rows++;
2778 2780
2779 if (png_ptr->flush_dist > 0 && 2781 if (png_ptr->flush_dist > 0 &&
2780 png_ptr->flush_rows >= png_ptr->flush_dist) 2782 png_ptr->flush_rows >= png_ptr->flush_dist)
2781 { 2783 {
2782 png_write_flush(png_ptr); 2784 png_write_flush(png_ptr);
2783 } 2785 }
2784 #endif 2786 #endif
2785 } 2787 }
2786 #endif /* PNG_WRITE_SUPPORTED */ 2788 #endif /* PNG_WRITE_SUPPORTED */
OLDNEW
« no previous file with comments | « third_party/libpng/pngwtran.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698