136 lines
3.9 KiB
C++
136 lines
3.9 KiB
C++
#include "dialog_multirotateimagefile.h"
|
|
#include "ui_dialog_multirotateimagefile.h"
|
|
#include "imgfmt/HGImgFmt.h"
|
|
#include "HGUIGlobal.h"
|
|
|
|
Dialog_MultiRotateImageFile::Dialog_MultiRotateImageFile(const QStringList &fileList, int rotateType, QWidget *parent) :
|
|
QDialog(parent),
|
|
ui(new Ui::Dialog_MultiRotateImageFile),
|
|
m_fileList(fileList),
|
|
m_rotateType(rotateType)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
ui->progressBar->setMinimum(0);
|
|
ui->progressBar->setMaximum(fileList.size());
|
|
ui->progressBar->setValue(0);
|
|
|
|
connect(this, SIGNAL(updateProgress(int)), this, SLOT(on_updateProgress(int)), Qt::QueuedConnection);
|
|
connect(this, SIGNAL(updateImageFile(QString)), this, SLOT(on_updateImageFile(QString)), Qt::QueuedConnection);
|
|
connect(this, SIGNAL(finish()), this, SLOT(on_finish()), Qt::QueuedConnection);
|
|
|
|
m_stopThread = false;
|
|
HGBase_OpenThread(ThreadFunc, this, &m_thread);
|
|
}
|
|
|
|
Dialog_MultiRotateImageFile::~Dialog_MultiRotateImageFile()
|
|
{
|
|
if (nullptr != m_thread)
|
|
{
|
|
HGBase_CloseThread(m_thread);
|
|
m_thread = nullptr;
|
|
}
|
|
|
|
delete ui;
|
|
}
|
|
|
|
void Dialog_MultiRotateImageFile::ThreadFunc(HGThread thread, HGPointer param)
|
|
{
|
|
(void)thread;
|
|
Dialog_MultiRotateImageFile *p = (Dialog_MultiRotateImageFile *)param;
|
|
|
|
for (int i = 0; i < (int)p->m_fileList.count(); ++i)
|
|
{
|
|
if (p->m_stopThread)
|
|
{
|
|
break;
|
|
}
|
|
|
|
emit p->updateProgress(i);
|
|
|
|
HGImage img = nullptr;
|
|
|
|
HGImgFmtReader imgFmtReader = nullptr;
|
|
HGImgFmt_OpenImageReader(getStdString(p->m_fileList[i]).c_str(), 0, &imgFmtReader);
|
|
if (nullptr != imgFmtReader)
|
|
{
|
|
HGUInt pageCount = 0;
|
|
HGImgFmt_GetImagePageCount(imgFmtReader, &pageCount);
|
|
if (1 == pageCount)
|
|
{
|
|
HGImgFmt_LoadImageFromReader(imgFmtReader, 0, nullptr, 0, HGBASE_IMGORIGIN_TOP, &img);
|
|
if (nullptr != img)
|
|
{
|
|
HGImageInfo imgInfo;
|
|
HGBase_GetImageInfo(img, &imgInfo);
|
|
|
|
if (0 == p->m_rotateType)
|
|
{
|
|
HGImage img2 = nullptr;
|
|
HGBase_CreateImage(imgInfo.height, imgInfo.width, imgInfo.type, imgInfo.origin, &img2);
|
|
HGBase_ImageRotateLeft(img, img2);
|
|
HGBase_DestroyImage(img);
|
|
img = img2;
|
|
}
|
|
else if (1 == p->m_rotateType)
|
|
{
|
|
HGBase_ImageRotate180(img, img);
|
|
}
|
|
else if (2 == p->m_rotateType)
|
|
{
|
|
HGImage img2 = nullptr;
|
|
HGBase_CreateImage(imgInfo.height, imgInfo.width, imgInfo.type, imgInfo.origin, &img2);
|
|
HGBase_ImageRotateRight(img, img2);
|
|
HGBase_DestroyImage(img);
|
|
img = img2;
|
|
}
|
|
}
|
|
}
|
|
|
|
HGImgFmt_CloseImageReader(imgFmtReader);
|
|
}
|
|
|
|
if (nullptr != img)
|
|
{
|
|
if (HGBASE_ERR_OK == HGImgFmt_SaveImage(img, 0, nullptr, getStdString(p->m_fileList[i]).c_str()))
|
|
{
|
|
emit p->updateImageFile(p->m_fileList[i]);
|
|
}
|
|
|
|
HGBase_DestroyImage(img);
|
|
}
|
|
}
|
|
|
|
emit p->finish();
|
|
}
|
|
|
|
void Dialog_MultiRotateImageFile::on_updateProgress(int value)
|
|
{
|
|
ui->progressBar->setValue(value);
|
|
}
|
|
|
|
void Dialog_MultiRotateImageFile::on_updateImageFile(QString fileName)
|
|
{
|
|
emit refreshImageFile(fileName);
|
|
}
|
|
|
|
void Dialog_MultiRotateImageFile::on_finish()
|
|
{
|
|
close();
|
|
}
|
|
|
|
void Dialog_MultiRotateImageFile::on_pushButton_clicked()
|
|
{
|
|
m_stopThread = true;
|
|
HGBase_CloseThread(m_thread);
|
|
m_thread = nullptr;
|
|
}
|
|
|
|
void Dialog_MultiRotateImageFile::closeEvent(QCloseEvent *e)
|
|
{
|
|
(void)e;
|
|
m_stopThread = true;
|
|
HGBase_CloseThread(m_thread);
|
|
m_thread = nullptr;
|
|
}
|