Skip to content

Commit

Permalink
Add GUI support
Browse files Browse the repository at this point in the history
  • Loading branch information
TianZerL committed Apr 19, 2020
1 parent c8a523d commit 5589623
Show file tree
Hide file tree
Showing 14 changed files with 1,848 additions and 12 deletions.
3 changes: 2 additions & 1 deletion Anime4KCore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ project(Anime4KCore)
aux_source_directory(src SOURCE)

include_directories(include)
file(GLOB INCLUDE include/*.h)

add_library(${PROJECT_NAME} SHARED ${SOURCE})
add_library(${PROJECT_NAME} SHARED ${INCLUDE} ${SOURCE})

include(../cmake/ThirdParty.cmake)
32 changes: 26 additions & 6 deletions Anime4KCore/include/Anime4K.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once
#include<iostream>
#include<sstream>
#include<functional>

#include<opencv2/opencv.hpp>
Expand All @@ -15,15 +16,32 @@
#include<omp.h>
#endif

#define MAX3(a, b, c) (a > b && a > c ? a : (b > c ? b : c))
#define MIN3(a, b, c) (a < b && a < c ? a : (b < c ? b : c))
#define UNFLOAT(n) (n >= 255 ? 255 : (n <= 0 ? 0 : uint8_t(n + 0.5)))
#ifdef _MSC_VER
#ifndef DLL
#define DLL __declspec(dllimport)
#else
#undef DLL
#define DLL __declspec(dllexport)
#endif
#else
#ifndef DLL
#define DLL
#endif
#endif

#define MAX3(a, b, c) std::max({a, b, c})
#define MIN3(a, b, c) std::min({a, b, c})
#define UNFLOAT(n) ((n) >= 255 ? 255 : ((n) <= 0 ? 0 : uint8_t((n) + 0.5)))

typedef unsigned char* RGBA;
typedef unsigned char* Line;

enum BGRA
{
B = 0, G = 1, R = 2, A = 3
};

class Anime4K
class DLL Anime4K
{
public:
Anime4K(
Expand All @@ -39,13 +57,16 @@ class Anime4K
uint8_t preFilters = 40,
uint8_t postFilters = 40,
unsigned int maxThreads = std::thread::hardware_concurrency());
void setVideoMode(const bool flag);
void loadVideo(const std::string& srcFile);
void loadImage(const std::string& srcFile);
void setVideoSaveInfo(const std::string& dstFile);
void saveImage(const std::string& dstFile);
void saveVideo();
void showInfo();
void showFiltersInfo();
std::string getInfo();
std::string getFiltersInfo();
void showImage();
void process();
private:
Expand All @@ -57,7 +78,6 @@ class Anime4K
void getLightest(RGBA mc, RGBA a, RGBA b, RGBA c);
void getAverage(RGBA mc, RGBA a, RGBA b, RGBA c);
private:
const static int B = 0, G = 1, R = 2, A = 3;
int orgH, orgW, H, W;
double fps;
size_t totalFrameCount, frameCount;
Expand All @@ -67,9 +87,9 @@ class Anime4K
std::mutex videoMtx;
std::condition_variable cnd;
private://arguments
unsigned int mt;
int ps, pcc;
double sc, sg, zf;
bool fm, vm, pre, post;
uint8_t pref, postf;
unsigned int mt;
};
6 changes: 3 additions & 3 deletions Anime4KCore/include/filterprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include<omp.h>
#endif

#define MAX5(a, b, c, d, e) (a > b && a > c && a > d && a > e ? a : (b > c && b > d && b > e ? b : (c > d && c > e ? c : ( d > e ? d : e))))
#define MIN5(a, b, c, d, e) (a < b && a < c && a < d && a < e ? a : (b < c && b < d && b < e ? b : (c < d && c < e ? c : ( d < e ? d : e))))
#define MAX5(a, b, c, d, e) std::max({a, b, c, d, e})
#define MIN5(a, b, c, d, e) std::min({a, b, c, d, e})
#define LERP(x, y, w) ((x) * (1 - (w)) + (y) * (w))
#define REC(n) ((n) < 1 ? 1.0 : 1.0 / (n))
#define UNFLOAT(n) (n >= 255 ? 255 : (n <= 0 ? 0 : uint8_t(n + 0.5)))
#define UNFLOAT(n) ((n) >= 255 ? 255 : ((n) <= 0 ? 0 : uint8_t((n) + 0.5)))

typedef unsigned char* RGBA;
typedef unsigned char* Line;
Expand Down
86 changes: 86 additions & 0 deletions Anime4KCore/src/Anime4K.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#define DLL

#include "Anime4K.h"

Anime4K::Anime4K(
Expand All @@ -24,6 +26,11 @@ Anime4K::Anime4K(
frameCount = totalFrameCount = fps = 0;
}

void Anime4K::setVideoMode(const bool flag)
{
vm = flag;
}

void Anime4K::loadVideo(const std::string& dstFile)
{
video.open(dstFile);
Expand Down Expand Up @@ -140,6 +147,85 @@ void Anime4K::showFiltersInfo()
std::cout << "----------------------------------------------" << std::endl;
}

std::string Anime4K::getInfo()
{
std::ostringstream oss;
oss << "----------------------------------------------" << std::endl;
oss << "Welcome to use Anime4KCPP" << std::endl;
oss << "----------------------------------------------" << std::endl;
if (vm)
{
oss << "Threads: " << mt << std::endl;
oss << "Total frame: " << totalFrameCount << std::endl;
}
oss << orgW << "x" << orgH << " to " << W << "x" << H << std::endl;
oss << "----------------------------------------------" << std::endl;
oss << "Passes: " << ps << std::endl
<< "pushColorCount: " << pcc << std::endl
<< "Zoom Factor: " << zf << std::endl
<< "Video Mode: " << std::boolalpha << vm << std::endl
<< "Fast Mode: " << std::boolalpha << fm << std::endl
<< "Strength Color: " << sc << std::endl
<< "Strength Gradient: " << sg << std::endl;
oss << "----------------------------------------------" << std::endl;
return std::string(oss.str());
}

std::string Anime4K::getFiltersInfo()
{
std::ostringstream oss;
oss << "----------------------------------------------" << std::endl;
oss << "Pre processing filters list:" << std::endl;
oss << "----------------------------------------------" << std::endl;
if (!pre)
{
oss << "Pre processing disable" << std::endl;
}
else
{
if (pref & MEDIAN_BLUR)
oss << "Median blur" << std::endl;
if (pref & MEAN_BLUR)
oss << "Mean blur" << std::endl;
if (pref & CAS_SHARPENING)
oss << "CAS Sharpening" << std::endl;
if (pref & GAUSSIAN_BLUR_WEAK)
oss << "Gaussian blur weak" << std::endl;
else if (pref & GAUSSIAN_BLUR)
oss << "Gaussian blur" << std::endl;
if (pref & BILATERAL_FILTER)
oss << "Bilateral filter" << std::endl;
else if (pref & BILATERAL_FILTER_FAST)
oss << "Bilateral filter faster" << std::endl;
}
oss << "----------------------------------------------" << std::endl;
oss << "Post processing filters list:" << std::endl;
oss << "----------------------------------------------" << std::endl;
if (!post)
{
oss << "Post processing disable" << std::endl;
}
else
{
if (postf & MEDIAN_BLUR)
oss << "Median blur" << std::endl;
if (postf & MEAN_BLUR)
oss << "Mean blur" << std::endl;
if (postf & CAS_SHARPENING)
oss << "CAS Sharpening" << std::endl;
if (postf & GAUSSIAN_BLUR_WEAK)
oss << "Gaussian blur weak" << std::endl;
else if (postf & GAUSSIAN_BLUR)
oss << "Gaussian blur" << std::endl;
if (postf & BILATERAL_FILTER)
oss << "Bilateral filter" << std::endl;
else if (postf & BILATERAL_FILTER_FAST)
oss << "Bilateral filter faster" << std::endl;
}
oss << "----------------------------------------------" << std::endl;
return std::string(oss.str());
}

void Anime4K::showImage()
{
cv::imshow("dstImg", dstImg);
Expand Down
4 changes: 2 additions & 2 deletions Anime4KCore/src/filterprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void FilterProcessor::process()
cv::bilateralFilter(img, tmpImg, 5, 35, 35);
}

void FilterProcessor::CASSharpening(cv::InputArray img)
inline void FilterProcessor::CASSharpening(cv::InputArray img)
{
int lineStep = W * 3;
changEachPixelBGR(img, [&](int i, int j, RGBA pixel, Line curLine) {
Expand Down Expand Up @@ -68,7 +68,7 @@ void FilterProcessor::CASSharpening(cv::InputArray img)
});
}

void FilterProcessor::changEachPixelBGR(cv::InputArray _src,
inline void FilterProcessor::changEachPixelBGR(cv::InputArray _src,
const std::function<void(int, int, RGBA, Line)>&& callBack)
{
cv::Mat src = _src.getMat();
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ endif()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(TOP_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

macro(SUBDIRLIST result curdir)
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
Expand Down
37 changes: 37 additions & 0 deletions GUI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
project(Anime4KCPP_GUI LANGUAGES CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(TS_FILES ./src/Anime4KCPP_GUI_zh_CN.ts)
set(UI_FILE ./src/mainwindow.ui)

include_directories(include ../ThirdParty/include ../Anime4KCore/include)
file(GLOB INCLUDE include/*.h)

aux_source_directory(src SOURCE)

add_executable(Anime4KCPP_GUI
WIN32
${INCLUDE}
${SOURCE}
${TS_FILES}
${UI_FILE}
)

find_package(Qt5 COMPONENTS Widgets LinguistTools REQUIRED)
find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})

target_link_libraries(Anime4KCPP_GUI PRIVATE Qt5::Widgets)
target_link_libraries(${PROJECT_NAME} PRIVATE ${OpenCV_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE Anime4KCore)

qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
19 changes: 19 additions & 0 deletions GUI/include/communicator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef COMMUNICATOR_H
#define COMMUNICATOR_H

#include <QObject>

class Communicator : public QObject
{
Q_OBJECT
public:
explicit Communicator(QObject *parent = nullptr);

signals:
void error(int row, QString err);
void done(int row, double pro, quint64 time);
void allDone();
void showInfo(std::string info);
};

#endif // COMMUNICATOR_H
103 changes: 103 additions & 0 deletions GUI/include/mainwindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "communicator.h"
#include "Anime4K.h"

#include <QMainWindow>
#include <QTranslator>
#include <QCloseEvent>
#include <QMessageBox>
#include <QStandardItemModel>
#include <QFileDialog>
#include <QFileInfo>
#include <QMimeData>
#include <QtConcurrent/QtConcurrent>
#include <QMutex>
#include <QMetaType>

#define CORE_VERSION "1.3"
#define VERSION "0.9"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

enum FileType
{
IMAGE = 0, VIDEO = 1, ERROR=2
};

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();

protected:
void closeEvent(QCloseEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
void dropEvent(QDropEvent *event);

private:
void initTextBrowser();
bool checkFFmpeg();
QString formatSuffixList(const QString &&type, QString str);
void initAnime4K(Anime4K *&anime4K);
void releaseAnime4K(Anime4K *&anime4K);
FileType fileType(QFileInfo &file);

private slots:
void solt_done_renewState(int row, double pro, quint64 time);
void solt_error_renewState(int row, QString err);
void solt_allDone_remindUser();
void solt_showInfo_renewTextBrowser(std::string info);

private slots:
void on_actionQuit_triggered();

void on_pushButtonInputPath_clicked();

void on_pushButtonOutputPath_clicked();

void on_pushButtonClear_clicked();

void on_pushButtonDelete_clicked();

void on_radioButtonFast_clicked();

void on_radioButtonBalance_clicked();

void on_radioButtonQuality_clicked();

void on_checkBoxEnablePreprocessing_stateChanged(int arg1);

void on_checkBoxEnablePostprocessing_stateChanged(int arg1);

void on_pushButtonPreview_clicked();

void on_pushButtonPreviewPick_clicked();

void on_pushButtonStart_clicked();

void on_actionAbout_triggered();

void on_tabWidgetMain_tabBarClicked(int index);

void on_actionChinese_triggered();

void on_actionEnglish_triggered();

private:
Ui::MainWindow *ui;
QTranslator *translator;
QStandardItemModel *tableModel;
QMutex *mutex;
quint64 totalTime;
int imageCount;
int videoCount;
bool ffmpeg;
};
#endif // MAINWINDOW_H
Loading

0 comments on commit 5589623

Please sign in to comment.