From eaa9b0b636a7f81020e213750392b8789301ed94 Mon Sep 17 00:00:00 2001 From: justburner Date: Sun, 10 Jul 2022 15:37:44 +0100 Subject: [PATCH] Simplify uneditable check code --- toonz/sources/common/tsystem/tfilepath.cpp | 13 ++++++--- toonz/sources/include/tfilepath.h | 1 + toonz/sources/include/tlevel_io.h | 28 ++++++++++++++++++++ toonz/sources/tnztools/tool.cpp | 7 +---- toonz/sources/toonz/cellselection.cpp | 11 ++------ toonz/sources/toonz/cellselectioncommand.cpp | 6 +---- toonz/sources/toonz/columnselection.cpp | 6 +---- toonz/sources/toonz/exportpanel.cpp | 2 +- toonz/sources/toonz/filebrowser.cpp | 5 ---- toonz/sources/toonz/filmstrip.cpp | 4 +-- toonz/sources/toonz/filmstripselection.cpp | 5 ++-- toonz/sources/toonz/matchlinecommand.cpp | 6 +---- toonz/sources/toonz/rendercommand.cpp | 2 +- toonz/sources/toonz/tasksviewer.cpp | 10 +------ toonz/sources/toonzlib/txshsimplelevel.cpp | 7 ++--- 15 files changed, 52 insertions(+), 61 deletions(-) diff --git a/toonz/sources/common/tsystem/tfilepath.cpp b/toonz/sources/common/tsystem/tfilepath.cpp index 362b5c15..d5d1a865 100644 --- a/toonz/sources/common/tsystem/tfilepath.cpp +++ b/toonz/sources/common/tsystem/tfilepath.cpp @@ -799,10 +799,15 @@ TFrameId TFilePath::getFrame() const { bool TFilePath::isFfmpegType() const { QString type = QString::fromStdString(getType()).toLower(); - if (type == "gif" || type == "mp4" || type == "webm" || type == "mov") - return true; - else - return false; + return (type == "gif" || type == "mp4" || type == "webm" || type == "mov"); +} + +//----------------------------------------------------------------------------- + +bool TFilePath::isUneditable() const { + QString type = QString::fromStdString(getType()).toLower(); + return (type == "psd" || type == "gif" || type == "mp4" || type == "webm" || + type == "mov"); } //----------------------------------------------------------------------------- diff --git a/toonz/sources/include/tfilepath.h b/toonz/sources/include/tfilepath.h index 301dfde4..d34b444f 100644 --- a/toonz/sources/include/tfilepath.h +++ b/toonz/sources/include/tfilepath.h @@ -247,6 +247,7 @@ If the path is ":" a slash will be added*/ TFrameId getFrame() const; bool isFfmpegType() const; + bool isUneditable() const; bool isLevelName() const; //{return getFrame() == TFrameId(TFrameId::EMPTY_FRAME);}; bool isAbsolute() const; diff --git a/toonz/sources/include/tlevel_io.h b/toonz/sources/include/tlevel_io.h index 51bde9e2..e4569376 100644 --- a/toonz/sources/include/tlevel_io.h +++ b/toonz/sources/include/tlevel_io.h @@ -250,6 +250,19 @@ inline bool isMovieType(const TFilePath &fp) { //----------------------------------------------------------- +inline bool isMovieTypeOpaque(std::string type) { + return (type == "avi" || type == "3gp" || type == "mp4"); +} + +//----------------------------------------------------------- + +inline bool isMovieTypeOpaque(const TFilePath &fp) { + std::string type(fp.getType()); + return isMovieTypeOpaque(type); +} + +//----------------------------------------------------------- + inline bool isSequencialRequired(std::string type) { return (type == "avi" || type == "3gp"); } @@ -263,6 +276,21 @@ inline bool isSequencialRequired(const TFilePath &fp) { //----------------------------------------------------------- +inline bool isMultipleFrameType(std::string type) { + return (type == "tlv" || type == "tzl" || type == "pli" || type == "mov" || + type == "avi" || type == "3gp" || type == "gif" || type == "mp4" || + type == "webm"); +} + +//----------------------------------------------------------- + +inline bool isMultipleFrameType(const TFilePath &fp) { + std::string type(fp.getType()); + return isMultipleFrameType(type); +} + +//----------------------------------------------------------- + inline bool doesSupportRandomAccess(const TFilePath &fp, bool isToonzOutput = false) { return (fp.getDots() == ".."); diff --git a/toonz/sources/tnztools/tool.cpp b/toonz/sources/tnztools/tool.cpp index 1abe0116..a72e7e10 100644 --- a/toonz/sources/tnztools/tool.cpp +++ b/toonz/sources/tnztools/tool.cpp @@ -1108,12 +1108,7 @@ QString TTool::updateEnabled(int rowIndex, int columnIndex) { "The current frame is locked: any editing is forbidden.")); // Check level type write support - if (sl->getPath().getType() == - "psd" || // We don't have the API to write psd files - sl->getPath().getType() == "gif" || - sl->getPath().getType() == "mp4" || - sl->getPath().getType() == "webm" || - sl->getPath().getType() == "mov" || + if (sl->getPath().isUneditable() || sl->is16BitChannelLevel() || // Inherited by previous // implementation. // Could be fixed? diff --git a/toonz/sources/toonz/cellselection.cpp b/toonz/sources/toonz/cellselection.cpp index 14892109..96f9db81 100644 --- a/toonz/sources/toonz/cellselection.cpp +++ b/toonz/sources/toonz/cellselection.cpp @@ -494,10 +494,7 @@ bool pasteStrokesInCellWithoutUndo( } else { vi = cell.getImage(true); sl = cell.getSimpleLevel(); - if (sl->getType() == OVL_XSHLEVEL && - (sl->getPath().getType() == "psd" || sl->getPath().getType() == "gif" || - sl->getPath().getType() == "mp4" || sl->getPath().getType() == "webm" || - sl->getPath().getType() == "mov")) + if (sl->getType() == OVL_XSHLEVEL && sl->getPath().isUneditable()) return false; fid = cell.getFrameId(); if (!vi) { @@ -1765,11 +1762,7 @@ static void pasteRasterImageInCell(int row, int col, } else { TXshSimpleLevel *sl = cell.getSimpleLevel(); // don't do anything to ffmpeg level types - if (sl->getType() == OVL_XSHLEVEL && (sl->getPath().getType() == "psd" || - sl->getPath().getType() == "gif" || - sl->getPath().getType() == "mp4" || - sl->getPath().getType() == "webm" || - sl->getPath().getType() == "mov")) + if (sl->getType() == OVL_XSHLEVEL && sl->getPath().isUneditable()) return; oldPalette = sl->getPalette(); } diff --git a/toonz/sources/toonz/cellselectioncommand.cpp b/toonz/sources/toonz/cellselectioncommand.cpp index c54c32b3..e10a03e6 100644 --- a/toonz/sources/toonz/cellselectioncommand.cpp +++ b/toonz/sources/toonz/cellselectioncommand.cpp @@ -1653,11 +1653,7 @@ void CloneLevelUndo::cloneLevels() const { assert(lt->first && !lt->second.empty()); TXshSimpleLevel *srcSl = lt->first; - if (srcSl->getPath().getType() == "psd" || - srcSl->getPath().getType() == "gif" || - srcSl->getPath().getType() == "mp4" || - srcSl->getPath().getType() == "webm" || - srcSl->getPath().getType() == "mov") + if (srcSl->getPath().isUneditable()) continue; const TFilePath &srcPath = srcSl->getPath(); diff --git a/toonz/sources/toonz/columnselection.cpp b/toonz/sources/toonz/columnselection.cpp index c3c517f9..f24fe020 100644 --- a/toonz/sources/toonz/columnselection.cpp +++ b/toonz/sources/toonz/columnselection.cpp @@ -249,11 +249,7 @@ static bool canMergeColumns(int column, int mColumn, bool forMatchlines) { return false; // Check level type write support. Based on TTool::updateEnabled() if (level->getType() == OVL_XSHLEVEL && - (level->getPath().getType() == "psd" || // PSD files. - level->getPath().getType() == "gif" || - level->getPath().getType() == "mp4" || - level->getPath().getType() == "webm" || - level->getPath().getType() == "mov" || + (level->getPath().isUneditable() || level->is16BitChannelLevel() || // 16bpc images. level->getProperties()->getBpp() == 1)) { // Black & White images. return false; diff --git a/toonz/sources/toonz/exportpanel.cpp b/toonz/sources/toonz/exportpanel.cpp index 4b5c3f3b..e1900976 100644 --- a/toonz/sources/toonz/exportpanel.cpp +++ b/toonz/sources/toonz/exportpanel.cpp @@ -171,7 +171,7 @@ bool RenderController::addScene(MovieGenerator &g, ToonzScene *scene) { } if (r1 < r0) return false; TPixel color = scene->getProperties()->getBgColor(); - if (isMovieType(m_movieExt) && m_movieExt != "mov" && m_movieExt != "webm") color.m = 255; + if (isMovieTypeOpaque(m_movieExt)) color.m = 255; g.setBackgroundColor(color); g.addScene(*scene, r0, r1); return true; diff --git a/toonz/sources/toonz/filebrowser.cpp b/toonz/sources/toonz/filebrowser.cpp index f2d4708a..0b1494fc 100644 --- a/toonz/sources/toonz/filebrowser.cpp +++ b/toonz/sources/toonz/filebrowser.cpp @@ -144,11 +144,6 @@ QMutex levelFileMutex; } // namespace -inline bool isMultipleFrameType(std::string type) { - return (type == "tlv" || type == "tzl" || type == "pli" || type == "avi" || - type == "gif" || type == "mp4" || type == "webm" || type == "mov"); -} - //============================================================================= // FileBrowser //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonz/filmstrip.cpp b/toonz/sources/toonz/filmstrip.cpp index 74073142..dc53a24f 100644 --- a/toonz/sources/toonz/filmstrip.cpp +++ b/toonz/sources/toonz/filmstrip.cpp @@ -1299,9 +1299,7 @@ void FilmstripFrames::contextMenuEvent(QContextMenuEvent *event) { } if (sl && (sl->getType() == TZP_XSHLEVEL || sl->getType() == PLI_XSHLEVEL || - (sl->getType() == OVL_XSHLEVEL && sl->getPath().getType() != "gif" && - sl->getPath().getType() != "mp4" && sl->getPath().getType() != "webm" && - sl->getPath().getType() != "mov"))) + (sl->getType() == OVL_XSHLEVEL && !sl->getPath().isUneditable()))) menu->addAction(cm->getAction(MI_RevertToLastSaved)); menu->addSeparator(); createSelectLevelMenu(menu); diff --git a/toonz/sources/toonz/filmstripselection.cpp b/toonz/sources/toonz/filmstripselection.cpp index f22ff4f0..282a1f08 100644 --- a/toonz/sources/toonz/filmstripselection.cpp +++ b/toonz/sources/toonz/filmstripselection.cpp @@ -57,9 +57,8 @@ void TFilmstripSelection::enableCommands() { bool doEnable = (type == PLI_XSHLEVEL || type == TZP_XSHLEVEL || type == MESH_XSHLEVEL || - (type == OVL_XSHLEVEL && path.getType() != "psd" && - path.getType() != "gif" && path.getType() != "mp4" && - path.getType() != "webm" && path.getType() != "mov")); + (type == OVL_XSHLEVEL && !path.isUneditable())); + TRasterImageP ri = (TRasterImageP)sl->getSimpleLevel()->getFrame( sl->getSimpleLevel()->getFirstFid(), false); diff --git a/toonz/sources/toonz/matchlinecommand.cpp b/toonz/sources/toonz/matchlinecommand.cpp index aa8d9381..8b678019 100644 --- a/toonz/sources/toonz/matchlinecommand.cpp +++ b/toonz/sources/toonz/matchlinecommand.cpp @@ -336,11 +336,7 @@ void doCloneLevelNoSave(const TCellSelection::Range &range, if (!img && !fid.isStopFrame()) continue; if (cell.getSimpleLevel() == 0 || - cell.getSimpleLevel()->getPath().getType() == "psd" || - cell.getSimpleLevel()->getPath().getType() == "gif" || - cell.getSimpleLevel()->getPath().getType() == "mp4" || - cell.getSimpleLevel()->getPath().getType() == "webm" || - cell.getSimpleLevel()->getPath().getType() == "mov") + cell.getSimpleLevel()->getPath().isUneditable()) continue; std::map::iterator it = diff --git a/toonz/sources/toonz/rendercommand.cpp b/toonz/sources/toonz/rendercommand.cpp index 91b19a67..5f13f270 100644 --- a/toonz/sources/toonz/rendercommand.cpp +++ b/toonz/sources/toonz/rendercommand.cpp @@ -447,7 +447,7 @@ void RenderCommand::rasterRender(bool isPreview) { // depth). I tried to make OT to detect the mov settings and adaptively switch // the behavior, but ended in vain :-( // So I just omitted every mov from applying solid background as a quick fix. - if (isMovieType(ext) && ext != "mov" && ext != "webm") { + if (isMovieTypeOpaque(ext)) { scene->getProperties()->setBgColor(currBgColor); } // for non alpha-enabled images (like jpg), background color will be inserted diff --git a/toonz/sources/toonz/tasksviewer.cpp b/toonz/sources/toonz/tasksviewer.cpp index c5f3b042..22c9bab1 100644 --- a/toonz/sources/toonz/tasksviewer.cpp +++ b/toonz/sources/toonz/tasksviewer.cpp @@ -16,6 +16,7 @@ // TnzCore includes #include "tconvert.h" +#include "tlevel_io.h" // Qt includes #include @@ -34,15 +35,6 @@ using namespace DVGui; //============================================================================= -namespace { -bool isMovieType(std::string type) { - return (type == "avi" || type == "mp4" || - type == "webm" || type == "mov"); -} -}; // namespace - -//============================================================================= - const std::vector &TasksViewer::getActions() const { return m_actions; } diff --git a/toonz/sources/toonzlib/txshsimplelevel.cpp b/toonz/sources/toonzlib/txshsimplelevel.cpp index 9f92bec7..e06fd8f2 100644 --- a/toonz/sources/toonzlib/txshsimplelevel.cpp +++ b/toonz/sources/toonzlib/txshsimplelevel.cpp @@ -119,9 +119,7 @@ bool isAreadOnlyLevel(const TFilePath &path) { if (path.getDots() == "." || (path.getDots() == ".." && (path.getType() == "tlv" || path.getType() == "tpl"))) { - if (path.getType() == "psd" || path.getType() == "gif" || - path.getType() == "mp4" || path.getType() == "webm" || - path.getType() == "mov") + if (path.isUneditable()) return true; if (!TSystem::doesExistFileOrLevel(path)) return false; TFileStatus fs(path); @@ -2496,8 +2494,7 @@ bool TXshSimpleLevel::isFrameReadOnly(TFrameId fid) { if (getProperties()->isStopMotionLevel()) return true; TFilePath fullPath = getScene()->decodeFilePath(m_path); std::string fileType = fullPath.getType(); - if (fileType == "psd" || fileType == "gif" || fileType == "mp4" || - fileType == "webm" || fileType == "mov") + if (fullPath.isUneditable()) return true; TFilePath path = fullPath.getDots() == ".." ? fullPath.withFrame(fid) : fullPath;