]> git.cworth.org Git - apitrace/blobdiff - retrace/json.cpp
retrace: Factor out image json dumping into json.cpp.
[apitrace] / retrace / json.cpp
index e500aa67b9a2fc086c264a332ea20faec17c8904..bb901c2e5fbcec1c7833f9e3ae855868a88a49db 100644 (file)
@@ -31,6 +31,9 @@
 #include <assert.h>
 #include <string.h>
 
+#include <sstream>
+
+#include "image.hpp"
 #include "json.hpp"
 
 
@@ -297,3 +300,27 @@ JSONWriter::writeBool(bool b) {
     value = true;
     space = ' ';
 }
+
+void
+JSONWriter::writeImage(image::Image *image, const char *format, unsigned depth)
+{
+    beginObject();
+
+    // Tell the GUI this is no ordinary object, but an image
+    writeStringMember("__class__", "image");
+
+    writeIntMember("__width__", image->width);
+    writeIntMember("__height__", image->height / depth);
+    writeIntMember("__depth__", depth);
+
+    writeStringMember("__format__", format);
+
+    beginMember("__data__");
+    std::stringstream ss;
+    image->writePNG(ss);
+    const std::string & s = ss.str();
+    writeBase64(s.data(), s.size());
+    endMember(); // __data__
+
+    endObject();
+}