Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

Fix(areaFiller,gap close): Remove gap close lines outside/inside filled region

Abel Youb8fa4dfc57e5
diff --git a/toonz/sources/include/toonz/fill.h b/toonz/sources/include/toonz/fill.h
index a83ad5e6d..a760d8327 100644
--- a/toonz/sources/include/toonz/fill.h
+++ b/toonz/sources/include/toonz/fill.h
@@ -159,6 +159,7 @@ private:
int color, bool onlyUnfilled, bool fillPaints,
bool fillInks, bool defRegionWithPaint,
bool usePrevailingReferFill);
+ const void removeUnneedReferLines(const TRasterCM32P &ras);
};
class DVAPI FullColorAreaFiller {
diff --git a/toonz/sources/toonzlib/fillutil.cpp b/toonz/sources/toonzlib/fillutil.cpp
index 3fdba1d6d..798066c1f 100644
--- a/toonz/sources/toonzlib/fillutil.cpp
+++ b/toonz/sources/toonzlib/fillutil.cpp
@@ -294,6 +294,7 @@ bool AreaFiller::rectFill(const TRect &rect, int color, bool onlyUnfilled,
}
}
}
+ removeUnneedReferLines(ras);
bool defRegionWithPaint = params.m_defRegionWithPaint;
bool usePrevailingReferFill = params.m_usePrevailingReferFill;
@@ -421,24 +422,51 @@ void AreaFiller::strokeFill(const TRect &rect, TStroke *stroke, int color,
// Put reference image, will be automatically removed by RAII
RefImageGuard refGuard(m_ras, m_refRas);
+ bool defRegionWithPaint = DEF_REGION_WITH_PAINT;
+ bool usePrevailingReferFill = USE_PREVAILING_REFER_FILL;
+ bool refFill = m_refRas.getPointer() != nullptr;
+
// std::vector<std::pair<TPoint, int>> seeds;
// computeSeeds(m_ras, stroke, seeds);
fillOutsideOfStroke(ras, stroke, TPixelCM32::getMaxPaint() - 1);
// Some pixels might be painted to in fillRow(),
// with PAINT Bounds off and refer/gap on
+ int lx = box.getLx(), ly = box.getLy();
+
+ // Restore those lines painted by fillRow() here
+ if (!defRegionWithPaint && refFill) {
+ TPixelCM32 *pix = ras->pixels(0);
+ TPixelCM32 *pix1 = ras->pixels(ly - 1) + lx;
+ for (int y = 0; y < ly; ++y) {
+ TPixelCM32 *pix = ras->pixels(y);
+ for (int x = 0; x < lx; ++x, ++pix) {
+ if (pix->getInk() == TPixelCM32::getMaxInk() - 1) {
+ pix->setInk(TPixelCM32::getMaxInk());
+ }
+ }
+ }
+ }
TVectorImage app;
app.addStroke(stroke);
app.findRegions();
// fillRegionsExcept() also process lines
+
+ // Before the refer lines be painted, remove unnecessary lines
+ if (refFill && fillInks) {
+ for (UINT i = 0; i < app.getRegionCount(); i++)
+ fillRegionExcept(ras, app.getRegion(i), TPixelCM32::getMaxPaint() - 1,
+ TPixelCM32::getMaxPaint(), 0, color, false);
+ removeUnneedReferLines(ras);
+ }
+ // Paint Lines and Areas
for (UINT i = 0; i < app.getRegionCount(); i++)
fillRegionExcept(ras, app.getRegion(i), TPixelCM32::getMaxPaint() - 1,
TPixelCM32::getMaxPaint(), m_palette, color, fillInks);
app.removeStroke(0);
- bool defRegionWithPaint = DEF_REGION_WITH_PAINT;
- bool usePrevailingReferFill = USE_PREVAILING_REFER_FILL;
- int lx = box.getLx(), ly = box.getLy();
+ if (!fillInks && refFill) removeUnneedReferLines(ras);
+
for (int y = 0; y < ly; ++y) {
TPixelCM32 *pix = ras->pixels(y);
TPixelCM32 *bak = backupRas->pixels(y);
@@ -460,8 +488,6 @@ const void AreaFiller::processPixel(TPixelCM32 &pix, const TPixelCM32 &bak,
: pix.getPaint() == TPixelCM32::getMaxPaint()) {
/*--- Process refer Lines ---*/
// paint refer lines
- if (!invert && pix.getInk() == TPixelCM32::getMaxInk() - 1) // !!!!
- pix.setInk(TPixelCM32::getMaxInk());
if (pix.getInk() == TPixelCM32::getMaxInk() && !defRegionWithPaint)
pix.setInk(color);
@@ -487,6 +513,116 @@ const void AreaFiller::processPixel(TPixelCM32 &pix, const TPixelCM32 &bak,
pix.setPaint(bak.getPaint());
}
+// Mainly two kinds of lines:
+// 1. Lines inside the closed region
+// 2. Lines outside the closed region
+const void AreaFiller::removeUnneedReferLines(const TRasterCM32P &ras) {
+ const int maxInk = TPixelCM32::getMaxInk();
+ const int maxTone = TPixelCM32::getMaxTone();
+ const int wrap = m_wrap;
+ int lx = ras->getLx();
+ int ly = ras->getLy();
+ if (lx < 3 || ly < 3) return;
+ TPixelCM32 *pix = ras->pixels(0);
+
+ for (int y = 1; y < ly - 1; y++) {
+ TPixelCM32 *pix = ras->pixels(y) + 1;
+ TPixelCM32 *rowEnd = pix + (lx - 2);
+ while (pix < rowEnd) {
+ if (pix->getInk() != maxInk) {
+ pix++;
+ continue;
+ }
+
+ TPixelCM32 *left = pix - 1;
+ TPixelCM32 *right = pix + 1;
+ TPixelCM32 *up = pix + wrap;
+ TPixelCM32 *down = pix - wrap;
+
+ int leftPaint = left->getPaint();
+ int rightPaint = right->getPaint();
+ int upPaint = up->getPaint();
+ int downPaint = down->getPaint();
+
+ int leftInk = left->getInk();
+ int rightInk = right->getInk();
+ int upInk = up->getInk();
+ int downInk = down->getInk();
+
+ bool leftIsMax = (left->getInk() == maxInk);
+ bool rightIsMax = (right->getInk() == maxInk);
+ bool upIsMax = (up->getInk() == maxInk);
+ bool downIsMax = (down->getInk() == maxInk);
+
+ unsigned char mask =
+ (leftIsMax << 3) | (rightIsMax << 2) | (upIsMax << 1) | downIsMax;
+
+ switch (mask) {
+ // 2 Inks and some 3 Inks
+ case 0b0001:
+ case 0b0010:
+ case 0b0011:
+ if (leftPaint == rightPaint) {
+ *pix = TPixelCM32(0, leftPaint, maxTone);
+ }
+ break;
+
+ case 0b0100:
+ case 0b1000:
+ case 0b1100:
+ if (upPaint == downPaint) {
+ *pix = TPixelCM32(0, upPaint, maxTone);
+ }
+ break;
+
+ // 1 INK
+ case 0b0000:
+ if (leftPaint == rightPaint) {
+ *pix = TPixelCM32(0, leftPaint, maxTone);
+ } else if (upPaint == downPaint) {
+ *pix = TPixelCM32(0, upPaint, maxTone);
+ }
+ break;
+
+ // 3 INKs
+ case 0b1001:
+ *pix = TPixelCM32(0, leftPaint, maxTone);
+ break;
+ case 0b0101:
+ *pix = TPixelCM32(0, upPaint, maxTone);
+ break;
+ case 0b1010:
+ *pix = TPixelCM32(0, leftPaint, maxTone);
+ break;
+ case 0b0110:
+ *pix = TPixelCM32(0, upPaint, maxTone);
+ break;
+
+ // 4 INKs
+ case 0b0111:
+ *pix = TPixelCM32(0, leftPaint, maxTone);
+ break;
+ case 0b1011:
+ *pix = TPixelCM32(0, rightPaint, maxTone);
+ break;
+ case 0b1101:
+ *pix = TPixelCM32(0, upPaint, maxTone);
+ break;
+ case 0b1110:
+ *pix = TPixelCM32(0, downPaint, maxTone);
+ break;
+
+ default:
+ assert(false);
+ continue;
+ }
+
+ pix++;
+ }
+ }
+ return;
+}
+
//=============================================================================
// FullColorAreaFiller