]> git.cworth.org Git - apitrace/commitdiff
image: Move helpers to respective modules.
authorJosé Fonseca <jfonseca@vmware.com>
Wed, 11 Sep 2013 17:14:22 +0000 (18:14 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Wed, 11 Sep 2013 17:14:22 +0000 (18:14 +0100)
image/image.hpp
image/image_bmp.cpp
image/image_png.cpp
image/image_pnm.cpp
image/image_raw.cpp

index 7e13dd6f490cc97e40e24918e98073b405dcc8c6..6b32f27df699f0abb49ec8e2b2130cbec6de19e7 100644 (file)
@@ -31,7 +31,7 @@
 #define _IMAGE_HPP_
 
 
-#include <fstream>
+#include <iostream>
 
 
 namespace image {
@@ -81,43 +81,26 @@ public:
         return flipped ? -(signed)(width*channels) : width*channels;
     }
 
-    bool writeBMP(const char *filename) const;
+    bool
+    writeBMP(const char *filename) const;
 
-    void writePNM(std::ostream &os, const char *comment = NULL) const;
+    void
+    writePNM(std::ostream &os, const char *comment = NULL) 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, comment);
-        return true;
-    }
+    bool
+    writePNM(const char *filename, const char *comment = NULL) const;
 
     bool
     writePNG(std::ostream &os) const;
 
-    inline bool
-    writePNG(const char *filename) const {
-        std::ofstream os(filename, std::ofstream::binary);
-        if (!os) {
-            return false;
-        }
-        return writePNG(os);
-    }
+    bool
+    writePNG(const char *filename) const;
 
     void
     writeRAW(std::ostream &os) const;
 
-    inline bool
-    writeRAW(const char *filename) const {
-       std::ofstream os(filename, std::ofstream::binary);
-       if (!os) {
-           return false;
-       }
-       writeRAW(os);
-       return true;
-    }
+    bool
+    writeRAW(const char *filename) const;
 };
 
 
index e0c64283a5f08299d868f526416ce1d0759019b6..1961f9d93abc90e4d3c5e127777a4c097c308a20 100644 (file)
@@ -28,6 +28,8 @@
 #include <assert.h>
 #include <stdint.h>
 
+#include <fstream>
+
 #include "image.hpp"
 
 
index 0a413e1c6bbf25b8c23017c8f4c303359f2afaf7..357a78e9a38c83a744668524339d54db7f50b123 100644 (file)
@@ -123,6 +123,17 @@ no_png:
 }
 
 
+bool
+Image::writePNG(const char *filename) const
+{
+    std::ofstream os(filename, std::ofstream::binary);
+    if (!os) {
+        return false;
+    }
+    return writePNG(os);
+}
+
+
 Image *
 readPNG(const char *filename)
 {
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)
 {
index dd45d104768a80ec8c722ec8169c133dc0854a70..93946be947659d44d8e5c7146ab5a2c63aad9ddc 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
+{
     const unsigned char *row;
 
     for (row = start(); row != end(); row += stride()) {
@@ -44,4 +48,17 @@ Image::writeRAW(std::ostream &os) const {
     }
 }
 
+
+bool
+Image::writeRAW(const char *filename) const
+{
+    std::ofstream os(filename, std::ofstream::binary);
+    if (!os) {
+        return false;
+    }
+    writeRAW(os);
+    return true;
+}
+
+
 } /* namespace image */