Final for 1151

Fixed line fill code.
Removed debugging statements.
This commit is contained in:
Tom 2023-10-06 15:32:18 -04:00
parent 881c6f9166
commit dc046e027c
3 changed files with 8 additions and 171 deletions

View file

@ -603,16 +603,6 @@ public:
else
filler.strokeFill(m_s, m_paintId, m_onlyUnfilled, m_colorType != LINES,
m_colorType != AREAS, m_fillArea);
TSystem::outputDebug("filltool.redo() final check, m_fillGaps is:" + std::to_string(m_fillGaps));
// final check
// ToDo - call finishGapLines instead of this code
//void finishGapLines(TRasterCM32P & rin, TRect & rect, const TRasterCM32P & rbefore,
// const TRasterCM32P & combined, TPalette * plt,
// int clickedColorStyle, int fillIndex, int closeColorStyle,
// bool closeGaps) {
if (m_fillGaps) {
@ -630,24 +620,6 @@ public:
TPixelCM32 *tempPix = tempRaster->pixels();
TPixelCM32 *keepPix = ras->pixels();
//for (int tempY = 0; tempY < tempRaster->getLy(); tempY++) {
// for (int tempX = 0; tempX < tempRaster->getLx();
// tempX++, tempPix++, keepPix++) {
// keepPix->setPaint(tempPix->getPaint());
// if (tempPix->getInk() != styleIndex) {
// if (m_colorType == AREAS && m_closeGaps &&
// tempPix->getInk() == GAP_CLOSE_USED) {
// keepPix->setInk(m_closeStyleIndex);
// keepPix->setTone(tempPix->getTone());
// } else if (m_colorType != AREAS && tempPix->getInk() == GAP_CLOSE_USED) {
// keepPix->setInk(m_paintId);
// keepPix->setTone(tempPix->getTone());
// } else if (tempPix->getInk() != GAP_CLOSE_USED) {
// keepPix->setInk(tempPix->getInk());
// }
// }
// }
//}
for (int tempY = 0; tempY < tempRaster->getLy(); tempY++) {
for (int tempX = 0; tempX < tempRaster->getLx();
tempX++, tempPix++, keepPix++) {
@ -1041,26 +1013,17 @@ void fillAreaWithUndo(const TImageP &img, const TRectD &area, TStroke *stroke,
TTileSetCM32 *tileSet = new TTileSetCM32(ras->getSize());
tileSet->add(ras, rasterFillArea);
//std::cout << "\nfillAreaWithUndo ras:";
//std::cout << ras->getSize();
//outputPixels("ras", ras);
TRasterCM32P tempRaster;
int styleIndex = GAP_CLOSE_TEMP;
TToonzImageP tempTi = ti->clone();
tempRaster = tempTi->getRaster();
//outputPixels("tempRaster before auto close", tempRaster);
if (fillGaps) {
applyAutoclose(tempTi, AutocloseDistance, AutocloseAngle,
AutocloseOpacity, GAP_CLOSE_TEMP, convert(rasterFillArea), stroke);
//std::cout << "\nfillAreaWithUndo after applyAutoclose, tempRaster size:";
//std::cout << tempRaster->getSize();
//outputPixels("tempRaster", tempRaster);
}
AreaFiller filler(tempRaster);
@ -1072,24 +1035,15 @@ void fillAreaWithUndo(const TImageP &img, const TRectD &area, TStroke *stroke,
delete tileSet;
return;
}
//std::cout << "\nfillAreaWithUndo after calling AreaFiller.rectFill()";
//std::cout << tempRaster->getSize();
//outputPixels("tempRaster", tempRaster);
} else {
filler.strokeFill(stroke, cs, onlyUnfilled, colorType != LINES,
colorType != AREAS, rasterFillArea);
//std::cout << "\nfillAreaWithUndo after calling AreaFiller.strokeFill()";
//std::cout << tempRaster->getSize();
//outputPixels("tempRaster", tempRaster);
}
TPixelCM32 *tempPix = tempRaster->pixels();
TPixelCM32 *keepPix = ras->pixels();
TSystem::outputDebug(
"filltool.fillAreaWithUndo() final check, fillGaps is:" +
std::to_string(fillGaps) + "\n");
finishGapLines(tempRaster, rasterFillArea, ras, ras, ti->getPalette(), 0,
cs, closeStyleIndex, closeGaps);
@ -1109,9 +1063,6 @@ void fillAreaWithUndo(const TImageP &img, const TRectD &area, TStroke *stroke,
}
}
TSystem::outputDebug("filltool.fillAreaWithUndo() final check complete.\n");
//outputPixels("ras", ras);
TPalette *plt = ti->getPalette();
// !autopaintLines will temporary disable autopaint line feature
@ -1248,7 +1199,7 @@ void doFill(const TImageP &img, const TPointD &pos, FillParameters &params,
if (tileSaver.getTileSet()->getTileCount() != 0) {
static int count = 0;
TSystem::outputDebug("FILL" + std::to_string(count++) + "\n");
TSystem::outputDebug("FILL" + std::to_string(count++));
if (offs != TPoint())
for (int i = 0; i < tileSet->getTileCount(); i++) {
TTileSet::Tile *t = tileSet->editTile(i);
@ -2657,8 +2608,8 @@ void FillTool::leftButtonDrag(const TPointD &pos, const TMouseEvent &e) {
invalidate();
return;
}
TSystem::outputDebug("ok. pix=" + std::to_string(pix.getTone()) + "," +
std::to_string(pix.getPaint()) + "\n");
//TSystem::outputDebug("ok. pix=" + std::to_string(pix.getTone()) + "," +
// std::to_string(pix.getPaint()));
} else
return;
int closeStyleIndex = m_closeStyleIndex.getStyleIndex();

View file

@ -527,9 +527,6 @@ bool fill(const TRasterCM32P &r, const FillParameters &params,
tempRaster = r;
}
//TSystem::outputDebug("fill.cpp::fill() tempRaster just after TAutocloser(), fillGaps:" + std::to_string(fillGaps) + "\n");
//outputPixels("tempRaster", tempRaster); // issue 1151
/*-- getBounds returns the entire image --*/
TRect bbbox = tempRaster->getBounds();
@ -581,9 +578,6 @@ bool fill(const TRasterCM32P &r, const FillParameters &params,
cr = convertRaster2CM(refRaster);
refCMRaster = cr->clone();
//outputPixels("refCMRaster", refCMRaster);
//outputPixels("cr", cr);
refGapsClosed = TAutocloser(refCMRaster, autoCloseDistance,
AutocloseAngle, styleIndex, AutocloseOpacity)
.exec();
@ -591,7 +585,6 @@ bool fill(const TRasterCM32P &r, const FillParameters &params,
if (!gapsClosed) tempRaster = r->clone();
// Transfer the gap segments to the refRaster
TSystem::outputDebug("fill.cpp::fill() Transfer the gap segments to the refRaster, refGapsClosed:" + std::to_string(refGapsClosed) +", gapsClosed:" + std::to_string(gapsClosed));
TPixelCM32 *tempPix = tempRaster->pixels(0);
TPixelCM32 *refCMPix = refCMRaster->pixels(0);
TPixel32 *refPix = refRaster->pixels(0);
@ -601,7 +594,6 @@ bool fill(const TRasterCM32P &r, const FillParameters &params,
if (refCMPix->getInk() != styleIndex) continue;
*refPix = color;
if (fillGaps) {
TSystem::outputDebug("y:" + std::to_string(refCMY) + "," + "x:" + std::to_string(refCMX) + "," + std::to_string(refCMPix->getInk()) + ":" + std::to_string(refCMPix->getPaint()) + ":" + std::to_string(refCMPix->getTone()) + "\n");
tempPix->setInk(refCMPix->getInk());
tempPix->setTone(refCMPix->getTone());
}
@ -613,7 +605,6 @@ bool fill(const TRasterCM32P &r, const FillParameters &params,
if (fillGaps && !gapsClosed && !refGapsClosed) {
fillGaps = false;
TSystem::outputDebug("fill.cpp::fill(), refGapsClosed:" + std::to_string(refGapsClosed) + ", gapsClosed:" + std::to_string(gapsClosed) + ", set fillGaps to:" + std::to_string(fillGaps));
}
assert(fillDepth >= 0 && fillDepth < 16);
@ -661,10 +652,6 @@ bool fill(const TRasterCM32P &r, const FillParameters &params,
seeds.push(FillSeed(xa, xb, y, 1));
seeds.push(FillSeed(xa, xb, y, -1));
//std::cout << "\nfill.fill().outputPixels() tempRaster about to process close gaps for first seed, fillGaps is:";
//std::cout << fillGaps;
//outputPixels("tempRaster",tempRaster); // issue 1151
while (!seeds.empty()) {
FillSeed fs = seeds.top();
seeds.pop();
@ -758,8 +745,6 @@ bool fill(const TRasterCM32P &r, const FillParameters &params,
}
if (fillGaps) {
TSystem::outputDebug("fill.cpp::fill() final check, fillGaps is:" + std::to_string(fillGaps));
//outputPixels("tempRaster", tempRaster); // issue 1151
finishGapLines(tempRaster, bbbox, r, refCMRaster, params.m_palette, paintAtClickedPos, paint, closeStyleIndex, closeGaps);
TPixelCM32 *tempPix, *tempPixRestart;
tempPixRestart = tempPix = tempRaster->pixels();
@ -781,9 +766,6 @@ bool fill(const TRasterCM32P &r, const FillParameters &params,
}
}
TSystem::outputDebug("fill.cpp:fill final check finished----\n");
//outputPixels("r", r); // issue 1151
return saveBoxChanged;
}
@ -1193,31 +1175,8 @@ void fullColorFill(const TRaster32P &ras, const FillParameters &params,
}
}
TSystem::outputDebug("fill::fullColorFill() final check, fillGaps is:" + std::to_string(fillGaps));
//outputPixels("refCMRaster", refCMRaster); // issue 1151
// final check for close gap pixels
if (fillGaps) {
// ToDo - Can this be adpated to call finishGapClosePixels instead of the logic below?
// This logic doesn't use the palette color styles it uses RGB pixel values
//void finishGapLines(TRasterCM32P& rin, TRect& rect, const TRasterCM32P& rbefore,
// const TRasterCM32P& combined, TPalette* plt,
// int clickedColorStyle, int fillIndex, int closeColorStyle,
// bool closeGaps) {
//finishGapLines(
// refCMRaster,
// bbbox,
// cr,
// refCMRaster,
// params.m_palette,
// clickedPosColor,
// fillIndex,
// closeStyleIndex,
// closeGaps
//);
TPixelCM32 *tempPix = refCMRaster->pixels();
TPixel32 *keepPix = ras->pixels();

View file

@ -100,9 +100,7 @@ void restoreColors(const TRasterCM32P &r,
params.m_prevailing = false;
for (UINT i = 0; i < seeds.size(); i++) {
params.m_p = seeds[i].first;
//params.m_styleId = seeds[i].second;
//params.m_styleId = 0;
params.m_styleId = IGNORECOLORSTYLE; //set to ignore in final check
params.m_styleId = seeds[i].second;
fill(r, params);
}
}
@ -168,23 +166,9 @@ void finishGapLine(const TRasterCM32P &r, const TRasterCM32P &combined,
int paintStyle = 0;
int toneValue = 0;
TSystem::outputDebug(
"fillutil.finishGapLine(), closeGaps:" + std::to_string(closeGaps) +
", clickedColorStyle:" + std::to_string(clickedColorStyle) +
", fillColorStyle:" + std::to_string(fillColorStyle) +
", closeColorStyle:" + std::to_string(closeColorStyle));
TSystem::outputDebug("point is p.y:" + std::to_string(p.y) +
", p.x:" + std::to_string(p.x));
TSystem::outputDebug("r->getBounds()), ly:" + std::to_string(r->getBounds().getLy()) + ", lx:" + std::to_string(r->getBounds().getLx()));
TSystem::outputDebug("insideRect, ly:" + std::to_string(insideRect->getLy()) + ", lx : " + std::to_string(insideRect->getLx()));
TPixelCM32 *pix = pixels + (p.y * r->getWrap() + p.x);
TPixelCM32 *pixc = combinedPixels + (p.y * myCombined->getWrap() + p.x);
// outputPixels("r", r);
std::stack<TPoint> gapLinePixels;
std::stack<TPoint> seeds;
seeds.push(p);
@ -194,40 +178,18 @@ void finishGapLine(const TRasterCM32P &r, const TRasterCM32P &combined,
seeds.pop();
if (!r->getBounds().contains(p)) {
TSystem::outputDebug("fillutil.finishGapLine(), out of bounds at p.y:" +
std::to_string(p.y) +
", p.x:" + std::to_string(p.x));
continue;
}
if (insideRect && !insideRect->contains(p)) {
TSystem::outputDebug("fillutil.finishGapLine(), insideRect && !insideRect->contains(p) at p.y:" +
std::to_string(p.y) +
", p.x:" + std::to_string(p.x));
continue;
}
TPixelCM32 *pix = pixels + (p.y * r->getWrap() + p.x);
TPixelCM32 *pixc = combinedPixels + (p.y * myCombined->getWrap() + p.x);
TSystem::outputDebug("--------------------- checking pixel at: p.y:"
+ std::to_string(p.y)
+ ", p.x:" + std::to_string(p.x)
+ ", ink:" + std::to_string(pix->getInk())
+ ", paint:" + std::to_string(pix->getPaint())
+ ", tone:" + std::to_string(pix->getTone())
+ ", pixc "
+ ", ink:" + std::to_string(pixc->getInk())
+ ", paint:" + std::to_string(pixc->getPaint())
+ ", tone:" + std::to_string(pixc->getTone()));
// handle gap close pixel
if (pix->getInk() == GAP_CLOSE_USED) continue;
if (pix->getInk() == GAP_CLOSE_TEMP) {
TSystem::outputDebug("Gap Close pixel at p.y:" +
std::to_string(p.y) +
", p.x:" + std::to_string(p.x));
pix->setInk(GAP_CLOSE_USED);
// push to the gapLinePixels collection for later processing as a line
gapLinePixels.push(p);
@ -246,57 +208,37 @@ void finishGapLine(const TRasterCM32P &r, const TRasterCM32P &combined,
// a neighboring filled pixel
if (pix->getTone() > 0 && pix->getPaint() == fillColorStyle) {
filledNeighbor++;
TSystem::outputDebug(" Filled neighbor at p.y:" + std::to_string(p.y) +
", p.x:" + std::to_string(p.x) + " ");
continue;
}
// a neighboring fillable but unfilled pixel
if ((pix->getTone() == 255 && ((pix->getPaint() == clickedColorStyle) ||
(pix->getPaint() == 0) || (pix->getPaint() == IGNORECOLORSTYLE))) &&
if ((pix->getTone() == 255 &&
((pix->getPaint() == clickedColorStyle) || (pix->getPaint() == 0) ||
(pix->getPaint() == IGNORECOLORSTYLE))) &&
(pixc->getTone() == 255 && ((pixc->getPaint() == clickedColorStyle) ||
(pixc->getPaint() == 0)))) {
(pixc->getPaint() == 0)))) {
unfilledNeighbor++;
TSystem::outputDebug(" Unfilled neighbor at p.y:" + std::to_string(p.y) +
", p.x:" + std::to_string(p.x) + " ");
continue;
}
}
TSystem::outputDebug("fillutil.finishGapLine(), filledNeighbor:" +
std::to_string(filledNeighbor) + ", unfilledNeighbor:" +
std::to_string(unfilledNeighbor));
// determine the final disposition of the gap line
if (filledNeighbor > 0) {
if (unfilledNeighbor > 0) {
TSystem::outputDebug(
"fillutil.finishGapLine(), a needed line so let's finish it.");
if (closeGaps) {
TSystem::outputDebug("fillutil.finishGapLine(), finish as ink.");
inkStyle = closeColorStyle;
paintStyle = fillColorStyle;
toneValue = 0;
} else {
TSystem::outputDebug("fillutil.finishGapLine(), finish as paint.");
inkStyle = 0;
paintStyle = fillColorStyle;
toneValue = 255;
}
} else {
// surrounded by filled pixels, not a needed line, fill with fill color
TSystem::outputDebug(
"fillutil.finishGapLine(), No unfilled pixel neighbors, so fill with "
"fill color.");
inkStyle = 0;
paintStyle = fillColorStyle;
toneValue = 255;
}
} else {
// not a needed line, restore original pixels
// set to IGNORECOLORSTYLE to resolve in final check
TSystem::outputDebug(
"fillutil.finishGapLine(), not a needed line, set ink to a value to "
"ignore later.");
inkStyle = IGNORECOLORSTYLE;
paintStyle = 0;
toneValue = 0;
@ -307,13 +249,6 @@ void finishGapLine(const TRasterCM32P &r, const TRasterCM32P &combined,
p = gapLinePixels.top();
gapLinePixels.pop();
// do I need these checks since these points are already valid?
if (!r->getBounds().contains(p)) continue;
if (insideRect && !insideRect->contains(p)) continue;
TSystem::outputDebug("finishing point p.y:" + std::to_string(p.y) +
", p.x:" + std::to_string(p.x));
TPixelCM32 *pix = pixels + (p.y * r->getWrap() + p.x);
pix->setInk(inkStyle);
@ -346,14 +281,6 @@ void finishGapLines(TRasterCM32P &rin, TRect &rect, const TRasterCM32P &rbefore,
int tone = pix->getTone();
int ink = pix->getInk();
/* Pseudocode:
* Start the finish line procedure at the current pixel if:
* The ink colorstyle is TEMP_GAP_CLOSE
* The paint colorstyle of at least one neighboring pixel:
* is the same as the fill colorstyle
* has changed from its prior version
*/
if (ink == GAP_CLOSE_TEMP &&
(
// north