From f6dad1b162d8f0b8240e536592f78bd31c90dd08 Mon Sep 17 00:00:00 2001 From: Xerbo Date: Tue, 19 Oct 2021 15:24:15 +0100 Subject: [PATCH] Make the output of bw presets actually grayscale --- src/imagecompositor.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/imagecompositor.cpp b/src/imagecompositor.cpp index e2144fe..2c7d4b5 100644 --- a/src/imagecompositor.cpp +++ b/src/imagecompositor.cpp @@ -142,14 +142,17 @@ double set_bw(double val) { // Evaluate `expression` and store the results in `image` void ImageCompositor::getExpression(QImage &image, std::string experssion) { - if (image.format() != QImage::Format_RGBX64) { - image = QImage(image.width(), image.height(), QImage::Format_RGBX64); + QImage::Format format = (experssion.substr(0, 3) == "rgb") ? QImage::Format_RGBX64 : QImage::Format_Grayscale16; + if (image.format() != format) { + image = QImage(image.width(), image.height(), format); } + std::vector rawbits(m_channels); for (size_t i = 0; i < m_channels; i++) { rawbits[i] = (quint16 *)rawChannels[i].bits(); } QRgba64 *bits = reinterpret_cast(image.bits()); + quint16 *grayscale_bits = reinterpret_cast(image.bits()); #pragma omp parallel { @@ -186,7 +189,12 @@ void ImageCompositor::getExpression(QImage &image, std::string experssion) { } double val = p.Eval(); - bits[y*m_width + x] = *(QRgba64 *)&val; + QRgba64 color = *(QRgba64 *)&val; + if (format == QImage::Format_Grayscale16) { + grayscale_bits[y*m_width + x] = color.red(); + } else { + bits[y*m_width + x] = color; + } } } }