Index: lib/jpegcontent.cpp =================================================================== --- lib/jpegcontent.cpp +++ lib/jpegcontent.cpp @@ -113,7 +113,11 @@ // performed a lossy image manipulation, mRawData is cleared and the image // pixels are kept in mImage until updateRawDataFromImage() is called. QImage mImage; + + // mFile needs to be kept open, as it may be memory mapped and mRawData may point to it + QFile mFile; QByteArray mRawData; + QSize mSize; QString mComment; bool mPendingTransformation; @@ -205,12 +209,25 @@ bool JpegContent::load(const QString& path) { - QFile file(path); - if (!file.open(QIODevice::ReadOnly)) { + d->mFile.setFileName(path); + if (!d->mFile.open(QIODevice::ReadOnly)) { qCritical() << "Could not open '" << path << "' for reading\n"; return false; } - return loadFromData(file.readAll()); + + QByteArray rawData; + uchar* mappedFile = d->mFile.map(0, d->mFile.size(), QFileDevice::MapPrivateOption); + if(mappedFile == nullptr) { + // process' mapping limit exceeded, file is sealed or filesystem doesn't support it, etc. + qDebug() << "Could not mmap '" << path << "', falling back to QFile::readAll()\n"; + + rawData = file.readAll(); + } + else { + rawData = QByteArray::fromRawData(reinterpret_cast(mappedFile), d->mFile.size()); + } + + return loadFromData(rawData); } bool JpegContent::loadFromData(const QByteArray& data)