]> git.cworth.org Git - apitrace/blobdiff - image/image_raw.cpp
image: Add floating point support.
[apitrace] / image / image_raw.cpp
index dd45d104768a80ec8c722ec8169c133dc0854a70..9e8fbfd36f8c32da11b083a527476ae2e8154606 100644 (file)
 #include <stdint.h>
 #include <stdio.h>
 
+#include <fstream>
+
 #include "image.hpp"
 
 
 namespace image {
 
+
 void
-Image::writeRAW(std::ostream &os) const {
+Image::writeRAW(std::ostream &os) const
+{
+    assert(channelType == TYPE_UNORM8);
+
     const unsigned char *row;
 
     for (row = start(); row != end(); row += stride()) {
-        os.write((const char *)row, width*channels);
+        os.write((const char *)row, width*channels*bytesPerPixel);
+    }
+}
+
+
+bool
+Image::writeRAW(const char *filename) const
+{
+    std::ofstream os(filename, std::ofstream::binary);
+    if (!os) {
+        return false;
     }
+    writeRAW(os);
+    return true;
 }
 
+
 } /* namespace image */