Allow piping image to stdout
This commit is contained in:
@@ -93,12 +93,16 @@ int writePNG(mazegrid_t const* g, char const* filename) {
|
|||||||
png_structp png_ptr = NULL;
|
png_structp png_ptr = NULL;
|
||||||
png_infop info_ptr = NULL;
|
png_infop info_ptr = NULL;
|
||||||
|
|
||||||
|
if (strcmp(filename, "-") == 0) {
|
||||||
|
f = stdout;
|
||||||
|
} else {
|
||||||
f = fopen(filename, "wb");
|
f = fopen(filename, "wb");
|
||||||
if (NULL == f) {
|
if (NULL == f) {
|
||||||
fprintf(stderr, "Could not open %s for writing.\n", filename);
|
fprintf(stderr, "Could not open %s for writing.\n", filename);
|
||||||
code = 0;
|
code = 0;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||||
if (png_ptr == NULL) {
|
if (png_ptr == NULL) {
|
||||||
@@ -134,7 +138,9 @@ int writePNG(mazegrid_t const* g, char const* filename) {
|
|||||||
png_write_end(png_ptr, NULL);
|
png_write_end(png_ptr, NULL);
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
if (strcmp(filename, "-") != 0) {
|
||||||
if (f != NULL) fclose(f);
|
if (f != NULL) fclose(f);
|
||||||
|
}
|
||||||
if (info_ptr != NULL) {
|
if (info_ptr != NULL) {
|
||||||
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
|
png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
|
||||||
png_destroy_info_struct(png_ptr, &info_ptr);
|
png_destroy_info_struct(png_ptr, &info_ptr);
|
||||||
|
|||||||
Reference in New Issue
Block a user