]> git.cworth.org Git - apitrace/blobdiff - image/image_pnm.cpp
image: Move helpers to respective modules.
[apitrace] / image / image_pnm.cpp
index f9cd05d1fbc7593dafcb6e5bf77d48beb7505a1d..9e9d0e1be9cb3542a63814730a081354000c20cf 100644 (file)
@@ -30,6 +30,8 @@
 #include <stdint.h>
 #include <stdio.h>
 
+#include <fstream>
+
 #include "image.hpp"
 
 
@@ -40,8 +42,8 @@ namespace image {
  * http://netpbm.sourceforge.net/doc/ppm.html
  */
 void
-Image::writePNM(std::ostream &os, const char *comment) const {
-    assert(channels == 1 || channels >= 3);
+Image::writePNM(std::ostream &os, const char *comment) const
+{
 
     os << (channels == 1 ? "P5" : "P6") << "\n";
     if (comment) {
@@ -109,6 +111,19 @@ Image::writePNM(std::ostream &os, const char *comment) const {
     }
 }
 
+
+bool
+Image::writePNM(const char *filename, const char *comment) const
+{
+    std::ofstream os(filename, std::ofstream::binary);
+    if (!os) {
+        return false;
+    }
+    writePNM(os, comment);
+    return true;
+}
+
+
 const char *
 readPNMHeader(const char *buffer, size_t bufferSize, unsigned *channels, unsigned *width, unsigned *height)
 {