mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 21:43:03 +02:00
Use alpha channel to indicate holes when importing terrain images.
This commit is contained in:
parent
a9f7533477
commit
2ed6835426
1 changed files with 5 additions and 5 deletions
|
@ -658,17 +658,17 @@ void HeightfieldHeightEditor::select() {
|
||||||
QMessageBox::warning(this, "Invalid Image", "The selected image could not be read.");
|
QMessageBox::warning(this, "Invalid Image", "The selected image could not be read.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
image = image.convertToFormat(QImage::Format_RGB888);
|
image = image.convertToFormat(QImage::Format_ARGB32);
|
||||||
int width = getHeightfieldSize(image.width()) + 2 * HeightfieldHeight::HEIGHT_BORDER;
|
int width = getHeightfieldSize(image.width()) + 2 * HeightfieldHeight::HEIGHT_BORDER;
|
||||||
int height = getHeightfieldSize(image.height()) + 2 * HeightfieldHeight::HEIGHT_BORDER;
|
int height = getHeightfieldSize(image.height()) + 2 * HeightfieldHeight::HEIGHT_BORDER;
|
||||||
QVector<quint16> contents(width * height);
|
QVector<quint16> contents(width * height);
|
||||||
quint16* dest = contents.data() + (width + 1) * HeightfieldHeight::HEIGHT_BORDER;
|
quint16* dest = contents.data() + (width + 1) * HeightfieldHeight::HEIGHT_BORDER;
|
||||||
const float CONVERSION_SCALE = 65534.0f / numeric_limits<quint8>::max();
|
const float CONVERSION_SCALE = 65534.0f / numeric_limits<quint8>::max();
|
||||||
for (int i = 0; i < image.height(); i++, dest += width) {
|
for (int i = 0; i < image.height(); i++, dest += width) {
|
||||||
const uchar* src = image.constScanLine(i);
|
const QRgb* src = (const QRgb*)image.constScanLine(i);
|
||||||
for (quint16* lineDest = dest, *end = dest + image.width(); lineDest != end; lineDest++,
|
for (quint16* lineDest = dest, *end = dest + image.width(); lineDest != end; lineDest++, src++) {
|
||||||
src += DataBlock::COLOR_BYTES) {
|
*lineDest = (qAlpha(*src) < numeric_limits<qint8>::max()) ? 0 :
|
||||||
*lineDest = (quint16)(*src * CONVERSION_SCALE) + CONVERSION_OFFSET;
|
(quint16)(qRed(*src) * CONVERSION_SCALE) + CONVERSION_OFFSET;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emit heightChanged(_height = new HeightfieldHeight(width, contents));
|
emit heightChanged(_height = new HeightfieldHeight(width, contents));
|
||||||
|
|
Loading…
Reference in a new issue