summaryrefslogtreecommitdiff
path: root/ppm.c
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2017-03-04 11:50:14 -0800
committerMichael Pavone <pavone@retrodev.com>2017-03-04 11:50:14 -0800
commit2eb32065b23a5cd90a6ae8908ae8a8ff24a4f209 (patch)
treef0afa5091944f9b2170428b77b7e65abc203ada2 /ppm.c
parentb933af364fff4b627930ccfb176332240f391d8e (diff)
Implement raw screenshot functionality requested in ticket:10
Diffstat (limited to 'ppm.c')
-rw-r--r--ppm.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/ppm.c b/ppm.c
new file mode 100644
index 0000000..5e46793
--- /dev/null
+++ b/ppm.c
@@ -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);
+ }
+}