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

Function writePPM

apps/ospTutorial/ospTutorialAsync.c:27–48  ·  view source on GitHub ↗

helper function to write the rendered image as PPM file

Source from the content-addressed store, hash-verified

25
26// helper function to write the rendered image as PPM file
27void writePPM(const char *fileName, const vec2i *size, const uint32_t *pixel)
28{
29 FILE *file = fopen(fileName, "wb");
30 if (!file) {
31 fprintf(stderr, "fopen('%s', 'wb') failed: %d", fileName, errno);
32 return;
33 }
34 fprintf(file, "P6\n%i %i\n255\n", size->x, size->y);
35 unsigned char *out = (unsigned char *)alloca(3 * size->x);
36 for (int y = 0; y < size->y; y++) {
37 const unsigned char *in =
38 (const unsigned char *)&pixel[(size->y - 1 - y) * size->x];
39 for (int x = 0; x < size->x; x++) {
40 out[3 * x + 0] = in[4 * x + 0];
41 out[3 * x + 1] = in[4 * x + 1];
42 out[3 * x + 2] = in[4 * x + 2];
43 }
44 fwrite(out, 3 * size->x, sizeof(char), file);
45 }
46 fprintf(file, "\n");
47 fclose(file);
48}
49
50void buildScene1(OSPCamera *camera,
51 OSPWorld *world,

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected