Skip to content

Commit

Permalink
Add batch tool
Browse files Browse the repository at this point in the history
This tool allows to process multiple images in one pipeline.
Can be usefull when one needs to process several images of the
same type.
  • Loading branch information
kmkolasinski committed Feb 16, 2017
1 parent 521bafb commit 8e4d630
Show file tree
Hide file tree
Showing 10 changed files with 363 additions and 40 deletions.
9 changes: 6 additions & 3 deletions Sources/Sources.pro
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ HEADERS = glwidget.h \
utils/glslshaderparser.h \
utils/glslparsedshadercontainer.h \
utils/contextinfo/contextwidget.h \
utils/contextinfo/renderwindow.h
utils/contextinfo/renderwindow.h \
formimagebatch.h

SOURCES = glwidget.cpp \
main.cpp \
Expand Down Expand Up @@ -118,7 +119,8 @@ SOURCES = glwidget.cpp \
properties/PropertyABColor.cpp \
properties/PropertyDelegateABColor.cpp \
utils/contextinfo/contextwidget.cpp \
utils/contextinfo/renderwindow.cpp
utils/contextinfo/renderwindow.cpp \
formimagebatch.cpp


RESOURCES += content.qrc
Expand All @@ -145,7 +147,8 @@ FORMS += \
allaboutdialog.ui \
dialogshortcuts.ui \
dockwidget3dsettings.ui \
properties/Dialog3DGeneralSettings.ui
properties/Dialog3DGeneralSettings.ui \
formimagebatch.ui

ICON = resources/icons/icon.icns

Expand Down
14 changes: 14 additions & 0 deletions Sources/formimagebatch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "formimagebatch.h"
#include "ui_formimagebatch.h"

FormImageBatch::FormImageBatch(QWidget *parent) :
QWidget(parent),
ui(new Ui::FormImageBatch)
{
ui->setupUi(this);
}

FormImageBatch::~FormImageBatch()
{
delete ui;
}
22 changes: 22 additions & 0 deletions Sources/formimagebatch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef FORMIMAGEBATCH_H
#define FORMIMAGEBATCH_H

#include <QWidget>

namespace Ui {
class FormImageBatch;
}

class FormImageBatch : public QWidget
{
Q_OBJECT

public:
explicit FormImageBatch(QWidget *parent = 0);
~FormImageBatch();

private:
Ui::FormImageBatch *ui;
};

#endif // FORMIMAGEBATCH_H
112 changes: 112 additions & 0 deletions Sources/formimagebatch.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FormImageBatch</class>
<widget class="QWidget" name="FormImageBatch">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>3</number>
</property>
<property name="leftMargin">
<number>3</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>3</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum>
</property>
<item>
<widget class="QPushButton" name="pushButtonSourcePath">
<property name="text">
<string>Source folder</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonOutputPath">
<property name="text">
<string>Output folder</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonRunBatch">
<property name="text">
<string>Run batch</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="horizontalSpacing">
<number>3</number>
</property>
<property name="verticalSpacing">
<number>3</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Source path</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lineEditSourcePath">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Output path</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="lineEditOutputPath">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>3</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
2 changes: 1 addition & 1 deletion Sources/formimageprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ bool FormImageProp::loadFile(const QString &fileName)
{
QFileInfo fileInfo(fileName);
QImage _image;

// qDebug() << "Opening file: " << fileName;
// Targa support added
if(fileInfo.completeSuffix().compare("tga") == 0){
TargaImage tgaImage;
Expand Down
4 changes: 2 additions & 2 deletions Sources/formimageprop.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class FormImageProp : public FormImageBase

void setupPopertiesGUI();
void reloadSettings();

bool loadFile(const QString &fileName);

~FormImageProp();

Expand Down Expand Up @@ -85,7 +85,7 @@ public slots:


private:
bool loadFile(const QString &fileName);

void pasteImageFromClipboard(QImage& _image);


Expand Down
2 changes: 1 addition & 1 deletion Sources/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ int main(int argc, char *argv[])
regABSliderDelegates();
regABColorDelegates();

qInstallMessageHandler(customMessageHandler);
// qInstallMessageHandler(customMessageHandler);

qDebug() << "Starting application:";
qDebug() << "Application dir:" << QApplication::applicationDirPath();
Expand Down
91 changes: 90 additions & 1 deletion Sources/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ void MainWindow::initializeApp()
connect(settingsContainer,SIGNAL(forceSaveCurrentConfig()),this,SLOT(saveSettings()));
connect(ui->pushButtonProjectManager,SIGNAL(toggled(bool)),settingsContainer,SLOT(setVisible(bool)));


// -------------------------------------------------------
// 3D settings widget
// -------------------------------------------------------
Expand Down Expand Up @@ -388,6 +389,12 @@ void MainWindow::initializeApp()
connect(ui->checkBoxToggleMouseLoop ,SIGNAL(toggled(bool)),glWidget,SLOT(toggleMouseWrap(bool)));
connect(ui->checkBoxToggleMouseLoop ,SIGNAL(toggled(bool)),glImage ,SLOT(toggleMouseWrap(bool)));

// batch settings
connect(ui->pushButtonImageBatchSource ,SIGNAL(pressed()),this,SLOT(selectSourceImages()));
connect(ui->pushButtonImageBatchOutput ,SIGNAL(pressed()),this,SLOT(selectOutputPath()));
connect(ui->pushButtonImageBatchRun ,SIGNAL(pressed()),this,SLOT(runBatch()));




#ifdef Q_OS_MAC
Expand Down Expand Up @@ -728,7 +735,8 @@ void MainWindow::saveImages(){
}

bool MainWindow::saveAllImages(const QString &dir){
QFileInfo fileInfo(dir);

QFileInfo fileInfo(dir);
if (!fileInfo.exists()) {
QMessageBox::information(this, QGuiApplication::applicationDisplayName(),
tr("Cannot save to %1.").arg(QDir::toNativeSeparators(dir)));
Expand Down Expand Up @@ -1321,6 +1329,87 @@ void MainWindow::selectContrastInputImage(int mode){
replotAllImages();
}

void MainWindow::selectSourceImages(){

QString startPath;
if(recentDir.exists()) startPath = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).first();
else startPath = recentDir.absolutePath();

QString source = QFileDialog::getExistingDirectory(this, tr("Select source directory"),
startPath,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);

QDir dir(source);
qDebug() << "Selecting source folder for batch processing: " << source;

QStringList filters;
filters << "*.png" << "*.jpg" << "*.bmp" << "*.tga";
QFileInfoList fileInfoList = dir.entryInfoList(filters, QDir::Files | QDir::NoDotAndDotDot);

ui->listWidgetImageBatch->clear();
foreach (QFileInfo fileInfo, fileInfoList) {
qDebug() << "Found:" << fileInfo.absoluteFilePath();
ui->listWidgetImageBatch->addItem(fileInfo.fileName());
}
ui->lineEditImageBatchSource->setText(source);
}

void MainWindow::selectOutputPath(){

QString startPath;
if(recentDir.exists()) startPath = QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).first();
else startPath = recentDir.absolutePath();

QString path = QFileDialog::getExistingDirectory(this, tr("Select source directory"),
startPath,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);

ui->lineEditImageBatchOutput->setText(path);
}

void MainWindow::runBatch(){

QString sourceFolder = ui->lineEditImageBatchSource->text();
QString outputFolder = ui->lineEditImageBatchOutput->text();

// check if output path exists
if(!QDir(outputFolder).exists() || outputFolder == ""){
QMessageBox msgBox;
msgBox.setText("Info");
msgBox.setInformativeText("Output path is not provided");
msgBox.setStandardButtons(QMessageBox::Cancel);
msgBox.exec();
return;
}

qDebug() << "Starting batch mode: this may take some time";


while(ui->listWidgetImageBatch->count() > 0){
QListWidgetItem* item = ui->listWidgetImageBatch->takeItem(0);
ui->labelBatchProgress->setText("Images left: " + QString::number(ui->listWidgetImageBatch->count()+1));
ui->labelBatchProgress->repaint();
QCoreApplication::processEvents();

QString imageName = item->text();
ui->lineEditOutputName->setText(imageName);
QString imagePath = sourceFolder + "/" + imageName;

qDebug() << "Processing image: " << imagePath;
diffuseImageProp->loadFile(imagePath);
convertFromBase();
saveAllImages(outputFolder);

delete item;
ui->listWidgetImageBatch->repaint();
QCoreApplication::processEvents();
}

ui->labelBatchProgress->setText("Done...");

}


void MainWindow::randomizeAngles(){
FBOImageProporties::seamlessRandomTiling.randomize();
replotAllImages();
Expand Down
5 changes: 5 additions & 0 deletions Sources/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QFileDialog>
#include <QDragEnterEvent>
#include <QDropEvent>

#include <QDir>

#include "CommonObjects.h"
Expand Down Expand Up @@ -136,6 +137,10 @@ public slots:
void resetRandomPatches();
void selectContrastInputImage(int mode);

// batch tool
void selectSourceImages();
void selectOutputPath();
void runBatch();
private:
// saves all textures to given directory
bool saveAllImages(const QString &dir);
Expand Down
Loading

0 comments on commit 8e4d630

Please sign in to comment.