commit 88a5991a28874e77a956f93517e053730dd1eb10
parent 232f064831b2e0d8ff7ae49cc4a746948d40aaf3
Author: vaplv <vaplv@free.fr>
Date: Tue, 10 Nov 2015 12:42:09 +0100
Add the image_ppm_write_stream function
Diffstat:
2 files changed, 39 insertions(+), 6 deletions(-)
diff --git a/src/image.c b/src/image.c
@@ -30,19 +30,45 @@ image_ppm_write
const int Bpp,
const unsigned char* buffer)
{
- char buf[BUFSIZ];
FILE* fp = NULL;
res_T res = RES_OK;
- if(width && height && Bpp && !buffer) {
- goto error;
- }
fp = fopen(path, "w");
if(NULL == fp) {
res = RES_IO_ERR;
goto error;
}
+ res = image_ppm_write_stream(fp, width, height, Bpp, buffer);
+ if(res != RES_OK) goto error;
+
+exit:
+ if(fp) fclose(fp);
+ return res;
+error:
+ goto exit;
+}
+
+res_T
+image_ppm_write_stream
+ (FILE* fp,
+ const int width,
+ const int height,
+ const int Bpp,
+ const unsigned char* buffer)
+{
+ char buf[BUFSIZ];
+ res_T res = RES_OK;
+
+ if(width && height && Bpp && !buffer) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+ if(!fp) {
+ res = RES_BAD_ARG;
+ goto error;
+ }
+
#define FWRITE(Fp, String) \
{ \
const size_t i = fwrite(String, sizeof(char), strlen(String), Fp); \
@@ -75,9 +101,8 @@ image_ppm_write
}
#undef SNPRINTF
#undef FWRITE
+
exit:
- if(fp)
- fclose(fp);
return res;
error:
goto exit;
diff --git a/src/image.h b/src/image.h
@@ -28,6 +28,14 @@ image_ppm_write
const int bytes_per_pixel,
const unsigned char* buffer);
+RSYS_API res_T
+image_ppm_write_stream
+ (FILE* stream,
+ const int width,
+ const int height,
+ const int bytes_per_pixel,
+ const unsigned char* buffer);
+
END_DECLS
#endif /* IMAGE_H */