]> git.cworth.org Git - apitrace/commitdiff
Embedded the call no in PNM images as a comment.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Mon, 5 Sep 2011 22:18:41 +0000 (23:18 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Mon, 5 Sep 2011 22:18:41 +0000 (23:18 +0100)
glretrace_main.cpp
image.hpp
image_pnm.cpp

index 56ee763210b4e3848f4b359549cb9e72c8f42580..3a900927a128a3d6d46ec0055002d03f964f7fe6 100644 (file)
@@ -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);
index 44fc4f4352252b148699097c08cef57afa16d523..dc53ec990ee3a19f931f5e9160269c7e0c875169 100644 (file)
--- 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;
     }
 
index 6625f3ddc6b9846c1876bab53fd8f0afb8000fdb..44ae624cfa425032364b6c81d6a0bcd856f2b684 100644 (file)
@@ -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";