Skip to content

Commit

Permalink
Order by dewarping mode at output stage
Browse files Browse the repository at this point in the history
  • Loading branch information
trufanov-nok committed Mar 30, 2022
1 parent c3d7086 commit 42bf8ef
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/core/filters/output/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ SET(
DepthPerception.cpp DepthPerception.h
OrderByModeProvider.cpp OrderByModeProvider.h
OrderBySourceColor.cpp OrderBySourceColor.h
OrderByDewarpingModeProvider.cpp OrderByDewarpingModeProvider.h
${exiv2_sources}
)
SOURCE_GROUP("Sources" FILES ${sources})
Expand Down
3 changes: 3 additions & 0 deletions src/core/filters/output/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "ImageViewTab.h"
#include "OrderByModeProvider.h"
#include "OrderBySourceColor.h"
#include "OrderByDewarpingModeProvider.h"
#include "version.h"
#include "FillColorProperty.h"

Expand All @@ -60,9 +61,11 @@ Filter::Filter(
ProviderPtr const default_order;
ProviderPtr const order_by_mode(new OrderByModeProvider(m_ptrSettings));
ProviderPtr const order_by_source_color(new OrderBySourceColor(m_ptrSettings, pages));
ProviderPtr const order_by_dewarping_mode(new OrderByDewarpingModeProvider(m_ptrSettings));
m_pageOrderOptions.push_back(PageOrderOption(tr("Natural order"), default_order));
m_pageOrderOptions.push_back(PageOrderOption(QObject::tr("Processed then unprocessed"), ProviderPtr(new OrderByReadiness())));
m_pageOrderOptions.push_back(PageOrderOption(tr("Order by mode"), order_by_mode));
m_pageOrderOptions.push_back(PageOrderOption(tr("Order by dewarping mode"), order_by_dewarping_mode));
m_pageOrderOptions.push_back(PageOrderOption(tr("Grayscale sources on top"), order_by_source_color,
tr("Groups the pages by presence\nof a non grey color in the source files")));
}
Expand Down
67 changes: 67 additions & 0 deletions src/core/filters/output/OrderByDewarpingModeProvider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
Copyright (C) Joseph Artsimovich <[email protected]>
Copyright (C) Alexander Trufanov <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "OrderByDewarpingModeProvider.h"
#include "Params.h"
#include <QSizeF>
#include <memory>
#include <assert.h>

namespace output
{

OrderByDewarpingModeProvider::OrderByDewarpingModeProvider(IntrusivePtr<Settings> const& settings)
: m_ptrSettings(settings)
{
}

bool
OrderByDewarpingModeProvider::precedes(
PageId const& lhs_page, bool const /*lhs_incomplete*/,
PageId const& rhs_page, bool const /*rhs_incomplete*/) const
{
DewarpingMode const l_param(m_ptrSettings->getParams(lhs_page).dewarpingMode());
DewarpingMode const r_param(m_ptrSettings->getParams(rhs_page).dewarpingMode());

if (l_param != r_param) {
return l_param < r_param;
}

return lhs_page < rhs_page;
}

QString dewarpingMode2String(DewarpingMode const mode)
{
switch (mode) {
case DewarpingMode::OFF: return QObject::tr("off");
case DewarpingMode::MANUAL: return QObject::tr("manual");
case DewarpingMode::MARGINAL: return QObject::tr("marginal");
case DewarpingMode::AUTO: return QObject::tr("auto");
default: return QString();
}
}

QString
OrderByDewarpingModeProvider::hint(PageId const& page) const
{
DewarpingMode const param(m_ptrSettings->getParams(page).dewarpingMode());
return dewarpingMode2String(param);
}

} // namespace output
46 changes: 46 additions & 0 deletions src/core/filters/output/OrderByDewarpingModeProvider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Scan Tailor - Interactive post-processing tool for scanned pages.
Copyright (C) Joseph Artsimovich <[email protected]>
Copyright (C) Alexander Trufanov <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef ORDER_BY_DEWARPING_MODE_PROVIDER_H_
#define ORDER_BY_DEWARPING_MODE_PROVIDER_H_

#include "Settings.h"
#include "IntrusivePtr.h"
#include "PageOrderProvider.h"

namespace output
{

class OrderByDewarpingModeProvider : public PageOrderProvider
{
public:
OrderByDewarpingModeProvider(IntrusivePtr<Settings> const& settings);

virtual bool precedes(
PageId const& lhs_page, bool lhs_incomplete,
PageId const& rhs_page, bool rhs_incomplete) const;

virtual QString hint(PageId const& page) const;
private:
IntrusivePtr<Settings> m_ptrSettings;
};

} // namespace output

#endif //ORDER_BY_DEWARPING_MODE_PROVIDER_H_
2 changes: 1 addition & 1 deletion src/core/filters/output/OrderByModeProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ OrderByModeProvider::hint(PageId const& page) const
return /*res.arg(*/colorMode2String(param.colorMode())/*)*/;
}

} // namespace page_split
} // namespace output
8 changes: 4 additions & 4 deletions src/core/filters/output/OrderByModeProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef PAGE_SPLIT_ORDER_BY_MODE_PROVIDER_H_
#define PAGE_SPLIT_ORDER_BY_MODE_PROVIDER_H_
#ifndef OUTPUT_ORDER_BY_MODE_PROVIDER_H_
#define OUTPUT_ORDER_BY_MODE_PROVIDER_H_

#include "Settings.h"
#include "IntrusivePtr.h"
Expand All @@ -41,6 +41,6 @@ class OrderByModeProvider : public PageOrderProvider
IntrusivePtr<Settings> m_ptrSettings;
};

} // namespace page_split
} // namespace output

#endif //PAGE_SPLIT_ORDER_BY_MODE_PROVIDER_H_
#endif //OUTPUT_ORDER_BY_MODE_PROVIDER_H_

0 comments on commit 42bf8ef

Please sign in to comment.