From 4d02654ea891a73f121f318ffe655cb3bda52677 Mon Sep 17 00:00:00 2001 From: manongjohn Date: Sep 27 2017 07:22:03 +0000 Subject: Toonz raster merge crash fix (#1480) close #1238 --- diff --git a/toonz/sources/toonz/matchlinecommand.cpp b/toonz/sources/toonz/matchlinecommand.cpp index 04f329f..4facb4c 100644 --- a/toonz/sources/toonz/matchlinecommand.cpp +++ b/toonz/sources/toonz/matchlinecommand.cpp @@ -473,15 +473,17 @@ public: cloneColumn(cells, newLevelPath); + TFilePath tmpPath = newLevelPath.withName( + QString::fromStdString(newLevelPath.getName() + "_tmp").toStdWString()); + it = indices.begin(); ++it; for (int count = 0; it != indices.end();) { int index = *it; it++; mergeCmapped(destColumn, index - count, - it == indices.end() - ? QString::fromStdWString(newLevelPath.getWideString()) - : "", + it == indices.end() ? newLevelPath.getQString() + : tmpPath.getQString(), false); ColumnCmd::deleteColumn(index - count); progress.setValue(++count); diff --git a/toonz/sources/toonz/mergecmapped.cpp b/toonz/sources/toonz/mergecmapped.cpp index 56f63d1..e4863e9 100644 --- a/toonz/sources/toonz/mergecmapped.cpp +++ b/toonz/sources/toonz/mergecmapped.cpp @@ -32,6 +32,8 @@ #include "toonz/levelproperties.h" #include "toonz/toonzscene.h" #include "toonz/childstack.h" +#include "toonz/toonzimageutils.h" +#include "tpaletteutil.h" #include @@ -73,6 +75,15 @@ void mergeCmapped(const std::vector &matchingLevels) { (TToonzImageP)matchingLevels[i].m_mcell->getImage(false); if (!img || !match) throw TRopException("Can merge only cmapped raster images!"); + + std::set usedStyles; + ToonzImageUtils::getUsedStyles(usedStyles, match); + std::map indexTable; + mergePalette(palette, indexTable, matchPalette, usedStyles); + ToonzImageUtils::scrambleStyles(match, indexTable); + match->setPalette(palette); + matchPalette = palette; + // img->lock(); TRasterCM32P ras = img->getRaster(); // img->getCMapped(false); TRasterCM32P matchRas = match->getRaster(); // match->getCMapped(true); @@ -129,35 +140,36 @@ void mergeCmapped(const std::vector &matchingLevels) { img->setSavebox(img->getSavebox() + (matchRas->getBounds() + offs)); } + /* + std::map::iterator it = usedColors.begin(); + for (; it != usedColors.end(); ++it) + if (it->first != it->second) break; - std::map::iterator it = usedColors.begin(); - for (; it != usedColors.end(); ++it) - if (it->first != it->second) break; + if (it == usedColors.end()) // this means that the merged palette does not + // differ from source palette.(all usedColors + // are not new color ) + return; - if (it == usedColors.end()) // this means that the merged palette does not - // differ from source palette.(all usedColors are - // not new color ) - return; + std::wstring pageName = L"merged palettes"; - std::wstring pageName = L"merged palettes"; - - for (i = 0; i < palette->getPageCount(); i++) - if (palette->getPage(i)->getName() == pageName) { - page = palette->getPage(i); - break; + for (i = 0; i < palette->getPageCount(); i++) + if (palette->getPage(i)->getName() == pageName) { + page = palette->getPage(i); + break; + } + if (i == palette->getPageCount()) page = palette->addPage(pageName); + + it = usedColors.begin(); + int count = 0; + for (; it != usedColors.end(); ++it) { + if (it->first == it->second) continue; + while (palette->getStyleCount() <= it->second) + palette->addStyle(TPixel32::Red); + palette->setStyle(it->second, matchPalette->getStyle(it->first)->clone()); + page->addStyle(it->second); } - if (i == palette->getPageCount()) page = palette->addPage(pageName); - - it = usedColors.begin(); - int count = 0; - for (; it != usedColors.end(); ++it) { - if (it->first == it->second) continue; - while (palette->getStyleCount() <= it->second) - palette->addStyle(TPixel32::Red); - palette->setStyle(it->second, matchPalette->getStyle(it->first)->clone()); - page->addStyle(it->second); - } - if (usedColors.size() > 0) palette->setDirtyFlag(true); + if (usedColors.size() > 0) palette->setDirtyFlag(true); + */ } /*------------------------------------------------------------------------*/ @@ -238,7 +250,7 @@ public: // assert(matchPalette); int i; for (i = 0; i < fids.size(); i++) { - QString id = "DeleteMatchlineUndo" + QString::number((uintptr_t)this) + + QString id = "DeleteMatchlineUndo" + QString::number((uintptr_t) this) + "-" + QString::number(i); TToonzImageP image = sl->getFrame(fids[i], false); assert(image); @@ -251,7 +263,7 @@ public: // TPalette *palette = m_matchlinePalette->clone(); // m_sl->setPalette(palette); for (i = 0; i < m_fids.size(); i++) { - QString id = "DeleteMatchlineUndo" + QString::number((uintptr_t)this) + + QString id = "DeleteMatchlineUndo" + QString::number((uintptr_t) this) + "-" + QString::number(i); TImageP img = TImageCache::instance()->get(id, false)->cloneImage(); @@ -286,7 +298,7 @@ public: int i; for (i = 0; i < m_fids.size(); i++) TImageCache::instance()->remove("DeleteMatchlineUndo" + - QString::number((uintptr_t)this) + "-" + + QString::number((uintptr_t) this) + "-" + QString::number(i)); } }; @@ -402,8 +414,8 @@ public: std::map::const_iterator it = m_images.begin(); for (; it != m_images.end(); ++it) //, ++mit) { - QString id = "MergeCmappedUndo" + QString::number((uintptr_t)this) + "-" + - QString::number(it->first.getNumber()); + QString id = "MergeCmappedUndo" + QString::number((uintptr_t) this) + + "-" + QString::number(it->first.getNumber()); TImageCache::instance()->remove(id); } delete m_palette; @@ -486,9 +498,10 @@ void mergeCmapped(int column, int mColumn, const QString &fullpath, TXshLevel *txl = level->getScene()->createNewLevel( level->getType(), fp.getWideName(), level->getResolution()); TXshSimpleLevel *newLevel = txl->getSimpleLevel(); + newLevel->setPath(fp); newLevel->setPalette(level->getPalette()); newLevel->clonePropertiesFrom(level); - newLevel->setPath(fp); + // newLevel->setPath(fp); TApp::instance()->getCurrentScene()->notifySceneChanged(); TApp::instance()->getCurrentScene()->notifyCastChange(); diff --git a/toonz/sources/toonz/pane.cpp b/toonz/sources/toonz/pane.cpp index 31a4ebc..527644a 100644 --- a/toonz/sources/toonz/pane.cpp +++ b/toonz/sources/toonz/pane.cpp @@ -182,8 +182,8 @@ void TPanelTitleBarButton::setPressed(bool pressed) { void TPanelTitleBarButton::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.drawPixmap( - 0, 0, m_pressed ? m_pressedPixmap - : m_rollover ? m_rolloverPixmap : m_standardPixmap); + 0, 0, m_pressed ? m_pressedPixmap : m_rollover ? m_rolloverPixmap + : m_standardPixmap); painter.end(); }