main ppm.c
 1#include <stdint.h>
 2#include <stdio.h>
 3
 4void save_ppm(FILE *f, uint32_t *buffer, uint32_t width, uint32_t height, uint32_t pitch)
 5{
 6	fprintf(f, "P6\n%d %d\n255\n", width, height);
 7	for(uint32_t y = 0; y < height; y++)
 8	{
 9		uint32_t *line = buffer;
10		for (uint32_t x = 0; x < width; x++, line++)
11		{
12			uint8_t buf[3] = {
13				*line >> 16, //red
14				*line >> 8,  //green
15				*line        //blue
16			};
17			fwrite(buf, 1, sizeof(buf), f);
18		}
19		buffer = buffer + pitch / sizeof(uint32_t);
20	}
21}