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);
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;
}
/**
* 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";