[libpng17] Merge contrib/examples/pngtopng.c with libpng-1.6.29beta02

This commit is contained in:
Glenn Randers-Pehrson 2017-02-24 09:25:27 -06:00
parent 7345c50aaa
commit ba42eccb05

View File

@ -1,10 +1,12 @@
/*- pngtopng /*- pngtopng
* *
* COPYRIGHT: Written by John Cunningham Bowler, 2011. * COPYRIGHT: Written by John Cunningham Bowler, 2011, 2017.
* To the extent possible under law, the author has waived all copyright and * To the extent possible under law, the author has waived all copyright and
* related or neighboring rights to this work. This work is published from: * related or neighboring rights to this work. This work is published from:
* United States. * United States.
* *
* Last changed in libpng 1.6.29 [%RDATE%]
*
* Read a PNG and write it out in a fixed format, using the 'simplified API' * Read a PNG and write it out in a fixed format, using the 'simplified API'
* that was introduced in libpng-1.6.0. * that was introduced in libpng-1.6.0.
* *
@ -59,28 +61,29 @@ int main(int argc, const char **argv)
else else
fprintf(stderr, "pngtopng: write %s: %s\n", argv[2], fprintf(stderr, "pngtopng: write %s: %s\n", argv[2],
image.message); image.message);
}
else
fprintf(stderr, "pngtopng: read %s: %s\n", argv[1],
image.message);
free(buffer); free(buffer);
} }
else else
{ {
fprintf(stderr, "pngtopng: read %s: %s\n", argv[1], fprintf(stderr, "pngtopng: out of memory: %lu bytes\n",
image.message); (unsigned long)PNG_IMAGE_SIZE(image));
/* This is the only place where a 'free' is required; libpng does /* This is the only place where a 'free' is required; libpng does
* the cleanup on error and success, but in this case we couldn't * the cleanup on error and success, but in this case we couldn't
* complete the read because of running out of memory. * complete the read because of running out of memory and so libpng
* has not got to the point where it can do cleanup.
*/ */
png_image_free(&image); png_image_free(&image);
} }
} }
else
fprintf(stderr, "pngtopng: out of memory: %lu bytes\n",
(unsigned long)PNG_IMAGE_SIZE(image));
}
else else
/* Failed to read the first argument: */ /* Failed to read the first argument: */
fprintf(stderr, "pngtopng: %s: %s\n", argv[1], image.message); fprintf(stderr, "pngtopng: %s: %s\n", argv[1], image.message);