MCPcopy Create free account
hub / github.com/RenderKit/ospray / writePPM

Function writePPM

modules/mpi/tutorials/ospMPIDistribTutorialAsync.c:35–57  ·  view source on GitHub ↗

helper function to write the rendered image as PPM file

Source from the content-addressed store, hash-verified

33
34// helper function to write the rendered image as PPM file
35void writePPM(
36 const char *fileName, int size_x, int size_y, const uint32_t *pixel)
37{
38 FILE *file = fopen(fileName, "wb");
39 if (!file) {
40 fprintf(stderr, "fopen('%s', 'wb') failed: %d", fileName, errno);
41 return;
42 }
43 fprintf(file, "P6\n%i %i\n255\n", size_x, size_y);
44 unsigned char *out = (unsigned char *)alloca(3 * size_x);
45 for (int y = 0; y < size_y; y++) {
46 const unsigned char *in =
47 (const unsigned char *)&pixel[(size_y - 1 - y) * size_x];
48 for (int x = 0; x < size_x; x++) {
49 out[3 * x + 0] = in[4 * x + 0];
50 out[3 * x + 1] = in[4 * x + 1];
51 out[3 * x + 2] = in[4 * x + 2];
52 }
53 fwrite(out, 3 * size_x, sizeof(char), file);
54 }
55 fprintf(file, "\n");
56 fclose(file);
57}
58
59int main(int argc, char **argv)
60{

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected