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 QTemporaryFile temporaryFile(QDir::tempPath() + QLatin1String("/krita_merged_image_XXXXXX.png"));
357 temporaryFile.open();
358
359 QByteArray buffer(BUFSIZ, 0);
360 qint64 totalWritten = 0;
361 const qint64 expectedFileSize = store->size();
362
363 while (true) {
364 qint64 read = store->read(buffer.data(), buffer.size());
365 if (read < 0) {
366 warnKrita <<
"Failed to read from mergedimage.png for the file layer's projection";
367 break;
368 } else if (read == 0) {
369
370 break;
371 } else {
372
373 qint64 written = temporaryFile.write(buffer.constData(), read);
374 if (written < 0) {
375
376 warnKrita <<
"Failed to wirte mergedimage.png into a temporary file for the file layer's projection"
377 << temporaryFile.fileName() << ":" << temporaryFile.error();
378 break;
379 }
380
381
382 totalWritten += written;
383 }
384 }
385
386 temporaryFile.close();
387 store->close();
388
389 if (totalWritten == expectedFileSize) {
390 successfullyLoaded = loadPathNatively(temporaryFile.fileName());
391 } else {
392 successfullyLoaded = false;
393 }
394 }
395 else {
396 qWarning() << "delayedLoadStart: Could not open mergedimage.png";
397 }
398 }
399 else {
400 qWarning() << "delayedLoadStart: Store was bad";
401 }
402 }
403 else {
405 }
406 } else {
407 dbgKrita <<
"File was modified externally. Restarting.";
414 }
415
418
419 if (!successfullyLoaded) {
420
424 }
425 else {
427 }
428 }
429 else {
434 m_d->
doc->image()->xRes(),
435 m_d->
doc->image()->yRes(),
436 m_d->
doc->image()->size());
437 }
438
440}
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