Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Version counting is based on semantic versioning (Major.Feature.Patch)
### YACReader
* Add support for continuous scroll mode.
* Fix the translator.
* Add Lanczos interpolation for image scaling. You can control the method used via the settings under `Image adjustments`.

### All GUI Apps
* Migrate Flow implementation from OpenGL to QRhi. This is a full new implementation with better performance and compatibility with operating systems and hardware.
Expand Down Expand Up @@ -131,7 +132,7 @@ Version counting is based on semantic versioning (Major.Feature.Patch)

### YACReaderLibraryServer
* Add `rescan-xml-info` command.
* Improved API to provide better integration with the clients (Android 1.4.0 and iOS 3.29.0).
* Improved API to provide better integration with the clients (Android 1.4.0 and iOS 3.29.0).

### All Apps
* New universal builds for macos.
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ add_subdirectory(common)
if(NOT BUILD_SERVER_STANDALONE)
add_subdirectory(shortcuts_management)
add_subdirectory(custom_widgets)
add_subdirectory(image_processing)
endif()

add_subdirectory(YACReaderLibrary/server)
Expand Down
1 change: 1 addition & 0 deletions YACReader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ target_link_libraries(YACReader PRIVATE
custom_widgets_reader
shortcuts_reader
cbx_backend
image_processing
QsLog
)

Expand Down
4 changes: 4 additions & 0 deletions YACReader/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QDate>

#include "yacreader_global_gui.h"
#include "resize_image.h"

#define CONF_FILE_PATH "."
#define SLIDE_ASPECT_RATIO 1.585
Expand Down Expand Up @@ -117,6 +118,9 @@ class Configuration : public QObject

MouseMode getMouseMode() { return static_cast<MouseMode>(settings->value(MOUSE_MODE, MouseMode::Normal).toInt()); }
void setMouseMode(MouseMode mouseMode) { settings->setValue(MOUSE_MODE, static_cast<int>(mouseMode)); }

ScaleMethod getScalingMethod() { return static_cast<ScaleMethod>(settings->value(SCALING_METHOD, static_cast<int>(ScaleMethod::Lanczos)).toInt()); }
void setScalingMethod(ScaleMethod method) { settings->setValue(SCALING_METHOD, static_cast<int>(method)); }
};

}
Expand Down
11 changes: 10 additions & 1 deletion YACReader/continuous_page_widget.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "continuous_page_widget.h"
#include "continuous_view_model.h"
#include "render.h"
#include "resize_image.h"
#include "configuration.h"

#include <QPainter>
#include <QPaintEvent>
Expand Down Expand Up @@ -77,6 +79,12 @@ QSize ContinuousPageWidget::sizeHint() const
return QSize(width(), continuousViewModel->totalHeight());
}

void ContinuousPageWidget::invalidateScaledImageCache()
{
scaledPageCache.invalidateAll();
update();
}

void ContinuousPageWidget::onPageAvailable(int absolutePageIndex)
{
if (!render || !continuousViewModel || absolutePageIndex < 0 || absolutePageIndex >= continuousViewModel->numPages()) {
Expand Down Expand Up @@ -183,7 +191,8 @@ const QImage *ContinuousPageWidget::scaledImageForPaint(int pageIndex, const QIm
entry.sourceCacheKey = sourceKey;
entry.sourceSize = source->size();
entry.targetSize = targetSize;
entry.scaledImage = source->scaled(targetSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
entry.scaledImage = scaleImage(*source, targetSize.width(), targetSize.height(),
Configuration::getConfiguration().getScalingMethod());
scaledPageCache.pages.insert(pageIndex, std::move(entry));

return &scaledPageCache.pages[pageIndex].scaledImage;
Expand Down
1 change: 1 addition & 0 deletions YACReader/continuous_page_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ContinuousPageWidget : public QWidget, protected Themable

public slots:
void onPageAvailable(int absolutePageIndex);
void invalidateScaledImageCache();

protected:
void paintEvent(QPaintEvent *event) override;
Expand Down
2 changes: 1 addition & 1 deletion YACReader/main_window_viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ void MainWindowViewer::setupUI()
connect(optionsDialog, &QDialog::accepted, viewer, &Viewer::updateOptions);
connect(optionsDialog, &YACReaderOptionsDialog::optionsChanged, this, &MainWindowViewer::reloadOptions);
connect(optionsDialog, &OptionsDialog::changedFilters, viewer, &Viewer::updateFilters);
connect(optionsDialog, &OptionsDialog::changedImageOptions, viewer, &Viewer::updatePage);
connect(optionsDialog, &OptionsDialog::changedImageOptions, viewer, &Viewer::onImageOptionsChanged);

optionsDialog->restoreOptions(settings);
// shortcutsDialog = new ShortcutsDialog(this);
Expand Down
26 changes: 26 additions & 0 deletions YACReader/options_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QLabel>
#include <QColorDialog>
#include <QCheckBox>
#include <QComboBox>
#include <QMessageBox>
#include "theme_manager.h"
#include "theme_factory.h"
Expand Down Expand Up @@ -198,6 +199,23 @@ OptionsDialog::OptionsDialog(QWidget *parent)
doublePageBoxLayout->addWidget(coverSPCheckBox);
doublePageBox->setLayout(doublePageBoxLayout);
layoutImageV->addWidget(doublePageBox);

auto scalingBox = new QGroupBox(tr("Scaling"));
auto scalingLayout = new QHBoxLayout();
scalingLayout->addWidget(new QLabel(tr("Scaling method")));
scalingMethodCombo = new QComboBox();
scalingMethodCombo->addItem(tr("Nearest (fast, low quality)"));
scalingMethodCombo->addItem(tr("Bilinear"));
scalingMethodCombo->addItem(tr("Lanczos (better quality)"));
connect(scalingMethodCombo, &QComboBox::currentIndexChanged, this, [this](int index) {
Configuration::getConfiguration().setScalingMethod(static_cast<ScaleMethod>(index));
emit changedImageOptions();
});
scalingLayout->addWidget(scalingMethodCombo);
scalingLayout->addStretch();
scalingBox->setLayout(scalingLayout);
layoutImageV->addWidget(scalingBox);

layoutImageV->addStretch();

// IMAGE ADJUSTMENTS END -----------------------------
Expand Down Expand Up @@ -294,6 +312,9 @@ void OptionsDialog::saveOptions()
}
Configuration::getConfiguration().setMouseMode(mouseMode);

Configuration::getConfiguration().setScalingMethod(static_cast<ScaleMethod>(scalingMethodCombo->currentIndex()));
emit changedImageOptions();

YACReaderOptionsDialog::saveOptions();
}

Expand Down Expand Up @@ -330,6 +351,11 @@ void OptionsDialog::restoreOptions(QSettings *settings)
#endif
disableScrollAnimations->setChecked(settings->value(DISABLE_SCROLL_ANIMATION, defaultDisableScrollAnimationsValue).toBool());

{
QSignalBlocker blocker(scalingMethodCombo);
scalingMethodCombo->setCurrentIndex(static_cast<int>(Configuration::getConfiguration().getScalingMethod()));
}

auto mouseMode = Configuration::getConfiguration().getMouseMode();

switch (mouseMode) {
Expand Down
3 changes: 3 additions & 0 deletions YACReader/options_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <QPointer>

class QComboBox;
class QDialog;
class QLabel;
class QLineEdit;
Expand Down Expand Up @@ -62,6 +63,8 @@ class OptionsDialog : public YACReaderOptionsDialog, protected Themable

QColor currentColor;

QComboBox *scalingMethodCombo;

QRadioButton *normalMouseModeRadioButton;
QRadioButton *leftRightNavigationMouseModeRadioButton;
QRadioButton *hotAreasMouseModeRadioButton;
Expand Down
27 changes: 19 additions & 8 deletions YACReader/viewer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "viewer.h"
#include "continuous_page_widget.h"
#include "continuous_view_model.h"
#include "resize_image.h"
#include "configuration.h"
#include "magnifying_glass.h"
#include "goto_flow_widget.h"
Expand Down Expand Up @@ -357,6 +358,15 @@ void Viewer::goTo(unsigned int page)
render->goTo(page);
}

void Viewer::onImageOptionsChanged()
{
if (continuousScroll) {
continuousWidget->invalidateScaledImageCache();
} else {
updatePage();
}
}

void Viewer::updatePage()
{
if (continuousScroll) {
Expand Down Expand Up @@ -433,16 +443,17 @@ void Viewer::updateContentSize()
if (zoom != 100) {
pagefit.scale(floor(pagefit.width() * zoom / 100.0f), 0, Qt::KeepAspectRatioByExpanding);
}
// apply scaling
// apply size to the container
content->resize(pagefit);

// TODO: updtateContentSize should only scale the pixmap once
if (devicePixelRatioF() > 1) // only in HDPI displays
{
QPixmap page = currentPage->scaled(content->width() * devicePixelRatioF(), content->height() * devicePixelRatioF(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
page.setDevicePixelRatio(devicePixelRatioF());
content->setPixmap(page);
}
// scale the pixmap to physical pixels for crisp rendering on all displays
auto dpr = devicePixelRatioF();
QPixmap page = scalePixmap(*currentPage,
qRound(content->width() * dpr),
qRound(content->height() * dpr),
Configuration::getConfiguration().getScalingMethod());
page.setDevicePixelRatio(dpr);
content->setPixmap(page);

emit backgroundChanges();
}
Expand Down
1 change: 1 addition & 0 deletions YACReader/viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public slots:
void goToLastPage();
void goTo(unsigned int page);
void updatePage();
void onImageOptionsChanged();
void updateContentSize();
void updateVerticalScrollBar();
void updateOptions();
Expand Down
1 change: 1 addition & 0 deletions common/yacreader_global_gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#define USE_SINGLE_SCROLL_STEP_TO_TURN_PAGE "USE_SINGLE_SCROLL_STEP_TO_TURN_PAGE"
#define DISABLE_SCROLL_ANIMATION "DISABLE_SCROLL_ANIMATION"
#define MOUSE_MODE "MOUSE_MODE"
#define SCALING_METHOD "SCALING_METHOD"

#define FLOW_TYPE_GL "FLOW_TYPE_GL"
#define Y_POSITION "Y_POSITION"
Expand Down
9 changes: 9 additions & 0 deletions image_processing/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
add_library(image_processing STATIC
resize_image.h
resize_image.cpp
lancir.h
)

target_include_directories(image_processing PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_link_libraries(image_processing PRIVATE Qt::Gui)
Loading