prng-tests/ppm.c
2024-03-22 11:52:40 +00:00

24 lines
526 B
C

#include "ppm.h"
#include "aliases.h"
#include <stdio.h>
#include <string.h>
void write_p6_ppm(const char *filepath, Image *img) {
FILE *fp = fopen(filepath, "wb");
if (!fp) {
return;
}
char header[1024] = {0};
sprintf(header, "P6\n%llu %llu\n255\n", (unsigned long long)img->width,
(unsigned long long)img->height);
u64 length = strlen(header);
fwrite(&header, length, 1, fp);
u64 pixel_count = img->width * img->height;
fwrite(img->data, sizeof(Pixel), pixel_count, fp);
fclose(fp);
}