Skip to content

Commit

Permalink
Prepare for page rotation in case of duplex ADF
Browse files Browse the repository at this point in the history
  • Loading branch information
Simul Piscator committed Feb 1, 2021
1 parent 15afa9c commit 53909a5
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 6 deletions.
14 changes: 14 additions & 0 deletions imageformats/imageencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ ImageEncoder::ImageEncoder()
, mComponents(0)
, mBitDepth(0)
, mDpi(0)
, mOrientationDegrees(0)
, mBytesPerLine(0)
, mCurrentLine(0)
, mCurrentImage(0)
Expand Down Expand Up @@ -88,6 +89,19 @@ ImageEncoder::resolutionDpi() const
return mDpi;
}

ImageEncoder&
ImageEncoder::setOrientationDegrees(int d)
{
mOrientationDegrees = d;
return *this;
}

int
ImageEncoder::orientationDegrees() const
{
return mOrientationDegrees;
}

ImageEncoder&
ImageEncoder::setColorspace(ImageEncoder::Colorspace cs)
{
Expand Down
5 changes: 4 additions & 1 deletion imageformats/imageencoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class ImageEncoder
ImageEncoder& setResolutionDpi(int dpi);
int resolutionDpi() const;

ImageEncoder& setOrientationDegrees(int);
int orientationDegrees() const;

enum Colorspace
{
Unknown,
Expand Down Expand Up @@ -75,7 +78,7 @@ class ImageEncoder
void onParamChange();

private:
int mWidth, mHeight, mComponents, mBitDepth, mDpi;
int mWidth, mHeight, mComponents, mBitDepth, mDpi, mOrientationDegrees;
int mBytesPerLine, mCurrentLine, mCurrentImage;
Colorspace mColorspace;
std::ostream* mpDestination;
Expand Down
2 changes: 2 additions & 0 deletions imageformats/jpegencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ JpegEncoder::onImageBegin()
throw std::runtime_error("JpegEncoder: bit depth unsupported");
if (currentImage() > 0)
throw std::runtime_error("JpegEncoder: cannot encode more than one image per file");
if (orientationDegrees() != 0)
throw std::runtime_error("JpegEncoder: cannot rotate image");
p->mCompressStruct.image_width = width();
p->mCompressStruct.image_height = height();
p->mCompressStruct.input_components = components();
Expand Down
1 change: 1 addition & 0 deletions imageformats/pdfencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ PdfEncoder::onImageBegin()
};
*destination() << p->defobj(++p->mObj) // mObj == 2
<< "<<\n/Type/Page\n/Contents " << p->mObj + 2 << " 0 R\n"
<< "/Rotate " << orientationDegrees() << "\n"
<< "/MediaBox [ 0 0 "
<< pdfunits_per_px * width() << " "
<< pdfunits_per_px * height() << " ]\n"
Expand Down
2 changes: 2 additions & 0 deletions imageformats/pngencoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ PngEncoder::onImageBegin()
{
if (currentImage() > 0)
throw std::runtime_error("PngEncoder: cannot encode more than one image per file");
if (orientationDegrees() != 0)
throw std::runtime_error("PngEncoder: cannot rotate image");
#if BYTE_ORDER == LITTLE_ENDIAN
if (bitDepth() == 16)
p->mLineBuffer.resize(width() * components());
Expand Down
20 changes: 17 additions & 3 deletions server/scanjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct ScanJob::Private

std::string mScanSource, mIntent, mDocumentFormat, mColorMode;
int mBitDepth, mRes_dpi;
bool mColorScan, mSynthesizedGray;
bool mColorScan, mSynthesizedGray, mRotateEvenPages;
double mLeft_px, mTop_px, mWidth_px, mHeight_px;

int mKind, mImagesToTransfer, mImagesCompleted;
Expand Down Expand Up @@ -241,7 +241,7 @@ ScanJob::Private::init(const ScanSettingsXml& settings, bool autoselectFormat, c

mDocumentFormat = settings.getString("DocumentFormat");
std::clog << "document format requested: " << mDocumentFormat << "\n";
if (autoselectFormat && mDocumentFormat == HttpServer::MIME_TYPE_JPEG)
if (autoselectFormat)
mDocumentFormat = HttpServer::MIME_TYPE_PNG;
std::clog << "document format used: " << mDocumentFormat << "\n";

Expand All @@ -257,7 +257,8 @@ ScanJob::Private::init(const ScanSettingsXml& settings, bool autoselectFormat, c
else if (inputSource == "Feeder") {
mScanSource = mpScanner->adfSourceName();
mImagesToTransfer = std::numeric_limits<int>::max();
if (settings.getNumber("BatchIfPossible") && mDocumentFormat == HttpServer::MIME_TYPE_PDF)
double batchIfPossible = settings.getNumber("BatchIfPossible");
if (batchIfPossible == 1.0 && mDocumentFormat == HttpServer::MIME_TYPE_PDF)
mKind = adfBatch;
else
mKind = adfSingle;
Expand Down Expand Up @@ -299,6 +300,7 @@ ScanJob::Private::applyDeviceOptions(const OptionsFile::Options& options)
mDeviceOptions.clear();
mGammaTable.clear();
mSynthesizedGray = false;
mRotateEvenPages = false;
for (const auto& option : options) {
if (option.first == "gray-gamma") {
if (!mColorScan) {
Expand All @@ -322,6 +324,16 @@ ScanJob::Private::applyDeviceOptions(const OptionsFile::Options& options)
mColorMode = mpScanner->grayScanModeName();
}
}
#if 0
} else if (option.first == "rotate-even") {
if (option.second == "yes") {
std::clog << "rotating even-numbered pages by 180 degrees" << std::endl;
mRotateEvenPages = true;
} else {
std::clog << "not rotating pages" << std::endl;
mRotateEvenPages = false;
}
#endif
} else {
mDeviceOptions.push_back(option);
}
Expand Down Expand Up @@ -681,6 +693,8 @@ ScanJob::Private::finishTransfer(std::ostream& os)
}
if (isProcessing()) {
++mImagesCompleted;
if (mRotateEvenPages)
pEncoder->setOrientationDegrees(mImagesCompleted % 2 ? 0 : 180);
std::clog << "images completed: " << mImagesCompleted << std::endl;
updateStatus(status);
if (pEncoder->linesLeftInCurrentImage() != pEncoder->height()) {
Expand Down
4 changes: 2 additions & 2 deletions server/scannerpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ ScannerPage::onRender()
std::string note;
for (const auto& s : mScanner.inputSources())
if (s == "Feeder")
note = "Choose \"Feeder\" input source and <br>PDF format to scan multiple pages.";
note = "Choose \"Feeder\" input source and \"PDF\"<br>document type to scan multiple pages.";

const struct
{
Expand Down Expand Up @@ -220,7 +220,7 @@ ScannerPage::onRender()
#settings { float:left; min-width:45%; padding:0.2em }
#downloadbtn { position:absolute; bottom:8px; margin-left:8px }
#previewbtn { position:absolute; bottom:8px; margin-left:8px }
#note { padding-top:2em; font-size:small }
#note { padding:2em; font-size:small }
#status { padding-top:2em; color:red }
#previewpane { overflow:hidden }
#previewimg { background-color:lightgray; line-height:2.5em; text-align:left }
Expand Down

0 comments on commit 53909a5

Please sign in to comment.