AshanGimhana's picture
Upload folder using huggingface_hub
9375c9a verified
<html><!-- Created using the cpp_pretty_printer from the dlib C++ library. See http://dlib.net for updates. --><head><title>dlib C++ Library - pngwrite.c</title></head><body bgcolor='white'><pre>
<font color='#009900'>/* pngwrite.c - general routines to write a PNG file
*
* Last changed in libpng 1.6.2 [April 25, 2013]
* Copyright (c) 1998-2013 Glenn Randers-Pehrson
* (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)
* (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)
*
* This code is released under the libpng license.
* For conditions of distribution and use, see the disclaimer
* and license in png.h
*/</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='pngpriv.h.html'>pngpriv.h</a>"
<font color='#0000FF'>#if</font> defined<font face='Lucida Console'>(</font>PNG_SIMPLIFIED_WRITE_SUPPORTED<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> defined<font face='Lucida Console'>(</font>PNG_STDIO_SUPPORTED<font face='Lucida Console'>)</font>
# include <font color='#5555FF'>&lt;</font>errno.h<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_SUPPORTED
<font color='#0000FF'>#ifdef</font> PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
<font color='#009900'>/* Write out all the unknown chunks for the current given location */</font>
<font color='#0000FF'>static</font> <font color='#0000FF'><u>void</u></font>
<b><a name='write_unknown_chunks'></a>write_unknown_chunks</b><font face='Lucida Console'>(</font>png_structrp png_ptr, png_const_inforp info_ptr,
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>int</u></font> where<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>unknown_chunks_num<font face='Lucida Console'>)</font>
<b>{</b>
png_const_unknown_chunkp up;
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>5</font>, "<font color='#CC0000'>writing extra chunks</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>up <font color='#5555FF'>=</font> info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>unknown_chunks;
up <font color='#5555FF'>&lt;</font> info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>unknown_chunks <font color='#5555FF'>+</font> info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>unknown_chunks_num;
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>up<font face='Lucida Console'>)</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>up<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>location <font color='#5555FF'>&amp;</font> where<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>/* If per-chunk unknown chunk handling is enabled use it, otherwise
* just write the chunks the application has set.
*/</font>
<font color='#0000FF'>#ifdef</font> PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
<font color='#0000FF'><u>int</u></font> keep <font color='#5555FF'>=</font> <font color='#BB00BB'>png_handle_as_unknown</font><font face='Lucida Console'>(</font>png_ptr, up<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>name<font face='Lucida Console'>)</font>;
<font color='#009900'>/* NOTE: this code is radically different from the read side in the
* matter of handling an ancillary unknown chunk. In the read side
* the default behavior is to discard it, in the code below the default
* behavior is to write it. Critical chunks are, however, only
* written if explicitly listed or if the default is set to write all
* unknown chunks.
*
* The default handling is also slightly weird - it is not possible to
* stop the writing of all unsafe-to-copy chunks!
*
* TODO: REVIEW: this would seem to be a bug.
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>keep <font color='#5555FF'>!</font><font color='#5555FF'>=</font> PNG_HANDLE_CHUNK_NEVER <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
<font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>up<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>name[<font color='#979000'>3</font>] <font color='#5555FF'>&amp;</font> <font color='#979000'>0x20</font><font face='Lucida Console'>)</font> <font color='#009900'>/* safe-to-copy overrides everything */</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font>
keep <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_HANDLE_CHUNK_ALWAYS <font color='#5555FF'>|</font><font color='#5555FF'>|</font>
<font face='Lucida Console'>(</font>keep <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_HANDLE_CHUNK_AS_DEFAULT <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>unknown_default <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_HANDLE_CHUNK_ALWAYS<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<font color='#0000FF'>#endif</font>
<b>{</b>
<font color='#009900'>/* TODO: review, what is wrong with a zero length unknown chunk? */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>up<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>size <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Writing zero-length unknown chunk</font>"<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>png_write_chunk</font><font face='Lucida Console'>(</font>png_ptr, up<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>name, up<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>data, up<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>size<font face='Lucida Console'>)</font>;
<b>}</b>
<b>}</b>
<b>}</b>
<b>}</b>
<font color='#0000FF'>#endif</font> <font color='#009900'>/* PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED */</font>
<font color='#009900'>/* Writes all the PNG information. This is the suggested way to use the
* library. If you have a new chunk to add, make a function to write it,
* and put it in the correct location here. If you want the chunk written
* after the image data, put it in png_write_end(). I strongly encourage
* you to supply a PNG_INFO_ flag, and check info_ptr-&gt;valid before writing
* the chunk, as that will keep the code from breaking if you want to just
* write a plain PNG file. If you have long comments, I suggest writing
* them in png_write_end(), and compressing them.
*/</font>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_write_info_before_PLTE'></a>png_write_info_before_PLTE</b><font face='Lucida Console'>(</font>png_structrp png_ptr, png_const_inforp info_ptr<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_write_info_before_PLTE</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL <font color='#5555FF'>|</font><font color='#5555FF'>|</font> info_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>mode <font color='#5555FF'>&amp;</font> PNG_WROTE_INFO_BEFORE_PLTE<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>/* Write PNG signature */</font>
<font color='#BB00BB'>png_write_sig</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#ifdef</font> PNG_MNG_FEATURES_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>mode<font color='#5555FF'>&amp;</font>PNG_HAVE_PNG_SIGNATURE<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> \
<font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>mng_features_permitted<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>MNG features are not allowed in a PNG datastream</font>"<font face='Lucida Console'>)</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>mng_features_permitted <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
<b>}</b>
<font color='#0000FF'>#endif</font>
<font color='#009900'>/* Write IHDR information. */</font>
<font color='#BB00BB'>png_write_IHDR</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>width, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>height,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>bit_depth, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>color_type, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>compression_type,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>filter_type,
<font color='#0000FF'>#ifdef</font> PNG_WRITE_INTERLACING_SUPPORTED
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>interlace_type
<font color='#0000FF'>#else</font>
<font color='#979000'>0</font>
<font color='#0000FF'>#endif</font>
<font face='Lucida Console'>)</font>;
<font color='#009900'>/* The rest of these check to see if the valid field has the appropriate
* flag set, and if it does, writes the chunk.
*
* 1.6.0: COLORSPACE support controls the writing of these chunks too, and
* the chunks will be written if the WRITE routine is there and information
* is available in the COLORSPACE. (See png_colorspace_sync_info in png.c
* for where the valid flags get set.)
*
* Under certain circumstances the colorspace can be invalidated without
* syncing the info_struct 'valid' flags; this happens if libpng detects and
* error and calls png_error while the color space is being set, yet the
* application continues writing the PNG. So check the 'invalid' flag here
* too.
*/</font>
<font color='#0000FF'>#ifdef</font> PNG_GAMMA_SUPPORTED
# ifdef PNG_WRITE_gAMA_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>colorspace.flags <font color='#5555FF'>&amp;</font> PNG_COLORSPACE_INVALID<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
<font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>colorspace.flags <font color='#5555FF'>&amp;</font> PNG_COLORSPACE_FROM_gAMA<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
<font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>valid <font color='#5555FF'>&amp;</font> PNG_INFO_gAMA<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_write_gAMA_fixed</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>colorspace.gamma<font face='Lucida Console'>)</font>;
# endif
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_COLORSPACE_SUPPORTED
<font color='#009900'>/* Write only one of sRGB or an ICC profile. If a profile was supplied
* and it matches one of the known sRGB ones issue a warning.
*/</font>
# ifdef PNG_WRITE_iCCP_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>colorspace.flags <font color='#5555FF'>&amp;</font> PNG_COLORSPACE_INVALID<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
<font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>valid <font color='#5555FF'>&amp;</font> PNG_INFO_iCCP<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<b>{</b>
# ifdef PNG_WRITE_sRGB_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>valid <font color='#5555FF'>&amp;</font> PNG_INFO_sRGB<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_app_warning</font><font face='Lucida Console'>(</font>png_ptr,
"<font color='#CC0000'>profile matches sRGB but writing iCCP instead</font>"<font face='Lucida Console'>)</font>;
# endif
<font color='#BB00BB'>png_write_iCCP</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>iccp_name,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>iccp_profile<font face='Lucida Console'>)</font>;
<b>}</b>
# ifdef PNG_WRITE_sRGB_SUPPORTED
<font color='#0000FF'>else</font>
# endif
# endif
# ifdef PNG_WRITE_sRGB_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>colorspace.flags <font color='#5555FF'>&amp;</font> PNG_COLORSPACE_INVALID<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
<font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>valid <font color='#5555FF'>&amp;</font> PNG_INFO_sRGB<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_write_sRGB</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>colorspace.rendering_intent<font face='Lucida Console'>)</font>;
# endif <font color='#009900'>/* WRITE_sRGB */</font>
<font color='#0000FF'>#endif</font> <font color='#009900'>/* COLORSPACE */</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_sBIT_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>valid <font color='#5555FF'>&amp;</font> PNG_INFO_sBIT<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_write_sBIT</font><font face='Lucida Console'>(</font>png_ptr, <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>sig_bit<font face='Lucida Console'>)</font>, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>color_type<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_COLORSPACE_SUPPORTED
# ifdef PNG_WRITE_cHRM_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>colorspace.flags <font color='#5555FF'>&amp;</font> PNG_COLORSPACE_INVALID<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
<font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>colorspace.flags <font color='#5555FF'>&amp;</font> PNG_COLORSPACE_FROM_cHRM<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
<font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>valid <font color='#5555FF'>&amp;</font> PNG_INFO_cHRM<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_write_cHRM_fixed</font><font face='Lucida Console'>(</font>png_ptr, <font color='#5555FF'>&amp;</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>colorspace.end_points_xy<font face='Lucida Console'>)</font>;
# endif
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
<font color='#BB00BB'>write_unknown_chunks</font><font face='Lucida Console'>(</font>png_ptr, info_ptr, PNG_HAVE_IHDR<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>mode <font color='#5555FF'>|</font><font color='#5555FF'>=</font> PNG_WROTE_INFO_BEFORE_PLTE;
<b>}</b>
<b>}</b>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_write_info'></a>png_write_info</b><font face='Lucida Console'>(</font>png_structrp png_ptr, png_const_inforp info_ptr<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>#if</font> defined<font face='Lucida Console'>(</font>PNG_WRITE_TEXT_SUPPORTED<font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> defined<font face='Lucida Console'>(</font>PNG_WRITE_sPLT_SUPPORTED<font face='Lucida Console'>)</font>
<font color='#0000FF'><u>int</u></font> i;
<font color='#0000FF'>#endif</font>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_write_info</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL <font color='#5555FF'>|</font><font color='#5555FF'>|</font> info_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
<font color='#BB00BB'>png_write_info_before_PLTE</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>valid <font color='#5555FF'>&amp;</font> PNG_INFO_PLTE<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_write_PLTE</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>palette,
<font face='Lucida Console'>(</font>png_uint_32<font face='Lucida Console'>)</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>num_palette<font face='Lucida Console'>)</font>;
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>color_type <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_COLOR_TYPE_PALETTE<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_error</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Valid palette required for paletted images</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#ifdef</font> PNG_WRITE_tRNS_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>valid <font color='#5555FF'>&amp;</font> PNG_INFO_tRNS<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_INVERT_ALPHA_SUPPORTED
<font color='#009900'>/* Invert the alpha channel (in tRNS) */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>transformations <font color='#5555FF'>&amp;</font> PNG_INVERT_ALPHA<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>color_type <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_COLOR_TYPE_PALETTE<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'><u>int</u></font> j;
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j<font color='#5555FF'>&lt;</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>int</u></font><font face='Lucida Console'>)</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>num_trans; j<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font>
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>trans_alpha[j] <font color='#5555FF'>=</font>
<font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font color='#979000'>255</font> <font color='#5555FF'>-</font> info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>trans_alpha[j]<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>#endif</font>
<font color='#BB00BB'>png_write_tRNS</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>trans_alpha, <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>trans_color<font face='Lucida Console'>)</font>,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>num_trans, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>color_type<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_bKGD_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>valid <font color='#5555FF'>&amp;</font> PNG_INFO_bKGD<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_write_bKGD</font><font face='Lucida Console'>(</font>png_ptr, <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>background<font face='Lucida Console'>)</font>, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>color_type<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_hIST_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>valid <font color='#5555FF'>&amp;</font> PNG_INFO_hIST<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_write_hIST</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>hist, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>num_palette<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_oFFs_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>valid <font color='#5555FF'>&amp;</font> PNG_INFO_oFFs<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_write_oFFs</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>x_offset, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>y_offset,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>offset_unit_type<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_pCAL_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>valid <font color='#5555FF'>&amp;</font> PNG_INFO_pCAL<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_write_pCAL</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>pcal_purpose, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>pcal_X0,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>pcal_X1, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>pcal_type, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>pcal_nparams,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>pcal_units, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>pcal_params<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_sCAL_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>valid <font color='#5555FF'>&amp;</font> PNG_INFO_sCAL<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_write_sCAL_s</font><font face='Lucida Console'>(</font>png_ptr, <font face='Lucida Console'>(</font><font color='#0000FF'><u>int</u></font><font face='Lucida Console'>)</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>scal_unit,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>scal_s_width, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>scal_s_height<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font> <font color='#009900'>/* sCAL */</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_pHYs_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>valid <font color='#5555FF'>&amp;</font> PNG_INFO_pHYs<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_write_pHYs</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>x_pixels_per_unit,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>y_pixels_per_unit, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>phys_unit_type<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font> <font color='#009900'>/* pHYs */</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_tIME_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>valid <font color='#5555FF'>&amp;</font> PNG_INFO_tIME<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_write_tIME</font><font face='Lucida Console'>(</font>png_ptr, <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>mod_time<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>mode <font color='#5555FF'>|</font><font color='#5555FF'>=</font> PNG_WROTE_tIME;
<b>}</b>
<font color='#0000FF'>#endif</font> <font color='#009900'>/* tIME */</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_sPLT_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>valid <font color='#5555FF'>&amp;</font> PNG_INFO_sPLT<font face='Lucida Console'>)</font>
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>int</u></font><font face='Lucida Console'>)</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>splt_palettes_num; i<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_write_sPLT</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>splt_palettes <font color='#5555FF'>+</font> i<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font> <font color='#009900'>/* sPLT */</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_TEXT_SUPPORTED
<font color='#009900'>/* Check to see if we need to write text chunks */</font>
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>num_text; i<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug2</font><font face='Lucida Console'>(</font><font color='#979000'>2</font>, "<font color='#CC0000'>Writing header text chunk %d, type %d</font>", i,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].compression<font face='Lucida Console'>)</font>;
<font color='#009900'>/* An internationalized chunk? */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].compression <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_iTXt_SUPPORTED
<font color='#009900'>/* Write international chunk */</font>
<font color='#BB00BB'>png_write_iTXt</font><font face='Lucida Console'>(</font>png_ptr,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].compression,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].key,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].lang,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].lang_key,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].text<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#else</font>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Unable to write international text</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#009900'>/* Mark this chunk as written */</font>
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].compression <font color='#5555FF'>=</font> PNG_TEXT_COMPRESSION_NONE_WR;
<b>}</b>
<font color='#009900'>/* If we want a compressed text chunk */</font>
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].compression <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_TEXT_COMPRESSION_zTXt<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_zTXt_SUPPORTED
<font color='#009900'>/* Write compressed chunk */</font>
<font color='#BB00BB'>png_write_zTXt</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].key,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].text, <font color='#979000'>0</font>,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].compression<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#else</font>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Unable to write compressed text</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#009900'>/* Mark this chunk as written */</font>
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].compression <font color='#5555FF'>=</font> PNG_TEXT_COMPRESSION_zTXt_WR;
<b>}</b>
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].compression <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_TEXT_COMPRESSION_NONE<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_tEXt_SUPPORTED
<font color='#009900'>/* Write uncompressed chunk */</font>
<font color='#BB00BB'>png_write_tEXt</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].key,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].text,
<font color='#979000'>0</font><font face='Lucida Console'>)</font>;
<font color='#009900'>/* Mark this chunk as written */</font>
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].compression <font color='#5555FF'>=</font> PNG_TEXT_COMPRESSION_NONE_WR;
<font color='#0000FF'>#else</font>
<font color='#009900'>/* Can't get here */</font>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Unable to write uncompressed text</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<b>}</b>
<b>}</b>
<font color='#0000FF'>#endif</font> <font color='#009900'>/* tEXt */</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
<font color='#BB00BB'>write_unknown_chunks</font><font face='Lucida Console'>(</font>png_ptr, info_ptr, PNG_HAVE_PLTE<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<b>}</b>
<font color='#009900'>/* Writes the end of the PNG file. If you don't want to write comments or
* time information, you can pass NULL for info. If you already wrote these
* in png_write_info(), do not write them again here. If you have long
* comments, I suggest writing them here, and compressing them.
*/</font>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_write_end'></a>png_write_end</b><font face='Lucida Console'>(</font>png_structrp png_ptr, png_inforp info_ptr<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_write_end</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>mode <font color='#5555FF'>&amp;</font> PNG_HAVE_IDAT<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_error</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>No IDATs written into file</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#ifdef</font> PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>num_palette_max <font color='#5555FF'>&gt;</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>num_palette<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_benign_error</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Wrote palette index exceeding num_palette</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#009900'>/* See if user wants us to write information chunks */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_TEXT_SUPPORTED
<font color='#0000FF'><u>int</u></font> i; <font color='#009900'>/* local index variable */</font>
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_tIME_SUPPORTED
<font color='#009900'>/* Check to see if user has supplied a time chunk */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>valid <font color='#5555FF'>&amp;</font> PNG_INFO_tIME<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
<font color='#5555FF'>!</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>mode <font color='#5555FF'>&amp;</font> PNG_WROTE_tIME<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_write_tIME</font><font face='Lucida Console'>(</font>png_ptr, <font color='#5555FF'>&amp;</font><font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>mod_time<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_TEXT_SUPPORTED
<font color='#009900'>/* Loop through comment chunks */</font>
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>num_text; i<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug2</font><font face='Lucida Console'>(</font><font color='#979000'>2</font>, "<font color='#CC0000'>Writing trailer text chunk %d, type %d</font>", i,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].compression<font face='Lucida Console'>)</font>;
<font color='#009900'>/* An internationalized chunk? */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].compression <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_iTXt_SUPPORTED
<font color='#009900'>/* Write international chunk */</font>
<font color='#BB00BB'>png_write_iTXt</font><font face='Lucida Console'>(</font>png_ptr,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].compression,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].key,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].lang,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].lang_key,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].text<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#else</font>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Unable to write international text</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#009900'>/* Mark this chunk as written */</font>
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].compression <font color='#5555FF'>=</font> PNG_TEXT_COMPRESSION_NONE_WR;
<b>}</b>
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].compression <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> PNG_TEXT_COMPRESSION_zTXt<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_zTXt_SUPPORTED
<font color='#009900'>/* Write compressed chunk */</font>
<font color='#BB00BB'>png_write_zTXt</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].key,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].text, <font color='#979000'>0</font>,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].compression<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#else</font>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Unable to write compressed text</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#009900'>/* Mark this chunk as written */</font>
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].compression <font color='#5555FF'>=</font> PNG_TEXT_COMPRESSION_zTXt_WR;
<b>}</b>
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].compression <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_TEXT_COMPRESSION_NONE<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_tEXt_SUPPORTED
<font color='#009900'>/* Write uncompressed chunk */</font>
<font color='#BB00BB'>png_write_tEXt</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].key,
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].text, <font color='#979000'>0</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>#else</font>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Unable to write uncompressed text</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#009900'>/* Mark this chunk as written */</font>
info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>text[i].compression <font color='#5555FF'>=</font> PNG_TEXT_COMPRESSION_NONE_WR;
<b>}</b>
<b>}</b>
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
<font color='#BB00BB'>write_unknown_chunks</font><font face='Lucida Console'>(</font>png_ptr, info_ptr, PNG_AFTER_IDAT<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<b>}</b>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>mode <font color='#5555FF'>|</font><font color='#5555FF'>=</font> PNG_AFTER_IDAT;
<font color='#009900'>/* Write end of PNG file */</font>
<font color='#BB00BB'>png_write_IEND</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#009900'>/* This flush, added in libpng-1.0.8, removed from libpng-1.0.9beta03,
* and restored again in libpng-1.2.30, may cause some applications that
* do not set png_ptr-&gt;output_flush_fn to crash. If your application
* experiences a problem, please try building libpng with
* PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to
* png-mng-implement at lists.sf.net .
*/</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_FLUSH_SUPPORTED
# ifdef PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED
<font color='#BB00BB'>png_flush</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
# endif
<font color='#0000FF'>#endif</font>
<b>}</b>
<font color='#0000FF'>#ifdef</font> PNG_CONVERT_tIME_SUPPORTED
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_convert_from_struct_tm'></a>png_convert_from_struct_tm</b><font face='Lucida Console'>(</font>png_timep ptime, PNG_CONST <font color='#0000FF'>struct</font> tm <font color='#5555FF'>*</font> ttime<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_convert_from_struct_tm</font>"<font face='Lucida Console'>)</font>;
ptime<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>year <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_uint_16<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font color='#979000'>1900</font> <font color='#5555FF'>+</font> ttime<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>tm_year<font face='Lucida Console'>)</font>;
ptime<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>month <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>ttime<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>tm_mon <font color='#5555FF'>+</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>;
ptime<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>day <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font>ttime<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>tm_mday;
ptime<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>hour <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font>ttime<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>tm_hour;
ptime<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>minute <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font>ttime<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>tm_min;
ptime<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>second <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font>ttime<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>tm_sec;
<b>}</b>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_convert_from_time_t'></a>png_convert_from_time_t</b><font face='Lucida Console'>(</font>png_timep ptime, time_t ttime<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>struct</font> tm <font color='#5555FF'>*</font>tbuf;
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_convert_from_time_t</font>"<font face='Lucida Console'>)</font>;
tbuf <font color='#5555FF'>=</font> <font color='#BB00BB'>gmtime</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>ttime<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>png_convert_from_struct_tm</font><font face='Lucida Console'>(</font>ptime, tbuf<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>#endif</font>
<font color='#009900'>/* Initialize png_ptr structure, and allocate any memory needed */</font>
<b><a name='PNG_FUNCTION'></a>PNG_FUNCTION</b><font face='Lucida Console'>(</font>png_structp,PNGAPI
png_create_write_struct,<font face='Lucida Console'>(</font>png_const_charp user_png_ver, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn<font face='Lucida Console'>)</font>,PNG_ALLOCATED<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>#ifndef</font> PNG_USER_MEM_SUPPORTED
png_structrp png_ptr <font color='#5555FF'>=</font> <font color='#BB00BB'>png_create_png_struct</font><font face='Lucida Console'>(</font>user_png_ver, error_ptr,
error_fn, warn_fn, NULL, NULL, NULL<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#else</font>
<font color='#0000FF'>return</font> <font color='#BB00BB'>png_create_write_struct_2</font><font face='Lucida Console'>(</font>user_png_ver, error_ptr, error_fn,
warn_fn, NULL, NULL, NULL<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>/* Alternate initialize png_ptr structure, and allocate any memory needed */</font>
<b><a name='PNG_FUNCTION'></a>PNG_FUNCTION</b><font face='Lucida Console'>(</font>png_structp,PNGAPI
png_create_write_struct_2,<font face='Lucida Console'>(</font>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<font face='Lucida Console'>)</font>,PNG_ALLOCATED<font face='Lucida Console'>)</font>
<b>{</b>
png_structrp png_ptr <font color='#5555FF'>=</font> <font color='#BB00BB'>png_create_png_struct</font><font face='Lucida Console'>(</font>user_png_ver, error_ptr,
error_fn, warn_fn, mem_ptr, malloc_fn, free_fn<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font> <font color='#009900'>/* PNG_USER_MEM_SUPPORTED */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>/* Set the zlib control values to defaults; they can be overridden by the
* application after the struct has been created.
*/</font>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zbuffer_size <font color='#5555FF'>=</font> PNG_ZBUF_SIZE;
<font color='#009900'>/* The 'zlib_strategy' setting is irrelevant because png_default_claim in
* pngwutil.c defaults it according to whether or not filters will be
* used, and ignores this setting.
*/</font>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_strategy <font color='#5555FF'>=</font> PNG_Z_DEFAULT_STRATEGY;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_level <font color='#5555FF'>=</font> PNG_Z_DEFAULT_COMPRESSION;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_mem_level <font color='#5555FF'>=</font> <font color='#979000'>8</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_window_bits <font color='#5555FF'>=</font> <font color='#979000'>15</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_method <font color='#5555FF'>=</font> <font color='#979000'>8</font>;
<font color='#0000FF'>#ifdef</font> PNG_WRITE_COMPRESSED_TEXT_SUPPORTED
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_text_strategy <font color='#5555FF'>=</font> PNG_TEXT_Z_DEFAULT_STRATEGY;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_text_level <font color='#5555FF'>=</font> PNG_TEXT_Z_DEFAULT_COMPRESSION;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_text_mem_level <font color='#5555FF'>=</font> <font color='#979000'>8</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_text_window_bits <font color='#5555FF'>=</font> <font color='#979000'>15</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_text_method <font color='#5555FF'>=</font> <font color='#979000'>8</font>;
<font color='#0000FF'>#endif</font> <font color='#009900'>/* PNG_WRITE_COMPRESSED_TEXT_SUPPORTED */</font>
<font color='#009900'>/* This is a highly dubious configuration option; by default it is off,
* but it may be appropriate for private builds that are testing
* extensions not conformant to the current specification, or of
* applications that must not fail to write at all costs!
*/</font>
<font color='#0000FF'>#ifdef</font> PNG_BENIGN_WRITE_ERRORS_SUPPORTED
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>flags <font color='#5555FF'>|</font><font color='#5555FF'>=</font> PNG_FLAG_BENIGN_ERRORS_WARN;
<font color='#009900'>/* In stable builds only warn if an application error can be completely
* handled.
*/</font>
<font color='#0000FF'>#endif</font>
<font color='#009900'>/* App warnings are warnings in release (or release candidate) builds but
* are errors during development.
*/</font>
<font color='#0000FF'>#if</font> PNG_LIBPNG_BUILD_BASE_TYPE <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> PNG_LIBPNG_BUILD_RC
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>flags <font color='#5555FF'>|</font><font color='#5555FF'>=</font> PNG_FLAG_APP_WARNINGS_WARN;
<font color='#0000FF'>#endif</font>
<font color='#009900'>/* TODO: delay this, it can be done in png_init_io() (if the app doesn't
* do it itself) avoiding setting the default function if it is not
* required.
*/</font>
<font color='#BB00BB'>png_set_write_fn</font><font face='Lucida Console'>(</font>png_ptr, NULL, NULL, NULL<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>return</font> png_ptr;
<b>}</b>
<font color='#009900'>/* Write a few rows of image data. If the image is interlaced,
* either you will have to write the 7 sub images, or, if you
* have called png_set_interlace_handling(), you will have to
* "write" the image seven times.
*/</font>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_write_rows'></a>png_write_rows</b><font face='Lucida Console'>(</font>png_structrp png_ptr, png_bytepp row,
png_uint_32 num_rows<font face='Lucida Console'>)</font>
<b>{</b>
png_uint_32 i; <font color='#009900'>/* row counter */</font>
png_bytepp rp; <font color='#009900'>/* row pointer */</font>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_write_rows</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
<font color='#009900'>/* Loop through the rows */</font>
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>=</font> <font color='#979000'>0</font>, rp <font color='#5555FF'>=</font> row; i <font color='#5555FF'>&lt;</font> num_rows; i<font color='#5555FF'>+</font><font color='#5555FF'>+</font>, rp<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_write_row</font><font face='Lucida Console'>(</font>png_ptr, <font color='#5555FF'>*</font>rp<font face='Lucida Console'>)</font>;
<b>}</b>
<b>}</b>
<font color='#009900'>/* Write the image. You only need to call this function once, even
* if you are writing an interlaced image.
*/</font>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_write_image'></a>png_write_image</b><font face='Lucida Console'>(</font>png_structrp png_ptr, png_bytepp image<font face='Lucida Console'>)</font>
<b>{</b>
png_uint_32 i; <font color='#009900'>/* row index */</font>
<font color='#0000FF'><u>int</u></font> pass, num_pass; <font color='#009900'>/* pass variables */</font>
png_bytepp rp; <font color='#009900'>/* points to current row */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_write_image</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#ifdef</font> PNG_WRITE_INTERLACING_SUPPORTED
<font color='#009900'>/* Initialize interlace handling. If image is not interlaced,
* this will set pass to 1
*/</font>
num_pass <font color='#5555FF'>=</font> <font color='#BB00BB'>png_set_interlace_handling</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#else</font>
num_pass <font color='#5555FF'>=</font> <font color='#979000'>1</font>;
<font color='#0000FF'>#endif</font>
<font color='#009900'>/* Loop through passes */</font>
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>pass <font color='#5555FF'>=</font> <font color='#979000'>0</font>; pass <font color='#5555FF'>&lt;</font> num_pass; pass<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>/* Loop through image */</font>
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>=</font> <font color='#979000'>0</font>, rp <font color='#5555FF'>=</font> image; i <font color='#5555FF'>&lt;</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>height; i<font color='#5555FF'>+</font><font color='#5555FF'>+</font>, rp<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_write_row</font><font face='Lucida Console'>(</font>png_ptr, <font color='#5555FF'>*</font>rp<font face='Lucida Console'>)</font>;
<b>}</b>
<b>}</b>
<b>}</b>
<font color='#009900'>/* Called by user to write a row of image data */</font>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_write_row'></a>png_write_row</b><font face='Lucida Console'>(</font>png_structrp png_ptr, png_const_bytep row<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>/* 1.5.6: moved from png_struct to be a local structure: */</font>
png_row_info row_info;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
<font color='#BB00BB'>png_debug2</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_write_row (row %u, pass %d)</font>",
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_number, png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>pass<font face='Lucida Console'>)</font>;
<font color='#009900'>/* Initialize transformations and other stuff if first time */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_number <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>pass <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>/* Make sure we wrote the header info */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>mode <font color='#5555FF'>&amp;</font> PNG_WROTE_INFO_BEFORE_PLTE<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_error</font><font face='Lucida Console'>(</font>png_ptr,
"<font color='#CC0000'>png_write_info was never called before png_write_row</font>"<font face='Lucida Console'>)</font>;
<font color='#009900'>/* Check for transforms that have been set but were defined out */</font>
<font color='#0000FF'>#if</font> <font color='#5555FF'>!</font>defined<font face='Lucida Console'>(</font>PNG_WRITE_INVERT_SUPPORTED<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> defined<font face='Lucida Console'>(</font>PNG_READ_INVERT_SUPPORTED<font face='Lucida Console'>)</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>transformations <font color='#5555FF'>&amp;</font> PNG_INVERT_MONO<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>PNG_WRITE_INVERT_SUPPORTED is not defined</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#if</font> <font color='#5555FF'>!</font>defined<font face='Lucida Console'>(</font>PNG_WRITE_FILLER_SUPPORTED<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> defined<font face='Lucida Console'>(</font>PNG_READ_FILLER_SUPPORTED<font face='Lucida Console'>)</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>transformations <font color='#5555FF'>&amp;</font> PNG_FILLER<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>PNG_WRITE_FILLER_SUPPORTED is not defined</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#if</font> <font color='#5555FF'>!</font>defined<font face='Lucida Console'>(</font>PNG_WRITE_PACKSWAP_SUPPORTED<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> \
<font color='#BB00BB'>defined</font><font face='Lucida Console'>(</font>PNG_READ_PACKSWAP_SUPPORTED<font face='Lucida Console'>)</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>transformations <font color='#5555FF'>&amp;</font> PNG_PACKSWAP<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr,
"<font color='#CC0000'>PNG_WRITE_PACKSWAP_SUPPORTED is not defined</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#if</font> <font color='#5555FF'>!</font>defined<font face='Lucida Console'>(</font>PNG_WRITE_PACK_SUPPORTED<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> defined<font face='Lucida Console'>(</font>PNG_READ_PACK_SUPPORTED<font face='Lucida Console'>)</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>transformations <font color='#5555FF'>&amp;</font> PNG_PACK<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>PNG_WRITE_PACK_SUPPORTED is not defined</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#if</font> <font color='#5555FF'>!</font>defined<font face='Lucida Console'>(</font>PNG_WRITE_SHIFT_SUPPORTED<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> defined<font face='Lucida Console'>(</font>PNG_READ_SHIFT_SUPPORTED<font face='Lucida Console'>)</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>transformations <font color='#5555FF'>&amp;</font> PNG_SHIFT<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>PNG_WRITE_SHIFT_SUPPORTED is not defined</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#if</font> <font color='#5555FF'>!</font>defined<font face='Lucida Console'>(</font>PNG_WRITE_BGR_SUPPORTED<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> defined<font face='Lucida Console'>(</font>PNG_READ_BGR_SUPPORTED<font face='Lucida Console'>)</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>transformations <font color='#5555FF'>&amp;</font> PNG_BGR<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>PNG_WRITE_BGR_SUPPORTED is not defined</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#if</font> <font color='#5555FF'>!</font>defined<font face='Lucida Console'>(</font>PNG_WRITE_SWAP_SUPPORTED<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> defined<font face='Lucida Console'>(</font>PNG_READ_SWAP_SUPPORTED<font face='Lucida Console'>)</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>transformations <font color='#5555FF'>&amp;</font> PNG_SWAP_BYTES<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>PNG_WRITE_SWAP_SUPPORTED is not defined</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#BB00BB'>png_write_start_row</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_INTERLACING_SUPPORTED
<font color='#009900'>/* If interlaced and not interested in row, return */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>interlaced <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>transformations <font color='#5555FF'>&amp;</font> PNG_INTERLACE<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>switch</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>pass<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>case</font> <font color='#979000'>0</font>:
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_number <font color='#5555FF'>&amp;</font> <font color='#979000'>0x07</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_write_finish_row</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font>;
<b>}</b>
<font color='#0000FF'>break</font>;
<font color='#0000FF'>case</font> <font color='#979000'>1</font>:
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_number <font color='#5555FF'>&amp;</font> <font color='#979000'>0x07</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>width <font color='#5555FF'>&lt;</font> <font color='#979000'>5</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_write_finish_row</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font>;
<b>}</b>
<font color='#0000FF'>break</font>;
<font color='#0000FF'>case</font> <font color='#979000'>2</font>:
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_number <font color='#5555FF'>&amp;</font> <font color='#979000'>0x07</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>4</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_write_finish_row</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font>;
<b>}</b>
<font color='#0000FF'>break</font>;
<font color='#0000FF'>case</font> <font color='#979000'>3</font>:
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_number <font color='#5555FF'>&amp;</font> <font color='#979000'>0x03</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>width <font color='#5555FF'>&lt;</font> <font color='#979000'>3</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_write_finish_row</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font>;
<b>}</b>
<font color='#0000FF'>break</font>;
<font color='#0000FF'>case</font> <font color='#979000'>4</font>:
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_number <font color='#5555FF'>&amp;</font> <font color='#979000'>0x03</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>2</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_write_finish_row</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font>;
<b>}</b>
<font color='#0000FF'>break</font>;
<font color='#0000FF'>case</font> <font color='#979000'>5</font>:
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_number <font color='#5555FF'>&amp;</font> <font color='#979000'>0x01</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>width <font color='#5555FF'>&lt;</font> <font color='#979000'>2</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_write_finish_row</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font>;
<b>}</b>
<font color='#0000FF'>break</font>;
<font color='#0000FF'>case</font> <font color='#979000'>6</font>:
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_number <font color='#5555FF'>&amp;</font> <font color='#979000'>0x01</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_write_finish_row</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font>;
<b>}</b>
<font color='#0000FF'>break</font>;
<font color='#0000FF'>default</font>: <font color='#009900'>/* error: ignore it */</font>
<font color='#0000FF'>break</font>;
<b>}</b>
<b>}</b>
<font color='#0000FF'>#endif</font>
<font color='#009900'>/* Set up row info for transformations */</font>
row_info.color_type <font color='#5555FF'>=</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>color_type;
row_info.width <font color='#5555FF'>=</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>usr_width;
row_info.channels <font color='#5555FF'>=</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>usr_channels;
row_info.bit_depth <font color='#5555FF'>=</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>usr_bit_depth;
row_info.pixel_depth <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>row_info.bit_depth <font color='#5555FF'>*</font> row_info.channels<font face='Lucida Console'>)</font>;
row_info.rowbytes <font color='#5555FF'>=</font> <font color='#BB00BB'>PNG_ROWBYTES</font><font face='Lucida Console'>(</font>row_info.pixel_depth, row_info.width<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>png_debug1</font><font face='Lucida Console'>(</font><font color='#979000'>3</font>, "<font color='#CC0000'>row_info-&gt;color_type = %d</font>", row_info.color_type<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>png_debug1</font><font face='Lucida Console'>(</font><font color='#979000'>3</font>, "<font color='#CC0000'>row_info-&gt;width = %u</font>", row_info.width<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>png_debug1</font><font face='Lucida Console'>(</font><font color='#979000'>3</font>, "<font color='#CC0000'>row_info-&gt;channels = %d</font>", row_info.channels<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>png_debug1</font><font face='Lucida Console'>(</font><font color='#979000'>3</font>, "<font color='#CC0000'>row_info-&gt;bit_depth = %d</font>", row_info.bit_depth<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>png_debug1</font><font face='Lucida Console'>(</font><font color='#979000'>3</font>, "<font color='#CC0000'>row_info-&gt;pixel_depth = %d</font>", row_info.pixel_depth<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>png_debug1</font><font face='Lucida Console'>(</font><font color='#979000'>3</font>, "<font color='#CC0000'>row_info-&gt;rowbytes = %lu</font>", <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>row_info.rowbytes<font face='Lucida Console'>)</font>;
<font color='#009900'>/* Copy user's row into buffer, leaving room for filter byte. */</font>
<font color='#BB00BB'>memcpy</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_buf <font color='#5555FF'>+</font> <font color='#979000'>1</font>, row, row_info.rowbytes<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#ifdef</font> PNG_WRITE_INTERLACING_SUPPORTED
<font color='#009900'>/* Handle interlacing */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>interlaced <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>pass <font color='#5555FF'>&lt;</font> <font color='#979000'>6</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
<font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>transformations <font color='#5555FF'>&amp;</font> PNG_INTERLACE<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_do_write_interlace</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>row_info, png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_buf <font color='#5555FF'>+</font> <font color='#979000'>1</font>, png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>pass<font face='Lucida Console'>)</font>;
<font color='#009900'>/* This should always get caught above, but still ... */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font face='Lucida Console'>(</font>row_info.width<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_write_finish_row</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font>;
<b>}</b>
<b>}</b>
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_TRANSFORMS_SUPPORTED
<font color='#009900'>/* Handle other transformations */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>transformations<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_do_write_transformations</font><font face='Lucida Console'>(</font>png_ptr, <font color='#5555FF'>&amp;</font>row_info<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#009900'>/* At this point the row_info pixel depth must match the 'transformed' depth,
* which is also the output depth.
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>row_info.pixel_depth <font color='#5555FF'>!</font><font color='#5555FF'>=</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>pixel_depth <font color='#5555FF'>|</font><font color='#5555FF'>|</font>
row_info.pixel_depth <font color='#5555FF'>!</font><font color='#5555FF'>=</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>transformed_pixel_depth<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_error</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>internal write transform logic error</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#ifdef</font> PNG_MNG_FEATURES_SUPPORTED
<font color='#009900'>/* Write filter_method 64 (intrapixel differencing) only if
* 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and
* 2. Libpng did not write a PNG signature (this filter_method is only
* used in PNG datastreams that are embedded in MNG datastreams) and
* 3. The application called png_permit_mng_features with a mask that
* included PNG_FLAG_MNG_FILTER_64 and
* 4. The filter_method is 64 and
* 5. The color_type is RGB or RGBA
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>mng_features_permitted <font color='#5555FF'>&amp;</font> PNG_FLAG_MNG_FILTER_64<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
<font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>filter_type <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_INTRAPIXEL_DIFFERENCING<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>/* Intrapixel differencing */</font>
<font color='#BB00BB'>png_do_write_intrapixel</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>row_info, png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_buf <font color='#5555FF'>+</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>#endif</font>
<font color='#009900'>/* Added at libpng-1.5.10 */</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED
<font color='#009900'>/* Check for out-of-range palette index */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>row_info.color_type <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_COLOR_TYPE_PALETTE <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>num_palette_max <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_do_check_palette_indexes</font><font face='Lucida Console'>(</font>png_ptr, <font color='#5555FF'>&amp;</font>row_info<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#009900'>/* Find a filter if necessary, filter the row and write it out. */</font>
<font color='#BB00BB'>png_write_find_filter</font><font face='Lucida Console'>(</font>png_ptr, <font color='#5555FF'>&amp;</font>row_info<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>write_row_fn <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>write_row_fn<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>png_ptr, png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_number, png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>pass<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_FLUSH_SUPPORTED
<font color='#009900'>/* Set the automatic flush interval or 0 to turn flushing off */</font>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_set_flush'></a>png_set_flush</b><font face='Lucida Console'>(</font>png_structrp png_ptr, <font color='#0000FF'><u>int</u></font> nrows<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_set_flush</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>flush_dist <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>nrows <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font> ? <font color='#979000'>0</font> : nrows<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>/* Flush the current output buffers now */</font>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_write_flush'></a>png_write_flush</b><font face='Lucida Console'>(</font>png_structrp png_ptr<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_write_flush</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
<font color='#009900'>/* We have already written out all of the data */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_number <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>num_rows<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
<font color='#BB00BB'>png_compress_IDAT</font><font face='Lucida Console'>(</font>png_ptr, NULL, <font color='#979000'>0</font>, Z_SYNC_FLUSH<font face='Lucida Console'>)</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>flush_rows <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
<font color='#BB00BB'>png_flush</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>#endif</font> <font color='#009900'>/* PNG_WRITE_FLUSH_SUPPORTED */</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
<font color='#0000FF'>static</font> <font color='#0000FF'><u>void</u></font> <b><a name='png_reset_filter_heuristics'></a>png_reset_filter_heuristics</b><font face='Lucida Console'>(</font>png_structrp png_ptr<font face='Lucida Console'>)</font>;<font color='#009900'>/* forward decl */</font>
<font color='#0000FF'>#endif</font>
<font color='#009900'>/* Free any memory used in png_ptr struct without freeing the struct itself. */</font>
<font color='#0000FF'>static</font> <font color='#0000FF'><u>void</u></font>
<b><a name='png_write_destroy'></a>png_write_destroy</b><font face='Lucida Console'>(</font>png_structrp png_ptr<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_write_destroy</font>"<font face='Lucida Console'>)</font>;
<font color='#009900'>/* Free any memory zlib uses */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>flags <font color='#5555FF'>&amp;</font> PNG_FLAG_ZSTREAM_INITIALIZED<font face='Lucida Console'>)</font>
<font color='#BB00BB'>deflateEnd</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zstream<font face='Lucida Console'>)</font>;
<font color='#009900'>/* Free our memory. png_free checks NULL for us. */</font>
<font color='#BB00BB'>png_free_buffer_list</font><font face='Lucida Console'>(</font>png_ptr, <font color='#5555FF'>&amp;</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zbuffer_list<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>png_free</font><font face='Lucida Console'>(</font>png_ptr, png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_buf<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#ifdef</font> PNG_WRITE_FILTER_SUPPORTED
<font color='#BB00BB'>png_free</font><font face='Lucida Console'>(</font>png_ptr, png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>prev_row<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>png_free</font><font face='Lucida Console'>(</font>png_ptr, png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>sub_row<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>png_free</font><font face='Lucida Console'>(</font>png_ptr, png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>up_row<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>png_free</font><font face='Lucida Console'>(</font>png_ptr, png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>avg_row<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>png_free</font><font face='Lucida Console'>(</font>png_ptr, png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>paeth_row<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
<font color='#009900'>/* Use this to save a little code space, it doesn't free the filter_costs */</font>
<font color='#BB00BB'>png_reset_filter_heuristics</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>png_free</font><font face='Lucida Console'>(</font>png_ptr, png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>filter_costs<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>png_free</font><font face='Lucida Console'>(</font>png_ptr, png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>inv_filter_costs<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_SET_UNKNOWN_CHUNKS_SUPPORTED
<font color='#BB00BB'>png_free</font><font face='Lucida Console'>(</font>png_ptr, png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>chunk_list<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#009900'>/* The error handling and memory handling information is left intact at this
* point: the jmp_buf may still have to be freed. See png_destroy_png_struct
* for how this happens.
*/</font>
<b>}</b>
<font color='#009900'>/* Free all memory used by the write.
* In libpng 1.6.0 this API changed quietly to no longer accept a NULL value for
* *png_ptr_ptr. Prior to 1.6.0 it would accept such a value and it would free
* the passed in info_structs but it would quietly fail to free any of the data
* inside them. In 1.6.0 it quietly does nothing (it has to be quiet because it
* has no png_ptr.)
*/</font>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_destroy_write_struct'></a>png_destroy_write_struct</b><font face='Lucida Console'>(</font>png_structpp png_ptr_ptr, png_infopp info_ptr_ptr<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_destroy_write_struct</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr_ptr <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
png_structrp png_ptr <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>png_ptr_ptr;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font> <font color='#009900'>/* added in libpng 1.6.0 */</font>
<b>{</b>
<font color='#BB00BB'>png_destroy_info_struct</font><font face='Lucida Console'>(</font>png_ptr, info_ptr_ptr<font face='Lucida Console'>)</font>;
<font color='#5555FF'>*</font>png_ptr_ptr <font color='#5555FF'>=</font> NULL;
<font color='#BB00BB'>png_write_destroy</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>png_destroy_png_struct</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<b>}</b>
<b>}</b>
<b>}</b>
<font color='#009900'>/* Allow the application to select one or more row filters to use. */</font>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_set_filter'></a>png_set_filter</b><font face='Lucida Console'>(</font>png_structrp png_ptr, <font color='#0000FF'><u>int</u></font> method, <font color='#0000FF'><u>int</u></font> filters<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_set_filter</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
<font color='#0000FF'>#ifdef</font> PNG_MNG_FEATURES_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>mng_features_permitted <font color='#5555FF'>&amp;</font> PNG_FLAG_MNG_FILTER_64<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
<font face='Lucida Console'>(</font>method <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_INTRAPIXEL_DIFFERENCING<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
method <font color='#5555FF'>=</font> PNG_FILTER_TYPE_BASE;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>method <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_FILTER_TYPE_BASE<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>switch</font> <font face='Lucida Console'>(</font>filters <font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>PNG_ALL_FILTERS <font color='#5555FF'>|</font> <font color='#979000'>0x07</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_FILTER_SUPPORTED
<font color='#0000FF'>case</font> <font color='#979000'>5</font>:
<font color='#0000FF'>case</font> <font color='#979000'>6</font>:
<font color='#0000FF'>case</font> <font color='#979000'>7</font>: <font color='#BB00BB'>png_app_error</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Unknown row filter for method 0</font>"<font face='Lucida Console'>)</font>;
<font color='#009900'>/* FALL THROUGH */</font>
<font color='#0000FF'>#endif</font> <font color='#009900'>/* PNG_WRITE_FILTER_SUPPORTED */</font>
<font color='#0000FF'>case</font> PNG_FILTER_VALUE_NONE:
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>do_filter <font color='#5555FF'>=</font> PNG_FILTER_NONE; <font color='#0000FF'>break</font>;
<font color='#0000FF'>#ifdef</font> PNG_WRITE_FILTER_SUPPORTED
<font color='#0000FF'>case</font> PNG_FILTER_VALUE_SUB:
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>do_filter <font color='#5555FF'>=</font> PNG_FILTER_SUB; <font color='#0000FF'>break</font>;
<font color='#0000FF'>case</font> PNG_FILTER_VALUE_UP:
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>do_filter <font color='#5555FF'>=</font> PNG_FILTER_UP; <font color='#0000FF'>break</font>;
<font color='#0000FF'>case</font> PNG_FILTER_VALUE_AVG:
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>do_filter <font color='#5555FF'>=</font> PNG_FILTER_AVG; <font color='#0000FF'>break</font>;
<font color='#0000FF'>case</font> PNG_FILTER_VALUE_PAETH:
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>do_filter <font color='#5555FF'>=</font> PNG_FILTER_PAETH; <font color='#0000FF'>break</font>;
<font color='#0000FF'>default</font>:
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>do_filter <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font>filters; <font color='#0000FF'>break</font>;
<font color='#0000FF'>#else</font>
<font color='#0000FF'>default</font>:
<font color='#BB00BB'>png_app_error</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Unknown row filter for method 0</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font> <font color='#009900'>/* PNG_WRITE_FILTER_SUPPORTED */</font>
<b>}</b>
<font color='#009900'>/* If we have allocated the row_buf, this means we have already started
* with the image and we should have allocated all of the filter buffers
* that have been selected. If prev_row isn't already allocated, then
* it is too late to start using the filters that need it, since we
* will be missing the data in the previous row. If an application
* wants to start and stop using particular filters during compression,
* it should start out with all of the filters, and then add and
* remove them after the start of compression.
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_buf <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_FILTER_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>do_filter <font color='#5555FF'>&amp;</font> PNG_FILTER_SUB<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>sub_row <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>sub_row <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_bytep<font face='Lucida Console'>)</font><font color='#BB00BB'>png_malloc</font><font face='Lucida Console'>(</font>png_ptr,
<font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>rowbytes <font color='#5555FF'>+</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>sub_row[<font color='#979000'>0</font>] <font color='#5555FF'>=</font> PNG_FILTER_VALUE_SUB;
<b>}</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>do_filter <font color='#5555FF'>&amp;</font> PNG_FILTER_UP<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>up_row <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>prev_row <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Can't add Up filter after starting</font>"<font face='Lucida Console'>)</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>do_filter <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>do_filter <font color='#5555FF'>&amp;</font>
~PNG_FILTER_UP<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>else</font>
<b>{</b>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>up_row <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_bytep<font face='Lucida Console'>)</font><font color='#BB00BB'>png_malloc</font><font face='Lucida Console'>(</font>png_ptr,
<font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>rowbytes <font color='#5555FF'>+</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>up_row[<font color='#979000'>0</font>] <font color='#5555FF'>=</font> PNG_FILTER_VALUE_UP;
<b>}</b>
<b>}</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>do_filter <font color='#5555FF'>&amp;</font> PNG_FILTER_AVG<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>avg_row <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>prev_row <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Can't add Average filter after starting</font>"<font face='Lucida Console'>)</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>do_filter <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>do_filter <font color='#5555FF'>&amp;</font>
~PNG_FILTER_AVG<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>else</font>
<b>{</b>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>avg_row <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_bytep<font face='Lucida Console'>)</font><font color='#BB00BB'>png_malloc</font><font face='Lucida Console'>(</font>png_ptr,
<font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>rowbytes <font color='#5555FF'>+</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>avg_row[<font color='#979000'>0</font>] <font color='#5555FF'>=</font> PNG_FILTER_VALUE_AVG;
<b>}</b>
<b>}</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>do_filter <font color='#5555FF'>&amp;</font> PNG_FILTER_PAETH<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>paeth_row <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>prev_row <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Can't add Paeth filter after starting</font>"<font face='Lucida Console'>)</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>do_filter <font color='#5555FF'>&amp;</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>~PNG_FILTER_PAETH<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>else</font>
<b>{</b>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>paeth_row <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_bytep<font face='Lucida Console'>)</font><font color='#BB00BB'>png_malloc</font><font face='Lucida Console'>(</font>png_ptr,
<font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>rowbytes <font color='#5555FF'>+</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>paeth_row[<font color='#979000'>0</font>] <font color='#5555FF'>=</font> PNG_FILTER_VALUE_PAETH;
<b>}</b>
<b>}</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>do_filter <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_NO_FILTERS<font face='Lucida Console'>)</font>
<font color='#0000FF'>#endif</font> <font color='#009900'>/* PNG_WRITE_FILTER_SUPPORTED */</font>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>do_filter <font color='#5555FF'>=</font> PNG_FILTER_NONE;
<b>}</b>
<b>}</b>
<font color='#0000FF'>else</font>
<font color='#BB00BB'>png_error</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Unknown custom filter method</font>"<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>/* This allows us to influence the way in which libpng chooses the "best"
* filter for the current scanline. While the "minimum-sum-of-absolute-
* differences metric is relatively fast and effective, there is some
* question as to whether it can be improved upon by trying to keep the
* filtered data going to zlib more consistent, hopefully resulting in
* better compression.
*/</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_WEIGHTED_FILTER_SUPPORTED <font color='#009900'>/* GRR 970116 */</font>
<font color='#009900'>/* Convenience reset API. */</font>
<font color='#0000FF'>static</font> <font color='#0000FF'><u>void</u></font>
<b><a name='png_reset_filter_heuristics'></a>png_reset_filter_heuristics</b><font face='Lucida Console'>(</font>png_structrp png_ptr<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>/* Clear out any old values in the 'weights' - this must be done because if
* the app calls set_filter_heuristics multiple times with different
* 'num_weights' values we would otherwise potentially have wrong sized
* arrays.
*/</font>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>num_prev_filters <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>heuristic_method <font color='#5555FF'>=</font> PNG_FILTER_HEURISTIC_UNWEIGHTED;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>prev_filters <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
png_bytep old <font color='#5555FF'>=</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>prev_filters;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>prev_filters <font color='#5555FF'>=</font> NULL;
<font color='#BB00BB'>png_free</font><font face='Lucida Console'>(</font>png_ptr, old<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>filter_weights <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
png_uint_16p old <font color='#5555FF'>=</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>filter_weights;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>filter_weights <font color='#5555FF'>=</font> NULL;
<font color='#BB00BB'>png_free</font><font face='Lucida Console'>(</font>png_ptr, old<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>inv_filter_weights <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
png_uint_16p old <font color='#5555FF'>=</font> png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>inv_filter_weights;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>inv_filter_weights <font color='#5555FF'>=</font> NULL;
<font color='#BB00BB'>png_free</font><font face='Lucida Console'>(</font>png_ptr, old<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>/* Leave the filter_costs - this array is fixed size. */</font>
<b>}</b>
<font color='#0000FF'>static</font> <font color='#0000FF'><u>int</u></font>
<b><a name='png_init_filter_heuristics'></a>png_init_filter_heuristics</b><font face='Lucida Console'>(</font>png_structrp png_ptr, <font color='#0000FF'><u>int</u></font> heuristic_method,
<font color='#0000FF'><u>int</u></font> num_weights<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font> <font color='#979000'>0</font>;
<font color='#009900'>/* Clear out the arrays */</font>
<font color='#BB00BB'>png_reset_filter_heuristics</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#009900'>/* Check arguments; the 'reset' function makes the correct settings for the
* unweighted case, but we must handle the weight case by initializing the
* arrays for the caller.
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>heuristic_method <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_FILTER_HEURISTIC_WEIGHTED<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'><u>int</u></font> i;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>num_weights <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<b>{</b>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>prev_filters <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_bytep<font face='Lucida Console'>)</font><font color='#BB00BB'>png_malloc</font><font face='Lucida Console'>(</font>png_ptr,
<font face='Lucida Console'>(</font>png_uint_32<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'>sizeof</font> <font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> num_weights<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<font color='#009900'>/* To make sure that the weighting starts out fairly */</font>
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> num_weights; i<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font>
<b>{</b>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>prev_filters[i] <font color='#5555FF'>=</font> <font color='#979000'>255</font>;
<b>}</b>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>filter_weights <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_uint_16p<font face='Lucida Console'>)</font><font color='#BB00BB'>png_malloc</font><font face='Lucida Console'>(</font>png_ptr,
<font face='Lucida Console'>(</font>png_uint_32<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'>sizeof</font> <font face='Lucida Console'>(</font>png_uint_16<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> num_weights<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>inv_filter_weights <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_uint_16p<font face='Lucida Console'>)</font><font color='#BB00BB'>png_malloc</font><font face='Lucida Console'>(</font>png_ptr,
<font face='Lucida Console'>(</font>png_uint_32<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'>sizeof</font> <font face='Lucida Console'>(</font>png_uint_16<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> num_weights<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> num_weights; i<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font>
<b>{</b>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>inv_filter_weights[i] <font color='#5555FF'>=</font>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>filter_weights[i] <font color='#5555FF'>=</font> PNG_WEIGHT_FACTOR;
<b>}</b>
<font color='#009900'>/* Safe to set this now */</font>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>num_prev_filters <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font>num_weights;
<b>}</b>
<font color='#009900'>/* If, in the future, there are other filter methods, this would
* need to be based on png_ptr-&gt;filter.
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>filter_costs <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>filter_costs <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_uint_16p<font face='Lucida Console'>)</font><font color='#BB00BB'>png_malloc</font><font face='Lucida Console'>(</font>png_ptr,
<font face='Lucida Console'>(</font>png_uint_32<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'>sizeof</font> <font face='Lucida Console'>(</font>png_uint_16<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> PNG_FILTER_VALUE_LAST<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>inv_filter_costs <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_uint_16p<font face='Lucida Console'>)</font><font color='#BB00BB'>png_malloc</font><font face='Lucida Console'>(</font>png_ptr,
<font face='Lucida Console'>(</font>png_uint_32<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'>sizeof</font> <font face='Lucida Console'>(</font>png_uint_16<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> PNG_FILTER_VALUE_LAST<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> PNG_FILTER_VALUE_LAST; i<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font>
<b>{</b>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>inv_filter_costs[i] <font color='#5555FF'>=</font>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>filter_costs[i] <font color='#5555FF'>=</font> PNG_COST_FACTOR;
<b>}</b>
<font color='#009900'>/* All the arrays are inited, safe to set this: */</font>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>heuristic_method <font color='#5555FF'>=</font> PNG_FILTER_HEURISTIC_WEIGHTED;
<font color='#009900'>/* Return the 'ok' code. */</font>
<font color='#0000FF'>return</font> <font color='#979000'>1</font>;
<b>}</b>
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>heuristic_method <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_FILTER_HEURISTIC_DEFAULT <font color='#5555FF'>|</font><font color='#5555FF'>|</font>
heuristic_method <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_FILTER_HEURISTIC_UNWEIGHTED<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>return</font> <font color='#979000'>1</font>;
<b>}</b>
<font color='#0000FF'>else</font>
<b>{</b>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Unknown filter heuristic method</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font> <font color='#979000'>0</font>;
<b>}</b>
<b>}</b>
<font color='#009900'>/* Provide floating and fixed point APIs */</font>
<font color='#0000FF'>#ifdef</font> PNG_FLOATING_POINT_SUPPORTED
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_set_filter_heuristics'></a>png_set_filter_heuristics</b><font face='Lucida Console'>(</font>png_structrp png_ptr, <font color='#0000FF'><u>int</u></font> heuristic_method,
<font color='#0000FF'><u>int</u></font> num_weights, png_const_doublep filter_weights,
png_const_doublep filter_costs<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_set_filter_heuristics</font>"<font face='Lucida Console'>)</font>;
<font color='#009900'>/* The internal API allocates all the arrays and ensures that the elements of
* those arrays are set to the default value.
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font color='#BB00BB'>png_init_filter_heuristics</font><font face='Lucida Console'>(</font>png_ptr, heuristic_method, num_weights<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
<font color='#009900'>/* If using the weighted method copy in the weights. */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>heuristic_method <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_FILTER_HEURISTIC_WEIGHTED<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'><u>int</u></font> i;
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> num_weights; i<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>filter_weights[i] <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font color='#979000'>0.0</font><font face='Lucida Console'>)</font>
<b>{</b>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>inv_filter_weights[i] <font color='#5555FF'>=</font>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>filter_weights[i] <font color='#5555FF'>=</font> PNG_WEIGHT_FACTOR;
<b>}</b>
<font color='#0000FF'>else</font>
<b>{</b>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>inv_filter_weights[i] <font color='#5555FF'>=</font>
<font face='Lucida Console'>(</font>png_uint_16<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>PNG_WEIGHT_FACTOR<font color='#5555FF'>*</font>filter_weights[i]<font color='#5555FF'>+</font>.<font color='#979000'>5</font><font face='Lucida Console'>)</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>filter_weights[i] <font color='#5555FF'>=</font>
<font face='Lucida Console'>(</font>png_uint_16<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>PNG_WEIGHT_FACTOR<font color='#5555FF'>/</font>filter_weights[i]<font color='#5555FF'>+</font>.<font color='#979000'>5</font><font face='Lucida Console'>)</font>;
<b>}</b>
<b>}</b>
<font color='#009900'>/* Here is where we set the relative costs of the different filters. We
* should take the desired compression level into account when setting
* the costs, so that Paeth, for instance, has a high relative cost at low
* compression levels, while it has a lower relative cost at higher
* compression settings. The filter types are in order of increasing
* relative cost, so it would be possible to do this with an algorithm.
*/</font>
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> PNG_FILTER_VALUE_LAST; i<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>filter_costs[i] <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>1.0</font><font face='Lucida Console'>)</font>
<b>{</b>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>inv_filter_costs[i] <font color='#5555FF'>=</font>
<font face='Lucida Console'>(</font>png_uint_16<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>PNG_COST_FACTOR <font color='#5555FF'>/</font> filter_costs[i] <font color='#5555FF'>+</font> .<font color='#979000'>5</font><font face='Lucida Console'>)</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>filter_costs[i] <font color='#5555FF'>=</font>
<font face='Lucida Console'>(</font>png_uint_16<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>PNG_COST_FACTOR <font color='#5555FF'>*</font> filter_costs[i] <font color='#5555FF'>+</font> .<font color='#979000'>5</font><font face='Lucida Console'>)</font>;
<b>}</b>
<b>}</b>
<b>}</b>
<font color='#0000FF'>#endif</font> <font color='#009900'>/* FLOATING_POINT */</font>
<font color='#0000FF'>#ifdef</font> PNG_FIXED_POINT_SUPPORTED
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_set_filter_heuristics_fixed'></a>png_set_filter_heuristics_fixed</b><font face='Lucida Console'>(</font>png_structrp png_ptr, <font color='#0000FF'><u>int</u></font> heuristic_method,
<font color='#0000FF'><u>int</u></font> num_weights, png_const_fixed_point_p filter_weights,
png_const_fixed_point_p filter_costs<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_set_filter_heuristics_fixed</font>"<font face='Lucida Console'>)</font>;
<font color='#009900'>/* The internal API allocates all the arrays and ensures that the elements of
* those arrays are set to the default value.
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font color='#BB00BB'>png_init_filter_heuristics</font><font face='Lucida Console'>(</font>png_ptr, heuristic_method, num_weights<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
<font color='#009900'>/* If using the weighted method copy in the weights. */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>heuristic_method <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_FILTER_HEURISTIC_WEIGHTED<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'><u>int</u></font> i;
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> num_weights; i<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>filter_weights[i] <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<b>{</b>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>inv_filter_weights[i] <font color='#5555FF'>=</font>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>filter_weights[i] <font color='#5555FF'>=</font> PNG_WEIGHT_FACTOR;
<b>}</b>
<font color='#0000FF'>else</font>
<b>{</b>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>inv_filter_weights[i] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_uint_16<font face='Lucida Console'>)</font>
<font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>PNG_WEIGHT_FACTOR<font color='#5555FF'>*</font>filter_weights[i]<font color='#5555FF'>+</font>PNG_FP_HALF<font face='Lucida Console'>)</font><font color='#5555FF'>/</font>PNG_FP_1<font face='Lucida Console'>)</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>filter_weights[i] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_uint_16<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>PNG_WEIGHT_FACTOR<font color='#5555FF'>*</font>
PNG_FP_1<font color='#5555FF'>+</font><font face='Lucida Console'>(</font>filter_weights[i]<font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>filter_weights[i]<font face='Lucida Console'>)</font>;
<b>}</b>
<b>}</b>
<font color='#009900'>/* Here is where we set the relative costs of the different filters. We
* should take the desired compression level into account when setting
* the costs, so that Paeth, for instance, has a high relative cost at low
* compression levels, while it has a lower relative cost at higher
* compression settings. The filter types are in order of increasing
* relative cost, so it would be possible to do this with an algorithm.
*/</font>
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> PNG_FILTER_VALUE_LAST; i<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>)</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>filter_costs[i] <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> PNG_FP_1<font face='Lucida Console'>)</font>
<b>{</b>
png_uint_32 tmp;
<font color='#009900'>/* Use a 32 bit unsigned temporary here because otherwise the
* intermediate value will be a 32 bit *signed* integer (ANSI rules)
* and this will get the wrong answer on division.
*/</font>
tmp <font color='#5555FF'>=</font> PNG_COST_FACTOR<font color='#5555FF'>*</font>PNG_FP_1 <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>filter_costs[i]<font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
tmp <font color='#5555FF'>/</font><font color='#5555FF'>=</font> filter_costs[i];
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>inv_filter_costs[i] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_uint_16<font face='Lucida Console'>)</font>tmp;
tmp <font color='#5555FF'>=</font> PNG_COST_FACTOR <font color='#5555FF'>*</font> filter_costs[i] <font color='#5555FF'>+</font> PNG_FP_HALF;
tmp <font color='#5555FF'>/</font><font color='#5555FF'>=</font> PNG_FP_1;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>filter_costs[i] <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_uint_16<font face='Lucida Console'>)</font>tmp;
<b>}</b>
<b>}</b>
<b>}</b>
<font color='#0000FF'>#endif</font> <font color='#009900'>/* FIXED_POINT */</font>
<font color='#0000FF'>#endif</font> <font color='#009900'>/* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */</font>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_set_compression_level'></a>png_set_compression_level</b><font face='Lucida Console'>(</font>png_structrp png_ptr, <font color='#0000FF'><u>int</u></font> level<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_set_compression_level</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_level <font color='#5555FF'>=</font> level;
<b>}</b>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_set_compression_mem_level'></a>png_set_compression_mem_level</b><font face='Lucida Console'>(</font>png_structrp png_ptr, <font color='#0000FF'><u>int</u></font> mem_level<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_set_compression_mem_level</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_mem_level <font color='#5555FF'>=</font> mem_level;
<b>}</b>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_set_compression_strategy'></a>png_set_compression_strategy</b><font face='Lucida Console'>(</font>png_structrp png_ptr, <font color='#0000FF'><u>int</u></font> strategy<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_set_compression_strategy</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
<font color='#009900'>/* The flag setting here prevents the libpng dynamic selection of strategy.
*/</font>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>flags <font color='#5555FF'>|</font><font color='#5555FF'>=</font> PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_strategy <font color='#5555FF'>=</font> strategy;
<b>}</b>
<font color='#009900'>/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a
* smaller value of window_bits if it can do so safely.
*/</font>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_set_compression_window_bits'></a>png_set_compression_window_bits</b><font face='Lucida Console'>(</font>png_structrp png_ptr, <font color='#0000FF'><u>int</u></font> window_bits<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
<font color='#009900'>/* Prior to 1.6.0 this would warn but then set the window_bits value, this
* meant that negative window bits values could be selected which would cause
* libpng to write a non-standard PNG file with raw deflate or gzip
* compressed IDAT or ancillary chunks. Such files can be read and there is
* no warning on read, so this seems like a very bad idea.
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>window_bits <font color='#5555FF'>&gt;</font> <font color='#979000'>15</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Only compression windows &lt;= 32k supported by PNG</font>"<font face='Lucida Console'>)</font>;
window_bits <font color='#5555FF'>=</font> <font color='#979000'>15</font>;
<b>}</b>
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>window_bits <font color='#5555FF'>&lt;</font> <font color='#979000'>8</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Only compression windows &gt;= 256 supported by PNG</font>"<font face='Lucida Console'>)</font>;
window_bits <font color='#5555FF'>=</font> <font color='#979000'>8</font>;
<b>}</b>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_window_bits <font color='#5555FF'>=</font> window_bits;
<b>}</b>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_set_compression_method'></a>png_set_compression_method</b><font face='Lucida Console'>(</font>png_structrp png_ptr, <font color='#0000FF'><u>int</u></font> method<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_set_compression_method</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
<font color='#009900'>/* This would produce an invalid PNG file if it worked, but it doesn't and
* deflate will fault it, so it is harmless to just warn here.
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>method <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>8</font><font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Only compression method 8 is supported by PNG</font>"<font face='Lucida Console'>)</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_method <font color='#5555FF'>=</font> method;
<b>}</b>
<font color='#009900'>/* The following were added to libpng-1.5.4 */</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_set_text_compression_level'></a>png_set_text_compression_level</b><font face='Lucida Console'>(</font>png_structrp png_ptr, <font color='#0000FF'><u>int</u></font> level<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_set_text_compression_level</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_text_level <font color='#5555FF'>=</font> level;
<b>}</b>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_set_text_compression_mem_level'></a>png_set_text_compression_mem_level</b><font face='Lucida Console'>(</font>png_structrp png_ptr, <font color='#0000FF'><u>int</u></font> mem_level<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_set_text_compression_mem_level</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_text_mem_level <font color='#5555FF'>=</font> mem_level;
<b>}</b>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_set_text_compression_strategy'></a>png_set_text_compression_strategy</b><font face='Lucida Console'>(</font>png_structrp png_ptr, <font color='#0000FF'><u>int</u></font> strategy<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_set_text_compression_strategy</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_text_strategy <font color='#5555FF'>=</font> strategy;
<b>}</b>
<font color='#009900'>/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a
* smaller value of window_bits if it can do so safely.
*/</font>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_set_text_compression_window_bits'></a>png_set_text_compression_window_bits</b><font face='Lucida Console'>(</font>png_structrp png_ptr, <font color='#0000FF'><u>int</u></font> window_bits<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>window_bits <font color='#5555FF'>&gt;</font> <font color='#979000'>15</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Only compression windows &lt;= 32k supported by PNG</font>"<font face='Lucida Console'>)</font>;
window_bits <font color='#5555FF'>=</font> <font color='#979000'>15</font>;
<b>}</b>
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>window_bits <font color='#5555FF'>&lt;</font> <font color='#979000'>8</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Only compression windows &gt;= 256 supported by PNG</font>"<font face='Lucida Console'>)</font>;
window_bits <font color='#5555FF'>=</font> <font color='#979000'>8</font>;
<b>}</b>
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_text_window_bits <font color='#5555FF'>=</font> window_bits;
<b>}</b>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_set_text_compression_method'></a>png_set_text_compression_method</b><font face='Lucida Console'>(</font>png_structrp png_ptr, <font color='#0000FF'><u>int</u></font> method<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_set_text_compression_method</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>method <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>8</font><font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_warning</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>Only compression method 8 is supported by PNG</font>"<font face='Lucida Console'>)</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>zlib_text_method <font color='#5555FF'>=</font> method;
<b>}</b>
<font color='#0000FF'>#endif</font> <font color='#009900'>/* PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED */</font>
<font color='#009900'>/* end of API added to libpng-1.5.4 */</font>
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_set_write_status_fn'></a>png_set_write_status_fn</b><font face='Lucida Console'>(</font>png_structrp png_ptr, png_write_status_ptr write_row_fn<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>write_row_fn <font color='#5555FF'>=</font> write_row_fn;
<b>}</b>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_USER_TRANSFORM_SUPPORTED
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_set_write_user_transform_fn'></a>png_set_write_user_transform_fn</b><font face='Lucida Console'>(</font>png_structrp png_ptr, png_user_transform_ptr
write_user_transform_fn<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_debug</font><font face='Lucida Console'>(</font><font color='#979000'>1</font>, "<font color='#CC0000'>in png_set_write_user_transform_fn</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>transformations <font color='#5555FF'>|</font><font color='#5555FF'>=</font> PNG_USER_TRANSFORM;
png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>write_user_transform_fn <font color='#5555FF'>=</font> write_user_transform_fn;
<b>}</b>
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_INFO_IMAGE_SUPPORTED
<font color='#0000FF'><u>void</u></font> PNGAPI
<b><a name='png_write_png'></a>png_write_png</b><font face='Lucida Console'>(</font>png_structrp png_ptr, png_inforp info_ptr,
<font color='#0000FF'><u>int</u></font> transforms, voidp params<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL <font color='#5555FF'>|</font><font color='#5555FF'>|</font> info_ptr <font color='#5555FF'>=</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font>;
<font color='#009900'>/* Write the file header information. */</font>
<font color='#BB00BB'>png_write_info</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font face='Lucida Console'>)</font>;
<font color='#009900'>/* ------ these transformations don't touch the info structure ------- */</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_INVERT_SUPPORTED
<font color='#009900'>/* Invert monochrome pixels */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>transforms <font color='#5555FF'>&amp;</font> PNG_TRANSFORM_INVERT_MONO<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_set_invert_mono</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_SHIFT_SUPPORTED
<font color='#009900'>/* Shift the pixels up to a legal bit depth and fill in
* as appropriate to correctly scale the image.
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>transforms <font color='#5555FF'>&amp;</font> PNG_TRANSFORM_SHIFT<font face='Lucida Console'>)</font>
<font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>valid <font color='#5555FF'>&amp;</font> PNG_INFO_sBIT<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_set_shift</font><font face='Lucida Console'>(</font>png_ptr, <font color='#5555FF'>&amp;</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>sig_bit<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_PACK_SUPPORTED
<font color='#009900'>/* Pack pixels into bytes */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>transforms <font color='#5555FF'>&amp;</font> PNG_TRANSFORM_PACKING<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_set_packing</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_SWAP_ALPHA_SUPPORTED
<font color='#009900'>/* Swap location of alpha bytes from ARGB to RGBA */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>transforms <font color='#5555FF'>&amp;</font> PNG_TRANSFORM_SWAP_ALPHA<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_set_swap_alpha</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_FILLER_SUPPORTED
<font color='#009900'>/* Pack XRGB/RGBX/ARGB/RGBA into RGB (4 channels -&gt; 3 channels) */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>transforms <font color='#5555FF'>&amp;</font> PNG_TRANSFORM_STRIP_FILLER_AFTER<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_set_filler</font><font face='Lucida Console'>(</font>png_ptr, <font color='#979000'>0</font>, PNG_FILLER_AFTER<font face='Lucida Console'>)</font>;
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>transforms <font color='#5555FF'>&amp;</font> PNG_TRANSFORM_STRIP_FILLER_BEFORE<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_set_filler</font><font face='Lucida Console'>(</font>png_ptr, <font color='#979000'>0</font>, PNG_FILLER_BEFORE<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_BGR_SUPPORTED
<font color='#009900'>/* Flip BGR pixels to RGB */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>transforms <font color='#5555FF'>&amp;</font> PNG_TRANSFORM_BGR<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_set_bgr</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_SWAP_SUPPORTED
<font color='#009900'>/* Swap bytes of 16-bit files to most significant byte first */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>transforms <font color='#5555FF'>&amp;</font> PNG_TRANSFORM_SWAP_ENDIAN<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_set_swap</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_PACKSWAP_SUPPORTED
<font color='#009900'>/* Swap bits of 1, 2, 4 bit packed pixel formats */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>transforms <font color='#5555FF'>&amp;</font> PNG_TRANSFORM_PACKSWAP<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_set_packswap</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_WRITE_INVERT_ALPHA_SUPPORTED
<font color='#009900'>/* Invert the alpha channel from opacity to transparency */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>transforms <font color='#5555FF'>&amp;</font> PNG_TRANSFORM_INVERT_ALPHA<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_set_invert_alpha</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>#endif</font>
<font color='#009900'>/* ----------------------- end of transformations ------------------- */</font>
<font color='#009900'>/* Write the bits */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>valid <font color='#5555FF'>&amp;</font> PNG_INFO_IDAT<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_write_image</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_pointers<font face='Lucida Console'>)</font>;
<font color='#009900'>/* It is REQUIRED to call this to finish writing the rest of the file */</font>
<font color='#BB00BB'>png_write_end</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>PNG_UNUSED</font><font face='Lucida Console'>(</font>transforms<font face='Lucida Console'>)</font> <font color='#009900'>/* Quiet compiler warnings */</font>
<font color='#BB00BB'>PNG_UNUSED</font><font face='Lucida Console'>(</font>params<font face='Lucida Console'>)</font>
<b>}</b>
<font color='#0000FF'>#endif</font>
<font color='#0000FF'>#ifdef</font> PNG_SIMPLIFIED_WRITE_SUPPORTED
<font color='#0000FF'>#ifdef</font> PNG_STDIO_SUPPORTED <font color='#009900'>/* currently required for png_image_write_* */</font>
<font color='#009900'>/* Initialize the write structure - general purpose utility. */</font>
<font color='#0000FF'>static</font> <font color='#0000FF'><u>int</u></font>
<b><a name='png_image_write_init'></a>png_image_write_init</b><font face='Lucida Console'>(</font>png_imagep image<font face='Lucida Console'>)</font>
<b>{</b>
png_structp png_ptr <font color='#5555FF'>=</font> <font color='#BB00BB'>png_create_write_struct</font><font face='Lucida Console'>(</font>PNG_LIBPNG_VER_STRING, image,
png_safe_error, png_safe_warning<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>png_ptr <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
png_infop info_ptr <font color='#5555FF'>=</font> <font color='#BB00BB'>png_create_info_struct</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>info_ptr <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
png_controlp control <font color='#5555FF'>=</font> <font color='#BB00BB'>png_voidcast</font><font face='Lucida Console'>(</font>png_controlp,
<font color='#BB00BB'>png_malloc_warn</font><font face='Lucida Console'>(</font>png_ptr, <font face='Lucida Console'>(</font><font color='#0000FF'>sizeof</font> <font color='#5555FF'>*</font>control<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>control <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>memset</font><font face='Lucida Console'>(</font>control, <font color='#979000'>0</font>, <font face='Lucida Console'>(</font><font color='#0000FF'>sizeof</font> <font color='#5555FF'>*</font>control<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
control<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr <font color='#5555FF'>=</font> png_ptr;
control<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>info_ptr <font color='#5555FF'>=</font> info_ptr;
control<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>for_write <font color='#5555FF'>=</font> <font color='#979000'>1</font>;
image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>opaque <font color='#5555FF'>=</font> control;
<font color='#0000FF'>return</font> <font color='#979000'>1</font>;
<b>}</b>
<font color='#009900'>/* Error clean up */</font>
<font color='#BB00BB'>png_destroy_info_struct</font><font face='Lucida Console'>(</font>png_ptr, <font color='#5555FF'>&amp;</font>info_ptr<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#BB00BB'>png_destroy_write_struct</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>png_ptr, NULL<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>return</font> <font color='#BB00BB'>png_image_error</font><font face='Lucida Console'>(</font>image, "<font color='#CC0000'>png_image_write_: out of memory</font>"<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>/* Arguments to png_image_write_main: */</font>
<font color='#0000FF'>typedef</font> <font color='#0000FF'>struct</font>
<b>{</b>
<font color='#009900'>/* Arguments: */</font>
png_imagep image;
png_const_voidp buffer;
png_int_32 row_stride;
png_const_voidp colormap;
<font color='#0000FF'><u>int</u></font> convert_to_8bit;
<font color='#009900'>/* Local variables: */</font>
png_const_voidp first_row;
ptrdiff_t row_bytes;
png_voidp local_row;
<b>}</b> png_image_write_control;
<font color='#009900'>/* Write png_uint_16 input to a 16-bit PNG; the png_ptr has already been set to
* do any necessary byte swapping. The component order is defined by the
* png_image format value.
*/</font>
<font color='#0000FF'>static</font> <font color='#0000FF'><u>int</u></font>
<b><a name='png_write_image_16bit'></a>png_write_image_16bit</b><font face='Lucida Console'>(</font>png_voidp argument<font face='Lucida Console'>)</font>
<b>{</b>
png_image_write_control <font color='#5555FF'>*</font>display <font color='#5555FF'>=</font> <font color='#BB00BB'>png_voidcast</font><font face='Lucida Console'>(</font>png_image_write_control<font color='#5555FF'>*</font>,
argument<font face='Lucida Console'>)</font>;
png_imagep image <font color='#5555FF'>=</font> display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>image;
png_structrp png_ptr <font color='#5555FF'>=</font> image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>opaque<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr;
png_const_uint_16p input_row <font color='#5555FF'>=</font> <font color='#BB00BB'>png_voidcast</font><font face='Lucida Console'>(</font>png_const_uint_16p,
display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>first_row<font face='Lucida Console'>)</font>;
png_uint_16p output_row <font color='#5555FF'>=</font> <font color='#BB00BB'>png_voidcast</font><font face='Lucida Console'>(</font>png_uint_16p, display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>local_row<font face='Lucida Console'>)</font>;
png_uint_16p row_end;
<font color='#0000FF'>const</font> <font color='#0000FF'><u>int</u></font> channels <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_COLOR<font face='Lucida Console'>)</font> ? <font color='#979000'>3</font> : <font color='#979000'>1</font>;
<font color='#0000FF'><u>int</u></font> aindex <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
png_uint_32 y <font color='#5555FF'>=</font> image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>height;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_ALPHA<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_AFIRST<font face='Lucida Console'>)</font>
<b>{</b>
aindex <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>input_row; <font color='#009900'>/* To point to the first component */</font>
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>output_row;
<b>}</b>
<font color='#0000FF'>else</font>
aindex <font color='#5555FF'>=</font> channels;
<b>}</b>
<font color='#0000FF'>else</font>
<font color='#BB00BB'>png_error</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>png_write_image: internal call error</font>"<font face='Lucida Console'>)</font>;
<font color='#009900'>/* Work out the output row end and count over this, note that the increment
* above to 'row' means that row_end can actually be beyond the end of the
* row; this is correct.
*/</font>
row_end <font color='#5555FF'>=</font> output_row <font color='#5555FF'>+</font> image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>width <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>channels<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>y<font color='#5555FF'>-</font><font color='#5555FF'>-</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<b>{</b>
png_const_uint_16p in_ptr <font color='#5555FF'>=</font> input_row;
png_uint_16p out_ptr <font color='#5555FF'>=</font> output_row;
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>out_ptr <font color='#5555FF'>&lt;</font> row_end<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>const</font> png_uint_16 alpha <font color='#5555FF'>=</font> in_ptr[aindex];
png_uint_32 reciprocal <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
<font color='#0000FF'><u>int</u></font> c;
out_ptr[aindex] <font color='#5555FF'>=</font> alpha;
<font color='#009900'>/* Calculate a reciprocal. The correct calculation is simply
* component/alpha*65535 &lt;&lt; 15. (I.e. 15 bits of precision); this
* allows correct rounding by adding .5 before the shift. 'reciprocal'
* is only initialized when required.
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>alpha <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> alpha <font color='#5555FF'>&lt;</font> <font color='#979000'>65535</font><font face='Lucida Console'>)</font>
reciprocal <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#979000'>0xffff</font><font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font><font color='#979000'>15</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font face='Lucida Console'>(</font>alpha<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>alpha;
c <font color='#5555FF'>=</font> channels;
<font color='#0000FF'>do</font> <font color='#009900'>/* always at least one channel */</font>
<b>{</b>
png_uint_16 component <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>in_ptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font>;
<font color='#009900'>/* The following gives 65535 for an alpha of 0, which is fine,
* otherwise if 0/0 is represented as some other value there is more
* likely to be a discontinuity which will probably damage
* compression when moving from a fully transparent area to a
* nearly transparent one. (The assumption here is that opaque
* areas tend not to be 0 intensity.)
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>component <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> alpha<font face='Lucida Console'>)</font>
component <font color='#5555FF'>=</font> <font color='#979000'>65535</font>;
<font color='#009900'>/* component&lt;alpha, so component/alpha is less than one and
* component*reciprocal is less than 2^31.
*/</font>
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>component <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> alpha <font color='#5555FF'>&lt;</font> <font color='#979000'>65535</font><font face='Lucida Console'>)</font>
<b>{</b>
png_uint_32 calc <font color='#5555FF'>=</font> component <font color='#5555FF'>*</font> reciprocal;
calc <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>16384</font>; <font color='#009900'>/* round to nearest */</font>
component <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_uint_16<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>calc <font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font> <font color='#979000'>15</font><font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#5555FF'>*</font>out_ptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font> <font color='#5555FF'>=</font> component;
<b>}</b>
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font><font color='#5555FF'>-</font><font color='#5555FF'>-</font>c <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>;
<font color='#009900'>/* Skip to next component (skip the intervening alpha channel) */</font>
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>in_ptr;
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>out_ptr;
<b>}</b>
<font color='#BB00BB'>png_write_row</font><font face='Lucida Console'>(</font>png_ptr, <font color='#BB00BB'>png_voidcast</font><font face='Lucida Console'>(</font>png_const_bytep, display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>local_row<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
input_row <font color='#5555FF'>+</font><font color='#5555FF'>=</font> display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_bytes<font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'>sizeof</font> <font face='Lucida Console'>(</font>png_uint_16<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>return</font> <font color='#979000'>1</font>;
<b>}</b>
<font color='#009900'>/* Given 16-bit input (1 to 4 channels) write 8-bit output. If an alpha channel
* is present it must be removed from the components, the components are then
* written in sRGB encoding. No components are added or removed.
*
* Calculate an alpha reciprocal to reverse pre-multiplication. As above the
* calculation can be done to 15 bits of accuracy; however, the output needs to
* be scaled in the range 0..255*65535, so include that scaling here.
*/</font>
<font color='#0000FF'>#define</font> UNP_RECIPROCAL<font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#979000'>0xffff</font><font color='#5555FF'>*</font><font color='#979000'>0xff</font><font face='Lucida Console'>)</font><font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font><font color='#979000'>7</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font face='Lucida Console'>(</font>alpha<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>alpha<font face='Lucida Console'>)</font>
<font color='#0000FF'>static</font> png_byte
<b><a name='png_unpremultiply'></a>png_unpremultiply</b><font face='Lucida Console'>(</font>png_uint_32 component, png_uint_32 alpha,
png_uint_32 reciprocal<font color='#009900'>/*from the above macro*/</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>/* The following gives 1.0 for an alpha of 0, which is fine, otherwise if 0/0
* is represented as some other value there is more likely to be a
* discontinuity which will probably damage compression when moving from a
* fully transparent area to a nearly transparent one. (The assumption here
* is that opaque areas tend not to be 0 intensity.)
*
* There is a rounding problem here; if alpha is less than 128 it will end up
* as 0 when scaled to 8 bits. To avoid introducing spurious colors into the
* output change for this too.
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>component <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> alpha <font color='#5555FF'>|</font><font color='#5555FF'>|</font> alpha <font color='#5555FF'>&lt;</font> <font color='#979000'>128</font><font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font> <font color='#979000'>255</font>;
<font color='#009900'>/* component&lt;alpha, so component/alpha is less than one and
* component*reciprocal is less than 2^31.
*/</font>
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>component <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>/* The test is that alpha/257 (rounded) is less than 255, the first value
* that becomes 255 is 65407.
* NOTE: this must agree with the PNG_DIV257 macro (which must, therefore,
* be exact!) [Could also test reciprocal != 0]
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>alpha <font color='#5555FF'>&lt;</font> <font color='#979000'>65407</font><font face='Lucida Console'>)</font>
<b>{</b>
component <font color='#5555FF'>*</font><font color='#5555FF'>=</font> reciprocal;
component <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>64</font>; <font color='#009900'>/* round to nearest */</font>
component <font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>7</font>;
<b>}</b>
<font color='#0000FF'>else</font>
component <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font color='#979000'>255</font>;
<font color='#009900'>/* Convert the component to sRGB. */</font>
<font color='#0000FF'>return</font> <font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font><font color='#BB00BB'>PNG_sRGB_FROM_LINEAR</font><font face='Lucida Console'>(</font>component<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>else</font>
<font color='#0000FF'>return</font> <font color='#979000'>0</font>;
<b>}</b>
<font color='#0000FF'>static</font> <font color='#0000FF'><u>int</u></font>
<b><a name='png_write_image_8bit'></a>png_write_image_8bit</b><font face='Lucida Console'>(</font>png_voidp argument<font face='Lucida Console'>)</font>
<b>{</b>
png_image_write_control <font color='#5555FF'>*</font>display <font color='#5555FF'>=</font> <font color='#BB00BB'>png_voidcast</font><font face='Lucida Console'>(</font>png_image_write_control<font color='#5555FF'>*</font>,
argument<font face='Lucida Console'>)</font>;
png_imagep image <font color='#5555FF'>=</font> display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>image;
png_structrp png_ptr <font color='#5555FF'>=</font> image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>opaque<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr;
png_const_uint_16p input_row <font color='#5555FF'>=</font> <font color='#BB00BB'>png_voidcast</font><font face='Lucida Console'>(</font>png_const_uint_16p,
display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>first_row<font face='Lucida Console'>)</font>;
png_bytep output_row <font color='#5555FF'>=</font> <font color='#BB00BB'>png_voidcast</font><font face='Lucida Console'>(</font>png_bytep, display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>local_row<font face='Lucida Console'>)</font>;
png_uint_32 y <font color='#5555FF'>=</font> image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>height;
<font color='#0000FF'>const</font> <font color='#0000FF'><u>int</u></font> channels <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_COLOR<font face='Lucida Console'>)</font> ? <font color='#979000'>3</font> : <font color='#979000'>1</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_ALPHA<font face='Lucida Console'>)</font>
<b>{</b>
png_bytep row_end;
<font color='#0000FF'><u>int</u></font> aindex;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_AFIRST<font face='Lucida Console'>)</font>
<b>{</b>
aindex <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>1</font>;
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>input_row; <font color='#009900'>/* To point to the first component */</font>
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>output_row;
<b>}</b>
<font color='#0000FF'>else</font>
aindex <font color='#5555FF'>=</font> channels;
<font color='#009900'>/* Use row_end in place of a loop counter: */</font>
row_end <font color='#5555FF'>=</font> output_row <font color='#5555FF'>+</font> image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>width <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font>channels<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>y<font color='#5555FF'>-</font><font color='#5555FF'>-</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<b>{</b>
png_const_uint_16p in_ptr <font color='#5555FF'>=</font> input_row;
png_bytep out_ptr <font color='#5555FF'>=</font> output_row;
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>out_ptr <font color='#5555FF'>&lt;</font> row_end<font face='Lucida Console'>)</font>
<b>{</b>
png_uint_16 alpha <font color='#5555FF'>=</font> in_ptr[aindex];
png_byte alphabyte <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font><font color='#BB00BB'>PNG_DIV257</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font>;
png_uint_32 reciprocal <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
<font color='#0000FF'><u>int</u></font> c;
<font color='#009900'>/* Scale and write the alpha channel. */</font>
out_ptr[aindex] <font color='#5555FF'>=</font> alphabyte;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>alphabyte <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> alphabyte <font color='#5555FF'>&lt;</font> <font color='#979000'>255</font><font face='Lucida Console'>)</font>
reciprocal <font color='#5555FF'>=</font> <font color='#BB00BB'>UNP_RECIPROCAL</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font>;
c <font color='#5555FF'>=</font> channels;
<font color='#0000FF'>do</font> <font color='#009900'>/* always at least one channel */</font>
<font color='#5555FF'>*</font>out_ptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font> <font color='#5555FF'>=</font> <font color='#BB00BB'>png_unpremultiply</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>in_ptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font>, alpha, reciprocal<font face='Lucida Console'>)</font>;
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font><font color='#5555FF'>-</font><font color='#5555FF'>-</font>c <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>;
<font color='#009900'>/* Skip to next component (skip the intervening alpha channel) */</font>
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>in_ptr;
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>out_ptr;
<b>}</b> <font color='#009900'>/* while out_ptr &lt; row_end */</font>
<font color='#BB00BB'>png_write_row</font><font face='Lucida Console'>(</font>png_ptr, <font color='#BB00BB'>png_voidcast</font><font face='Lucida Console'>(</font>png_const_bytep,
display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>local_row<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
input_row <font color='#5555FF'>+</font><font color='#5555FF'>=</font> display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_bytes<font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'>sizeof</font> <font face='Lucida Console'>(</font>png_uint_16<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<b>}</b> <font color='#009900'>/* while y */</font>
<b>}</b>
<font color='#0000FF'>else</font>
<b>{</b>
<font color='#009900'>/* No alpha channel, so the row_end really is the end of the row and it
* is sufficient to loop over the components one by one.
*/</font>
png_bytep row_end <font color='#5555FF'>=</font> output_row <font color='#5555FF'>+</font> image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>width <font color='#5555FF'>*</font> channels;
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>y<font color='#5555FF'>-</font><font color='#5555FF'>-</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<b>{</b>
png_const_uint_16p in_ptr <font color='#5555FF'>=</font> input_row;
png_bytep out_ptr <font color='#5555FF'>=</font> output_row;
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>out_ptr <font color='#5555FF'>&lt;</font> row_end<font face='Lucida Console'>)</font>
<b>{</b>
png_uint_32 component <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>in_ptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font>;
component <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font color='#979000'>255</font>;
<font color='#5555FF'>*</font>out_ptr<font color='#5555FF'>+</font><font color='#5555FF'>+</font> <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font><font color='#BB00BB'>PNG_sRGB_FROM_LINEAR</font><font face='Lucida Console'>(</font>component<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#BB00BB'>png_write_row</font><font face='Lucida Console'>(</font>png_ptr, output_row<font face='Lucida Console'>)</font>;
input_row <font color='#5555FF'>+</font><font color='#5555FF'>=</font> display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_bytes<font color='#5555FF'>/</font><font face='Lucida Console'>(</font><font color='#0000FF'>sizeof</font> <font face='Lucida Console'>(</font>png_uint_16<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<b>}</b>
<b>}</b>
<font color='#0000FF'>return</font> <font color='#979000'>1</font>;
<b>}</b>
<font color='#0000FF'>static</font> <font color='#0000FF'><u>void</u></font>
<b><a name='png_image_set_PLTE'></a>png_image_set_PLTE</b><font face='Lucida Console'>(</font>png_image_write_control <font color='#5555FF'>*</font>display<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>const</font> png_imagep image <font color='#5555FF'>=</font> display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>image;
<font color='#0000FF'>const</font> <font color='#0000FF'><u>void</u></font> <font color='#5555FF'>*</font>cmap <font color='#5555FF'>=</font> display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>colormap;
<font color='#0000FF'>const</font> <font color='#0000FF'><u>int</u></font> entries <font color='#5555FF'>=</font> image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>colormap_entries <font color='#5555FF'>&gt;</font> <font color='#979000'>256</font> ? <font color='#979000'>256</font> :
<font face='Lucida Console'>(</font><font color='#0000FF'><u>int</u></font><font face='Lucida Console'>)</font>image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>colormap_entries;
<font color='#009900'>/* NOTE: the caller must check for cmap != NULL and entries != 0 */</font>
<font color='#0000FF'>const</font> png_uint_32 format <font color='#5555FF'>=</font> image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>format;
<font color='#0000FF'>const</font> <font color='#0000FF'><u>int</u></font> channels <font color='#5555FF'>=</font> <font color='#BB00BB'>PNG_IMAGE_SAMPLE_CHANNELS</font><font face='Lucida Console'>(</font>format<font face='Lucida Console'>)</font>;
# ifdef PNG_FORMAT_BGR_SUPPORTED
<font color='#0000FF'>const</font> <font color='#0000FF'><u>int</u></font> afirst <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_AFIRST<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
<font face='Lucida Console'>(</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_ALPHA<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font>;
# <font color='#0000FF'>else</font>
# define afirst <font color='#979000'>0</font>
# endif
# ifdef PNG_FORMAT_BGR_SUPPORTED
<font color='#0000FF'>const</font> <font color='#0000FF'><u>int</u></font> bgr <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_BGR<font face='Lucida Console'>)</font> ? <font color='#979000'>2</font> : <font color='#979000'>0</font>;
# <font color='#0000FF'>else</font>
# define bgr <font color='#979000'>0</font>
# endif
<font color='#0000FF'><u>int</u></font> i, num_trans;
png_color palette[<font color='#979000'>256</font>];
png_byte tRNS[<font color='#979000'>256</font>];
<font color='#BB00BB'>memset</font><font face='Lucida Console'>(</font>tRNS, <font color='#979000'>255</font>, <font face='Lucida Console'>(</font><font color='#0000FF'>sizeof</font> tRNS<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<font color='#BB00BB'>memset</font><font face='Lucida Console'>(</font>palette, <font color='#979000'>0</font>, <font face='Lucida Console'>(</font><font color='#0000FF'>sizeof</font> palette<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>i<font color='#5555FF'>=</font>num_trans<font color='#5555FF'>=</font><font color='#979000'>0</font>; i<font color='#5555FF'>&lt;</font>entries; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>/* This gets automatically converted to sRGB with reversal of the
* pre-multiplication if the color-map has an alpha channel.
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_LINEAR<font face='Lucida Console'>)</font>
<b>{</b>
png_const_uint_16p entry <font color='#5555FF'>=</font> <font color='#BB00BB'>png_voidcast</font><font face='Lucida Console'>(</font>png_const_uint_16p, cmap<font face='Lucida Console'>)</font>;
entry <font color='#5555FF'>+</font><font color='#5555FF'>=</font> i <font color='#5555FF'>*</font> channels;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>channels <font color='#5555FF'>&amp;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#009900'>/* no alpha */</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>channels <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>3</font><font face='Lucida Console'>)</font> <font color='#009900'>/* RGB */</font>
<b>{</b>
palette[i].blue <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font><font color='#BB00BB'>PNG_sRGB_FROM_LINEAR</font><font face='Lucida Console'>(</font><font color='#979000'>255</font> <font color='#5555FF'>*</font>
entry[<font face='Lucida Console'>(</font><font color='#979000'>2</font> ^ bgr<font face='Lucida Console'>)</font>]<font face='Lucida Console'>)</font>;
palette[i].green <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font><font color='#BB00BB'>PNG_sRGB_FROM_LINEAR</font><font face='Lucida Console'>(</font><font color='#979000'>255</font> <font color='#5555FF'>*</font>
entry[<font color='#979000'>1</font>]<font face='Lucida Console'>)</font>;
palette[i].red <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font><font color='#BB00BB'>PNG_sRGB_FROM_LINEAR</font><font face='Lucida Console'>(</font><font color='#979000'>255</font> <font color='#5555FF'>*</font>
entry[bgr]<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>else</font> <font color='#009900'>/* Gray */</font>
palette[i].blue <font color='#5555FF'>=</font> palette[i].red <font color='#5555FF'>=</font> palette[i].green <font color='#5555FF'>=</font>
<font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font><font color='#BB00BB'>PNG_sRGB_FROM_LINEAR</font><font face='Lucida Console'>(</font><font color='#979000'>255</font> <font color='#5555FF'>*</font> <font color='#5555FF'>*</font>entry<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>else</font> <font color='#009900'>/* alpha */</font>
<b>{</b>
png_uint_16 alpha <font color='#5555FF'>=</font> entry[afirst ? <font color='#979000'>0</font> : channels<font color='#5555FF'>-</font><font color='#979000'>1</font>];
png_byte alphabyte <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>png_byte<font face='Lucida Console'>)</font><font color='#BB00BB'>PNG_DIV257</font><font face='Lucida Console'>(</font>alpha<font face='Lucida Console'>)</font>;
png_uint_32 reciprocal <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
<font color='#009900'>/* Calculate a reciprocal, as in the png_write_image_8bit code above
* this is designed to produce a value scaled to 255*65535 when
* divided by 128 (i.e. asr 7).
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>alphabyte <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> alphabyte <font color='#5555FF'>&lt;</font> <font color='#979000'>255</font><font face='Lucida Console'>)</font>
reciprocal <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#979000'>0xffff</font><font color='#5555FF'>*</font><font color='#979000'>0xff</font><font face='Lucida Console'>)</font><font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font><font color='#979000'>7</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font face='Lucida Console'>(</font>alpha<font color='#5555FF'>&gt;</font><font color='#5555FF'>&gt;</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>alpha;
tRNS[i] <font color='#5555FF'>=</font> alphabyte;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>alphabyte <font color='#5555FF'>&lt;</font> <font color='#979000'>255</font><font face='Lucida Console'>)</font>
num_trans <font color='#5555FF'>=</font> i<font color='#5555FF'>+</font><font color='#979000'>1</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>channels <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> <font color='#979000'>3</font><font face='Lucida Console'>)</font> <font color='#009900'>/* RGB */</font>
<b>{</b>
palette[i].blue <font color='#5555FF'>=</font> <font color='#BB00BB'>png_unpremultiply</font><font face='Lucida Console'>(</font>entry[afirst <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font><font color='#979000'>2</font> ^ bgr<font face='Lucida Console'>)</font>],
alpha, reciprocal<font face='Lucida Console'>)</font>;
palette[i].green <font color='#5555FF'>=</font> <font color='#BB00BB'>png_unpremultiply</font><font face='Lucida Console'>(</font>entry[afirst <font color='#5555FF'>+</font> <font color='#979000'>1</font>], alpha,
reciprocal<font face='Lucida Console'>)</font>;
palette[i].red <font color='#5555FF'>=</font> <font color='#BB00BB'>png_unpremultiply</font><font face='Lucida Console'>(</font>entry[afirst <font color='#5555FF'>+</font> bgr], alpha,
reciprocal<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>else</font> <font color='#009900'>/* gray */</font>
palette[i].blue <font color='#5555FF'>=</font> palette[i].red <font color='#5555FF'>=</font> palette[i].green <font color='#5555FF'>=</font>
<font color='#BB00BB'>png_unpremultiply</font><font face='Lucida Console'>(</font>entry[afirst], alpha, reciprocal<font face='Lucida Console'>)</font>;
<b>}</b>
<b>}</b>
<font color='#0000FF'>else</font> <font color='#009900'>/* Color-map has sRGB values */</font>
<b>{</b>
png_const_bytep entry <font color='#5555FF'>=</font> <font color='#BB00BB'>png_voidcast</font><font face='Lucida Console'>(</font>png_const_bytep, cmap<font face='Lucida Console'>)</font>;
entry <font color='#5555FF'>+</font><font color='#5555FF'>=</font> i <font color='#5555FF'>*</font> channels;
<font color='#0000FF'>switch</font> <font face='Lucida Console'>(</font>channels<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>case</font> <font color='#979000'>4</font>:
tRNS[i] <font color='#5555FF'>=</font> entry[afirst ? <font color='#979000'>0</font> : <font color='#979000'>3</font>];
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>tRNS[i] <font color='#5555FF'>&lt;</font> <font color='#979000'>255</font><font face='Lucida Console'>)</font>
num_trans <font color='#5555FF'>=</font> i<font color='#5555FF'>+</font><font color='#979000'>1</font>;
<font color='#009900'>/* FALL THROUGH */</font>
<font color='#0000FF'>case</font> <font color='#979000'>3</font>:
palette[i].blue <font color='#5555FF'>=</font> entry[afirst <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font><font color='#979000'>2</font> ^ bgr<font face='Lucida Console'>)</font>];
palette[i].green <font color='#5555FF'>=</font> entry[afirst <font color='#5555FF'>+</font> <font color='#979000'>1</font>];
palette[i].red <font color='#5555FF'>=</font> entry[afirst <font color='#5555FF'>+</font> bgr];
<font color='#0000FF'>break</font>;
<font color='#0000FF'>case</font> <font color='#979000'>2</font>:
tRNS[i] <font color='#5555FF'>=</font> entry[<font color='#979000'>1</font> ^ afirst];
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>tRNS[i] <font color='#5555FF'>&lt;</font> <font color='#979000'>255</font><font face='Lucida Console'>)</font>
num_trans <font color='#5555FF'>=</font> i<font color='#5555FF'>+</font><font color='#979000'>1</font>;
<font color='#009900'>/* FALL THROUGH */</font>
<font color='#0000FF'>case</font> <font color='#979000'>1</font>:
palette[i].blue <font color='#5555FF'>=</font> palette[i].red <font color='#5555FF'>=</font> palette[i].green <font color='#5555FF'>=</font>
entry[afirst];
<font color='#0000FF'>break</font>;
<font color='#0000FF'>default</font>:
<font color='#0000FF'>break</font>;
<b>}</b>
<b>}</b>
<b>}</b>
# ifdef afirst
# undef afirst
# endif
# ifdef bgr
# undef bgr
# endif
<font color='#BB00BB'>png_set_PLTE</font><font face='Lucida Console'>(</font>image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>opaque<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr, image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>opaque<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>info_ptr, palette,
entries<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>num_trans <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_set_tRNS</font><font face='Lucida Console'>(</font>image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>opaque<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr, image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>opaque<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>info_ptr, tRNS,
num_trans, NULL<font face='Lucida Console'>)</font>;
image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>colormap_entries <font color='#5555FF'>=</font> entries;
<b>}</b>
<font color='#0000FF'>static</font> <font color='#0000FF'><u>int</u></font>
<b><a name='png_image_write_main'></a>png_image_write_main</b><font face='Lucida Console'>(</font>png_voidp argument<font face='Lucida Console'>)</font>
<b>{</b>
png_image_write_control <font color='#5555FF'>*</font>display <font color='#5555FF'>=</font> <font color='#BB00BB'>png_voidcast</font><font face='Lucida Console'>(</font>png_image_write_control<font color='#5555FF'>*</font>,
argument<font face='Lucida Console'>)</font>;
png_imagep image <font color='#5555FF'>=</font> display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>image;
png_structrp png_ptr <font color='#5555FF'>=</font> image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>opaque<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr;
png_inforp info_ptr <font color='#5555FF'>=</font> image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>opaque<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>info_ptr;
png_uint_32 format <font color='#5555FF'>=</font> image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>format;
<font color='#0000FF'><u>int</u></font> colormap <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_COLORMAP<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font>;
<font color='#0000FF'><u>int</u></font> linear <font color='#5555FF'>=</font> <font color='#5555FF'>!</font>colormap <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_LINEAR<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font>; <font color='#009900'>/* input */</font>
<font color='#0000FF'><u>int</u></font> alpha <font color='#5555FF'>=</font> <font color='#5555FF'>!</font>colormap <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_ALPHA<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font>;
<font color='#0000FF'><u>int</u></font> write_16bit <font color='#5555FF'>=</font> linear <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>colormap <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>convert_to_8bit;
# ifdef PNG_BENIGN_ERRORS_SUPPORTED
<font color='#009900'>/* Make sure we error out on any bad situation */</font>
<font color='#BB00BB'>png_set_benign_errors</font><font face='Lucida Console'>(</font>png_ptr, <font color='#979000'>0</font><font color='#009900'>/*error*/</font><font face='Lucida Console'>)</font>;
# endif
<font color='#009900'>/* Default the 'row_stride' parameter if required. */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_stride <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_stride <font color='#5555FF'>=</font> <font color='#BB00BB'>PNG_IMAGE_ROW_STRIDE</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>image<font face='Lucida Console'>)</font>;
<font color='#009900'>/* Set the required transforms then write the rows in the correct order. */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_COLORMAP<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>colormap <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>colormap_entries <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<b>{</b>
png_uint_32 entries <font color='#5555FF'>=</font> image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>colormap_entries;
<font color='#BB00BB'>png_set_IHDR</font><font face='Lucida Console'>(</font>png_ptr, info_ptr, image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>width, image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>height,
entries <font color='#5555FF'>&gt;</font> <font color='#979000'>16</font> ? <font color='#979000'>8</font> : <font face='Lucida Console'>(</font>entries <font color='#5555FF'>&gt;</font> <font color='#979000'>4</font> ? <font color='#979000'>4</font> : <font face='Lucida Console'>(</font>entries <font color='#5555FF'>&gt;</font> <font color='#979000'>2</font> ? <font color='#979000'>2</font> : <font color='#979000'>1</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,
PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>png_image_set_PLTE</font><font face='Lucida Console'>(</font>display<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>else</font>
<font color='#BB00BB'>png_error</font><font face='Lucida Console'>(</font>image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>opaque<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr,
"<font color='#CC0000'>no color-map for color-mapped image</font>"<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>else</font>
<font color='#BB00BB'>png_set_IHDR</font><font face='Lucida Console'>(</font>png_ptr, info_ptr, image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>width, image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>height,
write_16bit ? <font color='#979000'>16</font> : <font color='#979000'>8</font>,
<font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_COLOR<font face='Lucida Console'>)</font> ? PNG_COLOR_MASK_COLOR : <font color='#979000'>0</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font>
<font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_ALPHA<font face='Lucida Console'>)</font> ? PNG_COLOR_MASK_ALPHA : <font color='#979000'>0</font><font face='Lucida Console'>)</font>,
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE<font face='Lucida Console'>)</font>;
<font color='#009900'>/* Counter-intuitively the data transformations must be called *after*
* png_write_info, not before as in the read code, but the 'set' functions
* must still be called before. Just set the color space information, never
* write an interlaced image.
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>write_16bit<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>/* The gamma here is 1.0 (linear) and the cHRM chunk matches sRGB. */</font>
<font color='#BB00BB'>png_set_gAMA_fixed</font><font face='Lucida Console'>(</font>png_ptr, info_ptr, PNG_GAMMA_LINEAR<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font face='Lucida Console'>(</font>image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>flags <font color='#5555FF'>&amp;</font> PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_set_cHRM_fixed</font><font face='Lucida Console'>(</font>png_ptr, info_ptr,
<font color='#009900'>/* color x y */</font>
<font color='#009900'>/* white */</font> <font color='#979000'>31270</font>, <font color='#979000'>32900</font>,
<font color='#009900'>/* red */</font> <font color='#979000'>64000</font>, <font color='#979000'>33000</font>,
<font color='#009900'>/* green */</font> <font color='#979000'>30000</font>, <font color='#979000'>60000</font>,
<font color='#009900'>/* blue */</font> <font color='#979000'>15000</font>, <font color='#979000'>6000</font>
<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font face='Lucida Console'>(</font>image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>flags <font color='#5555FF'>&amp;</font> PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_set_sRGB</font><font face='Lucida Console'>(</font>png_ptr, info_ptr, PNG_sRGB_INTENT_PERCEPTUAL<font face='Lucida Console'>)</font>;
<font color='#009900'>/* Else writing an 8-bit file and the *colors* aren't sRGB, but the 8-bit
* space must still be gamma encoded.
*/</font>
<font color='#0000FF'>else</font>
<font color='#BB00BB'>png_set_gAMA_fixed</font><font face='Lucida Console'>(</font>png_ptr, info_ptr, PNG_GAMMA_sRGB_INVERSE<font face='Lucida Console'>)</font>;
<font color='#009900'>/* Write the file header. */</font>
<font color='#BB00BB'>png_write_info</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font face='Lucida Console'>)</font>;
<font color='#009900'>/* Now set up the data transformations (*after* the header is written),
* remove the handled transformations from the 'format' flags for checking.
*
* First check for a little endian system if writing 16 bit files.
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>write_16bit<font face='Lucida Console'>)</font>
<b>{</b>
PNG_CONST png_uint_16 le <font color='#5555FF'>=</font> <font color='#979000'>0x0001</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font>png_const_bytep<font face='Lucida Console'>)</font><font color='#5555FF'>&amp;</font>le<font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_set_swap</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<b>}</b>
# ifdef PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_BGR<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>colormap <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_COLOR<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_set_bgr</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
format <font color='#5555FF'>&amp;</font><font color='#5555FF'>=</font> ~PNG_FORMAT_FLAG_BGR;
<b>}</b>
# endif
# ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_AFIRST<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>colormap <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>format <font color='#5555FF'>&amp;</font> PNG_FORMAT_FLAG_ALPHA<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_set_swap_alpha</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
format <font color='#5555FF'>&amp;</font><font color='#5555FF'>=</font> ~PNG_FORMAT_FLAG_AFIRST;
<b>}</b>
# endif
<font color='#009900'>/* If there are 16 or fewer color-map entries we wrote a lower bit depth
* above, but the application data is still byte packed.
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>colormap <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>colormap_entries <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font color='#979000'>16</font><font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_set_packing</font><font face='Lucida Console'>(</font>png_ptr<font face='Lucida Console'>)</font>;
<font color='#009900'>/* That should have handled all (both) the transforms. */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>format <font color='#5555FF'>&amp;</font> ~<font face='Lucida Console'>(</font>png_uint_32<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>PNG_FORMAT_FLAG_COLOR <font color='#5555FF'>|</font> PNG_FORMAT_FLAG_LINEAR <font color='#5555FF'>|</font>
PNG_FORMAT_FLAG_ALPHA <font color='#5555FF'>|</font> PNG_FORMAT_FLAG_COLORMAP<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<font color='#BB00BB'>png_error</font><font face='Lucida Console'>(</font>png_ptr, "<font color='#CC0000'>png_write_image: unsupported transformation</font>"<font face='Lucida Console'>)</font>;
<b>{</b>
png_const_bytep row <font color='#5555FF'>=</font> <font color='#BB00BB'>png_voidcast</font><font face='Lucida Console'>(</font>png_const_bytep, display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>buffer<font face='Lucida Console'>)</font>;
ptrdiff_t row_bytes <font color='#5555FF'>=</font> display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_stride;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>linear<font face='Lucida Console'>)</font>
row_bytes <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'>sizeof</font> <font face='Lucida Console'>(</font>png_uint_16<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>row_bytes <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
row <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>height<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> <font face='Lucida Console'>(</font><font color='#5555FF'>-</font>row_bytes<font face='Lucida Console'>)</font>;
display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>first_row <font color='#5555FF'>=</font> row;
display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_bytes <font color='#5555FF'>=</font> row_bytes;
<b>}</b>
<font color='#009900'>/* Apply 'fast' options if the flag is set. */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>flags <font color='#5555FF'>&amp;</font> PNG_IMAGE_FLAG_FAST<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_set_filter</font><font face='Lucida Console'>(</font>png_ptr, PNG_FILTER_TYPE_BASE, PNG_NO_FILTERS<font face='Lucida Console'>)</font>;
<font color='#009900'>/* NOTE: determined by experiment using pngstest, this reflects some
* balance between the time to write the image once and the time to read
* it about 50 times. The speed-up in pngstest was about 10-20% of the
* total (user) time on a heavily loaded system.
*/</font>
<font color='#BB00BB'>png_set_compression_level</font><font face='Lucida Console'>(</font>png_ptr, <font color='#979000'>3</font><font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#009900'>/* Check for the cases that currently require a pre-transform on the row
* before it is written. This only applies when the input is 16-bit and
* either there is an alpha channel or it is converted to 8-bit.
*/</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>linear <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> alpha<font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>colormap <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>convert_to_8bit<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<b>{</b>
png_bytep row <font color='#5555FF'>=</font> <font color='#BB00BB'>png_voidcast</font><font face='Lucida Console'>(</font>png_bytep, <font color='#BB00BB'>png_malloc</font><font face='Lucida Console'>(</font>png_ptr,
<font color='#BB00BB'>png_get_rowbytes</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<font color='#0000FF'><u>int</u></font> result;
display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>local_row <font color='#5555FF'>=</font> row;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>write_16bit<font face='Lucida Console'>)</font>
result <font color='#5555FF'>=</font> <font color='#BB00BB'>png_safe_execute</font><font face='Lucida Console'>(</font>image, png_write_image_16bit, display<font face='Lucida Console'>)</font>;
<font color='#0000FF'>else</font>
result <font color='#5555FF'>=</font> <font color='#BB00BB'>png_safe_execute</font><font face='Lucida Console'>(</font>image, png_write_image_8bit, display<font face='Lucida Console'>)</font>;
display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>local_row <font color='#5555FF'>=</font> NULL;
<font color='#BB00BB'>png_free</font><font face='Lucida Console'>(</font>png_ptr, row<font face='Lucida Console'>)</font>;
<font color='#009900'>/* Skip the 'write_end' on error: */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>result<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font> <font color='#979000'>0</font>;
<b>}</b>
<font color='#009900'>/* Otherwise this is the case where the input is in a format currently
* supported by the rest of the libpng write code; call it directly.
*/</font>
<font color='#0000FF'>else</font>
<b>{</b>
png_const_bytep row <font color='#5555FF'>=</font> <font color='#BB00BB'>png_voidcast</font><font face='Lucida Console'>(</font>png_const_bytep, display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>first_row<font face='Lucida Console'>)</font>;
ptrdiff_t row_bytes <font color='#5555FF'>=</font> display<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>row_bytes;
png_uint_32 y <font color='#5555FF'>=</font> image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>height;
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>y<font color='#5555FF'>-</font><font color='#5555FF'>-</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#BB00BB'>png_write_row</font><font face='Lucida Console'>(</font>png_ptr, row<font face='Lucida Console'>)</font>;
row <font color='#5555FF'>+</font><font color='#5555FF'>=</font> row_bytes;
<b>}</b>
<b>}</b>
<font color='#BB00BB'>png_write_end</font><font face='Lucida Console'>(</font>png_ptr, info_ptr<font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font> <font color='#979000'>1</font>;
<b>}</b>
<font color='#0000FF'><u>int</u></font> PNGAPI
<b><a name='png_image_write_to_stdio'></a>png_image_write_to_stdio</b><font face='Lucida Console'>(</font>png_imagep image, FILE <font color='#5555FF'>*</font>file, <font color='#0000FF'><u>int</u></font> convert_to_8bit,
<font color='#0000FF'>const</font> <font color='#0000FF'><u>void</u></font> <font color='#5555FF'>*</font>buffer, png_int_32 row_stride, <font color='#0000FF'>const</font> <font color='#0000FF'><u>void</u></font> <font color='#5555FF'>*</font>colormap<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>/* Write the image to the given (FILE*). */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>image <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>version <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_IMAGE_VERSION<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>file <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>png_image_write_init</font><font face='Lucida Console'>(</font>image<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<b>{</b>
png_image_write_control display;
<font color='#0000FF'><u>int</u></font> result;
<font color='#009900'>/* This is slightly evil, but png_init_io doesn't do anything other
* than this and we haven't changed the standard IO functions so
* this saves a 'safe' function.
*/</font>
image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>opaque<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>png_ptr<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>io_ptr <font color='#5555FF'>=</font> file;
<font color='#BB00BB'>memset</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>display, <font color='#979000'>0</font>, <font face='Lucida Console'>(</font><font color='#0000FF'>sizeof</font> display<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
display.image <font color='#5555FF'>=</font> image;
display.buffer <font color='#5555FF'>=</font> buffer;
display.row_stride <font color='#5555FF'>=</font> row_stride;
display.colormap <font color='#5555FF'>=</font> colormap;
display.convert_to_8bit <font color='#5555FF'>=</font> convert_to_8bit;
result <font color='#5555FF'>=</font> <font color='#BB00BB'>png_safe_execute</font><font face='Lucida Console'>(</font>image, png_image_write_main, <font color='#5555FF'>&amp;</font>display<font face='Lucida Console'>)</font>;
<font color='#BB00BB'>png_image_free</font><font face='Lucida Console'>(</font>image<font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font> result;
<b>}</b>
<font color='#0000FF'>else</font>
<font color='#0000FF'>return</font> <font color='#979000'>0</font>;
<b>}</b>
<font color='#0000FF'>else</font>
<font color='#0000FF'>return</font> <font color='#BB00BB'>png_image_error</font><font face='Lucida Console'>(</font>image,
"<font color='#CC0000'>png_image_write_to_stdio: invalid argument</font>"<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>image <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font> <font color='#BB00BB'>png_image_error</font><font face='Lucida Console'>(</font>image,
"<font color='#CC0000'>png_image_write_to_stdio: incorrect PNG_IMAGE_VERSION</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>else</font>
<font color='#0000FF'>return</font> <font color='#979000'>0</font>;
<b>}</b>
<font color='#0000FF'><u>int</u></font> PNGAPI
<b><a name='png_image_write_to_file'></a>png_image_write_to_file</b><font face='Lucida Console'>(</font>png_imagep image, <font color='#0000FF'>const</font> <font color='#0000FF'><u>char</u></font> <font color='#5555FF'>*</font>file_name,
<font color='#0000FF'><u>int</u></font> convert_to_8bit, <font color='#0000FF'>const</font> <font color='#0000FF'><u>void</u></font> <font color='#5555FF'>*</font>buffer, png_int_32 row_stride,
<font color='#0000FF'>const</font> <font color='#0000FF'><u>void</u></font> <font color='#5555FF'>*</font>colormap<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#009900'>/* Write the image to the named file. */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>image <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> image<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>version <font color='#5555FF'>=</font><font color='#5555FF'>=</font> PNG_IMAGE_VERSION<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>file_name <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
FILE <font color='#5555FF'>*</font>fp <font color='#5555FF'>=</font> <font color='#BB00BB'>fopen</font><font face='Lucida Console'>(</font>file_name, "<font color='#CC0000'>wb</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>fp <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>png_image_write_to_stdio</font><font face='Lucida Console'>(</font>image, fp, convert_to_8bit, buffer,
row_stride, colormap<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'><u>int</u></font> error; <font color='#009900'>/* from fflush/fclose */</font>
<font color='#009900'>/* Make sure the file is flushed correctly. */</font>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>fflush</font><font face='Lucida Console'>(</font>fp<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#BB00BB'>ferror</font><font face='Lucida Console'>(</font>fp<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<b>{</b>
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>fclose</font><font face='Lucida Console'>(</font>fp<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font> <font color='#979000'>1</font>;
error <font color='#5555FF'>=</font> errno; <font color='#009900'>/* from fclose */</font>
<b>}</b>
<font color='#0000FF'>else</font>
<b>{</b>
error <font color='#5555FF'>=</font> errno; <font color='#009900'>/* from fflush or ferror */</font>
<font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font><font color='#BB00BB'>fclose</font><font face='Lucida Console'>(</font>fp<font face='Lucida Console'>)</font>;
<b>}</b>
<font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font><font color='#BB00BB'>remove</font><font face='Lucida Console'>(</font>file_name<font face='Lucida Console'>)</font>;
<font color='#009900'>/* The image has already been cleaned up; this is just used to
* set the error (because the original write succeeded).
*/</font>
<font color='#0000FF'>return</font> <font color='#BB00BB'>png_image_error</font><font face='Lucida Console'>(</font>image, <font color='#BB00BB'>strerror</font><font face='Lucida Console'>(</font>error<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>else</font>
<b>{</b>
<font color='#009900'>/* Clean up: just the opened file. */</font>
<font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font><font color='#BB00BB'>fclose</font><font face='Lucida Console'>(</font>fp<font face='Lucida Console'>)</font>;
<font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>)</font><font color='#BB00BB'>remove</font><font face='Lucida Console'>(</font>file_name<font face='Lucida Console'>)</font>;
<font color='#0000FF'>return</font> <font color='#979000'>0</font>;
<b>}</b>
<b>}</b>
<font color='#0000FF'>else</font>
<font color='#0000FF'>return</font> <font color='#BB00BB'>png_image_error</font><font face='Lucida Console'>(</font>image, <font color='#BB00BB'>strerror</font><font face='Lucida Console'>(</font>errno<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>else</font>
<font color='#0000FF'>return</font> <font color='#BB00BB'>png_image_error</font><font face='Lucida Console'>(</font>image,
"<font color='#CC0000'>png_image_write_to_file: invalid argument</font>"<font face='Lucida Console'>)</font>;
<b>}</b>
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>image <font color='#5555FF'>!</font><font color='#5555FF'>=</font> NULL<font face='Lucida Console'>)</font>
<font color='#0000FF'>return</font> <font color='#BB00BB'>png_image_error</font><font face='Lucida Console'>(</font>image,
"<font color='#CC0000'>png_image_write_to_file: incorrect PNG_IMAGE_VERSION</font>"<font face='Lucida Console'>)</font>;
<font color='#0000FF'>else</font>
<font color='#0000FF'>return</font> <font color='#979000'>0</font>;
<b>}</b>
<font color='#0000FF'>#endif</font> <font color='#009900'>/* PNG_STDIO_SUPPORTED */</font>
<font color='#0000FF'>#endif</font> <font color='#009900'>/* SIMPLIFIED_WRITE */</font>
<font color='#0000FF'>#endif</font> <font color='#009900'>/* PNG_WRITE_SUPPORTED */</font>
</pre></body></html>