/*---------------------------------------------------------------------------
wpng - simple PNG-writing program writepng.c
---------------------------------------------------------------------------
Copyright (c) 1998-2000 Greg Roelofs. All rights reserved.
This software is provided "as is," without warranty of any kind,
express or implied. In no event shall the author or contributors
be held liable for any damages arising in any way from the use of
this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute
it freely, subject to the following restrictions:
1. Redistributions of source code must retain the above copyright
notice, disclaimer, and this list of conditions.
2. Redistributions in binary form must reproduce the above copyright
notice, disclaimer, and this list of conditions in the documenta-
3. All advertising materials mentioning features or use of this
software must display the following acknowledgment:
This product includes software developed by Greg Roelofs
and contributors for the book, "PNG: The Definitive Guide,"
published by O'Reilly and Associates.
---------------------------------------------------------------------------*/
#include <stdlib.h> /* for exit() prototype */
#include "writepng.h" /* typedefs, common macros, public prototypes */
/* local prototype */
void writepng_version_info(void)
{
}
/* returns 0 for success, 2 for libpng problem, 4 for out of memory, 11 for
* unexpected pnmtype; note that outfile might be stdout */
{
/* could also replace libpng warning-handler (final NULL), but no need: */
if (!png_ptr)
return 4; /* out of memory */
if (!info_ptr) {
return 4; /* out of memory */
}
/* setjmp() must be called in every function that calls a PNG-writing
* libpng function, unless an alternate error handler was installed--
* but compatible error handlers must either use longjmp() themselves
* (as in this program) or exit immediately, so here we go: */
return 2;
}
/* make sure outfile is (re)opened in BINARY mode */
/* set the compression levels--in general, always want to leave filtering
* turned on (except for palette images) and allow all of the filters,
* which is the default; want 32K zlib window, unless entire image buffer
* is 16K or smaller (unknown here)--also the default; usually want max
* compression (NOT the default); and remaining compression flags should
* be left alone */
/*
>> this is default for no filtering; Z_FILTERED is default otherwise:
png_set_compression_strategy(png_ptr, Z_DEFAULT_STRATEGY);
>> these are all defaults:
png_set_compression_mem_level(png_ptr, 8);
png_set_compression_window_bits(png_ptr, 15);
png_set_compression_method(png_ptr, 8);
*/
/* set the image parameters appropriately */
else {
return 11;
}
}
if (mainprog_ptr->have_time) {
}
if (mainprog_ptr->have_text) {
int num_text = 0;
++num_text;
}
++num_text;
}
++num_text;
}
++num_text;
}
++num_text;
}
++num_text;
}
}
/* write all chunks up to (but not including) first IDAT */
/* if we wanted to write any more text info *after* the image data, we
* would set up text struct(s) here and call png_set_text() again, with
* just the new data; png_set_tIME() could also go here, but it would
* have no effect since we already called it above (only one tIME chunk
* allowed) */
/* set up the transformations: for now, just pack low-bit-depth pixels
* into bytes (one, two or four pixels per byte) */
/* png_set_shift(png_ptr, &sig_bit); to scale low-bit-depth values */
/* make sure we save our pointers for use in writepng_encode_image() */
/* OK, that's all we need to do for now; return happy */
return 0;
}
/* returns 0 for success, 2 for libpng (longjmp) problem */
{
/* as always, setjmp() must be called in every function that calls a
* PNG-writing libpng function */
return 2;
}
/* and now we just write the whole image; libpng takes care of interlacing
* for us */
/* since that's it, we also close out the end of the PNG file now--if we
* had any text or time info to write after the IDATs, second argument
* would be info_ptr, but we optimize slightly by sending NULL pointer: */
return 0;
}
/* returns 0 if succeeds, 2 if libpng problem */
{
/* as always, setjmp() must be called in every function that calls a
* PNG-writing libpng function */
return 2;
}
/* image_data points at our one row of image data */
return 0;
}
/* returns 0 if succeeds, 2 if libpng problem */
{
/* as always, setjmp() must be called in every function that calls a
* PNG-writing libpng function */
return 2;
}
/* close out PNG file; if we had any text or time info to write after
* the IDATs, second argument would be info_ptr: */
return 0;
}
{
}
{
/* This function, aside from the extra step of retrieving the "error
* pointer" (below) and the fact that it exists within the application
* rather than within libpng, is essentially identical to libpng's
* default error handler. The second point is critical: since both
* setjmp() and longjmp() are called from the same code, they are
* guaranteed to have compatible notions of how big a jmp_buf is,
* regardless of whether _BSD_SOURCE or anything else has (or has not)
* been defined. */
"writepng severe error: jmpbuf not recoverable; terminating.\n");
exit(99);
}
}