Skip to content

Commit

Permalink
Implemented rotate left and right all images.
Browse files Browse the repository at this point in the history
  • Loading branch information
ponchio committed Jan 12, 2024
1 parent d4d18d4 commit 6fb43ff
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
19 changes: 18 additions & 1 deletion relight/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ MainWindow::MainWindow(QWidget *parent) :
connect(ui->actionDelete_selected, SIGNAL(triggered()), this, SLOT(deleteSelected()));
ui->actionDelete_selected->setShortcuts(QList<QKeySequence>() << Qt::Key_Delete << Qt::Key_Backspace);

connect(ui->actionRotate_all_left, SIGNAL(triggered()), this, SLOT(rotateAllLeft()));
connect(ui->actionRotate_all_right, SIGNAL(triggered()), this, SLOT(rotateAllRight()));

QObject::connect(new QShortcut(QKeySequence(Qt::Key_Escape), this), &QShortcut::activated, this, &MainWindow::esc);
QObject::connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Z), this), &QShortcut::activated, this, &MainWindow::undo);
QObject::connect(new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z), this), &QShortcut::activated, this, &MainWindow::redo);
Expand Down Expand Up @@ -406,6 +409,20 @@ void MainWindow::openImage(int id, bool fit) {
showHighlights(n);
}

void MainWindow::rotateAllLeft() {
if(project.size()) {
project.rotateImages(false);
openImage(currentImage, false);
}
}
void MainWindow::rotateAllRight() {
if(project.size()) {
project.rotateImages(true);
openImage(currentImage, false);
}
}


void MainWindow::showHighlights(size_t n) {
ignore_scene_changes = true;
for(auto marker: ui->markerList->getItems()) {
Expand Down Expand Up @@ -825,7 +842,7 @@ void MainWindow::loadLP(QString lp) {

if(project.size() != filenames.size()) {
auto response = QMessageBox::question(this, "Light directions and images",
QString("The folder contains %1 images, the .lp file specify %1 images.\n")
QString("The folder contains %1 images, the .lp file specify %2 images.\n")
.arg(project.size()).arg(filenames.size()));
if(response == QMessageBox::Cancel || response == QMessageBox::No)
return;
Expand Down
2 changes: 2 additions & 0 deletions relight/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public slots:
void openImage(int id, bool fit = false);
void imageChecked(QStandardItem *item);

void rotateAllLeft();
void rotateAllRight();
void next();
void previous();
void doubleClick(QPoint p);
Expand Down
4 changes: 2 additions & 2 deletions relight/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
<addaction name="actionDelete_selected"/>
<addaction name="separator"/>
<addaction name="actionRotate_all_right"/>
<addaction name="actionRotate_all_right_2"/>
<addaction name="actionRotate_all_left"/>
<addaction name="actionDStretch"/>
</widget>
<widget class="QMenu" name="menuHelp">
Expand Down Expand Up @@ -618,7 +618,7 @@
<string>Rotate right all images</string>
</property>
</action>
<action name="actionRotate_all_right_2">
<action name="actionRotate_all_left">
<property name="text">
<string>Rotate left all images</string>
</property>
Expand Down
12 changes: 11 additions & 1 deletion relight/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,16 @@ double mutualInfo(QImage &a, QImage &b) {
return m;
}

void Project::rotateImages(bool clockwise) {
QTransform rotate;
rotate.rotate(clockwise ? 90 : -90);
for(Image &image: images) {
QImage source(image.filename);
QImage rotated = source.transformed(rotate);
rotated.save(image.filename, "jpg", 100);
}
}

void Project::rotateImages() {
//find first image non rotated.
QString target_filename;
Expand Down Expand Up @@ -218,7 +228,7 @@ void Project::rotateImages() {
QTransform final = right_mutual > left_mutual ? rot_left : rot_right;
//TODO should be libjpeg to rotate.
QImage rotated = source.transformed(final);
rotated.save(image.filename);
rotated.save(image.filename, "jpg", 100);

image.size = imgsize;
image.valid = true;
Expand Down
1 change: 1 addition & 0 deletions relight/project.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Project {
bool setDir(QDir folder);
bool scanDir(); //load images from project.dir, and return false if some problems with resolution.
void rotateImages();
void rotateImages(bool clockwise);
bool hasDirections() {
for(auto &im: images)
if(!im.direction.isZero())
Expand Down

0 comments on commit 6fb43ff

Please sign in to comment.