]> git.cworth.org Git - apitrace/blobdiff - common/image.hpp
image: Make PNG writing an Image method.
[apitrace] / common / image.hpp
index dc53ec990ee3a19f931f5e9160269c7e0c875169..7dd18c1225e821a0286ea11e0a73989be57acc51 100644 (file)
@@ -34,7 +34,7 @@
 #include <fstream>
 
 
-namespace Image {
+namespace image {
 
 
 class Image {
@@ -78,7 +78,7 @@ public:
     }
 
     inline signed stride(void) const {
-        return flipped ? -width*channels : width*channels;
+        return flipped ? -(signed)(width*channels) : width*channels;
     }
 
     bool writeBMP(const char *filename) const;
@@ -94,22 +94,30 @@ public:
         return true;
     }
 
-    bool writePNG(const char *filename) 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);
+    }
 
     double compare(Image &ref);
 };
 
-bool writePixelsToBuffer(unsigned char *pixels,
-                         unsigned w, unsigned h, unsigned numChannels,
-                         bool flipped,
-                         char **buffer,
-                         int *size);
 
 Image *
 readPNG(const char *filename);
 
+const char *
+readPNMHeader(const char *buffer, size_t size, unsigned *channels, unsigned *width, unsigned *height);
+
 
-} /* namespace Image */
+} /* namespace image */
 
 
 #endif /* _IMAGE_HPP_ */