fractal/pnmout.c

37 lines
951 B
C
Raw Normal View History

2020-03-07 23:32:57 +01:00
/*
* fractal
* Written in 2020 by Lucas
* CC0 1.0 Universal/Public domain - No rights reserved
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty. You should have received a copy of the CC0 Public Domain
* Dedication along with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include "palette.h"
#include "pnmout.h"
2020-03-08 22:24:10 +01:00
#include "util.h"
2020-03-07 23:32:57 +01:00
void
pnmout_header(FILE *fp, unsigned int width, unsigned int height)
{
2020-03-08 22:24:10 +01:00
if (fprintf(fp, "P6\n%u %u 255\n", width, height) < 0)
err(1, "fprintf");
2020-03-07 23:32:57 +01:00
}
void
pnmout_pixel(FILE *fp, struct color c)
{
uint8_t v[3];
v[0] = c.r / 256;
v[1] = c.g / 256;
v[2] = c.b / 256;
2020-03-08 22:24:10 +01:00
if (fwrite(v, sizeof(v[0]), sizeof(v) / sizeof(v[0]), fp) != 3)
err(1, "fwrite");
2020-03-07 23:32:57 +01:00
}