Add Image struct
This commit is contained in:
parent
546229e412
commit
2708825924
10
ppm.c
10
ppm.c
@ -3,21 +3,21 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
void write_p6_ppm(const char *filepath, u64 width, u64 height, Pixel *data) {
|
void write_p6_ppm(const char *filepath, Image *img) {
|
||||||
FILE *fp = fopen(filepath, "wb");
|
FILE *fp = fopen(filepath, "wb");
|
||||||
if (!fp) {
|
if (!fp) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char header[1024] = {0};
|
char header[1024] = {0};
|
||||||
sprintf(header, "P6\n%llu %llu\n255\n", (unsigned long long)width,
|
sprintf(header, "P6\n%llu %llu\n255\n", (unsigned long long)img->width,
|
||||||
(unsigned long long)height);
|
(unsigned long long)img->height);
|
||||||
|
|
||||||
u64 length = strlen(header);
|
u64 length = strlen(header);
|
||||||
fwrite(&header, length, 1, fp);
|
fwrite(&header, length, 1, fp);
|
||||||
|
|
||||||
u64 pixel_count = width * height;
|
u64 pixel_count = img->width * img->height;
|
||||||
fwrite(data, sizeof(Pixel), pixel_count, fp);
|
fwrite(img->data, sizeof(Pixel), pixel_count, fp);
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user