Writes image to a PAM file.
| 498 | |
| 499 | // Writes image to a PAM file. |
| 500 | bool writePAM(const char *filename, const char *pixels, uint32_t width, uint32_t height, uint32_t numChannels, uint32_t rowPitch) { |
| 501 | PROFILE("writePAM"); |
| 502 | std::ofstream file(filename, ios::binary); |
| 503 | if (!file.is_open()) { |
| 504 | return false; |
| 505 | } |
| 506 | |
| 507 | file << "P7\n"; |
| 508 | file << "WIDTH " << width << "\n"; |
| 509 | file << "HEIGHT " << height << "\n"; |
| 510 | file << "DEPTH " << numChannels << "\n"; |
| 511 | file << "MAXVAL " << 255 << "\n"; |
| 512 | file << "TUPLTYPE " << (numChannels == 3 ? "RGB" : "RGB_ALPHA") << "\n"; |
| 513 | file << "ENDHDR\n"; |
| 514 | |
| 515 | if (numChannels * width == rowPitch) { |
| 516 | file.write(pixels, height * rowPitch); |
| 517 | } else { |
| 518 | for (uint32_t y = 0; y < height; y++) { |
| 519 | file.write(pixels, numChannels * width); |
| 520 | pixels += rowPitch; |
| 521 | } |
| 522 | } |
| 523 | file.close(); |
| 524 | return true; |
| 525 | } |
| 526 | |
| 527 | // Writes image to a PPM file. |
| 528 | bool writePPM(const char *filename, const char *pixels, uint32_t width, uint32_t height, uint32_t numChannels, uint32_t rowPitch) { |
no test coverage detected