]> git.cworth.org Git - apitrace/commitdiff
retrace: Factor out image json dumping into json.cpp.
authorJosé Fonseca <jfonseca@vmware.com>
Wed, 28 Nov 2012 09:58:09 +0000 (09:58 +0000)
committerJosé Fonseca <jfonseca@vmware.com>
Wed, 28 Nov 2012 09:58:09 +0000 (09:58 +0000)
retrace/glstate_images.cpp
retrace/json.cpp
retrace/json.hpp

index f46028588bb23f62ae27d83d847cca7436e38a35..7b0a42473fdf97cbc8c04ad4910247d078d4b2cf 100644 (file)
@@ -29,7 +29,6 @@
 
 #include <algorithm>
 #include <iostream>
-#include <sstream>
 
 #include "image.hpp"
 #include "json.hpp"
@@ -388,7 +387,6 @@ dumpActiveTextureLevel(JSONWriter &json, Context &context, GLenum target, GLint
     }
 
     char label[512];
-
     GLint active_texture = GL_TEXTURE0;
     glGetIntegerv(GL_ACTIVE_TEXTURE, &active_texture);
     snprintf(label, sizeof label, "%s, %s, level = %d",
@@ -396,8 +394,6 @@ dumpActiveTextureLevel(JSONWriter &json, Context &context, GLenum target, GLint
 
     json.beginMember(label);
 
-    json.beginObject();
-
     GLuint channels;
     GLenum format;
     if (!context.ES && isDepthFormat(desc.internalFormat)) {
@@ -408,15 +404,6 @@ dumpActiveTextureLevel(JSONWriter &json, Context &context, GLenum target, GLint
        channels = 4;
     }
 
-    // Tell the GUI this is no ordinary object, but an image
-    json.writeStringMember("__class__", "image");
-
-    json.writeIntMember("__width__", desc.width);
-    json.writeIntMember("__height__", desc.height);
-    json.writeIntMember("__depth__", desc.depth);
-
-    json.writeStringMember("__format__", formatToString(desc.internalFormat));
-
     image::Image *image = new image::Image(desc.width, desc.height*desc.depth, channels, true);
 
     context.resetPixelPackState();
@@ -429,15 +416,11 @@ dumpActiveTextureLevel(JSONWriter &json, Context &context, GLenum target, GLint
 
     context.restorePixelPackState();
 
-    json.beginMember("__data__");
-    std::stringstream ss;
-    image->writePNG(ss);
-    const std::string & s = ss.str();
-    json.writeBase64(s.data(), s.size());
-    json.endMember(); // __data__
+    json.writeImage(image, formatToString(desc.internalFormat), desc.depth);
 
     delete image;
-    json.endObject();
+
+    json.endMember(); // label
 }
 
 
@@ -849,17 +832,6 @@ dumpReadBufferImage(JSONWriter &json, GLint width, GLint height, GLenum format,
 
     Context context;
 
-    json.beginObject();
-
-    // Tell the GUI this is no ordinary object, but an image
-    json.writeStringMember("__class__", "image");
-
-    json.writeIntMember("__width__", width);
-    json.writeIntMember("__height__", height);
-    json.writeIntMember("__depth__", 1);
-
-    json.writeStringMember("__format__", formatToString(internalFormat));
-
     GLenum type = GL_UNSIGNED_BYTE;
 
 #if DEPTH_AS_RGBA
@@ -878,15 +850,9 @@ dumpReadBufferImage(JSONWriter &json, GLint width, GLint height, GLenum format,
 
     context.restorePixelPackState();
 
-    json.beginMember("__data__");
-    std::stringstream ss;
-    image->writePNG(ss);
-    const std::string & s = ss.str();
-    json.writeBase64(s.data(), s.size());
-    json.endMember(); // __data__
+    json.writeImage(image, formatToString(internalFormat));
 
     delete image;
-    json.endObject();
 }
 
 
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();
+}
index 94338008a3f1ac853389187ff3934997f1fc768f..2c555dbb1e906bd361b73732a50e9dae6c23796a 100644 (file)
 #include <string>
 
 
+namespace image {
+    class Image;
+}
+
+
 class JSONWriter
 {
 private:
@@ -177,6 +182,9 @@ public:
         writeInt(n);
         endMember();
     }
+
+    void
+    writeImage(image::Image *image, const char *format, unsigned depth = 1);
 };
 
 #endif /* _JSON_HPP_ */