diff options
author | Michael Pavone <pavone@retrodev.com> | 2017-03-04 11:50:14 -0800 |
---|---|---|
committer | Michael Pavone <pavone@retrodev.com> | 2017-03-04 11:50:14 -0800 |
commit | 2eb32065b23a5cd90a6ae8908ae8a8ff24a4f209 (patch) | |
tree | f0afa5091944f9b2170428b77b7e65abc203ada2 /ppm.c | |
parent | b933af364fff4b627930ccfb176332240f391d8e (diff) |
Implement raw screenshot functionality requested in ticket:10
Diffstat (limited to 'ppm.c')
-rw-r--r-- | ppm.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -0,0 +1,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); + } +} |