aboutsummaryrefslogtreecommitdiff
path: root/src/ppm.c
diff options
context:
space:
mode:
authorjvech <jmvalenciae@unal.edu.co>2023-06-21 20:23:29 -0500
committerjvech <jmvalenciae@unal.edu.co>2023-06-21 20:23:29 -0500
commit290aa13ddd8d05bde86f14a82cd76c18b4b8f082 (patch)
treebd28aabf58f962721753f5b6e50309d390087148 /src/ppm.c
parentd579b5e8bf669918908c894304efd66ee79f179e (diff)
add: CLI support added
Diffstat (limited to 'src/ppm.c')
-rw-r--r--src/ppm.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/ppm.c b/src/ppm.c
index a5cf3fe..a868b76 100644
--- a/src/ppm.c
+++ b/src/ppm.c
@@ -9,7 +9,8 @@ ppm_write(const char *file, Image *img)
/*
* Write a ppm file
*/
- FILE *fp = fopen(file, "w");
+ FILE *fp;
+ fp = (file) ? fopen(file, "r") : stdout;
if (fp == NULL) {
perror("ppm_read() Error");
@@ -20,7 +21,7 @@ ppm_write(const char *file, Image *img)
fprintf(fp, "P6\n%d %d\n%d\n", img->width, img->height, img->pixel_bits);
fwrite(img->data, n_pixels, sizeof(uint8_t), fp);
- fclose(fp);
+ if (fp != stdout) fclose(fp);
}
void
@@ -29,7 +30,8 @@ ppm_read(const char *file, Image *img)
* Read a ppm file
*/
{
- FILE *fp = fopen(file, "r");
+ FILE *fp;
+ fp = (file) ? fopen(file, "r") : stdin;
if (fp == NULL) {
perror("ppm_read() Error");
@@ -50,7 +52,7 @@ ppm_read(const char *file, Image *img)
fclose(fp);
exit(1);
}
- fclose(fp);
+ if (fp != stdin) fclose(fp);
}
void
Feel free to download, copy and edit any repo