mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 15:49:24 +02:00
Allow loading "MDR" files saved by Wilbur, fix for reallocating error.
This commit is contained in:
parent
466d99bcbb
commit
dff22b01b6
1 changed files with 12 additions and 7 deletions
|
@ -608,22 +608,27 @@ static int getHeightfieldSize(int size) {
|
||||||
void HeightfieldHeightEditor::select() {
|
void HeightfieldHeightEditor::select() {
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
QString result = QFileDialog::getOpenFileName(this, "Select Height Image", settings.value("heightDir").toString(),
|
QString result = QFileDialog::getOpenFileName(this, "Select Height Image", settings.value("heightDir").toString(),
|
||||||
"Images (*.png *.jpg *.bmp *.raw)");
|
"Images (*.png *.jpg *.bmp *.raw *.mdr)");
|
||||||
if (result.isNull()) {
|
if (result.isNull()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
settings.setValue("heightDir", QFileInfo(result).path());
|
settings.setValue("heightDir", QFileInfo(result).path());
|
||||||
const quint16 CONVERSION_OFFSET = 1;
|
const quint16 CONVERSION_OFFSET = 1;
|
||||||
if (result.toLower().endsWith(".raw")) {
|
QString lowerResult = result.toLower();
|
||||||
|
bool isMDR = lowerResult.endsWith(".mdr");
|
||||||
|
if (lowerResult.endsWith(".raw") || isMDR) {
|
||||||
QFile input(result);
|
QFile input(result);
|
||||||
input.open(QIODevice::ReadOnly);
|
input.open(QIODevice::ReadOnly);
|
||||||
QDataStream in(&input);
|
QDataStream in(&input);
|
||||||
in.setByteOrder(QDataStream::LittleEndian);
|
in.setByteOrder(QDataStream::LittleEndian);
|
||||||
QVector<quint16> rawContents;
|
if (isMDR) {
|
||||||
while (!in.atEnd()) {
|
const int MDR_HEADER_SIZE = 1024;
|
||||||
quint16 height;
|
input.seek(MDR_HEADER_SIZE);
|
||||||
in >> height;
|
}
|
||||||
rawContents.append(height);
|
int available = input.bytesAvailable() / sizeof(quint16);
|
||||||
|
QVector<quint16> rawContents(available);
|
||||||
|
for (quint16* height = rawContents.data(), *end = height + available; height != end; height++) {
|
||||||
|
in >> *height;
|
||||||
}
|
}
|
||||||
if (rawContents.isEmpty()) {
|
if (rawContents.isEmpty()) {
|
||||||
QMessageBox::warning(this, "Invalid Image", "The selected image could not be read.");
|
QMessageBox::warning(this, "Invalid Image", "The selected image could not be read.");
|
||||||
|
|
Loading…
Reference in a new issue