MCPcopy Create free account
hub / github.com/RenderKit/embree / storePPM

Function storePPM

tutorials/common/image/ppm.cpp:95–116  ·  view source on GitHub ↗

! store PPM file to disk */

Source from the content-addressed store, hash-verified

93
94 /*! store PPM file to disk */
95 void storePPM(const Ref<Image>& img, const FileName& fileName)
96 {
97 /* open file for writing */
98 std::fstream file;
99 file.exceptions (std::fstream::failbit | std::fstream::badbit);
100 file.open (fileName.c_str(), std::fstream::out | std::fstream::binary);
101
102 /* write file header */
103 file << "P6" << std::endl;
104 file << img->width << " " << img->height << std::endl;
105 file << 255 << std::endl;
106
107 /* write image */
108 for (size_t y=0; y<img->height; y++) {
109 for (size_t x=0; x<img->width; x++) {
110 const Color4 c = img->get(x,y);
111 file << (unsigned char)(clamp(c.r)*255.0f);
112 file << (unsigned char)(clamp(c.g)*255.0f);
113 file << (unsigned char)(clamp(c.b)*255.0f);
114 }
115 }
116 }
117}

Callers 1

storeImageFunction · 0.85

Calls 4

clampFunction · 0.50
openMethod · 0.45
c_strMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected