Skip to content

Commit bd87093

Browse files
authored
improve duplex ADF handling (#130)
- advertise both simplex and duplex ADF as per eSCL spec - handle request to scan as duplex appropriately
1 parent 3c418b4 commit bd87093

3 files changed

Lines changed: 70 additions & 38 deletions

File tree

server/scanjob.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ struct ScanJob::Private
129129
std::string mScanSource, mIntent, mDocumentFormat, mColorMode;
130130
int mBitDepth, mRes_dpi;
131131
bool mColorScan;
132+
bool mDuplex;
132133
double mLeft_px, mTop_px, mWidth_px, mHeight_px;
133134

134135
std::atomic<int> mKind, mImagesCompleted;
@@ -310,7 +311,12 @@ ScanJob::Private::init(const ScanSettingsXml& settings, bool autoselectFormat, c
310311
mKind = single;
311312
}
312313
else if (inputSource == "Feeder") {
313-
mScanSource = mpScanner->adfSourceName();
314+
mDuplex = settings.getNumber("Duplex") == 1.0;
315+
if (mDuplex) {
316+
mScanSource = mpScanner->adfDuplexSourceName();
317+
} else {
318+
mScanSource = mpScanner->adfSimplexSourceName();
319+
}
314320
double concatIfPossible = settings.getNumber("ConcatIfPossible");
315321
if (concatIfPossible == 1.0 && mDocumentFormat == HttpServer::MIME_TYPE_PDF)
316322
mKind = adfConcat;

server/scanner.cpp

Lines changed: 59 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ struct Scanner::Private
205205
explicit InputSource(Private* p);
206206
const char* init(const sanecpp::option_set&);
207207
void writeCapabilitiesXml(std::ostream&) const;
208-
} * mpPlaten, *mpAdf;
209-
bool mDuplex;
208+
} * mpPlaten, *mpAdfSimplex, *mpAdfDuplex;
210209

211210
std::string mGrayScanModeName, mColorScanModeName;
212211
mutable int mCurrentProfile;
@@ -239,8 +238,8 @@ std::set<Scanner::Private*> Scanner::Private::sInstances;
239238
Scanner::Private::Private(Scanner* p)
240239
: p(p)
241240
, mpPlaten(nullptr)
242-
, mpAdf(nullptr)
243-
, mDuplex(false)
241+
, mpAdfSimplex(nullptr)
242+
, mpAdfDuplex(nullptr)
244243
, mTemporaryAdfStatus(SANE_STATUS_GOOD)
245244
, mError(nullptr)
246245
{
@@ -250,7 +249,8 @@ Scanner::Private::Private(Scanner* p)
250249
Scanner::Private::~Private()
251250
{
252251
delete mpPlaten;
253-
delete mpAdf;
252+
delete mpAdfSimplex;
253+
delete mpAdfDuplex;
254254
sInstances.erase(this);
255255
}
256256

@@ -278,20 +278,16 @@ Scanner::Private::writeScannerCapabilitiesXml(std::ostream& os) const
278278
mpPlaten->writeCapabilitiesXml(os);
279279
os << "</scan:PlatenInputCaps>\r\n</scan:Platen>\r\n";
280280
}
281-
if (mpAdf && !mDuplex) {
281+
if (mpAdfSimplex) {
282282
os << "<scan:Adf>\r\n<scan:AdfSimplexInputCaps>\r\n";
283-
mpAdf->writeCapabilitiesXml(os);
284-
os << "</scan:AdfSimplexInputCaps>\r\n"
285-
<< "<scan:AdfOptions>\r\n"
286-
<< "<scan:AdfOption>DetectPaperLoaded</scan:AdfOption>\r\n"
287-
<< "</scan:AdfOptions>\r\n"
288-
<< "</scan:Adf>\r\n";
289-
}
290-
if (mpAdf && mDuplex) {
291-
os << "<scan:Adf>\r\n<scan:AdfDuplexInputCaps>\r\n";
292-
mpAdf->writeCapabilitiesXml(os);
293-
os << "</scan:AdfDuplexInputCaps>\r\n"
294-
<< "<scan:AdfOptions>\r\n"
283+
mpAdfSimplex->writeCapabilitiesXml(os);
284+
os << "</scan:AdfSimplexInputCaps>\r\n";
285+
if (mpAdfDuplex) {
286+
os << "<scan:AdfDuplexInputCaps>\r\n";
287+
mpAdfDuplex->writeCapabilitiesXml(os);
288+
os << "</scan:AdfDuplexInputCaps>\r\n";
289+
}
290+
os << "<scan:AdfOptions>\r\n"
295291
<< "<scan:AdfOption>DetectPaperLoaded</scan:AdfOption>\r\n"
296292
<< "</scan:AdfOptions>\r\n"
297293
<< "</scan:Adf>\r\n";
@@ -565,20 +561,35 @@ Scanner::Private::init2(const OptionsFile& optionsfile)
565561
mMaxHeightPx300dpi = std::max(mMaxHeightPx300dpi, mpPlaten->mMaxHeight);
566562
}
567563
}
568-
if (!adfName.empty()) {
569-
mInputSources.push_back("Feeder");
570-
mDuplex = !adfDuplexName.empty();
571-
opt[SANE_NAME_SCAN_SOURCE].set_string_value(adfName);
572-
mpAdf = new Private::InputSource(this);
573-
err = mpAdf->init(opt);
564+
if (!adfSimplexName.empty() || !adfDuplexName.empty()) {
565+
mInputSources.push_back("Feeder");
566+
}
567+
if (!adfSimplexName.empty()) {
568+
opt[SANE_NAME_SCAN_SOURCE].set_string_value(adfSimplexName);
569+
mpAdfSimplex = new Private::InputSource(this);
570+
err = mpAdfSimplex->init(opt);
574571
if (!err) {
575-
mpAdf->mSupportedIntents = std::vector<std::string>({
572+
mpAdfSimplex->mSupportedIntents = std::vector<std::string>({
576573
"TextAndGraphic",
577574
"Photo",
578575
});
579-
maxBits = std::max(maxBits, mpAdf->mMaxBits);
580-
mMaxWidthPx300dpi = std::max(mMaxWidthPx300dpi, mpAdf->mMaxWidth);
581-
mMaxHeightPx300dpi = std::max(mMaxHeightPx300dpi, mpAdf->mMaxHeight);
576+
maxBits = std::max(maxBits, mpAdfSimplex->mMaxBits);
577+
mMaxWidthPx300dpi = std::max(mMaxWidthPx300dpi, mpAdfSimplex->mMaxWidth);
578+
mMaxHeightPx300dpi = std::max(mMaxHeightPx300dpi, mpAdfSimplex->mMaxHeight);
579+
}
580+
}
581+
if (!adfDuplexName.empty()) {
582+
opt[SANE_NAME_SCAN_SOURCE].set_string_value(adfDuplexName);
583+
mpAdfDuplex = new Private::InputSource(this);
584+
err = mpAdfDuplex->init(opt);
585+
if (!err) {
586+
mpAdfDuplex->mSupportedIntents = std::vector<std::string>({
587+
"TextAndGraphic",
588+
"Photo",
589+
});
590+
maxBits = std::max(maxBits, mpAdfDuplex->mMaxBits);
591+
mMaxWidthPx300dpi = std::max(mMaxWidthPx300dpi, mpAdfDuplex->mMaxWidth);
592+
mMaxHeightPx300dpi = std::max(mMaxHeightPx300dpi, mpAdfDuplex->mMaxHeight);
582593
}
583594
}
584595
if (maxBits == 16) {
@@ -799,9 +810,16 @@ Scanner::platenSupportedIntents() const
799810
}
800811

801812
std::vector<std::string>
802-
Scanner::adfSupportedIntents() const
813+
Scanner::adfSimplexSupportedIntents() const
814+
{
815+
return p->mpAdfSimplex ? p->mpAdfSimplex->mSupportedIntents : std::vector<std::string>();
816+
;
817+
}
818+
819+
std::vector<std::string>
820+
Scanner::adfDuplexSupportedIntents() const
803821
{
804-
return p->mpAdf ? p->mpAdf->mSupportedIntents : std::vector<std::string>();
822+
return p->mpAdfDuplex ? p->mpAdfDuplex->mSupportedIntents : std::vector<std::string>();
805823
;
806824
}
807825

@@ -844,13 +862,13 @@ Scanner::hasPlaten() const
844862
bool
845863
Scanner::hasAdf() const
846864
{
847-
return p->mpAdf;
865+
return p->mpAdfSimplex;
848866
}
849867

850868
bool
851869
Scanner::hasDuplexAdf() const
852870
{
853-
return p->mpAdf && p->mDuplex;
871+
return p->mpAdfDuplex;
854872
}
855873

856874
std::string
@@ -860,9 +878,15 @@ Scanner::platenSourceName() const
860878
}
861879

862880
std::string
863-
Scanner::adfSourceName() const
881+
Scanner::adfSimplexSourceName() const
882+
{
883+
return p->mpAdfSimplex ? p->mpAdfSimplex->mSourceName : "";
884+
}
885+
886+
std::string
887+
Scanner::adfDuplexSourceName() const
864888
{
865-
return p->mpAdf ? p->mpAdf->mSourceName : "";
889+
return p->mpAdfDuplex ? p->mpAdfDuplex->mSourceName : "";
866890
}
867891

868892
std::string
@@ -963,7 +987,7 @@ Scanner::writeScannerStatusXml(std::ostream& os) const
963987
<< p->statusString()
964988
<< "</pwg:State>\r\n";
965989

966-
if (p->mpAdf)
990+
if (p->mpAdfSimplex || p->mpAdfDuplex)
967991
os << "<scan:AdfState>" << p->temporaryAdfStatusString()
968992
<< "</scan:AdfState>\r\n";
969993

server/scanner.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class Scanner
6464
const std::vector<std::string>& txtColorSpaces() const;
6565
const std::vector<std::string>& colorModes() const;
6666
std::vector<std::string> platenSupportedIntents() const;
67-
std::vector<std::string> adfSupportedIntents() const;
67+
std::vector<std::string> adfSimplexSupportedIntents() const;
68+
std::vector<std::string> adfDuplexSupportedIntents() const;
6869
const std::vector<std::string>& inputSources() const;
6970

7071
int minResDpi() const;
@@ -77,7 +78,8 @@ class Scanner
7778
bool hasDuplexAdf() const;
7879

7980
std::string platenSourceName() const;
80-
std::string adfSourceName() const;
81+
std::string adfSimplexSourceName() const;
82+
std::string adfDuplexSourceName() const;
8183
std::string grayScanModeName() const;
8284
std::string colorScanModeName() const;
8385

0 commit comments

Comments
 (0)