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

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

Issue 15041: Update libpng to 1.2.33. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 12 years 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.27 [April 29, 2008] 4 * Last changed in libpng 1.2.30 [August 15, 2008]
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-2008 Glenn Randers-Pehrson 6 * Copyright (c) 1998-2008 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 27 matching lines...) Expand all
42 * The parameter is declared unsigned int, not png_uint_16, 42 * The parameter is declared unsigned int, not png_uint_16,
43 * just to avoid potential problems on pre-ANSI C compilers. 43 * just to avoid potential problems on pre-ANSI C compilers.
44 */ 44 */
45 void PNGAPI 45 void PNGAPI
46 png_save_uint_16(png_bytep buf, unsigned int i) 46 png_save_uint_16(png_bytep buf, unsigned int i)
47 { 47 {
48 buf[0] = (png_byte)((i >> 8) & 0xff); 48 buf[0] = (png_byte)((i >> 8) & 0xff);
49 buf[1] = (png_byte)(i & 0xff); 49 buf[1] = (png_byte)(i & 0xff);
50 } 50 }
51 51
52 /* Simple function to write the signature. If we have already written
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,
55 * we should call png_set_sig_bytes() to tell libpng how many of the
56 * bytes have already been written.
57 */
58 void /* PRIVATE */
59 png_write_sig(png_structp png_ptr)
60 {
61 png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
62
63 /* write the rest of the 8 byte signature */
64 png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
65 (png_size_t)(8 - png_ptr->sig_bytes));
66 if (png_ptr->sig_bytes < 3)
67 png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
68 }
69
52 /* 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
53 * 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
54 * 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
55 * 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
56 * 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.
57 * 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
58 * 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()
59 * functions instead. 77 * functions instead.
60 */ 78 */
61 void PNGAPI 79 void PNGAPI
62 png_write_chunk(png_structp png_ptr, png_bytep chunk_name, 80 png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
63 png_bytep data, png_size_t length) 81 png_bytep data, png_size_t length)
64 { 82 {
65 if(png_ptr == NULL) return; 83 if (png_ptr == NULL) return;
66 png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length); 84 png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
67 png_write_chunk_data(png_ptr, data, length); 85 png_write_chunk_data(png_ptr, data, (png_size_t)length);
68 png_write_chunk_end(png_ptr); 86 png_write_chunk_end(png_ptr);
69 } 87 }
70 88
71 /* Write the start of a PNG chunk. The type is the chunk type. 89 /* Write the start of a PNG chunk. The type is the chunk type.
72 * The total_length is the sum of the lengths of all the data you will be 90 * The total_length is the sum of the lengths of all the data you will be
73 * passing in png_write_chunk_data(). 91 * passing in png_write_chunk_data().
74 */ 92 */
75 void PNGAPI 93 void PNGAPI
76 png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name, 94 png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
77 png_uint_32 length) 95 png_uint_32 length)
78 { 96 {
79 png_byte buf[4]; 97 png_byte buf[8];
80 png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
81 if(png_ptr == NULL) return;
82 98
83 /* write the length */ 99 png_debug2(0, "Writing %s chunk, length = %lu\n", chunk_name,
100 (unsigned long)length);
101 if (png_ptr == NULL) return;
102
103 /* write the length and the chunk name */
84 png_save_uint_32(buf, length); 104 png_save_uint_32(buf, length);
85 png_write_data(png_ptr, buf, (png_size_t)4); 105 png_memcpy(buf + 4, chunk_name, 4);
86 106 png_write_data(png_ptr, buf, (png_size_t)8);
87 /* write the chunk name */ 107 /* put the chunk name into png_ptr->chunk_name */
88 png_write_data(png_ptr, chunk_name, (png_size_t)4); 108 png_memcpy(png_ptr->chunk_name, chunk_name, 4);
89 /* reset the crc and run it over the chunk name */ 109 /* reset the crc and run it over the chunk name */
90 png_reset_crc(png_ptr); 110 png_reset_crc(png_ptr);
91 png_calculate_crc(png_ptr, chunk_name, (png_size_t)4); 111 png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
92 } 112 }
93 113
94 /* Write the data of a PNG chunk started with png_write_chunk_start(). 114 /* Write the data of a PNG chunk started with png_write_chunk_start().
95 * Note that multiple calls to this function are allowed, and that the 115 * Note that multiple calls to this function are allowed, and that the
96 * sum of the lengths from these calls *must* add up to the total_length 116 * sum of the lengths from these calls *must* add up to the total_length
97 * given to png_write_chunk_start(). 117 * given to png_write_chunk_start().
98 */ 118 */
99 void PNGAPI 119 void PNGAPI
100 png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length) 120 png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
101 { 121 {
102 /* write the data, and run the CRC over it */ 122 /* write the data, and run the CRC over it */
103 if(png_ptr == NULL) return; 123 if (png_ptr == NULL) return;
104 if (data != NULL && length > 0) 124 if (data != NULL && length > 0)
105 { 125 {
126 png_write_data(png_ptr, data, length);
127 /* update the CRC after writing the data,
128 * in case that the user I/O routine alters it.
129 */
106 png_calculate_crc(png_ptr, data, length); 130 png_calculate_crc(png_ptr, data, length);
107 png_write_data(png_ptr, data, length);
108 } 131 }
109 } 132 }
110 133
111 /* Finish a chunk started with png_write_chunk_start(). */ 134 /* Finish a chunk started with png_write_chunk_start(). */
112 void PNGAPI 135 void PNGAPI
113 png_write_chunk_end(png_structp png_ptr) 136 png_write_chunk_end(png_structp png_ptr)
114 { 137 {
115 png_byte buf[4]; 138 png_byte buf[4];
116 139
117 if(png_ptr == NULL) return; 140 if (png_ptr == NULL) return;
118 141
119 /* write the crc */ 142 /* write the crc in a single operation */
120 png_save_uint_32(buf, png_ptr->crc); 143 png_save_uint_32(buf, png_ptr->crc);
121 144
122 png_write_data(png_ptr, buf, (png_size_t)4); 145 png_write_data(png_ptr, buf, (png_size_t)4);
123 } 146 }
124 147
125 /* Simple function to write the signature. If we have already written
126 * the magic bytes of the signature, or more likely, the PNG stream is
127 * being embedded into another stream and doesn't need its own signature,
128 * we should call png_set_sig_bytes() to tell libpng how many of the
129 * bytes have already been written.
130 */
131 void /* PRIVATE */
132 png_write_sig(png_structp png_ptr)
133 {
134 png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
135 /* write the rest of the 8 byte signature */
136 png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
137 (png_size_t)8 - png_ptr->sig_bytes);
138 if(png_ptr->sig_bytes < 3)
139 png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
140 }
141
142 #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED) 148 #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
143 /* 149 /*
144 * This pair of functions encapsulates the operation of (a) compressing a 150 * This pair of functions encapsulates the operation of (a) compressing a
145 * text string, and (b) issuing it later as a series of chunk data writes. 151 * text string, and (b) issuing it later as a series of chunk data writes.
146 * The compression_state structure is shared context for these functions 152 * The compression_state structure is shared context for these functions
147 * set up by the caller in order to make the whole mess thread-safe. 153 * set up by the caller in order to make the whole mess thread-safe.
148 */ 154 */
149 155
150 typedef struct 156 typedef struct
151 { 157 {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 int old_max; 238 int old_max;
233 239
234 old_max = comp->max_output_ptr; 240 old_max = comp->max_output_ptr;
235 comp->max_output_ptr = comp->num_output_ptr + 4; 241 comp->max_output_ptr = comp->num_output_ptr + 4;
236 if (comp->output_ptr != NULL) 242 if (comp->output_ptr != NULL)
237 { 243 {
238 png_charpp old_ptr; 244 png_charpp old_ptr;
239 245
240 old_ptr = comp->output_ptr; 246 old_ptr = comp->output_ptr;
241 comp->output_ptr = (png_charpp)png_malloc(png_ptr, 247 comp->output_ptr = (png_charpp)png_malloc(png_ptr,
242 (png_uint_32)(comp->max_output_ptr * 248 (png_uint_32)
243 png_sizeof (png_charpp))); 249 (comp->max_output_ptr * png_sizeof(png_charpp)));
244 png_memcpy(comp->output_ptr, old_ptr, old_max 250 png_memcpy(comp->output_ptr, old_ptr, old_max
245 * png_sizeof (png_charp)); 251 * png_sizeof(png_charp));
246 png_free(png_ptr, old_ptr); 252 png_free(png_ptr, old_ptr);
247 } 253 }
248 else 254 else
249 comp->output_ptr = (png_charpp)png_malloc(png_ptr, 255 comp->output_ptr = (png_charpp)png_malloc(png_ptr,
250 (png_uint_32)(comp->max_output_ptr * 256 (png_uint_32)
251 png_sizeof (png_charp))); 257 (comp->max_output_ptr * png_sizeof(png_charp)));
252 } 258 }
253 259
254 /* save the data */ 260 /* save the data */
255 comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr, 261 comp->output_ptr[comp->num_output_ptr] =
262 (png_charp)png_malloc(png_ptr,
256 (png_uint_32)png_ptr->zbuf_size); 263 (png_uint_32)png_ptr->zbuf_size);
257 png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, 264 png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
258 png_ptr->zbuf_size); 265 png_ptr->zbuf_size);
259 comp->num_output_ptr++; 266 comp->num_output_ptr++;
260 267
261 /* and reset the buffer */ 268 /* and reset the buffer */
262 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; 269 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
263 png_ptr->zstream.next_out = png_ptr->zbuf; 270 png_ptr->zstream.next_out = png_ptr->zbuf;
264 } 271 }
265 /* continue until we don't have any more to compress */ 272 /* continue until we don't have any more to compress */
(...skipping 18 matching lines...) Expand all
284 old_max = comp->max_output_ptr; 291 old_max = comp->max_output_ptr;
285 comp->max_output_ptr = comp->num_output_ptr + 4; 292 comp->max_output_ptr = comp->num_output_ptr + 4;
286 if (comp->output_ptr != NULL) 293 if (comp->output_ptr != NULL)
287 { 294 {
288 png_charpp old_ptr; 295 png_charpp old_ptr;
289 296
290 old_ptr = comp->output_ptr; 297 old_ptr = comp->output_ptr;
291 /* This could be optimized to realloc() */ 298 /* This could be optimized to realloc() */
292 comp->output_ptr = (png_charpp)png_malloc(png_ptr, 299 comp->output_ptr = (png_charpp)png_malloc(png_ptr,
293 (png_uint_32)(comp->max_output_ptr * 300 (png_uint_32)(comp->max_output_ptr *
294 png_sizeof (png_charpp))); 301 png_sizeof(png_charp)));
295 png_memcpy(comp->output_ptr, old_ptr, 302 png_memcpy(comp->output_ptr, old_ptr,
296 old_max * png_sizeof (png_charp)); 303 old_max * png_sizeof(png_charp));
297 png_free(png_ptr, old_ptr); 304 png_free(png_ptr, old_ptr);
298 } 305 }
299 else 306 else
300 comp->output_ptr = (png_charpp)png_malloc(png_ptr, 307 comp->output_ptr = (png_charpp)png_malloc(png_ptr,
301 (png_uint_32)(comp->max_output_ptr * 308 (png_uint_32)(comp->max_output_ptr *
302 png_sizeof (png_charp))); 309 png_sizeof(png_charp)));
303 } 310 }
304 311
305 /* save off the data */ 312 /* save off the data */
306 comp->output_ptr[comp->num_output_ptr] = 313 comp->output_ptr[comp->num_output_ptr] =
307 (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size); 314 (png_charp)png_malloc(png_ptr,
315 (png_uint_32)png_ptr->zbuf_size);
308 png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf, 316 png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
309 png_ptr->zbuf_size); 317 png_ptr->zbuf_size);
310 comp->num_output_ptr++; 318 comp->num_output_ptr++;
311 319
312 /* and reset the buffer pointers */ 320 /* and reset the buffer pointers */
313 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size; 321 png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
314 png_ptr->zstream.next_out = png_ptr->zbuf; 322 png_ptr->zstream.next_out = png_ptr->zbuf;
315 } 323 }
316 } 324 }
317 else if (ret != Z_STREAM_END) 325 else if (ret != Z_STREAM_END)
(...skipping 24 matching lines...) Expand all
342 if (comp->input) 350 if (comp->input)
343 { 351 {
344 png_write_chunk_data(png_ptr, (png_bytep)comp->input, 352 png_write_chunk_data(png_ptr, (png_bytep)comp->input,
345 (png_size_t)comp->input_len); 353 (png_size_t)comp->input_len);
346 return; 354 return;
347 } 355 }
348 356
349 /* write saved output buffers, if any */ 357 /* write saved output buffers, if any */
350 for (i = 0; i < comp->num_output_ptr; i++) 358 for (i = 0; i < comp->num_output_ptr; i++)
351 { 359 {
352 png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i], 360 png_write_chunk_data(png_ptr, (png_bytep)comp->output_ptr[i],
353 png_ptr->zbuf_size); 361 (png_size_t)png_ptr->zbuf_size);
354 png_free(png_ptr, comp->output_ptr[i]); 362 png_free(png_ptr, comp->output_ptr[i]);
355 comp->output_ptr[i]=NULL; 363 comp->output_ptr[i]=NULL;
356 } 364 }
357 if (comp->max_output_ptr != 0) 365 if (comp->max_output_ptr != 0)
358 png_free(png_ptr, comp->output_ptr); 366 png_free(png_ptr, comp->output_ptr);
359 comp->output_ptr=NULL; 367 comp->output_ptr=NULL;
360 /* write anything left in zbuf */ 368 /* write anything left in zbuf */
361 if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size) 369 if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
362 png_write_chunk_data(png_ptr, png_ptr->zbuf, 370 png_write_chunk_data(png_ptr, png_ptr->zbuf,
363 png_ptr->zbuf_size - png_ptr->zstream.avail_out); 371 (png_size_t)(png_ptr->zbuf_size - png_ptr->zstream.avail_out));
364 372
365 /* reset zlib for another zTXt/iTXt or image data */ 373 /* reset zlib for another zTXt/iTXt or image data */
366 deflateReset(&png_ptr->zstream); 374 deflateReset(&png_ptr->zstream);
367 png_ptr->zstream.data_type = Z_BINARY; 375 png_ptr->zstream.data_type = Z_BINARY;
368 } 376 }
369 #endif 377 #endif
370 378
371 /* Write the IHDR chunk, and update the png_struct with the necessary 379 /* Write the IHDR chunk, and update the png_struct with the necessary
372 * information. Note that the rest of this code depends upon this 380 * information. Note that the rest of this code depends upon this
373 * information being correct. 381 * information being correct.
(...skipping 15 matching lines...) Expand all
389 switch (color_type) 397 switch (color_type)
390 { 398 {
391 case PNG_COLOR_TYPE_GRAY: 399 case PNG_COLOR_TYPE_GRAY:
392 switch (bit_depth) 400 switch (bit_depth)
393 { 401 {
394 case 1: 402 case 1:
395 case 2: 403 case 2:
396 case 4: 404 case 4:
397 case 8: 405 case 8:
398 case 16: png_ptr->channels = 1; break; 406 case 16: png_ptr->channels = 1; break;
399 default: png_error(png_ptr,"Invalid bit depth for grayscale image"); 407 default: png_error(png_ptr, "Invalid bit depth for grayscale image") ;
400 } 408 }
401 break; 409 break;
402 case PNG_COLOR_TYPE_RGB: 410 case PNG_COLOR_TYPE_RGB:
403 if (bit_depth != 8 && bit_depth != 16) 411 if (bit_depth != 8 && bit_depth != 16)
404 png_error(png_ptr, "Invalid bit depth for RGB image"); 412 png_error(png_ptr, "Invalid bit depth for RGB image");
405 png_ptr->channels = 3; 413 png_ptr->channels = 3;
406 break; 414 break;
407 case PNG_COLOR_TYPE_PALETTE: 415 case PNG_COLOR_TYPE_PALETTE:
408 switch (bit_depth) 416 switch (bit_depth)
409 { 417 {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 /* pack the header information into the buffer */ 497 /* pack the header information into the buffer */
490 png_save_uint_32(buf, width); 498 png_save_uint_32(buf, width);
491 png_save_uint_32(buf + 4, height); 499 png_save_uint_32(buf + 4, height);
492 buf[8] = (png_byte)bit_depth; 500 buf[8] = (png_byte)bit_depth;
493 buf[9] = (png_byte)color_type; 501 buf[9] = (png_byte)color_type;
494 buf[10] = (png_byte)compression_type; 502 buf[10] = (png_byte)compression_type;
495 buf[11] = (png_byte)filter_type; 503 buf[11] = (png_byte)filter_type;
496 buf[12] = (png_byte)interlace_type; 504 buf[12] = (png_byte)interlace_type;
497 505
498 /* write the chunk */ 506 /* write the chunk */
499 png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13); 507 png_write_chunk(png_ptr, (png_bytep)png_IHDR, buf, (png_size_t)13);
500 508
501 /* initialize zlib with PNG info */ 509 /* initialize zlib with PNG info */
502 png_ptr->zstream.zalloc = png_zalloc; 510 png_ptr->zstream.zalloc = png_zalloc;
503 png_ptr->zstream.zfree = png_zfree; 511 png_ptr->zstream.zfree = png_zfree;
504 png_ptr->zstream.opaque = (voidpf)png_ptr; 512 png_ptr->zstream.opaque = (voidpf)png_ptr;
505 if (!(png_ptr->do_filter)) 513 if (!(png_ptr->do_filter))
506 { 514 {
507 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE || 515 if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
508 png_ptr->bit_depth < 8) 516 png_ptr->bit_depth < 8)
509 png_ptr->do_filter = PNG_FILTER_NONE; 517 png_ptr->do_filter = PNG_FILTER_NONE;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR)) 590 if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
583 { 591 {
584 png_warning(png_ptr, 592 png_warning(png_ptr,
585 "Ignoring request to write a PLTE chunk in grayscale PNG"); 593 "Ignoring request to write a PLTE chunk in grayscale PNG");
586 return; 594 return;
587 } 595 }
588 596
589 png_ptr->num_palette = (png_uint_16)num_pal; 597 png_ptr->num_palette = (png_uint_16)num_pal;
590 png_debug1(3, "num_palette = %d\n", png_ptr->num_palette); 598 png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
591 599
592 png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3); 600 png_write_chunk_start(png_ptr, (png_bytep)png_PLTE,
601 (png_uint_32)(num_pal * 3));
593 #ifndef PNG_NO_POINTER_INDEXING 602 #ifndef PNG_NO_POINTER_INDEXING
594 for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++) 603 for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
595 { 604 {
596 buf[0] = pal_ptr->red; 605 buf[0] = pal_ptr->red;
597 buf[1] = pal_ptr->green; 606 buf[1] = pal_ptr->green;
598 buf[2] = pal_ptr->blue; 607 buf[2] = pal_ptr->blue;
599 png_write_chunk_data(png_ptr, buf, (png_size_t)3); 608 png_write_chunk_data(png_ptr, buf, (png_size_t)3);
600 } 609 }
601 #else 610 #else
602 /* This is a little slower but some buggy compilers need to do this instead * / 611 /* This is a little slower but some buggy compilers need to do this instead * /
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 data[1] &= 0xe0; 663 data[1] &= 0xe0;
655 data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f); 664 data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
656 } 665 }
657 } 666 }
658 } 667 }
659 else 668 else
660 png_error(png_ptr, 669 png_error(png_ptr,
661 "Invalid zlib compression method or flags in IDAT"); 670 "Invalid zlib compression method or flags in IDAT");
662 } 671 }
663 672
664 png_write_chunk(png_ptr, png_IDAT, data, length); 673 png_write_chunk(png_ptr, (png_bytep)png_IDAT, data, length);
665 png_ptr->mode |= PNG_HAVE_IDAT; 674 png_ptr->mode |= PNG_HAVE_IDAT;
666 } 675 }
667 676
668 /* write an IEND chunk */ 677 /* write an IEND chunk */
669 void /* PRIVATE */ 678 void /* PRIVATE */
670 png_write_IEND(png_structp png_ptr) 679 png_write_IEND(png_structp png_ptr)
671 { 680 {
672 #ifdef PNG_USE_LOCAL_ARRAYS 681 #ifdef PNG_USE_LOCAL_ARRAYS
673 PNG_IEND; 682 PNG_IEND;
674 #endif 683 #endif
675 png_debug(1, "in png_write_IEND\n"); 684 png_debug(1, "in png_write_IEND\n");
676 png_write_chunk(png_ptr, png_IEND, png_bytep_NULL, 685 png_write_chunk(png_ptr, (png_bytep)png_IEND, png_bytep_NULL,
677 (png_size_t)0); 686 (png_size_t)0);
678 png_ptr->mode |= PNG_HAVE_IEND; 687 png_ptr->mode |= PNG_HAVE_IEND;
679 } 688 }
680 689
681 #if defined(PNG_WRITE_gAMA_SUPPORTED) 690 #if defined(PNG_WRITE_gAMA_SUPPORTED)
682 /* write a gAMA chunk */ 691 /* write a gAMA chunk */
683 #ifdef PNG_FLOATING_POINT_SUPPORTED 692 #ifdef PNG_FLOATING_POINT_SUPPORTED
684 void /* PRIVATE */ 693 void /* PRIVATE */
685 png_write_gAMA(png_structp png_ptr, double file_gamma) 694 png_write_gAMA(png_structp png_ptr, double file_gamma)
686 { 695 {
687 #ifdef PNG_USE_LOCAL_ARRAYS 696 #ifdef PNG_USE_LOCAL_ARRAYS
688 PNG_gAMA; 697 PNG_gAMA;
689 #endif 698 #endif
690 png_uint_32 igamma; 699 png_uint_32 igamma;
691 png_byte buf[4]; 700 png_byte buf[4];
692 701
693 png_debug(1, "in png_write_gAMA\n"); 702 png_debug(1, "in png_write_gAMA\n");
694 /* file_gamma is saved in 1/100,000ths */ 703 /* file_gamma is saved in 1/100,000ths */
695 igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5); 704 igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
696 png_save_uint_32(buf, igamma); 705 png_save_uint_32(buf, igamma);
697 png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4); 706 png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4);
698 } 707 }
699 #endif 708 #endif
700 #ifdef PNG_FIXED_POINT_SUPPORTED 709 #ifdef PNG_FIXED_POINT_SUPPORTED
701 void /* PRIVATE */ 710 void /* PRIVATE */
702 png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma) 711 png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
703 { 712 {
704 #ifdef PNG_USE_LOCAL_ARRAYS 713 #ifdef PNG_USE_LOCAL_ARRAYS
705 PNG_gAMA; 714 PNG_gAMA;
706 #endif 715 #endif
707 png_byte buf[4]; 716 png_byte buf[4];
708 717
709 png_debug(1, "in png_write_gAMA\n"); 718 png_debug(1, "in png_write_gAMA\n");
710 /* file_gamma is saved in 1/100,000ths */ 719 /* file_gamma is saved in 1/100,000ths */
711 png_save_uint_32(buf, (png_uint_32)file_gamma); 720 png_save_uint_32(buf, (png_uint_32)file_gamma);
712 png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4); 721 png_write_chunk(png_ptr, (png_bytep)png_gAMA, buf, (png_size_t)4);
713 } 722 }
714 #endif 723 #endif
715 #endif 724 #endif
716 725
717 #if defined(PNG_WRITE_sRGB_SUPPORTED) 726 #if defined(PNG_WRITE_sRGB_SUPPORTED)
718 /* write a sRGB chunk */ 727 /* write a sRGB chunk */
719 void /* PRIVATE */ 728 void /* PRIVATE */
720 png_write_sRGB(png_structp png_ptr, int srgb_intent) 729 png_write_sRGB(png_structp png_ptr, int srgb_intent)
721 { 730 {
722 #ifdef PNG_USE_LOCAL_ARRAYS 731 #ifdef PNG_USE_LOCAL_ARRAYS
723 PNG_sRGB; 732 PNG_sRGB;
724 #endif 733 #endif
725 png_byte buf[1]; 734 png_byte buf[1];
726 735
727 png_debug(1, "in png_write_sRGB\n"); 736 png_debug(1, "in png_write_sRGB\n");
728 if(srgb_intent >= PNG_sRGB_INTENT_LAST) 737 if (srgb_intent >= PNG_sRGB_INTENT_LAST)
729 png_warning(png_ptr, 738 png_warning(png_ptr,
730 "Invalid sRGB rendering intent specified"); 739 "Invalid sRGB rendering intent specified");
731 buf[0]=(png_byte)srgb_intent; 740 buf[0]=(png_byte)srgb_intent;
732 png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1); 741 png_write_chunk(png_ptr, (png_bytep)png_sRGB, buf, (png_size_t)1);
733 } 742 }
734 #endif 743 #endif
735 744
736 #if defined(PNG_WRITE_iCCP_SUPPORTED) 745 #if defined(PNG_WRITE_iCCP_SUPPORTED)
737 /* write an iCCP chunk */ 746 /* write an iCCP chunk */
738 void /* PRIVATE */ 747 void /* PRIVATE */
739 png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type, 748 png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
740 png_charp profile, int profile_len) 749 png_charp profile, int profile_len)
741 { 750 {
742 #ifdef PNG_USE_LOCAL_ARRAYS 751 #ifdef PNG_USE_LOCAL_ARRAYS
(...skipping 20 matching lines...) Expand all
763 } 772 }
764 773
765 if (compression_type != PNG_COMPRESSION_TYPE_BASE) 774 if (compression_type != PNG_COMPRESSION_TYPE_BASE)
766 png_warning(png_ptr, "Unknown compression type in iCCP chunk"); 775 png_warning(png_ptr, "Unknown compression type in iCCP chunk");
767 776
768 if (profile == NULL) 777 if (profile == NULL)
769 profile_len = 0; 778 profile_len = 0;
770 779
771 if (profile_len > 3) 780 if (profile_len > 3)
772 embedded_profile_len = 781 embedded_profile_len =
773 ((*( (png_bytep)profile ))<<24) | 782 ((*( (png_bytep)profile ))<<24) |
774 ((*( (png_bytep)profile+1))<<16) | 783 ((*( (png_bytep)profile + 1))<<16) |
775 ((*( (png_bytep)profile+2))<< 8) | 784 ((*( (png_bytep)profile + 2))<< 8) |
776 ((*( (png_bytep)profile+3)) ); 785 ((*( (png_bytep)profile + 3)) );
777 786
778 if (profile_len < embedded_profile_len) 787 if (profile_len < embedded_profile_len)
779 { 788 {
780 png_warning(png_ptr, 789 png_warning(png_ptr,
781 "Embedded profile length too large in iCCP chunk"); 790 "Embedded profile length too large in iCCP chunk");
782 return; 791 return;
783 } 792 }
784 793
785 if (profile_len > embedded_profile_len) 794 if (profile_len > embedded_profile_len)
786 { 795 {
787 png_warning(png_ptr, 796 png_warning(png_ptr,
788 "Truncating profile to actual length in iCCP chunk"); 797 "Truncating profile to actual length in iCCP chunk");
789 profile_len = embedded_profile_len; 798 profile_len = embedded_profile_len;
790 } 799 }
791 800
792 if (profile_len) 801 if (profile_len)
793 profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len , 802 profile_len = png_text_compress(png_ptr, profile,
794 PNG_COMPRESSION_TYPE_BASE, &comp); 803 (png_size_t)profile_len, PNG_COMPRESSION_TYPE_BASE, &comp);
795 804
796 /* make sure we include the NULL after the name and the compression type */ 805 /* make sure we include the NULL after the name and the compression type */
797 png_write_chunk_start(png_ptr, png_iCCP, 806 png_write_chunk_start(png_ptr, (png_bytep)png_iCCP,
798 (png_uint_32)name_len+profile_len+2); 807 (png_uint_32)(name_len + profile_len + 2));
799 new_name[name_len+1]=0x00; 808 new_name[name_len + 1] = 0x00;
800 png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2); 809 png_write_chunk_data(png_ptr, (png_bytep)new_name,
810 (png_size_t)(name_len + 2));
801 811
802 if (profile_len) 812 if (profile_len)
803 png_write_compressed_data_out(png_ptr, &comp); 813 png_write_compressed_data_out(png_ptr, &comp);
804 814
805 png_write_chunk_end(png_ptr); 815 png_write_chunk_end(png_ptr);
806 png_free(png_ptr, new_name); 816 png_free(png_ptr, new_name);
807 } 817 }
808 #endif 818 #endif
809 819
810 #if defined(PNG_WRITE_sPLT_SUPPORTED) 820 #if defined(PNG_WRITE_sPLT_SUPPORTED)
(...skipping 16 matching lines...) Expand all
827 837
828 png_debug(1, "in png_write_sPLT\n"); 838 png_debug(1, "in png_write_sPLT\n");
829 if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr, 839 if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
830 spalette->name, &new_name))==0) 840 spalette->name, &new_name))==0)
831 { 841 {
832 png_warning(png_ptr, "Empty keyword in sPLT chunk"); 842 png_warning(png_ptr, "Empty keyword in sPLT chunk");
833 return; 843 return;
834 } 844 }
835 845
836 /* make sure we include the NULL after the name */ 846 /* make sure we include the NULL after the name */
837 png_write_chunk_start(png_ptr, png_sPLT, 847 png_write_chunk_start(png_ptr, (png_bytep)png_sPLT,
838 (png_uint_32)(name_len + 2 + palette_size)); 848 (png_uint_32)(name_len + 2 + palette_size));
839 png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1); 849 png_write_chunk_data(png_ptr, (png_bytep)new_name,
840 png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1); 850 (png_size_t)(name_len + 1));
851 png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, (png_size_t)1);
841 852
842 /* loop through each palette entry, writing appropriately */ 853 /* loop through each palette entry, writing appropriately */
843 #ifndef PNG_NO_POINTER_INDEXING 854 #ifndef PNG_NO_POINTER_INDEXING
844 for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++) 855 for (ep = spalette->entries; ep<spalette->entries + spalette->nentries; ep++)
845 { 856 {
846 if (spalette->depth == 8) 857 if (spalette->depth == 8)
847 { 858 {
848 entrybuf[0] = (png_byte)ep->red; 859 entrybuf[0] = (png_byte)ep->red;
849 entrybuf[1] = (png_byte)ep->green; 860 entrybuf[1] = (png_byte)ep->green;
850 entrybuf[2] = (png_byte)ep->blue; 861 entrybuf[2] = (png_byte)ep->blue;
851 entrybuf[3] = (png_byte)ep->alpha; 862 entrybuf[3] = (png_byte)ep->alpha;
852 png_save_uint_16(entrybuf + 4, ep->frequency); 863 png_save_uint_16(entrybuf + 4, ep->frequency);
853 } 864 }
854 else 865 else
855 { 866 {
856 png_save_uint_16(entrybuf + 0, ep->red); 867 png_save_uint_16(entrybuf + 0, ep->red);
857 png_save_uint_16(entrybuf + 2, ep->green); 868 png_save_uint_16(entrybuf + 2, ep->green);
858 png_save_uint_16(entrybuf + 4, ep->blue); 869 png_save_uint_16(entrybuf + 4, ep->blue);
859 png_save_uint_16(entrybuf + 6, ep->alpha); 870 png_save_uint_16(entrybuf + 6, ep->alpha);
860 png_save_uint_16(entrybuf + 8, ep->frequency); 871 png_save_uint_16(entrybuf + 8, ep->frequency);
861 } 872 }
862 png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size); 873 png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
863 } 874 }
864 #else 875 #else
865 ep=spalette->entries; 876 ep=spalette->entries;
866 for (i=0; i>spalette->nentries; i++) 877 for (i=0; i>spalette->nentries; i++)
867 { 878 {
868 if (spalette->depth == 8) 879 if (spalette->depth == 8)
869 { 880 {
870 entrybuf[0] = (png_byte)ep[i].red; 881 entrybuf[0] = (png_byte)ep[i].red;
871 entrybuf[1] = (png_byte)ep[i].green; 882 entrybuf[1] = (png_byte)ep[i].green;
872 entrybuf[2] = (png_byte)ep[i].blue; 883 entrybuf[2] = (png_byte)ep[i].blue;
873 entrybuf[3] = (png_byte)ep[i].alpha; 884 entrybuf[3] = (png_byte)ep[i].alpha;
874 png_save_uint_16(entrybuf + 4, ep[i].frequency); 885 png_save_uint_16(entrybuf + 4, ep[i].frequency);
875 } 886 }
876 else 887 else
877 { 888 {
878 png_save_uint_16(entrybuf + 0, ep[i].red); 889 png_save_uint_16(entrybuf + 0, ep[i].red);
879 png_save_uint_16(entrybuf + 2, ep[i].green); 890 png_save_uint_16(entrybuf + 2, ep[i].green);
880 png_save_uint_16(entrybuf + 4, ep[i].blue); 891 png_save_uint_16(entrybuf + 4, ep[i].blue);
881 png_save_uint_16(entrybuf + 6, ep[i].alpha); 892 png_save_uint_16(entrybuf + 6, ep[i].alpha);
882 png_save_uint_16(entrybuf + 8, ep[i].frequency); 893 png_save_uint_16(entrybuf + 8, ep[i].frequency);
883 } 894 }
884 png_write_chunk_data(png_ptr, entrybuf, entry_size); 895 png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
885 } 896 }
886 #endif 897 #endif
887 898
888 png_write_chunk_end(png_ptr); 899 png_write_chunk_end(png_ptr);
889 png_free(png_ptr, new_name); 900 png_free(png_ptr, new_name);
890 } 901 }
891 #endif 902 #endif
892 903
893 #if defined(PNG_WRITE_sBIT_SUPPORTED) 904 #if defined(PNG_WRITE_sBIT_SUPPORTED)
894 /* write the sBIT chunk */ 905 /* write the sBIT chunk */
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 if (color_type & PNG_COLOR_MASK_ALPHA) 946 if (color_type & PNG_COLOR_MASK_ALPHA)
936 { 947 {
937 if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth) 948 if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
938 { 949 {
939 png_warning(png_ptr, "Invalid sBIT depth specified"); 950 png_warning(png_ptr, "Invalid sBIT depth specified");
940 return; 951 return;
941 } 952 }
942 buf[size++] = sbit->alpha; 953 buf[size++] = sbit->alpha;
943 } 954 }
944 955
945 png_write_chunk(png_ptr, png_sBIT, buf, size); 956 png_write_chunk(png_ptr, (png_bytep)png_sBIT, buf, size);
946 } 957 }
947 #endif 958 #endif
948 959
949 #if defined(PNG_WRITE_cHRM_SUPPORTED) 960 #if defined(PNG_WRITE_cHRM_SUPPORTED)
950 /* write the cHRM chunk */ 961 /* write the cHRM chunk */
951 #ifdef PNG_FLOATING_POINT_SUPPORTED 962 #ifdef PNG_FLOATING_POINT_SUPPORTED
952 void /* PRIVATE */ 963 void /* PRIVATE */
953 png_write_cHRM(png_structp png_ptr, double white_x, double white_y, 964 png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
954 double red_x, double red_y, double green_x, double green_y, 965 double red_x, double red_y, double green_x, double green_y,
955 double blue_x, double blue_y) 966 double blue_x, double blue_y)
956 { 967 {
957 #ifdef PNG_USE_LOCAL_ARRAYS 968 #ifdef PNG_USE_LOCAL_ARRAYS
958 PNG_cHRM; 969 PNG_cHRM;
959 #endif 970 #endif
960 png_byte buf[32]; 971 png_byte buf[32];
961 png_uint_32 itemp; 972 png_uint_32 itemp;
962 973
963 png_debug(1, "in png_write_cHRM\n"); 974 png_debug(1, "in png_write_cHRM\n");
964 /* each value is saved in 1/100,000ths */ 975 /* each value is saved in 1/100,000ths */
965 if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 || 976 if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
966 white_x + white_y > 1.0) 977 white_x + white_y > 1.0)
967 { 978 {
968 png_warning(png_ptr, "Invalid cHRM white point specified"); 979 png_warning(png_ptr, "Invalid cHRM white point specified");
969 #if !defined(PNG_NO_CONSOLE_IO) 980 #if !defined(PNG_NO_CONSOLE_IO)
970 fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y); 981 fprintf(stderr, "white_x=%f, white_y=%f\n", white_x, white_y);
971 #endif 982 #endif
972 return; 983 return;
973 } 984 }
974 itemp = (png_uint_32)(white_x * 100000.0 + 0.5); 985 itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
975 png_save_uint_32(buf, itemp); 986 png_save_uint_32(buf, itemp);
976 itemp = (png_uint_32)(white_y * 100000.0 + 0.5); 987 itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
977 png_save_uint_32(buf + 4, itemp); 988 png_save_uint_32(buf + 4, itemp);
978 989
979 if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0) 990 if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
980 { 991 {
(...skipping 18 matching lines...) Expand all
999 if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0) 1010 if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
1000 { 1011 {
1001 png_warning(png_ptr, "Invalid cHRM blue point specified"); 1012 png_warning(png_ptr, "Invalid cHRM blue point specified");
1002 return; 1013 return;
1003 } 1014 }
1004 itemp = (png_uint_32)(blue_x * 100000.0 + 0.5); 1015 itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
1005 png_save_uint_32(buf + 24, itemp); 1016 png_save_uint_32(buf + 24, itemp);
1006 itemp = (png_uint_32)(blue_y * 100000.0 + 0.5); 1017 itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
1007 png_save_uint_32(buf + 28, itemp); 1018 png_save_uint_32(buf + 28, itemp);
1008 1019
1009 png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32); 1020 png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32);
1010 } 1021 }
1011 #endif 1022 #endif
1012 #ifdef PNG_FIXED_POINT_SUPPORTED 1023 #ifdef PNG_FIXED_POINT_SUPPORTED
1013 void /* PRIVATE */ 1024 void /* PRIVATE */
1014 png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x, 1025 png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
1015 png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y, 1026 png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
1016 png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x, 1027 png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
1017 png_fixed_point blue_y) 1028 png_fixed_point blue_y)
1018 { 1029 {
1019 #ifdef PNG_USE_LOCAL_ARRAYS 1030 #ifdef PNG_USE_LOCAL_ARRAYS
1020 PNG_cHRM; 1031 PNG_cHRM;
1021 #endif 1032 #endif
1022 png_byte buf[32]; 1033 png_byte buf[32];
1023 1034
1024 png_debug(1, "in png_write_cHRM\n"); 1035 png_debug(1, "in png_write_cHRM\n");
1025 /* each value is saved in 1/100,000ths */ 1036 /* each value is saved in 1/100,000ths */
1026 if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L) 1037 if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
1027 { 1038 {
1028 png_warning(png_ptr, "Invalid fixed cHRM white point specified"); 1039 png_warning(png_ptr, "Invalid fixed cHRM white point specified");
1029 #if !defined(PNG_NO_CONSOLE_IO) 1040 #if !defined(PNG_NO_CONSOLE_IO)
1030 fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y); 1041 fprintf(stderr, "white_x=%ld, white_y=%ld\n", (unsigned long)white_x,
1042 (unsigned long)white_y);
1031 #endif 1043 #endif
1032 return; 1044 return;
1033 } 1045 }
1034 png_save_uint_32(buf, (png_uint_32)white_x); 1046 png_save_uint_32(buf, (png_uint_32)white_x);
1035 png_save_uint_32(buf + 4, (png_uint_32)white_y); 1047 png_save_uint_32(buf + 4, (png_uint_32)white_y);
1036 1048
1037 if (red_x + red_y > 100000L) 1049 if (red_x + red_y > 100000L)
1038 { 1050 {
1039 png_warning(png_ptr, "Invalid cHRM fixed red point specified"); 1051 png_warning(png_ptr, "Invalid cHRM fixed red point specified");
1040 return; 1052 return;
(...skipping 10 matching lines...) Expand all
1051 png_save_uint_32(buf + 20, (png_uint_32)green_y); 1063 png_save_uint_32(buf + 20, (png_uint_32)green_y);
1052 1064
1053 if (blue_x + blue_y > 100000L) 1065 if (blue_x + blue_y > 100000L)
1054 { 1066 {
1055 png_warning(png_ptr, "Invalid fixed cHRM blue point specified"); 1067 png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
1056 return; 1068 return;
1057 } 1069 }
1058 png_save_uint_32(buf + 24, (png_uint_32)blue_x); 1070 png_save_uint_32(buf + 24, (png_uint_32)blue_x);
1059 png_save_uint_32(buf + 28, (png_uint_32)blue_y); 1071 png_save_uint_32(buf + 28, (png_uint_32)blue_y);
1060 1072
1061 png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32); 1073 png_write_chunk(png_ptr, (png_bytep)png_cHRM, buf, (png_size_t)32);
1062 } 1074 }
1063 #endif 1075 #endif
1064 #endif 1076 #endif
1065 1077
1066 #if defined(PNG_WRITE_tRNS_SUPPORTED) 1078 #if defined(PNG_WRITE_tRNS_SUPPORTED)
1067 /* write the tRNS chunk */ 1079 /* write the tRNS chunk */
1068 void /* PRIVATE */ 1080 void /* PRIVATE */
1069 png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran, 1081 png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
1070 int num_trans, int color_type) 1082 int num_trans, int color_type)
1071 { 1083 {
1072 #ifdef PNG_USE_LOCAL_ARRAYS 1084 #ifdef PNG_USE_LOCAL_ARRAYS
1073 PNG_tRNS; 1085 PNG_tRNS;
1074 #endif 1086 #endif
1075 png_byte buf[6]; 1087 png_byte buf[6];
1076 1088
1077 png_debug(1, "in png_write_tRNS\n"); 1089 png_debug(1, "in png_write_tRNS\n");
1078 if (color_type == PNG_COLOR_TYPE_PALETTE) 1090 if (color_type == PNG_COLOR_TYPE_PALETTE)
1079 { 1091 {
1080 if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette) 1092 if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
1081 { 1093 {
1082 png_warning(png_ptr,"Invalid number of transparent colors specified"); 1094 png_warning(png_ptr, "Invalid number of transparent colors specified");
1083 return; 1095 return;
1084 } 1096 }
1085 /* write the chunk out as it is */ 1097 /* write the chunk out as it is */
1086 png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans); 1098 png_write_chunk(png_ptr, (png_bytep)png_tRNS, trans,
1099 (png_size_t)num_trans);
1087 } 1100 }
1088 else if (color_type == PNG_COLOR_TYPE_GRAY) 1101 else if (color_type == PNG_COLOR_TYPE_GRAY)
1089 { 1102 {
1090 /* one 16 bit value */ 1103 /* one 16 bit value */
1091 if(tran->gray >= (1 << png_ptr->bit_depth)) 1104 if (tran->gray >= (1 << png_ptr->bit_depth))
1092 { 1105 {
1093 png_warning(png_ptr, 1106 png_warning(png_ptr,
1094 "Ignoring attempt to write tRNS chunk out-of-range for bit_depth"); 1107 "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
1095 return; 1108 return;
1096 } 1109 }
1097 png_save_uint_16(buf, tran->gray); 1110 png_save_uint_16(buf, tran->gray);
1098 png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2); 1111 png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)2);
1099 } 1112 }
1100 else if (color_type == PNG_COLOR_TYPE_RGB) 1113 else if (color_type == PNG_COLOR_TYPE_RGB)
1101 { 1114 {
1102 /* three 16 bit values */ 1115 /* three 16 bit values */
1103 png_save_uint_16(buf, tran->red); 1116 png_save_uint_16(buf, tran->red);
1104 png_save_uint_16(buf + 2, tran->green); 1117 png_save_uint_16(buf + 2, tran->green);
1105 png_save_uint_16(buf + 4, tran->blue); 1118 png_save_uint_16(buf + 4, tran->blue);
1106 if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) 1119 if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
1107 { 1120 {
1108 png_warning(png_ptr, 1121 png_warning(png_ptr,
1109 "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8") ; 1122 "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
1110 return; 1123 return;
1111 } 1124 }
1112 png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6); 1125 png_write_chunk(png_ptr, (png_bytep)png_tRNS, buf, (png_size_t)6);
1113 } 1126 }
1114 else 1127 else
1115 { 1128 {
1116 png_warning(png_ptr, "Can't write tRNS with an alpha channel"); 1129 png_warning(png_ptr, "Can't write tRNS with an alpha channel");
1117 } 1130 }
1118 } 1131 }
1119 #endif 1132 #endif
1120 1133
1121 #if defined(PNG_WRITE_bKGD_SUPPORTED) 1134 #if defined(PNG_WRITE_bKGD_SUPPORTED)
1122 /* write the background chunk */ 1135 /* write the background chunk */
(...skipping 12 matching lines...) Expand all
1135 #if defined(PNG_MNG_FEATURES_SUPPORTED) 1148 #if defined(PNG_MNG_FEATURES_SUPPORTED)
1136 (png_ptr->num_palette || 1149 (png_ptr->num_palette ||
1137 (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) && 1150 (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
1138 #endif 1151 #endif
1139 back->index > png_ptr->num_palette) 1152 back->index > png_ptr->num_palette)
1140 { 1153 {
1141 png_warning(png_ptr, "Invalid background palette index"); 1154 png_warning(png_ptr, "Invalid background palette index");
1142 return; 1155 return;
1143 } 1156 }
1144 buf[0] = back->index; 1157 buf[0] = back->index;
1145 png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1); 1158 png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)1);
1146 } 1159 }
1147 else if (color_type & PNG_COLOR_MASK_COLOR) 1160 else if (color_type & PNG_COLOR_MASK_COLOR)
1148 { 1161 {
1149 png_save_uint_16(buf, back->red); 1162 png_save_uint_16(buf, back->red);
1150 png_save_uint_16(buf + 2, back->green); 1163 png_save_uint_16(buf + 2, back->green);
1151 png_save_uint_16(buf + 4, back->blue); 1164 png_save_uint_16(buf + 4, back->blue);
1152 if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4])) 1165 if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
1153 { 1166 {
1154 png_warning(png_ptr, 1167 png_warning(png_ptr,
1155 "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8") ; 1168 "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
1156 return; 1169 return;
1157 } 1170 }
1158 png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6); 1171 png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)6);
1159 } 1172 }
1160 else 1173 else
1161 { 1174 {
1162 if(back->gray >= (1 << png_ptr->bit_depth)) 1175 if (back->gray >= (1 << png_ptr->bit_depth))
1163 { 1176 {
1164 png_warning(png_ptr, 1177 png_warning(png_ptr,
1165 "Ignoring attempt to write bKGD chunk out-of-range for bit_depth"); 1178 "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
1166 return; 1179 return;
1167 } 1180 }
1168 png_save_uint_16(buf, back->gray); 1181 png_save_uint_16(buf, back->gray);
1169 png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2); 1182 png_write_chunk(png_ptr, (png_bytep)png_bKGD, buf, (png_size_t)2);
1170 } 1183 }
1171 } 1184 }
1172 #endif 1185 #endif
1173 1186
1174 #if defined(PNG_WRITE_hIST_SUPPORTED) 1187 #if defined(PNG_WRITE_hIST_SUPPORTED)
1175 /* write the histogram */ 1188 /* write the histogram */
1176 void /* PRIVATE */ 1189 void /* PRIVATE */
1177 png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist) 1190 png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
1178 { 1191 {
1179 #ifdef PNG_USE_LOCAL_ARRAYS 1192 #ifdef PNG_USE_LOCAL_ARRAYS
1180 PNG_hIST; 1193 PNG_hIST;
1181 #endif 1194 #endif
1182 int i; 1195 int i;
1183 png_byte buf[3]; 1196 png_byte buf[3];
1184 1197
1185 png_debug(1, "in png_write_hIST\n"); 1198 png_debug(1, "in png_write_hIST\n");
1186 if (num_hist > (int)png_ptr->num_palette) 1199 if (num_hist > (int)png_ptr->num_palette)
1187 { 1200 {
1188 png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist, 1201 png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
1189 png_ptr->num_palette); 1202 png_ptr->num_palette);
1190 png_warning(png_ptr, "Invalid number of histogram entries specified"); 1203 png_warning(png_ptr, "Invalid number of histogram entries specified");
1191 return; 1204 return;
1192 } 1205 }
1193 1206
1194 png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2)); 1207 png_write_chunk_start(png_ptr, (png_bytep)png_hIST,
1208 (png_uint_32)(num_hist * 2));
1195 for (i = 0; i < num_hist; i++) 1209 for (i = 0; i < num_hist; i++)
1196 { 1210 {
1197 png_save_uint_16(buf, hist[i]); 1211 png_save_uint_16(buf, hist[i]);
1198 png_write_chunk_data(png_ptr, buf, (png_size_t)2); 1212 png_write_chunk_data(png_ptr, buf, (png_size_t)2);
1199 } 1213 }
1200 png_write_chunk_end(png_ptr); 1214 png_write_chunk_end(png_ptr);
1201 } 1215 }
1202 #endif 1216 #endif
1203 1217
1204 #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \ 1218 #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 key_len--; 1318 key_len--;
1305 kwarn=1; 1319 kwarn=1;
1306 } 1320 }
1307 else 1321 else
1308 { 1322 {
1309 *(dp++) = *kp; 1323 *(dp++) = *kp;
1310 kflag = 0; 1324 kflag = 0;
1311 } 1325 }
1312 } 1326 }
1313 *dp = '\0'; 1327 *dp = '\0';
1314 if(kwarn) 1328 if (kwarn)
1315 png_warning(png_ptr, "extra interior spaces removed from keyword"); 1329 png_warning(png_ptr, "extra interior spaces removed from keyword");
1316 1330
1317 if (key_len == 0) 1331 if (key_len == 0)
1318 { 1332 {
1319 png_free(png_ptr, *new_key); 1333 png_free(png_ptr, *new_key);
1320 *new_key=NULL; 1334 *new_key=NULL;
1321 png_warning(png_ptr, "Zero length keyword"); 1335 png_warning(png_ptr, "Zero length keyword");
1322 } 1336 }
1323 1337
1324 if (key_len > 79) 1338 if (key_len > 79)
1325 { 1339 {
1326 png_warning(png_ptr, "keyword length must be 1 - 79 characters"); 1340 png_warning(png_ptr, "keyword length must be 1 - 79 characters");
1327 new_key[79] = '\0'; 1341 new_key[79] = '\0';
1328 key_len = 79; 1342 key_len = 79;
1329 } 1343 }
1330 1344
(...skipping 19 matching lines...) Expand all
1350 png_warning(png_ptr, "Empty keyword in tEXt chunk"); 1364 png_warning(png_ptr, "Empty keyword in tEXt chunk");
1351 return; 1365 return;
1352 } 1366 }
1353 1367
1354 if (text == NULL || *text == '\0') 1368 if (text == NULL || *text == '\0')
1355 text_len = 0; 1369 text_len = 0;
1356 else 1370 else
1357 text_len = png_strlen(text); 1371 text_len = png_strlen(text);
1358 1372
1359 /* make sure we include the 0 after the key */ 1373 /* make sure we include the 0 after the key */
1360 png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1); 1374 png_write_chunk_start(png_ptr, (png_bytep)png_tEXt,
1375 (png_uint_32)(key_len + text_len + 1));
1361 /* 1376 /*
1362 * We leave it to the application to meet PNG-1.0 requirements on the 1377 * We leave it to the application to meet PNG-1.0 requirements on the
1363 * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of 1378 * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of
1364 * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them. 1379 * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them.
1365 * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. 1380 * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG.
1366 */ 1381 */
1367 png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1); 1382 png_write_chunk_data(png_ptr, (png_bytep)new_key,
1383 (png_size_t)(key_len + 1));
1368 if (text_len) 1384 if (text_len)
1369 png_write_chunk_data(png_ptr, (png_bytep)text, text_len); 1385 png_write_chunk_data(png_ptr, (png_bytep)text, (png_size_t)text_len);
1370 1386
1371 png_write_chunk_end(png_ptr); 1387 png_write_chunk_end(png_ptr);
1372 png_free(png_ptr, new_key); 1388 png_free(png_ptr, new_key);
1373 } 1389 }
1374 #endif 1390 #endif
1375 1391
1376 #if defined(PNG_WRITE_zTXt_SUPPORTED) 1392 #if defined(PNG_WRITE_zTXt_SUPPORTED)
1377 /* write a compressed text chunk */ 1393 /* write a compressed text chunk */
1378 void /* PRIVATE */ 1394 void /* PRIVATE */
1379 png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text, 1395 png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
(...skipping 11 matching lines...) Expand all
1391 1407
1392 comp.num_output_ptr = 0; 1408 comp.num_output_ptr = 0;
1393 comp.max_output_ptr = 0; 1409 comp.max_output_ptr = 0;
1394 comp.output_ptr = NULL; 1410 comp.output_ptr = NULL;
1395 comp.input = NULL; 1411 comp.input = NULL;
1396 comp.input_len = 0; 1412 comp.input_len = 0;
1397 1413
1398 if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0) 1414 if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
1399 { 1415 {
1400 png_warning(png_ptr, "Empty keyword in zTXt chunk"); 1416 png_warning(png_ptr, "Empty keyword in zTXt chunk");
1417 png_free(png_ptr, new_key);
1401 return; 1418 return;
1402 } 1419 }
1403 1420
1404 if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE) 1421 if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
1405 { 1422 {
1406 png_write_tEXt(png_ptr, new_key, text, (png_size_t)0); 1423 png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
1407 png_free(png_ptr, new_key); 1424 png_free(png_ptr, new_key);
1408 return; 1425 return;
1409 } 1426 }
1410 1427
1411 text_len = png_strlen(text); 1428 text_len = png_strlen(text);
1412 1429
1413 /* compute the compressed data; do it now for the length */ 1430 /* compute the compressed data; do it now for the length */
1414 text_len = png_text_compress(png_ptr, text, text_len, compression, 1431 text_len = png_text_compress(png_ptr, text, text_len, compression,
1415 &comp); 1432 &comp);
1416 1433
1417 /* write start of chunk */ 1434 /* write start of chunk */
1418 png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32) 1435 png_write_chunk_start(png_ptr, (png_bytep)png_zTXt,
1419 (key_len+text_len+2)); 1436 (png_uint_32)(key_len+text_len + 2));
1420 /* write key */ 1437 /* write key */
1421 png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1); 1438 png_write_chunk_data(png_ptr, (png_bytep)new_key,
1439 (png_size_t)(key_len + 1));
1422 png_free(png_ptr, new_key); 1440 png_free(png_ptr, new_key);
1423 1441
1424 buf[0] = (png_byte)compression; 1442 buf[0] = (png_byte)compression;
1425 /* write compression */ 1443 /* write compression */
1426 png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1); 1444 png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
1427 /* write the compressed data */ 1445 /* write the compressed data */
1428 png_write_compressed_data_out(png_ptr, &comp); 1446 png_write_compressed_data_out(png_ptr, &comp);
1429 1447
1430 /* close the chunk */ 1448 /* close the chunk */
1431 png_write_chunk_end(png_ptr); 1449 png_write_chunk_end(png_ptr);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1476 text_len = png_strlen(text); 1494 text_len = png_strlen(text);
1477 1495
1478 /* compute the compressed data; do it now for the length */ 1496 /* compute the compressed data; do it now for the length */
1479 text_len = png_text_compress(png_ptr, text, text_len, compression-2, 1497 text_len = png_text_compress(png_ptr, text, text_len, compression-2,
1480 &comp); 1498 &comp);
1481 1499
1482 1500
1483 /* make sure we include the compression flag, the compression byte, 1501 /* make sure we include the compression flag, the compression byte,
1484 * and the NULs after the key, lang, and lang_key parts */ 1502 * and the NULs after the key, lang, and lang_key parts */
1485 1503
1486 png_write_chunk_start(png_ptr, png_iTXt, 1504 png_write_chunk_start(png_ptr, (png_bytep)png_iTXt,
1487 (png_uint_32)( 1505 (png_uint_32)(
1488 5 /* comp byte, comp flag, terminators for key, lang and lang_key */ 1506 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
1489 + key_len 1507 + key_len
1490 + lang_len 1508 + lang_len
1491 + lang_key_len 1509 + lang_key_len
1492 + text_len)); 1510 + text_len));
1493 1511
1494 /* 1512 /*
1495 * We leave it to the application to meet PNG-1.0 requirements on the 1513 * We leave it to the application to meet PNG-1.0 requirements on the
1496 * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of 1514 * contents of the text. PNG-1.0 through PNG-1.2 discourage the use of
1497 * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them. 1515 * any non-Latin-1 characters except for NEWLINE. ISO PNG will forbid them.
1498 * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG. 1516 * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG.
1499 */ 1517 */
1500 png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1); 1518 png_write_chunk_data(png_ptr, (png_bytep)new_key,
1519 (png_size_t)(key_len + 1));
1501 1520
1502 /* set the compression flag */ 1521 /* set the compression flag */
1503 if (compression == PNG_ITXT_COMPRESSION_NONE || \ 1522 if (compression == PNG_ITXT_COMPRESSION_NONE || \
1504 compression == PNG_TEXT_COMPRESSION_NONE) 1523 compression == PNG_TEXT_COMPRESSION_NONE)
1505 cbuf[0] = 0; 1524 cbuf[0] = 0;
1506 else /* compression == PNG_ITXT_COMPRESSION_zTXt */ 1525 else /* compression == PNG_ITXT_COMPRESSION_zTXt */
1507 cbuf[0] = 1; 1526 cbuf[0] = 1;
1508 /* set the compression method */ 1527 /* set the compression method */
1509 cbuf[1] = 0; 1528 cbuf[1] = 0;
1510 png_write_chunk_data(png_ptr, cbuf, 2); 1529 png_write_chunk_data(png_ptr, cbuf, (png_size_t)2);
1511 1530
1512 cbuf[0] = 0; 1531 cbuf[0] = 0;
1513 png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_l en + 1); 1532 png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf),
1514 png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_k ey_len + 1); 1533 (png_size_t)(lang_len + 1));
1534 png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf),
1535 (png_size_t)(lang_key_len + 1));
1515 png_write_compressed_data_out(png_ptr, &comp); 1536 png_write_compressed_data_out(png_ptr, &comp);
1516 1537
1517 png_write_chunk_end(png_ptr); 1538 png_write_chunk_end(png_ptr);
1518 png_free(png_ptr, new_key); 1539 png_free(png_ptr, new_key);
1519 png_free(png_ptr, new_lang); 1540 png_free(png_ptr, new_lang);
1520 } 1541 }
1521 #endif 1542 #endif
1522 1543
1523 #if defined(PNG_WRITE_oFFs_SUPPORTED) 1544 #if defined(PNG_WRITE_oFFs_SUPPORTED)
1524 /* write the oFFs chunk */ 1545 /* write the oFFs chunk */
1525 void /* PRIVATE */ 1546 void /* PRIVATE */
1526 png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset, 1547 png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
1527 int unit_type) 1548 int unit_type)
1528 { 1549 {
1529 #ifdef PNG_USE_LOCAL_ARRAYS 1550 #ifdef PNG_USE_LOCAL_ARRAYS
1530 PNG_oFFs; 1551 PNG_oFFs;
1531 #endif 1552 #endif
1532 png_byte buf[9]; 1553 png_byte buf[9];
1533 1554
1534 png_debug(1, "in png_write_oFFs\n"); 1555 png_debug(1, "in png_write_oFFs\n");
1535 if (unit_type >= PNG_OFFSET_LAST) 1556 if (unit_type >= PNG_OFFSET_LAST)
1536 png_warning(png_ptr, "Unrecognized unit type for oFFs chunk"); 1557 png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
1537 1558
1538 png_save_int_32(buf, x_offset); 1559 png_save_int_32(buf, x_offset);
1539 png_save_int_32(buf + 4, y_offset); 1560 png_save_int_32(buf + 4, y_offset);
1540 buf[8] = (png_byte)unit_type; 1561 buf[8] = (png_byte)unit_type;
1541 1562
1542 png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9); 1563 png_write_chunk(png_ptr, (png_bytep)png_oFFs, buf, (png_size_t)9);
1543 } 1564 }
1544 #endif 1565 #endif
1545 #if defined(PNG_WRITE_pCAL_SUPPORTED) 1566 #if defined(PNG_WRITE_pCAL_SUPPORTED)
1546 /* write the pCAL chunk (described in the PNG extensions document) */ 1567 /* write the pCAL chunk (described in the PNG extensions document) */
1547 void /* PRIVATE */ 1568 void /* PRIVATE */
1548 png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0, 1569 png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
1549 png_int_32 X1, int type, int nparams, png_charp units, png_charpp params) 1570 png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
1550 { 1571 {
1551 #ifdef PNG_USE_LOCAL_ARRAYS 1572 #ifdef PNG_USE_LOCAL_ARRAYS
1552 PNG_pCAL; 1573 PNG_pCAL;
1553 #endif 1574 #endif
1554 png_size_t purpose_len, units_len, total_len; 1575 png_size_t purpose_len, units_len, total_len;
1555 png_uint_32p params_len; 1576 png_uint_32p params_len;
1556 png_byte buf[10]; 1577 png_byte buf[10];
1557 png_charp new_purpose; 1578 png_charp new_purpose;
1558 int i; 1579 int i;
1559 1580
1560 png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams); 1581 png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
1561 if (type >= PNG_EQUATION_LAST) 1582 if (type >= PNG_EQUATION_LAST)
1562 png_warning(png_ptr, "Unrecognized equation type for pCAL chunk"); 1583 png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
1563 1584
1564 purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1; 1585 purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
1565 png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len); 1586 png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
1566 units_len = png_strlen(units) + (nparams == 0 ? 0 : 1); 1587 units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
1567 png_debug1(3, "pCAL units length = %d\n", (int)units_len); 1588 png_debug1(3, "pCAL units length = %d\n", (int)units_len);
1568 total_len = purpose_len + units_len + 10; 1589 total_len = purpose_len + units_len + 10;
1569 1590
1570 params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams 1591 params_len = (png_uint_32p)png_malloc(png_ptr,
1571 *png_sizeof(png_uint_32))); 1592 (png_uint_32)(nparams * png_sizeof(png_uint_32)));
1572 1593
1573 /* Find the length of each parameter, making sure we don't count the 1594 /* Find the length of each parameter, making sure we don't count the
1574 null terminator for the last parameter. */ 1595 null terminator for the last parameter. */
1575 for (i = 0; i < nparams; i++) 1596 for (i = 0; i < nparams; i++)
1576 { 1597 {
1577 params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1); 1598 params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
1578 png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]); 1599 png_debug2(3, "pCAL parameter %d length = %lu\n", i,
1600 (unsigned long) params_len[i]);
1579 total_len += (png_size_t)params_len[i]; 1601 total_len += (png_size_t)params_len[i];
1580 } 1602 }
1581 1603
1582 png_debug1(3, "pCAL total length = %d\n", (int)total_len); 1604 png_debug1(3, "pCAL total length = %d\n", (int)total_len);
1583 png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len); 1605 png_write_chunk_start(png_ptr, (png_bytep)png_pCAL, (png_uint_32)total_len);
1584 png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len); 1606 png_write_chunk_data(png_ptr, (png_bytep)new_purpose,
1607 (png_size_t)purpose_len);
1585 png_save_int_32(buf, X0); 1608 png_save_int_32(buf, X0);
1586 png_save_int_32(buf + 4, X1); 1609 png_save_int_32(buf + 4, X1);
1587 buf[8] = (png_byte)type; 1610 buf[8] = (png_byte)type;
1588 buf[9] = (png_byte)nparams; 1611 buf[9] = (png_byte)nparams;
1589 png_write_chunk_data(png_ptr, buf, (png_size_t)10); 1612 png_write_chunk_data(png_ptr, buf, (png_size_t)10);
1590 png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len); 1613 png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
1591 1614
1592 png_free(png_ptr, new_purpose); 1615 png_free(png_ptr, new_purpose);
1593 1616
1594 for (i = 0; i < nparams; i++) 1617 for (i = 0; i < nparams; i++)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1633 total_len += wc_len; 1656 total_len += wc_len;
1634 } 1657 }
1635 #else 1658 #else
1636 png_snprintf(buf + 1, 63, "%12.12e", width); 1659 png_snprintf(buf + 1, 63, "%12.12e", width);
1637 total_len = 1 + png_strlen(buf + 1) + 1; 1660 total_len = 1 + png_strlen(buf + 1) + 1;
1638 png_snprintf(buf + total_len, 64-total_len, "%12.12e", height); 1661 png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
1639 total_len += png_strlen(buf + total_len); 1662 total_len += png_strlen(buf + total_len);
1640 #endif 1663 #endif
1641 1664
1642 png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len); 1665 png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
1643 png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len); 1666 png_write_chunk(png_ptr, (png_bytep)png_sCAL, (png_bytep)buf, total_len);
1644 } 1667 }
1645 #else 1668 #else
1646 #ifdef PNG_FIXED_POINT_SUPPORTED 1669 #ifdef PNG_FIXED_POINT_SUPPORTED
1647 void /* PRIVATE */ 1670 void /* PRIVATE */
1648 png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width, 1671 png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
1649 png_charp height) 1672 png_charp height)
1650 { 1673 {
1651 #ifdef PNG_USE_LOCAL_ARRAYS 1674 #ifdef PNG_USE_LOCAL_ARRAYS
1652 PNG_sCAL; 1675 PNG_sCAL;
1653 #endif 1676 #endif
1654 png_byte buf[64]; 1677 png_byte buf[64];
1655 png_size_t wlen, hlen, total_len; 1678 png_size_t wlen, hlen, total_len;
1656 1679
1657 png_debug(1, "in png_write_sCAL_s\n"); 1680 png_debug(1, "in png_write_sCAL_s\n");
1658 1681
1659 wlen = png_strlen(width); 1682 wlen = png_strlen(width);
1660 hlen = png_strlen(height); 1683 hlen = png_strlen(height);
1661 total_len = wlen + hlen + 2; 1684 total_len = wlen + hlen + 2;
1662 if (total_len > 64) 1685 if (total_len > 64)
1663 { 1686 {
1664 png_warning(png_ptr, "Can't write sCAL (buffer too small)"); 1687 png_warning(png_ptr, "Can't write sCAL (buffer too small)");
1665 return; 1688 return;
1666 } 1689 }
1667 1690
1668 buf[0] = (png_byte)unit; 1691 buf[0] = (png_byte)unit;
1669 png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */ 1692 png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
1670 png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */ 1693 png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
1671 1694
1672 png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len); 1695 png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
1673 png_write_chunk(png_ptr, png_sCAL, buf, total_len); 1696 png_write_chunk(png_ptr, (png_bytep)png_sCAL, buf, total_len);
1674 } 1697 }
1675 #endif 1698 #endif
1676 #endif 1699 #endif
1677 #endif 1700 #endif
1678 1701
1679 #if defined(PNG_WRITE_pHYs_SUPPORTED) 1702 #if defined(PNG_WRITE_pHYs_SUPPORTED)
1680 /* write the pHYs chunk */ 1703 /* write the pHYs chunk */
1681 void /* PRIVATE */ 1704 void /* PRIVATE */
1682 png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit, 1705 png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
1683 png_uint_32 y_pixels_per_unit, 1706 png_uint_32 y_pixels_per_unit,
1684 int unit_type) 1707 int unit_type)
1685 { 1708 {
1686 #ifdef PNG_USE_LOCAL_ARRAYS 1709 #ifdef PNG_USE_LOCAL_ARRAYS
1687 PNG_pHYs; 1710 PNG_pHYs;
1688 #endif 1711 #endif
1689 png_byte buf[9]; 1712 png_byte buf[9];
1690 1713
1691 png_debug(1, "in png_write_pHYs\n"); 1714 png_debug(1, "in png_write_pHYs\n");
1692 if (unit_type >= PNG_RESOLUTION_LAST) 1715 if (unit_type >= PNG_RESOLUTION_LAST)
1693 png_warning(png_ptr, "Unrecognized unit type for pHYs chunk"); 1716 png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
1694 1717
1695 png_save_uint_32(buf, x_pixels_per_unit); 1718 png_save_uint_32(buf, x_pixels_per_unit);
1696 png_save_uint_32(buf + 4, y_pixels_per_unit); 1719 png_save_uint_32(buf + 4, y_pixels_per_unit);
1697 buf[8] = (png_byte)unit_type; 1720 buf[8] = (png_byte)unit_type;
1698 1721
1699 png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9); 1722 png_write_chunk(png_ptr, (png_bytep)png_pHYs, buf, (png_size_t)9);
1700 } 1723 }
1701 #endif 1724 #endif
1702 1725
1703 #if defined(PNG_WRITE_tIME_SUPPORTED) 1726 #if defined(PNG_WRITE_tIME_SUPPORTED)
1704 /* Write the tIME chunk. Use either png_convert_from_struct_tm() 1727 /* Write the tIME chunk. Use either png_convert_from_struct_tm()
1705 * or png_convert_from_time_t(), or fill in the structure yourself. 1728 * or png_convert_from_time_t(), or fill in the structure yourself.
1706 */ 1729 */
1707 void /* PRIVATE */ 1730 void /* PRIVATE */
1708 png_write_tIME(png_structp png_ptr, png_timep mod_time) 1731 png_write_tIME(png_structp png_ptr, png_timep mod_time)
1709 { 1732 {
(...skipping 11 matching lines...) Expand all
1721 return; 1744 return;
1722 } 1745 }
1723 1746
1724 png_save_uint_16(buf, mod_time->year); 1747 png_save_uint_16(buf, mod_time->year);
1725 buf[2] = mod_time->month; 1748 buf[2] = mod_time->month;
1726 buf[3] = mod_time->day; 1749 buf[3] = mod_time->day;
1727 buf[4] = mod_time->hour; 1750 buf[4] = mod_time->hour;
1728 buf[5] = mod_time->minute; 1751 buf[5] = mod_time->minute;
1729 buf[6] = mod_time->second; 1752 buf[6] = mod_time->second;
1730 1753
1731 png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7); 1754 png_write_chunk(png_ptr, (png_bytep)png_tIME, buf, (png_size_t)7);
1732 } 1755 }
1733 #endif 1756 #endif
1734 1757
1735 /* initializes the row writing capability of libpng */ 1758 /* initializes the row writing capability of libpng */
1736 void /* PRIVATE */ 1759 void /* PRIVATE */
1737 png_write_start_row(png_structp png_ptr) 1760 png_write_start_row(png_structp png_ptr)
1738 { 1761 {
1739 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1762 #ifdef PNG_WRITE_INTERLACING_SUPPORTED
1740 #ifdef PNG_USE_LOCAL_ARRAYS 1763 #ifdef PNG_USE_LOCAL_ARRAYS
1741 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */ 1764 /* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
1742 1765
1743 /* start of interlace block */ 1766 /* start of interlace block */
1744 int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0}; 1767 int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
1745 1768
1746 /* offset to next interlace block */ 1769 /* offset to next interlace block */
1747 int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1}; 1770 int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
1748 1771
1749 /* start of interlace block in the y direction */ 1772 /* start of interlace block in the y direction */
1750 int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1}; 1773 int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
1751 1774
1752 /* offset to next interlace block in the y direction */ 1775 /* offset to next interlace block in the y direction */
1753 int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2}; 1776 int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
1754 #endif 1777 #endif
1755 #endif 1778 #endif
1756 1779
1757 png_size_t buf_size; 1780 png_size_t buf_size;
1758 1781
1759 png_debug(1, "in png_write_start_row\n"); 1782 png_debug(1, "in png_write_start_row\n");
1760 buf_size = (png_size_t)(PNG_ROWBYTES( 1783 buf_size = (png_size_t)(PNG_ROWBYTES(
1761 png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1); 1784 png_ptr->usr_channels*png_ptr->usr_bit_depth, png_ptr->width) + 1);
1762 1785
1763 /* set up row buffer */ 1786 /* set up row buffer */
1764 png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size); 1787 png_ptr->row_buf = (png_bytep)png_malloc(png_ptr,
1788 (png_uint_32)buf_size);
1765 png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE; 1789 png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
1766 1790
1767 #ifndef PNG_NO_WRITE_FILTERING 1791 #ifndef PNG_NO_WRITE_FILTER
1768 /* set up filtering buffer, if using this filter */ 1792 /* set up filtering buffer, if using this filter */
1769 if (png_ptr->do_filter & PNG_FILTER_SUB) 1793 if (png_ptr->do_filter & PNG_FILTER_SUB)
1770 { 1794 {
1771 png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, 1795 png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
1772 (png_ptr->rowbytes + 1)); 1796 (png_uint_32)(png_ptr->rowbytes + 1));
1773 png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; 1797 png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
1774 } 1798 }
1775 1799
1776 /* We only need to keep the previous row if we are using one of these. */ 1800 /* We only need to keep the previous row if we are using one of these. */
1777 if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) 1801 if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
1778 { 1802 {
1779 /* set up previous row buffer */ 1803 /* set up previous row buffer */
1780 png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size); 1804 png_ptr->prev_row = (png_bytep)png_malloc(png_ptr,
1805 (png_uint_32)buf_size);
1781 png_memset(png_ptr->prev_row, 0, buf_size); 1806 png_memset(png_ptr->prev_row, 0, buf_size);
1782 1807
1783 if (png_ptr->do_filter & PNG_FILTER_UP) 1808 if (png_ptr->do_filter & PNG_FILTER_UP)
1784 { 1809 {
1785 png_ptr->up_row = (png_bytep)png_malloc(png_ptr, 1810 png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
1786 (png_ptr->rowbytes + 1)); 1811 (png_uint_32)(png_ptr->rowbytes + 1));
1787 png_ptr->up_row[0] = PNG_FILTER_VALUE_UP; 1812 png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
1788 } 1813 }
1789 1814
1790 if (png_ptr->do_filter & PNG_FILTER_AVG) 1815 if (png_ptr->do_filter & PNG_FILTER_AVG)
1791 { 1816 {
1792 png_ptr->avg_row = (png_bytep)png_malloc(png_ptr, 1817 png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
1793 (png_ptr->rowbytes + 1)); 1818 (png_uint_32)(png_ptr->rowbytes + 1));
1794 png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG; 1819 png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
1795 } 1820 }
1796 1821
1797 if (png_ptr->do_filter & PNG_FILTER_PAETH) 1822 if (png_ptr->do_filter & PNG_FILTER_PAETH)
1798 { 1823 {
1799 png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, 1824 png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
1800 (png_ptr->rowbytes + 1)); 1825 (png_uint_32)(png_ptr->rowbytes + 1));
1801 png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; 1826 png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
1802 } 1827 }
1803 #endif /* PNG_NO_WRITE_FILTERING */
1804 } 1828 }
1829 #endif /* PNG_NO_WRITE_FILTER */
1805 1830
1806 #ifdef PNG_WRITE_INTERLACING_SUPPORTED 1831 #ifdef PNG_WRITE_INTERLACING_SUPPORTED
1807 /* if interlaced, we need to set up width and height of pass */ 1832 /* if interlaced, we need to set up width and height of pass */
1808 if (png_ptr->interlaced) 1833 if (png_ptr->interlaced)
1809 { 1834 {
1810 if (!(png_ptr->transformations & PNG_INTERLACE)) 1835 if (!(png_ptr->transformations & PNG_INTERLACE))
1811 { 1836 {
1812 png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 - 1837 png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
1813 png_pass_ystart[0]) / png_pass_yinc[0]; 1838 png_pass_ystart[0]) / png_pass_yinc[0];
1814 png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 - 1839 png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1892 } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0); 1917 } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
1893 1918
1894 } 1919 }
1895 1920
1896 /* reset the row above the image for the next pass */ 1921 /* reset the row above the image for the next pass */
1897 if (png_ptr->pass < 7) 1922 if (png_ptr->pass < 7)
1898 { 1923 {
1899 if (png_ptr->prev_row != NULL) 1924 if (png_ptr->prev_row != NULL)
1900 png_memset(png_ptr->prev_row, 0, 1925 png_memset(png_ptr->prev_row, 0,
1901 (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels* 1926 (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
1902 png_ptr->usr_bit_depth,png_ptr->width))+1); 1927 png_ptr->usr_bit_depth, png_ptr->width)) + 1);
1903 return; 1928 return;
1904 } 1929 }
1905 } 1930 }
1906 #endif 1931 #endif
1907 1932
1908 /* if we get here, we've just written the last row, so we need 1933 /* if we get here, we've just written the last row, so we need
1909 to flush the compressor */ 1934 to flush the compressor */
1910 do 1935 do
1911 { 1936 {
1912 /* tell the compressor we are done */ 1937 /* tell the compressor we are done */
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after
2793 png_ptr->flush_rows++; 2818 png_ptr->flush_rows++;
2794 2819
2795 if (png_ptr->flush_dist > 0 && 2820 if (png_ptr->flush_dist > 0 &&
2796 png_ptr->flush_rows >= png_ptr->flush_dist) 2821 png_ptr->flush_rows >= png_ptr->flush_dist)
2797 { 2822 {
2798 png_write_flush(png_ptr); 2823 png_write_flush(png_ptr);
2799 } 2824 }
2800 #endif 2825 #endif
2801 } 2826 }
2802 #endif /* PNG_WRITE_SUPPORTED */ 2827 #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