Skip to content

Commit 88e27ef

Browse files
committed
feat(output): fill outside page box option (#92)
Add ColorCommonOptions flag, RenderParams bit, OutputGenerator pre-crop using full output rect, UI checkbox mutually exclusive with Fill offcut.
1 parent cc5b626 commit 88e27ef

8 files changed

Lines changed: 72 additions & 9 deletions

File tree

src/core/filters/output/ColorCommonOptions.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,22 @@
88
namespace output {
99
ColorCommonOptions::ColorCommonOptions()
1010
: m_fillOffcut(true),
11+
m_fillOutsidePageBox(false),
1112
m_fillMargins(true),
1213
m_normalizeIllumination(false),
13-
m_fillingColor(FILL_BACKGROUND),
1414
m_wienerCoef(0.0),
15-
m_wienerWindowSize(5) {}
15+
m_wienerWindowSize(5),
16+
m_fillingColor(FILL_BACKGROUND) {}
1617

1718
ColorCommonOptions::ColorCommonOptions(const QDomElement& el)
1819
: m_fillOffcut(el.attribute("fillOffcut") == "1"),
20+
m_fillOutsidePageBox(el.attribute("fillOutsidePageBox") == "1"),
1921
m_fillMargins(el.attribute("fillMargins") == "1"),
2022
m_normalizeIllumination(el.attribute("normalizeIlluminationColor") == "1"),
21-
m_fillingColor(parseFillingColor(el.attribute("fillingColor"))),
22-
m_posterizationOptions(el.namedItem("posterization-options").toElement()),
2323
m_wienerCoef(el.attribute("wienerCoef").toDouble()),
24-
m_wienerWindowSize(el.attribute("wienerWinSize").toInt()) {
24+
m_wienerWindowSize(el.attribute("wienerWinSize").toInt()),
25+
m_fillingColor(parseFillingColor(el.attribute("fillingColor"))),
26+
m_posterizationOptions(el.namedItem("posterization-options").toElement()) {
2527
if (m_wienerCoef < 0.0 || m_wienerCoef > 1.0) {
2628
m_wienerCoef = 0.0;
2729
}
@@ -34,6 +36,7 @@ QDomElement ColorCommonOptions::toXml(QDomDocument& doc, const QString& name) co
3436
QDomElement el(doc.createElement(name));
3537
el.setAttribute("fillMargins", m_fillMargins ? "1" : "0");
3638
el.setAttribute("fillOffcut", m_fillOffcut ? "1" : "0");
39+
el.setAttribute("fillOutsidePageBox", m_fillOutsidePageBox ? "1" : "0");
3740
el.setAttribute("normalizeIlluminationColor", m_normalizeIllumination ? "1" : "0");
3841
el.setAttribute("fillingColor", formatFillingColor(m_fillingColor));
3942
el.appendChild(m_posterizationOptions.toXml(doc, "posterization-options"));
@@ -44,7 +47,8 @@ QDomElement ColorCommonOptions::toXml(QDomDocument& doc, const QString& name) co
4447

4548
bool ColorCommonOptions::operator==(const ColorCommonOptions& other) const {
4649
return (m_normalizeIllumination == other.m_normalizeIllumination) && (m_fillMargins == other.m_fillMargins)
47-
&& (m_fillOffcut == other.m_fillOffcut) && (m_fillingColor == other.m_fillingColor)
50+
&& (m_fillOffcut == other.m_fillOffcut) && (m_fillOutsidePageBox == other.m_fillOutsidePageBox)
51+
&& (m_fillingColor == other.m_fillingColor)
4852
&& (m_posterizationOptions == other.m_posterizationOptions) && (m_wienerCoef == other.m_wienerCoef)
4953
&& (m_wienerWindowSize == other.m_wienerWindowSize);
5054
}

src/core/filters/output/ColorCommonOptions.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ class ColorCommonOptions {
6060

6161
void setFillOffcut(bool fillOffcut);
6262

63+
bool fillOutsidePageBox() const;
64+
65+
void setFillOutsidePageBox(bool fillOutsidePageBox);
66+
6367
bool fillMargins() const;
6468

6569
void setFillMargins(bool val);
@@ -92,6 +96,7 @@ class ColorCommonOptions {
9296

9397

9498
bool m_fillOffcut;
99+
bool m_fillOutsidePageBox;
95100
bool m_fillMargins;
96101
bool m_normalizeIllumination;
97102
double m_wienerCoef;
@@ -155,6 +160,14 @@ inline void ColorCommonOptions::setFillOffcut(bool fillOffcut) {
155160
m_fillOffcut = fillOffcut;
156161
}
157162

163+
inline bool ColorCommonOptions::fillOutsidePageBox() const {
164+
return m_fillOutsidePageBox;
165+
}
166+
167+
inline void ColorCommonOptions::setFillOutsidePageBox(bool fillOutsidePageBox) {
168+
m_fillOutsidePageBox = fillOutsidePageBox;
169+
}
170+
158171
inline bool ColorCommonOptions::PosterizationOptions::isEnabled() const {
159172
return m_isEnabled;
160173
}

src/core/filters/output/OptionsWidget.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,26 @@ void OptionsWidget::fillMarginsToggled(const bool checked) {
207207
void OptionsWidget::fillOffcutToggled(const bool checked) {
208208
ColorCommonOptions colorCommonOptions(m_colorParams.colorCommonOptions());
209209
colorCommonOptions.setFillOffcut(checked);
210+
if (checked) {
211+
colorCommonOptions.setFillOutsidePageBox(false);
212+
fillOutsidePageBoxCB->blockSignals(true);
213+
fillOutsidePageBoxCB->setChecked(false);
214+
fillOutsidePageBoxCB->blockSignals(false);
215+
}
216+
m_colorParams.setColorCommonOptions(colorCommonOptions);
217+
m_settings->setColorParams(m_pageId, m_colorParams);
218+
emit reloadRequested();
219+
}
220+
221+
void OptionsWidget::fillOutsidePageBoxToggled(const bool checked) {
222+
ColorCommonOptions colorCommonOptions(m_colorParams.colorCommonOptions());
223+
colorCommonOptions.setFillOutsidePageBox(checked);
224+
if (checked) {
225+
colorCommonOptions.setFillOffcut(false);
226+
fillOffcutCB->blockSignals(true);
227+
fillOffcutCB->setChecked(false);
228+
fillOffcutCB->blockSignals(false);
229+
}
210230
m_colorParams.setColorCommonOptions(colorCommonOptions);
211231
m_settings->setColorParams(m_pageId, m_colorParams);
212232
emit reloadRequested();
@@ -595,6 +615,8 @@ void OptionsWidget::updateColorsDisplay() {
595615
fillMarginsCB->setVisible(true);
596616
fillOffcutCB->setChecked(colorCommonOptions.fillOffcut());
597617
fillOffcutCB->setVisible(true);
618+
fillOutsidePageBoxCB->setChecked(colorCommonOptions.fillOutsidePageBox());
619+
fillOutsidePageBoxCB->setVisible(true);
598620
equalizeIlluminationCB->setChecked(blackWhiteOptions.normalizeIllumination());
599621
equalizeIlluminationCB->setVisible(colorMode != COLOR_GRAYSCALE);
600622
equalizeIlluminationColorCB->setChecked(colorCommonOptions.normalizeIllumination());
@@ -951,6 +973,7 @@ void OptionsWidget::setupUiConnections() {
951973

952974
CONNECT(fillMarginsCB, SIGNAL(clicked(bool)), this, SLOT(fillMarginsToggled(bool)));
953975
CONNECT(fillOffcutCB, SIGNAL(clicked(bool)), this, SLOT(fillOffcutToggled(bool)));
976+
CONNECT(fillOutsidePageBoxCB, SIGNAL(clicked(bool)), this, SLOT(fillOutsidePageBoxToggled(bool)));
954977
CONNECT(equalizeIlluminationCB, SIGNAL(clicked(bool)), this, SLOT(equalizeIlluminationToggled(bool)));
955978
CONNECT(equalizeIlluminationColorCB, SIGNAL(clicked(bool)), this, SLOT(equalizeIlluminationColorToggled(bool)));
956979
CONNECT(savitzkyGolaySmoothingCB, SIGNAL(clicked(bool)), this, SLOT(savitzkyGolaySmoothingToggled(bool)));

src/core/filters/output/OptionsWidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ class OptionsWidget : public FilterOptionsWidget, private Ui::OptionsWidget {
120120

121121
void fillOffcutToggled(bool checked);
122122

123+
void fillOutsidePageBoxToggled(bool checked);
124+
123125
void equalizeIlluminationToggled(bool checked);
124126

125127
void equalizeIlluminationColorToggled(bool checked);

src/core/filters/output/OptionsWidget.ui

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,16 @@
224224
</property>
225225
</widget>
226226
</item>
227+
<item>
228+
<widget class="QCheckBox" name="fillOutsidePageBoxCB">
229+
<property name="toolTip">
230+
<string>Fill the full output page rectangle with the background color outside the page content, instead of following offcut geometry.</string>
231+
</property>
232+
<property name="text">
233+
<string>Fill outside page box</string>
234+
</property>
235+
</widget>
236+
</item>
227237
<item>
228238
<widget class="QCheckBox" name="fillMarginsCB">
229239
<property name="text">

src/core/filters/output/OutputGenerator.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ void OutputGenerator::Processor::initParams() {
319319
void OutputGenerator::Processor::calcAreas() {
320320
m_targetSize = m_outRect.size().expandedTo(QSize(1, 1));
321321

322-
if (m_renderParams.fillOffcut()) {
322+
if (m_renderParams.fillOutsidePageBox()) {
323+
m_preCropArea = QRectF(m_outRect);
324+
} else if (m_renderParams.fillOffcut()) {
323325
m_preCropArea = m_xform.resultingPreCropArea();
324326
} else {
325327
const QPolygonF imageRectInOutputCs = m_xform.transform().map(m_xform.origRect());

src/core/filters/output/RenderParams.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ RenderParams::RenderParams(const ColorParams& colorParams, const SplittingOption
5353
if (colorCommonOptions.fillMargins()) {
5454
m_mask |= FILL_MARGINS;
5555
}
56-
if (colorCommonOptions.fillOffcut()) {
56+
if (colorCommonOptions.fillOutsidePageBox()) {
57+
m_mask |= FILL_OUTSIDE_PAGE_BOX;
58+
} else if (colorCommonOptions.fillOffcut()) {
5759
m_mask |= FILL_OFFCUT;
5860
}
5961
if (colorCommonOptions.normalizeIllumination()) {

src/core/filters/output/RenderParams.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class RenderParams {
1717

1818
bool fillOffcut() const;
1919

20+
bool fillOutsidePageBox() const;
21+
2022
bool fillMargins() const;
2123

2224
bool normalizeIllumination() const;
@@ -54,7 +56,8 @@ class RenderParams {
5456
ORIGINAL_BACKGROUND = 1 << 8,
5557
COLOR_SEGMENTATION = 1 << 9,
5658
POSTERIZE = 1 << 10,
57-
FILL_OFFCUT = 1 << 11
59+
FILL_OFFCUT = 1 << 11,
60+
FILL_OUTSIDE_PAGE_BOX = 1 << 12
5861
};
5962

6063
int m_mask;
@@ -112,5 +115,9 @@ inline bool RenderParams::posterize() const {
112115
inline bool RenderParams::fillOffcut() const {
113116
return (m_mask & FILL_OFFCUT) != 0;
114117
}
118+
119+
inline bool RenderParams::fillOutsidePageBox() const {
120+
return (m_mask & FILL_OUTSIDE_PAGE_BOX) != 0;
121+
}
115122
} // namespace output
116123
#endif // ifndef SCANTAILOR_OUTPUT_RENDERPARAMS_H_

0 commit comments

Comments
 (0)