From 994535d1b11e13c11b923933ad39021d5040a466 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Thu, 12 Sep 2013 17:26:34 +0100 Subject: [PATCH] ui: Handle float images in dumps. --- gui/apisurface.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/gui/apisurface.cpp b/gui/apisurface.cpp index d6bc72c..3732ed5 100644 --- a/gui/apisurface.cpp +++ b/gui/apisurface.cpp @@ -35,12 +35,19 @@ void ApiSurface::contentsFromBase64(const QByteArray &base64) { QByteArray dataArray = QByteArray::fromBase64(base64); + image::Image *image; + /* - * FIXME: Detect the float PFM images here. + * Detect the PNG vs PFM images. */ - ByteArrayBuf buf(dataArray); - std::istream istr(&buf); - image::Image *image = image::readPNG(istr); + const char pngSignature[] = {(char)0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0}; + if (dataArray.startsWith(pngSignature)) { + ByteArrayBuf buf(dataArray); + std::istream istr(&buf); + image = image::readPNG(istr); + } else { + image = image::readPNM(dataArray.data(), dataArray.size()); + } /* * FIXME: Instead of converting to QImage here, we should be deferring the conversion @@ -81,7 +88,7 @@ void ApiSurface::contentsFromBase64(const QByteArray &base64) for (int c = 0; c < image->channels; ++c) { float f = *src++; unsigned char u; - if (f >= 255.0f) { + if (f >= 1.0f) { u = 255; } else if (f <= 0.0f) { u = 0; -- 2.43.0