File: ppm.c

package info (click to toggle)
blastem 0.6.3.3-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 5,048 kB
  • sloc: ansic: 75,683; python: 2,899; java: 1,590; asm: 461; makefile: 313; sh: 207; xml: 67
file content (21 lines) | stat: -rw-r--r-- 489 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdint.h>
#include <stdio.h>

void save_ppm(FILE *f, uint32_t *buffer, uint32_t width, uint32_t height, uint32_t pitch)
{
	fprintf(f, "P6\n%d %d\n255\n", width, height);
	for(uint32_t y = 0; y < height; y++)
	{
		uint32_t *line = buffer;
		for (uint32_t x = 0; x < width; x++, line++)
		{
			uint8_t buf[3] = {
				*line >> 16, //red
				*line >> 8,  //green
				*line        //blue
			};
			fwrite(buf, 1, sizeof(buf), f);
		}
		buffer = buffer + pitch / sizeof(uint32_t);
	}
}