Krita Source Code Documentation
Loading...
Searching...
No Matches
KisEncloseAndFillPainter::Private Class Reference

Public Member Functions

void applyPostProcessing (KisPixelSelectionSP mask, KisPaintDeviceSP referenceDevice) const
 
void computeEnclosedRegionsMask (KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
 
QVector< QPoint > getEnclosingContourPoints (KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect) const
 
void invertIfNeeded (KisPixelSelectionSP resultMask, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect) const
 
void invertMaskRect (KisPixelSelectionSP resultMask, const QRect &rect) const
 
 Private (KisEncloseAndFillPainter *q)
 
void removeContourRegions (KisPixelSelectionSP resultMask, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
 
void removeContourRegions (KisPixelSelectionSP resultMask, KisPixelSelectionSP enclosingMask, const QVector< QPoint > &enclosingPoints, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
 
void selectAllRegions (KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
 
void selectAllRegionsExceptFilledWithSpecificColor (KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
 
template<typename SelectionPolicy >
void selectAllRegionsExceptFilledWithSpecificColorGeneric (KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice, SelectionPolicy selectionPolicy) const
 
void selectAllRegionsExceptFilledWithSpecificColorOrTransparent (KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
 
void selectAllRegionsExceptFilledWithTransparent (KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
 
template<typename SelectionPolicy >
int selectDissimilarRegions (KisPixelSelectionSP resultMask, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice, SelectionPolicy selectionPolicy) const
 
void selectRegionsFilledWithSpecificColor (KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
 
template<typename SelectionPolicy >
void selectRegionsFilledWithSpecificColorGeneric (KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice, SelectionPolicy selectionPolicy) const
 
void selectRegionsFilledWithSpecificColorOrTransparent (KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
 
void selectRegionsFilledWithTransparent (KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
 
void selectRegionsFromContour (KisPixelSelectionSP resultMask, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
 
void selectRegionsFromContour (KisPixelSelectionSP resultMask, KisPixelSelectionSP enclosingMask, const QVector< QPoint > &enclosingPoints, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
 
void selectRegionsFromContourUntilColor (KisPixelSelectionSP resultMask, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice, const KoColor &color) const
 
void selectRegionsFromContourUntilColor (KisPixelSelectionSP resultMask, KisPixelSelectionSP enclosingMask, const QVector< QPoint > &enclosingPoints, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice, const KoColor &color) const
 
void selectRegionsFromContourUntilColorOrTransparent (KisPixelSelectionSP resultMask, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice, const KoColor &color) const
 
void selectRegionsFromContourUntilColorOrTransparent (KisPixelSelectionSP resultMask, KisPixelSelectionSP enclosingMask, const QVector< QPoint > &enclosingPoints, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice, const KoColor &color) const
 
void selectRegionsSurroundedBySpecificColor (KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
 
template<typename SelectionPolicy >
void selectRegionsSurroundedBySpecificColorGeneric (KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice, SelectionPolicy selectionPolicy, bool colorOrTransparent=false) const
 
void selectRegionsSurroundedBySpecificColorOrTransparent (KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
 
void selectRegionsSurroundedByTransparent (KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
 
template<typename SelectionPolicy >
int selectSimilarRegions (KisPixelSelectionSP resultMask, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice, SelectionPolicy selectionPolicy) const
 

Public Attributes

QRect imageRect
 
KisEncloseAndFillPainterq {nullptr}
 
KoColor regionSelectionColor
 
bool regionSelectionIncludeContourRegions {true}
 
bool regionSelectionIncludeSurroundingRegions {true}
 
bool regionSelectionInvert {false}
 
RegionSelectionMethod regionSelectionMethod {SelectAllRegions}
 

Detailed Description

Definition at line 126 of file KisEncloseAndFillPainter.cpp.

Constructor & Destructor Documentation

◆ Private()

KisEncloseAndFillPainter::Private::Private ( KisEncloseAndFillPainter * q)
inline

Definition at line 137 of file KisEncloseAndFillPainter.cpp.

137: q(q) {}

Member Function Documentation

◆ applyPostProcessing()

void KisEncloseAndFillPainter::Private::applyPostProcessing ( KisPixelSelectionSP mask,
KisPaintDeviceSP referenceDevice ) const

Definition at line 873 of file KisEncloseAndFillPainter.cpp.

875{
876 if (q->sizemod() > 0) {
878 KisGrowUntilDarkestPixelSelectionFilter biggy(q->sizemod(), referenceDevice);
879 biggy.process(
880 mask,
881 mask->selectedRect().adjusted(
882 -q->sizemod(), -q->sizemod(), q->sizemod(), q->sizemod()
883 )
884 );
885 } else {
887 biggy.process(
888 mask,
889 mask->selectedRect().adjusted(
890 -q->sizemod(), -q->sizemod(), q->sizemod(), q->sizemod()
891 )
892 );
893 }
894 } else if (q->sizemod() < 0) {
895 KisShrinkSelectionFilter tiny(-q->sizemod(), -q->sizemod(), false);
896 tiny.process(mask, mask->selectedRect());
897 }
898 // Since the feathering already smooths the selection, the antiAlias
899 // is not applied if we must feather
900 if (q->feather() > 0) {
902 feathery.process(mask, mask->selectedRect().adjusted(-q->feather(), -q->feather(), q->feather(), q->feather()));
903 } else if (q->antiAlias()) {
904 KisAntiAliasSelectionFilter antiAliasFilter;
905 antiAliasFilter.process(mask, mask->selectedRect());
906 }
907}
AntiAlias filter for selections inspired by FXAA.
void process(KisPixelSelectionSP pixelSelection, const QRect &rect) override
int sizemod() const
bool antiAlias() const
uint feather() const
bool stopGrowingAtDarkestPixel() const
Filter that dilates a selection and that can stop dilating adaptively at areas of higher darkness or ...

References KisFeatherSelectionFilter::process(), KisGrowSelectionFilter::process(), KisShrinkSelectionFilter::process(), KisAntiAliasSelectionFilter::process(), KisGrowUntilDarkestPixelSelectionFilter::process(), KisPainter::q, and KisPixelSelection::selectedRect().

◆ computeEnclosedRegionsMask()

void KisEncloseAndFillPainter::Private::computeEnclosedRegionsMask ( KisPixelSelectionSP resultMask,
QRect * resultMaskRect,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice ) const

Definition at line 463 of file KisEncloseAndFillPainter.cpp.

468{
469 // Create the regions mask
470 switch (regionSelectionMethod) {
471 case SelectAllRegions:
472 selectAllRegions(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice);
473 break;
475 selectRegionsFilledWithSpecificColor(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice);
476 break;
478 selectRegionsFilledWithTransparent(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice);
479 break;
481 selectRegionsFilledWithSpecificColorOrTransparent(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice);
482 break;
484 selectAllRegionsExceptFilledWithSpecificColor(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice);
485 break;
487 selectAllRegionsExceptFilledWithTransparent(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice);
488 break;
490 selectAllRegionsExceptFilledWithSpecificColorOrTransparent(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice);
491 break;
493 selectRegionsSurroundedBySpecificColor(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice);
494 break;
496 selectRegionsSurroundedByTransparent(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice);
497 break;
499 selectRegionsSurroundedBySpecificColorOrTransparent(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice);
500 break;
501 default: return;
502 }
503}
void selectRegionsFilledWithTransparent(KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
void selectRegionsFilledWithSpecificColorOrTransparent(KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
void selectRegionsSurroundedByTransparent(KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
void selectAllRegionsExceptFilledWithSpecificColorOrTransparent(KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
void selectRegionsSurroundedBySpecificColor(KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
void selectRegionsFilledWithSpecificColor(KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
void selectAllRegionsExceptFilledWithSpecificColor(KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
void selectAllRegionsExceptFilledWithTransparent(KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
void selectRegionsSurroundedBySpecificColorOrTransparent(KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
void selectAllRegions(KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const

References regionSelectionMethod, selectAllRegions(), KisEncloseAndFillPainter::SelectAllRegions, selectAllRegionsExceptFilledWithSpecificColor(), KisEncloseAndFillPainter::SelectAllRegionsExceptFilledWithSpecificColor, selectAllRegionsExceptFilledWithSpecificColorOrTransparent(), KisEncloseAndFillPainter::SelectAllRegionsExceptFilledWithSpecificColorOrTransparent, selectAllRegionsExceptFilledWithTransparent(), KisEncloseAndFillPainter::SelectAllRegionsExceptFilledWithTransparent, selectRegionsFilledWithSpecificColor(), KisEncloseAndFillPainter::SelectRegionsFilledWithSpecificColor, selectRegionsFilledWithSpecificColorOrTransparent(), KisEncloseAndFillPainter::SelectRegionsFilledWithSpecificColorOrTransparent, selectRegionsFilledWithTransparent(), KisEncloseAndFillPainter::SelectRegionsFilledWithTransparent, selectRegionsSurroundedBySpecificColor(), KisEncloseAndFillPainter::SelectRegionsSurroundedBySpecificColor, selectRegionsSurroundedBySpecificColorOrTransparent(), KisEncloseAndFillPainter::SelectRegionsSurroundedBySpecificColorOrTransparent, selectRegionsSurroundedByTransparent(), and KisEncloseAndFillPainter::SelectRegionsSurroundedByTransparent.

◆ getEnclosingContourPoints()

QVector< QPoint > KisEncloseAndFillPainter::Private::getEnclosingContourPoints ( KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect ) const

Definition at line 794 of file KisEncloseAndFillPainter.cpp.

796{
797 QVector<QPoint> enclosingPoints;
798 const int scanlineWidth = enclosingMaskRect.width() + 2;
799 QVector<quint8> buffer(scanlineWidth * 3);
800 quint8 *scanlines[3] = {buffer.data(), buffer.data() + scanlineWidth, buffer.data() + scanlineWidth * 2};
801 // Initialize the buffer
802 // Top, outside row
803 memset(scanlines[0], MIN_SELECTED, scanlineWidth);
804 // Middle row
805 // Left, outside pixel
806 *(scanlines[1]) = MIN_SELECTED;
807 // Middle, inside pixels
808 enclosingMask->readBytes(scanlines[1] + 1, enclosingMaskRect.x(), enclosingMaskRect.y(), enclosingMaskRect.width(), 1);
809 // Right, outside pixel
810 *(scanlines[2] - 1) = MIN_SELECTED;
811 // Bottom row
812 if (enclosingMaskRect.height() == 1) {
813 // Bottom, outside row
814 memset(scanlines[2], MIN_SELECTED, scanlineWidth);
815 } else {
816 // Left, outside pixel
817 *(scanlines[2]) = MIN_SELECTED;
818 // Middle, inside pixels
819 enclosingMask->readBytes(scanlines[2] + 1, enclosingMaskRect.x(), enclosingMaskRect.y() + 1, enclosingMaskRect.width(), 1);
820 // Right, outside pixel
821 *(scanlines[2] + scanlineWidth - 1) = MIN_SELECTED;
822 }
823
824 for (int y = 0; y < enclosingMaskRect.height(); ++y) {
825 if (y > 0) {
826 // Rotate pointers
827 quint8 *tmp = scanlines[0];
828 scanlines[0] = scanlines[1];
829 scanlines[1] = scanlines[2];
830 scanlines[2] = tmp;
831 // Read new row
832 if (y == enclosingMaskRect.height() - 1) {
833 // Bottom, outside row
834 memset(scanlines[2], MIN_SELECTED, scanlineWidth);
835 } else {
836 // Left, outside pixel
837 *(scanlines[2]) = MIN_SELECTED;
838 // Middle, inside pixels
839 enclosingMask->readBytes(scanlines[2] + 1, enclosingMaskRect.x(), enclosingMaskRect.y() + y + 1, enclosingMaskRect.width(), 1);
840 // Right, outside pixel
841 *(scanlines[2] + scanlineWidth - 1) = MIN_SELECTED;
842 }
843 }
844 const quint8 *topPixel = scanlines[0] + 1;
845 const quint8 *middlePixel = scanlines[1] + 1;
846 const quint8 *bottomPixel = scanlines[2] + 1;
847 for (int x = 0; x < enclosingMaskRect.width(); ++x, ++topPixel, ++middlePixel, ++bottomPixel) {
848 // Continue if the current pixel is not in the selection
849 if (*middlePixel == MIN_SELECTED) {
850 continue;
851 }
852 // Get all eight neighbor pixels. If at least one of them is not
853 // in the selection then the current pixel is a border pixel and
854 // we add it to the list
855 quint8 neighbors = 0;
856 neighbors |= (*(topPixel - 1) == MIN_SELECTED) << 7;
857 neighbors |= (*(topPixel ) == MIN_SELECTED) << 6;
858 neighbors |= (*(topPixel + 1) == MIN_SELECTED) << 5;
859 neighbors |= (*(middlePixel - 1) == MIN_SELECTED) << 4;
860 neighbors |= (*(middlePixel + 1) == MIN_SELECTED) << 3;
861 neighbors |= (*(bottomPixel - 1) == MIN_SELECTED) << 2;
862 neighbors |= (*(bottomPixel ) == MIN_SELECTED) << 1;
863 neighbors |= (*(bottomPixel + 1) == MIN_SELECTED) << 0;
864 if (neighbors != 0) {
865 enclosingPoints.push_back(QPoint(enclosingMaskRect.x() + x, enclosingMaskRect.y() + y));
866 }
867 }
868 }
869
870 return enclosingPoints;
871}
void readBytes(quint8 *data, qint32 x, qint32 y, qint32 w, qint32 h) const
const quint8 MIN_SELECTED
Definition kis_global.h:33

References MIN_SELECTED, and KisPaintDevice::readBytes().

◆ invertIfNeeded()

void KisEncloseAndFillPainter::Private::invertIfNeeded ( KisPixelSelectionSP resultMask,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect ) const

Definition at line 909 of file KisEncloseAndFillPainter.cpp.

910{
912 return;
913 }
914 invertMaskRect(resultMask, enclosingMaskRect);
915 // Since, after inverting, the mask includes the region outside the enclosing
916 // mask, we must intersect the current mask with the enclosing mask. The result
917 // is a mask that includes all the closed regions inside the enclosing mask
918 resultMask->applySelection(enclosingMask, SELECTION_INTERSECT);
919}
@ SELECTION_INTERSECT
void invertMaskRect(KisPixelSelectionSP resultMask, const QRect &rect) const
void applySelection(KisPixelSelectionSP selection, SelectionAction action)

References KisPixelSelection::applySelection(), KisEncloseAndFillPainter::regionSelectionInvert(), and SELECTION_INTERSECT.

◆ invertMaskRect()

void KisEncloseAndFillPainter::Private::invertMaskRect ( KisPixelSelectionSP resultMask,
const QRect & rect ) const

Definition at line 1125 of file KisEncloseAndFillPainter.cpp.

1126{
1127 KisSequentialIterator resultMaskIterator(resultMask, rect);
1128 while (resultMaskIterator.nextPixel()) {
1129 *resultMaskIterator.rawData() = MAX_SELECTED - *resultMaskIterator.oldRawData();
1130 }
1131}
const quint8 MAX_SELECTED
Definition kis_global.h:32

References MAX_SELECTED, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::oldRawData(), and KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData().

◆ removeContourRegions() [1/2]

void KisEncloseAndFillPainter::Private::removeContourRegions ( KisPixelSelectionSP resultMask,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice ) const

Definition at line 1101 of file KisEncloseAndFillPainter.cpp.

1105{
1106 const QVector<QPoint> enclosingPoints = getEnclosingContourPoints(enclosingMask, enclosingMaskRect);
1107 removeContourRegions(resultMask, enclosingMask, enclosingPoints, enclosingMaskRect, referenceDevice);
1108}
void removeContourRegions(KisPixelSelectionSP resultMask, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const
QVector< QPoint > getEnclosingContourPoints(KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect) const

◆ removeContourRegions() [2/2]

void KisEncloseAndFillPainter::Private::removeContourRegions ( KisPixelSelectionSP resultMask,
KisPixelSelectionSP enclosingMask,
const QVector< QPoint > & enclosingPoints,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice ) const

Definition at line 1110 of file KisEncloseAndFillPainter.cpp.

1115{
1116 if (enclosingPoints.isEmpty()) {
1117 return;
1118 }
1119
1120 KisPixelSelectionSP contourRegionsMask = new KisPixelSelection(new KisSelectionDefaultBounds(enclosingMask));
1121 selectRegionsFromContour(contourRegionsMask, enclosingMask, enclosingMaskRect, referenceDevice);
1122 resultMask->applySelection(contourRegionsMask, SELECTION_SUBTRACT);
1123}
@ SELECTION_SUBTRACT
void selectRegionsFromContour(KisPixelSelectionSP resultMask, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice) const

References KisPixelSelection::applySelection(), and SELECTION_SUBTRACT.

◆ selectAllRegions()

void KisEncloseAndFillPainter::Private::selectAllRegions ( KisPixelSelectionSP resultMask,
QRect * resultMaskRect,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice ) const

Definition at line 505 of file KisEncloseAndFillPainter.cpp.

510{
512 // Nothing is selected in this case, so return early
513 return;
514 }
515 resultMask->applySelection(enclosingMask, SELECTION_REPLACE);
518 selectRegionsFromContour(mask, enclosingMask, enclosingMaskRect, referenceDevice);
519 resultMask->applySelection(mask, SELECTION_SUBTRACT);
520 }
521 if (resultMaskRect) {
522 *resultMaskRect = resultMask->selectedExactRect();
523 }
524}
@ SELECTION_REPLACE
QRect selectedExactRect() const

References KisPixelSelection::applySelection(), KisEncloseAndFillPainter::regionSelectionIncludeContourRegions(), KisEncloseAndFillPainter::regionSelectionInvert(), KisPixelSelection::selectedExactRect(), SELECTION_REPLACE, and SELECTION_SUBTRACT.

◆ selectAllRegionsExceptFilledWithSpecificColor()

void KisEncloseAndFillPainter::Private::selectAllRegionsExceptFilledWithSpecificColor ( KisPixelSelectionSP resultMask,
QRect * resultMaskRect,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice ) const

Definition at line 615 of file KisEncloseAndFillPainter.cpp.

620{
621 using namespace KisEncloseAndFillPainterDetail;
622 const int softness = 100 - q->opacitySpread();
623 if (softness == 0) {
625 selectAllRegionsExceptFilledWithSpecificColorGeneric(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice, policy);
626 } else {
628 selectAllRegionsExceptFilledWithSpecificColorGeneric(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice, policy);
629 }
630}
void selectAllRegionsExceptFilledWithSpecificColorGeneric(KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice, SelectionPolicy selectionPolicy) const
int fillThreshold() const
int opacitySpread() const
const KoColorSpace * colorSpace() const

References KisPaintDevice::colorSpace(), KisPainter::q, and KisEncloseAndFillPainter::regionSelectionColor().

◆ selectAllRegionsExceptFilledWithSpecificColorGeneric()

template<typename SelectionPolicy >
void KisEncloseAndFillPainter::Private::selectAllRegionsExceptFilledWithSpecificColorGeneric ( KisPixelSelectionSP resultMask,
QRect * resultMaskRect,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice,
SelectionPolicy selectionPolicy ) const

Definition at line 668 of file KisEncloseAndFillPainter.cpp.

674{
675 const QVector<QPoint> enclosingPoints = getEnclosingContourPoints(enclosingMask, enclosingMaskRect);
676 // Remove the regions that touch the enclosing area
677 if (selectDissimilarRegions(resultMask, enclosingMask, enclosingMaskRect, referenceDevice, selectionPolicy) == 0) {
678 if (resultMaskRect) {
679 *resultMaskRect = QRect();
680 }
681 return;
682 }
684 // Here we don't use removeContourRegions because the contour regions
685 // in the mask may include multiple connected color regions
687 selectRegionsFromContour(mask, enclosingMask, enclosingPoints, enclosingMaskRect, referenceDevice);
688 resultMask->applySelection(mask, SELECTION_SUBTRACT);
689 }
690 if (resultMaskRect) {
691 *resultMaskRect = resultMask->selectedExactRect();
692 }
693}
int selectDissimilarRegions(KisPixelSelectionSP resultMask, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice, SelectionPolicy selectionPolicy) const

References KisPixelSelection::applySelection(), KisEncloseAndFillPainter::regionSelectionIncludeContourRegions(), KisPixelSelection::selectedExactRect(), and SELECTION_SUBTRACT.

◆ selectAllRegionsExceptFilledWithSpecificColorOrTransparent()

void KisEncloseAndFillPainter::Private::selectAllRegionsExceptFilledWithSpecificColorOrTransparent ( KisPixelSelectionSP resultMask,
QRect * resultMaskRect,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice ) const

Definition at line 649 of file KisEncloseAndFillPainter.cpp.

654{
655 using namespace KisEncloseAndFillPainterDetail;
656 const int softness = 100 - q->opacitySpread();
657 // Here we must compute the specific color and transparent masks separately
658 if (softness == 0) {
660 selectAllRegionsExceptFilledWithSpecificColorGeneric(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice, policy);
661 } else {
663 selectAllRegionsExceptFilledWithSpecificColorGeneric(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice, policy);
664 }
665}

References KisPaintDevice::colorSpace(), KisPainter::q, and KisEncloseAndFillPainter::regionSelectionColor().

◆ selectAllRegionsExceptFilledWithTransparent()

void KisEncloseAndFillPainter::Private::selectAllRegionsExceptFilledWithTransparent ( KisPixelSelectionSP resultMask,
QRect * resultMaskRect,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice ) const

Definition at line 632 of file KisEncloseAndFillPainter.cpp.

637{
638 using namespace KisEncloseAndFillPainterDetail;
639 const int softness = 100 - q->opacitySpread();
640 if (softness == 0) {
642 selectAllRegionsExceptFilledWithSpecificColorGeneric(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice, policy);
643 } else {
644 SoftSelectionPolicy<TransparentDifferencePolicy> policy(referenceDevice->colorSpace(), KoColor::createTransparent(referenceDevice->colorSpace()), q->fillThreshold(), softness);
645 selectAllRegionsExceptFilledWithSpecificColorGeneric(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice, policy);
646 }
647}
static KoColor createTransparent(const KoColorSpace *cs)
Definition KoColor.cpp:681

References KisPaintDevice::colorSpace(), KoColor::createTransparent(), and KisPainter::q.

◆ selectDissimilarRegions()

template<typename SelectionPolicy >
int KisEncloseAndFillPainter::Private::selectDissimilarRegions ( KisPixelSelectionSP resultMask,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice,
SelectionPolicy selectionPolicy ) const

Definition at line 947 of file KisEncloseAndFillPainter.cpp.

952{
953 KisSequentialIterator resultMaskIterator(resultMask, enclosingMaskRect);
954 KisSequentialConstIterator enclosingMaskIterator(enclosingMask, enclosingMaskRect);
955 KisSequentialConstIterator referenceDeviceIterator(referenceDevice, enclosingMaskRect);
956 int nPixels = 0;
957 // Select all the pixels using the given selection policy
958 while (resultMaskIterator.nextPixel() && enclosingMaskIterator.nextPixel() && referenceDeviceIterator.nextPixel()) {
959 if (*enclosingMaskIterator.oldRawData() == MIN_SELECTED) {
960 continue;
961 }
962 const quint8 selection = MAX_SELECTED - selectionPolicy.getSelectionFor(referenceDeviceIterator.oldRawData());
963 if (selection > MIN_SELECTED) {
964 *resultMaskIterator.rawData() = selection;
965 ++nPixels;
966 }
967 }
968 return nPixels;
969}
KisSelectionSP selection

References MAX_SELECTED, MIN_SELECTED, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::oldRawData(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData(), and KisPainter::selection.

◆ selectRegionsFilledWithSpecificColor()

void KisEncloseAndFillPainter::Private::selectRegionsFilledWithSpecificColor ( KisPixelSelectionSP resultMask,
QRect * resultMaskRect,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice ) const

Definition at line 526 of file KisEncloseAndFillPainter.cpp.

531{
532 using namespace KisEncloseAndFillPainterDetail;
533 const int softness = 100 - q->opacitySpread();
534 if (softness == 0) {
536 selectRegionsFilledWithSpecificColorGeneric(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice, policy);
537 } else {
539 selectRegionsFilledWithSpecificColorGeneric(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice, policy);
540 }
541}
void selectRegionsFilledWithSpecificColorGeneric(KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice, SelectionPolicy selectionPolicy) const

References KisPaintDevice::colorSpace(), KisPainter::q, and KisEncloseAndFillPainter::regionSelectionColor().

◆ selectRegionsFilledWithSpecificColorGeneric()

template<typename SelectionPolicy >
void KisEncloseAndFillPainter::Private::selectRegionsFilledWithSpecificColorGeneric ( KisPixelSelectionSP resultMask,
QRect * resultMaskRect,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice,
SelectionPolicy selectionPolicy ) const

Definition at line 591 of file KisEncloseAndFillPainter.cpp.

597{
598 // Select all the pixels using the given selection policy and
599 // return if there are no selected pixels
600 if (selectSimilarRegions(resultMask, enclosingMask, enclosingMaskRect, referenceDevice, selectionPolicy) == 0) {
601 if (resultMaskRect) {
602 *resultMaskRect = QRect();
603 }
604 return;
605 }
606 // Remove the regions that touch the enclosing area
608 removeContourRegions(resultMask, enclosingMask, enclosingMaskRect, referenceDevice);
609 }
610 if (resultMaskRect) {
611 *resultMaskRect = resultMask->selectedExactRect();
612 }
613}
int selectSimilarRegions(KisPixelSelectionSP resultMask, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice, SelectionPolicy selectionPolicy) const

References KisEncloseAndFillPainter::regionSelectionIncludeContourRegions(), and KisPixelSelection::selectedExactRect().

◆ selectRegionsFilledWithSpecificColorOrTransparent()

void KisEncloseAndFillPainter::Private::selectRegionsFilledWithSpecificColorOrTransparent ( KisPixelSelectionSP resultMask,
QRect * resultMaskRect,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice ) const

Definition at line 560 of file KisEncloseAndFillPainter.cpp.

565{
566 using namespace KisEncloseAndFillPainterDetail;
567 const int softness = 100 - q->opacitySpread();
568 // Here we must compute the specific color and transparent masks separately
569 // so that the contour regions can be removed independently if they are
570 // transparent or of the specific color and are connected
571 KisPixelSelectionSP resultMaskTransparent = new KisPixelSelection(new KisSelectionDefaultBounds(resultMask));
572 if (softness == 0) {
574 selectRegionsFilledWithSpecificColorGeneric(resultMask, nullptr, enclosingMask, enclosingMaskRect, referenceDevice, colorPolicy);
576 selectRegionsFilledWithSpecificColorGeneric(resultMaskTransparent, nullptr, enclosingMask, enclosingMaskRect, referenceDevice, transparentPolicy);
577 } else {
579 selectRegionsFilledWithSpecificColorGeneric(resultMask, nullptr, enclosingMask, enclosingMaskRect, referenceDevice, colorPolicy);
581 selectRegionsFilledWithSpecificColorGeneric(resultMaskTransparent, nullptr, enclosingMask, enclosingMaskRect, referenceDevice, transparentPolicy);
582 }
583 // Compose the masks
584 resultMask->applySelection(resultMaskTransparent, SELECTION_ADD);
585 if (resultMaskRect) {
586 *resultMaskRect = resultMask->selectedExactRect();
587 }
588}
@ SELECTION_ADD

References KisPixelSelection::applySelection(), KisPaintDevice::colorSpace(), KisPainter::q, KisEncloseAndFillPainter::regionSelectionColor(), KisPixelSelection::selectedExactRect(), and SELECTION_ADD.

◆ selectRegionsFilledWithTransparent()

void KisEncloseAndFillPainter::Private::selectRegionsFilledWithTransparent ( KisPixelSelectionSP resultMask,
QRect * resultMaskRect,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice ) const

Definition at line 543 of file KisEncloseAndFillPainter.cpp.

548{
549 using namespace KisEncloseAndFillPainterDetail;
550 const int softness = 100 - q->opacitySpread();
551 if (softness == 0) {
553 selectRegionsFilledWithSpecificColorGeneric(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice, policy);
554 } else {
556 selectRegionsFilledWithSpecificColorGeneric(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice, policy);
557 }
558}

References KisPaintDevice::colorSpace(), KisPainter::q, and KisEncloseAndFillPainter::regionSelectionColor().

◆ selectRegionsFromContour() [1/2]

void KisEncloseAndFillPainter::Private::selectRegionsFromContour ( KisPixelSelectionSP resultMask,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice ) const

Definition at line 971 of file KisEncloseAndFillPainter.cpp.

975{
976 const QVector<QPoint> enclosingPoints = getEnclosingContourPoints(enclosingMask, enclosingMaskRect);
977 selectRegionsFromContour(resultMask, enclosingMask, enclosingPoints, enclosingMaskRect, referenceDevice);
978}

◆ selectRegionsFromContour() [2/2]

void KisEncloseAndFillPainter::Private::selectRegionsFromContour ( KisPixelSelectionSP resultMask,
KisPixelSelectionSP enclosingMask,
const QVector< QPoint > & enclosingPoints,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice ) const

Definition at line 980 of file KisEncloseAndFillPainter.cpp.

985{
986 if (enclosingPoints.isEmpty()) {
987 return;
988 }
989 const QRect inclusionRect = q->device()->defaultBounds()->wrapAroundMode()
990 ? enclosingMaskRect
991 : imageRect;
992 // Here we just fill all the areas from the border towards inside
993 for (const QPoint &point : enclosingPoints) {
994 if (!inclusionRect.contains(point)) {
995 continue;
996 }
997 // Continue if the region under the point was already filled
998 if (*(resultMask->pixel(point).data()) == MAX_SELECTED) {
999 continue;
1000 }
1002 KisScanlineFill gc(referenceDevice, point, inclusionRect);
1003 gc.setThreshold(q->fillThreshold());
1004 gc.setOpacitySpread(q->opacitySpread());
1005 gc.setCloseGap(q->closeGap());
1006 // Use the enclosing mask as boundary so that we don't fill
1007 // potentially large regions on the outside
1008 gc.fillSelection(mask, enclosingMask);
1009 resultMask->applySelection(mask, SELECTION_ADD);
1010 }
1011}
virtual bool wrapAroundMode() const =0
uint closeGap() const
bool pixel(qint32 x, qint32 y, QColor *c) const
KisDefaultBoundsBaseSP defaultBounds() const
KisPaintDeviceSP device

References KisPixelSelection::applySelection(), KisPaintDevice::defaultBounds(), KisPainter::device, KisScanlineFill::fillSelection(), MAX_SELECTED, KisPaintDevice::pixel(), KisPainter::q, SELECTION_ADD, KisScanlineFill::setCloseGap(), KisScanlineFill::setOpacitySpread(), KisScanlineFill::setThreshold(), and KisDefaultBoundsBase::wrapAroundMode().

◆ selectRegionsFromContourUntilColor() [1/2]

void KisEncloseAndFillPainter::Private::selectRegionsFromContourUntilColor ( KisPixelSelectionSP resultMask,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice,
const KoColor & color ) const

Definition at line 1013 of file KisEncloseAndFillPainter.cpp.

1018{
1019 const QVector<QPoint> enclosingPoints = getEnclosingContourPoints(enclosingMask, enclosingMaskRect);
1020 selectRegionsFromContourUntilColor(resultMask, enclosingMask, enclosingPoints, enclosingMaskRect, referenceDevice, color);
1021}
void selectRegionsFromContourUntilColor(KisPixelSelectionSP resultMask, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice, const KoColor &color) const

◆ selectRegionsFromContourUntilColor() [2/2]

void KisEncloseAndFillPainter::Private::selectRegionsFromContourUntilColor ( KisPixelSelectionSP resultMask,
KisPixelSelectionSP enclosingMask,
const QVector< QPoint > & enclosingPoints,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice,
const KoColor & color ) const

Definition at line 1023 of file KisEncloseAndFillPainter.cpp.

1029{
1030 if (enclosingPoints.isEmpty()) {
1031 return;
1032 }
1033 const QRect inclusionRect = q->device()->defaultBounds()->wrapAroundMode()
1034 ? enclosingMaskRect
1035 : imageRect;
1036 // Here we just fill all the areas from the border towards inside until the specific color
1037 for (const QPoint &point : enclosingPoints) {
1038 if (!inclusionRect.contains(point)) {
1039 continue;
1040 }
1041 // Continue if the region under the point was already filled
1042 if (*(resultMask->pixel(point).data()) == MAX_SELECTED) {
1043 continue;
1044 }
1046 KisScanlineFill gc(referenceDevice, point, inclusionRect);
1047 gc.setThreshold(q->fillThreshold());
1048 gc.setOpacitySpread(q->opacitySpread());
1049 gc.setCloseGap(q->closeGap());
1050 // Use the enclosing mask as boundary so that we don't fill
1051 // potentially large regions in the outside
1052 gc.fillSelectionUntilColor(mask, color, enclosingMask);
1053 resultMask->applySelection(mask, SELECTION_ADD);
1054 }
1055}

References KisPixelSelection::applySelection(), KisPaintDevice::defaultBounds(), KisPainter::device, KisScanlineFill::fillSelectionUntilColor(), MAX_SELECTED, KisPaintDevice::pixel(), KisPainter::q, SELECTION_ADD, KisScanlineFill::setCloseGap(), KisScanlineFill::setOpacitySpread(), KisScanlineFill::setThreshold(), and KisDefaultBoundsBase::wrapAroundMode().

◆ selectRegionsFromContourUntilColorOrTransparent() [1/2]

void KisEncloseAndFillPainter::Private::selectRegionsFromContourUntilColorOrTransparent ( KisPixelSelectionSP resultMask,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice,
const KoColor & color ) const

Definition at line 1057 of file KisEncloseAndFillPainter.cpp.

1062{
1063 const QVector<QPoint> enclosingPoints = getEnclosingContourPoints(enclosingMask, enclosingMaskRect);
1064 selectRegionsFromContourUntilColorOrTransparent(resultMask, enclosingMask, enclosingPoints, enclosingMaskRect, referenceDevice, color);
1065}
void selectRegionsFromContourUntilColorOrTransparent(KisPixelSelectionSP resultMask, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice, const KoColor &color) const

◆ selectRegionsFromContourUntilColorOrTransparent() [2/2]

void KisEncloseAndFillPainter::Private::selectRegionsFromContourUntilColorOrTransparent ( KisPixelSelectionSP resultMask,
KisPixelSelectionSP enclosingMask,
const QVector< QPoint > & enclosingPoints,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice,
const KoColor & color ) const

Definition at line 1067 of file KisEncloseAndFillPainter.cpp.

1073{
1074 if (enclosingPoints.isEmpty()) {
1075 return;
1076 }
1077 const QRect inclusionRect = q->device()->defaultBounds()->wrapAroundMode()
1078 ? enclosingMaskRect
1079 : imageRect;
1080 // Here we just fill all the areas from the border towards inside until the specific color
1081 for (const QPoint &point : enclosingPoints) {
1082 if (!inclusionRect.contains(point)) {
1083 continue;
1084 }
1085 // Continue if the region under the point was already filled
1086 if (*(resultMask->pixel(point).data()) == MAX_SELECTED) {
1087 continue;
1088 }
1090 KisScanlineFill gc(referenceDevice, point, inclusionRect);
1091 gc.setThreshold(q->fillThreshold());
1092 gc.setOpacitySpread(q->opacitySpread());
1093 gc.setCloseGap(q->closeGap());
1094 // Use the enclosing mask as boundary so that we don't fill
1095 // potentially large regions in the outside
1096 gc.fillSelectionUntilColorOrTransparent(mask, color, enclosingMask);
1097 resultMask->applySelection(mask, SELECTION_ADD);
1098 }
1099}

References KisPixelSelection::applySelection(), KisPaintDevice::defaultBounds(), KisPainter::device, KisScanlineFill::fillSelectionUntilColorOrTransparent(), MAX_SELECTED, KisPaintDevice::pixel(), KisPainter::q, SELECTION_ADD, KisScanlineFill::setCloseGap(), KisScanlineFill::setOpacitySpread(), KisScanlineFill::setThreshold(), and KisDefaultBoundsBase::wrapAroundMode().

◆ selectRegionsSurroundedBySpecificColor()

void KisEncloseAndFillPainter::Private::selectRegionsSurroundedBySpecificColor ( KisPixelSelectionSP resultMask,
QRect * resultMaskRect,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice ) const

Definition at line 695 of file KisEncloseAndFillPainter.cpp.

700{
701 using namespace KisEncloseAndFillPainterDetail;
702 const int softness = 100 - q->opacitySpread();
703 if (softness == 0) {
705 selectRegionsSurroundedBySpecificColorGeneric(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice, policy);
706 } else {
708 selectRegionsSurroundedBySpecificColorGeneric(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice, policy);
709 }
710}
void selectRegionsSurroundedBySpecificColorGeneric(KisPixelSelectionSP resultMask, QRect *resultMaskRect, KisPixelSelectionSP enclosingMask, const QRect &enclosingMaskRect, KisPaintDeviceSP referenceDevice, SelectionPolicy selectionPolicy, bool colorOrTransparent=false) const

References KisPaintDevice::colorSpace(), KisPainter::q, and KisEncloseAndFillPainter::regionSelectionColor().

◆ selectRegionsSurroundedBySpecificColorGeneric()

template<typename SelectionPolicy >
void KisEncloseAndFillPainter::Private::selectRegionsSurroundedBySpecificColorGeneric ( KisPixelSelectionSP resultMask,
QRect * resultMaskRect,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice,
SelectionPolicy selectionPolicy,
bool colorOrTransparent = false ) const

Definition at line 749 of file KisEncloseAndFillPainter.cpp.

756{
757 // Get the enclosing mask contour points
758 const QVector<QPoint> enclosingPoints = getEnclosingContourPoints(enclosingMask, enclosingMaskRect);
759 if (enclosingPoints.isEmpty()) {
760 return;
761 }
762 // Here we just fill all the areas from the border towards inside until the
763 // specific color. This selects any region that touches the enclosing area
764 // contour and that is not equal to the surrounding color
765 if (colorOrTransparent) {
766 selectRegionsFromContourUntilColorOrTransparent(resultMask, enclosingMask, enclosingPoints, enclosingMaskRect, referenceDevice, selectionPolicy.color);
767 } else {
768 selectRegionsFromContourUntilColor(resultMask, enclosingMask, enclosingPoints, enclosingMaskRect, referenceDevice, selectionPolicy.color);
769 }
770 // Invert the mask since it contains the regions surrounding the regions we
771 // want, that is, the regions that touch the enclosing area contour and that
772 // are not equal to the surrounding color. We want the opposite
773 invertMaskRect(resultMask, enclosingMaskRect);
774 // Since, after inverting, the mask includes the region outside the enclosing
775 // mask, we must intersect the current mask with the enclosing mask. The result
776 // is a mask that includes all the closed regions inside the enclosing mask
777 resultMask->applySelection(enclosingMask, SELECTION_INTERSECT);
778
780 // Remove the regions that touch the enclosing area
781 removeContourRegions(resultMask, enclosingMask, enclosingPoints, enclosingMaskRect, referenceDevice);
782 } else {
783 // Remove the surrounding regions. Also there shouldn't be any regions
784 // that touch the enclosing area contour after this step
786 selectSimilarRegions(mask, enclosingMask, enclosingMaskRect, referenceDevice, selectionPolicy);
787 resultMask->applySelection(mask, SELECTION_SUBTRACT);
788 }
789 if (resultMaskRect) {
790 *resultMaskRect = resultMask->selectedExactRect();
791 }
792}

References KisPixelSelection::applySelection(), KisEncloseAndFillPainter::regionSelectionIncludeSurroundingRegions(), KisPixelSelection::selectedExactRect(), SELECTION_INTERSECT, and SELECTION_SUBTRACT.

◆ selectRegionsSurroundedBySpecificColorOrTransparent()

void KisEncloseAndFillPainter::Private::selectRegionsSurroundedBySpecificColorOrTransparent ( KisPixelSelectionSP resultMask,
QRect * resultMaskRect,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice ) const

Definition at line 729 of file KisEncloseAndFillPainter.cpp.

734{
735 using namespace KisEncloseAndFillPainterDetail;
736 const int softness = 100 - q->opacitySpread();
737 // Here we must compute the specific color and transparent masks separately
738 KisPixelSelectionSP resultMaskTransparent = new KisPixelSelection(new KisSelectionDefaultBounds(resultMask));
739 if (softness == 0) {
741 selectRegionsSurroundedBySpecificColorGeneric(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice, colorPolicy, true);
742 } else {
744 selectRegionsSurroundedBySpecificColorGeneric(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice, colorPolicy, true);
745 }
746}

References KisPaintDevice::colorSpace(), KisPainter::q, and KisEncloseAndFillPainter::regionSelectionColor().

◆ selectRegionsSurroundedByTransparent()

void KisEncloseAndFillPainter::Private::selectRegionsSurroundedByTransparent ( KisPixelSelectionSP resultMask,
QRect * resultMaskRect,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice ) const

Definition at line 712 of file KisEncloseAndFillPainter.cpp.

717{
718 using namespace KisEncloseAndFillPainterDetail;
719 const int softness = 100 - q->opacitySpread();
720 if (softness == 0) {
722 selectRegionsSurroundedBySpecificColorGeneric(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice, policy);
723 } else {
724 SoftSelectionPolicy<TransparentDifferencePolicy> policy(referenceDevice->colorSpace(), KoColor::createTransparent(referenceDevice->colorSpace()), q->fillThreshold(), softness);
725 selectRegionsSurroundedBySpecificColorGeneric(resultMask, resultMaskRect, enclosingMask, enclosingMaskRect, referenceDevice, policy);
726 }
727}

References KisPaintDevice::colorSpace(), KoColor::createTransparent(), and KisPainter::q.

◆ selectSimilarRegions()

template<typename SelectionPolicy >
int KisEncloseAndFillPainter::Private::selectSimilarRegions ( KisPixelSelectionSP resultMask,
KisPixelSelectionSP enclosingMask,
const QRect & enclosingMaskRect,
KisPaintDeviceSP referenceDevice,
SelectionPolicy selectionPolicy ) const

Definition at line 922 of file KisEncloseAndFillPainter.cpp.

927{
928 KisSequentialIterator resultMaskIterator(resultMask, enclosingMaskRect);
929 KisSequentialConstIterator enclosingMaskIterator(enclosingMask, enclosingMaskRect);
930 KisSequentialConstIterator referenceDeviceIterator(referenceDevice, enclosingMaskRect);
931 int nPixels = 0;
932 // Select all the pixels using the given selection policy
933 while (resultMaskIterator.nextPixel() && enclosingMaskIterator.nextPixel() && referenceDeviceIterator.nextPixel()) {
934 if (*enclosingMaskIterator.oldRawData() == MIN_SELECTED) {
935 continue;
936 }
937 const quint8 selection = selectionPolicy.getSelectionFor(referenceDeviceIterator.oldRawData());
938 if (selection > MIN_SELECTED) {
939 *resultMaskIterator.rawData() = selection;
940 ++nPixels;
941 }
942 }
943 return nPixels;
944}

References MIN_SELECTED, KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::nextPixel(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::oldRawData(), KisSequentialIteratorBase< IteratorPolicy, SourcePolicy, ProgressPolicy >::rawData(), and KisPainter::selection.

Member Data Documentation

◆ imageRect

QRect KisEncloseAndFillPainter::Private::imageRect

Definition at line 135 of file KisEncloseAndFillPainter.cpp.

◆ q

KisEncloseAndFillPainter* KisEncloseAndFillPainter::Private::q {nullptr}

Definition at line 129 of file KisEncloseAndFillPainter.cpp.

129{nullptr};

◆ regionSelectionColor

KoColor KisEncloseAndFillPainter::Private::regionSelectionColor

Definition at line 131 of file KisEncloseAndFillPainter.cpp.

◆ regionSelectionIncludeContourRegions

bool KisEncloseAndFillPainter::Private::regionSelectionIncludeContourRegions {true}

Definition at line 133 of file KisEncloseAndFillPainter.cpp.

133{true};

◆ regionSelectionIncludeSurroundingRegions

bool KisEncloseAndFillPainter::Private::regionSelectionIncludeSurroundingRegions {true}

Definition at line 134 of file KisEncloseAndFillPainter.cpp.

134{true};

◆ regionSelectionInvert

bool KisEncloseAndFillPainter::Private::regionSelectionInvert {false}

Definition at line 132 of file KisEncloseAndFillPainter.cpp.

132{false};

◆ regionSelectionMethod

RegionSelectionMethod KisEncloseAndFillPainter::Private::regionSelectionMethod {SelectAllRegions}

Definition at line 130 of file KisEncloseAndFillPainter.cpp.


The documentation for this class was generated from the following file: