Add util to write p7 image
This commit is contained in:
parent
837cb6e288
commit
64ec6bfa59
30
src/pam.c
Normal file
30
src/pam.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include "pam.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user