42
|
1
|
|
2 /* pngwrite.c - general routines to write a PNG file
|
|
3 *
|
|
4 * libpng 1.0.15 - October 3, 2002
|
|
5 * For conditions of distribution and use, see copyright notice in png.h
|
|
6 * Copyright (c) 1998-2002 Glenn Randers-Pehrson
|
|
7 * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
|
|
8 * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
|
|
9 */
|
|
10
|
|
11 /* get internal access to png.h */
|
|
12 #define PNG_INTERNAL
|
|
13 #include "png.h"
|
|
14 #ifdef PNG_WRITE_SUPPORTED
|
|
15
|
|
16 void png_write_init(png_struct *png_ptr)
|
|
17 {
|
|
18 png_debug(1, "in png_write_init_3\n");
|
|
19
|
|
20 /* reset all variables to 0 */
|
|
21 png_memset(png_ptr, 0, sizeof (png_struct));
|
|
22
|
|
23 /* initialize zbuf - compression buffer */
|
|
24 png_ptr->zbuf_size = PNG_ZBUF_SIZE;
|
|
25 png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
|
|
26 (png_uint_32)png_ptr->zbuf_size);
|
|
27
|
|
28 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
|
29 png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
|
|
30 1, png_doublep_NULL, png_doublep_NULL);
|
|
31 #endif
|
|
32 }
|
|
33
|
|
34 /* Writes all the PNG information. This is the suggested way to use the
|
|
35 * library. If you have a new chunk to add, make a function to write it,
|
|
36 * and put it in the correct location here. If you want the chunk written
|
|
37 * after the image data, put it in png_write_end(). I strongly encourage
|
|
38 * you to supply a PNG_INFO_ flag, and check info_ptr->valid before writing
|
|
39 * the chunk, as that will keep the code from breaking if you want to just
|
|
40 * write a plain PNG file. If you have long comments, I suggest writing
|
|
41 * them in png_write_end(), and compressing them.
|
|
42 */
|
|
43 void PNGAPI
|
|
44 png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
|
|
45 {
|
|
46 png_debug(1, "in png_write_info_before_PLTE\n");
|
|
47 if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
|
|
48 {
|
|
49 png_write_sig(png_ptr); /* write PNG signature */
|
|
50 #if defined(PNG_MNG_FEATURES_SUPPORTED)
|
|
51 if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
|
|
52 {
|
|
53 png_warning(png_ptr,"MNG features are not allowed in a PNG datastream\n");
|
|
54 png_ptr->mng_features_permitted=0;
|
|
55 }
|
|
56 #endif
|
|
57 /* write IHDR information. */
|
|
58 png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
|
|
59 info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
|
|
60 info_ptr->filter_type,
|
|
61 #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
|
|
62 info_ptr->interlace_type);
|
|
63 #else
|
|
64 0);
|
|
65 #endif
|
|
66 /* the rest of these check to see if the valid field has the appropriate
|
|
67 flag set, and if it does, writes the chunk. */
|
|
68 #if defined(PNG_WRITE_gAMA_SUPPORTED)
|
|
69 if (info_ptr->valid & PNG_INFO_gAMA)
|
|
70 {
|
|
71 # ifdef PNG_FLOATING_POINT_SUPPORTED
|
|
72 png_write_gAMA(png_ptr, info_ptr->gamma);
|
|
73 #else
|
|
74 #ifdef PNG_FIXED_POINT_SUPPORTED
|
|
75 png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
|
|
76 # endif
|
|
77 #endif
|
|
78 }
|
|
79 #endif
|
|
80 #if defined(PNG_WRITE_sRGB_SUPPORTED)
|
|
81 if (info_ptr->valid & PNG_INFO_sRGB)
|
|
82 png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
|
|
83 #endif
|
|
84 #if defined(PNG_WRITE_iCCP_SUPPORTED)
|
|
85 if (info_ptr->valid & PNG_INFO_iCCP)
|
|
86 png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
|
|
87 info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
|
|
88 #endif
|
|
89 #if defined(PNG_WRITE_sBIT_SUPPORTED)
|
|
90 if (info_ptr->valid & PNG_INFO_sBIT)
|
|
91 png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
|
|
92 #endif
|
|
93 #if defined(PNG_WRITE_cHRM_SUPPORTED)
|
|
94 if (info_ptr->valid & PNG_INFO_cHRM)
|
|
95 {
|
|
96 #ifdef PNG_FLOATING_POINT_SUPPORTED
|
|
97 png_write_cHRM(png_ptr,
|
|
98 info_ptr->x_white, info_ptr->y_white,
|
|
99 info_ptr->x_red, info_ptr->y_red,
|
|
100 info_ptr->x_green, info_ptr->y_green,
|
|
101 info_ptr->x_blue, info_ptr->y_blue);
|
|
102 #else
|
|
103 # ifdef PNG_FIXED_POINT_SUPPORTED
|
|
104 png_write_cHRM_fixed(png_ptr,
|
|
105 info_ptr->int_x_white, info_ptr->int_y_white,
|
|
106 info_ptr->int_x_red, info_ptr->int_y_red,
|
|
107 info_ptr->int_x_green, info_ptr->int_y_green,
|
|
108 info_ptr->int_x_blue, info_ptr->int_y_blue);
|
|
109 # endif
|
|
110 #endif
|
|
111 }
|
|
112 #endif
|
|
113 #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
|
|
114 if (info_ptr->unknown_chunks_num)
|
|
115 {
|
|
116 png_unknown_chunk *up;
|
|
117
|
|
118 png_debug(5, "writing extra chunks\n");
|
|
119
|
|
120 for (up = info_ptr->unknown_chunks;
|
|
121 up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
|
|
122 up++)
|
|
123 {
|
|
124 int keep=png_handle_as_unknown(png_ptr, up->name);
|
|
125 if (keep != HANDLE_CHUNK_NEVER &&
|
|
126 up->location && (!(up->location & PNG_HAVE_PLTE)) &&
|
|
127 ((up->name[3] & 0x20) || keep == HANDLE_CHUNK_ALWAYS ||
|
|
128 (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
|
|
129 {
|
|
130 png_write_chunk(png_ptr, up->name, up->data, up->size);
|
|
131 }
|
|
132 }
|
|
133 }
|
|
134 #endif
|
|
135 png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
|
|
136 }
|
|
137 }
|
|
138
|
|
139 void PNGAPI
|
|
140 png_write_info(png_structp png_ptr, png_infop info_ptr)
|
|
141 {
|
|
142 #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
|
|
143 int i;
|
|
144 #endif
|
|
145
|
|
146 png_debug(1, "in png_write_info\n");
|
|
147
|
|
148 png_write_info_before_PLTE(png_ptr, info_ptr);
|
|
149
|
|
150 if (info_ptr->valid & PNG_INFO_PLTE)
|
|
151 png_write_PLTE(png_ptr, info_ptr->palette,
|
|
152 (png_uint_32)info_ptr->num_palette);
|
|
153 else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
|
154 png_error(png_ptr, "Valid palette required for paletted images\n");
|
|
155
|
|
156 #if defined(PNG_WRITE_tRNS_SUPPORTED)
|
|
157 if (info_ptr->valid & PNG_INFO_tRNS)
|
|
158 {
|
|
159 #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
|
|
160 /* invert the alpha channel (in tRNS) */
|
|
161 if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
|
|
162 info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
|
|
163 {
|
|
164 int j;
|
|
165 for (j=0; j<(int)info_ptr->num_trans; j++)
|
|
166 info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
|
|
167 }
|
|
168 #endif
|
|
169 png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
|
|
170 info_ptr->num_trans, info_ptr->color_type);
|
|
171 }
|
|
172 #endif
|
|
173 #if defined(PNG_WRITE_bKGD_SUPPORTED)
|
|
174 if (info_ptr->valid & PNG_INFO_bKGD)
|
|
175 png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
|
|
176 #endif
|
|
177 #if defined(PNG_WRITE_hIST_SUPPORTED)
|
|
178 if (info_ptr->valid & PNG_INFO_hIST)
|
|
179 png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
|
|
180 #endif
|
|
181 #if defined(PNG_WRITE_oFFs_SUPPORTED)
|
|
182 if (info_ptr->valid & PNG_INFO_oFFs)
|
|
183 png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
|
|
184 info_ptr->offset_unit_type);
|
|
185 #endif
|
|
186 #if defined(PNG_WRITE_pCAL_SUPPORTED)
|
|
187 if (info_ptr->valid & PNG_INFO_pCAL)
|
|
188 png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
|
|
189 info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
|
|
190 info_ptr->pcal_units, info_ptr->pcal_params);
|
|
191 #endif
|
|
192 #if defined(PNG_WRITE_sCAL_SUPPORTED)
|
|
193 if (info_ptr->valid & PNG_INFO_sCAL)
|
|
194 #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
|
|
195 png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
|
|
196 info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
|
|
197 #else
|
|
198 #ifdef PNG_FIXED_POINT_SUPPORTED
|
|
199 png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
|
|
200 info_ptr->scal_s_width, info_ptr->scal_s_height);
|
|
201 #else
|
|
202 png_warning(png_ptr,
|
|
203 "png_write_sCAL not supported; sCAL chunk not written.\n");
|
|
204 #endif
|
|
205 #endif
|
|
206 #endif
|
|
207 #if defined(PNG_WRITE_pHYs_SUPPORTED)
|
|
208 if (info_ptr->valid & PNG_INFO_pHYs)
|
|
209 png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
|
|
210 info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
|
|
211 #endif
|
|
212 #if defined(PNG_WRITE_tIME_SUPPORTED)
|
|
213 if (info_ptr->valid & PNG_INFO_tIME)
|
|
214 {
|
|
215 png_write_tIME(png_ptr, &(info_ptr->mod_time));
|
|
216 png_ptr->mode |= PNG_WROTE_tIME;
|
|
217 }
|
|
218 #endif
|
|
219 #if defined(PNG_WRITE_sPLT_SUPPORTED)
|
|
220 if (info_ptr->valid & PNG_INFO_sPLT)
|
|
221 for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
|
|
222 png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
|
|
223 #endif
|
|
224 #if defined(PNG_WRITE_TEXT_SUPPORTED)
|
|
225 /* Check to see if we need to write text chunks */
|
|
226 for (i = 0; i < info_ptr->num_text; i++)
|
|
227 {
|
|
228 png_debug2(2, "Writing header text chunk %d, type %d\n", i,
|
|
229 info_ptr->text[i].compression);
|
|
230 /* an internationalized chunk? */
|
|
231 if (info_ptr->text[i].compression > 0)
|
|
232 {
|
|
233 #if defined(PNG_WRITE_iTXt_SUPPORTED)
|
|
234 /* write international chunk */
|
|
235 png_write_iTXt(png_ptr,
|
|
236 info_ptr->text[i].compression,
|
|
237 info_ptr->text[i].key,
|
|
238 info_ptr->text[i].lang,
|
|
239 info_ptr->text[i].lang_key,
|
|
240 info_ptr->text[i].text);
|
|
241 #else
|
|
242 png_warning(png_ptr, "Unable to write international text\n");
|
|
243 #endif
|
|
244 /* Mark this chunk as written */
|
|
245 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
|
|
246 }
|
|
247 /* If we want a compressed text chunk */
|
|
248 else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
|
|
249 {
|
|
250 #if defined(PNG_WRITE_zTXt_SUPPORTED)
|
|
251 /* write compressed chunk */
|
|
252 png_write_zTXt(png_ptr, info_ptr->text[i].key,
|
|
253 info_ptr->text[i].text, 0,
|
|
254 info_ptr->text[i].compression);
|
|
255 #else
|
|
256 png_warning(png_ptr, "Unable to write compressed text\n");
|
|
257 #endif
|
|
258 /* Mark this chunk as written */
|
|
259 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
|
|
260 }
|
|
261 else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
|
|
262 {
|
|
263 #if defined(PNG_WRITE_tEXt_SUPPORTED)
|
|
264 /* write uncompressed chunk */
|
|
265 png_write_tEXt(png_ptr, info_ptr->text[i].key,
|
|
266 info_ptr->text[i].text,
|
|
267 0);
|
|
268 #else
|
|
269 png_warning(png_ptr, "Unable to write uncompressed text\n");
|
|
270 #endif
|
|
271 /* Mark this chunk as written */
|
|
272 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
|
|
273 }
|
|
274 }
|
|
275 #endif
|
|
276 #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
|
|
277 if (info_ptr->unknown_chunks_num)
|
|
278 {
|
|
279 png_unknown_chunk *up;
|
|
280
|
|
281 png_debug(5, "writing extra chunks\n");
|
|
282
|
|
283 for (up = info_ptr->unknown_chunks;
|
|
284 up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
|
|
285 up++)
|
|
286 {
|
|
287 int keep=png_handle_as_unknown(png_ptr, up->name);
|
|
288 if (keep != HANDLE_CHUNK_NEVER &&
|
|
289 up->location && (up->location & PNG_HAVE_PLTE) &&
|
|
290 !(up->location & PNG_HAVE_IDAT) &&
|
|
291 ((up->name[3] & 0x20) || keep == HANDLE_CHUNK_ALWAYS ||
|
|
292 (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
|
|
293 {
|
|
294 png_write_chunk(png_ptr, up->name, up->data, up->size);
|
|
295 }
|
|
296 }
|
|
297 }
|
|
298 #endif
|
|
299 }
|
|
300
|
|
301 /* 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
|
|
303 * in png_write_info(), do not write them again here. If you have long
|
|
304 * comments, I suggest writing them here, and compressing them.
|
|
305 */
|
|
306 void PNGAPI
|
|
307 png_write_end(png_structp png_ptr, png_infop info_ptr)
|
|
308 {
|
|
309 png_debug(1, "in png_write_end\n");
|
|
310 if (!(png_ptr->mode & PNG_HAVE_IDAT))
|
|
311 png_error(png_ptr, "No IDATs written into file");
|
|
312
|
|
313 /* see if user wants us to write information chunks */
|
|
314 if (info_ptr != NULL)
|
|
315 {
|
|
316 #if defined(PNG_WRITE_TEXT_SUPPORTED)
|
|
317 int i; /* local index variable */
|
|
318 #endif
|
|
319 #if defined(PNG_WRITE_tIME_SUPPORTED)
|
|
320 /* check to see if user has supplied a time chunk */
|
|
321 if ((info_ptr->valid & PNG_INFO_tIME) &&
|
|
322 !(png_ptr->mode & PNG_WROTE_tIME))
|
|
323 png_write_tIME(png_ptr, &(info_ptr->mod_time));
|
|
324 #endif
|
|
325 #if defined(PNG_WRITE_TEXT_SUPPORTED)
|
|
326 /* loop through comment chunks */
|
|
327 for (i = 0; i < info_ptr->num_text; i++)
|
|
328 {
|
|
329 png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
|
|
330 info_ptr->text[i].compression);
|
|
331 /* an internationalized chunk? */
|
|
332 if (info_ptr->text[i].compression > 0)
|
|
333 {
|
|
334 #if defined(PNG_WRITE_iTXt_SUPPORTED)
|
|
335 /* write international chunk */
|
|
336 png_write_iTXt(png_ptr,
|
|
337 info_ptr->text[i].compression,
|
|
338 info_ptr->text[i].key,
|
|
339 info_ptr->text[i].lang,
|
|
340 info_ptr->text[i].lang_key,
|
|
341 info_ptr->text[i].text);
|
|
342 #else
|
|
343 png_warning(png_ptr, "Unable to write international text\n");
|
|
344 #endif
|
|
345 /* Mark this chunk as written */
|
|
346 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
|
|
347 }
|
|
348 else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
|
|
349 {
|
|
350 #if defined(PNG_WRITE_zTXt_SUPPORTED)
|
|
351 /* write compressed chunk */
|
|
352 png_write_zTXt(png_ptr, info_ptr->text[i].key,
|
|
353 info_ptr->text[i].text, 0,
|
|
354 info_ptr->text[i].compression);
|
|
355 #else
|
|
356 png_warning(png_ptr, "Unable to write compressed text\n");
|
|
357 #endif
|
|
358 /* Mark this chunk as written */
|
|
359 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
|
|
360 }
|
|
361 else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
|
|
362 {
|
|
363 #if defined(PNG_WRITE_tEXt_SUPPORTED)
|
|
364 /* write uncompressed chunk */
|
|
365 png_write_tEXt(png_ptr, info_ptr->text[i].key,
|
|
366 info_ptr->text[i].text, 0);
|
|
367 #else
|
|
368 png_warning(png_ptr, "Unable to write uncompressed text\n");
|
|
369 #endif
|
|
370
|
|
371 /* Mark this chunk as written */
|
|
372 info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
|
|
373 }
|
|
374 }
|
|
375 #endif
|
|
376 #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
|
|
377 if (info_ptr->unknown_chunks_num)
|
|
378 {
|
|
379 png_unknown_chunk *up;
|
|
380
|
|
381 png_debug(5, "writing extra chunks\n");
|
|
382
|
|
383 for (up = info_ptr->unknown_chunks;
|
|
384 up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
|
|
385 up++)
|
|
386 {
|
|
387 int keep=png_handle_as_unknown(png_ptr, up->name);
|
|
388 if (keep != HANDLE_CHUNK_NEVER &&
|
|
389 up->location && (up->location & PNG_AFTER_IDAT) &&
|
|
390 ((up->name[3] & 0x20) || keep == HANDLE_CHUNK_ALWAYS ||
|
|
391 (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
|
|
392 {
|
|
393 png_write_chunk(png_ptr, up->name, up->data, up->size);
|
|
394 }
|
|
395 }
|
|
396 }
|
|
397 #endif
|
|
398 }
|
|
399
|
|
400 png_ptr->mode |= PNG_AFTER_IDAT;
|
|
401
|
|
402 /* write end of PNG file */
|
|
403 png_write_IEND(png_ptr);
|
|
404 #if 0
|
|
405 /* This flush, added in libpng-1.0.8, causes some applications to crash
|
|
406 because they do not set png_ptr->output_flush_fn */
|
|
407 png_flush(png_ptr);
|
|
408 #endif
|
|
409 }
|
|
410
|
|
411 #if defined(PNG_WRITE_tIME_SUPPORTED)
|
|
412 #if !defined(_WIN32_WCE)
|
|
413 /* "time.h" functions are not supported on WindowsCE */
|
|
414 void PNGAPI
|
|
415 png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
|
|
416 {
|
|
417 png_debug(1, "in png_convert_from_struct_tm\n");
|
|
418 ptime->year = (png_uint_16)(1900 + ttime->tm_year);
|
|
419 ptime->month = (png_byte)(ttime->tm_mon + 1);
|
|
420 ptime->day = (png_byte)ttime->tm_mday;
|
|
421 ptime->hour = (png_byte)ttime->tm_hour;
|
|
422 ptime->minute = (png_byte)ttime->tm_min;
|
|
423 ptime->second = (png_byte)ttime->tm_sec;
|
|
424 }
|
|
425
|
|
426 void PNGAPI
|
|
427 png_convert_from_time_t(png_timep ptime, time_t ttime)
|
|
428 {
|
|
429 struct tm *tbuf;
|
|
430
|
|
431 png_debug(1, "in png_convert_from_time_t\n");
|
|
432 tbuf = gmtime(&ttime);
|
|
433 png_convert_from_struct_tm(ptime, tbuf);
|
|
434 }
|
|
435 #endif
|
|
436 #endif
|
|
437
|
|
438 /* called by user to write a row of image data */
|
|
439 void PNGAPI
|
|
440 png_write_row(png_structp png_ptr, png_bytep row)
|
|
441 {
|
|
442 png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
|
|
443 png_ptr->row_number, png_ptr->pass);
|
|
444 /* initialize transformations and other stuff if first time */
|
|
445 if (png_ptr->row_number == 0 && png_ptr->pass == 0)
|
|
446 {
|
|
447 /* make sure we wrote the header info */
|
|
448 if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
|
|
449 png_error(png_ptr,
|
|
450 "png_write_info was never called before png_write_row.");
|
|
451
|
|
452 /* check for transforms that have been set but were defined out */
|
|
453 #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
|
|
454 if (png_ptr->transformations & PNG_INVERT_MONO)
|
|
455 png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
|
|
456 #endif
|
|
457 #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
|
|
458 if (png_ptr->transformations & PNG_FILLER)
|
|
459 png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
|
|
460 #endif
|
|
461 #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
|
|
462 if (png_ptr->transformations & PNG_PACKSWAP)
|
|
463 png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
|
|
464 #endif
|
|
465 #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
|
|
466 if (png_ptr->transformations & PNG_PACK)
|
|
467 png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
|
|
468 #endif
|
|
469 #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
|
|
470 if (png_ptr->transformations & PNG_SHIFT)
|
|
471 png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
|
|
472 #endif
|
|
473 #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
|
|
474 if (png_ptr->transformations & PNG_BGR)
|
|
475 png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
|
|
476 #endif
|
|
477 #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
|
|
478 if (png_ptr->transformations & PNG_SWAP_BYTES)
|
|
479 png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
|
|
480 #endif
|
|
481
|
|
482 png_write_start_row(png_ptr);
|
|
483 }
|
|
484
|
|
485 #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
|
|
486 /* if interlaced and not interested in row, return */
|
|
487 if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
|
|
488 {
|
|
489 switch (png_ptr->pass)
|
|
490 {
|
|
491 case 0:
|
|
492 if (png_ptr->row_number & 0x07)
|
|
493 {
|
|
494 png_write_finish_row(png_ptr);
|
|
495 return;
|
|
496 }
|
|
497 break;
|
|
498 case 1:
|
|
499 if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
|
|
500 {
|
|
501 png_write_finish_row(png_ptr);
|
|
502 return;
|
|
503 }
|
|
504 break;
|
|
505 case 2:
|
|
506 if ((png_ptr->row_number & 0x07) != 4)
|
|
507 {
|
|
508 png_write_finish_row(png_ptr);
|
|
509 return;
|
|
510 }
|
|
511 break;
|
|
512 case 3:
|
|
513 if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
|
|
514 {
|
|
515 png_write_finish_row(png_ptr);
|
|
516 return;
|
|
517 }
|
|
518 break;
|
|
519 case 4:
|
|
520 if ((png_ptr->row_number & 0x03) != 2)
|
|
521 {
|
|
522 png_write_finish_row(png_ptr);
|
|
523 return;
|
|
524 }
|
|
525 break;
|
|
526 case 5:
|
|
527 if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
|
|
528 {
|
|
529 png_write_finish_row(png_ptr);
|
|
530 return;
|
|
531 }
|
|
532 break;
|
|
533 case 6:
|
|
534 if (!(png_ptr->row_number & 0x01))
|
|
535 {
|
|
536 png_write_finish_row(png_ptr);
|
|
537 return;
|
|
538 }
|
|
539 break;
|
|
540 }
|
|
541 }
|
|
542 #endif
|
|
543
|
|
544 /* set up row info for transformations */
|
|
545 png_ptr->row_info.color_type = png_ptr->color_type;
|
|
546 png_ptr->row_info.width = png_ptr->usr_width;
|
|
547 png_ptr->row_info.channels = png_ptr->usr_channels;
|
|
548 png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
|
|
549 png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
|
|
550 png_ptr->row_info.channels);
|
|
551
|
|
552 png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
|
|
553 (png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
|
|
554
|
|
555 png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
|
|
556 png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
|
|
557 png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
|
|
558 png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
|
|
559 png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
|
|
560 png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
|
|
561
|
|
562 /* Copy user's row into buffer, leaving room for filter byte. */
|
|
563 png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
|
|
564 png_ptr->row_info.rowbytes);
|
|
565
|
|
566 #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
|
|
567 /* handle interlacing */
|
|
568 if (png_ptr->interlaced && png_ptr->pass < 6 &&
|
|
569 (png_ptr->transformations & PNG_INTERLACE))
|
|
570 {
|
|
571 png_do_write_interlace(&(png_ptr->row_info),
|
|
572 png_ptr->row_buf + 1, png_ptr->pass);
|
|
573 /* this should always get caught above, but still ... */
|
|
574 if (!(png_ptr->row_info.width))
|
|
575 {
|
|
576 png_write_finish_row(png_ptr);
|
|
577 return;
|
|
578 }
|
|
579 }
|
|
580 #endif
|
|
581
|
|
582 #if 0
|
|
583 /* handle other transformations */
|
|
584 if (png_ptr->transformations)
|
|
585 png_do_write_transformations(png_ptr);
|
|
586 #endif
|
|
587
|
|
588 #if defined(PNG_MNG_FEATURES_SUPPORTED)
|
|
589 /* Write filter_method 64 (intrapixel differencing) only if
|
|
590 * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
|
|
591 * 2. Libpng did not write a PNG signature (this filter_method is only
|
|
592 * used in PNG datastreams that are embedded in MNG datastreams) and
|
|
593 * 3. The application called png_permit_mng_features with a mask that
|
|
594 * included PNG_FLAG_MNG_FILTER_64 and
|
|
595 * 4. The filter_method is 64 and
|
|
596 * 5. The color_type is RGB or RGBA
|
|
597 */
|
|
598 if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
|
|
599 (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
|
|
600 {
|
|
601 /* Intrapixel differencing */
|
|
602 png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
|
|
603 }
|
|
604 #endif
|
|
605
|
|
606 /* Find a filter if necessary, filter the row and write it out. */
|
|
607 png_write_find_filter(png_ptr, &(png_ptr->row_info));
|
|
608
|
|
609 if (png_ptr->write_row_fn != NULL)
|
|
610 (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
|
|
611 }
|
|
612
|
|
613 /* Free any memory used in png_ptr struct (old method) */
|
|
614 void /* PRIVATE */
|
|
615 png_write_destroy(png_structp png_ptr)
|
|
616 {
|
|
617 #ifdef PNG_SETJMP_SUPPORTED
|
|
618 jmp_buf tmp_jmp; /* save jump buffer */
|
|
619 #endif
|
|
620 #ifdef PNG_USER_MEM_SUPPORTED
|
|
621 png_free_ptr free_fn;
|
|
622 #endif
|
|
623
|
|
624 png_debug(1, "in png_write_destroy\n");
|
|
625 /* free any memory zlib uses */
|
|
626 deflateEnd(&png_ptr->zstream);
|
|
627
|
|
628 /* free our memory. png_free checks NULL for us. */
|
|
629 png_free(png_ptr, png_ptr->zbuf);
|
|
630 png_free(png_ptr, png_ptr->row_buf);
|
|
631 png_free(png_ptr, png_ptr->prev_row);
|
|
632 png_free(png_ptr, png_ptr->sub_row);
|
|
633 png_free(png_ptr, png_ptr->up_row);
|
|
634 png_free(png_ptr, png_ptr->avg_row);
|
|
635 png_free(png_ptr, png_ptr->paeth_row);
|
|
636
|
|
637 #if defined(PNG_TIME_RFC1123_SUPPORTED)
|
|
638 png_free(png_ptr, png_ptr->time_buffer);
|
|
639 #endif
|
|
640
|
|
641 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
|
|
642 png_free(png_ptr, png_ptr->prev_filters);
|
|
643 png_free(png_ptr, png_ptr->filter_weights);
|
|
644 png_free(png_ptr, png_ptr->inv_filter_weights);
|
|
645 png_free(png_ptr, png_ptr->filter_costs);
|
|
646 png_free(png_ptr, png_ptr->inv_filter_costs);
|
|
647 #endif
|
|
648
|
|
649 #ifdef PNG_SETJMP_SUPPORTED
|
|
650 /* reset structure */
|
|
651 png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
|
|
652 #endif
|
|
653
|
|
654 #ifdef PNG_USER_MEM_SUPPORTED
|
|
655 free_fn = png_ptr->free_fn;
|
|
656 #endif
|
|
657
|
|
658 png_memset(png_ptr, 0, sizeof (png_struct));
|
|
659
|
|
660 #ifdef PNG_USER_MEM_SUPPORTED
|
|
661 png_ptr->free_fn = free_fn;
|
|
662 #endif
|
|
663
|
|
664 #ifdef PNG_SETJMP_SUPPORTED
|
|
665 png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
|
|
666 #endif
|
|
667 }
|
|
668
|
|
669 /* Allow the application to select one or more row filters to use. */
|
|
670 void PNGAPI
|
|
671 png_set_filter(png_structp png_ptr, int method, int filters)
|
|
672 {
|
|
673 png_debug(1, "in png_set_filter\n");
|
|
674 #if defined(PNG_MNG_FEATURES_SUPPORTED)
|
|
675 if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
|
|
676 (method == PNG_INTRAPIXEL_DIFFERENCING))
|
|
677 method = PNG_FILTER_TYPE_BASE;
|
|
678 #endif
|
|
679 if (method == PNG_FILTER_TYPE_BASE)
|
|
680 {
|
|
681 switch (filters & (PNG_ALL_FILTERS | 0x07))
|
|
682 {
|
|
683 case 5:
|
|
684 case 6:
|
|
685 case 7: png_warning(png_ptr, "Unknown row filter for method 0");
|
|
686 case PNG_FILTER_VALUE_NONE: png_ptr->do_filter=PNG_FILTER_NONE; break;
|
|
687 case PNG_FILTER_VALUE_SUB: png_ptr->do_filter=PNG_FILTER_SUB; break;
|
|
688 case PNG_FILTER_VALUE_UP: png_ptr->do_filter=PNG_FILTER_UP; break;
|
|
689 case PNG_FILTER_VALUE_AVG: png_ptr->do_filter=PNG_FILTER_AVG; break;
|
|
690 case PNG_FILTER_VALUE_PAETH: png_ptr->do_filter=PNG_FILTER_PAETH;break;
|
|
691 default: png_ptr->do_filter = (png_byte)filters; break;
|
|
692 }
|
|
693
|
|
694 /* If we have allocated the row_buf, this means we have already started
|
|
695 * with the image and we should have allocated all of the filter buffers
|
|
696 * that have been selected. If prev_row isn't already allocated, then
|
|
697 * it is too late to start using the filters that need it, since we
|
|
698 * will be missing the data in the previous row. If an application
|
|
699 * wants to start and stop using particular filters during compression,
|
|
700 * it should start out with all of the filters, and then add and
|
|
701 * remove them after the start of compression.
|
|
702 */
|
|
703 if (png_ptr->row_buf != NULL)
|
|
704 {
|
|
705 if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
|
|
706 {
|
|
707 png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
|
|
708 (png_ptr->rowbytes + 1));
|
|
709 png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
|
|
710 }
|
|
711
|
|
712 if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
|
|
713 {
|
|
714 if (png_ptr->prev_row == NULL)
|
|
715 {
|
|
716 png_warning(png_ptr, "Can't add Up filter after starting");
|
|
717 png_ptr->do_filter &= ~PNG_FILTER_UP;
|
|
718 }
|
|
719 else
|
|
720 {
|
|
721 png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
|
|
722 (png_ptr->rowbytes + 1));
|
|
723 png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
|
|
724 }
|
|
725 }
|
|
726
|
|
727 if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
|
|
728 {
|
|
729 if (png_ptr->prev_row == NULL)
|
|
730 {
|
|
731 png_warning(png_ptr, "Can't add Average filter after starting");
|
|
732 png_ptr->do_filter &= ~PNG_FILTER_AVG;
|
|
733 }
|
|
734 else
|
|
735 {
|
|
736 png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
|
|
737 (png_ptr->rowbytes + 1));
|
|
738 png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
|
|
739 }
|
|
740 }
|
|
741
|
|
742 if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
|
|
743 png_ptr->paeth_row == NULL)
|
|
744 {
|
|
745 if (png_ptr->prev_row == NULL)
|
|
746 {
|
|
747 png_warning(png_ptr, "Can't add Paeth filter after starting");
|
|
748 png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
|
|
749 }
|
|
750 else
|
|
751 {
|
|
752 png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
|
|
753 (png_ptr->rowbytes + 1));
|
|
754 png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
|
|
755 }
|
|
756 }
|
|
757
|
|
758 if (png_ptr->do_filter == PNG_NO_FILTERS)
|
|
759 png_ptr->do_filter = PNG_FILTER_NONE;
|
|
760 }
|
|
761 }
|
|
762 else
|
|
763 png_error(png_ptr, "Unknown custom filter method");
|
|
764 }
|
|
765
|
|
766 /* This allows us to influence the way in which libpng chooses the "best"
|
|
767 * filter for the current scanline. While the "minimum-sum-of-absolute-
|
|
768 * differences metric is relatively fast and effective, there is some
|
|
769 * question as to whether it can be improved upon by trying to keep the
|
|
770 * filtered data going to zlib more consistent, hopefully resulting in
|
|
771 * better compression.
|
|
772 */
|
|
773 #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
|
|
774 void PNGAPI
|
|
775 png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
|
|
776 int num_weights, png_doublep filter_weights,
|
|
777 png_doublep filter_costs)
|
|
778 {
|
|
779 int i;
|
|
780
|
|
781 png_debug(1, "in png_set_filter_heuristics\n");
|
|
782 if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
|
|
783 {
|
|
784 png_warning(png_ptr, "Unknown filter heuristic method");
|
|
785 return;
|
|
786 }
|
|
787
|
|
788 if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
|
|
789 {
|
|
790 heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
|
|
791 }
|
|
792
|
|
793 if (num_weights < 0 || filter_weights == NULL ||
|
|
794 heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
|
|
795 {
|
|
796 num_weights = 0;
|
|
797 }
|
|
798
|
|
799 png_ptr->num_prev_filters = (png_byte)num_weights;
|
|
800 png_ptr->heuristic_method = (png_byte)heuristic_method;
|
|
801
|
|
802 if (num_weights > 0)
|
|
803 {
|
|
804 if (png_ptr->prev_filters == NULL)
|
|
805 {
|
|
806 png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
|
|
807 (png_uint_32)(sizeof(png_byte) * num_weights));
|
|
808
|
|
809 /* To make sure that the weighting starts out fairly */
|
|
810 for (i = 0; i < num_weights; i++)
|
|
811 {
|
|
812 png_ptr->prev_filters[i] = 255;
|
|
813 }
|
|
814 }
|
|
815
|
|
816 if (png_ptr->filter_weights == NULL)
|
|
817 {
|
|
818 png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
|
|
819 (png_uint_32)(sizeof(png_uint_16) * num_weights));
|
|
820
|
|
821 png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
|
|
822 (png_uint_32)(sizeof(png_uint_16) * num_weights));
|
|
823 for (i = 0; i < num_weights; i++)
|
|
824 {
|
|
825 png_ptr->inv_filter_weights[i] =
|
|
826 png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
|
|
827 }
|
|
828 }
|
|
829
|
|
830 for (i = 0; i < num_weights; i++)
|
|
831 {
|
|
832 if (filter_weights[i] < 0.0)
|
|
833 {
|
|
834 png_ptr->inv_filter_weights[i] =
|
|
835 png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
|
|
836 }
|
|
837 else
|
|
838 {
|
|
839 png_ptr->inv_filter_weights[i] =
|
|
840 (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
|
|
841 png_ptr->filter_weights[i] =
|
|
842 (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
|
|
843 }
|
|
844 }
|
|
845 }
|
|
846
|
|
847 /* If, in the future, there are other filter methods, this would
|
|
848 * need to be based on png_ptr->filter.
|
|
849 */
|
|
850 if (png_ptr->filter_costs == NULL)
|
|
851 {
|
|
852 png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
|
|
853 (png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
|
|
854
|
|
855 png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
|
|
856 (png_uint_32)(sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
|
|
857
|
|
858 for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
|
|
859 {
|
|
860 png_ptr->inv_filter_costs[i] =
|
|
861 png_ptr->filter_costs[i] = PNG_COST_FACTOR;
|
|
862 }
|
|
863 }
|
|
864
|
|
865 /* Here is where we set the relative costs of the different filters. We
|
|
866 * should take the desired compression level into account when setting
|
|
867 * the costs, so that Paeth, for instance, has a high relative cost at low
|
|
868 * compression levels, while it has a lower relative cost at higher
|
|
869 * compression settings. The filter types are in order of increasing
|
|
870 * relative cost, so it would be possible to do this with an algorithm.
|
|
871 */
|
|
872 for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
|
|
873 {
|
|
874 if (filter_costs == NULL || filter_costs[i] < 0.0)
|
|
875 {
|
|
876 png_ptr->inv_filter_costs[i] =
|
|
877 png_ptr->filter_costs[i] = PNG_COST_FACTOR;
|
|
878 }
|
|
879 else if (filter_costs[i] >= 1.0)
|
|
880 {
|
|
881 png_ptr->inv_filter_costs[i] =
|
|
882 (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
|
|
883 png_ptr->filter_costs[i] =
|
|
884 (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
|
|
885 }
|
|
886 }
|
|
887 }
|
|
888 #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
|
|
889
|
|
890 void PNGAPI
|
|
891 png_set_compression_level(png_structp png_ptr, int level)
|
|
892 {
|
|
893 png_debug(1, "in png_set_compression_level\n");
|
|
894 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
|
|
895 png_ptr->zlib_level = level;
|
|
896 }
|
|
897
|
|
898 void PNGAPI
|
|
899 png_set_compression_mem_level(png_structp png_ptr, int mem_level)
|
|
900 {
|
|
901 png_debug(1, "in png_set_compression_mem_level\n");
|
|
902 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
|
|
903 png_ptr->zlib_mem_level = mem_level;
|
|
904 }
|
|
905
|
|
906 void PNGAPI
|
|
907 png_set_compression_strategy(png_structp png_ptr, int strategy)
|
|
908 {
|
|
909 png_debug(1, "in png_set_compression_strategy\n");
|
|
910 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
|
|
911 png_ptr->zlib_strategy = strategy;
|
|
912 }
|
|
913
|
|
914 void PNGAPI
|
|
915 png_set_compression_window_bits(png_structp png_ptr, int window_bits)
|
|
916 {
|
|
917 if (window_bits > 15)
|
|
918 png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
|
|
919 else if (window_bits < 8)
|
|
920 png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
|
|
921 #ifndef WBITS_8_OK
|
|
922 /* avoid libpng bug with 256-byte windows */
|
|
923 if (window_bits == 8)
|
|
924 {
|
|
925 png_warning(png_ptr, "Compression window is being reset to 512");
|
|
926 window_bits=9;
|
|
927 }
|
|
928 #endif
|
|
929 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
|
|
930 png_ptr->zlib_window_bits = window_bits;
|
|
931 }
|
|
932
|
|
933 void PNGAPI
|
|
934 png_set_compression_method(png_structp png_ptr, int method)
|
|
935 {
|
|
936 png_debug(1, "in png_set_compression_method\n");
|
|
937 if (method != 8)
|
|
938 png_warning(png_ptr, "Only compression method 8 is supported by PNG");
|
|
939 png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
|
|
940 png_ptr->zlib_method = method;
|
|
941 }
|
|
942
|
|
943 #endif /* PNG_WRITE_SUPPORTED */
|