X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=retrace%2Fjson.cpp;h=850e37f934b539de9a53e67a7af9946a09629068;hb=d67cc37dee7e0d60af2cd172fa135962a6dc3ce5;hp=e500aa67b9a2fc086c264a332ea20faec17c8904;hpb=17a4541d67c73d413c9e8f8751cd9c2573933aef;p=apitrace diff --git a/retrace/json.cpp b/retrace/json.cpp index e500aa6..850e37f 100644 --- a/retrace/json.cpp +++ b/retrace/json.cpp @@ -31,6 +31,9 @@ #include #include +#include + +#include "image.hpp" #include "json.hpp" @@ -297,3 +300,38 @@ JSONWriter::writeBool(bool b) { value = true; space = ' '; } + +void +JSONWriter::writeImage(image::Image *image, const char *format, unsigned depth) +{ + if (!image) { + writeNull(); + return; + } + + 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; + + if (image->channelType == image::TYPE_UNORM8) { + image->writePNG(ss); + } else { + image->writePNM(ss); + } + + const std::string & s = ss.str(); + writeBase64(s.data(), s.size()); + endMember(); // __data__ + + endObject(); +}