Skip to content

Commit

Permalink
Merge pull request #1707 from MrStevns/bucket-tool-optimizations2
Browse files Browse the repository at this point in the history
Optimize floodfilling for expansion
  • Loading branch information
chchwy authored Apr 29, 2022
2 parents 5423a76 + f34ecec commit be2cdb3
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 115 deletions.
26 changes: 12 additions & 14 deletions core_lib/src/graphics/bitmap/bitmapbucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,43 +149,40 @@ void BitmapBucket::paint(const QPointF updatedPoint, std::function<void(BucketSt
fillColor = tempColor.rgba();
}

BitmapImage replaceImage = BitmapImage(targetImage->bounds(), Qt::transparent);
BitmapImage* replaceImage = nullptr;

int expandValue = mProperties.bucketFillExpandEnabled ? mProperties.bucketFillExpand : 0;
bool didFloodFill = BitmapImage::floodFill(&replaceImage,
&referenceImage,
cameraRect,
point,
fillColor,
tolerance);
tolerance,
expandValue);

if (!didFloodFill) {
delete replaceImage;
return;
}
Q_ASSERT(replaceImage != nullptr);

state(BucketState::WillFillTarget, targetLayerIndex, currentFrameIndex);

if (mProperties.bucketFillExpandEnabled)
{
BitmapImage::expandFill(&replaceImage,
fillColor,
mProperties.bucketFillExpand);
}

if (mProperties.fillMode == 0)
{
targetImage->paste(&replaceImage);
targetImage->paste(replaceImage);
}
else if (mProperties.fillMode == 2)
{
targetImage->paste(&replaceImage, QPainter::CompositionMode_DestinationOver);
targetImage->paste(replaceImage, QPainter::CompositionMode_DestinationOver);
}
else
{
// fill mode replace
targetImage->paste(&replaceImage, QPainter::CompositionMode_DestinationOut);
targetImage->paste(replaceImage, QPainter::CompositionMode_DestinationOut);
// Reduce the opacity of the fill to match the new color
BitmapImage properColor(replaceImage.bounds(), QColor::fromRgba(origColor));
properColor.paste(&replaceImage, QPainter::CompositionMode_DestinationIn);
BitmapImage properColor(replaceImage->bounds(), QColor::fromRgba(origColor));
properColor.paste(replaceImage, QPainter::CompositionMode_DestinationIn);
// Write reduced-opacity fill image on top of target image
targetImage->paste(&properColor);
}
Expand All @@ -194,6 +191,7 @@ void BitmapBucket::paint(const QPointF updatedPoint, std::function<void(BucketSt
mFirstPaint = false;

targetImage->modification();
delete replaceImage;

state(BucketState::DidFillTarget, targetLayerIndex, currentFrameIndex);
}
Expand Down
Loading

0 comments on commit be2cdb3

Please sign in to comment.