Skip to content

Commit

Permalink
separate reprocess image fast and smooth
Browse files Browse the repository at this point in the history
  • Loading branch information
plq committed Jul 27, 2016
1 parent 6dd1387 commit 1cd6e0a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
32 changes: 29 additions & 3 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ MainWindow::MainWindow(QWidget *parent):
QMainWindow(parent),
m_current_scale(0),
m_current_size(0),
m_fast(false),
m_orig_size(0),
m_processing(false),
ui(new Ui::MainWindow)
Expand Down Expand Up @@ -200,6 +201,12 @@ void MainWindow::on_actionExit_triggered(){
close();
}

void MainWindow::show_pixmap_fast() {
m_scene->clear();
m_scene->addPixmap(m_pixmap);
m_scene->setSceneRect(m_pixmap.rect());
}

void MainWindow::show_pixmap() {
std::lock_guard<std::mutex> guard(m_mutex);

Expand Down Expand Up @@ -268,8 +275,26 @@ void MainWindow::show_pixmap() {

}

void MainWindow::reprocess_image_fast(int scale, int) {
m_new_w = (m_orig_image.width() * scale) / 100;
m_new_h = (m_orig_image.height() * scale)/100;

m_pixmap = QPixmap::fromImage(
m_orig_image.scaled(m_new_w, m_new_h, Qt::KeepAspectRatio, Qt::FastTransformation));

show_pixmap_fast();
}

void MainWindow::reprocess_image(int scale, int quality) {
if (m_fast) {
reprocess_image_fast(scale, quality);
}
else {
reprocess_image_smooth(scale, quality);
}
}

void MainWindow::reprocess_image_smooth(int scale, int quality) {
std::lock_guard<std::mutex> guard(m_mutex);
if (m_processing) {
return;
Expand Down Expand Up @@ -307,11 +332,12 @@ bool MainWindow::rescale_image(int scale) {

m_current_scale = scale;

m_pixmap = QPixmap::fromImage(
m_orig_image.scaled(m_new_w, m_new_h, Qt::KeepAspectRatio, Qt::FastTransformation));
m_pixmap = QPixmap::fromImage(m_orig_image.scaled(m_new_w, m_new_h,
Qt::KeepAspectRatio, Qt::SmoothTransformation));

// for showing to the user
m_pixmap = m_pixmap.scaled(m_orig_image.width(), m_orig_image.height());
m_pixmap = m_pixmap.scaled(m_orig_image.width(), m_orig_image.height(),
Qt::KeepAspectRatio, Qt::FastTransformation);

return true;
}
Expand Down
12 changes: 8 additions & 4 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ private slots:
void on_btn_rotate_right_clicked();
void on_btn_rotate_left_clicked();

// runs in gui thread
void show_pixmap();
void show_pixmap(); // runs in gui thread
void reprocess_image_smooth(int scale, int); // runs in gui thread
void reprocess_image_impl(int scale, int quality); // runs in concurrent thread

// runs in concurrent thread
void reprocess_image_impl(int scale, int quality);
void reprocess_image_fast(int scale, int); // runs in gui thread
void show_pixmap_fast(); // runs in gui thread

void on_action_open_triggered();
void on_action_save_as_triggered();
Expand All @@ -82,6 +83,9 @@ private slots:
qint16 m_current_scale;
qint64 m_new_size;

qint64 m_current_size;
bool m_fast;

int m_new_w;
int m_new_h;
int m_sld_zoom_value;
Expand Down

0 comments on commit 1cd6e0a

Please sign in to comment.