Writes image to a PPM file.
| 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) { |
| 529 | PROFILE("writePPM"); |
| 530 | |
| 531 | std::ofstream file(filename, ios::binary); |
| 532 | if (!file.is_open()) { |
| 533 | return false; |
| 534 | } |
| 535 | |
| 536 | file << "P6\n"; |
| 537 | file << width << "\n"; |
| 538 | file << height << "\n"; |
| 539 | file << 255 << "\n"; |
| 540 | |
| 541 | if (3 == numChannels) { |
| 542 | for (uint32_t y = 0; y < height; y++) { |
| 543 | file.write(pixels, 3 * width); |
| 544 | pixels += rowPitch; |
| 545 | } |
| 546 | } else if (4 == numChannels) { |
| 547 | std::vector<unsigned char> tempRowBuffer; |
| 548 | tempRowBuffer.resize(3 * width + 1); |
| 549 | for (uint32_t y = 0; y < height; y++) { |
| 550 | const uint32_t *srcRow = reinterpret_cast<const uint32_t *>(pixels); |
| 551 | unsigned char *destRow = tempRowBuffer.data(); |
| 552 | |
| 553 | for (uint32_t x = 0; x < width; x++) { |
| 554 | *reinterpret_cast<uint32_t *>(destRow) = *srcRow++; |
| 555 | destRow += 3; |
| 556 | } |
| 557 | file.write(reinterpret_cast<const char *>(tempRowBuffer.data()), 3 * width); |
| 558 | pixels += rowPitch; |
| 559 | } |
| 560 | } |
| 561 | file.close(); |
| 562 | return true; |
| 563 | } |
| 564 | |
| 565 | static VkFormat determineOutputFormat(VkFormat format, ColorSpaceFormat userColorSpaceFormat, uint32_t numChannels) { |
| 566 | // Initial dest format is undefined as we will look for one |
no test coverage detected