OpenToonz - An open-source full-featured 2D animation creation software
C
raster level caching on loading
shun-iwasawa48d28989a572
diff --git a/toonz/sources/include/toonz/preferences.h b/toonz/sources/include/toonz/preferences.hindex 0efadb994..fb1d7a7a1 100644--- a/toonz/sources/include/toonz/preferences.h+++ b/toonz/sources/include/toonz/preferences.h@@ -250,8 +250,8 @@ public:return getBoolValue(removeSceneNumberFromLoadedLevelName);}bool isIgnoreImageDpiEnabled() const { return getBoolValue(IgnoreImageDpi); }- int getInitialLoadTlvCachingBehavior() const {- return getIntValue(initialLoadTlvCachingBehavior);+ int getRasterLevelCachingBehavior() const {+ return getIntValue(rasterLevelCachingBehavior);}ColumnIconLoadingPolicy getColumnIconLoadingPolicy() const {return ColumnIconLoadingPolicy(getIntValue(columnIconLoadingPolicy));diff --git a/toonz/sources/include/toonz/preferencesitemids.h b/toonz/sources/include/toonz/preferencesitemids.hindex 0e0dbd5d4..17407c3d0 100644--- a/toonz/sources/include/toonz/preferencesitemids.h+++ b/toonz/sources/include/toonz/preferencesitemids.h@@ -53,7 +53,8 @@ enum PreferencesItemId {subsceneFolderEnabled,removeSceneNumberFromLoadedLevelName,IgnoreImageDpi,- initialLoadTlvCachingBehavior,+ rasterLevelCachingBehavior,+ // initialLoadTlvCachingBehavior, // deprecatedcolumnIconLoadingPolicy,levelFormats, // need to be handle separatelyautoRemoveUnusedLevels,diff --git a/toonz/sources/toonz/filebrowserpopup.cpp b/toonz/sources/toonz/filebrowserpopup.cppindex 3569b98f2..e415e1af6 100644--- a/toonz/sources/toonz/filebrowserpopup.cpp+++ b/toonz/sources/toonz/filebrowserpopup.cpp@@ -682,8 +682,9 @@ LoadLevelPopup::LoadLevelPopup()QWidget *optionWidget = (QWidget *)m_customWidget;// choose tlv caching behavior- QLabel *cacheBehaviorLabel = new QLabel(tr("TLV Caching Behavior"), this);- m_loadTlvBehaviorComboBox = new QComboBox(this);+ QLabel *cacheBehaviorLabel =+ new QLabel(tr("Raster Level Caching Behavior"), this);+ m_rasterCacheBehaviorComboBox = new QComboBox(this);//----Load Subsequence LevelQPushButton *showSubsequenceButton = createShowButton(this);@@ -719,17 +720,17 @@ LoadLevelPopup::LoadLevelPopup()m_notExistLabel = new QLabel(tr("(FILE DOES NOT EXIST)"));//----- m_loadTlvBehaviorComboBox->addItem(tr("On Demand"),- IoCmd::LoadResourceArguments::ON_DEMAND);- m_loadTlvBehaviorComboBox->addItem(tr("All Icons"),- IoCmd::LoadResourceArguments::ALL_ICONS);- m_loadTlvBehaviorComboBox->addItem(+ m_rasterCacheBehaviorComboBox->addItem(+ tr("On Demand"), IoCmd::LoadResourceArguments::ON_DEMAND);+ m_rasterCacheBehaviorComboBox->addItem(+ tr("All Icons"), IoCmd::LoadResourceArguments::ALL_ICONS);+ m_rasterCacheBehaviorComboBox->addItem(tr("All Icons & Images"),IoCmd::LoadResourceArguments::ALL_ICONS_AND_IMAGES);// use the default value set in the preference- m_loadTlvBehaviorComboBox->setCurrentIndex(- m_loadTlvBehaviorComboBox->findData(- Preferences::instance()->getInitialLoadTlvCachingBehavior()));+ m_rasterCacheBehaviorComboBox->setCurrentIndex(+ m_rasterCacheBehaviorComboBox->findData(+ Preferences::instance()->getRasterLevelCachingBehavior()));cacheBehaviorLabel->setObjectName("TitleTxtLabel");//----Load Subsequence Level@@ -786,7 +787,7 @@ LoadLevelPopup::LoadLevelPopup(){cacheLay->addStretch(1);cacheLay->addWidget(cacheBehaviorLabel, 0);- cacheLay->addWidget(m_loadTlvBehaviorComboBox, 0);+ cacheLay->addWidget(m_rasterCacheBehaviorComboBox, 0);}mainLayout->addLayout(cacheLay, 0);@@ -1239,8 +1240,8 @@ bool LoadLevelPopup::execute() {args.step = m_stepCombo->currentIndex();args.inc = m_incCombo->currentIndex();args.doesFileActuallyExist = !m_notExistLabel->isVisible();- args.cachingBehavior = IoCmd::LoadResourceArguments::CacheTlvBehavior(- m_loadTlvBehaviorComboBox->currentData().toInt());+ args.cachingBehavior = IoCmd::LoadResourceArguments::CacheRasterBehavior(+ m_rasterCacheBehaviorComboBox->currentData().toInt());if (m_arrLvlPropWidget->isVisible() &&m_levelPropertiesFrame->isEnabled()) {@@ -1269,8 +1270,8 @@ bool LoadLevelPopup::execute() {args.frameIdsSet.insert(args.frameIdsSet.begin(), *fIdIt);}- args.cachingBehavior = IoCmd::LoadResourceArguments::CacheTlvBehavior(- m_loadTlvBehaviorComboBox->currentData().toInt());+ args.cachingBehavior = IoCmd::LoadResourceArguments::CacheRasterBehavior(+ m_rasterCacheBehaviorComboBox->currentData().toInt());if (m_arrLvlPropWidget->isVisible() &&m_levelPropertiesFrame->isEnabled()) {diff --git a/toonz/sources/toonz/filebrowserpopup.h b/toonz/sources/toonz/filebrowserpopup.hindex a26cc8e17..a01ae2fff 100644--- a/toonz/sources/toonz/filebrowserpopup.h+++ b/toonz/sources/toonz/filebrowserpopup.h@@ -49,7 +49,8 @@ class FileBrowserPopup : public QDialog {public:enum Options //! Various options used to customize the popup's behavior.- { STANDARD = 0x0, //!< Standard options.+ {+ STANDARD = 0x0, //!< Standard options.CUSTOM_LAYOUT = 0x1, //!< Prevents standard layout organization at//! construction, surrendering it//! to the user. Observe that sub-widgets creation is still enforced.@@ -284,7 +285,7 @@ class LoadLevelPopup final : public FileBrowserPopup {DVGui::CheckBox *m_premultiply, *m_whiteTransp; // , *m_doAntialias;QLabel *m_notExistLabel;- QComboBox *m_loadTlvBehaviorComboBox;+ QComboBox *m_rasterCacheBehaviorComboBox;public:LoadLevelPopup();diff --git a/toonz/sources/toonz/iocommand.cpp b/toonz/sources/toonz/iocommand.cppindex 4f00f2843..14cfb28f2 100644--- a/toonz/sources/toonz/iocommand.cpp+++ b/toonz/sources/toonz/iocommand.cpp@@ -86,7 +86,7 @@#include <boost/optional.hpp>#include <boost/utility/in_place_factory.hpp>-//#define USE_SQLITE_HDPOOL+// #define USE_SQLITE_HDPOOLusing namespace DVGui;@@ -2088,6 +2088,13 @@ bool IoCmd::loadScene(const TFilePath &path, bool updateRecentFile,}}+ // caching raster levels+ int cacheRasterBehavior =+ Preferences::instance()->getRasterLevelCachingBehavior();+ if (cacheRasterBehavior != 0) // not "On Demand"+ LevelCmd::loadAllUsedRasterLevelsAndPutInCache(cacheRasterBehavior ==+ 2); // "All Icons & Images"+printf("%s:%s loadScene() completed :\n", __FILE__, __FUNCTION__);return true;}@@ -2581,7 +2588,8 @@ int IoCmd::loadResources(LoadResourceArguments &args, bool updateRecentFile,// load the image data of all frames to cache at the beginningif (args.cachingBehavior != LoadResourceArguments::ON_DEMAND) {TXshSimpleLevel *simpleLevel = xl->getSimpleLevel();- if (simpleLevel && simpleLevel->getType() == TZP_XSHLEVEL) {+ if (simpleLevel && (simpleLevel->getType() == TZP_XSHLEVEL ||+ simpleLevel->getType() == OVL_XSHLEVEL)) {bool cacheImagesAsWell =(args.cachingBehavior ==LoadResourceArguments::ALL_ICONS_AND_IMAGES);@@ -2957,6 +2965,9 @@ public:QString path =RecentFiles::instance()->getFilePath(index, RecentFiles::Level);IoCmd::LoadResourceArguments args(TFilePath(path.toStdWString()));+ args.cachingBehavior = (IoCmd::LoadResourceArguments::CacheRasterBehavior)+ Preferences::instance()+ ->getRasterLevelCachingBehavior();IoCmd::loadResources(args, false);RecentFiles::instance()->moveFilePath(index, 0, RecentFiles::Level);diff --git a/toonz/sources/toonz/iocommand.h b/toonz/sources/toonz/iocommand.hindex 19af69c7f..f4f69ef2b 100644--- a/toonz/sources/toonz/iocommand.h+++ b/toonz/sources/toonz/iocommand.h@@ -95,9 +95,10 @@ struct LoadResourceArguments {enum ImportPolicy //! Policy adopted for resources external to current//! scene.- { ASK_USER, //!< User is prompted for a resolution.- IMPORT, //!< Resources are copied to scene folders (\a overwrites).- LOAD, //!< Resources are loaded from their original paths.+ {+ ASK_USER, //!< User is prompted for a resolution.+ IMPORT, //!< Resources are copied to scene folders (\a overwrites).+ LOAD, //!< Resources are loaded from their original paths.};public:@@ -132,7 +133,7 @@ public:int step, inc, frameCount;bool doesFileActuallyExist;- enum CacheTlvBehavior {+ enum CacheRasterBehavior {ON_DEMAND = 0, // image data will be loaded when neededALL_ICONS, // icon data of all frames will be cached at the begininngALL_ICONS_AND_IMAGES // both icon and image data of all frames will bediff --git a/toonz/sources/toonz/levelcommand.cpp b/toonz/sources/toonz/levelcommand.cppindex 1a4c8ecdd..faaac087c 100644--- a/toonz/sources/toonz/levelcommand.cpp+++ b/toonz/sources/toonz/levelcommand.cpp@@ -33,6 +33,10 @@#include "toonzqt/gutil.h"#include "toonz/namebuilder.h"+#include <QProgressDialog>+#include <QMainWindow>+#include <QApplication>+namespace {class DeleteLevelUndo final : public TUndo {@@ -117,6 +121,58 @@ bool LevelCmd::removeLevelFromCast(TXshLevel *level, ToonzScene *scene,return true;}+void LevelCmd::loadAllUsedRasterLevelsAndPutInCache(bool cacheImagesAsWell) {+ TApp *app = TApp::instance();+ ToonzScene *scene = app->getCurrentScene()->getScene();++ TLevelSet *levelSet = scene->getLevelSet();++ std::set<TXshLevel *> usedLevels;+ scene->getTopXsheet()->getUsedLevels(usedLevels);++ std::map<TXshSimpleLevel *, int>+ targetLevels; // level pointer and its frame amount+ int totalFrames = 0;+ // estimate the amount+ for (auto xl : usedLevels) {+ TXshSimpleLevel *simpleLevel = xl->getSimpleLevel();+ if (simpleLevel && (simpleLevel->getType() == TZP_XSHLEVEL ||+ simpleLevel->getType() == OVL_XSHLEVEL)) {+ targetLevels[simpleLevel] = simpleLevel->getFrameCount();+ totalFrames += simpleLevel->getFrameCount();+ }+ }++ // if the amount of frames is more than 10, open a progress dialog and+ // shows WaitCursor+ QProgressDialog *pd = nullptr;+ if (totalFrames > 10) {+ pd = new QProgressDialog(QObject::tr("Loading Raster Images To Cache..."),+ QObject::tr("Cancel"), 0, totalFrames,+ app->getMainWindow());+ pd->setAttribute(Qt::WA_DeleteOnClose, true);+ pd->setWindowModality(Qt::WindowModal);+ QApplication::setOverrideCursor(Qt::WaitCursor);+ pd->show();+ }+ std::map<TXshSimpleLevel *, int>::iterator i = targetLevels.begin();+ while (i != targetLevels.end()) {+ if (pd && pd->wasCanceled()) break;+ i->first->loadAllIconsAndPutInCache(cacheImagesAsWell);+ if (pd) {+ pd->setValue(pd->value() + i->second);+ QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);+ }+ ++i;+ }++ if (pd) {+ QApplication::restoreOverrideCursor();+ pd->close();+ }+ return;+}+//=============================================================================// RemoveUnusedLevelCommand//-----------------------------------------------------------------------------diff --git a/toonz/sources/toonz/levelcommand.h b/toonz/sources/toonz/levelcommand.hindex bbcbb229b..c2bee45d4 100644--- a/toonz/sources/toonz/levelcommand.h+++ b/toonz/sources/toonz/levelcommand.h@@ -26,6 +26,8 @@ bool removeUnusedLevelsFromCast(bool showMessage = true);// returns false.bool removeLevelFromCast(TXshLevel* level, ToonzScene* scene = nullptr,bool showMessage = true);++void loadAllUsedRasterLevelsAndPutInCache(bool cacheImagesAsWell);} // namespace LevelCmd#endif\ No newline at end of filediff --git a/toonz/sources/toonz/preferencespopup.cpp b/toonz/sources/toonz/preferencespopup.cppindex 87bf56543..0aebcbd38 100644--- a/toonz/sources/toonz/preferencespopup.cpp+++ b/toonz/sources/toonz/preferencespopup.cpp@@ -1197,7 +1197,7 @@ QString PreferencesPopup::getUIString(PreferencesItemId id) {{removeSceneNumberFromLoadedLevelName,tr("Automatically Remove Scene Number from Loaded Level Name")},{IgnoreImageDpi, tr("Use Camera DPI for All Imported Images")},- {initialLoadTlvCachingBehavior, tr("Default TLV Caching Behavior:")},+ {rasterLevelCachingBehavior, tr("Raster Level Caching Behavior:")},{columnIconLoadingPolicy, tr("Column Icon:")},//{ levelFormats, tr("") },@@ -1375,7 +1375,7 @@ QList<ComboBoxItem> PreferencesPopup::getComboItemList({{tr("Always ask before loading or importing"), 0},{tr("Always import the file to the current project"), 1},{tr("Always load the file from the current location"), 2}}},- {initialLoadTlvCachingBehavior,+ {rasterLevelCachingBehavior,{{tr("On Demand"), 0},{tr("All Icons"), 1},{tr("All Icons & Images"), 2}}},@@ -1745,8 +1745,8 @@ QWidget* PreferencesPopup::createLoadingPage() {insertUI(subsceneFolderEnabled, lay);insertUI(removeSceneNumberFromLoadedLevelName, lay);insertUI(IgnoreImageDpi, lay);- insertUI(initialLoadTlvCachingBehavior, lay,- getComboItemList(initialLoadTlvCachingBehavior));+ insertUI(rasterLevelCachingBehavior, lay,+ getComboItemList(rasterLevelCachingBehavior));insertUI(columnIconLoadingPolicy, lay,getComboItemList(columnIconLoadingPolicy));diff --git a/toonz/sources/toonzlib/imagebuilders.cpp b/toonz/sources/toonzlib/imagebuilders.cppindex 163eae2ab..dfb2f4e6c 100644--- a/toonz/sources/toonzlib/imagebuilders.cpp+++ b/toonz/sources/toonzlib/imagebuilders.cpp@@ -220,7 +220,10 @@ void ImageLoader::buildAllIconsAndPutInCache(TXshSimpleLevel *level,std::vector<TFrameId> fids,std::vector<std::string> iconIds,bool cacheImagesAsWell) {- if (m_path.getType() != "tlv") return;+ // if (m_path.getType() != "tlv") return;+ if (level->getType() != TZP_XSHLEVEL && level->getType() != OVL_XSHLEVEL)+ return;+if (fids.empty() || iconIds.empty()) return;/*- The number of fid and icon id should be the same -*/if ((int)fids.size() != (int)iconIds.size()) return;diff --git a/toonz/sources/toonzlib/preferences.cpp b/toonz/sources/toonzlib/preferences.cppindex 4861a6172..7c63cc205 100644--- a/toonz/sources/toonzlib/preferences.cpp+++ b/toonz/sources/toonzlib/preferences.cpp@@ -467,7 +467,7 @@ void Preferences::definePreferenceItems() {define(removeSceneNumberFromLoadedLevelName,"removeSceneNumberFromLoadedLevelName", QMetaType::Bool, false);define(IgnoreImageDpi, "IgnoreImageDpi", QMetaType::Bool, false);- define(initialLoadTlvCachingBehavior, "initialLoadTlvCachingBehavior",+ define(rasterLevelCachingBehavior, "rasterLevelCachingBehavior",QMetaType::Int, 0); // On Demanddefine(columnIconLoadingPolicy, "columnIconLoadingPolicy", QMetaType::Int,(int)LoadAtOnce);@@ -798,6 +798,16 @@ void Preferences::resolveCompatibility() {!m_settings->contains("DefRasterFormat")) {setValue(DefRasterFormat, m_settings->value("scanLevelType").toString());}+ // "initialLoadTlvCachingBehavior" is changed to "rasterLevelCachingBehavior"+ // , Now this setting also applies to raster levels (previously only Toonz+ // raster levels). It also applies to any operation that loads a level, such+ // as loading scene or loading a recent level. (Previously, this was only+ // available from the Load Level popup.)+ if (m_settings->contains("initialLoadTlvCachingBehavior") &&+ !m_settings->contains("rasterLevelCachingBehavior")) {+ setValue(rasterLevelCachingBehavior,+ m_settings->value("initialLoadTlvCachingBehavior").toInt());+ }}//-----------------------------------------------------------------diff --git a/toonz/sources/toonzlib/txshsimplelevel.cpp b/toonz/sources/toonzlib/txshsimplelevel.cppindex 27375d0b5..6c5201087 100644--- a/toonz/sources/toonzlib/txshsimplelevel.cpp+++ b/toonz/sources/toonzlib/txshsimplelevel.cpp@@ -625,7 +625,7 @@ TImageP TXshSimpleLevel::getFrameIcon(const TFrameId &fid) const {//-----------------------------------------------------------------------------// load icon (and image) data of all frames into cachevoid TXshSimpleLevel::loadAllIconsAndPutInCache(bool cacheImagesAsWell) {- if (m_type != TZP_XSHLEVEL) return;+ if (m_type != TZP_XSHLEVEL && m_type != OVL_XSHLEVEL) return;std::vector<TFrameId> fids;getFids(fids);