]> git.cworth.org Git - apitrace/blobdiff - gui/apisurface.cpp
gui: show the original pixel values in the surface viewer
[apitrace] / gui / apisurface.cpp
index 3732ed5f717482ad976fbf6f9f0d9e447113b91c..199cd7d3cdb115c884571fb58005150b644ed094 100644 (file)
@@ -33,8 +33,83 @@ struct ByteArrayBuf : public std::streambuf
 
 void ApiSurface::contentsFromBase64(const QByteArray &base64)
 {
-    QByteArray dataArray = QByteArray::fromBase64(base64);
+    m_base64Data = base64;
+
+    /*
+     * We need to do the conversion to create the thumbnail
+     */
+    image::Image *image = imageFromBase64(base64);
+    Q_ASSERT(image);
+    QImage img = qimageFromRawImage(image);
+    m_thumb = thumbnail(img);
+    delete image;
+}
+
+QByteArray ApiSurface::base64Data() const
+{
+    return m_base64Data;
+}
+
+QImage ApiSurface::thumb() const
+{
+    return m_thumb;
+}
+
+int ApiSurface::depth() const
+{
+    return m_depth;
+}
+
+void ApiSurface::setDepth(int depth)
+{
+    m_depth = depth;
+}
+
+QString ApiSurface::formatName() const
+{
+    return m_formatName;
+}
+
+void ApiSurface::setFormatName(const QString &str)
+{
+    m_formatName = str;
+}
+
+
+ApiTexture::ApiTexture()
+    : ApiSurface()
+{
+}
+
+QString ApiTexture::label() const
+{
+    return m_label;
+}
+
+void ApiTexture::setLabel(const QString &str)
+{
+    m_label = str;
+}
 
+ApiFramebuffer::ApiFramebuffer()
+    : ApiSurface()
+{
+}
+
+QString ApiFramebuffer::type() const
+{
+    return m_type;
+}
+
+void ApiFramebuffer::setType(const QString &str)
+{
+    m_type = str;
+}
+
+image::Image *
+ApiSurface::imageFromBase64(const QByteArray &base64)
+{
+    QByteArray dataArray = QByteArray::fromBase64(base64);
     image::Image *image;
 
     /*
@@ -49,23 +124,22 @@ void ApiSurface::contentsFromBase64(const QByteArray &base64)
         image = image::readPNM(dataArray.data(), dataArray.size());
     }
 
-    /*
-     * FIXME: Instead of converting to QImage here, we should be deferring the conversion
-     * to imageviewer.cpp.
-     *
-     * XXX: We still need the thumbnail though.
-     */
+    return image;
+}
 
-    Q_ASSERT(image);
 
+QImage
+ApiSurface::qimageFromRawImage(const image::Image *image)
+{
+    QImage img;
     int width = image->width;
     int height = image->height;
 
-    m_image = QImage(width, height, QImage::Format_ARGB32);
+    img = QImage(width, height, QImage::Format_ARGB32);
 
     const unsigned char *srcRow = image->start();
     for (int y = 0; y < height; ++y) {
-        QRgb *dst = (QRgb *)m_image.scanLine(y);
+        QRgb *dst = (QRgb *)img.scanLine(y);
 
         if (image->channelType == image::TYPE_UNORM8) {
             const unsigned char *src = srcRow;
@@ -109,69 +183,5 @@ void ApiSurface::contentsFromBase64(const QByteArray &base64)
         srcRow += image->stride();
     }
 
-    delete image;
-
-    m_thumb = thumbnail(m_image);
-}
-
-QImage ApiSurface::image() const
-{
-    return m_image;
-}
-
-QImage ApiSurface::thumb() const
-{
-    return m_thumb;
-}
-
-int ApiSurface::depth() const
-{
-    return m_depth;
+    return img;
 }
-
-void ApiSurface::setDepth(int depth)
-{
-    m_depth = depth;
-}
-
-QString ApiSurface::formatName() const
-{
-    return m_formatName;
-}
-
-void ApiSurface::setFormatName(const QString &str)
-{
-    m_formatName = str;
-}
-
-
-ApiTexture::ApiTexture()
-    : ApiSurface()
-{
-}
-
-QString ApiTexture::label() const
-{
-    return m_label;
-}
-
-void ApiTexture::setLabel(const QString &str)
-{
-    m_label = str;
-}
-
-ApiFramebuffer::ApiFramebuffer()
-    : ApiSurface()
-{
-}
-
-QString ApiFramebuffer::type() const
-{
-    return m_type;
-}
-
-void ApiFramebuffer::setType(const QString &str)
-{
-    m_type = str;
-}
-