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