annotate ppm.c @ 1868:bfacedbae5f0

Fix libretro and stateview targets
author Michael Pavone <pavone@retrodev.com>
date Mon, 24 Jun 2019 09:11:38 -0700
parents 5f65a16c23ff
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1263
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include <stdint.h>
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include <stdio.h>
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 void save_ppm(FILE *f, uint32_t *buffer, uint32_t width, uint32_t height, uint32_t pitch)
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 {
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6 fprintf(f, "P6\n%d %d\n255\n", width, height);
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 for(uint32_t y = 0; y < height; y++)
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8 {
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 uint32_t *line = buffer;
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10 for (uint32_t x = 0; x < width; x++, line++)
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11 {
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 uint8_t buf[3] = {
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 *line >> 16, //red
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 *line >> 8, //green
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 *line //blue
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 };
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
17 fwrite(buf, 1, sizeof(buf), f);
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18 }
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
19 buffer = buffer + pitch / sizeof(uint32_t);
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
20 }
5f65a16c23ff Implement raw screenshot functionality requested in ticket:10
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
21 }