From ed3ca0e3eba05442c9cc06ba2ba93e57b4a4164b Mon Sep 17 00:00:00 2001 From: John Bowler Date: Fri, 31 Aug 2012 17:32:36 -0500 Subject: [PATCH] [libpng16] Fixed the simplified API example programs and improved the error message if the version field is not set. --- ANNOUNCE | 6 ++++-- CHANGES | 4 +++- example.c | 19 ++++++++++++++++--- pngread.c | 16 ++++++++++++++++ pngwrite.c | 8 ++++++++ 5 files changed, 47 insertions(+), 6 deletions(-) diff --git a/ANNOUNCE b/ANNOUNCE index d40f70f32..d8dce54f1 100644 --- a/ANNOUNCE +++ b/ANNOUNCE @@ -1,5 +1,5 @@ -Libpng 1.6.0beta29 - August 29, 2012 +Libpng 1.6.0beta29 - August 31, 2012 This is not intended to be a public release. It will be replaced within a few weeks by a public version or by another test version. @@ -482,7 +482,9 @@ Version 1.6.0beta28 [August 29, 2012] contain the tags needed to process the PNG (tags all required by the ICC spec). Removed unused PNG_STATIC from pngpriv.h. -Version 1.6.0beta29 [August 29, 2012] +Version 1.6.0beta29 [August 31, 2012] + Fixed the simplified API example programs and improved the error message + if the version field is not set. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/CHANGES b/CHANGES index c7d3d9759..1f7850367 100644 --- a/CHANGES +++ b/CHANGES @@ -4233,7 +4233,9 @@ Version 1.6.0beta28 [August 29, 2012] contain the tags needed to process the PNG (tags all required by the ICC spec). Removed unused PNG_STATIC from pngpriv.h. -Version 1.6.0beta29 [August 29, 2012] +Version 1.6.0beta29 [August 31, 2012] + Fixed the simplified API example programs and improved the error message + if the version field is not set. Send comments/corrections/commendations to png-mng-implement at lists.sf.net (subscription required; visit diff --git a/example.c b/example.c index c1dacf27c..077fdc547 100644 --- a/example.c +++ b/example.c @@ -49,6 +49,7 @@ int main(int argc, const char **argv) /* Initialize the 'png_image' structure. */ memset(&image, 0, (sizeof image)); + image.version = PNG_IMAGE_VERSION; /* The first argument is the file to read: */ if (png_image_begin_read_from_file(&image, argv[1])) @@ -75,16 +76,28 @@ int main(int argc, const char **argv) * be supplied or the output buffer would have to be initialized to the * actual background of the image. * - * The final argument to png_image_finish_read is the 'row_stride' - + * The fourth argument to png_image_finish_read is the 'row_stride' - * this is the number of components allocated for the image in each * row. It has to be at least as big as the value returned by * PNG_IMAGE_ROW_STRIDE, but if you just allocate space for the * default, minimum, size using PNG_IMAGE_SIZE as above you can pass * zero. + * + * The final argument is a pointer to a buffer for the colormap; + * colormaps have exactly the same format as a row of image pixels (so + * you choose what format to make the colormap by setting + * image.format). A colormap is only returned if + * PNG_FORMAT_FLAG_COLORMAP is also set in image.format, so in this + * case NULL is passed as the final argument. If you do want to force + * all images into an index/color-mapped format then you can use: + * + * PNG_IMAGE_COLORMAP_SIZE(image) + * + * to find the maximum size of the colormap in bytes. */ if (buffer != NULL && png_image_finish_read(&image, NULL/*background*/, buffer, - 0/*row_stride*/)) + 0/*row_stride*/, NULL/*colormap*/)) { /* Now write the image out to the second argument. In the write * call 'convert_to_8bit' allows 16-bit data to be squashed down to @@ -92,7 +105,7 @@ int main(int argc, const char **argv) * to the 8-bit format. */ if (png_image_write_to_file(&image, argv[2], 0/*convert_to_8bit*/, - buffer, 0/*row_stride*/)) + buffer, 0/*row_stride*/, NULL/*colormap*/)) { /* The image has been written successfully. */ exit(0); diff --git a/pngread.c b/pngread.c index ce9d61eab..55fcbfcda 100644 --- a/pngread.c +++ b/pngread.c @@ -1357,6 +1357,10 @@ png_image_begin_read_from_stdio(png_imagep image, FILE* file) "png_image_begin_read_from_stdio: invalid argument"); } + else if (image != NULL) + return png_image_error(image, + "png_image_begin_read_from_stdio: incorrect PNG_IMAGE_VERSION"); + return 0; } @@ -1391,6 +1395,10 @@ png_image_begin_read_from_file(png_imagep image, const char *file_name) "png_image_begin_read_from_file: invalid argument"); } + else if (image != NULL) + return png_image_error(image, + "png_image_begin_read_from_file: incorrect PNG_IMAGE_VERSION"); + return 0; } #endif /* PNG_STDIO_SUPPORTED */ @@ -1452,6 +1460,10 @@ int PNGAPI png_image_begin_read_from_memory(png_imagep image, "png_image_begin_read_from_memory: invalid argument"); } + else if (image != NULL) + return png_image_error(image, + "png_image_begin_read_from_memory: incorrect PNG_IMAGE_VERSION"); + return 0; } @@ -3954,6 +3966,10 @@ png_image_finish_read(png_imagep image, png_const_colorp background, "png_image_finish_read: invalid argument"); } + else if (image != NULL) + return png_image_error(image, + "png_image_finish_read: damaged PNG_IMAGE_VERSION"); + return 0; } diff --git a/pngwrite.c b/pngwrite.c index c0b65d120..4e33ee08b 100644 --- a/pngwrite.c +++ b/pngwrite.c @@ -2248,6 +2248,10 @@ png_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit, "png_image_write_to_stdio: invalid argument"); } + else if (image != NULL) + return png_image_error(image, + "png_image_write_to_stdio: incorrect PNG_IMAGE_VERSION"); + else return 0; } @@ -2311,6 +2315,10 @@ png_image_write_to_file(png_imagep image, const char *file_name, "png_image_write_to_file: invalid argument"); } + else if (image != NULL) + return png_image_error(image, + "png_image_write_to_file: incorrect PNG_IMAGE_VERSION"); + else return 0; }