Skip to content

Commit

Permalink
1.0.19: renamed zone objects for further development.
Browse files Browse the repository at this point in the history
  • Loading branch information
zvezdochiot committed Jul 19, 2023
1 parent 6df8b7d commit be3b2f1
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 53 deletions.
14 changes: 7 additions & 7 deletions src/core/filters/output/OutputGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ void removeAutoPictureZones(ZoneSet& pictureZones) {

Zone createPictureZoneFromPoly(const QPolygonF& polygon) {
PropertySet propertySet;
propertySet.locateOrCreate<output::PictureLayerProperty>()->setLayer(output::PictureLayerProperty::PAINTER2);
propertySet.locateOrCreate<output::PictureLayerProperty>()->setLayer(output::PictureLayerProperty::ZONEPAINTER2);
propertySet.locateOrCreate<output::ZoneCategoryProperty>()->setZoneCategory(ZoneCategoryProperty::AUTO);
return Zone(SerializableSpline(polygon), propertySet);
}
Expand Down Expand Up @@ -1905,25 +1905,25 @@ void OutputGenerator::Processor::modifyBinarizationMask(BinaryImage& bwMask,

using PLP = PictureLayerProperty;

// Pass 1: ERASER1
// Pass 1: ZONEERASER1
for (const Zone& zone : zones) {
if (zone.properties().locateOrDefault<PLP>()->layer() == PLP::ERASER1) {
if (zone.properties().locateOrDefault<PLP>()->layer() == PLP::ZONEERASER1) {
const QPolygonF poly(zone.spline().toPolygon());
PolygonRasterizer::fill(bwMask, BLACK, xform.map(poly), Qt::WindingFill);
}
}

// Pass 2: PAINTER2
// Pass 2: ZONEPAINTER2
for (const Zone& zone : zones) {
if (zone.properties().locateOrDefault<PLP>()->layer() == PLP::PAINTER2) {
if (zone.properties().locateOrDefault<PLP>()->layer() == PLP::ZONEPAINTER2) {
const QPolygonF poly(zone.spline().toPolygon());
PolygonRasterizer::fill(bwMask, WHITE, xform.map(poly), Qt::WindingFill);
}
}

// Pass 1: ERASER3
// Pass 1: ZONEERASER3
for (const Zone& zone : zones) {
if (zone.properties().locateOrDefault<PLP>()->layer() == PLP::ERASER3) {
if (zone.properties().locateOrDefault<PLP>()->layer() == PLP::ZONEERASER3) {
const QPolygonF poly(zone.spline().toPolygon());
PolygonRasterizer::fill(bwMask, BLACK, xform.map(poly), Qt::WindingFill);
}
Expand Down
16 changes: 8 additions & 8 deletions src/core/filters/output/PictureLayerProperty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,27 +33,27 @@ std::shared_ptr<Property> PictureLayerProperty::construct(const QDomElement& el)

PictureLayerProperty::Layer PictureLayerProperty::layerFromString(const QString& str) {
if (str == "eraser1") {
return ERASER1;
return ZONEERASER1;
} else if (str == "painter2") {
return PAINTER2;
return ZONEPAINTER2;
} else if (str == "eraser3") {
return ERASER3;
return ZONEERASER3;
} else {
return NO_OP;
return ZONENOOP;
}
}

QString PictureLayerProperty::layerToString(Layer layer) {
QString str;

switch (layer) {
case ERASER1:
case ZONEERASER1:
str = "eraser1";
break;
case PAINTER2:
case ZONEPAINTER2:
str = "painter2";
break;
case ERASER3:
case ZONEERASER3:
str = "eraser3";
break;
default:
Expand All @@ -64,4 +64,4 @@ QString PictureLayerProperty::layerToString(Layer layer) {
}

PictureLayerProperty::PictureLayerProperty(PictureLayerProperty::Layer layer) : m_layer(layer) {}
} // namespace output
} // namespace output
4 changes: 2 additions & 2 deletions src/core/filters/output/PictureLayerProperty.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class QString;
namespace output {
class PictureLayerProperty : public Property {
public:
enum Layer { NO_OP, ERASER1, PAINTER2, ERASER3 };
enum Layer { ZONENOOP, ZONEERASER1, ZONEPAINTER2, ZONEERASER3 };

explicit PictureLayerProperty(Layer layer = NO_OP);
explicit PictureLayerProperty(Layer layer = ZONENOOP);

explicit PictureLayerProperty(const QDomElement& el);

Expand Down
12 changes: 6 additions & 6 deletions src/core/filters/output/PictureZoneEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,27 +215,27 @@ void PictureZoneEditor::paintOverPictureMask(QPainter& painter) {

painter.setCompositionMode(QPainter::CompositionMode_Clear);

// First pass: ERASER1
// First pass: ZONEERASER1
for (const EditableZoneSet::Zone& zone : zones()) {
if (zone.properties()->locateOrDefault<PLP>()->layer() == PLP::ERASER1) {
if (zone.properties()->locateOrDefault<PLP>()->layer() == PLP::ZONEERASER1) {
painter.drawPolygon(zone.spline()->toPolygon(), Qt::WindingFill);
}
}

painter.setCompositionMode(QPainter::CompositionMode_SourceOver);

// Second pass: PAINTER2
// Second pass: ZONEPAINTER2
for (const EditableZoneSet::Zone& zone : zones()) {
if (zone.properties()->locateOrDefault<PLP>()->layer() == PLP::PAINTER2) {
if (zone.properties()->locateOrDefault<PLP>()->layer() == PLP::ZONEPAINTER2) {
painter.drawPolygon(zone.spline()->toPolygon(), Qt::WindingFill);
}
}

painter.setCompositionMode(QPainter::CompositionMode_Clear);

// Third pass: ERASER3
// Third pass: ZONEERASER3
for (const EditableZoneSet::Zone& zone : zones()) {
if (zone.properties()->locateOrDefault<PLP>()->layer() == PLP::ERASER3) {
if (zone.properties()->locateOrDefault<PLP>()->layer() == PLP::ZONEERASER3) {
painter.drawPolygon(zone.spline()->toPolygon(), Qt::WindingFill);
}
}
Expand Down
34 changes: 17 additions & 17 deletions src/core/filters/output/PictureZonePropDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,34 @@ PictureZonePropDialog::PictureZonePropDialog(std::shared_ptr<PropertySet> props,
ui.setupUi(this);

switch (m_props->locateOrDefault<PictureLayerProperty>()->layer()) {
case PictureLayerProperty::NO_OP:
case PictureLayerProperty::ZONENOOP:
break;
case PictureLayerProperty::ERASER1:
ui.eraser1->setChecked(true);
case PictureLayerProperty::ZONEERASER1:
ui.zoneeraser1->setChecked(true);
break;
case PictureLayerProperty::PAINTER2:
ui.painter2->setChecked(true);
case PictureLayerProperty::ZONEPAINTER2:
ui.zonepainter2->setChecked(true);
break;
case PictureLayerProperty::ERASER3:
ui.eraser3->setChecked(true);
case PictureLayerProperty::ZONEERASER3:
ui.zoneeraser3->setChecked(true);
break;
}

connect(ui.eraser1, SIGNAL(toggled(bool)), SLOT(itemToggled(bool)));
connect(ui.painter2, SIGNAL(toggled(bool)), SLOT(itemToggled(bool)));
connect(ui.eraser3, SIGNAL(toggled(bool)), SLOT(itemToggled(bool)));
connect(ui.zoneeraser1, SIGNAL(toggled(bool)), SLOT(itemToggled(bool)));
connect(ui.zonepainter2, SIGNAL(toggled(bool)), SLOT(itemToggled(bool)));
connect(ui.zoneeraser3, SIGNAL(toggled(bool)), SLOT(itemToggled(bool)));
}

void PictureZonePropDialog::itemToggled(bool selected) {
PictureLayerProperty::Layer layer = PictureLayerProperty::NO_OP;
PictureLayerProperty::Layer layer = PictureLayerProperty::ZONENOOP;

QObject* const obj = sender();
if (obj == ui.eraser1) {
layer = PictureLayerProperty::ERASER1;
} else if (obj == ui.painter2) {
layer = PictureLayerProperty::PAINTER2;
} else if (obj == ui.eraser3) {
layer = PictureLayerProperty::ERASER3;
if (obj == ui.zoneeraser1) {
layer = PictureLayerProperty::ZONEERASER1;
} else if (obj == ui.zonepainter2) {
layer = PictureLayerProperty::ZONEPAINTER2;
} else if (obj == ui.zoneeraser3) {
layer = PictureLayerProperty::ZONEERASER3;
}

m_props->locateOrCreate<PictureLayerProperty>()->setLayer(layer);
Expand Down
8 changes: 4 additions & 4 deletions src/core/filters/output/PictureZonePropDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,23 @@
<property name="windowTitle">
<string>Zone Properties</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<layout class="QVBoxLayout" name="zoneverticalLayout">
<item>
<widget class="QRadioButton" name="eraser3">
<widget class="QRadioButton" name="zoneeraser3">
<property name="text">
<string>Subtract from all layers</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="painter2">
<widget class="QRadioButton" name="zonepainter2">
<property name="text">
<string>Add to auto layer</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="eraser1">
<widget class="QRadioButton" name="zoneeraser1">
<property name="text">
<string>Subtract from auto layer</string>
</property>
Expand Down
2 changes: 1 addition & 1 deletion src/core/filters/output/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void Settings::setDefaultFillZoneProperties(const PropertySet& props) {

PropertySet Settings::initialPictureZoneProps() {
PropertySet props;
props.locateOrCreate<PictureLayerProperty>()->setLayer(PictureLayerProperty::PAINTER2);
props.locateOrCreate<PictureLayerProperty>()->setLayer(PictureLayerProperty::ZONEPAINTER2);
return props;
}

Expand Down
17 changes: 10 additions & 7 deletions src/imageproc/ImageCombination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ void combineImagesColor<uint8_t, uint8_t>(QImage& mixedImage, const QImage& fore
}

template <typename MixedPixel>
void applyMask(QImage& image, const BinaryImage& bwMask, const BWColor fillingColor = WHITE) {
void applyMask(QImage& image,
const BinaryImage& bwMask,
const BWColor fillingColor = WHITE,
const bool bgflags = false) {
auto* imageLine = reinterpret_cast<MixedPixel*>(image.bits());
const int imageStride = image.bytesPerLine() / sizeof(MixedPixel);
const uint32_t* bwMaskLine = bwMask.data();
Expand All @@ -272,7 +275,7 @@ void applyMask(QImage& image, const BinaryImage& bwMask, const BWColor fillingCo

for (int y = 0; y < height; ++y) {
for (int x = 0; x < width; ++x) {
if (!(bwMaskLine[x >> 5] & (msb >> (x & 31)))) {
if ((bwMaskLine[x >> 5] & (msb >> (x & 31))) == bgflags) {
imageLine[x] = fillingPixel;
}
}
Expand Down Expand Up @@ -354,11 +357,11 @@ void combineImagesColor(QImage& mixedImage, const QImage& foreground, const Bina
}
}

void applyMask(QImage& image, const BinaryImage& bwMask, const BWColor fillingColor) {
void applyMask(QImage& image, const BinaryImage& bwMask, const BWColor fillingColor, bool bgflags) {
if (image.format() == QImage::Format_Indexed8) {
applyMask<uint8_t>(image, bwMask, fillingColor);
applyMask<uint8_t>(image, bwMask, fillingColor, bgflags);
} else {
applyMask<uint32_t>(image, bwMask, fillingColor);
applyMask<uint32_t>(image, bwMask, fillingColor, bgflags);
}
}
} // namespace impl
Expand Down Expand Up @@ -399,10 +402,10 @@ void combineImages(QImage& mixedImage, const QImage& foreground, const BinaryIma
}
}

void applyMask(QImage& image, const BinaryImage& bwMask, const BWColor fillingColor) {
void applyMask(QImage& image, const BinaryImage& bwMask, const BWColor fillingColor, const bool bgflags) {
checkImageFormatSupported(image);
checkImagesHaveEqualSize(image, bwMask);

impl::applyMask(image, bwMask, fillingColor);
impl::applyMask(image, bwMask, fillingColor, bgflags);
}
} // namespace imageproc
2 changes: 1 addition & 1 deletion src/imageproc/ImageCombination.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void combineImages(QImage& mixedImage, const QImage& foreground);

void combineImages(QImage& mixedImage, const QImage& foreground, const BinaryImage& mask);

void applyMask(QImage& image, const BinaryImage& bwMask, BWColor fillingColor = WHITE);
void applyMask(QImage& image, const BinaryImage& bwMask, BWColor fillingColor = WHITE, bool bgflags = false);
} // namespace imageproc


Expand Down

0 comments on commit be3b2f1

Please sign in to comment.