Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/app/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent) {
ui.blackOnWhiteDetectionAtOutputCB->setChecked(settings.isBlackOnWhiteDetectionOutputEnabled());
connect(ui.blackOnWhiteDetectionCB, SIGNAL(clicked(bool)), SLOT(blackOnWhiteDetectionToggled(bool)));

ui.contentDetectionIgnorePageBoxCB->setChecked(settings.isContentDetectionIgnoringPageBox());

ui.highlightDeviationCB->setChecked(settings.isHighlightDeviationEnabled());

ui.deskewDeviationCoefSB->setValue(settings.getDeskewDeviationCoef());
Expand Down Expand Up @@ -109,6 +111,8 @@ void SettingsDialog::commitChanges() {
settings.setBlackOnWhiteDetectionEnabled(ui.blackOnWhiteDetectionCB->isChecked());
settings.setBlackOnWhiteDetectionOutputEnabled(ui.blackOnWhiteDetectionAtOutputCB->isChecked());

settings.setContentDetectionIgnoringPageBox(ui.contentDetectionIgnorePageBoxCB->isChecked());

{
const int quality = ui.thumbnailQualitySB->value();
settings.setThumbnailQuality(QSize(quality, quality));
Expand Down
32 changes: 32 additions & 0 deletions src/app/SettingsDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,38 @@
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Content detection</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QCheckBox" name="contentDetectionIgnorePageBoxCB">
<property name="text">
<string>Detect content independently of the page box</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="contentDetectionIgnorePageBoxLabel">
<property name="text">
<string>Use the whole image to search for content instead of only the area inside the page box. Useful when the page box noticeably deteriorates content recognition. The detected content box is still clipped to the page box afterwards. Re-run the Select Content stage to apply this to already processed pages.</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
<property name="indent">
<number>20</number>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
Expand Down
9 changes: 9 additions & 0 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <core/StyledIconPack.h>

#include <QGuiApplication>
#include <QImageReader>
#include <QSettings>
#include <QStringList>

Expand All @@ -33,6 +34,14 @@ int main(int argc, char* argv[]) {
#endif
Application app(argc, argv);

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
// By default, Qt6 refuses to decode any image whose *uncompressed* size exceeds 256 MB,
// which is routinely hit by high-DPI scans of large pages.
if (!qEnvironmentVariableIsSet("QT_IMAGEIO_MAXALLOC")) {
QImageReader::setAllocationLimit(0);
}
#endif

#ifdef _WIN32
// Get rid of all references to Qt's installation directory.
Application::setLibraryPaths(QStringList(Application::applicationDirPath()));
Expand Down
11 changes: 11 additions & 0 deletions src/core/ApplicationSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ const QString ApplicationSettings::CURRENT_PROFILE_KEY = "current_profile";
const QString ApplicationSettings::SHOW_CANCELING_SELECTION_QUESTION_KEY = "selection_canceling_question";
const QString ApplicationSettings::DEFAULT_ZONE_CREATION_MODE_KEY = "default_zone_creation_mode";
const QString ApplicationSettings::OUTPUT_SHOW_GUIDES_KEY = "output_show_guides";
const QString ApplicationSettings::CONTENT_DETECTION_IGNORE_PAGE_BOX_KEY = "content_detection_ignore_page_box";
const int ApplicationSettings::DEFAULT_ZONE_CREATION_MODE = 0; // POLYGONAL
const bool ApplicationSettings::DEFAULT_OUTPUT_SHOW_GUIDES = false;
const bool ApplicationSettings::DEFAULT_CONTENT_DETECTION_IGNORE_PAGE_BOX = false;

QString ApplicationSettings::getKey(const QString& keyName) {
return ApplicationSettings::ROOT_KEY + '/' + keyName;
Expand Down Expand Up @@ -258,3 +260,12 @@ bool ApplicationSettings::isOutputShowGuidesEnabled() const {
void ApplicationSettings::setOutputShowGuidesEnabled(bool enabled) {
m_settings.setValue(getKey(OUTPUT_SHOW_GUIDES_KEY), enabled);
}

bool ApplicationSettings::isContentDetectionIgnoringPageBox() const {
return m_settings.value(getKey(CONTENT_DETECTION_IGNORE_PAGE_BOX_KEY), DEFAULT_CONTENT_DETECTION_IGNORE_PAGE_BOX)
.toBool();
}

void ApplicationSettings::setContentDetectionIgnoringPageBox(bool enabled) {
m_settings.setValue(getKey(CONTENT_DETECTION_IGNORE_PAGE_BOX_KEY), enabled);
}
7 changes: 7 additions & 0 deletions src/core/ApplicationSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ class ApplicationSettings {

void setOutputShowGuidesEnabled(bool enabled);

/** Disable page box masking when searching for content. */
bool isContentDetectionIgnoringPageBox() const;

void setContentDetectionIgnoringPageBox(bool enabled);

private:
static inline QString getKey(const QString& keyName);

Expand Down Expand Up @@ -163,9 +168,11 @@ class ApplicationSettings {
static const QString SHOW_CANCELING_SELECTION_QUESTION_KEY;
static const QString DEFAULT_ZONE_CREATION_MODE_KEY;
static const QString OUTPUT_SHOW_GUIDES_KEY;
static const QString CONTENT_DETECTION_IGNORE_PAGE_BOX_KEY;

static const int DEFAULT_ZONE_CREATION_MODE; // 0 = polygonal
static const bool DEFAULT_OUTPUT_SHOW_GUIDES;
static const bool DEFAULT_CONTENT_DETECTION_IGNORE_PAGE_BOX;

QSettings m_settings;
};
Expand Down
15 changes: 10 additions & 5 deletions src/core/filters/select_content/ContentBoxFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <SeedFill.h>
#include <SlicedHistogram.h>
#include <Transform.h>
#include <core/ApplicationSettings.h>

#include <QDebug>
#include <QPainter>
Expand Down Expand Up @@ -97,11 +98,15 @@ QRectF ContentBoxFinder::findContentBox(const TaskStatus& status,
dbg->add(bw150, "bw150");
}

const double xscale = 150.0 / data.xform().origDpi().horizontal();
const double yscale = 150.0 / data.xform().origDpi().vertical();
QRectF pageRect150(pageRect.left() * xscale, pageRect.top() * yscale, pageRect.right() * xscale,
pageRect.bottom() * yscale);
PolygonRasterizer::fillExcept(bw150, BLACK, pageRect150, Qt::WindingFill);
// Masking everything outside the page box sometimes leads to worse content detection.
// Skipping the mask lets the search use the whole image.
if (!ApplicationSettings::getInstance().isContentDetectionIgnoringPageBox()) {
const double xscale = 150.0 / data.xform().origDpi().horizontal();
const double yscale = 150.0 / data.xform().origDpi().vertical();
QRectF pageRect150(pageRect.left() * xscale, pageRect.top() * yscale, pageRect.right() * xscale,
pageRect.bottom() * yscale);
PolygonRasterizer::fillExcept(bw150, BLACK, pageRect150, Qt::WindingFill);
}

PolygonRasterizer::fillExcept(bw150, BLACK, xform150dpi.resultingPreCropArea(), Qt::WindingFill);
if (dbg) {
Expand Down