[libpng15] Simplified read/write API initial version; basic read/write tested

on a variety of images, limited documentation (in the header file.)
This commit is contained in:
John Bowler
2011-11-07 22:33:49 -06:00
committed by Glenn Randers-Pehrson
parent 92a1d46c8d
commit 7875d534cb
13 changed files with 2186 additions and 32 deletions

View File

@@ -673,4 +673,84 @@ png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
}
}
#endif
#if defined PNG_SIMPLIFIED_READ_SUPPORTED ||\
defined PNG_SIMPLIFIED_WRITE_SUPPORTED
/* Currently the above both depend on SETJMP_SUPPORTED, however it would be
* possible to implement without setjmp support just so long as there is some
* way to handle the error return here:
*/
PNG_FUNCTION(void /* PRIVATE */,
png_safe_error,(png_structp png_ptr, png_const_charp error_message),
PNG_NORETURN)
{
png_imagep image = png_ptr->error_ptr;
/* An error is always logged here, overwriting anything (typically a warning)
* that is already there:
*/
if (image != NULL)
{
png_safecat(image->message, sizeof image->message, 0, error_message);
image->warning_or_error = 1;
/* Retrieve the jmp_buf from within the png_control */
if (image->opaque != NULL && image->opaque->error_buf != NULL)
longjmp(image->opaque->error_buf, 1);
/* Missing longjmp buffer, the following is to help debugging: */
{
size_t pos = png_safecat(image->message, sizeof image->message, 0,
"bad longjmp: ");
png_safecat(image->message, sizeof image->message, pos, error_message);
}
}
/* Here on an internal programming error. */
abort();
}
#ifdef PNG_WARNINGS_SUPPORTED
void /* PRIVATE */
png_safe_warning(png_structp png_ptr, png_const_charp warning_message)
{
png_imagep image = png_ptr->error_ptr;
/* A warning is just logged if there is no warning or error. */
if (image->warning_or_error == 0)
{
png_safecat(image->message, sizeof image->message, 0, warning_message);
image->warning_or_error = 2;
}
}
#endif
int /* PRIVATE */
png_safe_execute(png_imagep imageIn, int (*function)(png_voidp), png_voidp arg)
{
volatile png_imagep image = imageIn;
volatile int result;
volatile png_voidp saved_error_buf;
jmp_buf safe_jmpbuf;
/* Safely execute function(arg) with png_error returning to this function. */
saved_error_buf = image->opaque->error_buf;
result = setjmp(safe_jmpbuf) == 0;
if (result)
{
image->opaque->error_buf = safe_jmpbuf;
result = function(arg);
}
image->opaque->error_buf = saved_error_buf;
/* And do the cleanup prior to any failure return. */
if (!result)
png_image_free(image);
return result;
}
#endif /* SIMPLIFIED READ/WRITE */
#endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */