diff --git a/Anime4KCore/include/Anime4K.h b/Anime4KCore/include/Anime4K.h index fe4359a1..df239864 100644 --- a/Anime4KCore/include/Anime4K.h +++ b/Anime4KCore/include/Anime4K.h @@ -58,6 +58,21 @@ class DLL Anime4K uint8_t postFilters = 40, unsigned int maxThreads = std::thread::hardware_concurrency() ); + virtual ~Anime4K(); + void setArguments( + int passes = 2, + int pushColorCount = 2, + double strengthColor = 0.3, + double strengthGradient = 1.0, + double zoomFactor = 2.0, + bool fastMode = false, + bool videoMode = false, + bool PreProcessing = false, + bool postProcessing = false, + 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); diff --git a/Anime4KCore/include/Anime4KGPU.h b/Anime4KCore/include/Anime4KGPU.h index ac620273..6db36839 100644 --- a/Anime4KCore/include/Anime4KGPU.h +++ b/Anime4KCore/include/Anime4KGPU.h @@ -7,7 +7,7 @@ #include #else #include -#endif // __APPLE__ +#endif // SPECIAL OS class DLL Anime4KGPU : @@ -28,7 +28,7 @@ class DLL Anime4KGPU : uint8_t postFilters = 40, unsigned int maxThreads = std::thread::hardware_concurrency() ); - ~Anime4KGPU(); + virtual ~Anime4KGPU(); virtual void process(); static std::pair checkGPUSupport(); protected: diff --git a/Anime4KCore/src/Anime4K.cpp b/Anime4KCore/src/Anime4K.cpp index c213f513..80f7caeb 100644 --- a/Anime4KCore/src/Anime4K.cpp +++ b/Anime4KCore/src/Anime4K.cpp @@ -15,8 +15,7 @@ Anime4K::Anime4K( uint8_t preFilters, uint8_t postFilters, unsigned int maxThreads -) : - ps(passes), pcc(pushColorCount), +) : ps(passes), pcc(pushColorCount), sc(strengthColor), sg(strengthGradient), zf(zoomFactor), fm(fastMode), vm(videoMode), pre(PreProcessing), post(postProcessing), pref(preFilters), @@ -26,6 +25,46 @@ Anime4K::Anime4K( frameCount = totalFrameCount = fps = 0; } +Anime4K::~Anime4K() +{ + orgImg.release(); + dstImg.release(); + videoWriter.release(); + video.release(); +} + +void Anime4K::setArguments( + int passes, + int pushColorCount, + double strengthColor, + double strengthGradient, + double zoomFactor, + bool fastMode, + bool videoMode, + bool PreProcessing, + bool postProcessing, + uint8_t preFilters, + uint8_t postFilters, + unsigned int maxThreads +) +{ + ps = passes; + pcc = pushColorCount; + sc = strengthColor; + sg = strengthGradient; + zf = zoomFactor; + fm = fastMode; + vm = videoMode; + pre = PreProcessing; + post = postProcessing; + pref = preFilters; + postf = postFilters; + mt = maxThreads; + + orgH = orgW = H = W = 0; + frameCount = totalFrameCount = fps = 0; +} + void Anime4K::setVideoMode(const bool flag) { vm = flag; diff --git a/GUI/include/mainwindow.h b/GUI/include/mainwindow.h index 296d354d..bf4cb83e 100644 --- a/GUI/include/mainwindow.h +++ b/GUI/include/mainwindow.h @@ -3,6 +3,7 @@ #include "communicator.h" #include "Anime4K.h" +#include "Anime4KGPU.h" #include #include @@ -43,6 +44,11 @@ enum FileType IMAGE = 0, VIDEO = 1, ERROR_TYPE=2 }; +enum GPUMode +{ + GPUMODE_INITIALZED = 0, GPUMODE_UNINITIALZED = 1, GPUMODE_UNSUPPORT = 3 +}; + class MainWindow : public QMainWindow { Q_OBJECT @@ -66,7 +72,7 @@ class MainWindow : public QMainWindow bool checkFFmpeg(); QString formatSuffixList(const QString &&type, QString str); void initAnime4K(Anime4K *&anime4K); - void releaseAnime4K(Anime4K *&anime4K); + void releaseMainAnime4K(); FileType fileType(const QFileInfo &file); QString getOutputPrefix(); @@ -125,6 +131,8 @@ private slots: void on_pushButtonPickFolder_clicked(); + void on_checkBoxGPUMode_stateChanged(int arg1); + private: Ui::MainWindow *ui; QTranslator *translator; @@ -136,5 +144,9 @@ private slots: bool ffmpeg; unsigned int totalTaskCount; Language currLanguage; + + GPUMode GPU; + Anime4K *mainAnime4kCPU; + Anime4K *mainAnime4kGPU; }; #endif // MAINWINDOW_H diff --git a/GUI/src/Anime4KCPP_GUI_zh_CN.ts b/GUI/src/Anime4KCPP_GUI_zh_CN.ts index 555e9b58..fe41cf4d 100644 --- a/GUI/src/Anime4KCPP_GUI_zh_CN.ts +++ b/GUI/src/Anime4KCPP_GUI_zh_CN.ts @@ -15,7 +15,7 @@ - + pick 打开 @@ -176,8 +176,8 @@ - - + + image 图像 @@ -188,8 +188,8 @@ - - + + video 视频 @@ -396,84 +396,94 @@ 使用线程数 - + Faster but maybe low quality 更快但可能降低质量 - + fast mode 快速模式 - + + Enable GPU acceleration + + + + + GPU acceleration + GPU加速 + + + Preview for test preview for test 快速预览 - + Quickly preview for testing arguments 快速预览以测试参数 - + preview 预览 - + only resize 仅放大 - + orgin image 原图 - + Menu 菜单 - + Language 语言 - + Option 选项 - + GUI - - + + About 关于 - + Quit 退出 - + English - + Chinese 中文 - + Quit confirmation 退出时确认 @@ -501,75 +511,91 @@ 状态 - + Confirm 确认 - + Do you really want to exit? 确认退出? - - - + + + ready 就绪 - + Error 错误 - + Only ASCII encoding is supported 仅支持英文文件名 - + File type error, only image support 文件类型错误,仅支持图像 - + + Warning 警告 - + FFmpeg did not fount 未发现FFmpeg - + done 完成 - - + + error 出错 - - + + + + + Notice 注意 - + + You are using GPU acceleration but still enabledpreprocessing or postprocessing, which is not GPU acceletation yet, and may slow down processing for GPU (usually still faster than CPU), close them? + You are using GPU acceleration but still enablepreprocessing or postprocessing, which is not GPU acceletation yet,and may slow down processing for GPU(usually still faster than CPU), close them? + 您正在使用GPU加速模式,但依然启用了预处理或者后处理,这可能会拖慢GPU的处理速度(通常依然快于CPU),关闭他们吗? + + + Log has been copied to the clipboard 日志已拷贝至剪切板 - + + You are trying to enable GPU acceleration, which is an experimental function, check and inital GPU? + You are trying to enable GPU accelaretion, which is an experimental function, check and inital GPU? + 您正在尝试启用GPU加速,这还是一个实验性功能,检查兼容性并初始化吗? + + + File does not exists 文件不存在 @@ -578,25 +604,25 @@ 文件类型错误,仅支持图片 - + File type error, you can add it manually 文件类型错误,可手动添加后缀 - + Processing list empty 处理列表为空 - - + + pick files 打开文件 - - + + output directory 输出文件夹 diff --git a/GUI/src/mainwindow.cpp b/GUI/src/mainwindow.cpp index 581747e5..5a585eba 100644 --- a/GUI/src/mainwindow.cpp +++ b/GUI/src/mainwindow.cpp @@ -41,6 +41,11 @@ MainWindow::MainWindow(QWidget *parent) //inital config config = new QSettings("settings.ini", QSettings::IniFormat, this); readConfig(config); + //inital Anime4KCoreForCPU + mainAnime4kCPU = new Anime4K; + mainAnime4kGPU = nullptr; + //inital GPU + GPU = GPUMODE_UNINITIALZED; //Register qRegisterMetaType("std::string"); } @@ -48,6 +53,7 @@ MainWindow::MainWindow(QWidget *parent) MainWindow::~MainWindow() { delete ui; + releaseMainAnime4K(); } void MainWindow::closeEvent(QCloseEvent *event) @@ -435,7 +441,11 @@ void MainWindow::initAnime4K(Anime4K *&anime4K) if (ui->checkBoxPostBilateralFaster->isChecked()) postfilters|=64; } - anime4K = new Anime4K(passes, + if(ui->checkBoxGPUMode->isChecked()) + anime4K = mainAnime4kGPU; + else + anime4K = mainAnime4kCPU; + anime4K->setArguments(passes, pushColorCount, pushColorStrength, pushGradientStrength, @@ -449,9 +459,11 @@ void MainWindow::initAnime4K(Anime4K *&anime4K) threads); } -inline void MainWindow::releaseAnime4K(Anime4K *&anime4K) +inline void MainWindow::releaseMainAnime4K() { - delete anime4K; + delete mainAnime4kCPU; + if(mainAnime4kGPU!=nullptr) + delete mainAnime4kGPU; } FileType MainWindow::fileType(const QFileInfo &file) @@ -733,8 +745,6 @@ void MainWindow::on_pushButtonPreview_clicked() break; } - releaseAnime4K(anime4k); - ui->pushButtonPreview->setEnabled(true); } @@ -753,6 +763,21 @@ void MainWindow::on_pushButtonPreviewPick_clicked() void MainWindow::on_pushButtonStart_clicked() { + if(ui->checkBoxGPUMode->isChecked() && (ui->checkBoxEnablePreprocessing->isChecked() || ui->checkBoxEnablePostprocessing->isChecked())) + { + if (QMessageBox::Yes == QMessageBox::information(this, + tr("Notice"), + tr("You are using GPU acceleration but still enabled" + "preprocessing or postprocessing, which is not GPU acceletation yet, " + "and may slow down processing for GPU (usually still faster than CPU), close them?"), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::Yes)) + { + ui->checkBoxEnablePreprocessing->setChecked(false); + ui->checkBoxEnablePostprocessing->setChecked(false); + } + } + int rows = tableModel->rowCount(); if(!rows) { @@ -883,7 +908,6 @@ void MainWindow::on_pushButtonStart_clicked() } } - releaseAnime4K(anime4k); emit cm.allDone(); }); @@ -1025,3 +1049,43 @@ void MainWindow::on_pushButtonPickFolder_clicked() ui->labelTotalTaskCount->setText(QString("Total: %1 ").arg(totalTaskCount)); } + +void MainWindow::on_checkBoxGPUMode_stateChanged(int state) +{ + if((state == Qt::Checked) && (GPU == GPUMODE_UNINITIALZED)) + { + if(QMessageBox::Yes == QMessageBox::information(this, + tr("Notice"), + tr("You are trying to enable GPU acceleration, " + "which is an experimental function, check and inital GPU?"), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No)) + { + std::pair ret = Anime4KGPU::checkGPUSupport(); + if(!ret.first) + { + QMessageBox::warning(this, + tr("Warning"), + QString::fromStdString(ret.second), + QMessageBox::Ok); + GPU = GPUMODE_UNSUPPORT; + } + else + { + mainAnime4kGPU = new Anime4KGPU; + GPU = GPUMODE_INITIALZED; + QMessageBox::information(this, + tr("Notice"), + "Inital successful!\n" + + QString::fromStdString(ret.second), + QMessageBox::Ok); + ui->textBrowserInfoOut->insertPlainText("GPU inital successful!\n" + QString::fromStdString(ret.second) + "\n"); + ui->textBrowserInfoOut->moveCursor(QTextCursor::End); + } + } + else + { + ui->checkBoxGPUMode->setCheckState(Qt::Unchecked); + } + } +} diff --git a/GUI/src/mainwindow.ui b/GUI/src/mainwindow.ui index 9ca9df94..f6e65664 100644 --- a/GUI/src/mainwindow.ui +++ b/GUI/src/mainwindow.ui @@ -562,7 +562,7 @@ Arguments - + @@ -666,14 +666,28 @@ - - - Faster but maybe low quality - - - fast mode - - + + + + + Faster but maybe low quality + + + fast mode + + + + + + + Enable GPU acceleration + + + GPU acceleration + + + +