MCPcopy Create free account
hub / github.com/LunarG/VulkanTools / writePAM

Function writePAM

layersvt/screenshot.cpp:500–525  ·  view source on GitHub ↗

Writes image to a PAM file.

Source from the content-addressed store, hash-verified

498
499// Writes image to a PAM file.
500bool 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.
528bool writePPM(const char *filename, const char *pixels, uint32_t width, uint32_t height, uint32_t numChannels, uint32_t rowPitch) {

Callers 1

writeScreenshotFunction · 0.85

Calls 1

writeMethod · 0.80

Tested by

no test coverage detected