diff --git a/src/pam.c b/src/pam.c new file mode 100644 index 0000000..6913d09 --- /dev/null +++ b/src/pam.c @@ -0,0 +1,30 @@ +#include "pam.h" +#include +#include + +void write_p7_image(u64 width, u64 height, u8 *buf, const char *outfile) { + FILE *fp = fopen(outfile, "wb"); + if (!fp) { + fprintf(stderr, "Couldn't open file: %s\n", outfile); + return; + } + + char header[4096] = {0}; + snprintf(header, 4095, + "P7\n" + "WIDTH %lu\n" + "HEIGHT %lu\n" + "DEPTH 4\n" + "MAXVAL 255\n" + "TUPLTYPE RGB_ALPHA\n" + "ENDHDR\n", + width, height); + + u64 hdr_size = strlen(header); + u64 buf_size = width * height * 4; + + fwrite(header, hdr_size, 1, fp); + fwrite(buf, buf_size, 1, fp); + + fclose(fp); +} diff --git a/src/pam.h b/src/pam.h new file mode 100644 index 0000000..05537e4 --- /dev/null +++ b/src/pam.h @@ -0,0 +1,8 @@ +#ifndef PAM_H +#define PAM_H + +#include "aliases.h" + +void write_p7_image(u64 width, u64 height, u8 *buf, const char *outfile); + +#endif // PAM_H