Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize floodfilling for expansion #1707

Merged
merged 12 commits into from
Apr 29, 2022
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