OpenToonz - An open-source full-featured 2D animation creation software
C
Feat(Raster Fill Tool) Add Refer Fill and Gap Close Options
Abel Youb7fa53eb02e2
diff --git a/toonz/sources/common/trop/tropcm.cpp b/toonz/sources/common/trop/tropcm.cppindex a209f54c6..9348ff840 100644--- a/toonz/sources/common/trop/tropcm.cpp+++ b/toonz/sources/common/trop/tropcm.cpp@@ -1481,4 +1481,28 @@ void TRop::makeIcon(TRasterCM32P &_rout, const TRasterCM32P &rin) {rin->unlock();}+void TRop::putRefImage(const TRasterCM32P &Up, const TRaster32P &Ref,+ int style) {+ if (style < 0) style = TPixelCM32::getMaxInk();+ assert(Up->getSize() == Ref->getSize());+ if (Up->getSize() != Ref->getSize()) return;+ int lx = Up->getLx(), ly = Up->getLy();+ for (int y = 0; y < ly; ++y) {+ TPixelCM32 *dstRow = Up->pixels(y);+ TPixel32 *refRow = Ref->pixels(y);+ for (int x = 0; x < lx; ++x) {+ if (refRow[x] != TPixel32(0, 0, 0, 0))+ if (dstRow[x].getTone() == TPixelCM32::getMaxTone()) {+ dstRow[x].setInk(style);+ dstRow[x].setTone(TPixelCM32::getMaxTone() - refRow[x].m);+ }+ }+ }+}++void TRop::eraseRefInks(const TRasterCM32P &r) {+ auto id = new std::vector<int>{TPixelCM32::getMaxInk()};+ TRop::eraseColors(r, id, true, false);+ delete id;+}/*-----------------------------------------------------------------------------*/diff --git a/toonz/sources/include/tools/tool.h b/toonz/sources/include/tools/tool.hindex 7a334905f..67f4dc8e7 100644--- a/toonz/sources/include/tools/tool.h+++ b/toonz/sources/include/tools/tool.h@@ -483,7 +483,8 @@ return true if the method execution can have changed the current tool//! update//! override by vector selection tool//! images on the level view.- void notifyImageChanged(const TFrameId &fid); //!< Notifies changes on the+ void notifyImageChanged(const TFrameId &fid,+ TXshSimpleLevel *sl= nullptr); //!< Notifies changes on the//! frame \p fid; used to update//! images on the level view.diff --git a/toonz/sources/include/tools/tooloptions.h b/toonz/sources/include/tools/tooloptions.hindex 710353df0..2d30c7338 100644--- a/toonz/sources/include/tools/tooloptions.h+++ b/toonz/sources/include/tools/tooloptions.h@@ -516,7 +516,7 @@ class FillToolOptionsBox final : public ToolOptionsBox {QLabel *m_fillDepthLabel;ToolOptionCombo *m_colorMode, *m_toolType;ToolOptionCheckbox *m_selectiveMode, *m_segmentMode, *m_onionMode,- *m_multiFrameMode, *m_autopaintMode;+ *m_multiFrameMode, *m_autopaintMode, *m_closeGap, *m_referFill;ToolOptionPairSlider *m_fillDepthField;public:diff --git a/toonz/sources/include/tools/toolutils.h b/toonz/sources/include/tools/toolutils.hindex 7658c2065..4df92ed4e 100644--- a/toonz/sources/include/tools/toolutils.h+++ b/toonz/sources/include/tools/toolutils.h@@ -89,6 +89,10 @@ void drawCross(const TPointD &q, double pixelSize);//-----------------------------------------------------------------------------+void drawLine(const TPointD &p0, const TPointD p1);++//-----------------------------------------------------------------------------+void drawArrow(const TSegment &s, double pixelSize);//-----------------------------------------------------------------------------diff --git a/toonz/sources/include/toonz/fill.h b/toonz/sources/include/toonz/fill.hindex 06f2b03a9..697f8413f 100644--- a/toonz/sources/include/toonz/fill.h+++ b/toonz/sources/include/toonz/fill.h@@ -3,8 +3,6 @@#ifndef T_FILL_INCLUDED#define T_FILL_INCLUDED-class TPalette;-#undef DVAPI#undef DVVAR#ifdef TOONZLIB_EXPORTS@@ -23,7 +21,8 @@ class TPalette;#include "tpixelcm.h"#include "traster.h"#include "trastercm.h"-#include "tpalette.h"++class TPalette;class FillParameters {public:@@ -71,7 +70,8 @@ class TTileSaverFullColor;// returns true if the savebox is changed typically, if you fill the bg)DVAPI bool fill(const TRasterCM32P &r, const FillParameters ¶ms,- TTileSaverCM32 *saver = 0);+ TTileSaverCM32 *saver = 0,+ const TRaster32P &ref = TRaster32P());DVAPI void fill(const TRaster32P &ras, const TRaster32P &ref,const FillParameters ¶ms, TTileSaverFullColor *saver = 0);@@ -106,13 +106,15 @@ void DVAPI fillHoles(const TRasterCM32P &ras, const int size,class DVAPI AreaFiller {typedef TPixelCM32 Pixel;TRasterCM32P m_ras;+ TRaster32P m_refRas;TRect m_bounds;Pixel *m_pixels;+ TPalette* m_palette;int m_wrap;int m_color;-+public:- AreaFiller(const TRasterCM32P &ras);+ AreaFiller(const TRasterCM32P &ras, const TRaster32P& ref = TRaster32P(), TPalette *palette = nullptr);~AreaFiller();/*!Fill \b rect in raster with \b color.diff --git a/toonz/sources/include/tropcm.h b/toonz/sources/include/tropcm.hindex 0c6bf2101..557cdb15e 100644--- a/toonz/sources/include/tropcm.h+++ b/toonz/sources/include/tropcm.h@@ -94,6 +94,10 @@ DVAPI void makeIcon(TRasterCM32P &rout, const TRasterCM32P &rin);DVAPI void expandPaint(const TRasterCM32P &rasCM);+DVAPI void putRefImage(const TRasterCM32P &Up, const TRaster32P &Ref,+ int style = -1);++DVAPI void eraseRefInks(const TRasterCM32P &r);} // namespace TRop#endifdiff --git a/toonz/sources/tnztools/filltool.cpp b/toonz/sources/tnztools/filltool.cppindex 84ea12311..307d23400 100644--- a/toonz/sources/tnztools/filltool.cpp+++ b/toonz/sources/tnztools/filltool.cpp@@ -22,7 +22,10 @@#include "tenv.h"#include "tools/stylepicker.h"+#include "toonz/tstageobject.h"+#include "toonz/dpiscale.h"#include "toonz/stage2.h"+#include "toonz/stagevisitor.h"#include "tstroke.h"#include "drawutil.h"#include "tsystem.h"@@ -30,6 +33,7 @@#include "tregion.h"#include "tgl.h"#include "trop.h"+#include "tropcm.h"#include "toonz/onionskinmask.h"#include "toonz/ttileset.h"@@ -37,22 +41,27 @@#include "toonz/toonzimageutils.h"#include "toonz/levelproperties.h"+#include "toonz/imagemanager.h"#include "toonz/txshcell.h"#include "toonzqt/imageutils.h"#include "autofill.h"+#include "toonz/fill.h"+#include "toonz/autoclose.h"#include "historytypes.h"#include <stack>+#include <algorithm>+#include <vector>// For Qt translation support#include <QCoreApplication>using namespace ToolUtils;-//#define LINES L"Lines"-//#define AREAS L"Areas"-//#define ALL L"Lines & Areas"+// #define LINES L"Lines"+// #define AREAS L"Areas"+// #define ALL L"Lines & Areas"#define NORMALFILL L"Normal"#define RECTFILL L"Rectangular"@@ -67,9 +76,12 @@ TEnv::StringVar FillColorType("InknpaintFillColorType", "Areas");TEnv::IntVar FillSelective("InknpaintFillSelective", 0);TEnv::IntVar FillOnion("InknpaintFillOnion", 0);TEnv::IntVar FillSegment("InknpaintFillSegment", 0);+TEnv::IntVar FillCloseGap("InknpaintFillCloseGap", 0);+TEnv::IntVar FillReferFill("InknpaintFillReferFill", 0);TEnv::IntVar FillRange("InknpaintFillRange", 0);//-----------------------------------------------------------------------------+namespace {inline int vectorFill(const TVectorImageP &img, const std::wstring &type,@@ -348,6 +360,8 @@ public:class RasterFillUndo final : public TRasterUndo {FillParameters m_params;bool m_saveboxOnly;+ TRect m_savebox;+ TRaster32P m_refImg;public:/*RasterFillUndo(TTileSetCM32 *tileSet, TPoint fillPoint,@@ -360,11 +374,27 @@ public:TXshSimpleLevel* sl,const TFrameId& fid)*/RasterFillUndo(TTileSetCM32 *tileSet, const FillParameters ¶ms,- TXshSimpleLevel *sl, const TFrameId &fid, bool saveboxOnly)+ TXshSimpleLevel *sl, const TFrameId &fid, bool saveboxOnly,+ TRaster32P ref): TRasterUndo(tileSet, sl, fid, false, false, 0), m_params(params)- , m_saveboxOnly(saveboxOnly) {}-+ , m_saveboxOnly(saveboxOnly)+ , m_refImg(ref) {+ if (saveboxOnly) {+ m_savebox = TRect();+ TToonzImageP image = getImage();+ if (!image)+ m_savebox = sl->getProperties()->getImageRes();+ else+ m_savebox = convert(getImage()->getBBox());+ }+ }+ void undo() const override {+ TRasterUndo::undo();+ TToonzImageP image = getImage();+ if (!image) return;+ image->setSavebox(m_savebox);+ }void redo() const override {TToonzImageP image = getImage();if (!image) return;@@ -377,12 +407,7 @@ public:} elser = image->getRaster();if (m_params.m_fillType == ALL || m_params.m_fillType == AREAS) {- if (m_params.m_shiftFill) {- FillParameters aux(m_params);- aux.m_styleId = (m_params.m_styleId == 0) ? 1 : 0;- recomputeSavebox = fill(r, aux);- }- recomputeSavebox = fill(r, m_params);+ recomputeSavebox = fill(r, m_params, 0, m_refImg);}if (m_params.m_fillType == ALL || m_params.m_fillType == LINES) {if (m_params.m_segment)@@ -421,6 +446,7 @@ class RasterRectFillUndo final : public TRasterUndo {std::wstring m_colorType;TStroke *m_s;bool m_onlyUnfilled;+ TRaster32P m_refImg;TPalette *m_palette;public:@@ -431,12 +457,13 @@ public:RasterRectFillUndo(TTileSetCM32 *tileSet, TStroke *s, TRect fillArea,int paintId, TXshSimpleLevel *level,std::wstring colorType, bool onlyUnfilled,- const TFrameId &fid, TPalette *palette)+ const TFrameId &fid, TRaster32P refImg, TPalette *palette): TRasterUndo(tileSet, level, fid, false, false, 0), m_fillArea(fillArea), m_paintId(paintId), m_colorType(colorType), m_onlyUnfilled(onlyUnfilled)+ , m_refImg(refImg), m_palette(palette) {m_s = s ? new TStroke(*s) : 0;}@@ -445,7 +472,7 @@ public:TToonzImageP image = getImage();if (!image) return;TRasterCM32P ras = image->getRaster();- AreaFiller filler(ras);+ AreaFiller filler(ras, m_refImg, m_palette);if (!m_s)filler.rectFill(m_fillArea, m_paintId, m_onlyUnfilled,m_colorType != LINES, m_colorType != AREAS);@@ -805,26 +832,39 @@ bool inline hasAutoInks(const TPalette *plt) {//------------------------------------------------------------------------------void fillAreaWithUndo(const TImageP &img, const TRectD &area, TStroke *stroke,- bool onlyUnfilled, std::wstring colorType,- TXshSimpleLevel *sl, const TFrameId &fid, int cs,- bool autopaintLines) {- TRectD selArea = stroke ? stroke->getBBox() : area;-+void fillAreaWithUndo(const TImageP &img, const TRaster32P &ref,+ const TRectD &area, TStroke *stroke, bool onlyUnfilled,+ std::wstring colorType, TXshSimpleLevel *sl,+ const TFrameId &fid, int cs, bool autopaintLines) {+ TRectD selArea = stroke ? stroke->getBBox().enlarge(1) : area;if (TToonzImageP ti = img) {// allargo di 1 la savebox, perche cosi' il rectfill di tutta l'immagine fa// una sola fillata- TRect enlargedSavebox =- ti->getSavebox().enlarge(1) * TRect(TPoint(0, 0), ti->getSize());- TRect rasterFillArea =- ToonzImageUtils::convertWorldToRaster(selArea, ti) * enlargedSavebox;+ TRect refSavebox = ref ? ref->getBounds() : TRect();+ TRect enlargedSavebox = (ti->getSavebox().enlarge(1) + refSavebox) *+ TRect(TPoint(0, 0), ti->getSize());+ TRect strokeBox = ToonzImageUtils::convertWorldToRaster(selArea, ti);+ TRect rasterFillArea = strokeBox * enlargedSavebox;if (rasterFillArea.isEmpty()) return;TRasterCM32P ras = ti->getRaster();/*-- tileSetでFill範囲のRectをUndoに格納しておく --*/TTileSetCM32 *tileSet = new TTileSetCM32(ras->getSize());tileSet->add(ras, rasterFillArea);- AreaFiller filler(ti->getRaster());++ // Don't use ti to get palette+ TPalette *plt = sl->getPalette();++ // !autopaintLines will temporary disable autopaint line feature+ if ((plt && !hasAutoInks(plt)) || !autopaintLines) plt = 0;++ TRasterCM32P raux = ras;++ if (ref && ti->getSize() != ref->getSize()) {+ TRect saveBox = ti->getSavebox();+ raux = raux->extract(saveBox);+ }+ AreaFiller filler(raux, ref, plt);if (!stroke) {bool ret = filler.rectFill(rasterFillArea, cs, onlyUnfilled,colorType != LINES, colorType != AREAS);@@ -832,32 +872,31 @@ void fillAreaWithUndo(const TImageP &img, const TRectD &area, TStroke *stroke,delete tileSet;return;}- } else+ if (plt) {+ TRect rect = rasterFillArea;+ TRect bounds = ras->getBounds();+ if (bounds.overlaps(rect)) {+ rect *= bounds;+ const TTileSetCM32::Tile *tile =+ tileSet->getTile(tileSet->getTileCount() - 1);+ TRasterCM32P rbefore;+ tile->getRaster(rbefore);+ fillautoInks(ras, rect, rbefore, plt);+ }+ }+ } else {+ if (stroke) stroke->transform(TTranslation(convert(ras->getCenter())));+ if (ref)+ stroke->transform(TTranslation(-convert(ti->getSavebox().getP00())));filler.strokeFill(stroke, cs, onlyUnfilled, colorType != LINES,colorType != AREAS);-- TPalette *plt = ti->getPalette();-- // !autopaintLines will temporary disable autopaint line feature- if ((plt && !hasAutoInks(plt)) || !autopaintLines) plt = 0;-- if (plt) {- TRect rect = rasterFillArea;- TRect bounds = ras->getBounds();- if (bounds.overlaps(rect)) {- rect *= bounds;- const TTileSetCM32::Tile *tile =- tileSet->getTile(tileSet->getTileCount() - 1);- TRasterCM32P rbefore;- tile->getRaster(rbefore);- fillautoInks(ras, rect, rbefore, plt);- }}+ToolUtils::updateSaveBox(sl, fid);TUndoManager::manager()->add(new RasterRectFillUndo(tileSet, stroke, rasterFillArea, cs, sl,- colorType, onlyUnfilled, fid, plt));+ colorType, onlyUnfilled, fid, ref, plt));} else if (TVectorImageP vi = img) {TPalette *palette = vi->getPalette();assert(palette);@@ -893,16 +932,93 @@ void fillAreaWithUndo(const TImageP &img, const TRectD &area, TStroke *stroke,}}+void drawReferImage(TRaster32P &ras, TXsheet *xsh, int col, int row,+ TPointD saveboxoffset) {+ assert(col >= 0);+ TXshColumn *column = xsh->getColumn(col);+ TStageObject *pegbar = xsh->getStageObject(TStageObjectId::ColumnId(col));+ TAffine cAff = pegbar->getPlacement(row);+ TXshCell cell = xsh->getCell(row, col);+ TPointD dpi = cell.getSimpleLevel()->getDpi();+ cAff.a13 *= dpi.x / Stage::inch;+ cAff.a23 *= dpi.y / Stage::inch;+ TRaster32P r32(ras->getSize());++ for (int colIndex = 0; colIndex < xsh->getColumnCount(); ++colIndex) {+ if (colIndex == col) continue;+ TXshColumn *column = xsh->getColumn(colIndex);+ if (!column->isCamstandVisible()) continue;+ TXshCell cell = xsh->getCell(row, colIndex);+ if (cell.isEmpty()) continue;+ TXshSimpleLevel *sl = cell.getSimpleLevel();+ if (!sl) continue;+ TStageObject *pegbar =+ xsh->getStageObject(TStageObjectId::ColumnId(colIndex));+ TAffine aff = pegbar->getPlacement(row);+ TPointD dpi = sl->getDpi();+ // From stageInch to pixel+ aff.a13 *= dpi.x / Stage::inch;+ aff.a23 *= dpi.y / Stage::inch;++ if (sl->getType() & (TZP_XSHLEVEL | OVL_XSHLEVEL)) {+ TImageP img = sl->getFrame(cell.m_frameId, false);+ TToonzImageP ti = img;+ TRasterImageP ri = img;+ TRasterP r;+ if (ti)+ r = ti->getRaster();+ else if (ri)+ r = ri->getRaster();+ if (!r.getPointer()) continue;+ TPointD offset = ras->getCenterD() - r->getCenterD() + saveboxoffset;+ r32->clear();+ if (ri) TRop::quickPut(r32, r, TTranslation(offset));+ if (ti) {+ TRop::CmappedQuickputSettings st;+ st.m_inksOnly = true;+ TRop::quickPut(r32, r, sl->getPalette(), TTranslation(offset), st);+ }+ aff = TTranslation(ras->getCenterD()) * cAff.inv() * aff *+ TTranslation(-ras->getCenterD());+ assert(r32->getSize() == ras->getSize());+ TRop::quickPut(ras, r32, aff);+ } else if (sl->getType() == PLI_XSHLEVEL) {+ // TODO: ToonzVector?+ }+ }+};++void gapClose(TRaster32P &ras, TRasterCM32P &raux, TXshSimpleLevel *sl,+ bool referFill) {+ AutocloseSettings closeStting =+ ToonzCheck::instance()->getAutocloseSettings();+ TRasterCM32P tnzRas = raux->clone();+ if (referFill) TRop::putRefImage(tnzRas, ras, 1);++ std::set<int> autoPaintInks;+ if (closeStting.m_ignoreAPInks) {+ TPalette *plt = sl->getPalette();+ for (int i = 1; i < plt->getStyleCount(); ++i) {+ if (plt->getStyle(i)->getFlags() != 0) autoPaintInks.insert(i);+ }+ }++ TAutocloser ac(tnzRas, 1, closeStting, autoPaintInks);+ ac.exec();+ TRop::CmappedQuickputSettings putSetting;+ putSetting.m_inksOnly = true;+ TRop::quickPut(ras, tnzRas, sl->getPalette(), TAffine(), putSetting);+}+//=============================================================================// doFill//------------------------------------------------------------------------------void doFill(const TImageP &img, const TPointD &pos, FillParameters ¶ms,- bool isShiftFill, TXshSimpleLevel *sl, const TFrameId &fid,- bool autopaintLines) {+void doRefFill(const TImageP &img, const TRaster32P &refImg, const TPointD &pos,+ FillParameters ¶ms, bool isShiftFill, TXshSimpleLevel *sl,+ const TFrameId &fid, bool autopaintLines) {TTool::Application *app = TTool::getApplication();if (!app) return;-if (TToonzImageP ti = TToonzImageP(img)) {TPoint offs(0, 0);TRasterCM32P ras = ti->getRaster();@@ -942,14 +1058,9 @@ void doFill(const TImageP &img, const TPointD &pos, FillParameters ¶ms,// !autoPaintLines will temporary disable autopaint line featureif (plt && hasAutoInks(plt) && autopaintLines) params.m_palette = plt;-+ TRaster32P refRas;if (params.m_fillType == ALL || params.m_fillType == AREAS) {- if (isShiftFill) {- FillParameters aux(params);- aux.m_styleId = (params.m_styleId == 0) ? 1 : 0;- recomputeSavebox = fill(ras, aux, &tileSaver);- }- recomputeSavebox = fill(ras, params, &tileSaver);+ recomputeSavebox = fill(ras, params, &tileSaver, refImg);}if (params.m_fillType == ALL || params.m_fillType == LINES) {if (params.m_segment)@@ -966,9 +1077,9 @@ void doFill(const TImageP &img, const TPointD &pos, FillParameters ¶ms,TTileSet::Tile *t = tileSet->editTile(i);t->m_rasterBounds = t->m_rasterBounds + offs;}- TUndoManager::manager()->add(- new RasterFillUndo(tileSet, params, sl, fid,- Preferences::instance()->getFillOnlySavebox()));+ TUndoManager::manager()->add(new RasterFillUndo(+ tileSet, params, sl, fid,+ Preferences::instance()->getFillOnlySavebox(), std::move(refRas)));}// al posto di updateFrame:@@ -999,6 +1110,12 @@ vi->computeRegion(pos, params.m_styleId);*/if (t) t->notifyImageChanged();}+void doFill(const TImageP &img, const TPointD &pos, FillParameters ¶ms,+ bool isShiftFill, TXshSimpleLevel *sl, const TFrameId &fid,+ bool autopaintLines) {+ doRefFill(img, TRaster32P(), pos, params, isShiftFill, sl, fid,+ autopaintLines);+}//=============================================================================// SequencePainter// da spostare in toolutils?@@ -1008,53 +1125,26 @@ class SequencePainter {public:virtual void process(TImageP img /*, TImageLocation &imgloc*/, double t,TXshSimpleLevel *sl, const TFrameId &fid) = 0;- void processSequence(TXshSimpleLevel *sl, TFrameId firstFid,- TFrameId lastFid);+ void processSequence(const SlFidsPairs &SlFidsPairs);virtual ~SequencePainter() {}};//------------------------------------------------------------------------------void SequencePainter::processSequence(TXshSimpleLevel *sl, TFrameId firstFid,- TFrameId lastFid) {- if (!sl) return;-- bool backward = false;- if (firstFid > lastFid) {- std::swap(firstFid, lastFid);- backward = true;- }- assert(firstFid <= lastFid);- std::vector<TFrameId> allFids;- sl->getFids(allFids);-- std::vector<TFrameId>::iterator i0 = allFids.begin();- while (i0 != allFids.end() && *i0 < firstFid) i0++;- if (i0 == allFids.end()) return;- std::vector<TFrameId>::iterator i1 = i0;- while (i1 != allFids.end() && *i1 <= lastFid) i1++;- assert(i0 < i1);- std::vector<TFrameId> fids(i0, i1);- int m = fids.size();- assert(m > 0);-+void SequencePainter::processSequence(const SlFidsPairs &slFidsPairs) {TUndoManager::manager()->beginBlock();- for (int i = 0; i < m; ++i) {- TFrameId fid = fids[i];- assert(firstFid <= fid && fid <= lastFid);+ int m = slFidsPairs.size();+ int i = 0;+ for (auto &[sl, fid] : slFidsPairs) {TImageP img = sl->getFrame(fid, true);double t = m > 1 ? (double)i / (double)(m - 1) : 0.5;- process(img, backward ? 1 - t : t, sl, fid);- // Setto il fid come corrente per notificare il cambiamento dell'immagine+ process(img, t, sl, fid);TTool::Application *app = TTool::getApplication();if (app) {- if (app->getCurrentFrame()->isEditingScene())- app->getCurrentFrame()->setFrame(fid.getNumber());- else- app->getCurrentFrame()->setFid(fid);TTool *tool = app->getCurrentTool()->getTool();- if (tool) tool->notifyImageChanged(fid);+ if (tool) tool->notifyImageChanged(fid, sl);}+ ++i;}TUndoManager::manager()->endBlock();}@@ -1070,11 +1160,12 @@ class MultiAreaFiller final : public SequencePainter {TVectorImageP m_firstImage, m_lastImage;int m_styleIndex;bool m_autopaintLines;+ RefImgTable m_refImgTable;public:- MultiAreaFiller(const TRectD &firstRect, const TRectD &lastRect,- bool unfilledOnly, std::wstring colorType, int styleIndex,- bool autopaintLines)+ MultiAreaFiller(RefImgTable refImgTable, const TRectD &firstRect,+ const TRectD &lastRect, bool unfilledOnly,+ std::wstring colorType, int styleIndex, bool autopaintLines): m_firstRect(firstRect), m_lastRect(lastRect), m_unfilledOnly(unfilledOnly)@@ -1082,24 +1173,26 @@ public:, m_firstImage(), m_lastImage(), m_styleIndex(styleIndex)- , m_autopaintLines(autopaintLines) {}+ , m_autopaintLines(autopaintLines)+ , m_refImgTable(std::move(refImgTable)) {}~MultiAreaFiller() {- if (m_firstImage) {- m_firstImage->removeStroke(0);- m_lastImage->removeStroke(0);- }+ if (m_firstImage) m_firstImage->removeStroke(0)->release();+ if (m_lastImage) m_lastImage->removeStroke(0)->release();}- MultiAreaFiller(TStroke *&firstStroke, TStroke *&lastStroke,- bool unfilledOnly, std::wstring colorType, int styleIndex,- bool autopaintLines)+ MultiAreaFiller(RefImgTable &refImgTable, TStroke *&firstStroke,+ TStroke *&lastStroke, bool unfilledOnly,+ std::wstring colorType, int styleIndex, bool autopaintLines): m_firstRect(), m_lastRect(), m_unfilledOnly(unfilledOnly), m_colorType(colorType), m_styleIndex(styleIndex)- , m_autopaintLines(autopaintLines) {+ , m_autopaintLines(autopaintLines)+ , m_refImgTable(std::move(refImgTable)) {+ firstStroke->addRef();+ lastStroke->addRef();m_firstImage = new TVectorImage();m_lastImage = new TVectorImage();m_firstImage->addStroke(firstStroke);@@ -1108,21 +1201,22 @@ public:void process(TImageP img, double t, TXshSimpleLevel *sl,const TFrameId &fid) override {+ std::string imgId = sl->getImageId(fid, 0);if (!m_firstImage) {TPointD p0 = m_firstRect.getP00() * (1 - t) + m_lastRect.getP00() * t;TPointD p1 = m_firstRect.getP11() * (1 - t) + m_lastRect.getP11() * t;TRectD rect(p0.x, p0.y, p1.x, p1.y);- fillAreaWithUndo(img, rect, 0, m_unfilledOnly, m_colorType, sl, fid,- m_styleIndex, m_autopaintLines);+ fillAreaWithUndo(img, m_refImgTable[imgId], rect, 0, m_unfilledOnly,+ m_colorType, sl, fid, m_styleIndex, m_autopaintLines);} else {if (t == 0)- fillAreaWithUndo(img, TRectD(), m_firstImage->getStroke(0),- m_unfilledOnly, m_colorType, sl, fid, m_styleIndex,- m_autopaintLines);+ fillAreaWithUndo(img, m_refImgTable[imgId], TRectD(),+ m_firstImage->getStroke(0), m_unfilledOnly,+ m_colorType, sl, fid, m_styleIndex, m_autopaintLines);else if (t == 1)- fillAreaWithUndo(img, TRectD(), m_lastImage->getStroke(0),- m_unfilledOnly, m_colorType, sl, fid, m_styleIndex,- m_autopaintLines);+ fillAreaWithUndo(img, m_refImgTable[imgId], TRectD(),+ m_lastImage->getStroke(0), m_unfilledOnly, m_colorType,+ sl, fid, m_styleIndex, m_autopaintLines);else// if(t>1){@@ -1134,9 +1228,9 @@ public:assert(vi->getStrokeCount() == 1);- fillAreaWithUndo(img, TRectD(), vi->getStroke(0) /*, imgloc*/,- m_unfilledOnly, m_colorType, sl, fid, m_styleIndex,- m_autopaintLines);+ fillAreaWithUndo(img, m_refImgTable[imgId], TRectD(),+ vi->getStroke(0) /*, imgloc*/, m_unfilledOnly,+ m_colorType, sl, fid, m_styleIndex, m_autopaintLines);}}}@@ -1150,6 +1244,7 @@ class MultiFiller final : public SequencePainter {TPointD m_firstPoint, m_lastPoint;FillParameters m_params;bool m_autopaintLines;+ RefImgTable m_refImgTable;public:MultiFiller(const TPointD &firstPoint, const TPointD &lastPoint,@@ -1158,10 +1253,22 @@ public:, m_lastPoint(lastPoint), m_params(params), m_autopaintLines(autopaintLines) {}+ MultiFiller(const RefImgTable &refImgTable, const TPointD &firstPoint,+ const TPointD &lastPoint, const FillParameters ¶ms,+ bool autopaintLines)+ : m_refImgTable(refImgTable)+ , m_firstPoint(firstPoint)+ , m_lastPoint(lastPoint)+ , m_params(params)+ , m_autopaintLines(autopaintLines) {}void process(TImageP img, double t, TXshSimpleLevel *sl,const TFrameId &fid) override {TPointD p = m_firstPoint * (1 - t) + m_lastPoint * t;- doFill(img, p, m_params, false, sl, fid, m_autopaintLines);+ if (m_refImgTable.empty())+ doFill(img, p, m_params, false, sl, fid, m_autopaintLines);+ else+ doRefFill(img, m_refImgTable[sl->getImageId(fid, 0)], p, m_params, false,+ sl, fid, m_autopaintLines);}};@@ -1175,7 +1282,7 @@ TApplication::instance()->getCurrentFrameId();}else{- m_firstClick = false;+ m_firstFrameSelected = false;TApplication::instance()->setCurrentFrame(m_veryFirstFrameId);}TNotifier::instance()->notify(TLevelChange());@@ -1292,7 +1399,7 @@ void AreaFillTool::resetMulti() {m_level = xl ? xl->getSimpleLevel() : 0;m_firstFrameId = m_veryFirstFrameId = m_parent->getCurrentFid();if (m_firstStroke) {- delete m_firstStroke;+ if (m_firstStroke->getRefCount()) m_firstStroke->release();m_firstStroke = 0;}}@@ -1356,7 +1463,9 @@ void AreaFillTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e,void AreaFillTool::leftButtonDoubleClick(const TPointD &pos,const TMouseEvent &e) {TStroke *stroke;-+ FillTool *fillTool = (FillTool *)m_parent;+ auto refImgTable = fillTool->getRefImgTable();+ auto slFidsPairs = fillTool->getSlFidsPairs();TTool::Application *app = TTool::getApplication();if (!app) return;@@ -1387,10 +1496,10 @@ void AreaFillTool::leftButtonDoubleClick(const TPointD &pos,if (m_frameRange) // stroke multi{if (m_firstFrameSelected) {- MultiAreaFiller filler(m_firstStroke, stroke, m_onlyUnfilled, m_colorType,- styleIndex, m_autopaintLines);- filler.processSequence(m_level.getPointer(), m_firstFrameId,- m_parent->getCurrentFid());+ MultiAreaFiller filler(refImgTable, m_firstStroke, stroke, m_onlyUnfilled,+ m_colorType, styleIndex, m_autopaintLines);+ filler.processSequence(slFidsPairs);+m_parent->invalidate(m_selectingRect.enlarge(2));if (e.isShiftPressed()) {m_firstStroke = stroke;@@ -1405,21 +1514,24 @@ void AreaFillTool::leftButtonDoubleClick(const TPointD &pos,}} else // primo frame{- m_firstStroke = stroke;+ m_firstFrameSelected = true;+ m_firstStroke = stroke;// if (app->getCurrentFrame()->isEditingScene())m_currCell =std::pair<int, int>(app->getCurrentColumn()->getColumnIndex(),app->getCurrentFrame()->getFrame());}} else {+ std::string imgId = m_level->getImageId(m_parent->getCurrentFid(), 0);if (m_onion) {OnionSkinMask osMask = app->getCurrentOnionSkin()->getOnionSkinMask();doStrokeAutofill(m_parent->getImage(true), stroke, m_onlyUnfilled, osMask,m_level.getPointer(), m_parent->getCurrentFid());} else- fillAreaWithUndo(m_parent->getImage(true), TRectD(), stroke,- m_onlyUnfilled, m_colorType, m_level.getPointer(),- m_parent->getCurrentFid(), styleIndex, m_autopaintLines);+ fillAreaWithUndo(m_parent->getImage(true), refImgTable[imgId], TRectD(),+ stroke, m_onlyUnfilled, m_colorType,+ m_level.getPointer(), m_parent->getCurrentFid(),+ styleIndex, m_autopaintLines);TTool *t = app->getCurrentTool()->getTool();if (t) t->notifyImageChanged();}@@ -1449,8 +1561,11 @@ void AreaFillTool::mouseMove(const TPointD &pos, const TMouseEvent &e) {void AreaFillTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e) {if (!m_isLeftButtonPressed) return;- m_isLeftButtonPressed = false;-+ m_isLeftButtonPressed = false;+ FillTool *fillTool = dynamic_cast<FillTool *>(m_parent);+ bool get = !m_frameRange || m_firstFrameSelected;+ auto refImgTable = get ? fillTool->getRefImgTable() : RefImgTable();+ auto slFidsPairs = get ? fillTool->getSlFidsPairs() : SlFidsPairs();TTool::Application *app = TTool::getApplication();if (!app) return;@@ -1467,10 +1582,10 @@ void AreaFillTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e) {if (m_frameRange) {if (m_firstFrameSelected) {- MultiAreaFiller filler(m_firstRect, m_selectingRect, m_onlyUnfilled,- m_colorType, styleIndex, m_autopaintLines);- filler.processSequence(m_level.getPointer(), m_firstFrameId,- m_parent->getCurrentFid());+ MultiAreaFiller filler(refImgTable, m_firstRect, m_selectingRect,+ m_onlyUnfilled, m_colorType, styleIndex,+ m_autopaintLines);+ filler.processSequence(slFidsPairs);m_parent->invalidate(m_selectingRect.enlarge(2));if (e.isShiftPressed()) {m_firstRect = m_selectingRect;@@ -1484,26 +1599,29 @@ void AreaFillTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e) {resetMulti();}} else {- // if (app->getCurrentFrame()->isEditingScene())+ m_firstFrameSelected = true;+ assert(!m_selectingRect.isEmpty());+ m_firstRect = m_selectingRect;m_currCell =std::pair<int, int>(app->getCurrentColumn()->getColumnIndex(),app->getCurrentFrame()->getFrame());}- } else {+ } else { // Process current Frame+ std::string imgId = m_level->getImageId(m_parent->getCurrentFid(), 0);if (m_onion) {OnionSkinMask osMask = app->getCurrentOnionSkin()->getOnionSkinMask();doRectAutofill(m_parent->getImage(true), m_selectingRect,m_onlyUnfilled, osMask, m_level.getPointer(),- m_parent->getCurrentFid());+ m_parent->getCurrentFid()); // Do not support ReferImg} else- fillAreaWithUndo(m_parent->getImage(true), m_selectingRect, 0,- m_onlyUnfilled, m_colorType, m_level.getPointer(),- m_parent->getCurrentFid(), styleIndex,- m_autopaintLines);+ fillAreaWithUndo(m_parent->getImage(true), refImgTable[imgId],+ m_selectingRect, 0, m_onlyUnfilled, m_colorType,+ m_level.getPointer(), m_parent->getCurrentFid(),+ styleIndex, m_autopaintLines);m_parent->invalidate();m_selectingRect.empty();TTool *t = app->getCurrentTool()->getTool();- if (t) t->notifyImageChanged();+ if (t) m_parent->notifyImageChanged();}} else if (m_type == FREEHAND || m_type == FREEPICK) {#if defined(MACOSX)@@ -1524,26 +1642,30 @@ void AreaFillTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e) {if (m_frameRange) // stroke multi{+ stroke->addRef();if (m_firstFrameSelected) {- MultiAreaFiller filler(m_firstStroke, stroke, m_onlyUnfilled,- m_colorType, styleIndex, m_autopaintLines);- filler.processSequence(m_level.getPointer(), m_firstFrameId,- m_parent->getCurrentFid());+ MultiAreaFiller filler(refImgTable, m_firstStroke, stroke,+ m_onlyUnfilled, m_colorType, styleIndex,+ m_autopaintLines);+ filler.processSequence(slFidsPairs);m_parent->invalidate(m_selectingRect.enlarge(2));if (e.isShiftPressed()) {m_firstStroke = stroke;m_firstFrameId = m_parent->getCurrentFid();} else {- if (app->getCurrentFrame()->isEditingScene()) {+ if (app->getCurrentFrame()->isEditingLevel())+ app->getCurrentFrame()->setFid(m_veryFirstFrameId);+ else {app->getCurrentColumn()->setColumnIndex(m_currCell.first);app->getCurrentFrame()->setFrame(m_currCell.second);- } else- app->getCurrentFrame()->setFid(m_veryFirstFrameId);+ }resetMulti();}} else // primo frame{- m_firstStroke = stroke;+ m_firstFrameSelected = true;+ m_firstRect = m_selectingRect;+ m_firstStroke = stroke;// if (app->getCurrentFrame()->isEditingScene())m_currCell =std::pair<int, int>(app->getCurrentColumn()->getColumnIndex(),@@ -1552,6 +1674,7 @@ void AreaFillTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e) {} else // stroke non multi{+ std::string imgId = m_level->getImageId(m_parent->getCurrentFid(), 0);if (!m_parent->getImage(true)) return;if (m_onion) {OnionSkinMask osMask = app->getCurrentOnionSkin()->getOnionSkinMask();@@ -1559,10 +1682,11 @@ void AreaFillTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e) {osMask, m_level.getPointer(),m_parent->getCurrentFid());} else- fillAreaWithUndo(- m_parent->getImage(true), TRectD(), stroke /*, imageLocation*/,- m_onlyUnfilled, m_colorType, m_level.getPointer(),- m_parent->getCurrentFid(), styleIndex, m_autopaintLines);+ fillAreaWithUndo(m_parent->getImage(true), refImgTable[imgId], TRectD(),+ stroke /*, imageLocation*/, m_onlyUnfilled,+ m_colorType, m_level.getPointer(),+ m_parent->getCurrentFid(), styleIndex,+ m_autopaintLines);delete stroke;TTool *t = app->getCurrentTool()->getTool();if (t) t->notifyImageChanged();@@ -1582,17 +1706,6 @@ void AreaFillTool::onImageChanged() {if (!xshl || m_level.getPointer() != xshl ||(m_selectingRect.isEmpty() && !m_firstStroke))resetMulti();- else if (m_firstFrameId == m_parent->getCurrentFid())- m_firstFrameSelected = false; // nel caso sono passato allo stato 1 e- // torno all'immagine iniziale, torno allo- // stato iniziale- else { // cambio stato.- m_firstFrameSelected = true;- if (m_type != FREEHAND && m_type != POLYLINE && m_type != FREEPICK) {- assert(!m_selectingRect.isEmpty());- m_firstRect = m_selectingRect;- }- }}/*--Normal以外のTypeが選択された場合に呼ばれる--*/@@ -1693,9 +1806,9 @@ public:double k = dy / dx; /*-- 直線の傾き --*//*--- roundでは負値のときにうまく繋がらない ---*/int start = std::min((int)floor(m_startPosition.x + 0.5),- (int)floor(m_mousePosition.x + 0.5));+ (int)floor(m_mousePosition.x + 0.5));int end = std::max((int)floor(m_startPosition.x + 0.5),- (int)floor(m_mousePosition.x + 0.5));+ (int)floor(m_mousePosition.x + 0.5));double start_x = (m_startPosition.x < m_mousePosition.x)? m_startPosition.x: m_mousePosition.x;@@ -1718,9 +1831,9 @@ public:double k = dx / dy; /*-- 直線の傾き --*//*--- roundでは負値のときにうまく繋がらない ---*/int start = std::min((int)floor(m_startPosition.y + 0.5),- (int)floor(m_mousePosition.y + 0.5));+ (int)floor(m_mousePosition.y + 0.5));int end = std::max((int)floor(m_startPosition.y + 0.5),- (int)floor(m_mousePosition.y + 0.5));+ (int)floor(m_mousePosition.y + 0.5));double start_x = (m_startPosition.y < m_mousePosition.y)? m_startPosition.x: m_mousePosition.x;@@ -1770,12 +1883,14 @@ FillTool::FillTool(int targetType), m_onion("Onion Skin", false), m_fillDepth("Fill Depth", 0, 15, 0, 15), m_segment("Segment", false)+ , m_closeGap("Close Gap", false), m_onionStyleId(0)- , m_currCell(-1, -1)+ , m_beginCell{-1, -1}, m_maxGapDistance("Maximum Gap", 0.01, 10.0, 1.15), m_firstTime(true)- , m_autopaintLines("Autopaint Lines", true) {- m_rectFill = new AreaFillTool(this);+ , m_autopaintLines("Autopaint Lines", true)+ , m_referFill("Refer Fill", false) {+ m_areaFillTool = new AreaFillTool(this);m_normalLineFillTool = new NormalLineFillTool(this);bind(targetType);@@ -1795,6 +1910,8 @@ FillTool::FillTool(int targetType)if (targetType == TTool::ToonzImage) {m_prop.bind(m_fillDepth);m_prop.bind(m_segment);+ m_prop.bind(m_closeGap);+ m_prop.bind(m_referFill);}m_prop.bind(m_onion);m_prop.bind(m_frameRange);@@ -1807,6 +1924,8 @@ FillTool::FillTool(int targetType)m_onion.setId("OnionSkin");m_frameRange.setId("FrameRange");m_segment.setId("SegmentInk");+ m_closeGap.setId("CloseGaps");+ m_referFill.setId("ReferFill");m_fillType.setId("Type");m_colorType.setId("Mode");m_autopaintLines.setId("AutopaintLines");@@ -1837,6 +1956,118 @@ int FillTool::getCursorId() const {return ret;}+void FillTool::buildFillInfo(const FillParameters ¶ms) {+ auto app = getApplication();+ if (!m_firstFrameSelected) {+ if (m_fillType.getValue() != NORMALFILL) m_firstFrameSelected = true;++ TXshLevel *xl = app->getCurrentLevel()->getLevel();+ m_level = xl ? xl->getSimpleLevel() : 0;+ m_beginCell.col = getColumnIndex();+ m_beginCell.row = getFrame();+ m_firstFrameId = m_veryFirstFrameId = getCurrentFid();+ m_firstPoint = m_mousePos;+ invalidate();+ if (m_frameRange.getValue()) return;+ }++ m_slFidsPairs.clear();++ // Multi+ if (m_frameRange.getValue()) {+ if (app->getCurrentFrame()->isEditingScene()) {+ int endRow = getFrame();+ auto xsh = app->getCurrentXsheet()->getXsheet();+ TXshCell cell, oldCell;+ int step = m_beginCell.row <= endRow ? +1 : -1;+ for (int row = m_beginCell.row; row != endRow + step; row += step) {+ cell = xsh->getCell(row, m_beginCell.col);+ if (!cell.isEmpty() && cell != oldCell) {+ if (std::find(+ m_slFidsPairs.begin(), m_slFidsPairs.end(),+ std::make_pair(cell.getSimpleLevel(), cell.getFrameId())) ==+ m_slFidsPairs.end())+ m_slFidsPairs.push_back({cell.getSimpleLevel(), cell.getFrameId()});+ oldCell = cell;+ }+ }+ } else {+ TXshSimpleLevel *sl = app->getCurrentLevel()->getSimpleLevel();+ int e = sl->fid2index(getCurrentFid());+ int i = sl->fid2index(m_firstFrameId);+ int step = i <= e ? +1 : -1;+ for (; i != e + step; i += step)+ m_slFidsPairs.push_back({sl, sl->getFrameId(i)});+ }+ computeRefImgsIfNeeded(params);+ if (m_fillType.getValue() != NORMALFILL) resetMulti();+ }+ // Not Multi+ else {+ m_firstFrameSelected = false;+ TXshSimpleLevel *sl = app->getCurrentLevel()->getSimpleLevel();+ auto fid = getCurrentFid();+ m_slFidsPairs.push_back({sl, fid});+ computeRefImgsIfNeeded(params);+ }+ assert(!m_slFidsPairs.empty());+}++void FillTool::computeRefImgsIfNeeded(const FillParameters ¶ms) {+ assert(!m_slFidsPairs.empty());+ m_refImgTable.clear();+ if (params.m_fillType == LINES) return;+ auto app = getApplication();+ bool referFill =+ m_referFill.getValue() && app->getCurrentFrame()->isEditingScene();+ bool closeGap = m_closeGap.getValue();+ if (!closeGap && !referFill) return;++ auto xsh = app->getCurrentXsheet()->getXsheet();++ // Build map if need to generate refer Image from xsh+ std::map<std::pair<TXshSimpleLevel *, TFrameId>, int> slFidToRow;+ if (referFill) {+ int dx = m_beginCell.row < getFrame() ? +1 : -1;+ for (int i = m_beginCell.row; i != getFrame() + dx; i += dx) {+ TXshCell cell = xsh->getCell(i, m_beginCell.col);+ if (auto sl = cell.getSimpleLevel())+ slFidToRow[std::make_pair(sl, cell.getFrameId())] = i;+ }+ }++ // Caculate every refImg+ bool fillOnlySavebox = Preferences::instance()->getFillOnlySavebox();+ for (auto [sl, fid] : m_slFidsPairs) {+ if (sl->getType() != TXshLevelType::TZP_XSHLEVEL) continue;++ auto img = sl->getFrame(fid, false);+ TToonzImageP ti = (TToonzImageP)img;+ if (!ti) continue;++ auto raux = ti->getRaster();+ auto imgId = sl->getImageId(fid, 0);+ TPointD saveboxOffset = TPointD(0, 0);+ if (fillOnlySavebox) {+ TRectD bbox = ti->getBBox();+ TRect ibbox = convert(bbox);+ TDimension res = ti->getSize();+ saveboxOffset = TPointD(res.lx / 2, res.ly / 2) - bbox.getP11() / 2 -+ bbox.getP00() / 2;+ raux = ti->getRaster()->extract(ibbox);+ }+ TRaster32P ras(raux->getSize());+ ras->clear();++ m_refImgTable[imgId] = ras;++ if (referFill)+ drawReferImage(ras, xsh, m_beginCell.col, slFidToRow[{sl, fid}],+ saveboxOffset);+ if (closeGap) gapClose(ras, raux, sl, referFill);+ }+}+//-----------------------------------------------------------------------------void FillTool::updateTranslation() {@@ -1859,6 +2090,8 @@ void FillTool::updateTranslation() {m_onion.setQStringName(tr("Onion Skin"));m_fillDepth.setQStringName(tr("Fill Depth"));m_segment.setQStringName(tr("Segment"));+ m_closeGap.setQStringName(tr("Close Gap"));+ m_referFill.setQStringName(tr("Refer Fill"));m_maxGapDistance.setQStringName(tr("Maximum Gap"));m_autopaintLines.setQStringName(tr("Autopaint Lines"));}@@ -1870,9 +2103,10 @@ FillParameters FillTool::getFillParameters() const {int styleId = TTool::getApplication()->getCurrentLevelStyleIndex();params.m_styleId = styleId;/*---紛らわしいことに、colorTypeをfillTypeに名前を変えて保存している。間違いではない。---*/- params.m_fillType = m_colorType.getValue();- params.m_emptyOnly = m_selective.getValue();- params.m_segment = m_segment.getValue();+ params.m_fillType = m_colorType.getValue();+ params.m_emptyOnly = m_selective.getValue();+ params.m_segment = m_segment.getValue();+ // RefFill is not controlled paramsparams.m_minFillDepth = (int)m_fillDepth.getValue().first;params.m_maxFillDepth = (int)m_fillDepth.getValue().second;return params;@@ -1881,69 +2115,63 @@ FillParameters FillTool::getFillParameters() const {//-----------------------------------------------------------------------------void FillTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e) {- TTool::Application *app = TTool::getApplication();- if (!app) return;-m_clickPoint = pos;+ // Area modeif (m_fillType.getValue() != NORMALFILL) {- m_rectFill->leftButtonDown(pos, e, getImage(true));+ m_areaFillTool->leftButtonDown(pos, e, getImage(true));+ return;+ }+ // Line mode+ if (m_colorType.getValue() == LINES && m_targetType == TTool::ToonzImage) {+ m_normalLineFillTool->leftButtonDown(pos, e);return;}+/*--以下、NormalFillの場合--*/+ TTool::Application *app = TTool::getApplication();+ if (!app) return;FillParameters params = getFillParameters();-- if (m_onion.getValue()) {+ if (m_onion.getValue() &&+ app->getCurrentOnionSkin()->getOnionSkinMask().isEnabled() &&+ !app->getCurrentOnionSkin()->getOnionSkinMask().isEmpty()) {m_onionStyleId = pickOnionColor(pos);if (m_onionStyleId > 0) app->setCurrentLevelStyleIndex(m_onionStyleId);- } else if (m_frameRange.getValue()) {- if (!m_firstClick) {- // PRIMO CLICK- // if (app->getCurrentFrame()->isEditingScene())- m_currCell = std::pair<int, int>(getColumnIndex(), getFrame());-- m_firstClick = true;+ return;+ }+ buildFillInfo(params);+ if (!m_frameRange.getValue()) {+ auto fid = getCurrentFid();+ TRaster32P Ref =+ m_level ? m_refImgTable[m_level->getImageId(fid, 0)] : TRaster32P();+ doRefFill(getImage(true), Ref, pos, params, e.isShiftPressed(),+ m_level.getPointer(), fid, m_autopaintLines.getValue());+ invalidate();+ } else if (!m_firstFrameSelected)+ m_firstFrameSelected = true;+ else { // Multi+ // When using tablet on windows, the mouse press event may be called AFTER+ // tablet release. It causes unwanted another "first click" just after+ // frame-range-filling. Calling processEvents() here to make sure to+ // consume the mouse press event in advance.+ qApp->processEvents();+ // SECONDO CLICK+ MultiFiller filler(m_refImgTable, m_firstPoint, pos, params,+ m_autopaintLines.getValue());+ filler.processSequence(m_slFidsPairs);++ if (e.isShiftPressed()) {m_firstPoint = pos;- m_firstFrameId = m_veryFirstFrameId = getCurrentFid();- // gmt. NON BISOGNA DISEGNARE DENTRO LE CALLBACKS!!!!- // drawCross(m_firstPoint, 6);- invalidate();+ m_firstFrameId = getCurrentFid();} else {- // When using tablet on windows, the mouse press event may be called AFTER- // tablet release. It causes unwanted another "first click" just after- // frame-range-filling. Calling processEvents() here to make sure to- // consume the mouse press event in advance.- qApp->processEvents();- // SECONDO CLICK- TFrameId fid = getCurrentFid();- MultiFiller filler(m_firstPoint, pos, params,- m_autopaintLines.getValue());- filler.processSequence(m_level.getPointer(), m_firstFrameId, fid);- if (e.isShiftPressed()) {- m_firstPoint = pos;- m_firstFrameId = getCurrentFid();- } else {- m_firstClick = false;- if (app->getCurrentFrame()->isEditingScene()) {- app->getCurrentColumn()->setColumnIndex(m_currCell.first);- app->getCurrentFrame()->setFrame(m_currCell.second);- } else- app->getCurrentFrame()->setFid(m_veryFirstFrameId);- }- TTool *t = app->getCurrentTool()->getTool();- if (t) t->notifyImageChanged();- }-- } else {- if (params.m_fillType == LINES && m_targetType == TTool::ToonzImage)- m_normalLineFillTool->leftButtonDown(pos, e);- else {- TXshLevel *xl = app->getCurrentLevel()->getLevel();- m_level = xl ? xl->getSimpleLevel() : 0;- doFill(getImage(true), pos, params, e.isShiftPressed(),- m_level.getPointer(), getCurrentFid(),- m_autopaintLines.getValue());- invalidate();+ if (app->getCurrentFrame()->isEditingScene()) {+ app->getCurrentColumn()->setColumnIndex(m_beginCell.col);+ app->getCurrentFrame()->setFrame(m_beginCell.row);+ } else+ app->getCurrentFrame()->setFid(m_veryFirstFrameId);+ resetMulti();}+ TTool *t = app->getCurrentTool()->getTool();+ if (t) t->notifyImageChanged();}}@@ -1951,7 +2179,8 @@ void FillTool::leftButtonDown(const TPointD &pos, const TMouseEvent &e) {void FillTool::leftButtonDoubleClick(const TPointD &pos, const TMouseEvent &e) {if (m_fillType.getValue() != NORMALFILL) {- m_rectFill->leftButtonDoubleClick(pos, e);+ buildFillInfo(getFillParameters());+ m_areaFillTool->leftButtonDoubleClick(pos, e);return;}}@@ -1959,22 +2188,30 @@ void FillTool::leftButtonDoubleClick(const TPointD &pos, const TMouseEvent &e) {//-----------------------------------------------------------------------------void FillTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {- if ((m_fillType.getValue() != NORMALFILL && !m_onion.getValue()) ||- (m_colorType.getValue() == AREAS && m_onion.getValue()))- m_rectFill->leftButtonDrag(pos, e);- else if (!m_onion.getValue() && !m_frameRange.getValue()) {+ // Area mode+ if (m_fillType.getValue() != NORMALFILL) {+ m_areaFillTool->leftButtonDrag(pos, e);+ return;+ }+ // Line mode+ if ((m_colorType.getValue() == LINES) && m_targetType == TTool::ToonzImage) {+ m_normalLineFillTool->leftButtonDrag(pos, e);+ return;+ }++ // Drag to Fill+ if (!m_onion.getValue() && !m_frameRange.getValue()) {FillParameters params = getFillParameters();- if (params.m_fillType == LINES && m_targetType == TTool::ToonzImage) {- m_normalLineFillTool->leftButtonDrag(pos, e);- return;- }if (m_clickPoint == pos) return;TImageP img = getImage(true);int styleId = params.m_styleId;if (TVectorImageP vi = img) {TRegion *r = vi->getRegion(pos);if (r && r->getStyle() == styleId) return;- } else if (TToonzImageP ti = img) {+ doFill(img, pos, params, e.isShiftPressed(), m_level.getPointer(),+ getCurrentFid(), m_autopaintLines.getValue());+ }+ if (TToonzImageP ti = img) {TRasterCM32P ras = ti->getRaster();if (!ras) return;TPointD center = ras->getCenterD();@@ -1985,59 +2222,61 @@ void FillTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {invalidate();return;}+ std::string imgId =+ m_application ? m_level.getPointer()->getImageId(getCurrentFid(), 0)+ : "";+ doRefFill(img, m_refImgTable[imgId], pos, params, e.isShiftPressed(),+ m_level.getPointer(), getCurrentFid(),+ m_autopaintLines.getValue());TSystem::outputDebug("ok. pix=" + std::to_string(pix.getTone()) + "," +std::to_string(pix.getPaint()) + "\n");- } else- return;- doFill(img, pos, params, e.isShiftPressed(), m_level.getPointer(),- getCurrentFid(), m_autopaintLines.getValue());- invalidate();+ }}}//-----------------------------------------------------------------------------void FillTool::leftButtonUp(const TPointD &pos, const TMouseEvent &e) {- if (m_onion.getValue()) {- if (m_fillType.getValue() != NORMALFILL && m_colorType.getValue() == AREAS)- m_rectFill->leftButtonUp(pos, e);- else if (m_onionStyleId > 0) {- FillParameters tmp = getFillParameters();- doFill(getImage(true), pos, tmp, e.isShiftPressed(), m_level.getPointer(),- getCurrentFid(), m_autopaintLines.getValue());- invalidate();- }- } else if (m_fillType.getValue() != NORMALFILL) {- m_rectFill->leftButtonUp(pos, e);+ FillParameters params = getFillParameters();+ // Area mode+ if (m_fillType.getValue() != NORMALFILL) {+ buildFillInfo(params); // Frame range, refFill and so on+ m_areaFillTool->leftButtonUp(pos, e);return;}- if (!m_frameRange.getValue()) {- TFrameId fid = getCurrentFid();- // notifyImageChanged();- if (getFillParameters().m_fillType == LINES &&- m_targetType == TTool::ToonzImage) {- FillParameters params = getFillParameters();- m_normalLineFillTool->leftButtonUp(pos, e, getImage(true), params);- return;- }+ // Line mode+ if ((m_colorType.getValue() == LINES) && m_targetType == TTool::ToonzImage) {+ m_normalLineFillTool->leftButtonUp(pos, e, getImage(true), params);+ return;+ }++ // Normal Fill+ if (m_onion.getValue() && m_onionStyleId > 0) {+ buildFillInfo(params); // Frame range, refFill and so on+ doRefFill(getImage(true),+ m_refImgTable[m_level->getImageId(getCurrentFid(), false)], pos,+ params, e.isShiftPressed(), m_level.getPointer(), getCurrentFid(),+ m_autopaintLines.getValue());+ m_onionStyleId = 0;+ invalidate();}}//-----------------------------------------------------------------------------void FillTool::resetMulti() {- m_firstClick = false;- m_firstFrameId = -1;- m_firstPoint = TPointD();- TXshLevel *xl = TTool::getApplication()->getCurrentLevel()->getLevel();- m_level = xl ? xl->getSimpleLevel() : 0;+ m_firstFrameSelected = false;+ m_firstFrameId = -1;+ m_firstPoint = TPointD();+ TXshLevel *xl = TTool::getApplication()->getCurrentLevel()->getLevel();+ m_level = xl ? xl->getSimpleLevel() : 0;}//-----------------------------------------------------------------------------bool FillTool::onPropertyChanged(std::string propertyName, bool addToUndo) {- /*--- m_rectFill->onPropertyChangedを呼ぶかどうかのフラグ+ /*--- m_areaFillTool->onPropertyChangedを呼ぶかどうかのフラグfillType, frameRange, selective,colorTypeが変わったときに呼ぶ---*/bool rectPropChangedflag = false;@@ -2086,7 +2325,14 @@ bool FillTool::onPropertyChanged(std::string propertyName, bool addToUndo) {if (m_segment.getValue()) FillType = ::to_string(m_fillType.getValue());FillSegment = (int)(m_segment.getValue());}-+ // Close Gap+ else if (propertyName == m_closeGap.getName()) {+ FillCloseGap = (int)(m_closeGap.getValue());+ }+ // Refer Fill+ else if (propertyName == m_referFill.getName()) {+ FillReferFill = (int)(m_referFill.getValue());+ }// Autopaintelse if (propertyName == m_autopaintLines.getName()) {rectPropChangedflag = true;@@ -2141,7 +2387,7 @@ bool FillTool::onPropertyChanged(std::string propertyName, bool addToUndo) {elseassert(false);- m_rectFill->onPropertyChanged(+ m_areaFillTool->onPropertyChanged(m_frameRange.getValue(), m_selective.getValue(), m_onion.getValue(),type, m_colorType.getValue(), m_autopaintLines.getValue());}@@ -2152,14 +2398,15 @@ bool FillTool::onPropertyChanged(std::string propertyName, bool addToUndo) {//-----------------------------------------------------------------------------void FillTool::mouseMove(const TPointD &pos, const TMouseEvent &e) {- if (m_fillType.getValue() != NORMALFILL) m_rectFill->mouseMove(pos, e);+ if (m_fillType.getValue() != NORMALFILL) m_areaFillTool->mouseMove(pos, e);+ m_mousePos = pos;}//-----------------------------------------------------------------------------void FillTool::onImageChanged() {if (m_fillType.getValue() != NORMALFILL) {- m_rectFill->onImageChanged();+ m_areaFillTool->onImageChanged();return;}if (TVectorImageP vi = getImage(true)) {@@ -2200,17 +2447,17 @@ void FillTool::draw() {}}if (m_fillType.getValue() != NORMALFILL) {- m_rectFill->draw();+ m_areaFillTool->draw();return;}-- if (m_frameRange.getValue() && m_firstClick) {+ if (m_colorType.getValue() == LINES && m_targetType == TTool::ToonzImage)+ m_normalLineFillTool->draw();+ else if (m_frameRange.getValue() && m_firstFrameSelected) {tglColor(TPixel::Red);+ invalidate();drawCross(m_firstPoint, 6);- } else if (!m_frameRange.getValue() &&- getFillParameters().m_fillType == LINES &&- m_targetType == TTool::ToonzImage)- m_normalLineFillTool->draw();+ drawLine(m_firstPoint, m_mousePos);+ }}//-----------------------------------------------------------------------------@@ -2331,6 +2578,8 @@ void FillTool::onActivate() {// m_onlyEmpty.setValue(FillSelective ? 1 :0);m_onion.setValue(FillOnion ? 1 : 0);m_segment.setValue(FillSegment ? 1 : 0);+ m_closeGap.setValue(FillCloseGap ? 1 : 0);+ m_referFill.setValue(FillReferFill ? 1 : 0);m_frameRange.setValue(FillRange ? 1 : 0);m_firstTime = false;@@ -2347,14 +2596,14 @@ void FillTool::onActivate() {elseassert(false);- m_rectFill->onPropertyChanged(+ m_areaFillTool->onPropertyChanged(m_frameRange.getValue(), m_selective.getValue(), m_onion.getValue(),type, m_colorType.getValue(), m_autopaintLines.getValue());}}if (m_fillType.getValue() != NORMALFILL) {- m_rectFill->onActivate();+ m_areaFillTool->onActivate();return;}@@ -2378,9 +2627,9 @@ void FillTool::onActivate() {}bool ret = true;ret = ret && connect(TTool::m_application->getCurrentFrame(),- SIGNAL(frameSwitched()), this, SLOT(onFrameSwitched()));+ SIGNAL(frameSwitched()), this, SLOT(onFrameSwitched()));ret = ret && connect(TTool::m_application->getCurrentScene(),- SIGNAL(sceneSwitched()), this, SLOT(onFrameSwitched()));+ SIGNAL(sceneSwitched()), this, SLOT(onFrameSwitched()));ret = ret &&connect(TTool::m_application->getCurrentColumn(),SIGNAL(columnIndexSwitched()), this, SLOT(onFrameSwitched()));diff --git a/toonz/sources/tnztools/filltool.h b/toonz/sources/tnztools/filltool.hindex 29ca18671..ae504d214 100644--- a/toonz/sources/tnztools/filltool.h+++ b/toonz/sources/tnztools/filltool.h@@ -3,6 +3,8 @@#ifndef FILLTOOL_H#define FILLTOOL_H+#include <string>+// TnzCore includes#include "tproperty.h"#include "toonz/txshlevelhandle.h"@@ -21,7 +23,11 @@#define ALL L"Lines & Areas"class NormalLineFillTool;+typedef std::vector<std::pair<TXshSimpleLevel *, TFrameId>> SlFidsPairs;+typedef std::map<std::string, TRaster32P> RefImgTable;+namespace {+class AreaFillTool {public:enum Type { RECT, FREEHAND, POLYLINE, FREEPICK };@@ -73,12 +79,13 @@ public:void onEnter();};} // namespace+class FillTool final : public QObject, public TTool {// Q_DECLARE_TR_FUNCTIONS(FillTool)Q_OBJECTbool m_firstTime;- TPointD m_firstPoint, m_clickPoint;- bool m_firstClick;+ TPointD m_firstPoint, m_clickPoint, m_mousePos;+ bool m_firstFrameSelected;bool m_frameSwitched = false;double m_changedGapOriginalValue = -1.0;TXshSimpleLevelP m_level;@@ -91,12 +98,17 @@ class FillTool final : public QObject, public TTool {TBoolProperty m_selective;TDoublePairProperty m_fillDepth;TBoolProperty m_segment;+ TBoolProperty m_closeGap;+ TBoolProperty m_referFill;TDoubleProperty m_maxGapDistance;- AreaFillTool *m_rectFill;+ AreaFillTool *m_areaFillTool;NormalLineFillTool *m_normalLineFillTool;TPropertyGroup m_prop;- std::pair<int, int> m_currCell;+ struct cellPos {+ int col, row;+ } m_beginCell;+std::vector<TFilledRegionInf> m_oldFillInformation;#ifdef _DEBUGstd::vector<TRect> m_rects;@@ -106,6 +118,9 @@ class FillTool final : public QObject, public TTool {// disabledTBoolProperty m_autopaintLines;+ SlFidsPairs m_slFidsPairs;+ RefImgTable m_refImgTable;// imageId+public:FillTool(int targetType);@@ -140,6 +155,13 @@ public:int getCursorId() const override;int getColorClass() const { return 2; }++ void buildFillInfo(const FillParameters ¶ms);+ void computeRefImgsIfNeeded(const FillParameters ¶ms);++ const SlFidsPairs &getSlFidsPairs() const { return m_slFidsPairs; }+ const RefImgTable &getRefImgTable() const { return m_refImgTable; }+public slots:void onFrameSwitched() override;};diff --git a/toonz/sources/tnztools/tool.cpp b/toonz/sources/tnztools/tool.cppindex ff47314a4..6c657fc7c 100644--- a/toonz/sources/tnztools/tool.cpp+++ b/toonz/sources/tnztools/tool.cpp@@ -738,16 +738,19 @@ void TTool::notifyImageChanged() {/*! Notify change of image in \b fid: update Icon & Closer and notify level change.*/-void TTool::notifyImageChanged(const TFrameId &fid) {+void TTool::notifyImageChanged(const TFrameId &fid,+ TXshSimpleLevel *sl) {onImageChanged();if (!m_application) return;m_application->getCurrentScene()->setDirtyFlag(true);if (m_application->getCurrentFrame()->isEditingLevel()) {- TXshLevel *xl = m_application->getCurrentLevel()->getLevel();- if (!xl) return;- TXshSimpleLevel *sl = xl->getSimpleLevel();+ if (!sl) {+ TXshLevel *xl = m_application->getCurrentLevel()->getLevel();+ if (!xl) return;+ sl = xl->getSimpleLevel();+ }if (!sl) return;sl->setDirtyFlag(true);IconGenerator::instance()->invalidate(sl, fid);@@ -761,7 +764,7 @@ void TTool::notifyImageChanged(const TFrameId &fid) {TXsheet *xsh = m_application->getCurrentXsheet()->getXsheet();if (!xsh) return;TXshCell cell = xsh->getCell(row, col);- TXshSimpleLevel *sl = cell.getSimpleLevel();+ if(!sl) sl = cell.getSimpleLevel();if (sl) {IconGenerator::instance()->invalidate(sl, fid);IconGenerator::instance()->invalidateSceneIcon();diff --git a/toonz/sources/tnztools/tooloptions.cpp b/toonz/sources/tnztools/tooloptions.cppindex 1e6cc394a..2642fc2f4 100644--- a/toonz/sources/tnztools/tooloptions.cpp+++ b/toonz/sources/tnztools/tooloptions.cpp@@ -1767,7 +1767,10 @@ FillToolOptionsBox::FillToolOptionsBox(QWidget *parent, TTool *tool,dynamic_cast<ToolOptionCheckbox *>(m_controls.value("Frame Range"));m_autopaintMode =dynamic_cast<ToolOptionCheckbox *>(m_controls.value("Autopaint Lines"));-+ m_closeGap =+ dynamic_cast<ToolOptionCheckbox *>(m_controls.value("Close Gap"));+ m_referFill =+ dynamic_cast<ToolOptionCheckbox *>(m_controls.value("Refer Fill"));bool ret = connect(m_colorMode, SIGNAL(currentIndexChanged(int)), this,SLOT(onColorModeChanged(int)));ret = ret && connect(m_toolType, SIGNAL(currentIndexChanged(int)), this,@@ -1777,24 +1780,9 @@ FillToolOptionsBox::FillToolOptionsBox(QWidget *parent, TTool *tool,ret = ret && connect(m_multiFrameMode, SIGNAL(toggled(bool)), this,SLOT(onMultiFrameModeToggled(bool)));assert(ret);- if (m_colorMode->getProperty()->getValue() == L"Lines") {- m_selectiveMode->setEnabled(false);- if (m_fillDepthLabel && m_fillDepthField) {- m_fillDepthLabel->setEnabled(false);- m_fillDepthField->setEnabled(false);- }- if (m_toolType->getProperty()->getValue() == L"Normal" ||- m_multiFrameMode->isChecked())- m_onionMode->setEnabled(false);- if (m_autopaintMode) m_autopaintMode->setEnabled(false);- }- if (m_toolType->getProperty()->getValue() != L"Normal") {- if (m_segmentMode) m_segmentMode->setEnabled(false);- if (m_colorMode->getProperty()->getValue() == L"Lines" ||- m_multiFrameMode->isChecked())- m_onionMode->setEnabled(false);- }- if (m_onionMode->isChecked()) m_multiFrameMode->setEnabled(false);+ onColorModeChanged(m_colorMode->getProperty()->getIndex());+ onToolTypeChanged(m_toolType->getProperty()->getIndex());+ onOnionModeToggled(m_onionMode->isChecked());}//-----------------------------------------------------------------------------@@ -1810,6 +1798,7 @@ void FillToolOptionsBox::updateStatus() {void FillToolOptionsBox::onColorModeChanged(int index) {const TEnumProperty::Range &range = m_colorMode->getProperty()->getRange();bool enabled = range[index] != L"Lines";+ m_multiFrameMode->setEnabled(enabled);m_selectiveMode->setEnabled(enabled);if (m_autopaintMode) m_autopaintMode->setEnabled(enabled);if (m_fillDepthLabel && m_fillDepthField) {@@ -1823,6 +1812,8 @@ void FillToolOptionsBox::onColorModeChanged(int index) {}enabled = range[index] != L"Lines" && !m_multiFrameMode->isChecked();m_onionMode->setEnabled(enabled);+ if(m_referFill) m_referFill->setEnabled(enabled);+ if(m_closeGap) m_closeGap->setEnabled(enabled);}//-----------------------------------------------------------------------------@@ -1836,6 +1827,9 @@ void FillToolOptionsBox::onToolTypeChanged(int index) {enabled = enabled || (m_colorMode->getProperty()->getValue() != L"Lines" &&!m_multiFrameMode->isChecked());m_onionMode->setEnabled(enabled);+ enabled = range[index] != L"Polyline";+ if (m_referFill) m_referFill->setEnabled(enabled);+ if (m_closeGap) m_closeGap->setEnabled(enabled);}//-----------------------------------------------------------------------------diff --git a/toonz/sources/tnztools/toolutils.cpp b/toonz/sources/tnztools/toolutils.cppindex 1dcf1c118..3d7ec35cc 100644--- a/toonz/sources/tnztools/toolutils.cpp+++ b/toonz/sources/tnztools/toolutils.cpp@@ -232,7 +232,15 @@ void ToolUtils::drawCross(const TPointD &q, double pixelSize) {glEnd();}+//-----------------------------------------------------------------------------+void ToolUtils::drawLine(const TPointD &p0, const TPointD p1) {+ glBegin(GL_LINE_STRIP);+ glVertex2d(p0.x, p0.y);+ glVertex2d(p1.x, p1.y);+ glEnd();+}+ //-----------------------------------------------------------------------------void ToolUtils::drawArrow(const TSegment &s, double pixelSize) {TPointD v, vn;diff --git a/toonz/sources/toonzlib/autoclose.cpp b/toonz/sources/toonzlib/autoclose.cppindex 8e4b0f5b1..56e193065 100644--- a/toonz/sources/toonzlib/autoclose.cpp+++ b/toonz/sources/toonzlib/autoclose.cpp@@ -173,7 +173,7 @@ TRasterGR8P fillByteRaster(const TRasterCM32P &r, TRasterGR8P &bRaster) {*(br++) = 131;TPixelCM32 *pix = r->pixels(i);for (j = 0; j < lx; j++, pix++) {- if (pix->getTone() != pix->getMaxTone() || pix->getPaint())+ if (pix->getTone() != pix->getMaxTone())*(br++) = 3;else*(br++) = 0;diff --git a/toonz/sources/toonzlib/fill.cpp b/toonz/sources/toonzlib/fill.cppindex c62258029..6a08bc16b 100644--- a/toonz/sources/toonzlib/fill.cpp+++ b/toonz/sources/toonzlib/fill.cpp@@ -1,15 +1,16 @@-#include "trastercm.h"+#include <stack>+#include "toonz/fill.h"#include "toonz/ttilesaver.h"#include "tpalette.h"#include "tpixelutils.h"-#include <stack>+#include "trastercm.h"+#include "tropcm.h"//-----------------------------------------------------------------------------namespace { // Utility Function-//-----------------------------------------------------------------------------inline TPoint nearestInkNotDiagonal(const TRasterCM32P &r, const TPoint &p) {TPixelCM32 *buf = (TPixelCM32 *)r->pixels(p.y) + p.x;@@ -39,18 +40,19 @@ inline TPoint nearestInkNotDiagonal(const TRasterCM32P &r, const TPoint &p) {void fillRow(const TRasterCM32P &r, const TPoint &p, int &xa, int &xb,int paint, TPalette *palette, TTileSaverCM32 *saver,- bool prevailing = true) {+ bool prevailing = true, bool refImagePut = false,+ int paintAtClickPos = 0) {int tone, oldtone;TPixelCM32 *pix, *pix0, *limit, *tmp_limit;/* vai a destra */TPixelCM32 *line = r->pixels(p.y);- pix0 = line + p.x;- pix = pix0;- limit = line + r->getBounds().x1;+ pix0 = line + p.x;+ pix = pix0;+ limit = line + r->getBounds().x1;oldtone = pix->getTone();- tone = oldtone;+ tone = oldtone;for (; pix <= limit; pix++) {if (pix->getPaint() == paint) break;tone = pix->getTone();@@ -70,7 +72,7 @@ void fillRow(const TRasterCM32P &r, const TPoint &p, int &xa, int &xb,// check if the current pixel is NOT with the lowest tone among the// vertical neighbors as wellif (p.y > 0 && p.y < r->getLy() - 1) {- TPixelCM32 *upPix = pix - r->getWrap();+ TPixelCM32 *upPix = pix - r->getWrap();TPixelCM32 *downPix = pix + r->getWrap();if (upPix->getTone() > pix->getTone() &&downPix->getTone() > pix->getTone())@@ -84,7 +86,7 @@ void fillRow(const TRasterCM32P &r, const TPoint &p, int &xa, int &xb,}oldtone = tone;}- if (tone == 0) {+ if (prevailing && tone == 0) {tmp_limit = pix + 10; // edge stop fill == 10 per defaultif (limit > tmp_limit) limit = tmp_limit;for (; pix <= limit; pix++) {@@ -97,10 +99,10 @@ void fillRow(const TRasterCM32P &r, const TPoint &p, int &xa, int &xb,/* vai a sinistra */- pix = pix0;- limit = line + r->getBounds().x0;+ pix = pix0;+ limit = line + r->getBounds().x0;oldtone = pix->getTone();- tone = oldtone;+ tone = oldtone;for (pix--; pix >= limit; pix--) {if (pix->getPaint() == paint) break;tone = pix->getTone();@@ -120,7 +122,7 @@ void fillRow(const TRasterCM32P &r, const TPoint &p, int &xa, int &xb,// check if the current pixel is NOT with the lowest tone among the// vertical neighbors as wellif (p.y > 0 && p.y < r->getLy() - 1) {- TPixelCM32 *upPix = pix - r->getWrap();+ TPixelCM32 *upPix = pix - r->getWrap();TPixelCM32 *downPix = pix + r->getWrap();if (upPix->getTone() > pix->getTone() &&downPix->getTone() > pix->getTone())@@ -134,7 +136,7 @@ void fillRow(const TRasterCM32P &r, const TPoint &p, int &xa, int &xb,}oldtone = tone;}- if (tone == 0) {+ if (prevailing && tone == 0) {tmp_limit = pix - 10;if (limit < tmp_limit) limit = tmp_limit;for (; pix >= limit; pix--) {@@ -151,19 +153,38 @@ void fillRow(const TRasterCM32P &r, const TPoint &p, int &xa, int &xb,pix = line + xa;int n;for (n = 0; n < xb - xa + 1; n++, pix++) {- if (palette && pix->isPurePaint()) {- TPoint pInk = nearestInkNotDiagonal(r, TPoint(xa + n, p.y));- if (pInk != TPoint(-1, -1)) {- TPixelCM32 *pixInk =- (TPixelCM32 *)r->getRawData() + (pInk.y * r->getWrap() + pInk.x);- if (pixInk->getInk() != paint &&- palette->getStyle(pixInk->getInk())->getFlags() != 0)- inkFill(r, pInk, paint, 0, saver);+ if (palette) {+ if (pix->isPurePaint()) {+ TPoint pInk = nearestInkNotDiagonal(r, TPoint(xa + n, p.y));+ if (pInk != TPoint(-1, -1)) {+ TPixelCM32 *pixInk = (TPixelCM32 *)r->getRawData() ++ (pInk.y * r->getWrap() + pInk.x);+ if (pixInk->getInk() != paint &&+ palette->getStyle(pixInk->getInk())->getFlags() != 0)+ inkFill(r, pInk, paint, 0, saver);+ else if (pixInk->getInk() == paintAtClickPos)+ inkFill(r, pInk, paint, 0, saver);+ }}}-+ if (refImagePut && pix->getInk() == TPixelCM32::getMaxInk())+ pix->setInk(paint);pix->setPaint(paint);}++ // Make sure the up and down ref Ink Pixels can be painted+ if (refImagePut && p.y > 0 && p.y < r->getLy() - 1) {+ pix = line + xa;+ for (n = 0; n < xb - xa + 1; n++, pix++) {+ if (pix->isPurePaint()) {+ TPixelCM32 *upPix = pix - r->getWrap();+ TPixelCM32 *downPix = pix + r->getWrap();+ if (upPix->getInk() == TPixelCM32::getMaxInk()) upPix->setInk(paint);+ if (downPix->getInk() == TPixelCM32::getMaxInk())+ downPix->setInk(paint);+ }+ }+ }}}@@ -177,11 +198,11 @@ void findSegment(const TRaster32P &r, const TPoint &p, int &xa, int &xb,/* vai a destra */TPixel32 *line = r->pixels(p.y);- pix0 = line + p.x;- pix = pix0;- limit = line + r->getBounds().x1;+ pix0 = line + p.x;+ pix = pix0;+ limit = line + r->getBounds().x1;oldmatte = pix->m;- matte = oldmatte;+ matte = oldmatte;for (; pix <= limit; pix++) {if (*pix == color) break;matte = pix->m;@@ -199,10 +220,10 @@ void findSegment(const TRaster32P &r, const TPoint &p, int &xa, int &xb,xb = p.x + pix - pix0 - 1;/* vai a sinistra */- pix = pix0;- limit = line + r->getBounds().x0;+ pix = pix0;+ limit = line + r->getBounds().x0;oldmatte = pix->m;- matte = oldmatte;+ matte = oldmatte;for (; pix >= limit; pix--) {if (*pix == color) break;matte = pix->m;@@ -252,8 +273,8 @@ void fullColorFindSegment(const TRaster32P &r, const TPoint &p, int &xa,// check to the rightTPixel32 *line = r->pixels(p.y);- pix0 = line + p.x; // seed pixel- pix = pix0;+ pix0 = line + p.x; // seed pixel+ pix = pix0;limit = line + r->getBounds().x1; // right endTPixel32 oldPix = *pix;@@ -274,8 +295,8 @@ void fullColorFindSegment(const TRaster32P &r, const TPoint &p, int &xa,xb = p.x + pix - pix0 - 1;// check to the left- pix = pix0; // seed pixel- limit = line + r->getBounds().x0; // left end+ pix = pix0; // seed pixel+ limit = line + r->getBounds().x0; // left endoldPix = *pix;for (; pix >= limit; pix--) {// break if the target pixel is with the same as filling color@@ -294,7 +315,7 @@ void fullColorFindSegment(const TRaster32P &r, const TPoint &p, int &xa,//-----------------------------------------------------------------------------class FillSeed {-public:+ public:int m_xa, m_xb;int m_y, m_dy;FillSeed(int xa, int xb, int y, int dy)@@ -352,7 +373,7 @@ bool floodCheck(const TPixel32 &clickColor, const TPixel32 *targetPix,if (clickColor.m == 0) {int oldMatte = fullColorThreshMatte(oldPix->m, fillDepth);- int matte = fullColorThreshMatte(targetPix->m, fillDepth);+ int matte = fullColorThreshMatte(targetPix->m, fillDepth);return matte >= oldMatte && matte != 255;}int fillDepth2 = fillDepth * fillDepth;@@ -461,7 +482,7 @@ int getMostFrequentNeighborStyleId(TRasterCM32P ras,//-----------------------------------------------------------------------------/*-- The return value is whether the saveBox has been updated or not. --*/bool fill(const TRasterCM32P &r, const FillParameters ¶ms,- TTileSaverCM32 *saver) {+ TTileSaverCM32 *saver, const TRaster32P &Ref) {TPixelCM32 *pix, *limit, *pix0, *oldpix;int oldy, xa, xb, xc, xd, dy;int oldxc, oldxd;@@ -478,46 +499,66 @@ bool fill(const TRasterCM32P &r, const FillParameters ¶ms,/*- Return if clicked outside the screen -*/if (!bbbox.contains(p)) return false;/*- If the same color has already been painted, return -*/- int paintAtClickedPos = (r->pixels(p.y) + p.x)->getPaint();- if (paintAtClickedPos == paint) return false;+ pix0 = r->pixels(p.y) + p.x;+ int paintAtClickedPos = pix0->getPaint();+ if (paintAtClickedPos == paint)+ if (params.m_shiftFill) {+ FillParameters tmp = FillParameters(params);+ tmp.m_styleId = 0;+ tmp.m_shiftFill = false;+ tmp.m_minFillDepth = params.m_maxFillDepth;+ fill(r, tmp, saver, Ref);+ paintAtClickedPos = pix0->getPaint();+ } else+ return false;/*- If the "paint only transparent areas" option is enabled and the area is* already colored, return* -*/- if (params.m_emptyOnly && (r->pixels(p.y) + p.x)->getPaint() != 0)+ if (params.m_emptyOnly && pix0->getPaint() != 0 && !params.m_shiftFill)return false;+ if (pix0->isPureInk()) return false;++ bool refImagePut = Ref.getPointer();+ if (refImagePut) {+ if (*(Ref->pixels(p.y) + p.x) != TPixel32(0, 0, 0, 0)) return false;+ if (saver) saver->save(Ref->getBounds());+ TRop::putRefImage(r, Ref);+ }+assert(fillDepth >= 0 && fillDepth < 16);switch (TPixelCM32::getMaxTone()) {- case 15:- fillDepth = (15 - fillDepth);- break;- case 255:- fillDepth = ((15 - fillDepth) << 4) | (15 - fillDepth);- break;- default:- assert(false);+ case 15:+ fillDepth = (15 - fillDepth);+ break;+ case 255:+ fillDepth = ((15 - fillDepth) << 4) | (15 - fillDepth);+ break;+ default:+ assert(false);}/*--Look at the colors in the four corners and update the saveBox if any of* the colors change. --*/TPixelCM32 borderIndex[4];TPixelCM32 *borderPix[4];- pix = r->pixels(0);- borderPix[0] = pix;+ pix = r->pixels(0);+ borderPix[0] = pix;borderIndex[0] = *pix;pix += r->getLx() - 1;- borderPix[1] = pix;+ borderPix[1] = pix;borderIndex[1] = *pix;- pix = r->pixels(r->getLy() - 1);- borderPix[2] = pix;+ pix = r->pixels(r->getLy() - 1);+ borderPix[2] = pix;borderIndex[2] = *pix;pix += r->getLx() - 1;- borderPix[3] = pix;+ borderPix[3] = pix;borderIndex[3] = *pix;std::stack<FillSeed> seeds;- fillRow(r, p, xa, xb, paint, params.m_palette, saver, params.m_prevailing);+ fillRow(r, p, xa, xb, paint, params.m_palette, saver, params.m_prevailing,+ refImagePut, paintAtClickedPos);seeds.push(FillSeed(xa, xb, y, 1));seeds.push(FillSeed(xa, xb, y, -1));@@ -525,28 +566,28 @@ bool fill(const TRasterCM32P &r, const FillParameters ¶ms,FillSeed fs = seeds.top();seeds.pop();- xa = fs.m_xa;- xb = fs.m_xb;+ xa = fs.m_xa;+ xb = fs.m_xb;oldy = fs.m_y;- dy = fs.m_dy;- y = oldy + dy;+ dy = fs.m_dy;+ y = oldy + dy;if (y > bbbox.y1 || y < bbbox.y0) continue;pix = pix0 = r->pixels(y) + xa;- limit = r->pixels(y) + xb;- oldpix = r->pixels(oldy) + xa;- x = xa;- oldxd = (std::numeric_limits<int>::min)();- oldxc = (std::numeric_limits<int>::max)();+ limit = r->pixels(y) + xb;+ oldpix = r->pixels(oldy) + xa;+ x = xa;+ oldxd = (std::numeric_limits<int>::min)();+ oldxc = (std::numeric_limits<int>::max)();while (pix <= limit) {oldtone = threshTone(*oldpix, fillDepth);- tone = threshTone(*pix, fillDepth);+ tone = threshTone(*pix, fillDepth);// the last condition is added in order to prevent fill area from// protruding behind the colored lineif (pix->getPaint() != paint && tone <= oldtone && tone != 0 &&(pix->getPaint() != pix->getInk() ||pix->getPaint() == paintAtClickedPos)) {fillRow(r, TPoint(x, y), xc, xd, paint, params.m_palette, saver,- params.m_prevailing);+ params.m_prevailing, refImagePut, paintAtClickedPos);if (xc < xa) seeds.push(FillSeed(xc, xa - 1, y, -dy));if (xd > xb) seeds.push(FillSeed(xb + 1, xd, y, -dy));if (oldxd >= xc - 1)@@ -567,6 +608,8 @@ bool fill(const TRasterCM32P &r, const FillParameters ¶ms,if (oldxd > 0) seeds.push(FillSeed(oldxc, oldxd, y, dy));}+ if (refImagePut) TRop::eraseRefInks(r);+bool saveBoxChanged = false;for (int i = 0; i < 4; i++) {if (!((*borderPix[i]) == borderIndex[i])) {@@ -592,7 +635,7 @@ void fill(const TRaster32P &ras, const TRaster32P &ref,if (!bbbox.contains(params.m_p)) return;- TPaletteP plt = params.m_palette;+ TPaletteP plt = params.m_palette;TPixel32 color = plt->getStyle(params.m_styleId)->getMainColor();int fillDepth =params.m_shiftFill ? params.m_maxFillDepth : params.m_minFillDepth;@@ -605,12 +648,12 @@ void fill(const TRaster32P &ras, const TRaster32P &ref,// it means that I filled the bg and the savebox needs to be recomputed!TPixel32 borderIndex;TPixel32 *borderPix = 0;- pix = workRas->pixels(0);+ pix = workRas->pixels(0);int i;for (i = 0; i < workRas->getLx(); i++, pix++) // border downif (pix->m == 0) {borderIndex = *pix;- borderPix = pix;+ borderPix = pix;break;}if (borderPix == 0) // not found in border down...try border up (avoid left@@ -620,7 +663,7 @@ void fill(const TRaster32P &ras, const TRaster32P &ref,for (i = 0; i < workRas->getLx(); i++, pix++) // border upif (pix->m == 0) {borderIndex = *pix;- borderPix = pix;+ borderPix = pix;break;}}@@ -638,21 +681,21 @@ void fill(const TRaster32P &ras, const TRaster32P &ref,FillSeed fs = seeds.top();seeds.pop();- xa = fs.m_xa;- xb = fs.m_xb;+ xa = fs.m_xa;+ xb = fs.m_xb;oldy = fs.m_y;- dy = fs.m_dy;- y = oldy + dy;+ dy = fs.m_dy;+ y = oldy + dy;if (y > bbbox.y1 || y < bbbox.y0) continue;pix = pix0 = workRas->pixels(y) + xa;- limit = workRas->pixels(y) + xb;- oldpix = workRas->pixels(oldy) + xa;- x = xa;- oldxd = (std::numeric_limits<int>::min)();- oldxc = (std::numeric_limits<int>::max)();+ limit = workRas->pixels(y) + xb;+ oldpix = workRas->pixels(oldy) + xa;+ x = xa;+ oldxd = (std::numeric_limits<int>::min)();+ oldxc = (std::numeric_limits<int>::max)();while (pix <= limit) {- oldMatte = threshMatte(oldpix->m, fillDepth);- matte = threshMatte(pix->m, fillDepth);+ oldMatte = threshMatte(oldpix->m, fillDepth);+ matte = threshMatte(pix->m, fillDepth);bool test = false;if (segments.find(y) != segments.end())test = isPixelInSegment(segments[y], x);@@ -682,7 +725,7 @@ void fill(const TRaster32P &ras, const TRaster32P &ref,std::map<int, std::vector<std::pair<int, int>>>::iterator it;for (it = segments.begin(); it != segments.end(); it++) {- TPixel32 *line = ras->pixels(it->first);+ TPixel32 *line = ras->pixels(it->first);TPixel32 *refLine = 0;TPixel32 *refPix;if (ref) refLine = ref->pixels(it->first);@@ -789,7 +832,7 @@ void fullColorFill(const TRaster32P &ras, const FillParameters ¶ms,TPixel32 clickedPosColor = *(ras->pixels(y) + x);- TPaletteP plt = params.m_palette;+ TPaletteP plt = params.m_palette;TPixel32 color = plt->getStyle(params.m_styleId)->getMainColor();if (clickedPosColor == color) return;@@ -817,11 +860,11 @@ void fullColorFill(const TRaster32P &ras, const FillParameters ¶ms,FillSeed fs = seeds.top();seeds.pop();- xa = fs.m_xa;- xb = fs.m_xb;+ xa = fs.m_xa;+ xb = fs.m_xb;oldy = fs.m_y;- dy = fs.m_dy;- y = oldy + dy;+ dy = fs.m_dy;+ y = oldy + dy;// continue if the fill runs over image boundingif (y > bbbox.y1 || y < bbbox.y0) continue;// left end of the pixels to be filled@@ -831,7 +874,7 @@ void fullColorFill(const TRaster32P &ras, const FillParameters ¶ms,// left end of the fill seed pixelsoldpix = ras->pixels(oldy) + xa;- x = xa;+ x = xa;oldxd = (std::numeric_limits<int>::min)();oldxc = (std::numeric_limits<int>::max)();@@ -877,8 +920,8 @@ void fullColorFill(const TRaster32P &ras, const FillParameters ¶ms,std::map<int, std::vector<std::pair<int, int>>>::iterator it;for (it = segments.begin(); it != segments.end(); it++) {- TPixel32 *line = ras->pixels(it->first);- TPixel32 *refLine = 0;+ TPixel32 *line = ras->pixels(it->first);+ TPixel32 *refLine = 0;std::vector<std::pair<int, int>> segmentVector = it->second;for (int i = 0; i < (int)segmentVector.size(); i++) {std::pair<int, int> segment = segmentVector[i];diff --git a/toonz/sources/toonzlib/fillutil.cpp b/toonz/sources/toonzlib/fillutil.cppindex 7a5ce99c6..f1c335e34 100644--- a/toonz/sources/toonzlib/fillutil.cpp+++ b/toonz/sources/toonzlib/fillutil.cpp@@ -10,6 +10,7 @@#include "toonz/toonzimageutils.h"#include "skeletonlut.h"#include "tpixelutils.h"+#include "tropcm.h"#include <stack>@@ -38,7 +39,7 @@ void computeSeeds(const TRasterCM32P &r, TStroke *stroke,//-----------------------------------------------------------------------------void fillArea(const TRasterCM32P &ras, TRegion *r, int colorId,- bool onlyUnfilled, bool fillPaints, bool fillInks) {+ bool onlyUnfilled, bool fillPaints, bool fillInks, TPalette *plt) {TRect bbox = convert(r->getBBox());bbox *= ras->getBounds();ras->lock();@@ -55,6 +56,8 @@ void fillArea(const TRasterCM32P &ras, TRegion *r, int colorId,int to = std::min(tceil(intersections[j + 1]), bbox.x1);TPixelCM32 *pix = line + from;for (int k = from; k < to; k++, pix++) {+ if (plt && plt->getStyle(pix->getInk())->getFlags() != 0)+ pix->setInk(colorId);if (fillPaints && (!onlyUnfilled || pix->getPaint() == 0))pix->setPaint(colorId);if (fillInks) pix->setInk(colorId);@@ -117,12 +120,15 @@ bool areRectPixelsTransparent(TPixel32 *pixels, TRect rect, int wrap) {//=============================================================================// AreaFiller-AreaFiller::AreaFiller(const TRasterCM32P &ras)+AreaFiller::AreaFiller(const TRasterCM32P &ras, const TRaster32P &ref,+ TPalette *palette): m_ras(ras), m_bounds(ras->getBounds()), m_pixels(ras->pixels()), m_wrap(ras->getWrap())- , m_color(0) {+ , m_color(0)+ , m_palette(palette)+ , m_refRas(ref) {m_ras->lock();}@@ -165,10 +171,12 @@ bool AreaFiller::rectFill(const TRect &rect, int color, bool onlyUnfilled,if (!fillPaints) {assert(fillInks);assert(m_ras->getBounds().contains(rect));+ if (m_refRas) TRop::putRefImage(m_ras, m_refRas);for (int y = rect.y0; y <= rect.y1; y++) {TPixelCM32 *pix = m_ras->pixels(y) + rect.x0;for (int x = rect.x0; x <= rect.x1; x++, pix++) pix->setInk(color);}+ if (m_refRas) TRop::eraseRefInks(m_ras);return true;}@@ -192,6 +200,8 @@ bool AreaFiller::rectFill(const TRect &rect, int color, bool onlyUnfilled,if (!rect.contains(m_bounds) && areRectPixelsPurePaint(m_pixels, r, m_wrap))return false;+ if (m_refRas) TRop::putRefImage(m_ras, m_refRas);+// Viene riempito frameSeed con tutti i paint delle varie aree del rettangolo// di contorno.// Viene verificato se i pixels del rettangolo sono tutti pure paint.@@ -269,15 +279,17 @@ bool AreaFiller::rectFill(const TRect &rect, int color, bool onlyUnfilled,params.m_styleId = frameSeed[count1++];fill(m_ras, params);}++ if (m_refRas) TRop::eraseRefInks(m_ras);return true;}//------------------------------------------------------------------------------void AreaFiller::strokeFill(TStroke *stroke, int colorId, bool onlyUnfilled,+void AreaFiller::strokeFill(TStroke *stroke, int color, bool onlyUnfilled,bool fillPaints, bool fillInks) {- stroke->transform(TTranslation(convert(m_ras->getCenter())));m_ras->lock();+ if (m_refRas) TRop::putRefImage(m_ras, m_refRas);std::vector<std::pair<TPoint, int>> seeds;computeSeeds(m_ras, stroke, seeds);@@ -287,11 +299,12 @@ void AreaFiller::strokeFill(TStroke *stroke, int colorId, bool onlyUnfilled,app.findRegions();for (UINT i = 0; i < app.getRegionCount(); i++)fillArea(m_ras, app.getRegion(i), colorId, onlyUnfilled, fillPaints,- fillInks);+ fillInks, m_palette);app.removeStroke(0);stroke->transform(TTranslation(convert(-m_ras->getCenter())));restoreColors(m_ras, seeds);+ if (m_refRas) TRop::eraseRefInks(m_ras);m_ras->unlock();}