From 2ed6835426cdd2037af2b861e2f10f0b250f0614 Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Sun, 18 Jan 2015 16:30:46 -0800 Subject: [PATCH] Use alpha channel to indicate holes when importing terrain images. --- libraries/metavoxels/src/Spanner.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/metavoxels/src/Spanner.cpp b/libraries/metavoxels/src/Spanner.cpp index 946c9a9da5..67d6fef123 100644 --- a/libraries/metavoxels/src/Spanner.cpp +++ b/libraries/metavoxels/src/Spanner.cpp @@ -658,17 +658,17 @@ void HeightfieldHeightEditor::select() { QMessageBox::warning(this, "Invalid Image", "The selected image could not be read."); return; } - image = image.convertToFormat(QImage::Format_RGB888); + image = image.convertToFormat(QImage::Format_ARGB32); int width = getHeightfieldSize(image.width()) + 2 * HeightfieldHeight::HEIGHT_BORDER; int height = getHeightfieldSize(image.height()) + 2 * HeightfieldHeight::HEIGHT_BORDER; QVector contents(width * height); quint16* dest = contents.data() + (width + 1) * HeightfieldHeight::HEIGHT_BORDER; const float CONVERSION_SCALE = 65534.0f / numeric_limits::max(); for (int i = 0; i < image.height(); i++, dest += width) { - const uchar* src = image.constScanLine(i); - for (quint16* lineDest = dest, *end = dest + image.width(); lineDest != end; lineDest++, - src += DataBlock::COLOR_BYTES) { - *lineDest = (quint16)(*src * CONVERSION_SCALE) + CONVERSION_OFFSET; + const QRgb* src = (const QRgb*)image.constScanLine(i); + for (quint16* lineDest = dest, *end = dest + image.width(); lineDest != end; lineDest++, src++) { + *lineDest = (qAlpha(*src) < numeric_limits::max()) ? 0 : + (quint16)(qRed(*src) * CONVERSION_SCALE) + CONVERSION_OFFSET; } } emit heightChanged(_height = new HeightfieldHeight(width, contents));