From 6ee49770e066ed045984e31c527c0e8f615f802e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Mon, 5 Sep 2011 23:18:41 +0100 Subject: [PATCH] Embedded the call no in PNM images as a comment. --- glretrace_main.cpp | 4 +++- image.hpp | 6 +++--- image_pnm.cpp | 6 +++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/glretrace_main.cpp b/glretrace_main.cpp index 56ee763..3a90092 100644 --- a/glretrace_main.cpp +++ b/glretrace_main.cpp @@ -131,7 +131,9 @@ void snapshot(unsigned call_no) { if (snapshot_prefix) { if (snapshot_prefix[0] == '-' && snapshot_prefix[1] == 0) { - src->writePNM(std::cout); + char comment[21]; + snprintf(comment, sizeof comment, "%u", call_no); + src->writePNM(std::cout, comment); } else { char filename[PATH_MAX]; snprintf(filename, sizeof filename, "%s%010u.png", snapshot_prefix, call_no); diff --git a/image.hpp b/image.hpp index 44fc4f4..dc53ec9 100644 --- a/image.hpp +++ b/image.hpp @@ -83,14 +83,14 @@ public: bool writeBMP(const char *filename) const; - void writePNM(std::ostream &os) const; + void writePNM(std::ostream &os, const char *comment = NULL) const; - inline bool writePNM(const char *filename) const { + inline bool writePNM(const char *filename, const char *comment = NULL) const { std::ofstream os(filename, std::ofstream::binary); if (!os) { return false; } - writePNM(os); + writePNM(os, comment); return true; } diff --git a/image_pnm.cpp b/image_pnm.cpp index 6625f3d..44ae624 100644 --- a/image_pnm.cpp +++ b/image_pnm.cpp @@ -35,12 +35,16 @@ namespace Image { /** * http://en.wikipedia.org/wiki/Netpbm_format + * http://netpbm.sourceforge.net/doc/ppm.html */ void -Image::writePNM(std::ostream &os) const { +Image::writePNM(std::ostream &os, const char *comment) const { assert(channels == 1 || channels >= 3); os << (channels == 1 ? "P5" : "P6") << "\n"; + if (comment) { + os << "#" << comment << "\n"; + } os << width << " " << height << "\n"; os << "255" << "\n"; -- 2.43.0