2020-11-10 16:31:32 +01:00
|
|
|
#include "ppm.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "image.h"
|
|
|
|
|
|
|
|
void print_ppm(const struct image *image, FILE *f) {
|
|
|
|
// Header
|
|
|
|
fputs("P3\n", f);
|
|
|
|
fprintf(f, "%zu %zu\n", image->w, image->h);
|
|
|
|
fputs("255\n", f);
|
|
|
|
|
|
|
|
// One row per line
|
|
|
|
for (size_t i = 0; i < image->h; ++i) {
|
|
|
|
for (size_t j = 0; j < image->w; ++j) {
|
|
|
|
if (j != 0)
|
|
|
|
fputc(' ', f);
|
2020-11-10 17:39:00 +01:00
|
|
|
const struct pixel *p = &image->buf[to_index(i, j, image)];
|
2020-11-10 16:31:32 +01:00
|
|
|
fprintf(f, "%hhu %hhu %hhu", p->r, p->g, p->b);
|
|
|
|
}
|
|
|
|
fputc('\n', f);
|
|
|
|
}
|
|
|
|
}
|