diff --git a/toonz/sources/image/tzl/tiio_tzl.cpp b/toonz/sources/image/tzl/tiio_tzl.cpp index 47c6929..bcdf7f6 100644 --- a/toonz/sources/image/tzl/tiio_tzl.cpp +++ b/toonz/sources/image/tzl/tiio_tzl.cpp @@ -40,7 +40,7 @@ char *reverse(char *buffer, int size) { } return buffer; } -} +} // namespace static int tfwrite(const char *data, const unsigned int count, FILE *f) { return fwrite(data, sizeof(char), count, f); @@ -208,8 +208,8 @@ bool readHeaderAndOffsets(FILE *chan, TzlOffsetMap &frameOffsTable, if (version >= 12) fread(&length, sizeof(TINT32), 1, chan); #if !TNZ_LITTLE_ENDIAN - number = swapTINT32(number); - offs = swapTINT32(offs); + number = swapTINT32(number); + offs = swapTINT32(offs); if (version == 12) length = swapTINT32(length); #endif // std::cout << "#" << i << std::hex << " n 0x" << number @@ -270,16 +270,16 @@ bool readHeaderAndOffsets(FILE *chan, TzlOffsetMap &frameOffsTable, level->setFrame(TFrameId(i), TImageP()); } - res.lx = lx; - res.ly = ly; - if (_offsetTablePos) *_offsetTablePos = offsetTablePos; + res.lx = lx; + res.ly = ly; + if (_offsetTablePos) *_offsetTablePos = offsetTablePos; if (_iconOffsetTablePos) *_iconOffsetTablePos = iconOffsetTablePos; if (_frameCount) *_frameCount = frameCount; return true; } -} +} // namespace static bool adjustIconAspectRatio(TDimension &outDimension, TDimension inDimension, TDimension imageRes) { @@ -295,7 +295,7 @@ static bool adjustIconAspectRatio(TDimension &outDimension, double(ly) / inDimension.ly) iconLx = tround((double(lx) * inDimension.ly) / ly); else - iconLy = tround((double(ly) * inDimension.lx) / lx); + iconLy = tround((double(ly) * inDimension.lx) / lx); outDimension = TDimension(iconLx, iconLy); return true; } @@ -1084,7 +1084,7 @@ void TLevelWriterTzl::renumberFids( frameOffsTableTemp = m_frameOffsTable; TzlOffsetMap::iterator it = frameOffsTableTemp.begin(); while (it != frameOffsTableTemp.end()) { - TFrameId fid = it->first; + TFrameId fid = it->first; std::map::const_iterator it2 = renumberTable.find(fid); if (it2 == renumberTable.end()) remove(fid); it++; @@ -1403,12 +1403,11 @@ bool TLevelWriterTzl::optimize() { void TLevelReaderTzl::readPalette() { TFilePath pltfp = m_path.withNoFrame().withType("tpl"); - TFileStatus fs(pltfp); - TPersist *p = 0; + TPersist *p = 0; TIStream is(pltfp); TPalette *palette = 0; - if (is && fs.doesExist()) { + if (is) { std::string tagName; if (is.matchTag(tagName) && tagName == "palette") { std::string gname; diff --git a/toonz/sources/include/toonzqt/icongenerator.h b/toonz/sources/include/toonzqt/icongenerator.h index 8c366e3..1ca7aa3 100644 --- a/toonz/sources/include/toonzqt/icongenerator.h +++ b/toonz/sources/include/toonzqt/icongenerator.h @@ -140,6 +140,10 @@ public: const TDimension &iconSize, const TFrameId &fid); + // This function is called when only colors of styles are changed in toonz + // raster levels. In such case it doesn't need to re-compute icons but needs + // to let panels to update. See TApp::onLevelColorStyleChanged() for details. + void notifyIconGenerated() { emit iconGenerated(); } signals: void iconGenerated(); diff --git a/toonz/sources/toonz/tapp.cpp b/toonz/sources/toonz/tapp.cpp index d03b861..f5b0bde 100644 --- a/toonz/sources/toonz/tapp.cpp +++ b/toonz/sources/toonz/tapp.cpp @@ -631,10 +631,23 @@ void TApp::onLevelColorStyleSwitched() { static void notifyPaletteChanged(TXshSimpleLevel *simpleLevel) { simpleLevel->onPaletteChanged(); + // palette change can update icons only for ToonzVector / ToonzRaster types + if (simpleLevel->getType() != TZP_XSHLEVEL && + simpleLevel->getType() != PLI_XSHLEVEL) + return; std::vector fids; simpleLevel->getFids(fids); - for (int i = 0; i < (int)fids.size(); i++) - IconGenerator::instance()->invalidate(simpleLevel, fids[i]); + // ToonzRaster level does not need to re-generate icons along with palette + // changes since the icons are cached as color mapped images and the current + // palette is applied just before using it. So here we just emit the signal to + // update related panels. + if (simpleLevel->getType() == TZP_XSHLEVEL) + IconGenerator::instance()->notifyIconGenerated(); + else { // ToonzVecor needs to re-generate icons since it includes colors in + // the cache. + for (int i = 0; i < (int)fids.size(); i++) + IconGenerator::instance()->invalidate(simpleLevel, fids[i]); + } } //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonzlib/imagebuilders.cpp b/toonz/sources/toonzlib/imagebuilders.cpp index 3e25b73..57b972e 100644 --- a/toonz/sources/toonzlib/imagebuilders.cpp +++ b/toonz/sources/toonzlib/imagebuilders.cpp @@ -100,7 +100,10 @@ TImageP ImageLoader::build(int imFlags, void *extData) { (m_path.getType() == "psd")) lr->loadInfo(); - lr->doReadPalette(true); // Allow palette loading + bool isTlvIcon = data->m_icon && m_path.getType() == "tlv"; + + // for TLV icons, palettes will be applied in IconGenerator later + if (!isTlvIcon) lr->doReadPalette(true); // Allow palette loading TImageReaderP ir = lr->getFrameReader(m_fid); @@ -110,7 +113,7 @@ TImageP ImageLoader::build(int imFlags, void *extData) { // Load the image TImageP img; - if (data->m_icon && m_path.getType() == "tlv") + if (isTlvIcon) img = ir->loadIcon(); // TODO: Why just in the tlv case?? else { ir->setShrink(subsampling);