1 /*
2     Scan Tailor - Interactive post-processing tool for scanned pages.
3     Copyright (C)  Joseph Artsimovich <joseph.artsimovich@gmail.com>
4 
5     This program is free software: you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation, either version 3 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "DewarpingOptions.h"
20 #include <cassert>
21 
22 namespace output {
DewarpingOptions(DewarpingMode mode,bool needPostDeskew)23 DewarpingOptions::DewarpingOptions(DewarpingMode mode, bool needPostDeskew)
24     : m_mode(mode), m_needPostDeskew(needPostDeskew) {}
25 
DewarpingOptions(const QDomElement & el)26 DewarpingOptions::DewarpingOptions(const QDomElement& el)
27     : m_mode(parseDewarpingMode(el.attribute("mode"))), m_needPostDeskew(el.attribute("postDeskew", "1") == "1") {}
28 
toXml(QDomDocument & doc,const QString & name) const29 QDomElement DewarpingOptions::toXml(QDomDocument& doc, const QString& name) const {
30   QDomElement el(doc.createElement(name));
31   el.setAttribute("mode", formatDewarpingMode(m_mode));
32   el.setAttribute("postDeskew", m_needPostDeskew ? "1" : "0");
33 
34   return el;
35 }
36 
operator ==(const DewarpingOptions & other) const37 bool DewarpingOptions::operator==(const DewarpingOptions& other) const {
38   return (m_mode == other.m_mode) && (m_needPostDeskew == other.m_needPostDeskew);
39 }
40 
operator !=(const DewarpingOptions & other) const41 bool DewarpingOptions::operator!=(const DewarpingOptions& other) const {
42   return !(*this == other);
43 }
44 
setDewarpingMode(DewarpingMode m_mode)45 void DewarpingOptions::setDewarpingMode(DewarpingMode m_mode) {
46   DewarpingOptions::m_mode = m_mode;
47 }
48 
setPostDeskew(bool postDeskew)49 void DewarpingOptions::setPostDeskew(bool postDeskew) {
50   DewarpingOptions::m_needPostDeskew = postDeskew;
51 }
52 
needPostDeskew() const53 bool DewarpingOptions::needPostDeskew() const {
54   return m_needPostDeskew;
55 }
56 
dewarpingMode() const57 DewarpingMode DewarpingOptions::dewarpingMode() const {
58   return m_mode;
59 }
60 
parseDewarpingMode(const QString & str)61 DewarpingMode DewarpingOptions::parseDewarpingMode(const QString& str) {
62   if (str == "auto") {
63     return AUTO;
64   } else if (str == "manual") {
65     return MANUAL;
66   } else if (str == "marginal") {
67     return MARGINAL;
68   } else {
69     return OFF;
70   }
71 }
72 
formatDewarpingMode(DewarpingMode mode)73 QString DewarpingOptions::formatDewarpingMode(DewarpingMode mode) {
74   switch (mode) {
75     case OFF:
76       return "off";
77     case AUTO:
78       return "auto";
79     case MANUAL:
80       return "manual";
81     case MARGINAL:
82       return "marginal";
83   }
84 
85   assert(!"Unreachable");
86 
87   return QString();
88 }
89 }  // namespace output