1 #include "apisurface.h"
9 #include "image/image.hpp"
12 ApiSurface::ApiSurface()
16 QSize ApiSurface::size() const
21 void ApiSurface::setSize(const QSize &size)
26 struct ByteArrayBuf : public std::streambuf
28 ByteArrayBuf(QByteArray & a)
30 setg(a.data(), a.data(), a.data() + a.size());
34 void ApiSurface::contentsFromBase64(const QByteArray &base64)
36 QByteArray dataArray = QByteArray::fromBase64(base64);
41 * Detect the PNG vs PFM images.
43 const char pngSignature[] = {(char)0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0};
44 if (dataArray.startsWith(pngSignature)) {
45 ByteArrayBuf buf(dataArray);
46 std::istream istr(&buf);
47 image = image::readPNG(istr);
49 image = image::readPNM(dataArray.data(), dataArray.size());
53 * FIXME: Instead of converting to QImage here, we should be deferring the conversion
56 * XXX: We still need the thumbnail though.
61 int width = image->width;
62 int height = image->height;
64 m_image = QImage(width, height, QImage::Format_ARGB32);
66 const unsigned char *srcRow = image->start();
67 for (int y = 0; y < height; ++y) {
68 QRgb *dst = (QRgb *)m_image.scanLine(y);
70 if (image->channelType == image::TYPE_UNORM8) {
71 const unsigned char *src = srcRow;
72 for (int x = 0; x < width; ++x) {
73 unsigned char rgba[4];
74 for (int c = 0; c < image->channels; ++c) {
77 if (image->channels == 1) {
78 // Use gray-scale instead of red
82 dst[x] = qRgba(rgba[0], rgba[1], rgba[2], rgba[3]);
85 const float *src = (const float *)srcRow;
86 for (int x = 0; x < width; ++x) {
87 unsigned char rgba[4] = {0, 0, 0, 0xff};
88 for (int c = 0; c < image->channels; ++c) {
93 } else if (f <= 0.0f) {
100 if (image->channels == 1) {
101 // Use gray-scale instead of red
105 dst[x] = qRgba(rgba[0], rgba[1], rgba[2], rgba[3]);
109 srcRow += image->stride();
114 m_thumb = thumbnail(m_image);
117 QImage ApiSurface::image() const
122 QImage ApiSurface::thumb() const
127 int ApiSurface::depth() const
132 void ApiSurface::setDepth(int depth)
137 QString ApiSurface::formatName() const
142 void ApiSurface::setFormatName(const QString &str)
148 ApiTexture::ApiTexture()
153 QString ApiTexture::label() const
158 void ApiTexture::setLabel(const QString &str)
163 ApiFramebuffer::ApiFramebuffer()
168 QString ApiFramebuffer::type() const
173 void ApiFramebuffer::setType(const QString &str)