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);
39 * FIXME: Detect the float PFM images here.
41 ByteArrayBuf buf(dataArray);
42 std::istream istr(&buf);
43 image::Image *image = image::readPNG(istr);
46 * FIXME: Instead of converting to QImage here, we should be deferring the conversion
49 * XXX: We still need the thumbnail though.
54 int width = image->width;
55 int height = image->height;
57 m_image = QImage(width, height, QImage::Format_ARGB32);
59 const unsigned char *srcRow = image->start();
60 for (int y = 0; y < height; ++y) {
61 QRgb *dst = (QRgb *)m_image.scanLine(y);
63 if (image->channelType == image::TYPE_UNORM8) {
64 const unsigned char *src = srcRow;
65 for (int x = 0; x < width; ++x) {
66 unsigned char rgba[4];
67 for (int c = 0; c < image->channels; ++c) {
70 if (image->channels == 1) {
71 // Use gray-scale instead of red
75 dst[x] = qRgba(rgba[0], rgba[1], rgba[2], rgba[3]);
78 const float *src = (const float *)srcRow;
79 for (int x = 0; x < width; ++x) {
80 unsigned char rgba[4] = {0, 0, 0, 0xff};
81 for (int c = 0; c < image->channels; ++c) {
86 } else if (f <= 0.0f) {
93 if (image->channels == 1) {
94 // Use gray-scale instead of red
98 dst[x] = qRgba(rgba[0], rgba[1], rgba[2], rgba[3]);
102 srcRow += image->stride();
107 m_thumb = thumbnail(m_image);
110 QImage ApiSurface::image() const
115 QImage ApiSurface::thumb() const
120 int ApiSurface::depth() const
125 void ApiSurface::setDepth(int depth)
130 QString ApiSurface::formatName() const
135 void ApiSurface::setFormatName(const QString &str)
141 ApiTexture::ApiTexture()
146 QString ApiTexture::label() const
151 void ApiTexture::setLabel(const QString &str)
156 ApiFramebuffer::ApiFramebuffer()
161 QString ApiFramebuffer::type() const
166 void ApiFramebuffer::setType(const QString &str)