X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=gui%2Fapisurface.cpp;h=199cd7d3cdb115c884571fb58005150b644ed094;hb=a69f0de6b922160bec029cfd18b5002b904afccf;hp=3732ed5f717482ad976fbf6f9f0d9e447113b91c;hpb=994535d1b11e13c11b923933ad39021d5040a466;p=apitrace diff --git a/gui/apisurface.cpp b/gui/apisurface.cpp index 3732ed5..199cd7d 100644 --- a/gui/apisurface.cpp +++ b/gui/apisurface.cpp @@ -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; -} -