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

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

Issue 1118002: libpng: update to 1.2.43 (Closed)
Patch Set: Created 10 years, 9 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
OLDNEW
1 1
2 /* pngwrite.c - general routines to write a PNG file 2 /* pngwrite.c - general routines to write a PNG file
3 * 3 *
4 * Last changed in libpng 1.2.37 [June 4, 2009] 4 * Last changed in libpng 1.2.42 [January 3, 2010]
5 * For conditions of distribution and use, see copyright notice in png.h 5 * Copyright (c) 1998-2010 Glenn Randers-Pehrson
6 * Copyright (c) 1998-2009 Glenn Randers-Pehrson
7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger) 6 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.) 7 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
8 *
9 * This code is released under the libpng license.
10 * For conditions of distribution and use, see the disclaimer
11 * and license in png.h
9 */ 12 */
10 13
11 /* Get internal access to png.h */ 14 /* Get internal access to png.h */
12 #define PNG_INTERNAL 15 #define PNG_INTERNAL
16 #define PNG_NO_PEDANTIC_WARNINGS
13 #include "png.h" 17 #include "png.h"
14 #ifdef PNG_WRITE_SUPPORTED 18 #ifdef PNG_WRITE_SUPPORTED
15 19
16 /* Writes all the PNG information. This is the suggested way to use the 20 /* Writes all the PNG information. This is the suggested way to use the
17 * library. If you have a new chunk to add, make a function to write it, 21 * library. If you have a new chunk to add, make a function to write it,
18 * and put it in the correct location here. If you want the chunk written 22 * and put it in the correct location here. If you want the chunk written
19 * after the image data, put it in png_write_end(). I strongly encourage 23 * after the image data, put it in png_write_end(). I strongly encourage
20 * you to supply a PNG_INFO_ flag, and check info_ptr->valid before writing 24 * you to supply a PNG_INFO_ flag, and check info_ptr->valid before writing
21 * the chunk, as that will keep the code from breaking if you want to just 25 * the chunk, as that will keep the code from breaking if you want to just
22 * write a plain PNG file. If you have long comments, I suggest writing 26 * write a plain PNG file. If you have long comments, I suggest writing
23 * them in png_write_end(), and compressing them. 27 * them in png_write_end(), and compressing them.
24 */ 28 */
25 void PNGAPI 29 void PNGAPI
26 png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr) 30 png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
27 { 31 {
28 png_debug(1, "in png_write_info_before_PLTE"); 32 png_debug(1, "in png_write_info_before_PLTE");
33
29 if (png_ptr == NULL || info_ptr == NULL) 34 if (png_ptr == NULL || info_ptr == NULL)
30 return; 35 return;
31 if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) 36 if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
32 { 37 {
33 png_write_sig(png_ptr); /* Write PNG signature */ 38 /* Write PNG signature */
34 #if defined(PNG_MNG_FEATURES_SUPPORTED) 39 png_write_sig(png_ptr);
35 if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted) ) 40 #ifdef PNG_MNG_FEATURES_SUPPORTED
41 if ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) && \
42 (png_ptr->mng_features_permitted))
36 { 43 {
37 png_warning(png_ptr, "MNG features are not allowed in a PNG datastream"); 44 png_warning(png_ptr, "MNG features are not allowed in a PNG datastream");
38 png_ptr->mng_features_permitted=0; 45 png_ptr->mng_features_permitted = 0;
39 } 46 }
40 #endif 47 #endif
41 /* Write IHDR information. */ 48 /* Write IHDR information. */
42 png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height, 49 png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
43 info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type, 50 info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
44 info_ptr->filter_type, 51 info_ptr->filter_type,
45 #if defined(PNG_WRITE_INTERLACING_SUPPORTED) 52 #ifdef PNG_WRITE_INTERLACING_SUPPORTED
46 info_ptr->interlace_type); 53 info_ptr->interlace_type);
47 #else 54 #else
48 0); 55 0);
49 #endif 56 #endif
50 /* The rest of these check to see if the valid field has the appropriate 57 /* The rest of these check to see if the valid field has the appropriate
51 * flag set, and if it does, writes the chunk. 58 * flag set, and if it does, writes the chunk.
52 */ 59 */
53 #if defined(PNG_WRITE_gAMA_SUPPORTED) 60 #ifdef PNG_WRITE_gAMA_SUPPORTED
54 if (info_ptr->valid & PNG_INFO_gAMA) 61 if (info_ptr->valid & PNG_INFO_gAMA)
55 { 62 {
56 # ifdef PNG_FLOATING_POINT_SUPPORTED 63 # ifdef PNG_FLOATING_POINT_SUPPORTED
57 png_write_gAMA(png_ptr, info_ptr->gamma); 64 png_write_gAMA(png_ptr, info_ptr->gamma);
58 #else 65 #else
59 #ifdef PNG_FIXED_POINT_SUPPORTED 66 #ifdef PNG_FIXED_POINT_SUPPORTED
60 png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma); 67 png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
61 # endif 68 # endif
62 #endif 69 #endif
63 } 70 }
64 #endif 71 #endif
65 #if defined(PNG_WRITE_sRGB_SUPPORTED) 72 #ifdef PNG_WRITE_sRGB_SUPPORTED
66 if (info_ptr->valid & PNG_INFO_sRGB) 73 if (info_ptr->valid & PNG_INFO_sRGB)
67 png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent); 74 png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
68 #endif 75 #endif
69 #if defined(PNG_WRITE_iCCP_SUPPORTED) 76 #ifdef PNG_WRITE_iCCP_SUPPORTED
70 if (info_ptr->valid & PNG_INFO_iCCP) 77 if (info_ptr->valid & PNG_INFO_iCCP)
71 png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE, 78 png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
72 info_ptr->iccp_profile, (int)info_ptr->iccp_proflen); 79 info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
73 #endif 80 #endif
74 #if defined(PNG_WRITE_sBIT_SUPPORTED) 81 #ifdef PNG_WRITE_sBIT_SUPPORTED
75 if (info_ptr->valid & PNG_INFO_sBIT) 82 if (info_ptr->valid & PNG_INFO_sBIT)
76 png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type); 83 png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
77 #endif 84 #endif
78 #if defined(PNG_WRITE_cHRM_SUPPORTED) 85 #ifdef PNG_WRITE_cHRM_SUPPORTED
79 if (info_ptr->valid & PNG_INFO_cHRM) 86 if (info_ptr->valid & PNG_INFO_cHRM)
80 { 87 {
81 #ifdef PNG_FLOATING_POINT_SUPPORTED 88 #ifdef PNG_FLOATING_POINT_SUPPORTED
82 png_write_cHRM(png_ptr, 89 png_write_cHRM(png_ptr,
83 info_ptr->x_white, info_ptr->y_white, 90 info_ptr->x_white, info_ptr->y_white,
84 info_ptr->x_red, info_ptr->y_red, 91 info_ptr->x_red, info_ptr->y_red,
85 info_ptr->x_green, info_ptr->y_green, 92 info_ptr->x_green, info_ptr->y_green,
86 info_ptr->x_blue, info_ptr->y_blue); 93 info_ptr->x_blue, info_ptr->y_blue);
87 #else 94 #else
88 # ifdef PNG_FIXED_POINT_SUPPORTED 95 # ifdef PNG_FIXED_POINT_SUPPORTED
89 png_write_cHRM_fixed(png_ptr, 96 png_write_cHRM_fixed(png_ptr,
90 info_ptr->int_x_white, info_ptr->int_y_white, 97 info_ptr->int_x_white, info_ptr->int_y_white,
91 info_ptr->int_x_red, info_ptr->int_y_red, 98 info_ptr->int_x_red, info_ptr->int_y_red,
92 info_ptr->int_x_green, info_ptr->int_y_green, 99 info_ptr->int_x_green, info_ptr->int_y_green,
93 info_ptr->int_x_blue, info_ptr->int_y_blue); 100 info_ptr->int_x_blue, info_ptr->int_y_blue);
94 # endif 101 # endif
95 #endif 102 #endif
96 } 103 }
97 #endif 104 #endif
98 #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) 105 #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
99 if (info_ptr->unknown_chunks_num) 106 if (info_ptr->unknown_chunks_num)
100 { 107 {
101 png_unknown_chunk *up; 108 png_unknown_chunk *up;
102 109
103 png_debug(5, "writing extra chunks"); 110 png_debug(5, "writing extra chunks");
104 111
105 for (up = info_ptr->unknown_chunks; 112 for (up = info_ptr->unknown_chunks;
106 up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; 113 up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
107 up++) 114 up++)
108 { 115 {
109 int keep=png_handle_as_unknown(png_ptr, up->name); 116 int keep = png_handle_as_unknown(png_ptr, up->name);
110 if (keep != PNG_HANDLE_CHUNK_NEVER && 117 if (keep != PNG_HANDLE_CHUNK_NEVER &&
111 up->location && !(up->location & PNG_HAVE_PLTE) && 118 up->location && !(up->location & PNG_HAVE_PLTE) &&
112 !(up->location & PNG_HAVE_IDAT) && 119 !(up->location & PNG_HAVE_IDAT) &&
113 ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || 120 ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
114 (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) 121 (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
115 { 122 {
116 if (up->size == 0) 123 if (up->size == 0)
117 png_warning(png_ptr, "Writing zero-length unknown chunk"); 124 png_warning(png_ptr, "Writing zero-length unknown chunk");
118 png_write_chunk(png_ptr, up->name, up->data, up->size); 125 png_write_chunk(png_ptr, up->name, up->data, up->size);
119 } 126 }
(...skipping 17 matching lines...) Expand all
137 return; 144 return;
138 145
139 png_write_info_before_PLTE(png_ptr, info_ptr); 146 png_write_info_before_PLTE(png_ptr, info_ptr);
140 147
141 if (info_ptr->valid & PNG_INFO_PLTE) 148 if (info_ptr->valid & PNG_INFO_PLTE)
142 png_write_PLTE(png_ptr, info_ptr->palette, 149 png_write_PLTE(png_ptr, info_ptr->palette,
143 (png_uint_32)info_ptr->num_palette); 150 (png_uint_32)info_ptr->num_palette);
144 else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 151 else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
145 png_error(png_ptr, "Valid palette required for paletted images"); 152 png_error(png_ptr, "Valid palette required for paletted images");
146 153
147 #if defined(PNG_WRITE_tRNS_SUPPORTED) 154 #ifdef PNG_WRITE_tRNS_SUPPORTED
148 if (info_ptr->valid & PNG_INFO_tRNS) 155 if (info_ptr->valid & PNG_INFO_tRNS)
149 { 156 {
150 #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED) 157 #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
151 /* Invert the alpha channel (in tRNS) */ 158 /* Invert the alpha channel (in tRNS) */
152 if ((png_ptr->transformations & PNG_INVERT_ALPHA) && 159 if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
153 info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) 160 info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
154 { 161 {
155 int j; 162 int j;
156 for (j=0; j<(int)info_ptr->num_trans; j++) 163 for (j = 0; j<(int)info_ptr->num_trans; j++)
157 info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]); 164 info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
158 } 165 }
159 #endif 166 #endif
160 png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values), 167 png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
161 info_ptr->num_trans, info_ptr->color_type); 168 info_ptr->num_trans, info_ptr->color_type);
162 } 169 }
163 #endif 170 #endif
164 #if defined(PNG_WRITE_bKGD_SUPPORTED) 171 #ifdef PNG_WRITE_bKGD_SUPPORTED
165 if (info_ptr->valid & PNG_INFO_bKGD) 172 if (info_ptr->valid & PNG_INFO_bKGD)
166 png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type); 173 png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
167 #endif 174 #endif
168 #if defined(PNG_WRITE_hIST_SUPPORTED) 175 #ifdef PNG_WRITE_hIST_SUPPORTED
169 if (info_ptr->valid & PNG_INFO_hIST) 176 if (info_ptr->valid & PNG_INFO_hIST)
170 png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette); 177 png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
171 #endif 178 #endif
172 #if defined(PNG_WRITE_oFFs_SUPPORTED) 179 #ifdef PNG_WRITE_oFFs_SUPPORTED
173 if (info_ptr->valid & PNG_INFO_oFFs) 180 if (info_ptr->valid & PNG_INFO_oFFs)
174 png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset, 181 png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
175 info_ptr->offset_unit_type); 182 info_ptr->offset_unit_type);
176 #endif 183 #endif
177 #if defined(PNG_WRITE_pCAL_SUPPORTED) 184 #ifdef PNG_WRITE_pCAL_SUPPORTED
178 if (info_ptr->valid & PNG_INFO_pCAL) 185 if (info_ptr->valid & PNG_INFO_pCAL)
179 png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0, 186 png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
180 info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams, 187 info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
181 info_ptr->pcal_units, info_ptr->pcal_params); 188 info_ptr->pcal_units, info_ptr->pcal_params);
182 #endif 189 #endif
183 190
184 #if defined(PNG_sCAL_SUPPORTED) 191 #ifdef PNG_sCAL_SUPPORTED
185 if (info_ptr->valid & PNG_INFO_sCAL) 192 if (info_ptr->valid & PNG_INFO_sCAL)
186 #if defined(PNG_WRITE_sCAL_SUPPORTED) 193 #ifdef PNG_WRITE_sCAL_SUPPORTED
187 #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO) 194 #if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_STDIO_SUPPORTED)
188 png_write_sCAL(png_ptr, (int)info_ptr->scal_unit, 195 png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
189 info_ptr->scal_pixel_width, info_ptr->scal_pixel_height); 196 info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
190 #else /* !FLOATING_POINT */ 197 #else /* !FLOATING_POINT */
191 #ifdef PNG_FIXED_POINT_SUPPORTED 198 #ifdef PNG_FIXED_POINT_SUPPORTED
192 png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit, 199 png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
193 info_ptr->scal_s_width, info_ptr->scal_s_height); 200 info_ptr->scal_s_width, info_ptr->scal_s_height);
194 #endif /* FIXED_POINT */ 201 #endif /* FIXED_POINT */
195 #endif /* FLOATING_POINT */ 202 #endif /* FLOATING_POINT */
196 #else /* !WRITE_sCAL */ 203 #else /* !WRITE_sCAL */
197 png_warning(png_ptr, 204 png_warning(png_ptr,
198 "png_write_sCAL not supported; sCAL chunk not written."); 205 "png_write_sCAL not supported; sCAL chunk not written.");
199 #endif /* WRITE_sCAL */ 206 #endif /* WRITE_sCAL */
200 #endif /* sCAL */ 207 #endif /* sCAL */
201 208
202 #if defined(PNG_WRITE_pHYs_SUPPORTED) 209 #ifdef PNG_WRITE_pHYs_SUPPORTED
203 if (info_ptr->valid & PNG_INFO_pHYs) 210 if (info_ptr->valid & PNG_INFO_pHYs)
204 png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit, 211 png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
205 info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type); 212 info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
206 #endif /* pHYs */ 213 #endif /* pHYs */
207 214
208 #if defined(PNG_WRITE_tIME_SUPPORTED) 215 #ifdef PNG_WRITE_tIME_SUPPORTED
209 if (info_ptr->valid & PNG_INFO_tIME) 216 if (info_ptr->valid & PNG_INFO_tIME)
210 { 217 {
211 png_write_tIME(png_ptr, &(info_ptr->mod_time)); 218 png_write_tIME(png_ptr, &(info_ptr->mod_time));
212 png_ptr->mode |= PNG_WROTE_tIME; 219 png_ptr->mode |= PNG_WROTE_tIME;
213 } 220 }
214 #endif /* tIME */ 221 #endif /* tIME */
215 222
216 #if defined(PNG_WRITE_sPLT_SUPPORTED) 223 #ifdef PNG_WRITE_sPLT_SUPPORTED
217 if (info_ptr->valid & PNG_INFO_sPLT) 224 if (info_ptr->valid & PNG_INFO_sPLT)
218 for (i = 0; i < (int)info_ptr->splt_palettes_num; i++) 225 for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
219 png_write_sPLT(png_ptr, info_ptr->splt_palettes + i); 226 png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
220 #endif /* sPLT */ 227 #endif /* sPLT */
221 228
222 #if defined(PNG_WRITE_TEXT_SUPPORTED) 229 #ifdef PNG_WRITE_TEXT_SUPPORTED
223 /* Check to see if we need to write text chunks */ 230 /* Check to see if we need to write text chunks */
224 for (i = 0; i < info_ptr->num_text; i++) 231 for (i = 0; i < info_ptr->num_text; i++)
225 { 232 {
226 png_debug2(2, "Writing header text chunk %d, type %d", i, 233 png_debug2(2, "Writing header text chunk %d, type %d", i,
227 info_ptr->text[i].compression); 234 info_ptr->text[i].compression);
228 /* An internationalized chunk? */ 235 /* An internationalized chunk? */
229 if (info_ptr->text[i].compression > 0) 236 if (info_ptr->text[i].compression > 0)
230 { 237 {
231 #if defined(PNG_WRITE_iTXt_SUPPORTED) 238 #ifdef PNG_WRITE_iTXt_SUPPORTED
232 /* Write international chunk */ 239 /* Write international chunk */
233 png_write_iTXt(png_ptr, 240 png_write_iTXt(png_ptr,
234 info_ptr->text[i].compression, 241 info_ptr->text[i].compression,
235 info_ptr->text[i].key, 242 info_ptr->text[i].key,
236 info_ptr->text[i].lang, 243 info_ptr->text[i].lang,
237 info_ptr->text[i].lang_key, 244 info_ptr->text[i].lang_key,
238 info_ptr->text[i].text); 245 info_ptr->text[i].text);
239 #else 246 #else
240 png_warning(png_ptr, "Unable to write international text"); 247 png_warning(png_ptr, "Unable to write international text");
241 #endif 248 #endif
242 /* Mark this chunk as written */ 249 /* Mark this chunk as written */
243 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; 250 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
244 } 251 }
245 /* If we want a compressed text chunk */ 252 /* If we want a compressed text chunk */
246 else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt) 253 else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
247 { 254 {
248 #if defined(PNG_WRITE_zTXt_SUPPORTED) 255 #ifdef PNG_WRITE_zTXt_SUPPORTED
249 /* Write compressed chunk */ 256 /* Write compressed chunk */
250 png_write_zTXt(png_ptr, info_ptr->text[i].key, 257 png_write_zTXt(png_ptr, info_ptr->text[i].key,
251 info_ptr->text[i].text, 0, 258 info_ptr->text[i].text, 0,
252 info_ptr->text[i].compression); 259 info_ptr->text[i].compression);
253 #else 260 #else
254 png_warning(png_ptr, "Unable to write compressed text"); 261 png_warning(png_ptr, "Unable to write compressed text");
255 #endif 262 #endif
256 /* Mark this chunk as written */ 263 /* Mark this chunk as written */
257 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; 264 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
258 } 265 }
259 else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) 266 else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
260 { 267 {
261 #if defined(PNG_WRITE_tEXt_SUPPORTED) 268 #ifdef PNG_WRITE_tEXt_SUPPORTED
262 /* Write uncompressed chunk */ 269 /* Write uncompressed chunk */
263 png_write_tEXt(png_ptr, info_ptr->text[i].key, 270 png_write_tEXt(png_ptr, info_ptr->text[i].key,
264 info_ptr->text[i].text, 271 info_ptr->text[i].text,
265 0); 272 0);
266 /* Mark this chunk as written */ 273 /* Mark this chunk as written */
267 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; 274 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
268 #else 275 #else
269 /* Can't get here */ 276 /* Can't get here */
270 png_warning(png_ptr, "Unable to write uncompressed text"); 277 png_warning(png_ptr, "Unable to write uncompressed text");
271 #endif 278 #endif
272 } 279 }
273 } 280 }
274 #endif /* tEXt */ 281 #endif /* tEXt */
275 282
276 #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) 283 #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
277 if (info_ptr->unknown_chunks_num) 284 if (info_ptr->unknown_chunks_num)
278 { 285 {
279 png_unknown_chunk *up; 286 png_unknown_chunk *up;
280 287
281 png_debug(5, "writing extra chunks"); 288 png_debug(5, "writing extra chunks");
282 289
283 for (up = info_ptr->unknown_chunks; 290 for (up = info_ptr->unknown_chunks;
284 up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; 291 up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
285 up++) 292 up++)
286 { 293 {
287 int keep=png_handle_as_unknown(png_ptr, up->name); 294 int keep = png_handle_as_unknown(png_ptr, up->name);
288 if (keep != PNG_HANDLE_CHUNK_NEVER && 295 if (keep != PNG_HANDLE_CHUNK_NEVER &&
289 up->location && (up->location & PNG_HAVE_PLTE) && 296 up->location && (up->location & PNG_HAVE_PLTE) &&
290 !(up->location & PNG_HAVE_IDAT) && 297 !(up->location & PNG_HAVE_IDAT) &&
291 ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || 298 ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
292 (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) 299 (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
293 { 300 {
294 png_write_chunk(png_ptr, up->name, up->data, up->size); 301 png_write_chunk(png_ptr, up->name, up->data, up->size);
295 } 302 }
296 } 303 }
297 } 304 }
298 #endif 305 #endif
299 } 306 }
300 307
301 /* Writes the end of the PNG file. If you don't want to write comments or 308 /* Writes the end of the PNG file. If you don't want to write comments or
302 * time information, you can pass NULL for info. If you already wrote these 309 * time information, you can pass NULL for info. If you already wrote these
303 * in png_write_info(), do not write them again here. If you have long 310 * in png_write_info(), do not write them again here. If you have long
304 * comments, I suggest writing them here, and compressing them. 311 * comments, I suggest writing them here, and compressing them.
305 */ 312 */
306 void PNGAPI 313 void PNGAPI
307 png_write_end(png_structp png_ptr, png_infop info_ptr) 314 png_write_end(png_structp png_ptr, png_infop info_ptr)
308 { 315 {
309 png_debug(1, "in png_write_end"); 316 png_debug(1, "in png_write_end");
317
310 if (png_ptr == NULL) 318 if (png_ptr == NULL)
311 return; 319 return;
312 if (!(png_ptr->mode & PNG_HAVE_IDAT)) 320 if (!(png_ptr->mode & PNG_HAVE_IDAT))
313 png_error(png_ptr, "No IDATs written into file"); 321 png_error(png_ptr, "No IDATs written into file");
314 322
315 /* See if user wants us to write information chunks */ 323 /* See if user wants us to write information chunks */
316 if (info_ptr != NULL) 324 if (info_ptr != NULL)
317 { 325 {
318 #if defined(PNG_WRITE_TEXT_SUPPORTED) 326 #ifdef PNG_WRITE_TEXT_SUPPORTED
319 int i; /* Local index variable */ 327 int i; /* local index variable */
320 #endif 328 #endif
321 #if defined(PNG_WRITE_tIME_SUPPORTED) 329 #ifdef PNG_WRITE_tIME_SUPPORTED
322 /* Check to see if user has supplied a time chunk */ 330 /* Check to see if user has supplied a time chunk */
323 if ((info_ptr->valid & PNG_INFO_tIME) && 331 if ((info_ptr->valid & PNG_INFO_tIME) &&
324 !(png_ptr->mode & PNG_WROTE_tIME)) 332 !(png_ptr->mode & PNG_WROTE_tIME))
325 png_write_tIME(png_ptr, &(info_ptr->mod_time)); 333 png_write_tIME(png_ptr, &(info_ptr->mod_time));
326 #endif 334 #endif
327 #if defined(PNG_WRITE_TEXT_SUPPORTED) 335 #ifdef PNG_WRITE_TEXT_SUPPORTED
328 /* Loop through comment chunks */ 336 /* Loop through comment chunks */
329 for (i = 0; i < info_ptr->num_text; i++) 337 for (i = 0; i < info_ptr->num_text; i++)
330 { 338 {
331 png_debug2(2, "Writing trailer text chunk %d, type %d", i, 339 png_debug2(2, "Writing trailer text chunk %d, type %d", i,
332 info_ptr->text[i].compression); 340 info_ptr->text[i].compression);
333 /* An internationalized chunk? */ 341 /* An internationalized chunk? */
334 if (info_ptr->text[i].compression > 0) 342 if (info_ptr->text[i].compression > 0)
335 { 343 {
336 #if defined(PNG_WRITE_iTXt_SUPPORTED) 344 #ifdef PNG_WRITE_iTXt_SUPPORTED
337 /* Write international chunk */ 345 /* Write international chunk */
338 png_write_iTXt(png_ptr, 346 png_write_iTXt(png_ptr,
339 info_ptr->text[i].compression, 347 info_ptr->text[i].compression,
340 info_ptr->text[i].key, 348 info_ptr->text[i].key,
341 info_ptr->text[i].lang, 349 info_ptr->text[i].lang,
342 info_ptr->text[i].lang_key, 350 info_ptr->text[i].lang_key,
343 info_ptr->text[i].text); 351 info_ptr->text[i].text);
344 #else 352 #else
345 png_warning(png_ptr, "Unable to write international text"); 353 png_warning(png_ptr, "Unable to write international text");
346 #endif 354 #endif
347 /* Mark this chunk as written */ 355 /* Mark this chunk as written */
348 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; 356 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
349 } 357 }
350 else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt) 358 else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
351 { 359 {
352 #if defined(PNG_WRITE_zTXt_SUPPORTED) 360 #ifdef PNG_WRITE_zTXt_SUPPORTED
353 /* Write compressed chunk */ 361 /* Write compressed chunk */
354 png_write_zTXt(png_ptr, info_ptr->text[i].key, 362 png_write_zTXt(png_ptr, info_ptr->text[i].key,
355 info_ptr->text[i].text, 0, 363 info_ptr->text[i].text, 0,
356 info_ptr->text[i].compression); 364 info_ptr->text[i].compression);
357 #else 365 #else
358 png_warning(png_ptr, "Unable to write compressed text"); 366 png_warning(png_ptr, "Unable to write compressed text");
359 #endif 367 #endif
360 /* Mark this chunk as written */ 368 /* Mark this chunk as written */
361 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR; 369 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
362 } 370 }
363 else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE) 371 else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
364 { 372 {
365 #if defined(PNG_WRITE_tEXt_SUPPORTED) 373 #ifdef PNG_WRITE_tEXt_SUPPORTED
366 /* Write uncompressed chunk */ 374 /* Write uncompressed chunk */
367 png_write_tEXt(png_ptr, info_ptr->text[i].key, 375 png_write_tEXt(png_ptr, info_ptr->text[i].key,
368 info_ptr->text[i].text, 0); 376 info_ptr->text[i].text, 0);
369 #else 377 #else
370 png_warning(png_ptr, "Unable to write uncompressed text"); 378 png_warning(png_ptr, "Unable to write uncompressed text");
371 #endif 379 #endif
372 380
373 /* Mark this chunk as written */ 381 /* Mark this chunk as written */
374 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR; 382 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
375 } 383 }
376 } 384 }
377 #endif 385 #endif
378 #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) 386 #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
379 if (info_ptr->unknown_chunks_num) 387 if (info_ptr->unknown_chunks_num)
380 { 388 {
381 png_unknown_chunk *up; 389 png_unknown_chunk *up;
382 390
383 png_debug(5, "writing extra chunks"); 391 png_debug(5, "writing extra chunks");
384 392
385 for (up = info_ptr->unknown_chunks; 393 for (up = info_ptr->unknown_chunks;
386 up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num; 394 up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
387 up++) 395 up++)
388 { 396 {
389 int keep=png_handle_as_unknown(png_ptr, up->name); 397 int keep = png_handle_as_unknown(png_ptr, up->name);
390 if (keep != PNG_HANDLE_CHUNK_NEVER && 398 if (keep != PNG_HANDLE_CHUNK_NEVER &&
391 up->location && (up->location & PNG_AFTER_IDAT) && 399 up->location && (up->location & PNG_AFTER_IDAT) &&
392 ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS || 400 ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
393 (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS))) 401 (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
394 { 402 {
395 png_write_chunk(png_ptr, up->name, up->data, up->size); 403 png_write_chunk(png_ptr, up->name, up->data, up->size);
396 } 404 }
397 } 405 }
398 } 406 }
399 #endif 407 #endif
400 } 408 }
401 409
402 png_ptr->mode |= PNG_AFTER_IDAT; 410 png_ptr->mode |= PNG_AFTER_IDAT;
403 411
404 /* Write end of PNG file */ 412 /* Write end of PNG file */
405 png_write_IEND(png_ptr); 413 png_write_IEND(png_ptr);
406 /* This flush, added in libpng-1.0.8, removed from libpng-1.0.9beta03, 414 /* This flush, added in libpng-1.0.8, removed from libpng-1.0.9beta03,
407 * and restored again in libpng-1.2.30, may cause some applications that 415 * and restored again in libpng-1.2.30, may cause some applications that
408 * do not set png_ptr->output_flush_fn to crash. If your application 416 * do not set png_ptr->output_flush_fn to crash. If your application
409 * experiences a problem, please try building libpng with 417 * experiences a problem, please try building libpng with
410 * PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to 418 * PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to
411 * png-mng-implement at lists.sf.net . This kludge will be removed 419 * png-mng-implement at lists.sf.net .
412 * from libpng-1.4.0.
413 */ 420 */
414 #if defined(PNG_WRITE_FLUSH_SUPPORTED) && \ 421 #ifdef PNG_WRITE_FLUSH_SUPPORTED
415 defined(PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED) 422 # ifdef PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED
416 png_flush(png_ptr); 423 png_flush(png_ptr);
424 # endif
417 #endif 425 #endif
418 } 426 }
419 427
420 #if defined(PNG_WRITE_tIME_SUPPORTED) 428 #ifdef PNG_CONVERT_tIME_SUPPORTED
421 #if !defined(_WIN32_WCE) 429 /* "tm" structure is not supported on WindowsCE */
422 /* "time.h" functions are not supported on WindowsCE */
423 void PNGAPI 430 void PNGAPI
424 png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime) 431 png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
425 { 432 {
426 png_debug(1, "in png_convert_from_struct_tm"); 433 png_debug(1, "in png_convert_from_struct_tm");
434
427 ptime->year = (png_uint_16)(1900 + ttime->tm_year); 435 ptime->year = (png_uint_16)(1900 + ttime->tm_year);
428 ptime->month = (png_byte)(ttime->tm_mon + 1); 436 ptime->month = (png_byte)(ttime->tm_mon + 1);
429 ptime->day = (png_byte)ttime->tm_mday; 437 ptime->day = (png_byte)ttime->tm_mday;
430 ptime->hour = (png_byte)ttime->tm_hour; 438 ptime->hour = (png_byte)ttime->tm_hour;
431 ptime->minute = (png_byte)ttime->tm_min; 439 ptime->minute = (png_byte)ttime->tm_min;
432 ptime->second = (png_byte)ttime->tm_sec; 440 ptime->second = (png_byte)ttime->tm_sec;
433 } 441 }
434 442
435 void PNGAPI 443 void PNGAPI
436 png_convert_from_time_t(png_timep ptime, time_t ttime) 444 png_convert_from_time_t(png_timep ptime, time_t ttime)
437 { 445 {
438 struct tm *tbuf; 446 struct tm *tbuf;
439 447
440 png_debug(1, "in png_convert_from_time_t"); 448 png_debug(1, "in png_convert_from_time_t");
449
441 tbuf = gmtime(&ttime); 450 tbuf = gmtime(&ttime);
442 png_convert_from_struct_tm(ptime, tbuf); 451 png_convert_from_struct_tm(ptime, tbuf);
443 } 452 }
444 #endif 453 #endif
445 #endif
446 454
447 /* Initialize png_ptr structure, and allocate any memory needed */ 455 /* Initialize png_ptr structure, and allocate any memory needed */
448 png_structp PNGAPI 456 png_structp PNGAPI
449 png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr, 457 png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
450 png_error_ptr error_fn, png_error_ptr warn_fn) 458 png_error_ptr error_fn, png_error_ptr warn_fn)
451 { 459 {
452 #ifdef PNG_USER_MEM_SUPPORTED 460 #ifdef PNG_USER_MEM_SUPPORTED
453 return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn, 461 return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
454 warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL)); 462 warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
455 } 463 }
456 464
457 /* Alternate initialize png_ptr structure, and allocate any memory needed */ 465 /* Alternate initialize png_ptr structure, and allocate any memory needed */
458 png_structp PNGAPI 466 png_structp PNGAPI
459 png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr, 467 png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
460 png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, 468 png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
461 png_malloc_ptr malloc_fn, png_free_ptr free_fn) 469 png_malloc_ptr malloc_fn, png_free_ptr free_fn)
462 { 470 {
463 #endif /* PNG_USER_MEM_SUPPORTED */ 471 #endif /* PNG_USER_MEM_SUPPORTED */
464 #ifdef PNG_SETJMP_SUPPORTED 472 #ifdef PNG_SETJMP_SUPPORTED
465 volatile 473 volatile
466 #endif 474 #endif
467 png_structp png_ptr; 475 png_structp png_ptr;
468 #ifdef PNG_SETJMP_SUPPORTED 476 #ifdef PNG_SETJMP_SUPPORTED
469 #ifdef USE_FAR_KEYWORD 477 #ifdef USE_FAR_KEYWORD
470 jmp_buf jmpbuf; 478 jmp_buf jmpbuf;
471 #endif 479 #endif
472 #endif 480 #endif
473 int i; 481 int i;
482
474 png_debug(1, "in png_create_write_struct"); 483 png_debug(1, "in png_create_write_struct");
484
475 #ifdef PNG_USER_MEM_SUPPORTED 485 #ifdef PNG_USER_MEM_SUPPORTED
476 png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG, 486 png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
477 (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr); 487 (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
478 #else 488 #else
479 png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); 489 png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
480 #endif /* PNG_USER_MEM_SUPPORTED */ 490 #endif /* PNG_USER_MEM_SUPPORTED */
481 if (png_ptr == NULL) 491 if (png_ptr == NULL)
482 return (NULL); 492 return (NULL);
483 493
484 /* Added at libpng-1.2.6 */ 494 /* Added at libpng-1.2.6 */
485 #ifdef PNG_SET_USER_LIMITS_SUPPORTED 495 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
486 png_ptr->user_width_max=PNG_USER_WIDTH_MAX; 496 png_ptr->user_width_max = PNG_USER_WIDTH_MAX;
487 png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; 497 png_ptr->user_height_max = PNG_USER_HEIGHT_MAX;
488 #endif 498 #endif
489 499
490 #ifdef PNG_SETJMP_SUPPORTED 500 #ifdef PNG_SETJMP_SUPPORTED
491 #ifdef USE_FAR_KEYWORD 501 #ifdef USE_FAR_KEYWORD
492 if (setjmp(jmpbuf)) 502 if (setjmp(jmpbuf))
493 #else 503 #else
494 if (setjmp(png_ptr->jmpbuf)) 504 if (setjmp(png_ptr->jmpbuf))
495 #endif 505 #endif
496 { 506 {
497 png_free(png_ptr, png_ptr->zbuf); 507 png_free(png_ptr, png_ptr->zbuf);
498 png_ptr->zbuf=NULL; 508 png_ptr->zbuf = NULL;
499 png_destroy_struct(png_ptr); 509 #ifdef PNG_USER_MEM_SUPPORTED
510 png_destroy_struct_2((png_voidp)png_ptr,
511 (png_free_ptr)free_fn, (png_voidp)mem_ptr);
512 #else
513 png_destroy_struct((png_voidp)png_ptr);
514 #endif
500 return (NULL); 515 return (NULL);
501 } 516 }
502 #ifdef USE_FAR_KEYWORD 517 #ifdef USE_FAR_KEYWORD
503 png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); 518 png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
504 #endif 519 #endif
505 #endif 520 #endif
506 521
507 #ifdef PNG_USER_MEM_SUPPORTED 522 #ifdef PNG_USER_MEM_SUPPORTED
508 png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn); 523 png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
509 #endif /* PNG_USER_MEM_SUPPORTED */ 524 #endif /* PNG_USER_MEM_SUPPORTED */
510 png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn); 525 png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
511 526
512 if (user_png_ver) 527 if (user_png_ver)
513 { 528 {
514 i=0; 529 i = 0;
515 do 530 do
516 { 531 {
517 if (user_png_ver[i] != png_libpng_ver[i]) 532 if (user_png_ver[i] != png_libpng_ver[i])
518 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; 533 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
519 } while (png_libpng_ver[i++]); 534 } while (png_libpng_ver[i++]);
520 } 535 }
521 536
522 if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) 537 if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
523 { 538 {
524 /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so 539 /* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
525 * we must recompile any applications that use any older library version. 540 * we must recompile any applications that use any older library version.
526 * For versions after libpng 1.0, we will be compatible, so we need 541 * For versions after libpng 1.0, we will be compatible, so we need
527 * only check the first digit. 542 * only check the first digit.
528 */ 543 */
529 if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] || 544 if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
530 (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) || 545 (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
531 (user_png_ver[0] == '0' && user_png_ver[2] < '9')) 546 (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
532 { 547 {
533 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) 548 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
534 char msg[80]; 549 char msg[80];
535 if (user_png_ver) 550 if (user_png_ver)
536 { 551 {
537 png_snprintf(msg, 80, 552 png_snprintf(msg, 80,
538 "Application was compiled with png.h from libpng-%.20s", 553 "Application was compiled with png.h from libpng-%.20s",
539 user_png_ver); 554 user_png_ver);
540 png_warning(png_ptr, msg); 555 png_warning(png_ptr, msg);
541 } 556 }
542 png_snprintf(msg, 80, 557 png_snprintf(msg, 80,
543 "Application is running with png.c from libpng-%.20s", 558 "Application is running with png.c from libpng-%.20s",
544 png_libpng_ver); 559 png_libpng_ver);
545 png_warning(png_ptr, msg); 560 png_warning(png_ptr, msg);
546 #endif 561 #endif
547 #ifdef PNG_ERROR_NUMBERS_SUPPORTED 562 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
548 png_ptr->flags=0; 563 png_ptr->flags = 0;
549 #endif 564 #endif
550 png_error(png_ptr, 565 png_error(png_ptr,
551 "Incompatible libpng version in application and library"); 566 "Incompatible libpng version in application and library");
552 } 567 }
553 } 568 }
554 569
555 /* Initialize zbuf - compression buffer */ 570 /* Initialize zbuf - compression buffer */
556 png_ptr->zbuf_size = PNG_ZBUF_SIZE; 571 png_ptr->zbuf_size = PNG_ZBUF_SIZE;
557 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, 572 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
558 (png_uint_32)png_ptr->zbuf_size); 573 (png_uint_32)png_ptr->zbuf_size);
559 574
560 png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL, 575 png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
561 png_flush_ptr_NULL); 576 png_flush_ptr_NULL);
562 577
563 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 578 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
564 png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, 579 png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
565 1, png_doublep_NULL, png_doublep_NULL); 580 1, png_doublep_NULL, png_doublep_NULL);
566 #endif 581 #endif
567 582
568 #ifdef PNG_SETJMP_SUPPORTED 583 #ifdef PNG_SETJMP_SUPPORTED
569 /* Applications that neglect to set up their own setjmp() and then encounter 584 /* Applications that neglect to set up their own setjmp() and then
570 a png_error() will longjmp here. Since the jmpbuf is then meaningless we 585 * encounter a png_error() will longjmp here. Since the jmpbuf is
571 abort instead of returning. */ 586 * then meaningless we abort instead of returning.
587 */
572 #ifdef USE_FAR_KEYWORD 588 #ifdef USE_FAR_KEYWORD
573 if (setjmp(jmpbuf)) 589 if (setjmp(jmpbuf))
574 PNG_ABORT(); 590 PNG_ABORT();
575 png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf)); 591 png_memcpy(png_ptr->jmpbuf, jmpbuf, png_sizeof(jmp_buf));
576 #else 592 #else
577 if (setjmp(png_ptr->jmpbuf)) 593 if (setjmp(png_ptr->jmpbuf))
578 PNG_ABORT(); 594 PNG_ABORT();
579 #endif 595 #endif
580 #endif 596 #endif
581 return (png_ptr); 597 return (png_ptr);
582 } 598 }
583 599
584 /* Initialize png_ptr structure, and allocate any memory needed */ 600 /* Initialize png_ptr structure, and allocate any memory needed */
585 #if defined(PNG_1_0_X) || defined(PNG_1_2_X) 601 #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
586 /* Deprecated. */ 602 /* Deprecated. */
587 #undef png_write_init 603 #undef png_write_init
588 void PNGAPI 604 void PNGAPI
589 png_write_init(png_structp png_ptr) 605 png_write_init(png_structp png_ptr)
590 { 606 {
591 /* We only come here via pre-1.0.7-compiled applications */ 607 /* We only come here via pre-1.0.7-compiled applications */
592 png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0); 608 png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
593 } 609 }
594 610
595 void PNGAPI 611 void PNGAPI
596 png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver, 612 png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
597 png_size_t png_struct_size, png_size_t png_info_size) 613 png_size_t png_struct_size, png_size_t png_info_size)
598 { 614 {
599 /* We only come here via pre-1.0.12-compiled applications */ 615 /* We only come here via pre-1.0.12-compiled applications */
600 if (png_ptr == NULL) return; 616 if (png_ptr == NULL) return;
601 #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE) 617 #if defined(PNG_STDIO_SUPPORTED) && !defined(_WIN32_WCE)
602 if (png_sizeof(png_struct) > png_struct_size || 618 if (png_sizeof(png_struct) > png_struct_size ||
603 png_sizeof(png_info) > png_info_size) 619 png_sizeof(png_info) > png_info_size)
604 { 620 {
605 char msg[80]; 621 char msg[80];
606 png_ptr->warning_fn=NULL; 622 png_ptr->warning_fn = NULL;
607 if (user_png_ver) 623 if (user_png_ver)
608 { 624 {
609 png_snprintf(msg, 80, 625 png_snprintf(msg, 80,
610 "Application was compiled with png.h from libpng-%.20s", 626 "Application was compiled with png.h from libpng-%.20s",
611 user_png_ver); 627 user_png_ver);
612 png_warning(png_ptr, msg); 628 png_warning(png_ptr, msg);
613 } 629 }
614 png_snprintf(msg, 80, 630 png_snprintf(msg, 80,
615 "Application is running with png.c from libpng-%.20s", 631 "Application is running with png.c from libpng-%.20s",
616 png_libpng_ver); 632 png_libpng_ver);
617 png_warning(png_ptr, msg); 633 png_warning(png_ptr, msg);
618 } 634 }
619 #endif 635 #endif
620 if (png_sizeof(png_struct) > png_struct_size) 636 if (png_sizeof(png_struct) > png_struct_size)
621 { 637 {
622 png_ptr->error_fn=NULL; 638 png_ptr->error_fn = NULL;
623 #ifdef PNG_ERROR_NUMBERS_SUPPORTED 639 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
624 png_ptr->flags=0; 640 png_ptr->flags = 0;
625 #endif 641 #endif
626 png_error(png_ptr, 642 png_error(png_ptr,
627 "The png struct allocated by the application for writing is too small."); 643 "The png struct allocated by the application for writing is"
628 } 644 " too small.");
645 }
629 if (png_sizeof(png_info) > png_info_size) 646 if (png_sizeof(png_info) > png_info_size)
630 { 647 {
631 png_ptr->error_fn=NULL; 648 png_ptr->error_fn = NULL;
632 #ifdef PNG_ERROR_NUMBERS_SUPPORTED 649 #ifdef PNG_ERROR_NUMBERS_SUPPORTED
633 png_ptr->flags=0; 650 png_ptr->flags = 0;
634 #endif 651 #endif
635 png_error(png_ptr, 652 png_error(png_ptr,
636 "The info struct allocated by the application for writing is too small.") ; 653 "The info struct allocated by the application for writing is"
637 } 654 " too small.");
655 }
638 png_write_init_3(&png_ptr, user_png_ver, png_struct_size); 656 png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
639 } 657 }
640 #endif /* PNG_1_0_X || PNG_1_2_X */ 658 #endif /* PNG_1_0_X || PNG_1_2_X */
641 659
642 660
643 void PNGAPI 661 void PNGAPI
644 png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver, 662 png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
645 png_size_t png_struct_size) 663 png_size_t png_struct_size)
646 { 664 {
647 png_structp png_ptr=*ptr_ptr; 665 png_structp png_ptr = *ptr_ptr;
648 #ifdef PNG_SETJMP_SUPPORTED 666 #ifdef PNG_SETJMP_SUPPORTED
649 jmp_buf tmp_jmp; /* To save current jump buffer */ 667 jmp_buf tmp_jmp; /* to save current jump buffer */
650 #endif 668 #endif
651 669
652 int i = 0; 670 int i = 0;
653 671
654 if (png_ptr == NULL) 672 if (png_ptr == NULL)
655 return; 673 return;
656 674
657 do 675 do
658 { 676 {
659 if (user_png_ver[i] != png_libpng_ver[i]) 677 if (user_png_ver[i] != png_libpng_ver[i])
660 { 678 {
661 #ifdef PNG_LEGACY_SUPPORTED 679 #ifdef PNG_LEGACY_SUPPORTED
662 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH; 680 png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
663 #else 681 #else
664 png_ptr->warning_fn=NULL; 682 png_ptr->warning_fn = NULL;
665 png_warning(png_ptr, 683 png_warning(png_ptr,
666 "Application uses deprecated png_write_init() and should be recompiled."); 684 "Application uses deprecated png_write_init() and should be recompiled.");
667 break;
668 #endif 685 #endif
669 } 686 }
670 } while (png_libpng_ver[i++]); 687 } while (png_libpng_ver[i++]);
671 688
672 png_debug(1, "in png_write_init_3"); 689 png_debug(1, "in png_write_init_3");
673 690
674 #ifdef PNG_SETJMP_SUPPORTED 691 #ifdef PNG_SETJMP_SUPPORTED
675 /* Save jump buffer and error functions */ 692 /* Save jump buffer and error functions */
676 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf)); 693 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
677 #endif 694 #endif
678 695
679 if (png_sizeof(png_struct) > png_struct_size) 696 if (png_sizeof(png_struct) > png_struct_size)
680 { 697 {
681 png_destroy_struct(png_ptr); 698 png_destroy_struct(png_ptr);
682 png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG); 699 png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
683 *ptr_ptr = png_ptr; 700 *ptr_ptr = png_ptr;
684 } 701 }
685 702
686 /* Reset all variables to 0 */ 703 /* Reset all variables to 0 */
687 png_memset(png_ptr, 0, png_sizeof(png_struct)); 704 png_memset(png_ptr, 0, png_sizeof(png_struct));
688 705
689 /* Added at libpng-1.2.6 */ 706 /* Added at libpng-1.2.6 */
690 #ifdef PNG_SET_USER_LIMITS_SUPPORTED 707 #ifdef PNG_SET_USER_LIMITS_SUPPORTED
691 png_ptr->user_width_max=PNG_USER_WIDTH_MAX; 708 png_ptr->user_width_max = PNG_USER_WIDTH_MAX;
692 png_ptr->user_height_max=PNG_USER_HEIGHT_MAX; 709 png_ptr->user_height_max = PNG_USER_HEIGHT_MAX;
693 #endif 710 #endif
694 711
695 #ifdef PNG_SETJMP_SUPPORTED 712 #ifdef PNG_SETJMP_SUPPORTED
696 /* Restore jump buffer */ 713 /* Restore jump buffer */
697 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf)); 714 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
698 #endif 715 #endif
699 716
700 png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL, 717 png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
701 png_flush_ptr_NULL); 718 png_flush_ptr_NULL);
702 719
703 /* Initialize zbuf - compression buffer */ 720 /* Initialize zbuf - compression buffer */
704 png_ptr->zbuf_size = PNG_ZBUF_SIZE; 721 png_ptr->zbuf_size = PNG_ZBUF_SIZE;
705 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, 722 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
706 (png_uint_32)png_ptr->zbuf_size); 723 (png_uint_32)png_ptr->zbuf_size);
707 724 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
708 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
709 png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT, 725 png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
710 1, png_doublep_NULL, png_doublep_NULL); 726 1, png_doublep_NULL, png_doublep_NULL);
711 #endif 727 #endif
712 } 728 }
713 729
714 /* Write a few rows of image data. If the image is interlaced, 730 /* Write a few rows of image data. If the image is interlaced,
715 * either you will have to write the 7 sub images, or, if you 731 * either you will have to write the 7 sub images, or, if you
716 * have called png_set_interlace_handling(), you will have to 732 * have called png_set_interlace_handling(), you will have to
717 * "write" the image seven times. 733 * "write" the image seven times.
718 */ 734 */
719 void PNGAPI 735 void PNGAPI
720 png_write_rows(png_structp png_ptr, png_bytepp row, 736 png_write_rows(png_structp png_ptr, png_bytepp row,
721 png_uint_32 num_rows) 737 png_uint_32 num_rows)
722 { 738 {
723 png_uint_32 i; /* Row counter */ 739 png_uint_32 i; /* row counter */
724 png_bytepp rp; /* Row pointer */ 740 png_bytepp rp; /* row pointer */
725 741
726 png_debug(1, "in png_write_rows"); 742 png_debug(1, "in png_write_rows");
727 743
728 if (png_ptr == NULL) 744 if (png_ptr == NULL)
729 return; 745 return;
730 746
731 /* Loop through the rows */ 747 /* Loop through the rows */
732 for (i = 0, rp = row; i < num_rows; i++, rp++) 748 for (i = 0, rp = row; i < num_rows; i++, rp++)
733 { 749 {
734 png_write_row(png_ptr, *rp); 750 png_write_row(png_ptr, *rp);
735 } 751 }
736 } 752 }
737 753
738 /* Write the image. You only need to call this function once, even 754 /* Write the image. You only need to call this function once, even
739 * if you are writing an interlaced image. 755 * if you are writing an interlaced image.
740 */ 756 */
741 void PNGAPI 757 void PNGAPI
742 png_write_image(png_structp png_ptr, png_bytepp image) 758 png_write_image(png_structp png_ptr, png_bytepp image)
743 { 759 {
744 png_uint_32 i; /* Row index */ 760 png_uint_32 i; /* row index */
745 int pass, num_pass; /* Pass variables */ 761 int pass, num_pass; /* pass variables */
746 png_bytepp rp; /* Points to current row */ 762 png_bytepp rp; /* points to current row */
747 763
748 if (png_ptr == NULL) 764 if (png_ptr == NULL)
749 return; 765 return;
750 766
751 png_debug(1, "in png_write_image"); 767 png_debug(1, "in png_write_image");
752 #if defined(PNG_WRITE_INTERLACING_SUPPORTED) 768
769 #ifdef PNG_WRITE_INTERLACING_SUPPORTED
753 /* Initialize interlace handling. If image is not interlaced, 770 /* Initialize interlace handling. If image is not interlaced,
754 * this will set pass to 1 771 * this will set pass to 1
755 */ 772 */
756 num_pass = png_set_interlace_handling(png_ptr); 773 num_pass = png_set_interlace_handling(png_ptr);
757 #else 774 #else
758 num_pass = 1; 775 num_pass = 1;
759 #endif 776 #endif
760 /* Loop through passes */ 777 /* Loop through passes */
761 for (pass = 0; pass < num_pass; pass++) 778 for (pass = 0; pass < num_pass; pass++)
762 { 779 {
763 /* Loop through image */ 780 /* Loop through image */
764 for (i = 0, rp = image; i < png_ptr->height; i++, rp++) 781 for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
765 { 782 {
766 png_write_row(png_ptr, *rp); 783 png_write_row(png_ptr, *rp);
767 } 784 }
768 } 785 }
769 } 786 }
770 787
771 /* Called by user to write a row of image data */ 788 /* Called by user to write a row of image data */
772 void PNGAPI 789 void PNGAPI
773 png_write_row(png_structp png_ptr, png_bytep row) 790 png_write_row(png_structp png_ptr, png_bytep row)
774 { 791 {
775 if (png_ptr == NULL) 792 if (png_ptr == NULL)
776 return; 793 return;
794
777 png_debug2(1, "in png_write_row (row %ld, pass %d)", 795 png_debug2(1, "in png_write_row (row %ld, pass %d)",
778 png_ptr->row_number, png_ptr->pass); 796 png_ptr->row_number, png_ptr->pass);
779 797
780 /* Initialize transformations and other stuff if first time */ 798 /* Initialize transformations and other stuff if first time */
781 if (png_ptr->row_number == 0 && png_ptr->pass == 0) 799 if (png_ptr->row_number == 0 && png_ptr->pass == 0)
782 { 800 {
783 /* Make sure we wrote the header info */ 801 /* Make sure we wrote the header info */
784 if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE)) 802 if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
785 png_error(png_ptr, 803 png_error(png_ptr,
786 "png_write_info was never called before png_write_row."); 804 "png_write_info was never called before png_write_row.");
787 805
788 /* Check for transforms that have been set but were defined out */ 806 /* Check for transforms that have been set but were defined out */
789 #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED) 807 #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
790 if (png_ptr->transformations & PNG_INVERT_MONO) 808 if (png_ptr->transformations & PNG_INVERT_MONO)
791 png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined."); 809 png_warning(png_ptr,
810 "PNG_WRITE_INVERT_SUPPORTED is not defined.");
792 #endif 811 #endif
793 #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED) 812 #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
794 if (png_ptr->transformations & PNG_FILLER) 813 if (png_ptr->transformations & PNG_FILLER)
795 png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined."); 814 png_warning(png_ptr,
815 "PNG_WRITE_FILLER_SUPPORTED is not defined.");
796 #endif 816 #endif
797 #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTE D) 817 #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \
818 defined(PNG_READ_PACKSWAP_SUPPORTED)
798 if (png_ptr->transformations & PNG_PACKSWAP) 819 if (png_ptr->transformations & PNG_PACKSWAP)
799 png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined."); 820 png_warning(png_ptr,
821 "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
800 #endif 822 #endif
801 #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED) 823 #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
802 if (png_ptr->transformations & PNG_PACK) 824 if (png_ptr->transformations & PNG_PACK)
803 png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined."); 825 png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
804 #endif 826 #endif
805 #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED) 827 #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
806 if (png_ptr->transformations & PNG_SHIFT) 828 if (png_ptr->transformations & PNG_SHIFT)
807 png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined."); 829 png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
808 #endif 830 #endif
809 #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED) 831 #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
810 if (png_ptr->transformations & PNG_BGR) 832 if (png_ptr->transformations & PNG_BGR)
811 png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined."); 833 png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
812 #endif 834 #endif
813 #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED) 835 #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
814 if (png_ptr->transformations & PNG_SWAP_BYTES) 836 if (png_ptr->transformations & PNG_SWAP_BYTES)
815 png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined."); 837 png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
816 #endif 838 #endif
817 839
818 png_write_start_row(png_ptr); 840 png_write_start_row(png_ptr);
819 } 841 }
820 842
821 #if defined(PNG_WRITE_INTERLACING_SUPPORTED) 843 #ifdef PNG_WRITE_INTERLACING_SUPPORTED
822 /* If interlaced and not interested in row, return */ 844 /* If interlaced and not interested in row, return */
823 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE)) 845 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
824 { 846 {
825 switch (png_ptr->pass) 847 switch (png_ptr->pass)
826 { 848 {
827 case 0: 849 case 0:
828 if (png_ptr->row_number & 0x07) 850 if (png_ptr->row_number & 0x07)
829 { 851 {
830 png_write_finish_row(png_ptr); 852 png_write_finish_row(png_ptr);
831 return; 853 return;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 png_debug1(3, "row_info->width = %lu", png_ptr->row_info.width); 914 png_debug1(3, "row_info->width = %lu", png_ptr->row_info.width);
893 png_debug1(3, "row_info->channels = %d", png_ptr->row_info.channels); 915 png_debug1(3, "row_info->channels = %d", png_ptr->row_info.channels);
894 png_debug1(3, "row_info->bit_depth = %d", png_ptr->row_info.bit_depth); 916 png_debug1(3, "row_info->bit_depth = %d", png_ptr->row_info.bit_depth);
895 png_debug1(3, "row_info->pixel_depth = %d", png_ptr->row_info.pixel_depth); 917 png_debug1(3, "row_info->pixel_depth = %d", png_ptr->row_info.pixel_depth);
896 png_debug1(3, "row_info->rowbytes = %lu", png_ptr->row_info.rowbytes); 918 png_debug1(3, "row_info->rowbytes = %lu", png_ptr->row_info.rowbytes);
897 919
898 /* Copy user's row into buffer, leaving room for filter byte. */ 920 /* Copy user's row into buffer, leaving room for filter byte. */
899 png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row, 921 png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
900 png_ptr->row_info.rowbytes); 922 png_ptr->row_info.rowbytes);
901 923
902 #if defined(PNG_WRITE_INTERLACING_SUPPORTED) 924 #ifdef PNG_WRITE_INTERLACING_SUPPORTED
903 /* Handle interlacing */ 925 /* Handle interlacing */
904 if (png_ptr->interlaced && png_ptr->pass < 6 && 926 if (png_ptr->interlaced && png_ptr->pass < 6 &&
905 (png_ptr->transformations & PNG_INTERLACE)) 927 (png_ptr->transformations & PNG_INTERLACE))
906 { 928 {
907 png_do_write_interlace(&(png_ptr->row_info), 929 png_do_write_interlace(&(png_ptr->row_info),
908 png_ptr->row_buf + 1, png_ptr->pass); 930 png_ptr->row_buf + 1, png_ptr->pass);
909 /* This should always get caught above, but still ... */ 931 /* This should always get caught above, but still ... */
910 if (!(png_ptr->row_info.width)) 932 if (!(png_ptr->row_info.width))
911 { 933 {
912 png_write_finish_row(png_ptr); 934 png_write_finish_row(png_ptr);
913 return; 935 return;
914 } 936 }
915 } 937 }
916 #endif 938 #endif
917 939
918 /* Handle other transformations */ 940 /* Handle other transformations */
919 if (png_ptr->transformations) 941 if (png_ptr->transformations)
920 png_do_write_transformations(png_ptr); 942 png_do_write_transformations(png_ptr);
921 943
922 #if defined(PNG_MNG_FEATURES_SUPPORTED) 944 #ifdef PNG_MNG_FEATURES_SUPPORTED
923 /* Write filter_method 64 (intrapixel differencing) only if 945 /* Write filter_method 64 (intrapixel differencing) only if
924 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and 946 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
925 * 2. Libpng did not write a PNG signature (this filter_method is only 947 * 2. Libpng did not write a PNG signature (this filter_method is only
926 * used in PNG datastreams that are embedded in MNG datastreams) and 948 * used in PNG datastreams that are embedded in MNG datastreams) and
927 * 3. The application called png_permit_mng_features with a mask that 949 * 3. The application called png_permit_mng_features with a mask that
928 * included PNG_FLAG_MNG_FILTER_64 and 950 * included PNG_FLAG_MNG_FILTER_64 and
929 * 4. The filter_method is 64 and 951 * 4. The filter_method is 64 and
930 * 5. The color_type is RGB or RGBA 952 * 5. The color_type is RGB or RGBA
931 */ 953 */
932 if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && 954 if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
933 (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING)) 955 (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
934 { 956 {
935 /* Intrapixel differencing */ 957 /* Intrapixel differencing */
936 png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1); 958 png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
937 } 959 }
938 #endif 960 #endif
939 961
940 /* Find a filter if necessary, filter the row and write it out. */ 962 /* Find a filter if necessary, filter the row and write it out. */
941 png_write_find_filter(png_ptr, &(png_ptr->row_info)); 963 png_write_find_filter(png_ptr, &(png_ptr->row_info));
942 964
943 if (png_ptr->write_row_fn != NULL) 965 if (png_ptr->write_row_fn != NULL)
944 (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass); 966 (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
945 } 967 }
946 968
947 #if defined(PNG_WRITE_FLUSH_SUPPORTED) 969 #ifdef PNG_WRITE_FLUSH_SUPPORTED
948 /* Set the automatic flush interval or 0 to turn flushing off */ 970 /* Set the automatic flush interval or 0 to turn flushing off */
949 void PNGAPI 971 void PNGAPI
950 png_set_flush(png_structp png_ptr, int nrows) 972 png_set_flush(png_structp png_ptr, int nrows)
951 { 973 {
952 png_debug(1, "in png_set_flush"); 974 png_debug(1, "in png_set_flush");
975
953 if (png_ptr == NULL) 976 if (png_ptr == NULL)
954 return; 977 return;
955 png_ptr->flush_dist = (nrows < 0 ? 0 : nrows); 978 png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
956 } 979 }
957 980
958 /* Flush the current output buffers now */ 981 /* Flush the current output buffers now */
959 void PNGAPI 982 void PNGAPI
960 png_write_flush(png_structp png_ptr) 983 png_write_flush(png_structp png_ptr)
961 { 984 {
962 int wrote_IDAT; 985 int wrote_IDAT;
963 986
964 png_debug(1, "in png_write_flush"); 987 png_debug(1, "in png_write_flush");
988
965 if (png_ptr == NULL) 989 if (png_ptr == NULL)
966 return; 990 return;
967 /* We have already written out all of the data */ 991 /* We have already written out all of the data */
968 if (png_ptr->row_number >= png_ptr->num_rows) 992 if (png_ptr->row_number >= png_ptr->num_rows)
969 return; 993 return;
970 994
971 do 995 do
972 { 996 {
973 int ret; 997 int ret;
974 998
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr) 1039 png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
1016 { 1040 {
1017 png_structp png_ptr = NULL; 1041 png_structp png_ptr = NULL;
1018 png_infop info_ptr = NULL; 1042 png_infop info_ptr = NULL;
1019 #ifdef PNG_USER_MEM_SUPPORTED 1043 #ifdef PNG_USER_MEM_SUPPORTED
1020 png_free_ptr free_fn = NULL; 1044 png_free_ptr free_fn = NULL;
1021 png_voidp mem_ptr = NULL; 1045 png_voidp mem_ptr = NULL;
1022 #endif 1046 #endif
1023 1047
1024 png_debug(1, "in png_destroy_write_struct"); 1048 png_debug(1, "in png_destroy_write_struct");
1049
1025 if (png_ptr_ptr != NULL) 1050 if (png_ptr_ptr != NULL)
1026 { 1051 {
1027 png_ptr = *png_ptr_ptr; 1052 png_ptr = *png_ptr_ptr;
1028 #ifdef PNG_USER_MEM_SUPPORTED 1053 #ifdef PNG_USER_MEM_SUPPORTED
1029 free_fn = png_ptr->free_fn; 1054 free_fn = png_ptr->free_fn;
1030 mem_ptr = png_ptr->mem_ptr; 1055 mem_ptr = png_ptr->mem_ptr;
1031 #endif 1056 #endif
1032 } 1057 }
1033 1058
1034 #ifdef PNG_USER_MEM_SUPPORTED 1059 #ifdef PNG_USER_MEM_SUPPORTED
1035 if (png_ptr != NULL) 1060 if (png_ptr != NULL)
1036 { 1061 {
1037 free_fn = png_ptr->free_fn; 1062 free_fn = png_ptr->free_fn;
1038 mem_ptr = png_ptr->mem_ptr; 1063 mem_ptr = png_ptr->mem_ptr;
1039 } 1064 }
1040 #endif 1065 #endif
1041 1066
1042 if (info_ptr_ptr != NULL) 1067 if (info_ptr_ptr != NULL)
1043 info_ptr = *info_ptr_ptr; 1068 info_ptr = *info_ptr_ptr;
1044 1069
1045 if (info_ptr != NULL) 1070 if (info_ptr != NULL)
1046 { 1071 {
1047 if (png_ptr != NULL) 1072 if (png_ptr != NULL)
1048 { 1073 {
1049 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1); 1074 png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
1050 1075
1051 #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED) 1076 #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
1052 if (png_ptr->num_chunk_list) 1077 if (png_ptr->num_chunk_list)
1053 { 1078 {
1054 png_free(png_ptr, png_ptr->chunk_list); 1079 png_free(png_ptr, png_ptr->chunk_list);
1055 png_ptr->chunk_list=NULL; 1080 png_ptr->chunk_list = NULL;
1056 png_ptr->num_chunk_list = 0; 1081 png_ptr->num_chunk_list = 0;
1057 } 1082 }
1058 #endif 1083 #endif
1059 } 1084 }
1060 1085
1061 #ifdef PNG_USER_MEM_SUPPORTED 1086 #ifdef PNG_USER_MEM_SUPPORTED
1062 png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn, 1087 png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
1063 (png_voidp)mem_ptr); 1088 (png_voidp)mem_ptr);
1064 #else 1089 #else
1065 png_destroy_struct((png_voidp)info_ptr); 1090 png_destroy_struct((png_voidp)info_ptr);
(...skipping 23 matching lines...) Expand all
1089 jmp_buf tmp_jmp; /* Save jump buffer */ 1114 jmp_buf tmp_jmp; /* Save jump buffer */
1090 #endif 1115 #endif
1091 png_error_ptr error_fn; 1116 png_error_ptr error_fn;
1092 png_error_ptr warning_fn; 1117 png_error_ptr warning_fn;
1093 png_voidp error_ptr; 1118 png_voidp error_ptr;
1094 #ifdef PNG_USER_MEM_SUPPORTED 1119 #ifdef PNG_USER_MEM_SUPPORTED
1095 png_free_ptr free_fn; 1120 png_free_ptr free_fn;
1096 #endif 1121 #endif
1097 1122
1098 png_debug(1, "in png_write_destroy"); 1123 png_debug(1, "in png_write_destroy");
1124
1099 /* Free any memory zlib uses */ 1125 /* Free any memory zlib uses */
1100 deflateEnd(&png_ptr->zstream); 1126 deflateEnd(&png_ptr->zstream);
1101 1127
1102 /* Free our memory. png_free checks NULL for us. */ 1128 /* Free our memory. png_free checks NULL for us. */
1103 png_free(png_ptr, png_ptr->zbuf); 1129 png_free(png_ptr, png_ptr->zbuf);
1104 png_free(png_ptr, png_ptr->row_buf); 1130 png_free(png_ptr, png_ptr->row_buf);
1105 #ifndef PNG_NO_WRITE_FILTER 1131 #ifdef PNG_WRITE_FILTER_SUPPORTED
1106 png_free(png_ptr, png_ptr->prev_row); 1132 png_free(png_ptr, png_ptr->prev_row);
1107 png_free(png_ptr, png_ptr->sub_row); 1133 png_free(png_ptr, png_ptr->sub_row);
1108 png_free(png_ptr, png_ptr->up_row); 1134 png_free(png_ptr, png_ptr->up_row);
1109 png_free(png_ptr, png_ptr->avg_row); 1135 png_free(png_ptr, png_ptr->avg_row);
1110 png_free(png_ptr, png_ptr->paeth_row); 1136 png_free(png_ptr, png_ptr->paeth_row);
1111 #endif 1137 #endif
1112 1138
1113 #if defined(PNG_TIME_RFC1123_SUPPORTED) 1139 #ifdef PNG_TIME_RFC1123_SUPPORTED
1114 png_free(png_ptr, png_ptr->time_buffer); 1140 png_free(png_ptr, png_ptr->time_buffer);
1115 #endif 1141 #endif
1116 1142
1117 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) 1143 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
1118 png_free(png_ptr, png_ptr->prev_filters); 1144 png_free(png_ptr, png_ptr->prev_filters);
1119 png_free(png_ptr, png_ptr->filter_weights); 1145 png_free(png_ptr, png_ptr->filter_weights);
1120 png_free(png_ptr, png_ptr->inv_filter_weights); 1146 png_free(png_ptr, png_ptr->inv_filter_weights);
1121 png_free(png_ptr, png_ptr->filter_costs); 1147 png_free(png_ptr, png_ptr->filter_costs);
1122 png_free(png_ptr, png_ptr->inv_filter_costs); 1148 png_free(png_ptr, png_ptr->inv_filter_costs);
1123 #endif 1149 #endif
1124 1150
1125 #ifdef PNG_SETJMP_SUPPORTED 1151 #ifdef PNG_SETJMP_SUPPORTED
1126 /* Reset structure */ 1152 /* Reset structure */
1127 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf)); 1153 png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof(jmp_buf));
(...skipping 18 matching lines...) Expand all
1146 #ifdef PNG_SETJMP_SUPPORTED 1172 #ifdef PNG_SETJMP_SUPPORTED
1147 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf)); 1173 png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof(jmp_buf));
1148 #endif 1174 #endif
1149 } 1175 }
1150 1176
1151 /* Allow the application to select one or more row filters to use. */ 1177 /* Allow the application to select one or more row filters to use. */
1152 void PNGAPI 1178 void PNGAPI
1153 png_set_filter(png_structp png_ptr, int method, int filters) 1179 png_set_filter(png_structp png_ptr, int method, int filters)
1154 { 1180 {
1155 png_debug(1, "in png_set_filter"); 1181 png_debug(1, "in png_set_filter");
1182
1156 if (png_ptr == NULL) 1183 if (png_ptr == NULL)
1157 return; 1184 return;
1158 #if defined(PNG_MNG_FEATURES_SUPPORTED) 1185 #ifdef PNG_MNG_FEATURES_SUPPORTED
1159 if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) && 1186 if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
1160 (method == PNG_INTRAPIXEL_DIFFERENCING)) 1187 (method == PNG_INTRAPIXEL_DIFFERENCING))
1161 method = PNG_FILTER_TYPE_BASE; 1188 method = PNG_FILTER_TYPE_BASE;
1162 #endif 1189 #endif
1163 if (method == PNG_FILTER_TYPE_BASE) 1190 if (method == PNG_FILTER_TYPE_BASE)
1164 { 1191 {
1165 switch (filters & (PNG_ALL_FILTERS | 0x07)) 1192 switch (filters & (PNG_ALL_FILTERS | 0x07))
1166 { 1193 {
1167 #ifndef PNG_NO_WRITE_FILTER 1194 #ifdef PNG_WRITE_FILTER_SUPPORTED
1168 case 5: 1195 case 5:
1169 case 6: 1196 case 6:
1170 case 7: png_warning(png_ptr, "Unknown row filter for method 0"); 1197 case 7: png_warning(png_ptr, "Unknown row filter for method 0");
1171 #endif /* PNG_NO_WRITE_FILTER */ 1198 #endif /* PNG_WRITE_FILTER_SUPPORTED */
1172 case PNG_FILTER_VALUE_NONE: 1199 case PNG_FILTER_VALUE_NONE:
1173 png_ptr->do_filter=PNG_FILTER_NONE; break; 1200 png_ptr->do_filter = PNG_FILTER_NONE; break;
1174 #ifndef PNG_NO_WRITE_FILTER 1201 #ifdef PNG_WRITE_FILTER_SUPPORTED
1175 case PNG_FILTER_VALUE_SUB: 1202 case PNG_FILTER_VALUE_SUB:
1176 png_ptr->do_filter=PNG_FILTER_SUB; break; 1203 png_ptr->do_filter = PNG_FILTER_SUB; break;
1177 case PNG_FILTER_VALUE_UP: 1204 case PNG_FILTER_VALUE_UP:
1178 png_ptr->do_filter=PNG_FILTER_UP; break; 1205 png_ptr->do_filter = PNG_FILTER_UP; break;
1179 case PNG_FILTER_VALUE_AVG: 1206 case PNG_FILTER_VALUE_AVG:
1180 png_ptr->do_filter=PNG_FILTER_AVG; break; 1207 png_ptr->do_filter = PNG_FILTER_AVG; break;
1181 case PNG_FILTER_VALUE_PAETH: 1208 case PNG_FILTER_VALUE_PAETH:
1182 png_ptr->do_filter=PNG_FILTER_PAETH; break; 1209 png_ptr->do_filter = PNG_FILTER_PAETH; break;
1183 default: png_ptr->do_filter = (png_byte)filters; break; 1210 default: png_ptr->do_filter = (png_byte)filters; break;
1184 #else 1211 #else
1185 default: png_warning(png_ptr, "Unknown row filter for method 0"); 1212 default: png_warning(png_ptr, "Unknown row filter for method 0");
1186 #endif /* PNG_NO_WRITE_FILTER */ 1213 #endif /* PNG_WRITE_FILTER_SUPPORTED */
1187 } 1214 }
1188 1215
1189 /* If we have allocated the row_buf, this means we have already started 1216 /* If we have allocated the row_buf, this means we have already started
1190 * with the image and we should have allocated all of the filter buffers 1217 * with the image and we should have allocated all of the filter buffers
1191 * that have been selected. If prev_row isn't already allocated, then 1218 * that have been selected. If prev_row isn't already allocated, then
1192 * it is too late to start using the filters that need it, since we 1219 * it is too late to start using the filters that need it, since we
1193 * will be missing the data in the previous row. If an application 1220 * will be missing the data in the previous row. If an application
1194 * wants to start and stop using particular filters during compression, 1221 * wants to start and stop using particular filters during compression,
1195 * it should start out with all of the filters, and then add and 1222 * it should start out with all of the filters, and then add and
1196 * remove them after the start of compression. 1223 * remove them after the start of compression.
1197 */ 1224 */
1198 if (png_ptr->row_buf != NULL) 1225 if (png_ptr->row_buf != NULL)
1199 { 1226 {
1200 #ifndef PNG_NO_WRITE_FILTER 1227 #ifdef PNG_WRITE_FILTER_SUPPORTED
1201 if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL) 1228 if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
1202 { 1229 {
1203 png_ptr->sub_row = (png_bytep)png_malloc(png_ptr, 1230 png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
1204 (png_ptr->rowbytes + 1)); 1231 (png_ptr->rowbytes + 1));
1205 png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB; 1232 png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
1206 } 1233 }
1207 1234
1208 if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL) 1235 if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
1209 { 1236 {
1210 if (png_ptr->prev_row == NULL) 1237 if (png_ptr->prev_row == NULL)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 } 1272 }
1246 else 1273 else
1247 { 1274 {
1248 png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr, 1275 png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
1249 (png_ptr->rowbytes + 1)); 1276 (png_ptr->rowbytes + 1));
1250 png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH; 1277 png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
1251 } 1278 }
1252 } 1279 }
1253 1280
1254 if (png_ptr->do_filter == PNG_NO_FILTERS) 1281 if (png_ptr->do_filter == PNG_NO_FILTERS)
1255 #endif /* PNG_NO_WRITE_FILTER */ 1282 #endif /* PNG_WRITE_FILTER_SUPPORTED */
1256 png_ptr->do_filter = PNG_FILTER_NONE; 1283 png_ptr->do_filter = PNG_FILTER_NONE;
1257 } 1284 }
1258 } 1285 }
1259 else 1286 else
1260 png_error(png_ptr, "Unknown custom filter method"); 1287 png_error(png_ptr, "Unknown custom filter method");
1261 } 1288 }
1262 1289
1263 /* This allows us to influence the way in which libpng chooses the "best" 1290 /* This allows us to influence the way in which libpng chooses the "best"
1264 * filter for the current scanline. While the "minimum-sum-of-absolute- 1291 * filter for the current scanline. While the "minimum-sum-of-absolute-
1265 * differences metric is relatively fast and effective, there is some 1292 * differences metric is relatively fast and effective, there is some
1266 * question as to whether it can be improved upon by trying to keep the 1293 * question as to whether it can be improved upon by trying to keep the
1267 * filtered data going to zlib more consistent, hopefully resulting in 1294 * filtered data going to zlib more consistent, hopefully resulting in
1268 * better compression. 1295 * better compression.
1269 */ 1296 */
1270 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */ 1297 #ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* GRR 970116 */
1271 void PNGAPI 1298 void PNGAPI
1272 png_set_filter_heuristics(png_structp png_ptr, int heuristic_method, 1299 png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
1273 int num_weights, png_doublep filter_weights, 1300 int num_weights, png_doublep filter_weights,
1274 png_doublep filter_costs) 1301 png_doublep filter_costs)
1275 { 1302 {
1276 int i; 1303 int i;
1277 1304
1278 png_debug(1, "in png_set_filter_heuristics"); 1305 png_debug(1, "in png_set_filter_heuristics");
1306
1279 if (png_ptr == NULL) 1307 if (png_ptr == NULL)
1280 return; 1308 return;
1281 if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST) 1309 if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
1282 { 1310 {
1283 png_warning(png_ptr, "Unknown filter heuristic method"); 1311 png_warning(png_ptr, "Unknown filter heuristic method");
1284 return; 1312 return;
1285 } 1313 }
1286 1314
1287 if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT) 1315 if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
1288 { 1316 {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5); 1411 (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
1384 } 1412 }
1385 } 1413 }
1386 } 1414 }
1387 #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */ 1415 #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
1388 1416
1389 void PNGAPI 1417 void PNGAPI
1390 png_set_compression_level(png_structp png_ptr, int level) 1418 png_set_compression_level(png_structp png_ptr, int level)
1391 { 1419 {
1392 png_debug(1, "in png_set_compression_level"); 1420 png_debug(1, "in png_set_compression_level");
1421
1393 if (png_ptr == NULL) 1422 if (png_ptr == NULL)
1394 return; 1423 return;
1395 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL; 1424 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
1396 png_ptr->zlib_level = level; 1425 png_ptr->zlib_level = level;
1397 } 1426 }
1398 1427
1399 void PNGAPI 1428 void PNGAPI
1400 png_set_compression_mem_level(png_structp png_ptr, int mem_level) 1429 png_set_compression_mem_level(png_structp png_ptr, int mem_level)
1401 { 1430 {
1402 png_debug(1, "in png_set_compression_mem_level"); 1431 png_debug(1, "in png_set_compression_mem_level");
1432
1403 if (png_ptr == NULL) 1433 if (png_ptr == NULL)
1404 return; 1434 return;
1405 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL; 1435 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
1406 png_ptr->zlib_mem_level = mem_level; 1436 png_ptr->zlib_mem_level = mem_level;
1407 } 1437 }
1408 1438
1409 void PNGAPI 1439 void PNGAPI
1410 png_set_compression_strategy(png_structp png_ptr, int strategy) 1440 png_set_compression_strategy(png_structp png_ptr, int strategy)
1411 { 1441 {
1412 png_debug(1, "in png_set_compression_strategy"); 1442 png_debug(1, "in png_set_compression_strategy");
1443
1413 if (png_ptr == NULL) 1444 if (png_ptr == NULL)
1414 return; 1445 return;
1415 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY; 1446 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
1416 png_ptr->zlib_strategy = strategy; 1447 png_ptr->zlib_strategy = strategy;
1417 } 1448 }
1418 1449
1419 void PNGAPI 1450 void PNGAPI
1420 png_set_compression_window_bits(png_structp png_ptr, int window_bits) 1451 png_set_compression_window_bits(png_structp png_ptr, int window_bits)
1421 { 1452 {
1422 if (png_ptr == NULL) 1453 if (png_ptr == NULL)
1423 return; 1454 return;
1424 if (window_bits > 15) 1455 if (window_bits > 15)
1425 png_warning(png_ptr, "Only compression windows <= 32k supported by PNG"); 1456 png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
1426 else if (window_bits < 8) 1457 else if (window_bits < 8)
1427 png_warning(png_ptr, "Only compression windows >= 256 supported by PNG"); 1458 png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
1428 #ifndef WBITS_8_OK 1459 #ifndef WBITS_8_OK
1429 /* Avoid libpng bug with 256-byte windows */ 1460 /* Avoid libpng bug with 256-byte windows */
1430 if (window_bits == 8) 1461 if (window_bits == 8)
1431 { 1462 {
1432 png_warning(png_ptr, "Compression window is being reset to 512"); 1463 png_warning(png_ptr, "Compression window is being reset to 512");
1433 window_bits=9; 1464 window_bits = 9;
1434 } 1465 }
1435 #endif 1466 #endif
1436 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS; 1467 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
1437 png_ptr->zlib_window_bits = window_bits; 1468 png_ptr->zlib_window_bits = window_bits;
1438 } 1469 }
1439 1470
1440 void PNGAPI 1471 void PNGAPI
1441 png_set_compression_method(png_structp png_ptr, int method) 1472 png_set_compression_method(png_structp png_ptr, int method)
1442 { 1473 {
1443 png_debug(1, "in png_set_compression_method"); 1474 png_debug(1, "in png_set_compression_method");
1475
1444 if (png_ptr == NULL) 1476 if (png_ptr == NULL)
1445 return; 1477 return;
1446 if (method != 8) 1478 if (method != 8)
1447 png_warning(png_ptr, "Only compression method 8 is supported by PNG"); 1479 png_warning(png_ptr, "Only compression method 8 is supported by PNG");
1448 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD; 1480 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
1449 png_ptr->zlib_method = method; 1481 png_ptr->zlib_method = method;
1450 } 1482 }
1451 1483
1452 void PNGAPI 1484 void PNGAPI
1453 png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn) 1485 png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
1454 { 1486 {
1455 if (png_ptr == NULL) 1487 if (png_ptr == NULL)
1456 return; 1488 return;
1457 png_ptr->write_row_fn = write_row_fn; 1489 png_ptr->write_row_fn = write_row_fn;
1458 } 1490 }
1459 1491
1460 #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) 1492 #ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED
1461 void PNGAPI 1493 void PNGAPI
1462 png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr 1494 png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
1463 write_user_transform_fn) 1495 write_user_transform_fn)
1464 { 1496 {
1465 png_debug(1, "in png_set_write_user_transform_fn"); 1497 png_debug(1, "in png_set_write_user_transform_fn");
1498
1466 if (png_ptr == NULL) 1499 if (png_ptr == NULL)
1467 return; 1500 return;
1468 png_ptr->transformations |= PNG_USER_TRANSFORM; 1501 png_ptr->transformations |= PNG_USER_TRANSFORM;
1469 png_ptr->write_user_transform_fn = write_user_transform_fn; 1502 png_ptr->write_user_transform_fn = write_user_transform_fn;
1470 } 1503 }
1471 #endif 1504 #endif
1472 1505
1473 1506
1474 #if defined(PNG_INFO_IMAGE_SUPPORTED) 1507 #ifdef PNG_INFO_IMAGE_SUPPORTED
1475 void PNGAPI 1508 void PNGAPI
1476 png_write_png(png_structp png_ptr, png_infop info_ptr, 1509 png_write_png(png_structp png_ptr, png_infop info_ptr,
1477 int transforms, voidp params) 1510 int transforms, voidp params)
1478 { 1511 {
1479 if (png_ptr == NULL || info_ptr == NULL) 1512 if (png_ptr == NULL || info_ptr == NULL)
1480 return; 1513 return;
1481 #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
1482 /* Invert the alpha channel from opacity to transparency */
1483 if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
1484 png_set_invert_alpha(png_ptr);
1485 #endif
1486 1514
1487 /* Write the file header information. */ 1515 /* Write the file header information. */
1488 png_write_info(png_ptr, info_ptr); 1516 png_write_info(png_ptr, info_ptr);
1489 1517
1490 /* ------ these transformations don't touch the info structure ------- */ 1518 /* ------ these transformations don't touch the info structure ------- */
1491 1519
1492 #if defined(PNG_WRITE_INVERT_SUPPORTED) 1520 #ifdef PNG_WRITE_INVERT_SUPPORTED
1493 /* Invert monochrome pixels */ 1521 /* Invert monochrome pixels */
1494 if (transforms & PNG_TRANSFORM_INVERT_MONO) 1522 if (transforms & PNG_TRANSFORM_INVERT_MONO)
1495 png_set_invert_mono(png_ptr); 1523 png_set_invert_mono(png_ptr);
1496 #endif 1524 #endif
1497 1525
1498 #if defined(PNG_WRITE_SHIFT_SUPPORTED) 1526 #ifdef PNG_WRITE_SHIFT_SUPPORTED
1499 /* Shift the pixels up to a legal bit depth and fill in 1527 /* Shift the pixels up to a legal bit depth and fill in
1500 * as appropriate to correctly scale the image. 1528 * as appropriate to correctly scale the image.
1501 */ 1529 */
1502 if ((transforms & PNG_TRANSFORM_SHIFT) 1530 if ((transforms & PNG_TRANSFORM_SHIFT)
1503 && (info_ptr->valid & PNG_INFO_sBIT)) 1531 && (info_ptr->valid & PNG_INFO_sBIT))
1504 png_set_shift(png_ptr, &info_ptr->sig_bit); 1532 png_set_shift(png_ptr, &info_ptr->sig_bit);
1505 #endif 1533 #endif
1506 1534
1507 #if defined(PNG_WRITE_PACK_SUPPORTED) 1535 #ifdef PNG_WRITE_PACK_SUPPORTED
1508 /* Pack pixels into bytes */ 1536 /* Pack pixels into bytes */
1509 if (transforms & PNG_TRANSFORM_PACKING) 1537 if (transforms & PNG_TRANSFORM_PACKING)
1510 png_set_packing(png_ptr); 1538 png_set_packing(png_ptr);
1511 #endif 1539 #endif
1512 1540
1513 #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED) 1541 #ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
1514 /* Swap location of alpha bytes from ARGB to RGBA */ 1542 /* Swap location of alpha bytes from ARGB to RGBA */
1515 if (transforms & PNG_TRANSFORM_SWAP_ALPHA) 1543 if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
1516 png_set_swap_alpha(png_ptr); 1544 png_set_swap_alpha(png_ptr);
1517 #endif 1545 #endif
1518 1546
1519 #if defined(PNG_WRITE_FILLER_SUPPORTED) 1547 #ifdef PNG_WRITE_FILLER_SUPPORTED
1520 /* Pack XRGB/RGBX/ARGB/RGBA into * RGB (4 channels -> 3 channels) */ 1548 /* Pack XRGB/RGBX/ARGB/RGBA into * RGB (4 channels -> 3 channels) */
1521 if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER) 1549 if (transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER)
1522 png_set_filler(png_ptr, 0, PNG_FILLER_AFTER); 1550 png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);
1523 else if (transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE) 1551 else if (transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE)
1524 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE); 1552 png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
1525 #endif 1553 #endif
1526 1554
1527 #if defined(PNG_WRITE_BGR_SUPPORTED) 1555 #ifdef PNG_WRITE_BGR_SUPPORTED
1528 /* Flip BGR pixels to RGB */ 1556 /* Flip BGR pixels to RGB */
1529 if (transforms & PNG_TRANSFORM_BGR) 1557 if (transforms & PNG_TRANSFORM_BGR)
1530 png_set_bgr(png_ptr); 1558 png_set_bgr(png_ptr);
1531 #endif 1559 #endif
1532 1560
1533 #if defined(PNG_WRITE_SWAP_SUPPORTED) 1561 #ifdef PNG_WRITE_SWAP_SUPPORTED
1534 /* Swap bytes of 16-bit files to most significant byte first */ 1562 /* Swap bytes of 16-bit files to most significant byte first */
1535 if (transforms & PNG_TRANSFORM_SWAP_ENDIAN) 1563 if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
1536 png_set_swap(png_ptr); 1564 png_set_swap(png_ptr);
1537 #endif 1565 #endif
1538 1566
1539 #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) 1567 #ifdef PNG_WRITE_PACKSWAP_SUPPORTED
1540 /* Swap bits of 1, 2, 4 bit packed pixel formats */ 1568 /* Swap bits of 1, 2, 4 bit packed pixel formats */
1541 if (transforms & PNG_TRANSFORM_PACKSWAP) 1569 if (transforms & PNG_TRANSFORM_PACKSWAP)
1542 png_set_packswap(png_ptr); 1570 png_set_packswap(png_ptr);
1543 #endif 1571 #endif
1544 1572
1573 #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
1574 /* Invert the alpha channel from opacity to transparency */
1575 if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
1576 png_set_invert_alpha(png_ptr);
1577 #endif
1578
1545 /* ----------------------- end of transformations ------------------- */ 1579 /* ----------------------- end of transformations ------------------- */
1546 1580
1547 /* Write the bits */ 1581 /* Write the bits */
1548 if (info_ptr->valid & PNG_INFO_IDAT) 1582 if (info_ptr->valid & PNG_INFO_IDAT)
1549 png_write_image(png_ptr, info_ptr->row_pointers); 1583 png_write_image(png_ptr, info_ptr->row_pointers);
1550 1584
1551 /* It is REQUIRED to call this to finish writing the rest of the file */ 1585 /* It is REQUIRED to call this to finish writing the rest of the file */
1552 png_write_end(png_ptr, info_ptr); 1586 png_write_end(png_ptr, info_ptr);
1553 1587
1554 transforms = transforms; /* Quiet compiler warnings */ 1588 transforms = transforms; /* Quiet compiler warnings */
1555 params = params; 1589 params = params;
1556 } 1590 }
1557 #endif 1591 #endif
1558 #endif /* PNG_WRITE_SUPPORTED */ 1592 #endif /* PNG_WRITE_SUPPORTED */
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698