OpenToonz - An open-source full-featured 2D animation creation software
C
fix convert to painted tlv
shun_iwasawa22ad9ee8efc4
diff --git a/toonz/sources/include/toonz/Naa2TlvConverter.h b/toonz/sources/include/toonz/Naa2TlvConverter.hindex e15fd38a2..29627d3e7 100644--- a/toonz/sources/include/toonz/Naa2TlvConverter.h+++ b/toonz/sources/include/toonz/Naa2TlvConverter.h@@ -146,12 +146,13 @@ public:return -1;}- TToonzImageP makeTlv(bool transparentSyntheticInks,- bool removeUnusedStyles = false);+ TToonzImageP makeTlv(bool transparentSyntheticInks, QList<int> &usedStyleIds);TVectorImageP vectorize(const TToonzImageP &ti);TVectorImageP vectorize(const TRaster32P &ras);TVectorImageP vectorize();++ void removeUnusedStyles(const QList<int> &styleIds);};#endifdiff --git a/toonz/sources/toonz/convertpopup.cpp b/toonz/sources/toonz/convertpopup.cppindex 7ed582e9f..ae61abfc1 100644--- a/toonz/sources/toonz/convertpopup.cpp+++ b/toonz/sources/toonz/convertpopup.cpp@@ -784,6 +784,7 @@ void ConvertPopup::setFiles(const std::vector<TFilePath> &fps) {// if (m_unpaintedFolder->getPath()==SameAsPainted)// m_unpaintedFolder->setPath(toQString(fps[0].getParentDir()));m_palettePath->setPath(CreateNewPalette);+ m_removeUnusedStyles->setEnabled(false);// m_fileFormat->setCurrentIndex(areFullcolor?0:m_fileFormat->findText("tif"));}diff --git a/toonz/sources/toonzlib/Naa2TlvConverter.cpp b/toonz/sources/toonzlib/Naa2TlvConverter.cppindex d0a5e6e60..50004f5a7 100644--- a/toonz/sources/toonzlib/Naa2TlvConverter.cpp+++ b/toonz/sources/toonzlib/Naa2TlvConverter.cpp@@ -331,8 +331,7 @@ void Naa2TlvConverter::computeLinks() {//------------------------------------------------------------------------------// find background regions :-// (almost) white, touching image border+// find background regions : (almost) white//void Naa2TlvConverter::findBackgroundRegions() {if (!m_regionRas || m_regions.empty()) return;@@ -358,11 +357,8 @@ void Naa2TlvConverter::findBackgroundRegions() {}for (int i = 0; i < m_regions.count(); i++) {- RegionInfo ®ion = m_regions[i];- if (region.colorIndex == bgColorIndex && region.links.contains(-1)) {- region.type = RegionInfo::Background;- ;- }+ RegionInfo ®ion = m_regions[i];+ if (region.colorIndex == bgColorIndex) region.type = RegionInfo::Background;}}@@ -1006,7 +1002,7 @@ int Naa2TlvConverter::measureThickness(int x0, int y0) {//-----------------------------------------------------------------------------TToonzImageP Naa2TlvConverter::makeTlv(bool transparentSyntheticInks,- bool removeUnusedStyles) {+ QList<int> &usedStyleIds) {if (!m_valid || m_colors.empty() || m_regions.empty() || !m_regionRas)return TToonzImageP();int lx = m_regionRas->getLx();@@ -1031,27 +1027,13 @@ TToonzImageP Naa2TlvConverter::makeTlv(bool transparentSyntheticInks,cs = palette->getStyle(styleId);}styleIds.append(styleId);+ if (!usedStyleIds.contains(styleId)) usedStyleIds.append(styleId);}styleIds.append(0); // syntetic ink// int synteticInkStyleId = palette->getPage(0)->addStyle(TPixel32(0,0,0,0));// styleIds.append(synteticInkStyleId);- // Remove unused styles from input palette- if (removeUnusedStyles) {- for (int p = palette->getPageCount() - 1; p >= 0; p--) {- TPalette::Page *page = palette->getPage(p);- for (int s = page->getStyleCount() - 1; s >= 0; s--) {- int styleId = page->getStyleId(s);- if (styleId == -1) continue;- // check if the style is used or not- if (!styleIds.contains(styleId)) page->removeStyle(s);- }- // erase empty page- if (page->getStyleCount() == 0) palette->erasePage(p);- }- }-for (int y = 0; y < ly; y++) {unsigned short *workScanLine = m_regionRas->pixels(y);TPixelCM32 *outScanLine = ras->pixels(y);@@ -1115,3 +1097,21 @@ TVectorImageP Naa2TlvConverter::vectorize(const TToonzImageP &ti) {vi->setPalette(palette);return vi;}++//-----------------------------------------------------------------------------++void Naa2TlvConverter::removeUnusedStyles(const QList<int> &styleIds) {+ // Remove unused styles from input palette+ if (!m_palette) return;+ for (int p = m_palette->getPageCount() - 1; p >= 0; p--) {+ TPalette::Page *page = m_palette->getPage(p);+ for (int s = page->getStyleCount() - 1; s >= 0; s--) {+ int styleId = page->getStyleId(s);+ if (styleId == -1) continue;+ // check if the style is used or not+ if (!styleIds.contains(styleId)) page->removeStyle(s);+ }+ // erase empty page+ if (page->getStyleCount() == 0) m_palette->erasePage(p);+ }+}diff --git a/toonz/sources/toonzlib/tcenterlinevectorizer.cpp b/toonz/sources/toonzlib/tcenterlinevectorizer.cppindex 5db93d782..65992fd15 100644--- a/toonz/sources/toonzlib/tcenterlinevectorizer.cpp+++ b/toonz/sources/toonzlib/tcenterlinevectorizer.cpp@@ -176,7 +176,8 @@ TVectorImageP VectorizerCore::centerlineVectorize(converter.process(ras32);converter.setPalette(palette);- if (ti = converter.makeTlv(true)) // Transparent synthetic inks+ QList<int> dummy;+ if (ti = converter.makeTlv(true, dummy)) // Transparent synthetic inks{image = ti;ras = ti->getRaster();diff --git a/toonz/sources/toonzqt/imageutils.cpp b/toonz/sources/toonzqt/imageutils.cppindex 06b67b6c4..8131c3228 100644--- a/toonz/sources/toonzqt/imageutils.cpp+++ b/toonz/sources/toonzqt/imageutils.cpp@@ -652,6 +652,8 @@ void convertNaa2Tlv(const TFilePath &source, const TFilePath &dest,Naa2TlvConverter converter;converter.setPalette(palette);+ QList<int> usedStyleIds({0});+int f, fCount = int(frames.size());for (f = 0; f != fCount; ++f) {if (frameNotifier->abortTask()) break;@@ -672,8 +674,8 @@ void convertNaa2Tlv(const TFilePath &source, const TFilePath &dest,converter.process(raster);- if (TToonzImageP dstImg = converter.makeTlv(- false, removeUnusedStyles)) // Opaque synthetic inks+ if (TToonzImageP dstImg =+ converter.makeTlv(false, usedStyleIds)) // Opaque synthetic inks{if (converter.getPalette() == 0)converter.setPalette(dstImg->getPalette());@@ -693,6 +695,8 @@ void convertNaa2Tlv(const TFilePath &source, const TFilePath &dest,frameNotifier->notifyFrameCompleted(100 * (f + 1) / frames.size());}++ if (removeUnusedStyles) converter.removeUnusedStyles(usedStyleIds);}//=============================================================================