! store PPM file to disk */
| 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 | } |
no test coverage detected