From kde-commits Mon Apr 30 19:24:18 2018 From: Maik Qualmann Date: Mon, 30 Apr 2018 19:24:18 +0000 To: kde-commits Subject: [digikam] core/utilities/imageeditor/core: undo is now very fast on big images Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=152511626927133 Git commit cbfbb398be95d1bf66838375e481f261f5cb99b2 by Maik Qualmann. Committed on 30/04/2018 at 19:23. Pushed by mqualmann into branch 'master'. undo is now very fast on big images M +11 -13 core/utilities/imageeditor/core/undocache.cpp https://commits.kde.org/digikam/cbfbb398be95d1bf66838375e481f261f5cb99b2 diff --git a/core/utilities/imageeditor/core/undocache.cpp b/core/utilities= /imageeditor/core/undocache.cpp index b45748edc7..b27ecb7200 100644 --- a/core/utilities/imageeditor/core/undocache.cpp +++ b/core/utilities/imageeditor/core/undocache.cpp @@ -44,7 +44,6 @@ // Local includes = #include "digikam_debug.h" -#include "dimgloader.h" = namespace Digikam { @@ -166,12 +165,14 @@ bool UndoCache::putData(int level, const DImg& img) c= onst { file.close(); file.remove(); + return false; } = d->cachedLevels << level; = file.close(); + return true; } = @@ -197,38 +198,35 @@ DImg UndoCache::getData(int level) const ds >> hasAlpha; ds >> sixteenBit; = - qint64 size =3D w * h * (sixteenBit ? 8 : 4); - - if (ds.status() !=3D QDataStream::Ok || - ds.atEnd() || numBytes !=3D size || size =3D=3D 0) + if (ds.status() !=3D QDataStream::Ok || ds.atEnd()) { qCDebug(DIGIKAM_GENERAL_LOG) << "The undo cache file is corrupt"; = file.close(); + return DImg(); } = - char* data =3D (char*)DImgLoader::new_failureTolerant(size); + DImg img(w, h, sixteenBit, hasAlpha); = - if (!data) + if (img.isNull() || numBytes !=3D img.numBytes()) { file.close(); + return DImg(); } = - qint64 readSize =3D file.read(data, size); + qint64 readBytes =3D file.read((char*)img.bits(), numBytes); = - if (file.error() !=3D QFileDevice::NoError || readSize !=3D size) + if (file.error() !=3D QFileDevice::NoError || readBytes !=3D numBytes) { - delete [] data; - file.close(); + return DImg(); } = - DImg img(w, h, sixteenBit, hasAlpha, (uchar*)data, false); - file.close(); + return img; } =20