NOTE: we cannot use QImage for loading, since it strips the color profile attached to the PNG file
319{
320 QFileInfo originalInfo(
m_d->
path);
322 bool successfullyLoaded = false;
323
328
330 m_d->
doc->setFileBatchMode(
true);
331
332 auto loadPathNatively = [&doc =
m_d->
doc](
const QString &path) ->
bool {
334 if (successfullyLoaded) {
335
337 doc->image()->waitForDone();
338 }
339 return successfullyLoaded;
340 };
341
342 if (
m_d->
path.toLower().endsWith(
"ora") ||
m_d->
path.toLower().endsWith(
"kra")) {
344 if (store && !store->bad()) {
345 if (store->open(QString("mergedimage.png"))) {
356 qint64 totalWritten = 0;
357 const qint64 expectedFileSize = store->size();
358 QTemporaryFile temporaryFile(QDir::tempPath() + QLatin1String("/krita_merged_image_XXXXXX.png"));
359 if (temporaryFile.open()) {
360 QByteArray buffer(BUFSIZ, 0);
361
362 while (true) {
363 qint64 read = store->read(buffer.data(), buffer.size());
364 if (read < 0) {
365 warnKrita <<
"Failed to read from mergedimage.png for the file layer's projection";
366 break;
367 } else if (read == 0) {
368
369 break;
370 } else {
371
372 qint64 written = temporaryFile.write(buffer.constData(), read);
373 if (written < 0) {
374
375 warnKrita <<
"Failed to write mergedimage.png into a temporary file for the file layer's projection"
376 << temporaryFile.fileName() << ":" << temporaryFile.errorString();
377 break;
378 }
379
380
381 totalWritten += written;
382 }
383 }
384
385 temporaryFile.close();
386 } else {
387 warnKrita <<
"Failed to open temporary file for mergedimage.png for the file layer's projection"
388 << temporaryFile.fileName() << ":" << temporaryFile.errorString();
389 }
390 store->close();
391
392 if (totalWritten == expectedFileSize) {
393 successfullyLoaded = loadPathNatively(temporaryFile.fileName());
394 } else {
395 successfullyLoaded = false;
396 }
397 }
398 else {
399 qWarning() << "delayedLoadStart: Could not open mergedimage.png";
400 }
401 }
402 else {
403 qWarning() << "delayedLoadStart: Store was bad";
404 }
405 }
406 else {
408 }
409 } else {
410 dbgKrita <<
"File was modified externally. Restarting.";
417 }
418
421
422 if (!successfullyLoaded) {
423
427 }
428 else {
430 }
431 }
432 else {
437 m_d->
doc->image()->xRes(),
438 m_d->
doc->image()->yRes(),
439 m_d->
doc->image()->size());
440 }
441
443}
void makeCloneFrom(KisPaintDeviceSP src, const QRect &rect)
static KisPart * instance()
void loadingFinished(KisPaintDeviceSP paintDevice, qreal xRes, qreal yRes, const QSize &size)
static KoStore * createStore(const QString &fileName, Mode mode, const QByteArray &appIdentification=QByteArray(), Backend backend=Auto, bool writeMimetype=true)
void forceAllDelayedNodesUpdate(KisNodeSP root)
QDateTime initialFileTimeStamp
QScopedPointer< KisDocument > doc