Changeset View
Changeset View
Standalone View
Standalone View
lib/jpegcontent.cpp
Context not available. | |||||
113 | // performed a lossy image manipulation, mRawData is cleared and the image | 113 | // performed a lossy image manipulation, mRawData is cleared and the image | ||
---|---|---|---|---|---|
114 | // pixels are kept in mImage until updateRawDataFromImage() is called. | 114 | // pixels are kept in mImage until updateRawDataFromImage() is called. | ||
115 | QImage mImage; | 115 | QImage mImage; | ||
116 | | ||||
117 | // mFile needs to be kept open, as it may be memory mapped and mRawData may point to it | ||||
118 | QFile mFile; | ||||
116 | QByteArray mRawData; | 119 | QByteArray mRawData; | ||
120 | | ||||
117 | QSize mSize; | 121 | QSize mSize; | ||
118 | QString mComment; | 122 | QString mComment; | ||
119 | bool mPendingTransformation; | 123 | bool mPendingTransformation; | ||
Context not available. | |||||
205 | 209 | | |||
206 | bool JpegContent::load(const QString& path) | 210 | bool JpegContent::load(const QString& path) | ||
207 | { | 211 | { | ||
208 | QFile file(path); | 212 | d->mFile.setFileName(path); | ||
209 | if (!file.open(QIODevice::ReadOnly)) { | 213 | if (!d->mFile.open(QIODevice::ReadOnly)) { | ||
210 | qCritical() << "Could not open '" << path << "' for reading\n"; | 214 | qCritical() << "Could not open '" << path << "' for reading\n"; | ||
211 | return false; | 215 | return false; | ||
212 | } | 216 | } | ||
213 | return loadFromData(file.readAll()); | 217 | | ||
218 | QByteArray rawData; | ||||
219 | uchar* mappedFile = d->mFile.map(0, d->mFile.size(), QFileDevice::MapPrivateOption); | ||||
220 | if(mappedFile == nullptr) { | ||||
221 | // process' mapping limit exceeded, file is sealed or filesystem doesn't support it, etc. | ||||
222 | qDebug() << "Could not mmap '" << path << "', falling back to QFile::readAll()\n"; | ||||
223 | | ||||
224 | rawData = file.readAll(); | ||||
225 | } | ||||
226 | else { | ||||
227 | rawData = QByteArray::fromRawData(reinterpret_cast<char*>(mappedFile), d->mFile.size()); | ||||
228 | } | ||||
229 | | ||||
230 | return loadFromData(rawData); | ||||
214 | } | 231 | } | ||
215 | 232 | | |||
216 | bool JpegContent::loadFromData(const QByteArray& data) | 233 | bool JpegContent::loadFromData(const QByteArray& data) | ||
Context not available. |