[libpng16] Fixed the simplified API example programs and improved the error

message if the version field is not set.
This commit is contained in:
John Bowler 2012-08-31 17:32:36 -05:00 committed by Glenn Randers-Pehrson
parent fd043e5d0d
commit ed3ca0e3eb
5 changed files with 47 additions and 6 deletions

View File

@ -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 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. 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 contain the tags needed to process the PNG (tags all required by the ICC
spec). Removed unused PNG_STATIC from pngpriv.h. 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 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit (subscription required; visit

View File

@ -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 contain the tags needed to process the PNG (tags all required by the ICC
spec). Removed unused PNG_STATIC from pngpriv.h. 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 Send comments/corrections/commendations to png-mng-implement at lists.sf.net
(subscription required; visit (subscription required; visit

View File

@ -49,6 +49,7 @@ int main(int argc, const char **argv)
/* Initialize the 'png_image' structure. */ /* Initialize the 'png_image' structure. */
memset(&image, 0, (sizeof image)); memset(&image, 0, (sizeof image));
image.version = PNG_IMAGE_VERSION;
/* The first argument is the file to read: */ /* The first argument is the file to read: */
if (png_image_begin_read_from_file(&image, argv[1])) 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 * be supplied or the output buffer would have to be initialized to the
* actual background of the image. * 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 * 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 * 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 * PNG_IMAGE_ROW_STRIDE, but if you just allocate space for the
* default, minimum, size using PNG_IMAGE_SIZE as above you can pass * default, minimum, size using PNG_IMAGE_SIZE as above you can pass
* zero. * 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 && if (buffer != NULL &&
png_image_finish_read(&image, NULL/*background*/, buffer, 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 /* 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 * 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. * to the 8-bit format.
*/ */
if (png_image_write_to_file(&image, argv[2], 0/*convert_to_8bit*/, 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. */ /* The image has been written successfully. */
exit(0); exit(0);

View File

@ -1357,6 +1357,10 @@ png_image_begin_read_from_stdio(png_imagep image, FILE* file)
"png_image_begin_read_from_stdio: invalid argument"); "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; 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"); "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; return 0;
} }
#endif /* PNG_STDIO_SUPPORTED */ #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"); "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; return 0;
} }
@ -3954,6 +3966,10 @@ png_image_finish_read(png_imagep image, png_const_colorp background,
"png_image_finish_read: invalid argument"); "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; return 0;
} }

View File

@ -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"); "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 else
return 0; 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"); "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 else
return 0; return 0;
} }