Skip to content

Commit

Permalink
Version 1.0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
4lex4 committed Mar 28, 2018
2 parents a30d503 + ea2b64f commit 91211e0
Show file tree
Hide file tree
Showing 681 changed files with 45,670 additions and 51,007 deletions.
17 changes: 5 additions & 12 deletions Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
#include <config.h>
#include <QtCore/QDir>

Application::Application(int& argc, char** argv)
: QApplication(argc, argv),
m_currentLocale("en") {
Application::Application(int& argc, char** argv) : QApplication(argc, argv), m_currentLocale("en") {
initTranslations();
}

Expand Down Expand Up @@ -73,20 +71,15 @@ const QString& Application::getCurrentLocale() const {
}

std::list<QString> Application::getLanguagesList() const {
std::list<QString> list{ "en" };
std::transform(m_translationsMap.begin(), m_translationsMap.end(),
std::back_inserter(list),
[](const std::pair<QString, QString>& val) {
return val.first;
});
std::list<QString> list{"en"};
std::transform(m_translationsMap.begin(), m_translationsMap.end(), std::back_inserter(list),
[](const std::pair<QString, QString>& val) { return val.first; });

return list;
}

void Application::initTranslations() {
const QStringList translation_dirs(
QString::fromUtf8(TRANSLATION_DIRS).split(QChar(':'), QString::SkipEmptyParts)
);
const QStringList translation_dirs(QString::fromUtf8(TRANSLATION_DIRS).split(QChar(':'), QString::SkipEmptyParts));

const QStringList language_file_filter("scantailor_*.qm");
for (const QString& path : translation_dirs) {
Expand Down
2 changes: 1 addition & 1 deletion Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "OutputFileNameGenerator.h"

class Application : public QApplication {
Q_OBJECT
Q_OBJECT
public:
Application(int& argc, char** argv);

Expand Down
1 change: 0 additions & 1 deletion AtomicFileOverwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,3 @@ void AtomicFileOverwriter::abort() {
m_ptrTempFile.reset(); // See comments in commit()
QFile::remove(temp_file_path);
}

2 changes: 1 addition & 1 deletion AtomicFileOverwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class QTemporaryFile;
* in the same directory as the target file.
*/
class AtomicFileOverwriter {
DECLARE_NON_COPYABLE(AtomicFileOverwriter)
DECLARE_NON_COPYABLE(AtomicFileOverwriter)

public:
AtomicFileOverwriter();
Expand Down
5 changes: 1 addition & 4 deletions AutoManualMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
#ifndef AUTOMANUALMODE_H_
#define AUTOMANUALMODE_H_

enum AutoManualMode {
MODE_AUTO,
MODE_MANUAL
};
enum AutoManualMode { MODE_AUTO, MODE_MANUAL };

#endif
15 changes: 4 additions & 11 deletions BackgroundExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ class BackgroundExecutor::Impl : public QThread {

/*============================ BackgroundExecutor ==========================*/

BackgroundExecutor::BackgroundExecutor()
: m_ptrImpl(new Impl(*this)) {
BackgroundExecutor::BackgroundExecutor() : m_ptrImpl(new Impl(*this)) {
}

BackgroundExecutor::~BackgroundExecutor() = default;
Expand All @@ -74,8 +73,7 @@ void BackgroundExecutor::enqueueTask(const TaskPtr& task) {

/*===================== BackgroundExecutor::Dispatcher =====================*/

BackgroundExecutor::Dispatcher::Dispatcher(Impl& owner)
: m_rOwner(owner) {
BackgroundExecutor::Dispatcher::Dispatcher(Impl& owner) : m_rOwner(owner) {
}

void BackgroundExecutor::Dispatcher::customEvent(QEvent* event) {
Expand All @@ -88,9 +86,7 @@ void BackgroundExecutor::Dispatcher::customEvent(QEvent* event) {

const TaskResultPtr result((*task)());
if (result) {
QCoreApplication::postEvent(
&m_rOwner, new ResultEvent(result)
);
QCoreApplication::postEvent(&m_rOwner, new ResultEvent(result));
}
} catch (const std::bad_alloc&) {
OutOfMemoryHandler::instance().handleOutOfMemorySituation();
Expand All @@ -100,9 +96,7 @@ void BackgroundExecutor::Dispatcher::customEvent(QEvent* event) {
/*======================= BackgroundExecutor::Impl =========================*/

BackgroundExecutor::Impl::Impl(BackgroundExecutor& owner)
: m_rOwner(owner),
m_dispatcher(*this),
m_threadStarted(false) {
: m_rOwner(owner), m_dispatcher(*this), m_threadStarted(false) {
m_dispatcher.moveToThread(this);
}

Expand Down Expand Up @@ -132,4 +126,3 @@ void BackgroundExecutor::Impl::customEvent(QEvent* event) {

(*result)();
}

2 changes: 1 addition & 1 deletion BackgroundExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <memory>

class BackgroundExecutor {
DECLARE_NON_COPYABLE(BackgroundExecutor)
DECLARE_NON_COPYABLE(BackgroundExecutor)

public:
typedef intrusive_ptr<AbstractCommand0<void>> TaskResultPtr;
Expand Down
1 change: 0 additions & 1 deletion BackgroundTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ void BackgroundTask::throwIfCancelled() const {
throw CancelledException();
}
}

8 changes: 2 additions & 6 deletions BackgroundTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,15 @@

class BackgroundTask : public AbstractCommand0<FilterResultPtr>, public TaskStatus {
public:
enum Type {
INTERACTIVE,
BATCH
};
enum Type { INTERACTIVE, BATCH };

class CancelledException : public std::exception {
public:
const char* what() const throw() override;
};


explicit BackgroundTask(Type type)
: m_type(type) {
explicit BackgroundTask(Type type) : m_type(type) {
}

Type type() const {
Expand Down
6 changes: 1 addition & 5 deletions BasicImageView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@
#include "BasicImageView.h"

BasicImageView::BasicImageView(const QImage& image, const ImagePixmapUnion& downscaled_image, const Margins& margins)
: ImageViewBase(
image, downscaled_image,
ImagePresentation(QTransform(), QRectF(image.rect())), margins
),
: ImageViewBase(image, downscaled_image, ImagePresentation(QTransform(), QRectF(image.rect())), margins),
m_dragHandler(*this),
m_zoomHandler(*this) {
rootInteractionHandler().makeLastFollower(m_dragHandler);
rootInteractionHandler().makeLastFollower(m_zoomHandler);
}

BasicImageView::~BasicImageView() = default;

2 changes: 1 addition & 1 deletion BasicImageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <QImage>

class BasicImageView : public ImageViewBase {
Q_OBJECT
Q_OBJECT
public:
explicit BasicImageView(const QImage& image,
const ImagePixmapUnion& downscaled_image = ImagePixmapUnion(),
Expand Down
5 changes: 1 addition & 4 deletions BeforeOrAfter.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
#ifndef BEFORE_OR_AFTER_H_
#define BEFORE_OR_AFTER_H_

enum BeforeOrAfter {
BEFORE,
AFTER
};
enum BeforeOrAfter { BEFORE, AFTER };

#endif
103 changes: 103 additions & 0 deletions BlackOnWhiteEstimator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@

#include <imageproc/Transform.h>
#include <imageproc/Grayscale.h>
#include <imageproc/Binarize.h>
#include <imageproc/Morphology.h>
#include <imageproc/RasterOp.h>
#include <imageproc/PolygonRasterizer.h>
#include "BlackOnWhiteEstimator.h"
#include "Despeckle.h"
#include "DebugImages.h"
#include "TaskStatus.h"

using namespace imageproc;

bool BlackOnWhiteEstimator::isBlackOnWhiteRefining(const imageproc::GrayImage& grayImage,
const ImageTransformation& xform,
const TaskStatus& status,
DebugImages* dbg) {
BinaryImage bw150;
{
ImageTransformation xform150dpi(xform);
xform150dpi.preScaleToDpi(Dpi(150, 150));

if (xform150dpi.resultingRect().toRect().isEmpty()) {
return true;
}

QImage gray150(transformToGray(grayImage, xform150dpi.transform(), xform150dpi.resultingRect().toRect(),
OutsidePixels::assumeColor(Qt::white)));
bw150 = binarizeOtsu(gray150);

Despeckle::despeckleInPlace(bw150, Dpi(150, 150), Despeckle::NORMAL, status);
bw150.invert();
Despeckle::despeckleInPlace(bw150, Dpi(150, 150), Despeckle::NORMAL, status);
bw150.invert();
if (dbg) {
dbg->add(bw150, "bw150");
}
}

status.throwIfCancelled();

BinaryImage contentMask;
{
BinaryImage whiteTopHat = whiteTopHatTransform(bw150, QSize(13, 13));
BinaryImage blackTopHat = blackTopHatTransform(bw150, QSize(13, 13));

contentMask = whiteTopHat;
rasterOp<RopOr<RopSrc, RopDst>>(contentMask, blackTopHat);

contentMask = closeBrick(contentMask, QSize(200, 200));
contentMask = dilateBrick(contentMask, QSize(30, 30));
if (dbg) {
dbg->add(contentMask, "content_mask");
}
}

status.throwIfCancelled();

rasterOp<RopAnd<RopSrc, RopDst>>(bw150, contentMask);

return (2 * bw150.countBlackPixels() <= contentMask.countBlackPixels());
}

bool BlackOnWhiteEstimator::isBlackOnWhite(const imageproc::GrayImage& grayImage,
const ImageTransformation& xform,
const TaskStatus& status,
DebugImages* dbg) {
if (isBlackOnWhite(grayImage, xform.resultingPreCropArea())) {
return true;
} else {
// The black borders of the page can make the method above giving the wrong result.
return isBlackOnWhiteRefining(grayImage, xform, status, dbg);
}
}

bool BlackOnWhiteEstimator::isBlackOnWhite(const GrayImage& img, const BinaryImage& mask) {
if (img.isNull()) {
throw std::invalid_argument("BlackOnWhiteEstimator: image is null.");
}
if (img.size() != mask.size()) {
throw std::invalid_argument("BlackOnWhiteEstimator: img and mask have different sizes");
}

BinaryImage bwImage(img, BinaryThreshold::otsuThreshold(GrayscaleHistogram(img, mask)));
rasterOp<RopAnd<RopSrc, RopDst>>(bwImage, mask);

return (2 * bwImage.countBlackPixels() <= mask.countBlackPixels());
}

bool BlackOnWhiteEstimator::isBlackOnWhite(const GrayImage& img, const QPolygonF& cropArea) {
if (img.isNull()) {
throw std::invalid_argument("BlackOnWhiteEstimator: image is null.");
}
if (cropArea.intersected(QRectF(img.rect())).isEmpty()) {
throw std::invalid_argument("BlackOnWhiteEstimator: the cropping area is wrong.");
}

BinaryImage mask(img.size(), BLACK);
PolygonRasterizer::fillExcept(mask, WHITE, cropArea, Qt::WindingFill);

return isBlackOnWhite(img, mask);
}
35 changes: 35 additions & 0 deletions BlackOnWhiteEstimator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

#ifndef SCANTAILOR_BLACKONWHITEESTIMATOR_H
#define SCANTAILOR_BLACKONWHITEESTIMATOR_H

#include <imageproc/BinaryImage.h>
#include <QtGui/QPolygonF>
#include "ImageTransformation.h"

class TaskStatus;
class DebugImages;

namespace imageproc {
class GrayImage;
class BinaryImage;
} // namespace imageproc

class BlackOnWhiteEstimator {
public:
static bool isBlackOnWhite(const imageproc::GrayImage& grayImage,
const ImageTransformation& xform,
const TaskStatus& status,
DebugImages* dbg = nullptr);

static bool isBlackOnWhiteRefining(const imageproc::GrayImage& grayImage,
const ImageTransformation& xform,
const TaskStatus& status,
DebugImages* dbg = nullptr);

static bool isBlackOnWhite(const imageproc::GrayImage& img, const imageproc::BinaryImage& mask);

static bool isBlackOnWhite(const imageproc::GrayImage& img, const QPolygonF& cropArea);
};


#endif // SCANTAILOR_BLACKONWHITEESTIMATOR_H
19 changes: 7 additions & 12 deletions BubbleAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@

using namespace imageproc;

BubbleAnimation::BubbleAnimation(const int num_bubbles)
: m_numBubbles(num_bubbles),
m_curFrame(0) {
BubbleAnimation::BubbleAnimation(const int num_bubbles) : m_numBubbles(num_bubbles), m_curFrame(0) {
assert(m_numBubbles > 0);
}

Expand All @@ -42,12 +40,12 @@ bool BubbleAnimation::nextFrame(const QColor& head_color, const QColor& tail_col
return nextFrame(head_color, tail_color, &painter, rect);
}

bool BubbleAnimation::nextFrame(const QColor& head_color, const QColor& tail_color, QPainter* painter,
bool BubbleAnimation::nextFrame(const QColor& head_color,
const QColor& tail_color,
QPainter* painter,
const QRectF rect) {
const QPointF center(rect.center());
const double radius = std::min(
center.x() - rect.x(), center.y() - rect.y()
);
const double radius = std::min(center.x() - rect.x(), center.y() - rect.y());

const double PI = imageproc::constants::PI;
const double arc_fraction_as_radius = 0.25;
Expand All @@ -56,9 +54,7 @@ bool BubbleAnimation::nextFrame(const QColor& head_color, const QColor& tail_col
// arc_between_bubbles = 2.0 * PI * reduced_radius / m_numBubbles;
// reduced_radius = radius - bubble_radius.
// Solving this system of equations, we get:
const double reduced_radius = radius / (
1.0 + 2.0 * PI * arc_fraction_as_radius / m_numBubbles
);
const double reduced_radius = radius / (1.0 + 2.0 * PI * arc_fraction_as_radius / m_numBubbles);
const double bubble_radius = radius - reduced_radius;

const double tail_length = 0.5 * m_numBubbles;
Expand Down Expand Up @@ -87,5 +83,4 @@ bool BubbleAnimation::nextFrame(const QColor& head_color, const QColor& tail_col

return false;
}
} // BubbleAnimation::nextFrame

} // BubbleAnimation::nextFrame
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,8 @@ SET(
DefaultParamsProvider.cpp DefaultParamsProvider.h
DeviationProvider.h
OrderByDeviationProvider.cpp OrderByDeviationProvider.h
BlackOnWhiteEstimator.cpp BlackOnWhiteEstimator.h
ImageSettings.cpp ImageSettings.h
version.h
config.h.in
${common_ui_files})
Expand Down
Loading

0 comments on commit 91211e0

Please sign in to comment.