Prusa MINI Firmware overview
pngwrite.c File Reference
#include "pngpriv.h"
#include <errno.h>

Classes

struct  png_image_write_control
 

Macros

#define UNP_RECIPROCAL(alpha)   ((((0xffff*0xff)<<7)+((alpha)>>1))/(alpha))
 

Functions

static void write_unknown_chunks (png_structrp png_ptr, png_const_inforp info_ptr, unsigned int where)
 
void PNGAPI png_write_info_before_PLTE (png_structrp png_ptr, png_const_inforp info_ptr)
 
void PNGAPI png_write_info (png_structrp png_ptr, png_const_inforp info_ptr)
 
void PNGAPI png_write_end (png_structrp png_ptr, png_inforp info_ptr)
 
void PNGAPI png_convert_from_struct_tm (png_timep ptime, const struct tm *ttime)
 
void PNGAPI png_convert_from_time_t (png_timep ptime, time_t ttime)
 
 PNG_FUNCTION (png_structp, PNGAPI png_create_write_struct,(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn), PNG_ALLOCATED)
 
 PNG_FUNCTION (png_structp, PNGAPI png_create_write_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn), PNG_ALLOCATED)
 
void PNGAPI png_write_rows (png_structrp png_ptr, png_bytepp row, png_uint_32 num_rows)
 
void PNGAPI png_write_image (png_structrp png_ptr, png_bytepp image)
 
static void png_do_write_intrapixel (png_row_infop row_info, png_bytep row)
 
void PNGAPI png_write_row (png_structrp png_ptr, png_const_bytep row)
 
void PNGAPI png_set_flush (png_structrp png_ptr, int nrows)
 
void PNGAPI png_write_flush (png_structrp png_ptr)
 
static void png_write_destroy (png_structrp png_ptr)
 
void PNGAPI png_destroy_write_struct (png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
 
void PNGAPI png_set_filter (png_structrp png_ptr, int method, int filters)
 
void PNGAPI png_set_filter_heuristics (png_structrp png_ptr, int heuristic_method, int num_weights, png_const_doublep filter_weights, png_const_doublep filter_costs)
 
void PNGAPI png_set_filter_heuristics_fixed (png_structrp png_ptr, int heuristic_method, int num_weights, png_const_fixed_point_p filter_weights, png_const_fixed_point_p filter_costs)
 
void PNGAPI png_set_compression_level (png_structrp png_ptr, int level)
 
void PNGAPI png_set_compression_mem_level (png_structrp png_ptr, int mem_level)
 
void PNGAPI png_set_compression_strategy (png_structrp png_ptr, int strategy)
 
void PNGAPI png_set_compression_window_bits (png_structrp png_ptr, int window_bits)
 
void PNGAPI png_set_compression_method (png_structrp png_ptr, int method)
 
void PNGAPI png_set_text_compression_level (png_structrp png_ptr, int level)
 
void PNGAPI png_set_text_compression_mem_level (png_structrp png_ptr, int mem_level)
 
void PNGAPI png_set_text_compression_strategy (png_structrp png_ptr, int strategy)
 
void PNGAPI png_set_text_compression_window_bits (png_structrp png_ptr, int window_bits)
 
void PNGAPI png_set_text_compression_method (png_structrp png_ptr, int method)
 
void PNGAPI png_set_write_status_fn (png_structrp png_ptr, png_write_status_ptr write_row_fn)
 
void PNGAPI png_set_write_user_transform_fn (png_structrp png_ptr, png_user_transform_ptr write_user_transform_fn)
 
void PNGAPI png_write_png (png_structrp png_ptr, png_inforp info_ptr, int transforms, voidp params)
 
static int png_image_write_init (png_imagep image)
 
static int png_write_image_16bit (png_voidp argument)
 
static png_byte png_unpremultiply (png_uint_32 component, png_uint_32 alpha, png_uint_32 reciprocal)
 
static int png_write_image_8bit (png_voidp argument)
 
static void png_image_set_PLTE (png_image_write_control *display)
 
static int png_image_write_main (png_voidp argument)
 
static void (PNGCBAPI image_memory_write)(png_structp png_ptr
 
 if (size<=((png_alloc_size_t) -1) - ob)
 
else png_error (png_ptr, "png_image_write_to_memory: PNG too big")
 
static int png_image_write_memory (png_voidp argument)
 
int PNGAPI png_image_write_to_memory (png_imagep image, void *memory, png_alloc_size_t *PNG_RESTRICT memory_bytes, int convert_to_8bit, const void *buffer, png_int_32 row_stride, const void *colormap)
 
int PNGAPI png_image_write_to_stdio (png_imagep image, FILE *file, int convert_to_8bit, const void *buffer, png_int_32 row_stride, const void *colormap)
 
int PNGAPI png_image_write_to_file (png_imagep image, const char *file_name, int convert_to_8bit, const void *buffer, png_int_32 row_stride, const void *colormap)
 

Variables

static png_bytep data
 
static png_bytep size_t size
 
png_alloc_size_t ob = display->output_bytes
 

Macro Definition Documentation

◆ UNP_RECIPROCAL

#define UNP_RECIPROCAL (   alpha)    ((((0xffff*0xff)<<7)+((alpha)>>1))/(alpha))

Function Documentation

◆ write_unknown_chunks()

static void write_unknown_chunks ( png_structrp  png_ptr,
png_const_inforp  info_ptr,
unsigned int  where 
)
static
26 {
27  if (info_ptr->unknown_chunks_num != 0)
28  {
30 
31  png_debug(5, "writing extra chunks");
32 
33  for (up = info_ptr->unknown_chunks;
34  up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
35  ++up)
36  if ((up->location & where) != 0)
37  {
38  /* If per-chunk unknown chunk handling is enabled use it, otherwise
39  * just write the chunks the application has set.
40  */
41 #ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
42  int keep = png_handle_as_unknown(png_ptr, up->name);
43 
44  /* NOTE: this code is radically different from the read side in the
45  * matter of handling an ancillary unknown chunk. In the read side
46  * the default behavior is to discard it, in the code below the default
47  * behavior is to write it. Critical chunks are, however, only
48  * written if explicitly listed or if the default is set to write all
49  * unknown chunks.
50  *
51  * The default handling is also slightly weird - it is not possible to
52  * stop the writing of all unsafe-to-copy chunks!
53  *
54  * TODO: REVIEW: this would seem to be a bug.
55  */
56  if (keep != PNG_HANDLE_CHUNK_NEVER &&
57  ((up->name[3] & 0x20) /* safe-to-copy overrides everything */ ||
58  keep == PNG_HANDLE_CHUNK_ALWAYS ||
59  (keep == PNG_HANDLE_CHUNK_AS_DEFAULT &&
60  png_ptr->unknown_default == PNG_HANDLE_CHUNK_ALWAYS)))
61 #endif
62  {
63  /* TODO: review, what is wrong with a zero length unknown chunk? */
64  if (up->size == 0)
65  png_warning(png_ptr, "Writing zero-length unknown chunk");
66 
67  png_write_chunk(png_ptr, up->name, up->data, up->size);
68  }
69  }
70  }
71 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ png_write_info_before_PLTE()

void PNGAPI png_write_info_before_PLTE ( png_structrp  png_ptr,
png_const_inforp  info_ptr 
)
85 {
86  png_debug(1, "in png_write_info_before_PLTE");
87 
88  if (png_ptr == NULL || info_ptr == NULL)
89  return;
90 
91  if ((png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE) == 0)
92  {
93  /* Write PNG signature */
95 
96 #ifdef PNG_MNG_FEATURES_SUPPORTED
97  if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) != 0 && \
98  png_ptr->mng_features_permitted != 0)
99  {
101  "MNG features are not allowed in a PNG datastream");
102  png_ptr->mng_features_permitted = 0;
103  }
104 #endif
105 
106  /* Write IHDR information. */
107  png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
108  info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
109  info_ptr->filter_type,
111  info_ptr->interlace_type
112 #else
113  0
114 #endif
115  );
116 
117  /* The rest of these check to see if the valid field has the appropriate
118  * flag set, and if it does, writes the chunk.
119  *
120  * 1.6.0: COLORSPACE support controls the writing of these chunks too, and
121  * the chunks will be written if the WRITE routine is there and
122  * information * is available in the COLORSPACE. (See
123  * png_colorspace_sync_info in png.c for where the valid flags get set.)
124  *
125  * Under certain circumstances the colorspace can be invalidated without
126  * syncing the info_struct 'valid' flags; this happens if libpng detects
127  * an error and calls png_error while the color space is being set, yet
128  * the application continues writing the PNG. So check the 'invalid'
129  * flag here too.
130  */
131 #ifdef PNG_GAMMA_SUPPORTED
132 # ifdef PNG_WRITE_gAMA_SUPPORTED
133  if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
134  (info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_gAMA) != 0 &&
135  (info_ptr->valid & PNG_INFO_gAMA) != 0)
136  png_write_gAMA_fixed(png_ptr, info_ptr->colorspace.gamma);
137 # endif
138 #endif
139 
140 #ifdef PNG_COLORSPACE_SUPPORTED
141  /* Write only one of sRGB or an ICC profile. If a profile was supplied
142  * and it matches one of the known sRGB ones issue a warning.
143  */
144 # ifdef PNG_WRITE_iCCP_SUPPORTED
145  if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
146  (info_ptr->valid & PNG_INFO_iCCP) != 0)
147  {
148 # ifdef PNG_WRITE_sRGB_SUPPORTED
149  if ((info_ptr->valid & PNG_INFO_sRGB) != 0)
151  "profile matches sRGB but writing iCCP instead");
152 # endif
153 
154  png_write_iCCP(png_ptr, info_ptr->iccp_name,
155  info_ptr->iccp_profile);
156  }
157 # ifdef PNG_WRITE_sRGB_SUPPORTED
158  else
159 # endif
160 # endif
161 
162 # ifdef PNG_WRITE_sRGB_SUPPORTED
163  if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
164  (info_ptr->valid & PNG_INFO_sRGB) != 0)
165  png_write_sRGB(png_ptr, info_ptr->colorspace.rendering_intent);
166 # endif /* WRITE_sRGB */
167 #endif /* COLORSPACE */
168 
169 #ifdef PNG_WRITE_sBIT_SUPPORTED
170  if ((info_ptr->valid & PNG_INFO_sBIT) != 0)
171  png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
172 #endif
173 
174 #ifdef PNG_COLORSPACE_SUPPORTED
175 # ifdef PNG_WRITE_cHRM_SUPPORTED
176  if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&
177  (info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_cHRM) != 0 &&
178  (info_ptr->valid & PNG_INFO_cHRM) != 0)
179  png_write_cHRM_fixed(png_ptr, &info_ptr->colorspace.end_points_xy);
180 # endif
181 #endif
182 
183 #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
185 #endif
186 
188  }
189 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ png_write_info()

void PNGAPI png_write_info ( png_structrp  png_ptr,
png_const_inforp  info_ptr 
)
193 {
194 #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
195  int i;
196 #endif
197 
198  png_debug(1, "in png_write_info");
199 
200  if (png_ptr == NULL || info_ptr == NULL)
201  return;
202 
204 
205  if ((info_ptr->valid & PNG_INFO_PLTE) != 0)
206  png_write_PLTE(png_ptr, info_ptr->palette,
207  (png_uint_32)info_ptr->num_palette);
208 
209  else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
210  png_error(png_ptr, "Valid palette required for paletted images");
211 
212 #ifdef PNG_WRITE_tRNS_SUPPORTED
213  if ((info_ptr->valid & PNG_INFO_tRNS) !=0)
214  {
215 #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
216  /* Invert the alpha channel (in tRNS) */
217  if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0 &&
218  info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
219  {
220  int j, jend;
221 
222  jend = info_ptr->num_trans;
223  if (jend > PNG_MAX_PALETTE_LENGTH)
224  jend = PNG_MAX_PALETTE_LENGTH;
225 
226  for (j = 0; j<jend; ++j)
227  info_ptr->trans_alpha[j] =
228  (png_byte)(255 - info_ptr->trans_alpha[j]);
229  }
230 #endif
231  png_write_tRNS(png_ptr, info_ptr->trans_alpha, &(info_ptr->trans_color),
232  info_ptr->num_trans, info_ptr->color_type);
233  }
234 #endif
235 #ifdef PNG_WRITE_bKGD_SUPPORTED
236  if ((info_ptr->valid & PNG_INFO_bKGD) != 0)
237  png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
238 #endif
239 
240 #ifdef PNG_WRITE_eXIf_SUPPORTED
241  if ((info_ptr->valid & PNG_INFO_eXIf) != 0)
242  png_write_eXIf(png_ptr, info_ptr->exif, info_ptr->num_exif);
243 #endif
244 
245 #ifdef PNG_WRITE_hIST_SUPPORTED
246  if ((info_ptr->valid & PNG_INFO_hIST) != 0)
247  png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
248 #endif
249 
250 #ifdef PNG_WRITE_oFFs_SUPPORTED
251  if ((info_ptr->valid & PNG_INFO_oFFs) != 0)
252  png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
253  info_ptr->offset_unit_type);
254 #endif
255 
256 #ifdef PNG_WRITE_pCAL_SUPPORTED
257  if ((info_ptr->valid & PNG_INFO_pCAL) != 0)
258  png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
259  info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
260  info_ptr->pcal_units, info_ptr->pcal_params);
261 #endif
262 
263 #ifdef PNG_WRITE_sCAL_SUPPORTED
264  if ((info_ptr->valid & PNG_INFO_sCAL) != 0)
265  png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
266  info_ptr->scal_s_width, info_ptr->scal_s_height);
267 #endif /* sCAL */
268 
269 #ifdef PNG_WRITE_pHYs_SUPPORTED
270  if ((info_ptr->valid & PNG_INFO_pHYs) != 0)
271  png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
272  info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
273 #endif /* pHYs */
274 
275 #ifdef PNG_WRITE_tIME_SUPPORTED
276  if ((info_ptr->valid & PNG_INFO_tIME) != 0)
277  {
278  png_write_tIME(png_ptr, &(info_ptr->mod_time));
279  png_ptr->mode |= PNG_WROTE_tIME;
280  }
281 #endif /* tIME */
282 
283 #ifdef PNG_WRITE_sPLT_SUPPORTED
284  if ((info_ptr->valid & PNG_INFO_sPLT) != 0)
285  for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
286  png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
287 #endif /* sPLT */
288 
289 #ifdef PNG_WRITE_TEXT_SUPPORTED
290  /* Check to see if we need to write text chunks */
291  for (i = 0; i < info_ptr->num_text; i++)
292  {
293  png_debug2(2, "Writing header text chunk %d, type %d", i,
294  info_ptr->text[i].compression);
295  /* An internationalized chunk? */
296  if (info_ptr->text[i].compression > 0)
297  {
298 #ifdef PNG_WRITE_iTXt_SUPPORTED
299  /* Write international chunk */
301  info_ptr->text[i].compression,
302  info_ptr->text[i].key,
303  info_ptr->text[i].lang,
304  info_ptr->text[i].lang_key,
305  info_ptr->text[i].text);
306  /* Mark this chunk as written */
307  if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
308  info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
309  else
310  info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
311 #else
312  png_warning(png_ptr, "Unable to write international text");
313 #endif
314  }
315 
316  /* If we want a compressed text chunk */
317  else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
318  {
319 #ifdef PNG_WRITE_zTXt_SUPPORTED
320  /* Write compressed chunk */
321  png_write_zTXt(png_ptr, info_ptr->text[i].key,
322  info_ptr->text[i].text, info_ptr->text[i].compression);
323  /* Mark this chunk as written */
324  info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
325 #else
326  png_warning(png_ptr, "Unable to write compressed text");
327 #endif
328  }
329 
330  else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
331  {
332 #ifdef PNG_WRITE_tEXt_SUPPORTED
333  /* Write uncompressed chunk */
334  png_write_tEXt(png_ptr, info_ptr->text[i].key,
335  info_ptr->text[i].text,
336  0);
337  /* Mark this chunk as written */
338  info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
339 #else
340  /* Can't get here */
341  png_warning(png_ptr, "Unable to write uncompressed text");
342 #endif
343  }
344  }
345 #endif /* tEXt */
346 
347 #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
349 #endif
350 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ png_write_end()

void PNGAPI png_write_end ( png_structrp  png_ptr,
png_inforp  info_ptr 
)
359 {
360  png_debug(1, "in png_write_end");
361 
362  if (png_ptr == NULL)
363  return;
364 
365  if ((png_ptr->mode & PNG_HAVE_IDAT) == 0)
366  png_error(png_ptr, "No IDATs written into file");
367 
368 #ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED
369  if (png_ptr->num_palette_max > png_ptr->num_palette)
370  png_benign_error(png_ptr, "Wrote palette index exceeding num_palette");
371 #endif
372 
373  /* See if user wants us to write information chunks */
374  if (info_ptr != NULL)
375  {
376 #ifdef PNG_WRITE_TEXT_SUPPORTED
377  int i; /* local index variable */
378 #endif
379 #ifdef PNG_WRITE_tIME_SUPPORTED
380  /* Check to see if user has supplied a time chunk */
381  if ((info_ptr->valid & PNG_INFO_tIME) != 0 &&
382  (png_ptr->mode & PNG_WROTE_tIME) == 0)
383  png_write_tIME(png_ptr, &(info_ptr->mod_time));
384 
385 #endif
386 #ifdef PNG_WRITE_TEXT_SUPPORTED
387  /* Loop through comment chunks */
388  for (i = 0; i < info_ptr->num_text; i++)
389  {
390  png_debug2(2, "Writing trailer text chunk %d, type %d", i,
391  info_ptr->text[i].compression);
392  /* An internationalized chunk? */
393  if (info_ptr->text[i].compression > 0)
394  {
395 #ifdef PNG_WRITE_iTXt_SUPPORTED
396  /* Write international chunk */
398  info_ptr->text[i].compression,
399  info_ptr->text[i].key,
400  info_ptr->text[i].lang,
401  info_ptr->text[i].lang_key,
402  info_ptr->text[i].text);
403  /* Mark this chunk as written */
404  if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
405  info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
406  else
407  info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
408 #else
409  png_warning(png_ptr, "Unable to write international text");
410 #endif
411  }
412 
413  else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
414  {
415 #ifdef PNG_WRITE_zTXt_SUPPORTED
416  /* Write compressed chunk */
417  png_write_zTXt(png_ptr, info_ptr->text[i].key,
418  info_ptr->text[i].text, info_ptr->text[i].compression);
419  /* Mark this chunk as written */
420  info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
421 #else
422  png_warning(png_ptr, "Unable to write compressed text");
423 #endif
424  }
425 
426  else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
427  {
428 #ifdef PNG_WRITE_tEXt_SUPPORTED
429  /* Write uncompressed chunk */
430  png_write_tEXt(png_ptr, info_ptr->text[i].key,
431  info_ptr->text[i].text, 0);
432  /* Mark this chunk as written */
433  info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
434 #else
435  png_warning(png_ptr, "Unable to write uncompressed text");
436 #endif
437  }
438  }
439 #endif
440 
441 #ifdef PNG_WRITE_eXIf_SUPPORTED
442  if ((info_ptr->valid & PNG_INFO_eXIf) != 0)
443  png_write_eXIf(png_ptr, info_ptr->exif, info_ptr->num_exif);
444 #endif
445 
446 #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
448 #endif
449  }
450 
451  png_ptr->mode |= PNG_AFTER_IDAT;
452 
453  /* Write end of PNG file */
455 
456  /* This flush, added in libpng-1.0.8, removed from libpng-1.0.9beta03,
457  * and restored again in libpng-1.2.30, may cause some applications that
458  * do not set png_ptr->output_flush_fn to crash. If your application
459  * experiences a problem, please try building libpng with
460  * PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to
461  * png-mng-implement at lists.sf.net .
462  */
463 #ifdef PNG_WRITE_FLUSH_SUPPORTED
464 # ifdef PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED
466 # endif
467 #endif
468 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ png_convert_from_struct_tm()

void PNGAPI png_convert_from_struct_tm ( png_timep  ptime,
const struct tm *  ttime 
)
473 {
474  png_debug(1, "in png_convert_from_struct_tm");
475 
476  ptime->year = (png_uint_16)(1900 + ttime->tm_year);
477  ptime->month = (png_byte)(ttime->tm_mon + 1);
478  ptime->day = (png_byte)ttime->tm_mday;
479  ptime->hour = (png_byte)ttime->tm_hour;
480  ptime->minute = (png_byte)ttime->tm_min;
481  ptime->second = (png_byte)ttime->tm_sec;
482 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ png_convert_from_time_t()

void PNGAPI png_convert_from_time_t ( png_timep  ptime,
time_t  ttime 
)
486 {
487  struct tm *tbuf;
488 
489  png_debug(1, "in png_convert_from_time_t");
490 
491  tbuf = gmtime(&ttime);
492  png_convert_from_struct_tm(ptime, tbuf);
493 }
Here is the call graph for this function:

◆ PNG_FUNCTION() [1/2]

PNG_FUNCTION ( png_structp  ,
PNGAPI  png_create_write_struct,
(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn)  ,
PNG_ALLOCATED   
)
500 {
501 #ifndef PNG_USER_MEM_SUPPORTED
502  png_structrp png_ptr = png_create_png_struct(user_png_ver, error_ptr,
503  error_fn, warn_fn, NULL, NULL, NULL);
504 #else
505  return png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
506  warn_fn, NULL, NULL, NULL);
507 }

◆ PNG_FUNCTION() [2/2]

PNG_FUNCTION ( png_structp  ,
PNGAPI  png_create_write_struct_2,
(png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn)  ,
PNG_ALLOCATED   
)
514 {
515  png_structrp png_ptr = png_create_png_struct(user_png_ver, error_ptr,
516  error_fn, warn_fn, mem_ptr, malloc_fn, free_fn);
517 #endif /* USER_MEM */
518  if (png_ptr != NULL)
519  {
520  /* Set the zlib control values to defaults; they can be overridden by the
521  * application after the struct has been created.
522  */
523  png_ptr->zbuffer_size = PNG_ZBUF_SIZE;
524 
525  /* The 'zlib_strategy' setting is irrelevant because png_default_claim in
526  * pngwutil.c defaults it according to whether or not filters will be
527  * used, and ignores this setting.
528  */
529  png_ptr->zlib_strategy = PNG_Z_DEFAULT_STRATEGY;
530  png_ptr->zlib_level = PNG_Z_DEFAULT_COMPRESSION;
531  png_ptr->zlib_mem_level = 8;
532  png_ptr->zlib_window_bits = 15;
533  png_ptr->zlib_method = 8;
534 
535 #ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED
536  png_ptr->zlib_text_strategy = PNG_TEXT_Z_DEFAULT_STRATEGY;
537  png_ptr->zlib_text_level = PNG_TEXT_Z_DEFAULT_COMPRESSION;
538  png_ptr->zlib_text_mem_level = 8;
539  png_ptr->zlib_text_window_bits = 15;
540  png_ptr->zlib_text_method = 8;
541 #endif /* WRITE_COMPRESSED_TEXT */
542 
543  /* This is a highly dubious configuration option; by default it is off,
544  * but it may be appropriate for private builds that are testing
545  * extensions not conformant to the current specification, or of
546  * applications that must not fail to write at all costs!
547  */
548 #ifdef PNG_BENIGN_WRITE_ERRORS_SUPPORTED
549  /* In stable builds only warn if an application error can be completely
550  * handled.
551  */
553 #endif
554 
555  /* App warnings are warnings in release (or release candidate) builds but
556  * are errors during development.
557  */
558 #if PNG_RELEASE_BUILD
560 #endif
561 
562  /* TODO: delay this, it can be done in png_init_io() (if the app doesn't
563  * do it itself) avoiding setting the default function if it is not
564  * required.
565  */
567  }
568 
569  return png_ptr;
570 }
Here is the call graph for this function:

◆ png_write_rows()

void PNGAPI png_write_rows ( png_structrp  png_ptr,
png_bytepp  row,
png_uint_32  num_rows 
)
581 {
582  png_uint_32 i; /* row counter */
583  png_bytepp rp; /* row pointer */
584 
585  png_debug(1, "in png_write_rows");
586 
587  if (png_ptr == NULL)
588  return;
589 
590  /* Loop through the rows */
591  for (i = 0, rp = row; i < num_rows; i++, rp++)
592  {
593  png_write_row(png_ptr, *rp);
594  }
595 }
Here is the call graph for this function:

◆ png_write_image()

void PNGAPI png_write_image ( png_structrp  png_ptr,
png_bytepp  image 
)
602 {
603  png_uint_32 i; /* row index */
604  int pass, num_pass; /* pass variables */
605  png_bytepp rp; /* points to current row */
606 
607  if (png_ptr == NULL)
608  return;
609 
610  png_debug(1, "in png_write_image");
611 
612 #ifdef PNG_WRITE_INTERLACING_SUPPORTED
613  /* Initialize interlace handling. If image is not interlaced,
614  * this will set pass to 1
615  */
617 #else
618  num_pass = 1;
619 #endif
620  /* Loop through passes */
621  for (pass = 0; pass < num_pass; pass++)
622  {
623  /* Loop through image */
624  for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
625  {
626  png_write_row(png_ptr, *rp);
627  }
628  }
629 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ png_do_write_intrapixel()

static void png_do_write_intrapixel ( png_row_infop  row_info,
png_bytep  row 
)
static
635 {
636  png_debug(1, "in png_do_write_intrapixel");
637 
638  if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)
639  {
640  int bytes_per_pixel;
641  png_uint_32 row_width = row_info->width;
642  if (row_info->bit_depth == 8)
643  {
644  png_bytep rp;
645  png_uint_32 i;
646 
647  if (row_info->color_type == PNG_COLOR_TYPE_RGB)
648  bytes_per_pixel = 3;
649 
650  else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
651  bytes_per_pixel = 4;
652 
653  else
654  return;
655 
656  for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
657  {
658  *(rp) = (png_byte)(*rp - *(rp + 1));
659  *(rp + 2) = (png_byte)(*(rp + 2) - *(rp + 1));
660  }
661  }
662 
663 #ifdef PNG_WRITE_16BIT_SUPPORTED
664  else if (row_info->bit_depth == 16)
665  {
666  png_bytep rp;
667  png_uint_32 i;
668 
669  if (row_info->color_type == PNG_COLOR_TYPE_RGB)
670  bytes_per_pixel = 6;
671 
672  else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
673  bytes_per_pixel = 8;
674 
675  else
676  return;
677 
678  for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
679  {
680  png_uint_32 s0 = (png_uint_32)(*(rp ) << 8) | *(rp + 1);
681  png_uint_32 s1 = (png_uint_32)(*(rp + 2) << 8) | *(rp + 3);
682  png_uint_32 s2 = (png_uint_32)(*(rp + 4) << 8) | *(rp + 5);
683  png_uint_32 red = (png_uint_32)((s0 - s1) & 0xffffL);
684  png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL);
685  *(rp ) = (png_byte)(red >> 8);
686  *(rp + 1) = (png_byte)red;
687  *(rp + 4) = (png_byte)(blue >> 8);
688  *(rp + 5) = (png_byte)blue;
689  }
690  }
691 #endif /* WRITE_16BIT */
692  }
693 }
Here is the caller graph for this function:

◆ png_write_row()

void PNGAPI png_write_row ( png_structrp  png_ptr,
png_const_bytep  row 
)
699 {
700  /* 1.5.6: moved from png_struct to be a local structure: */
701  png_row_info row_info;
702 
703  if (png_ptr == NULL)
704  return;
705 
706  png_debug2(1, "in png_write_row (row %u, pass %d)",
707  png_ptr->row_number, png_ptr->pass);
708 
709  /* Initialize transformations and other stuff if first time */
710  if (png_ptr->row_number == 0 && png_ptr->pass == 0)
711  {
712  /* Make sure we wrote the header info */
713  if ((png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE) == 0)
715  "png_write_info was never called before png_write_row");
716 
717  /* Check for transforms that have been set but were defined out */
718 #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
719  if ((png_ptr->transformations & PNG_INVERT_MONO) != 0)
720  png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined");
721 #endif
722 
723 #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
724  if ((png_ptr->transformations & PNG_FILLER) != 0)
725  png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined");
726 #endif
727 #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \
728  defined(PNG_READ_PACKSWAP_SUPPORTED)
729  if ((png_ptr->transformations & PNG_PACKSWAP) != 0)
731  "PNG_WRITE_PACKSWAP_SUPPORTED is not defined");
732 #endif
733 
734 #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
735  if ((png_ptr->transformations & PNG_PACK) != 0)
736  png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined");
737 #endif
738 
739 #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
740  if ((png_ptr->transformations & PNG_SHIFT) != 0)
741  png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined");
742 #endif
743 
744 #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
745  if ((png_ptr->transformations & PNG_BGR) != 0)
746  png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined");
747 #endif
748 
749 #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
750  if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0)
751  png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined");
752 #endif
753 
755  }
756 
757 #ifdef PNG_WRITE_INTERLACING_SUPPORTED
758  /* If interlaced and not interested in row, return */
759  if (png_ptr->interlaced != 0 &&
760  (png_ptr->transformations & PNG_INTERLACE) != 0)
761  {
762  switch (png_ptr->pass)
763  {
764  case 0:
765  if ((png_ptr->row_number & 0x07) != 0)
766  {
768  return;
769  }
770  break;
771 
772  case 1:
773  if ((png_ptr->row_number & 0x07) != 0 || png_ptr->width < 5)
774  {
776  return;
777  }
778  break;
779 
780  case 2:
781  if ((png_ptr->row_number & 0x07) != 4)
782  {
784  return;
785  }
786  break;
787 
788  case 3:
789  if ((png_ptr->row_number & 0x03) != 0 || png_ptr->width < 3)
790  {
792  return;
793  }
794  break;
795 
796  case 4:
797  if ((png_ptr->row_number & 0x03) != 2)
798  {
800  return;
801  }
802  break;
803 
804  case 5:
805  if ((png_ptr->row_number & 0x01) != 0 || png_ptr->width < 2)
806  {
808  return;
809  }
810  break;
811 
812  case 6:
813  if ((png_ptr->row_number & 0x01) == 0)
814  {
816  return;
817  }
818  break;
819 
820  default: /* error: ignore it */
821  break;
822  }
823  }
824 #endif
825 
826  /* Set up row info for transformations */
827  row_info.color_type = png_ptr->color_type;
828  row_info.width = png_ptr->usr_width;
829  row_info.channels = png_ptr->usr_channels;
830  row_info.bit_depth = png_ptr->usr_bit_depth;
831  row_info.pixel_depth = (png_byte)(row_info.bit_depth * row_info.channels);
832  row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width);
833 
834  png_debug1(3, "row_info->color_type = %d", row_info.color_type);
835  png_debug1(3, "row_info->width = %u", row_info.width);
836  png_debug1(3, "row_info->channels = %d", row_info.channels);
837  png_debug1(3, "row_info->bit_depth = %d", row_info.bit_depth);
838  png_debug1(3, "row_info->pixel_depth = %d", row_info.pixel_depth);
839  png_debug1(3, "row_info->rowbytes = %lu", (unsigned long)row_info.rowbytes);
840 
841  /* Copy user's row into buffer, leaving room for filter byte. */
842  memcpy(png_ptr->row_buf + 1, row, row_info.rowbytes);
843 
844 #ifdef PNG_WRITE_INTERLACING_SUPPORTED
845  /* Handle interlacing */
846  if (png_ptr->interlaced && png_ptr->pass < 6 &&
847  (png_ptr->transformations & PNG_INTERLACE) != 0)
848  {
849  png_do_write_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass);
850  /* This should always get caught above, but still ... */
851  if (row_info.width == 0)
852  {
854  return;
855  }
856  }
857 #endif
858 
859 #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
860  /* Handle other transformations */
861  if (png_ptr->transformations != 0)
863 #endif
864 
865  /* At this point the row_info pixel depth must match the 'transformed' depth,
866  * which is also the output depth.
867  */
868  if (row_info.pixel_depth != png_ptr->pixel_depth ||
869  row_info.pixel_depth != png_ptr->transformed_pixel_depth)
870  png_error(png_ptr, "internal write transform logic error");
871 
872 #ifdef PNG_MNG_FEATURES_SUPPORTED
873  /* Write filter_method 64 (intrapixel differencing) only if
874  * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
875  * 2. Libpng did not write a PNG signature (this filter_method is only
876  * used in PNG datastreams that are embedded in MNG datastreams) and
877  * 3. The application called png_permit_mng_features with a mask that
878  * included PNG_FLAG_MNG_FILTER_64 and
879  * 4. The filter_method is 64 and
880  * 5. The color_type is RGB or RGBA
881  */
882  if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 &&
883  (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
884  {
885  /* Intrapixel differencing */
886  png_do_write_intrapixel(&row_info, png_ptr->row_buf + 1);
887  }
888 #endif
889 
890 /* Added at libpng-1.5.10 */
891 #ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED
892  /* Check for out-of-range palette index */
893  if (row_info.color_type == PNG_COLOR_TYPE_PALETTE &&
894  png_ptr->num_palette_max >= 0)
896 #endif
897 
898  /* Find a filter if necessary, filter the row and write it out. */
899  png_write_find_filter(png_ptr, &row_info);
900 
901  if (png_ptr->write_row_fn != NULL)
902  (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
903 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ png_set_flush()

void PNGAPI png_set_flush ( png_structrp  png_ptr,
int  nrows 
)
909 {
910  png_debug(1, "in png_set_flush");
911 
912  if (png_ptr == NULL)
913  return;
914 
915  png_ptr->flush_dist = (nrows < 0 ? 0 : (png_uint_32)nrows);
916 }

◆ png_write_flush()

void PNGAPI png_write_flush ( png_structrp  png_ptr)
921 {
922  png_debug(1, "in png_write_flush");
923 
924  if (png_ptr == NULL)
925  return;
926 
927  /* We have already written out all of the data */
928  if (png_ptr->row_number >= png_ptr->num_rows)
929  return;
930 
932  png_ptr->flush_rows = 0;
934 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ png_write_destroy()

static void png_write_destroy ( png_structrp  png_ptr)
static
940 {
941  png_debug(1, "in png_write_destroy");
942 
943  /* Free any memory zlib uses */
944  if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0)
945  deflateEnd(&png_ptr->zstream);
946 
947  /* Free our memory. png_free checks NULL for us. */
948  png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list);
949  png_free(png_ptr, png_ptr->row_buf);
950  png_ptr->row_buf = NULL;
951 #ifdef PNG_READ_EXPANDED_SUPPORTED
952  png_free(png_ptr, png_ptr->riffled_palette);
953  png_ptr->riffled_palette = NULL;
954 #endif
955 #ifdef PNG_WRITE_FILTER_SUPPORTED
956  png_free(png_ptr, png_ptr->prev_row);
957  png_free(png_ptr, png_ptr->try_row);
958  png_free(png_ptr, png_ptr->tst_row);
959  png_ptr->prev_row = NULL;
960  png_ptr->try_row = NULL;
961  png_ptr->tst_row = NULL;
962 #endif
963 
964 #ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
965  png_free(png_ptr, png_ptr->chunk_list);
966  png_ptr->chunk_list = NULL;
967 #endif
968 
969  /* The error handling and memory handling information is left intact at this
970  * point: the jmp_buf may still have to be freed. See png_destroy_png_struct
971  * for how this happens.
972  */
973 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ png_destroy_write_struct()

void PNGAPI png_destroy_write_struct ( png_structpp  png_ptr_ptr,
png_infopp  info_ptr_ptr 
)
984 {
985  png_debug(1, "in png_destroy_write_struct");
986 
987  if (png_ptr_ptr != NULL)
988  {
989  png_structrp png_ptr = *png_ptr_ptr;
990 
991  if (png_ptr != NULL) /* added in libpng 1.6.0 */
992  {
993  png_destroy_info_struct(png_ptr, info_ptr_ptr);
994 
995  *png_ptr_ptr = NULL;
998  }
999  }
1000 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ png_set_filter()

void PNGAPI png_set_filter ( png_structrp  png_ptr,
int  method,
int  filters 
)
1005 {
1006  png_debug(1, "in png_set_filter");
1007 
1008  if (png_ptr == NULL)
1009  return;
1010 
1011 #ifdef PNG_MNG_FEATURES_SUPPORTED
1012  if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 &&
1013  (method == PNG_INTRAPIXEL_DIFFERENCING))
1014  method = PNG_FILTER_TYPE_BASE;
1015 
1016 #endif
1017  if (method == PNG_FILTER_TYPE_BASE)
1018  {
1019  switch (filters & (PNG_ALL_FILTERS | 0x07))
1020  {
1021 #ifdef PNG_WRITE_FILTER_SUPPORTED
1022  case 5:
1023  case 6:
1024  case 7: png_app_error(png_ptr, "Unknown row filter for method 0");
1025 #endif /* WRITE_FILTER */
1026  /* FALLTHROUGH */
1027  case PNG_FILTER_VALUE_NONE:
1028  png_ptr->do_filter = PNG_FILTER_NONE; break;
1029 
1030 #ifdef PNG_WRITE_FILTER_SUPPORTED
1031  case PNG_FILTER_VALUE_SUB:
1032  png_ptr->do_filter = PNG_FILTER_SUB; break;
1033 
1034  case PNG_FILTER_VALUE_UP:
1035  png_ptr->do_filter = PNG_FILTER_UP; break;
1036 
1037  case PNG_FILTER_VALUE_AVG:
1038  png_ptr->do_filter = PNG_FILTER_AVG; break;
1039 
1041  png_ptr->do_filter = PNG_FILTER_PAETH; break;
1042 
1043  default:
1044  png_ptr->do_filter = (png_byte)filters; break;
1045 #else
1046  default:
1047  png_app_error(png_ptr, "Unknown row filter for method 0");
1048 #endif /* WRITE_FILTER */
1049  }
1050 
1051 #ifdef PNG_WRITE_FILTER_SUPPORTED
1052  /* If we have allocated the row_buf, this means we have already started
1053  * with the image and we should have allocated all of the filter buffers
1054  * that have been selected. If prev_row isn't already allocated, then
1055  * it is too late to start using the filters that need it, since we
1056  * will be missing the data in the previous row. If an application
1057  * wants to start and stop using particular filters during compression,
1058  * it should start out with all of the filters, and then remove them
1059  * or add them back after the start of compression.
1060  *
1061  * NOTE: this is a nasty constraint on the code, because it means that the
1062  * prev_row buffer must be maintained even if there are currently no
1063  * 'prev_row' requiring filters active.
1064  */
1065  if (png_ptr->row_buf != NULL)
1066  {
1067  int num_filters;
1068  png_alloc_size_t buf_size;
1069 
1070  /* Repeat the checks in png_write_start_row; 1 pixel high or wide
1071  * images cannot benefit from certain filters. If this isn't done here
1072  * the check below will fire on 1 pixel high images.
1073  */
1074  if (png_ptr->height == 1)
1076 
1077  if (png_ptr->width == 1)
1079 
1081  && png_ptr->prev_row == NULL)
1082  {
1083  /* This is the error case, however it is benign - the previous row
1084  * is not available so the filter can't be used. Just warn here.
1085  */
1087  "png_set_filter: UP/AVG/PAETH cannot be added after start");
1089  }
1090 
1091  num_filters = 0;
1092 
1093  if (filters & PNG_FILTER_SUB)
1094  num_filters++;
1095 
1096  if (filters & PNG_FILTER_UP)
1097  num_filters++;
1098 
1099  if (filters & PNG_FILTER_AVG)
1100  num_filters++;
1101 
1102  if (filters & PNG_FILTER_PAETH)
1103  num_filters++;
1104 
1105  /* Allocate needed row buffers if they have not already been
1106  * allocated.
1107  */
1108  buf_size = PNG_ROWBYTES(png_ptr->usr_channels * png_ptr->usr_bit_depth,
1109  png_ptr->width) + 1;
1110 
1111  if (png_ptr->try_row == NULL)
1112  png_ptr->try_row = png_voidcast(png_bytep,
1113  png_malloc(png_ptr, buf_size));
1114 
1115  if (num_filters > 1)
1116  {
1117  if (png_ptr->tst_row == NULL)
1118  png_ptr->tst_row = png_voidcast(png_bytep,
1119  png_malloc(png_ptr, buf_size));
1120  }
1121  }
1122  png_ptr->do_filter = (png_byte)filters;
1123 #endif
1124  }
1125  else
1126  png_error(png_ptr, "Unknown custom filter method");
1127 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ png_set_filter_heuristics()

void PNGAPI png_set_filter_heuristics ( png_structrp  png_ptr,
int  heuristic_method,
int  num_weights,
png_const_doublep  filter_weights,
png_const_doublep  filter_costs 
)
1136 {
1141  PNG_UNUSED(filter_costs)
1142 }

◆ png_set_filter_heuristics_fixed()

void PNGAPI png_set_filter_heuristics_fixed ( png_structrp  png_ptr,
int  heuristic_method,
int  num_weights,
png_const_fixed_point_p  filter_weights,
png_const_fixed_point_p  filter_costs 
)
1150 {
1155  PNG_UNUSED(filter_costs)
1156 }

◆ png_set_compression_level()

void PNGAPI png_set_compression_level ( png_structrp  png_ptr,
int  level 
)
1163 {
1164  png_debug(1, "in png_set_compression_level");
1165 
1166  if (png_ptr == NULL)
1167  return;
1168 
1169  png_ptr->zlib_level = level;
1170 }
Here is the caller graph for this function:

◆ png_set_compression_mem_level()

void PNGAPI png_set_compression_mem_level ( png_structrp  png_ptr,
int  mem_level 
)
1174 {
1175  png_debug(1, "in png_set_compression_mem_level");
1176 
1177  if (png_ptr == NULL)
1178  return;
1179 
1180  png_ptr->zlib_mem_level = mem_level;
1181 }

◆ png_set_compression_strategy()

void PNGAPI png_set_compression_strategy ( png_structrp  png_ptr,
int  strategy 
)
1185 {
1186  png_debug(1, "in png_set_compression_strategy");
1187 
1188  if (png_ptr == NULL)
1189  return;
1190 
1191  /* The flag setting here prevents the libpng dynamic selection of strategy.
1192  */
1194  png_ptr->zlib_strategy = strategy;
1195 }

◆ png_set_compression_window_bits()

void PNGAPI png_set_compression_window_bits ( png_structrp  png_ptr,
int  window_bits 
)
1202 {
1203  if (png_ptr == NULL)
1204  return;
1205 
1206  /* Prior to 1.6.0 this would warn but then set the window_bits value. This
1207  * meant that negative window bits values could be selected that would cause
1208  * libpng to write a non-standard PNG file with raw deflate or gzip
1209  * compressed IDAT or ancillary chunks. Such files can be read and there is
1210  * no warning on read, so this seems like a very bad idea.
1211  */
1212  if (window_bits > 15)
1213  {
1214  png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
1215  window_bits = 15;
1216  }
1217 
1218  else if (window_bits < 8)
1219  {
1220  png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
1221  window_bits = 8;
1222  }
1223 
1224  png_ptr->zlib_window_bits = window_bits;
1225 }
Here is the call graph for this function:

◆ png_set_compression_method()

void PNGAPI png_set_compression_method ( png_structrp  png_ptr,
int  method 
)
1229 {
1230  png_debug(1, "in png_set_compression_method");
1231 
1232  if (png_ptr == NULL)
1233  return;
1234 
1235  /* This would produce an invalid PNG file if it worked, but it doesn't and
1236  * deflate will fault it, so it is harmless to just warn here.
1237  */
1238  if (method != 8)
1239  png_warning(png_ptr, "Only compression method 8 is supported by PNG");
1240 
1241  png_ptr->zlib_method = method;
1242 }
Here is the call graph for this function:

◆ png_set_text_compression_level()

void PNGAPI png_set_text_compression_level ( png_structrp  png_ptr,
int  level 
)
1249 {
1250  png_debug(1, "in png_set_text_compression_level");
1251 
1252  if (png_ptr == NULL)
1253  return;
1254 
1255  png_ptr->zlib_text_level = level;
1256 }

◆ png_set_text_compression_mem_level()

void PNGAPI png_set_text_compression_mem_level ( png_structrp  png_ptr,
int  mem_level 
)
1260 {
1261  png_debug(1, "in png_set_text_compression_mem_level");
1262 
1263  if (png_ptr == NULL)
1264  return;
1265 
1266  png_ptr->zlib_text_mem_level = mem_level;
1267 }

◆ png_set_text_compression_strategy()

void PNGAPI png_set_text_compression_strategy ( png_structrp  png_ptr,
int  strategy 
)
1271 {
1272  png_debug(1, "in png_set_text_compression_strategy");
1273 
1274  if (png_ptr == NULL)
1275  return;
1276 
1277  png_ptr->zlib_text_strategy = strategy;
1278 }

◆ png_set_text_compression_window_bits()

void PNGAPI png_set_text_compression_window_bits ( png_structrp  png_ptr,
int  window_bits 
)
1285 {
1286  if (png_ptr == NULL)
1287  return;
1288 
1289  if (window_bits > 15)
1290  {
1291  png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
1292  window_bits = 15;
1293  }
1294 
1295  else if (window_bits < 8)
1296  {
1297  png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
1298  window_bits = 8;
1299  }
1300 
1301  png_ptr->zlib_text_window_bits = window_bits;
1302 }
Here is the call graph for this function:

◆ png_set_text_compression_method()

void PNGAPI png_set_text_compression_method ( png_structrp  png_ptr,
int  method 
)
1306 {
1307  png_debug(1, "in png_set_text_compression_method");
1308 
1309  if (png_ptr == NULL)
1310  return;
1311 
1312  if (method != 8)
1313  png_warning(png_ptr, "Only compression method 8 is supported by PNG");
1314 
1315  png_ptr->zlib_text_method = method;
1316 }
Here is the call graph for this function:

◆ png_set_write_status_fn()

void PNGAPI png_set_write_status_fn ( png_structrp  png_ptr,
png_write_status_ptr  write_row_fn 
)
1322 {
1323  if (png_ptr == NULL)
1324  return;
1325 
1326  png_ptr->write_row_fn = write_row_fn;
1327 }

◆ png_set_write_user_transform_fn()

void PNGAPI png_set_write_user_transform_fn ( png_structrp  png_ptr,
png_user_transform_ptr  write_user_transform_fn 
)
1333 {
1334  png_debug(1, "in png_set_write_user_transform_fn");
1335 
1336  if (png_ptr == NULL)
1337  return;
1338 
1339  png_ptr->transformations |= PNG_USER_TRANSFORM;
1340  png_ptr->write_user_transform_fn = write_user_transform_fn;
1341 }

◆ png_write_png()

void PNGAPI png_write_png ( png_structrp  png_ptr,
png_inforp  info_ptr,
int  transforms,
voidp  params 
)
1349 {
1350  if (png_ptr == NULL || info_ptr == NULL)
1351  return;
1352 
1353  if ((info_ptr->valid & PNG_INFO_IDAT) == 0)
1354  {
1355  png_app_error(png_ptr, "no rows for png_write_image to write");
1356  return;
1357  }
1358 
1359  /* Write the file header information. */
1361 
1362  /* ------ these transformations don't touch the info structure ------- */
1363 
1364  /* Invert monochrome pixels */
1365  if ((transforms & PNG_TRANSFORM_INVERT_MONO) != 0)
1366 #ifdef PNG_WRITE_INVERT_SUPPORTED
1368 #else
1369  png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_MONO not supported");
1370 #endif
1371 
1372  /* Shift the pixels up to a legal bit depth and fill in
1373  * as appropriate to correctly scale the image.
1374  */
1375  if ((transforms & PNG_TRANSFORM_SHIFT) != 0)
1376 #ifdef PNG_WRITE_SHIFT_SUPPORTED
1377  if ((info_ptr->valid & PNG_INFO_sBIT) != 0)
1378  png_set_shift(png_ptr, &info_ptr->sig_bit);
1379 #else
1380  png_app_error(png_ptr, "PNG_TRANSFORM_SHIFT not supported");
1381 #endif
1382 
1383  /* Pack pixels into bytes */
1384  if ((transforms & PNG_TRANSFORM_PACKING) != 0)
1385 #ifdef PNG_WRITE_PACK_SUPPORTED
1387 #else
1388  png_app_error(png_ptr, "PNG_TRANSFORM_PACKING not supported");
1389 #endif
1390 
1391  /* Swap location of alpha bytes from ARGB to RGBA */
1392  if ((transforms & PNG_TRANSFORM_SWAP_ALPHA) != 0)
1393 #ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED
1395 #else
1396  png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ALPHA not supported");
1397 #endif
1398 
1399  /* Remove a filler (X) from XRGB/RGBX/AG/GA into to convert it into
1400  * RGB, note that the code expects the input color type to be G or RGB; no
1401  * alpha channel.
1402  */
1403  if ((transforms & (PNG_TRANSFORM_STRIP_FILLER_AFTER|
1405  {
1406 #ifdef PNG_WRITE_FILLER_SUPPORTED
1407  if ((transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER) != 0)
1408  {
1409  if ((transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE) != 0)
1411  "PNG_TRANSFORM_STRIP_FILLER: BEFORE+AFTER not supported");
1412 
1413  /* Continue if ignored - this is the pre-1.6.10 behavior */
1415  }
1416 
1417  else if ((transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE) != 0)
1419 #else
1420  png_app_error(png_ptr, "PNG_TRANSFORM_STRIP_FILLER not supported");
1421 #endif
1422  }
1423 
1424  /* Flip BGR pixels to RGB */
1425  if ((transforms & PNG_TRANSFORM_BGR) != 0)
1426 #ifdef PNG_WRITE_BGR_SUPPORTED
1428 #else
1429  png_app_error(png_ptr, "PNG_TRANSFORM_BGR not supported");
1430 #endif
1431 
1432  /* Swap bytes of 16-bit files to most significant byte first */
1433  if ((transforms & PNG_TRANSFORM_SWAP_ENDIAN) != 0)
1434 #ifdef PNG_WRITE_SWAP_SUPPORTED
1436 #else
1437  png_app_error(png_ptr, "PNG_TRANSFORM_SWAP_ENDIAN not supported");
1438 #endif
1439 
1440  /* Swap bits of 1-bit, 2-bit, 4-bit packed pixel formats */
1441  if ((transforms & PNG_TRANSFORM_PACKSWAP) != 0)
1442 #ifdef PNG_WRITE_PACKSWAP_SUPPORTED
1444 #else
1445  png_app_error(png_ptr, "PNG_TRANSFORM_PACKSWAP not supported");
1446 #endif
1447 
1448  /* Invert the alpha channel from opacity to transparency */
1449  if ((transforms & PNG_TRANSFORM_INVERT_ALPHA) != 0)
1450 #ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED
1452 #else
1453  png_app_error(png_ptr, "PNG_TRANSFORM_INVERT_ALPHA not supported");
1454 #endif
1455 
1456  /* ----------------------- end of transformations ------------------- */
1457 
1458  /* Write the bits */
1459  png_write_image(png_ptr, info_ptr->row_pointers);
1460 
1461  /* It is REQUIRED to call this to finish writing the rest of the file */
1463 
1464  PNG_UNUSED(params)
1465 }
Here is the call graph for this function:

◆ png_image_write_init()

static int png_image_write_init ( png_imagep  image)
static
1473 {
1474  png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, image,
1475  png_safe_error, png_safe_warning);
1476 
1477  if (png_ptr != NULL)
1478  {
1479  png_infop info_ptr = png_create_info_struct(png_ptr);
1480 
1481  if (info_ptr != NULL)
1482  {
1484  png_malloc_warn(png_ptr, (sizeof *control)));
1485 
1486  if (control != NULL)
1487  {
1488  memset(control, 0, (sizeof *control));
1489 
1490  control->png_ptr = png_ptr;
1491  control->info_ptr = info_ptr;
1492  control->for_write = 1;
1493 
1494  image->opaque = control;
1495  return 1;
1496  }
1497 
1498  /* Error clean up */
1500  }
1501 
1503  }
1504 
1505  return png_image_error(image, "png_image_write_: out of memory");
1506 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ png_write_image_16bit()

static int png_write_image_16bit ( png_voidp  argument)
static
1533 {
1535  argument);
1536  png_imagep image = display->image;
1537  png_structrp png_ptr = image->opaque->png_ptr;
1538 
1540  display->first_row);
1541  png_uint_16p output_row = png_voidcast(png_uint_16p, display->local_row);
1542  png_uint_16p row_end;
1543  unsigned int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ?
1544  3 : 1;
1545  int aindex = 0;
1546  png_uint_32 y = image->height;
1547 
1548  if ((image->format & PNG_FORMAT_FLAG_ALPHA) != 0)
1549  {
1550 # ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
1551  if ((image->format & PNG_FORMAT_FLAG_AFIRST) != 0)
1552  {
1553  aindex = -1;
1554  ++input_row; /* To point to the first component */
1555  ++output_row;
1556  }
1557  else
1558  aindex = (int)channels;
1559 # else
1560  aindex = (int)channels;
1561 # endif
1562  }
1563 
1564  else
1565  png_error(png_ptr, "png_write_image: internal call error");
1566 
1567  /* Work out the output row end and count over this, note that the increment
1568  * above to 'row' means that row_end can actually be beyond the end of the
1569  * row; this is correct.
1570  */
1571  row_end = output_row + image->width * (channels+1);
1572 
1573  for (; y > 0; --y)
1574  {
1575  png_const_uint_16p in_ptr = input_row;
1576  png_uint_16p out_ptr = output_row;
1577 
1578  while (out_ptr < row_end)
1579  {
1580  png_uint_16 alpha = in_ptr[aindex];
1581  png_uint_32 reciprocal = 0;
1582  int c;
1583 
1584  out_ptr[aindex] = alpha;
1585 
1586  /* Calculate a reciprocal. The correct calculation is simply
1587  * component/alpha*65535 << 15. (I.e. 15 bits of precision); this
1588  * allows correct rounding by adding .5 before the shift. 'reciprocal'
1589  * is only initialized when required.
1590  */
1591  if (alpha > 0 && alpha < 65535)
1592  reciprocal = ((0xffff<<15)+(alpha>>1))/alpha;
1593 
1594  c = (int)channels;
1595  do /* always at least one channel */
1596  {
1597  png_uint_16 component = *in_ptr++;
1598 
1599  /* The following gives 65535 for an alpha of 0, which is fine,
1600  * otherwise if 0/0 is represented as some other value there is more
1601  * likely to be a discontinuity which will probably damage
1602  * compression when moving from a fully transparent area to a
1603  * nearly transparent one. (The assumption here is that opaque
1604  * areas tend not to be 0 intensity.)
1605  */
1606  if (component >= alpha)
1607  component = 65535;
1608 
1609  /* component<alpha, so component/alpha is less than one and
1610  * component*reciprocal is less than 2^31.
1611  */
1612  else if (component > 0 && alpha < 65535)
1613  {
1614  png_uint_32 calc = component * reciprocal;
1615  calc += 16384; /* round to nearest */
1616  component = (png_uint_16)(calc >> 15);
1617  }
1618 
1619  *out_ptr++ = component;
1620  }
1621  while (--c > 0);
1622 
1623  /* Skip to next component (skip the intervening alpha channel) */
1624  ++in_ptr;
1625  ++out_ptr;
1626  }
1627 
1629  input_row += (png_uint_16)display->row_bytes/(sizeof (png_uint_16));
1630  }
1631 
1632  return 1;
1633 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ png_unpremultiply()

static png_byte png_unpremultiply ( png_uint_32  component,
png_uint_32  alpha,
png_uint_32  reciprocal 
)
static
1648 {
1649  /* The following gives 1.0 for an alpha of 0, which is fine, otherwise if 0/0
1650  * is represented as some other value there is more likely to be a
1651  * discontinuity which will probably damage compression when moving from a
1652  * fully transparent area to a nearly transparent one. (The assumption here
1653  * is that opaque areas tend not to be 0 intensity.)
1654  *
1655  * There is a rounding problem here; if alpha is less than 128 it will end up
1656  * as 0 when scaled to 8 bits. To avoid introducing spurious colors into the
1657  * output change for this too.
1658  */
1659  if (component >= alpha || alpha < 128)
1660  return 255;
1661 
1662  /* component<alpha, so component/alpha is less than one and
1663  * component*reciprocal is less than 2^31.
1664  */
1665  else if (component > 0)
1666  {
1667  /* The test is that alpha/257 (rounded) is less than 255, the first value
1668  * that becomes 255 is 65407.
1669  * NOTE: this must agree with the PNG_DIV257 macro (which must, therefore,
1670  * be exact!) [Could also test reciprocal != 0]
1671  */
1672  if (alpha < 65407)
1673  {
1674  component *= reciprocal;
1675  component += 64; /* round to nearest */
1676  component >>= 7;
1677  }
1678 
1679  else
1680  component *= 255;
1681 
1682  /* Convert the component to sRGB. */
1683  return (png_byte)PNG_sRGB_FROM_LINEAR(component);
1684  }
1685 
1686  else
1687  return 0;
1688 }
Here is the caller graph for this function:

◆ png_write_image_8bit()

static int png_write_image_8bit ( png_voidp  argument)
static
1692 {
1694  argument);
1695  png_imagep image = display->image;
1696  png_structrp png_ptr = image->opaque->png_ptr;
1697 
1699  display->first_row);
1700  png_bytep output_row = png_voidcast(png_bytep, display->local_row);
1701  png_uint_32 y = image->height;
1702  unsigned int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ?
1703  3 : 1;
1704 
1705  if ((image->format & PNG_FORMAT_FLAG_ALPHA) != 0)
1706  {
1707  png_bytep row_end;
1708  int aindex;
1709 
1710 # ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
1711  if ((image->format & PNG_FORMAT_FLAG_AFIRST) != 0)
1712  {
1713  aindex = -1;
1714  ++input_row; /* To point to the first component */
1715  ++output_row;
1716  }
1717 
1718  else
1719 # endif
1720  aindex = (int)channels;
1721 
1722  /* Use row_end in place of a loop counter: */
1723  row_end = output_row + image->width * (channels+1);
1724 
1725  for (; y > 0; --y)
1726  {
1727  png_const_uint_16p in_ptr = input_row;
1728  png_bytep out_ptr = output_row;
1729 
1730  while (out_ptr < row_end)
1731  {
1732  png_uint_16 alpha = in_ptr[aindex];
1733  png_byte alphabyte = (png_byte)PNG_DIV257(alpha);
1734  png_uint_32 reciprocal = 0;
1735  int c;
1736 
1737  /* Scale and write the alpha channel. */
1738  out_ptr[aindex] = alphabyte;
1739 
1740  if (alphabyte > 0 && alphabyte < 255)
1741  reciprocal = UNP_RECIPROCAL(alpha);
1742 
1743  c = (int)channels;
1744  do /* always at least one channel */
1745  *out_ptr++ = png_unpremultiply(*in_ptr++, alpha, reciprocal);
1746  while (--c > 0);
1747 
1748  /* Skip to next component (skip the intervening alpha channel) */
1749  ++in_ptr;
1750  ++out_ptr;
1751  } /* while out_ptr < row_end */
1752 
1754  display->local_row));
1755  input_row += (png_uint_16)display->row_bytes/(sizeof (png_uint_16));
1756  } /* while y */
1757  }
1758 
1759  else
1760  {
1761  /* No alpha channel, so the row_end really is the end of the row and it
1762  * is sufficient to loop over the components one by one.
1763  */
1764  png_bytep row_end = output_row + image->width * channels;
1765 
1766  for (; y > 0; --y)
1767  {
1768  png_const_uint_16p in_ptr = input_row;
1769  png_bytep out_ptr = output_row;
1770 
1771  while (out_ptr < row_end)
1772  {
1773  png_uint_32 component = *in_ptr++;
1774 
1775  component *= 255;
1776  *out_ptr++ = (png_byte)PNG_sRGB_FROM_LINEAR(component);
1777  }
1778 
1779  png_write_row(png_ptr, output_row);
1780  input_row += (png_uint_16)display->row_bytes/(sizeof (png_uint_16));
1781  }
1782  }
1783 
1784  return 1;
1785 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ png_image_set_PLTE()

static void png_image_set_PLTE ( png_image_write_control display)
static
1789 {
1790  png_imagep image = display->image;
1791  const void *cmap = display->colormap;
1792  int entries = image->colormap_entries > 256 ? 256 :
1793  (int)image->colormap_entries;
1794 
1795  /* NOTE: the caller must check for cmap != NULL and entries != 0 */
1796  png_uint_32 format = image->format;
1797  unsigned int channels = PNG_IMAGE_SAMPLE_CHANNELS(format);
1798 
1799 # if defined(PNG_FORMAT_BGR_SUPPORTED) &&\
1800  defined(PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED)
1801  int afirst = (format & PNG_FORMAT_FLAG_AFIRST) != 0 &&
1802  (format & PNG_FORMAT_FLAG_ALPHA) != 0;
1803 # else
1804 # define afirst 0
1805 # endif
1806 
1807 # ifdef PNG_FORMAT_BGR_SUPPORTED
1808  int bgr = (format & PNG_FORMAT_FLAG_BGR) != 0 ? 2 : 0;
1809 # else
1810 # define bgr 0
1811 # endif
1812 
1813  int i, num_trans;
1814  png_color palette[256];
1815  png_byte tRNS[256];
1816 
1817  memset(tRNS, 255, (sizeof tRNS));
1818  memset(palette, 0, (sizeof palette));
1819 
1820  for (i=num_trans=0; i<entries; ++i)
1821  {
1822  /* This gets automatically converted to sRGB with reversal of the
1823  * pre-multiplication if the color-map has an alpha channel.
1824  */
1825  if ((format & PNG_FORMAT_FLAG_LINEAR) != 0)
1826  {
1828 
1829  entry += (unsigned int)i * channels;
1830 
1831  if ((channels & 1) != 0) /* no alpha */
1832  {
1833  if (channels >= 3) /* RGB */
1834  {
1835  palette[i].blue = (png_byte)PNG_sRGB_FROM_LINEAR(255 *
1836  entry[(2 ^ bgr)]);
1837  palette[i].green = (png_byte)PNG_sRGB_FROM_LINEAR(255 *
1838  entry[1]);
1839  palette[i].red = (png_byte)PNG_sRGB_FROM_LINEAR(255 *
1840  entry[bgr]);
1841  }
1842 
1843  else /* Gray */
1844  palette[i].blue = palette[i].red = palette[i].green =
1845  (png_byte)PNG_sRGB_FROM_LINEAR(255 * *entry);
1846  }
1847 
1848  else /* alpha */
1849  {
1850  png_uint_16 alpha = entry[afirst ? 0 : channels-1];
1851  png_byte alphabyte = (png_byte)PNG_DIV257(alpha);
1852  png_uint_32 reciprocal = 0;
1853 
1854  /* Calculate a reciprocal, as in the png_write_image_8bit code above
1855  * this is designed to produce a value scaled to 255*65535 when
1856  * divided by 128 (i.e. asr 7).
1857  */
1858  if (alphabyte > 0 && alphabyte < 255)
1859  reciprocal = (((0xffff*0xff)<<7)+(alpha>>1))/alpha;
1860 
1861  tRNS[i] = alphabyte;
1862  if (alphabyte < 255)
1863  num_trans = i+1;
1864 
1865  if (channels >= 3) /* RGB */
1866  {
1867  palette[i].blue = png_unpremultiply(entry[afirst + (2 ^ bgr)],
1868  alpha, reciprocal);
1869  palette[i].green = png_unpremultiply(entry[afirst + 1], alpha,
1870  reciprocal);
1871  palette[i].red = png_unpremultiply(entry[afirst + bgr], alpha,
1872  reciprocal);
1873  }
1874 
1875  else /* gray */
1876  palette[i].blue = palette[i].red = palette[i].green =
1877  png_unpremultiply(entry[afirst], alpha, reciprocal);
1878  }
1879  }
1880 
1881  else /* Color-map has sRGB values */
1882  {
1884 
1885  entry += (unsigned int)i * channels;
1886 
1887  switch (channels)
1888  {
1889  case 4:
1890  tRNS[i] = entry[afirst ? 0 : 3];
1891  if (tRNS[i] < 255)
1892  num_trans = i+1;
1893  /* FALLTHROUGH */
1894  case 3:
1895  palette[i].blue = entry[afirst + (2 ^ bgr)];
1896  palette[i].green = entry[afirst + 1];
1897  palette[i].red = entry[afirst + bgr];
1898  break;
1899 
1900  case 2:
1901  tRNS[i] = entry[1 ^ afirst];
1902  if (tRNS[i] < 255)
1903  num_trans = i+1;
1904  /* FALLTHROUGH */
1905  case 1:
1906  palette[i].blue = palette[i].red = palette[i].green =
1907  entry[afirst];
1908  break;
1909 
1910  default:
1911  break;
1912  }
1913  }
1914  }
1915 
1916 # ifdef afirst
1917 # undef afirst
1918 # endif
1919 # ifdef bgr
1920 # undef bgr
1921 # endif
1922 
1923  png_set_PLTE(image->opaque->png_ptr, image->opaque->info_ptr, palette,
1924  entries);
1925 
1926  if (num_trans > 0)
1927  png_set_tRNS(image->opaque->png_ptr, image->opaque->info_ptr, tRNS,
1928  num_trans, NULL);
1929 
1930  image->colormap_entries = (png_uint_32)entries;
1931 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ png_image_write_main()

static int png_image_write_main ( png_voidp  argument)
static
1935 {
1937  argument);
1938  png_imagep image = display->image;
1939  png_structrp png_ptr = image->opaque->png_ptr;
1940  png_inforp info_ptr = image->opaque->info_ptr;
1941  png_uint_32 format = image->format;
1942 
1943  /* The following four ints are actually booleans */
1944  int colormap = (format & PNG_FORMAT_FLAG_COLORMAP);
1945  int linear = !colormap && (format & PNG_FORMAT_FLAG_LINEAR); /* input */
1946  int alpha = !colormap && (format & PNG_FORMAT_FLAG_ALPHA);
1947  int write_16bit = linear && (display->convert_to_8bit == 0);
1948 
1949 # ifdef PNG_BENIGN_ERRORS_SUPPORTED
1950  /* Make sure we error out on any bad situation */
1951  png_set_benign_errors(png_ptr, 0/*error*/);
1952 # endif
1953 
1954  /* Default the 'row_stride' parameter if required, also check the row stride
1955  * and total image size to ensure that they are within the system limits.
1956  */
1957  {
1958  unsigned int channels = PNG_IMAGE_PIXEL_CHANNELS(image->format);
1959 
1960  if (image->width <= 0x7fffffffU/channels) /* no overflow */
1961  {
1962  png_uint_32 check;
1963  png_uint_32 png_row_stride = image->width * channels;
1964 
1965  if (display->row_stride == 0)
1966  display->row_stride = (png_int_32)/*SAFE*/png_row_stride;
1967 
1968  if (display->row_stride < 0)
1969  check = (png_uint_32)(-display->row_stride);
1970 
1971  else
1972  check = (png_uint_32)display->row_stride;
1973 
1974  if (check >= png_row_stride)
1975  {
1976  /* Now check for overflow of the image buffer calculation; this
1977  * limits the whole image size to 32 bits for API compatibility with
1978  * the current, 32-bit, PNG_IMAGE_BUFFER_SIZE macro.
1979  */
1980  if (image->height > 0xffffffffU/png_row_stride)
1981  png_error(image->opaque->png_ptr, "memory image too large");
1982  }
1983 
1984  else
1985  png_error(image->opaque->png_ptr, "supplied row stride too small");
1986  }
1987 
1988  else
1989  png_error(image->opaque->png_ptr, "image row stride too large");
1990  }
1991 
1992  /* Set the required transforms then write the rows in the correct order. */
1993  if ((format & PNG_FORMAT_FLAG_COLORMAP) != 0)
1994  {
1995  if (display->colormap != NULL && image->colormap_entries > 0)
1996  {
1997  png_uint_32 entries = image->colormap_entries;
1998 
1999  png_set_IHDR(png_ptr, info_ptr, image->width, image->height,
2000  entries > 16 ? 8 : (entries > 4 ? 4 : (entries > 2 ? 2 : 1)),
2003 
2005  }
2006 
2007  else
2008  png_error(image->opaque->png_ptr,
2009  "no color-map for color-mapped image");
2010  }
2011 
2012  else
2013  png_set_IHDR(png_ptr, info_ptr, image->width, image->height,
2014  write_16bit ? 16 : 8,
2015  ((format & PNG_FORMAT_FLAG_COLOR) ? PNG_COLOR_MASK_COLOR : 0) +
2016  ((format & PNG_FORMAT_FLAG_ALPHA) ? PNG_COLOR_MASK_ALPHA : 0),
2018 
2019  /* Counter-intuitively the data transformations must be called *after*
2020  * png_write_info, not before as in the read code, but the 'set' functions
2021  * must still be called before. Just set the color space information, never
2022  * write an interlaced image.
2023  */
2024 
2025  if (write_16bit != 0)
2026  {
2027  /* The gamma here is 1.0 (linear) and the cHRM chunk matches sRGB. */
2029 
2030  if ((image->flags & PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB) == 0)
2032  /* color x y */
2033  /* white */ 31270, 32900,
2034  /* red */ 64000, 33000,
2035  /* green */ 30000, 60000,
2036  /* blue */ 15000, 6000
2037  );
2038  }
2039 
2040  else if ((image->flags & PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB) == 0)
2042 
2043  /* Else writing an 8-bit file and the *colors* aren't sRGB, but the 8-bit
2044  * space must still be gamma encoded.
2045  */
2046  else
2048 
2049  /* Write the file header. */
2051 
2052  /* Now set up the data transformations (*after* the header is written),
2053  * remove the handled transformations from the 'format' flags for checking.
2054  *
2055  * First check for a little endian system if writing 16-bit files.
2056  */
2057  if (write_16bit != 0)
2058  {
2059  png_uint_16 le = 0x0001;
2060 
2061  if ((*(png_const_bytep) & le) != 0)
2063  }
2064 
2065 # ifdef PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED
2066  if ((format & PNG_FORMAT_FLAG_BGR) != 0)
2067  {
2068  if (colormap == 0 && (format & PNG_FORMAT_FLAG_COLOR) != 0)
2070  format &= ~PNG_FORMAT_FLAG_BGR;
2071  }
2072 # endif
2073 
2074 # ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
2075  if ((format & PNG_FORMAT_FLAG_AFIRST) != 0)
2076  {
2077  if (colormap == 0 && (format & PNG_FORMAT_FLAG_ALPHA) != 0)
2079  format &= ~PNG_FORMAT_FLAG_AFIRST;
2080  }
2081 # endif
2082 
2083  /* If there are 16 or fewer color-map entries we wrote a lower bit depth
2084  * above, but the application data is still byte packed.
2085  */
2086  if (colormap != 0 && image->colormap_entries <= 16)
2088 
2089  /* That should have handled all (both) the transforms. */
2092  png_error(png_ptr, "png_write_image: unsupported transformation");
2093 
2094  {
2096  ptrdiff_t row_bytes = display->row_stride;
2097 
2098  if (linear != 0)
2099  row_bytes *= (sizeof (png_uint_16));
2100 
2101  if (row_bytes < 0)
2102  row += (image->height-1) * (-row_bytes);
2103 
2104  display->first_row = row;
2105  display->row_bytes = row_bytes;
2106  }
2107 
2108  /* Apply 'fast' options if the flag is set. */
2109  if ((image->flags & PNG_IMAGE_FLAG_FAST) != 0)
2110  {
2112  /* NOTE: determined by experiment using pngstest, this reflects some
2113  * balance between the time to write the image once and the time to read
2114  * it about 50 times. The speed-up in pngstest was about 10-20% of the
2115  * total (user) time on a heavily loaded system.
2116  */
2117 # ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED
2119 # endif
2120  }
2121 
2122  /* Check for the cases that currently require a pre-transform on the row
2123  * before it is written. This only applies when the input is 16-bit and
2124  * either there is an alpha channel or it is converted to 8-bit.
2125  */
2126  if ((linear != 0 && alpha != 0 ) ||
2127  (colormap == 0 && display->convert_to_8bit != 0))
2128  {
2129  png_bytep row = png_voidcast(png_bytep, png_malloc(png_ptr,
2131  int result;
2132 
2133  display->local_row = row;
2134  if (write_16bit != 0)
2136  else
2137  result = png_safe_execute(image, png_write_image_8bit, display);
2138  display->local_row = NULL;
2139 
2140  png_free(png_ptr, row);
2141 
2142  /* Skip the 'write_end' on error: */
2143  if (result == 0)
2144  return 0;
2145  }
2146 
2147  /* Otherwise this is the case where the input is in a format currently
2148  * supported by the rest of the libpng write code; call it directly.
2149  */
2150  else
2151  {
2153  ptrdiff_t row_bytes = display->row_bytes;
2154  png_uint_32 y = image->height;
2155 
2156  for (; y > 0; --y)
2157  {
2158  png_write_row(png_ptr, row);
2159  row += row_bytes;
2160  }
2161  }
2162 
2164  return 1;
2165 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ void()

static void ( PNGCBAPI  image_memory_write)
static
2195 {
2197 }
Here is the caller graph for this function:

◆ if()

if ( size<=((png_alloc_size_t) -1) -  ob)
2177  {
2178  /* I don't think libpng ever does this, but just in case: */
2179  if (size > 0)
2180  {
2181  if (display->memory_bytes >= ob+size) /* writing */
2182  memcpy(display->memory+ob, data, size);
2183 
2184  /* Always update the size: */
2185  display->output_bytes = ob+size;
2186  }
2187  }
Here is the caller graph for this function:

◆ png_error()

else png_error ( png_ptr  ,
"png_image_write_to_memory: PNG too big"   
)

◆ png_image_write_memory()

static int png_image_write_memory ( png_voidp  argument)
static
2201 {
2203  argument);
2204 
2205  /* The rest of the memory-specific init and write_main in an error protected
2206  * environment. This case needs to use callbacks for the write operations
2207  * since libpng has no built in support for writing to memory.
2208  */
2209  png_set_write_fn(display->image->opaque->png_ptr, display/*io_ptr*/,
2210  image_memory_write, image_memory_flush);
2211 
2212  return png_image_write_main(display);
2213 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ png_image_write_to_memory()

int PNGAPI png_image_write_to_memory ( png_imagep  image,
void memory,
png_alloc_size_t *PNG_RESTRICT  memory_bytes,
int  convert_to_8bit,
const void buffer,
png_int_32  row_stride,
const void colormap 
)
2219 {
2220  /* Write the image to the given buffer, or count the bytes if it is NULL */
2221  if (image != NULL && image->version == PNG_IMAGE_VERSION)
2222  {
2223  if (memory_bytes != NULL && buffer != NULL)
2224  {
2225  /* This is to give the caller an easier error detection in the NULL
2226  * case and guard against uninitialized variable problems:
2227  */
2228  if (memory == NULL)
2229  *memory_bytes = 0;
2230 
2231  if (png_image_write_init(image) != 0)
2232  {
2234  int result;
2235 
2236  memset(&display, 0, (sizeof display));
2237  display.image = image;
2238  display.buffer = buffer;
2239  display.row_stride = row_stride;
2240  display.colormap = colormap;
2241  display.convert_to_8bit = convert_to_8bit;
2242  display.memory = png_voidcast(png_bytep, memory);
2243  display.memory_bytes = *memory_bytes;
2244  display.output_bytes = 0;
2245 
2246  result = png_safe_execute(image, png_image_write_memory, &display);
2247  png_image_free(image);
2248 
2249  /* write_memory returns true even if we ran out of buffer. */
2250  if (result)
2251  {
2252  /* On out-of-buffer this function returns '0' but still updates
2253  * memory_bytes:
2254  */
2255  if (memory != NULL && display.output_bytes > *memory_bytes)
2256  result = 0;
2257 
2258  *memory_bytes = display.output_bytes;
2259  }
2260 
2261  return result;
2262  }
2263 
2264  else
2265  return 0;
2266  }
2267 
2268  else
2269  return png_image_error(image,
2270  "png_image_write_to_memory: invalid argument");
2271  }
2272 
2273  else if (image != NULL)
2274  return png_image_error(image,
2275  "png_image_write_to_memory: incorrect PNG_IMAGE_VERSION");
2276 
2277  else
2278  return 0;
2279 }
Here is the call graph for this function:

◆ png_image_write_to_stdio()

int PNGAPI png_image_write_to_stdio ( png_imagep  image,
FILE *  file,
int  convert_to_8bit,
const void buffer,
png_int_32  row_stride,
const void colormap 
)
2285 {
2286  /* Write the image to the given (FILE*). */
2287  if (image != NULL && image->version == PNG_IMAGE_VERSION)
2288  {
2289  if (file != NULL && buffer != NULL)
2290  {
2291  if (png_image_write_init(image) != 0)
2292  {
2294  int result;
2295 
2296  /* This is slightly evil, but png_init_io doesn't do anything other
2297  * than this and we haven't changed the standard IO functions so
2298  * this saves a 'safe' function.
2299  */
2300  image->opaque->png_ptr->io_ptr = file;
2301 
2302  memset(&display, 0, (sizeof display));
2303  display.image = image;
2304  display.buffer = buffer;
2305  display.row_stride = row_stride;
2306  display.colormap = colormap;
2307  display.convert_to_8bit = convert_to_8bit;
2308 
2309  result = png_safe_execute(image, png_image_write_main, &display);
2310  png_image_free(image);
2311  return result;
2312  }
2313 
2314  else
2315  return 0;
2316  }
2317 
2318  else
2319  return png_image_error(image,
2320  "png_image_write_to_stdio: invalid argument");
2321  }
2322 
2323  else if (image != NULL)
2324  return png_image_error(image,
2325  "png_image_write_to_stdio: incorrect PNG_IMAGE_VERSION");
2326 
2327  else
2328  return 0;
2329 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ png_image_write_to_file()

int PNGAPI png_image_write_to_file ( png_imagep  image,
const char *  file_name,
int  convert_to_8bit,
const void buffer,
png_int_32  row_stride,
const void colormap 
)
2335 {
2336  /* Write the image to the named file. */
2337  if (image != NULL && image->version == PNG_IMAGE_VERSION)
2338  {
2339  if (file_name != NULL && buffer != NULL)
2340  {
2341  FILE *fp = fopen(file_name, "wb");
2342 
2343  if (fp != NULL)
2344  {
2345  if (png_image_write_to_stdio(image, fp, convert_to_8bit, buffer,
2346  row_stride, colormap) != 0)
2347  {
2348  int error; /* from fflush/fclose */
2349 
2350  /* Make sure the file is flushed correctly. */
2351  if (fflush(fp) == 0 && ferror(fp) == 0)
2352  {
2353  if (fclose(fp) == 0)
2354  return 1;
2355 
2356  error = errno; /* from fclose */
2357  }
2358 
2359  else
2360  {
2361  error = errno; /* from fflush or ferror */
2362  (void)fclose(fp);
2363  }
2364 
2365  (void)remove(file_name);
2366  /* The image has already been cleaned up; this is just used to
2367  * set the error (because the original write succeeded).
2368  */
2369  return png_image_error(image, strerror(error));
2370  }
2371 
2372  else
2373  {
2374  /* Clean up: just the opened file. */
2375  (void)fclose(fp);
2376  (void)remove(file_name);
2377  return 0;
2378  }
2379  }
2380 
2381  else
2382  return png_image_error(image, strerror(errno));
2383  }
2384 
2385  else
2386  return png_image_error(image,
2387  "png_image_write_to_file: invalid argument");
2388  }
2389 
2390  else if (image != NULL)
2391  return png_image_error(image,
2392  "png_image_write_to_file: incorrect PNG_IMAGE_VERSION");
2393 
2394  else
2395  return 0;
2396 }
Here is the call graph for this function:

Variable Documentation

◆ data

png_bytep data

◆ size

◆ ob

png_alloc_size_t ob = display->output_bytes
PNG_BGR
#define PNG_BGR
Definition: pngpriv.h:642
png_image::width
png_uint_32 width
Definition: png.h:2675
png_set_tRNS
void PNGAPI png_set_tRNS(png_structrp png_ptr, png_inforp info_ptr, png_const_bytep trans_alpha, int num_trans, png_const_color_16p trans_color)
Definition: pngset.c:994
png_image_write_memory
static int png_image_write_memory(png_voidp argument)
Definition: pngwrite.c:2200
png_image::colormap_entries
png_uint_32 colormap_entries
Definition: png.h:2679
png_const_bytep
const typedef png_byte * png_const_bytep
Definition: pngconf.h:580
png_write_image
void PNGAPI png_write_image(png_structrp png_ptr, png_bytepp image)
Definition: pngwrite.c:601
PNG_AFTER_IDAT
#define PNG_AFTER_IDAT
Definition: png.h:646
PNG_FLAG_ZLIB_CUSTOM_STRATEGY
#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY
Definition: pngpriv.h:679
png_safe_execute
int png_safe_execute(png_imagep image_in, int(*function)(png_voidp), png_voidp arg)
Definition: pngerror.c:936
PNG_TEXT_COMPRESSION_zTXt
#define PNG_TEXT_COMPRESSION_zTXt
Definition: png.h:589
PNG_FILLER_AFTER
#define PNG_FILLER_AFTER
Definition: png.h:1249
PNG_UNUSED
#define PNG_UNUSED(param)
Definition: pngpriv.h:438
PNG_sRGB_FROM_LINEAR
#define PNG_sRGB_FROM_LINEAR(linear)
Definition: pngpriv.h:952
png_write_find_filter
void png_write_find_filter(png_structrp png_ptr, png_row_infop row_info)
Definition: pngwutil.c:2550
auto_build.error
bool error
Definition: auto_build.py:637
png_unpremultiply
static png_byte png_unpremultiply(png_uint_32 component, png_uint_32 alpha, png_uint_32 reciprocal)
Definition: pngwrite.c:1646
png_time_struct::second
png_byte second
Definition: png.h:607
png_set_sRGB
void PNGAPI png_set_sRGB(png_const_structrp png_ptr, png_inforp info_ptr, int srgb_intent)
Definition: pngset.c:653
PNG_INVERT_ALPHA
#define PNG_INVERT_ALPHA
Definition: pngpriv.h:661
png_write_gAMA_fixed
void png_write_gAMA_fixed(png_structrp png_ptr, png_fixed_point file_gamma)
Definition: pngwutil.c:1084
PNG_INFO_tIME
#define PNG_INFO_tIME
Definition: png.h:741
png_write_tEXt
void png_write_tEXt(png_structrp png_ptr, png_const_charp key, png_const_charp text, size_t text_len)
Definition: pngwutil.c:1530
deflateEnd
int ZEXPORT deflateEnd(z_streamp strm)
Definition: deflate.c:1076
PNG_HAVE_PLTE
#define PNG_HAVE_PLTE
Definition: png.h:645
png_set_compression_level
void PNGAPI png_set_compression_level(png_structrp png_ptr, int level)
Definition: pngwrite.c:1162
filter_weights
png_structrp int int png_const_fixed_point_p filter_weights
Definition: png.h:1488
PNG_INFO_tRNS
#define PNG_INFO_tRNS
Definition: png.h:736
png_set_PLTE
void PNGAPI png_set_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_const_colorp palette, int num_palette)
Definition: pngset.c:572
PNG_FLAG_APP_WARNINGS_WARN
#define PNG_FLAG_APP_WARNINGS_WARN
Definition: pngpriv.h:700
png_image_write_main
static int png_image_write_main(png_voidp argument)
Definition: pngwrite.c:1934
png_free
void PNGAPI png_free(png_const_structrp png_ptr, png_voidp ptr)
Definition: pngmem.c:232
PNG_FILTER_AVG
#define PNG_FILTER_AVG
Definition: png.h:1468
PNG_INFO_pCAL
#define PNG_INFO_pCAL
Definition: png.h:742
PNG_INFO_oFFs
#define PNG_INFO_oFFs
Definition: png.h:740
png_set_swap_alpha
void PNGAPI png_set_swap_alpha(png_structrp png_ptr)
Definition: pngtrans.c:223
png_write_oFFs
void png_write_oFFs(png_structrp png_ptr, png_int_32 x_offset, png_int_32 y_offset, int unit_type)
Definition: pngwutil.c:1724
PNG_IMAGE_VERSION
#define PNG_IMAGE_VERSION
Definition: png.h:2668
png_write_info
void PNGAPI png_write_info(png_structrp png_ptr, png_const_inforp info_ptr)
Definition: pngwrite.c:192
png_image_write_to_stdio
int PNGAPI png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit, const void *buffer, png_int_32 row_stride, const void *colormap)
Definition: pngwrite.c:2283
PNG_TRANSFORM_INVERT_MONO
#define PNG_TRANSFORM_INVERT_MONO
Definition: png.h:838
png_set_interlace_handling
int PNGAPI png_set_interlace_handling(png_structrp png_ptr)
Definition: pngtrans.c:99
png_image::flags
png_uint_32 flags
Definition: png.h:2678
PNG_INTERLACE_NONE
#define PNG_INTERLACE_NONE
Definition: png.h:687
png_inforp
png_info *PNG_RESTRICT png_inforp
Definition: png.h:471
png_bytepp
png_byte ** png_bytepp
Definition: pngconf.h:606
png_write_start_row
void png_write_start_row(png_structrp png_ptr)
Definition: pngwutil.c:1890
png_bytep
png_byte * png_bytep
Definition: pngconf.h:579
i
uint8_t i
Definition: screen_test_graph.c:72
PNG_INVERT_MONO
#define PNG_INVERT_MONO
Definition: pngpriv.h:647
png_write_row
void PNGAPI png_write_row(png_structrp png_ptr, png_const_bytep row)
Definition: pngwrite.c:698
png_flush
void png_flush(png_structrp png_ptr)
Definition: pngwio.c:71
PNG_INFO_PLTE
#define PNG_INFO_PLTE
Definition: png.h:735
png_image_set_PLTE
static void png_image_set_PLTE(png_image_write_control *display)
Definition: pngwrite.c:1788
png_write_cHRM_fixed
void png_write_cHRM_fixed(png_structrp png_ptr, const png_xy *xy)
Definition: pngwutil.c:1322
png_set_shift
void PNGAPI png_set_shift(png_structrp png_ptr, png_const_color_8p true_bits)
Definition: pngtrans.c:84
png_set_invert_mono
void PNGAPI png_set_invert_mono(png_structrp png_ptr)
Definition: pngtrans.c:250
PNG_FORMAT_FLAG_AFIRST
#define PNG_FORMAT_FLAG_AFIRST
Definition: png.h:2787
PNG_FORMAT_FLAG_BGR
#define PNG_FORMAT_FLAG_BGR
Definition: png.h:2783
PNG_COLOR_TYPE_RGB_ALPHA
#define PNG_COLOR_TYPE_RGB_ALPHA
Definition: png.h:671
png_control::for_write
unsigned int for_write
Definition: pngpriv.h:2044
PNG_WRITE_INTERLACING_SUPPORTED
#define PNG_WRITE_INTERLACING_SUPPORTED
Definition: pnglibconf.h:138
png_set_write_fn
void PNGAPI png_set_write_fn(png_structrp png_ptr, png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
Definition: pngwio.c:122
PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB
#define PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB
Definition: png.h:2937
PNG_FILTER_TYPE_BASE
#define PNG_FILTER_TYPE_BASE
Definition: png.h:682
PNG_NO_FILTERS
#define PNG_NO_FILTERS
Definition: png.h:1464
png_free_buffer_list
void png_free_buffer_list(png_structrp png_ptr, png_compression_bufferp *listp)
Definition: pngwutil.c:439
png_debug2
#define png_debug2(l, m, p1, p2)
Definition: pngdebug.h:151
PNG_GAMMA_LINEAR
#define PNG_GAMMA_LINEAR
Definition: png.h:1150
png_destroy_write_struct
void PNGAPI png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
Definition: pngwrite.c:983
PNG_INTRAPIXEL_DIFFERENCING
#define PNG_INTRAPIXEL_DIFFERENCING
Definition: png.h:683
png_write_iTXt
void png_write_iTXt(png_structrp png_ptr, int compression, png_const_charp key, png_const_charp lang, png_const_charp lang_key, png_const_charp text)
Definition: pngwutil.c:1624
png_voidcast
#define png_voidcast(type, value)
Definition: pngpriv.h:494
png_const_unknown_chunkp
const typedef png_unknown_chunk * png_const_unknown_chunkp
Definition: png.h:639
NULL
#define NULL
Definition: usbd_def.h:53
png_row_info_struct::width
png_uint_32 width
Definition: png.h:756
png_ptr
png_structrp png_ptr
Definition: png.h:1083
PNG_FORMAT_FLAG_LINEAR
#define PNG_FORMAT_FLAG_LINEAR
Definition: png.h:2779
PNG_Z_DEFAULT_STRATEGY
#define PNG_Z_DEFAULT_STRATEGY
Definition: pnglibconf.h:215
PNG_COLOR_TYPE_RGB
#define PNG_COLOR_TYPE_RGB
Definition: png.h:670
info_ptr
png_const_structrp png_const_inforp info_ptr
Definition: png.h:1939
PNG_FLAG_MNG_FILTER_64
#define PNG_FLAG_MNG_FILTER_64
Definition: png.h:858
png_time_struct::year
png_uint_16 year
Definition: png.h:602
PNG_INFO_gAMA
#define PNG_INFO_gAMA
Definition: png.h:732
PNG_TRANSFORM_PACKSWAP
#define PNG_TRANSFORM_PACKSWAP
Definition: png.h:836
png_time_struct::month
png_byte month
Definition: png.h:603
PNG_INFO_bKGD
#define PNG_INFO_bKGD
Definition: png.h:737
PNG_FORMAT_FLAG_COLOR
#define PNG_FORMAT_FLAG_COLOR
Definition: png.h:2778
PNG_SWAP_BYTES
#define PNG_SWAP_BYTES
Definition: pngpriv.h:646
png_do_check_palette_indexes
void png_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info)
Definition: pngtrans.c:699
PNG_TEXT_Z_DEFAULT_COMPRESSION
#define PNG_TEXT_Z_DEFAULT_COMPRESSION
Definition: pnglibconf.h:205
png_write_IEND
void png_write_IEND(png_structrp png_ptr)
Definition: pngwutil.c:1073
png_uint_32
unsigned int png_uint_32
Definition: pngconf.h:511
png_image_write_init
static int png_image_write_init(png_imagep image)
Definition: pngwrite.c:1472
PNG_INFO_eXIf
#define PNG_INFO_eXIf
Definition: png.h:748
png_image_free
void PNGAPI png_image_free(png_imagep image)
Definition: png.c:4582
png_write_PLTE
void png_write_PLTE(png_structrp png_ptr, png_const_colorp palette, png_uint_32 num_pal)
Definition: pngwutil.c:842
PNG_TEXT_COMPRESSION_NONE
#define PNG_TEXT_COMPRESSION_NONE
Definition: png.h:588
png_uint_16
png_uint_16(PNGAPI png_get_uint_16)(png_const_bytep buf)
Definition: pngrutil.c:102
png_write_tRNS
void png_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha, png_const_color_16p tran, int num_trans, int color_type)
Definition: pngwutil.c:1348
png_write_sBIT
void png_write_sBIT(png_structrp png_ptr, png_const_color_8p sbit, int color_type)
Definition: pngwutil.c:1263
PNG_MAX_PALETTE_LENGTH
#define PNG_MAX_PALETTE_LENGTH
Definition: png.h:725
png_const_uint_16p
const typedef png_uint_16 * png_const_uint_16p
Definition: pngconf.h:586
PNG_HAVE_IHDR
#define PNG_HAVE_IHDR
Definition: png.h:644
PNG_PACKSWAP
#define PNG_PACKSWAP
Definition: pngpriv.h:658
PNG_FORMAT_FLAG_COLORMAP
#define PNG_FORMAT_FLAG_COLORMAP
Definition: png.h:2780
png_image_write_control
Definition: pngwrite.c:1509
PNG_HAVE_IDAT
#define PNG_HAVE_IDAT
Definition: pngpriv.h:626
red
png_structrp int png_fixed_point red
Definition: png.h:1083
png_set_cHRM_fixed
void PNGFAPI png_set_cHRM_fixed(png_const_structrp png_ptr, png_inforp info_ptr, png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x, png_fixed_point blue_y)
Definition: pngset.c:40
errno
int errno
PNG_TEXT_Z_DEFAULT_STRATEGY
#define PNG_TEXT_Z_DEFAULT_STRATEGY
Definition: pnglibconf.h:206
UNP_RECIPROCAL
#define UNP_RECIPROCAL(alpha)
Definition: pngwrite.c:1643
data
static png_bytep data
Definition: pngwrite.c:2169
png_image::version
png_uint_32 version
Definition: png.h:2674
png_write_sPLT
void png_write_sPLT(png_structrp png_ptr, png_const_sPLT_tp spalette)
Definition: pngwutil.c:1179
png_info_def
Definition: pnginfo.h:55
PNG_IMAGE_PIXEL_CHANNELS
#define PNG_IMAGE_PIXEL_CHANNELS(fmt)
Definition: png.h:2881
png_row_info_struct::channels
png_byte channels
Definition: png.h:760
PNG_TRANSFORM_INVERT_ALPHA
#define PNG_TRANSFORM_INVERT_ALPHA
Definition: png.h:843
png_write_image_8bit
static int png_write_image_8bit(png_voidp argument)
Definition: pngwrite.c:1691
PNG_TEXT_COMPRESSION_NONE_WR
#define PNG_TEXT_COMPRESSION_NONE_WR
Definition: png.h:586
png_row_info_struct::color_type
png_byte color_type
Definition: png.h:758
PNG_INFO_sRGB
#define PNG_INFO_sRGB
Definition: png.h:743
png_benign_error
void PNGAPI png_benign_error(png_const_structrp png_ptr, png_const_charp error_message)
Definition: pngerror.c:362
PNG_HANDLE_CHUNK_ALWAYS
#define PNG_HANDLE_CHUNK_ALWAYS
Definition: png.h:2348
PNG_HANDLE_CHUNK_NEVER
#define PNG_HANDLE_CHUNK_NEVER
Definition: png.h:2346
png_color_struct::blue
png_byte blue
Definition: png.h:482
PNG_FILTER_NONE
#define PNG_FILTER_NONE
Definition: png.h:1465
PNG_IMAGE_FLAG_FAST
#define PNG_IMAGE_FLAG_FAST
Definition: png.h:2942
png_debug
#define png_debug(l, m)
Definition: pngdebug.h:145
PNG_TRANSFORM_PACKING
#define PNG_TRANSFORM_PACKING
Definition: png.h:835
png_set_IHDR
void PNGAPI png_set_IHDR(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int interlace_type, int compression_type, int filter_type)
Definition: pngset.c:254
PNG_TRANSFORM_STRIP_FILLER_BEFORE
#define PNG_TRANSFORM_STRIP_FILLER_BEFORE
Definition: png.h:846
png_color_struct::green
png_byte green
Definition: png.h:481
png_write_hIST
void png_write_hIST(png_structrp png_ptr, png_const_uint_16p hist, int num_hist)
Definition: pngwutil.c:1499
PNG_INTERLACE
#define PNG_INTERLACE
Definition: pngpriv.h:643
png_write_finish_row
void png_write_finish_row(png_structrp png_ptr)
Definition: pngwutil.c:2005
png_set_invert_alpha
void PNGAPI png_set_invert_alpha(png_structrp png_ptr)
Definition: pngtrans.c:237
png_write_end
void PNGAPI png_write_end(png_structrp png_ptr, png_inforp info_ptr)
Definition: pngwrite.c:358
PNG_FILLER
#define PNG_FILLER
Definition: pngpriv.h:657
PNG_TRANSFORM_STRIP_FILLER_AFTER
#define PNG_TRANSFORM_STRIP_FILLER_AFTER
Definition: png.h:847
png_write_destroy
static void png_write_destroy(png_structrp png_ptr)
Definition: pngwrite.c:939
PNG_sRGB_INTENT_PERCEPTUAL
#define PNG_sRGB_INTENT_PERCEPTUAL
Definition: png.h:715
PNG_COMPRESSION_TYPE_BASE
#define PNG_COMPRESSION_TYPE_BASE
Definition: png.h:678
png_write_bKGD
void png_write_bKGD(png_structrp png_ptr, png_const_color_16p back, int color_type)
Definition: pngwutil.c:1414
png_image_error
int png_image_error(png_imagep image, png_const_charp error_message)
Definition: png.c:4598
PNG_FILTER_VALUE_NONE
#define PNG_FILTER_VALUE_NONE
Definition: png.h:1476
png_get_rowbytes
size_t PNGAPI png_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr)
Definition: pngget.c:30
num_weights
png_structrp int int num_weights
Definition: png.h:1488
Z_SYNC_FLUSH
#define Z_SYNC_FLUSH
Definition: zlib.h:170
png_structrp
png_struct *PNG_RESTRICT png_structrp
Definition: png.h:469
png_write_IHDR
void png_write_IHDR(png_structrp png_ptr, png_uint_32 width, png_uint_32 height, int bit_depth, int color_type, int compression_type, int filter_type, int interlace_type)
Definition: pngwutil.c:672
PNG_FILTER_UP
#define PNG_FILTER_UP
Definition: png.h:1467
png_color_struct
Definition: png.h:478
png_write_zTXt
void png_write_zTXt(png_structrp png_ptr, png_const_charp key, png_const_charp text, int compression)
Definition: pngwutil.c:1573
png_control
Definition: pngpriv.h:2035
png_set_benign_errors
void PNGAPI png_set_benign_errors(png_structrp png_ptr, int allowed)
Definition: pngset.c:1671
png_image::format
png_uint_32 format
Definition: png.h:2677
PNG_INFO_sCAL
#define PNG_INFO_sCAL
Definition: png.h:746
PNG_FILTER_VALUE_AVG
#define PNG_FILTER_VALUE_AVG
Definition: png.h:1479
PNG_HANDLE_CHUNK_AS_DEFAULT
#define PNG_HANDLE_CHUNK_AS_DEFAULT
Definition: png.h:2345
if
if(size<=((png_alloc_size_t) -1) - ob)
Definition: pngwrite.c:2176
png_write_sCAL_s
void png_write_sCAL_s(png_structrp png_ptr, int unit, png_const_charp width, png_const_charp height)
Definition: pngwutil.c:1809
png_write_pCAL
void png_write_pCAL(png_structrp png_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams, png_const_charp units, png_charpp params)
Definition: pngwutil.c:1744
PNG_FILTER_VALUE_PAETH
#define PNG_FILTER_VALUE_PAETH
Definition: png.h:1480
L
#define L(CODE)
Definition: macros.h:76
png_set_packswap
void PNGAPI png_set_packswap(png_structrp png_ptr)
Definition: pngtrans.c:70
PNG_FILTER_PAETH
#define PNG_FILTER_PAETH
Definition: png.h:1469
PNG_FILTER_VALUE_UP
#define PNG_FILTER_VALUE_UP
Definition: png.h:1478
png_row_info_struct::pixel_depth
png_byte pixel_depth
Definition: png.h:761
png_set_filler
void PNGAPI png_set_filler(png_structrp png_ptr, png_uint_32 filler, int filler_loc)
Definition: pngtrans.c:120
PNG_IMAGE_SAMPLE_CHANNELS
#define PNG_IMAGE_SAMPLE_CHANNELS(fmt)
Definition: png.h:2845
PNG_TRANSFORM_BGR
#define PNG_TRANSFORM_BGR
Definition: png.h:840
PNG_INFO_sPLT
#define PNG_INFO_sPLT
Definition: png.h:745
PNG_FILLER_BEFORE
#define PNG_FILLER_BEFORE
Definition: png.h:1248
png_struct_def
Definition: pngstruct.h:143
png_write_iCCP
void png_write_iCCP(png_structrp png_ptr, png_const_charp name, png_const_bytep profile)
Definition: pngwutil.c:1117
display
display_t * display
Definition: display.c:6
png_image
Definition: png.h:2671
png_set_filter
void PNGAPI png_set_filter(png_structrp png_ptr, int method, int filters)
Definition: pngwrite.c:1004
png_safe_warning
void PNGCBAPI png_safe_warning(png_structp png_nonconst_ptr, png_const_charp warning_message)
Definition: pngerror.c:921
png_handle_as_unknown
int PNGAPI png_handle_as_unknown(png_const_structrp png_ptr, png_const_bytep chunk_name)
Definition: png.c:926
png_image::height
png_uint_32 height
Definition: png.h:2676
PNG_INFO_pHYs
#define PNG_INFO_pHYs
Definition: png.h:739
PNG_FILTER_VALUE_SUB
#define PNG_FILTER_VALUE_SUB
Definition: png.h:1477
png_set_packing
void PNGAPI png_set_packing(png_structrp png_ptr)
Definition: pngtrans.c:50
png_error
else png_error(png_ptr, "png_image_write_to_memory: PNG too big")
png_set_swap
void PNGAPI png_set_swap(png_structrp png_ptr)
Definition: pngtrans.c:35
png_uint_16p
png_uint_16 * png_uint_16p
Definition: pngconf.h:585
png_write_image_16bit
static int png_write_image_16bit(png_voidp argument)
Definition: pngwrite.c:1532
png_struct_def::io_ptr
png_voidp io_ptr
Definition: pngstruct.h:158
png_debug1
#define png_debug1(l, m, p1)
Definition: pngdebug.h:148
PNG_LIBPNG_VER_STRING
#define PNG_LIBPNG_VER_STRING
Definition: png.h:280
PNG_ZBUF_SIZE
#define PNG_ZBUF_SIZE
Definition: pnglibconf.h:211
PNG_FLAG_ZSTREAM_INITIALIZED
#define PNG_FLAG_ZSTREAM_INITIALIZED
Definition: pngpriv.h:680
PNG_FLAG_BENIGN_ERRORS_WARN
#define PNG_FLAG_BENIGN_ERRORS_WARN
Definition: pngpriv.h:699
write_unknown_chunks
static void write_unknown_chunks(png_structrp png_ptr, png_const_inforp info_ptr, unsigned int where)
Definition: pngwrite.c:24
png_alloc_size_t
size_t png_alloc_size_t
Definition: pngconf.h:557
png_destroy_png_struct
void png_destroy_png_struct(png_structrp png_ptr)
Definition: pngmem.c:25
PNG_SHIFT
#define PNG_SHIFT
Definition: pngpriv.h:645
png_time_struct::minute
png_byte minute
Definition: png.h:606
PNG_INFO_cHRM
#define PNG_INFO_cHRM
Definition: png.h:734
png_write_sig
void PNGAPI png_write_sig(png_structrp png_ptr)
Definition: pngwutil.c:51
PNG_ROWBYTES
#define PNG_ROWBYTES(pixel_bits, width)
Definition: pngpriv.h:738
png_write_chunk
void PNGAPI png_write_chunk(png_structrp png_ptr, png_const_bytep chunk_string, png_const_bytep data, size_t length)
Definition: pngwutil.c:192
png_write_tIME
void png_write_tIME(png_structrp png_ptr, png_const_timep mod_time)
Definition: pngwutil.c:1863
png_set_gAMA_fixed
png_const_structrp png_const_inforp png_fixed_point *int_file_gamma png_set_gAMA_fixed
Definition: png.h:2004
void
static void(PNGCBAPI image_memory_write)(png_structp png_ptr
Definition: pngwrite.c:2193
png_write_pHYs
void png_write_pHYs(png_structrp png_ptr, png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit, int unit_type)
Definition: pngwutil.c:1839
PNG_COLOR_MASK_COLOR
#define PNG_COLOR_MASK_COLOR
Definition: png.h:664
PNG_HAVE_PNG_SIGNATURE
#define PNG_HAVE_PNG_SIGNATURE
Definition: pngpriv.h:636
png_compress_IDAT
void png_compress_IDAT(png_structrp png_ptr, png_const_bytep input, png_alloc_size_t input_len, int flush)
Definition: pngwutil.c:931
PNG_TRANSFORM_SWAP_ALPHA
#define PNG_TRANSFORM_SWAP_ALPHA
Definition: png.h:841
png_color_struct::red
png_byte red
Definition: png.h:480
PNG_WROTE_INFO_BEFORE_PLTE
#define PNG_WROTE_INFO_BEFORE_PLTE
Definition: pngpriv.h:634
createSpeedLookupTable.int
int
Definition: createSpeedLookupTable.py:15
png_row_info_struct
Definition: png.h:754
PNG_PACK
#define PNG_PACK
Definition: pngpriv.h:644
PNG_INFO_sBIT
#define PNG_INFO_sBIT
Definition: png.h:733
filters
static const char * filters[]
Definition: screen_filebrowser.cpp:44
png_do_write_transformations
void png_do_write_transformations(png_structrp png_ptr, png_row_infop row_info)
Definition: pngwtran.c:501
PNG_WROTE_tIME
#define PNG_WROTE_tIME
Definition: pngpriv.h:633
png_write_eXIf
void png_write_eXIf(png_structrp png_ptr, png_bytep exif, int num_exif)
Definition: pngwutil.c:1477
PNG_TRANSFORM_SWAP_ENDIAN
#define PNG_TRANSFORM_SWAP_ENDIAN
Definition: png.h:842
PNG_INFO_hIST
#define PNG_INFO_hIST
Definition: png.h:738
png_time_struct::day
png_byte day
Definition: png.h:604
PNG_FILTER_SUB
#define PNG_FILTER_SUB
Definition: png.h:1466
ob
png_alloc_size_t ob
Definition: pngwrite.c:2173
png_app_warning
void png_app_warning(png_const_structrp png_ptr, png_const_charp error_message)
Definition: pngerror.c:392
png_row_info_struct::rowbytes
size_t rowbytes
Definition: png.h:757
png_control::info_ptr
png_infop info_ptr
Definition: pngpriv.h:2038
png_app_error
void png_app_error(png_const_structrp png_ptr, png_const_charp error_message)
Definition: pngerror.c:405
PNG_INFO_iCCP
#define PNG_INFO_iCCP
Definition: png.h:744
PNG_TRANSFORM_SHIFT
#define PNG_TRANSFORM_SHIFT
Definition: png.h:839
png_row_info_struct::bit_depth
png_byte bit_depth
Definition: png.h:759
png_convert_from_struct_tm
void PNGAPI png_convert_from_struct_tm(png_timep ptime, const struct tm *ttime)
Definition: pngwrite.c:472
PNG_FORMAT_FLAG_ALPHA
#define PNG_FORMAT_FLAG_ALPHA
Definition: png.h:2777
png_write_info_before_PLTE
void PNGAPI png_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr)
Definition: pngwrite.c:84
PNG_GAMMA_sRGB_INVERSE
#define PNG_GAMMA_sRGB_INVERSE
Definition: pngpriv.h:906
png_time_struct::hour
png_byte hour
Definition: png.h:605
png_control::png_ptr
png_structp png_ptr
Definition: pngpriv.h:2037
PNG_Z_DEFAULT_COMPRESSION
#define PNG_Z_DEFAULT_COMPRESSION
Definition: pnglibconf.h:213
png_warning
void PNGAPI png_warning(png_const_structrp png_ptr, png_const_charp warning_message)
Definition: pngerror.c:216
heuristic_method
png_structrp int heuristic_method
Definition: png.h:1488
png_do_write_interlace
void png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
Definition: pngwutil.c:2096
png_int_32
png_int_32(PNGAPI png_get_int_32)(png_const_bytep buf)
Definition: pngrutil.c:84
PNG_ALL_FILTERS
#define PNG_ALL_FILTERS
Definition: png.h:1471
PNG_DIV257
#define PNG_DIV257(v16)
Definition: pngpriv.h:735
PNG_COLOR_MASK_ALPHA
#define PNG_COLOR_MASK_ALPHA
Definition: png.h:665
PNG_INFO_IDAT
#define PNG_INFO_IDAT
Definition: png.h:747
PNG_TEXT_COMPRESSION_zTXt_WR
#define PNG_TEXT_COMPRESSION_zTXt_WR
Definition: png.h:587
png_destroy_info_struct
void PNGAPI png_destroy_info_struct(png_const_structrp png_ptr, png_infopp info_ptr_ptr)
Definition: png.c:386
png_write_sRGB
void png_write_sRGB(png_structrp png_ptr, int srgb_intent)
Definition: pngwutil.c:1099
PNG_COLOR_TYPE_PALETTE
#define PNG_COLOR_TYPE_PALETTE
Definition: png.h:669
PNG_USER_TRANSFORM
#define PNG_USER_TRANSFORM
Definition: pngpriv.h:662
size
static png_bytep size_t size
Definition: pngwrite.c:2170
png_do_write_intrapixel
static void png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
Definition: pngwrite.c:634
png_image::opaque
png_controlp opaque
Definition: png.h:2673
png_set_bgr
void PNGAPI png_set_bgr(png_structrp png_ptr)
Definition: pngtrans.c:21