Mercurial > repos > blastem
diff ppm.c @ 1263:5f65a16c23ff
Implement raw screenshot functionality requested in ticket:10
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 04 Mar 2017 11:50:14 -0800 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ppm.c Sat Mar 04 11:50:14 2017 -0800 @@ -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); + } +}