code_app/app/scanner/dialog_multirotateimagefile...

159 lines
4.7 KiB
C++
Raw Normal View History

2022-05-03 10:25:52 +00:00
#include "dialog_multirotateimagefile.h"
#include "ui_dialog_multirotateimagefile.h"
#include "imgfmt/HGImgFmt.h"
#include "HGUIGlobal.h"
2022-11-24 09:02:26 +00:00
#include "mainwindow.h"
#include <QMessageBox>
2022-05-03 10:25:52 +00:00
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);
2022-11-24 10:14:56 +00:00
connect(this, SIGNAL(finish(int)), this, SLOT(on_finish(int)), Qt::QueuedConnection);
2022-05-03 10:25:52 +00:00
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;
}
2022-10-12 03:51:41 +00:00
void HGAPI Dialog_MultiRotateImageFile::ThreadFunc(HGThread thread, HGPointer param)
2022-05-03 10:25:52 +00:00
{
(void)thread;
Dialog_MultiRotateImageFile *p = (Dialog_MultiRotateImageFile *)param;
2022-11-24 09:02:26 +00:00
HGResult ret = HGBASE_ERR_FAIL;
2022-05-03 10:25:52 +00:00
for (int i = 0; i < (int)p->m_fileList.count(); ++i)
{
if (p->m_stopThread)
{
break;
}
emit p->updateProgress(i);
HGImage img = nullptr;
2022-05-03 10:25:52 +00:00
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)
{
2022-05-27 01:23:06 +00:00
HGImgFmt_LoadImageFromReader(imgFmtReader, 0, nullptr, 0, HGBASE_IMGORIGIN_TOP, &img);
2022-05-03 10:25:52 +00:00
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);
HGUInt xDpi, yDpi;
HGBase_GetImageDpi(img, &xDpi, &yDpi);
HGBase_SetImageDpi(img2, xDpi, yDpi);
2022-05-03 10:25:52 +00:00
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);
HGUInt xDpi, yDpi;
HGBase_GetImageDpi(img, &xDpi, &yDpi);
HGBase_SetImageDpi(img2, xDpi, yDpi);
2022-05-03 10:25:52 +00:00
HGBase_ImageRotateRight(img, img2);
HGBase_DestroyImage(img);
img = img2;
}
}
}
HGImgFmt_CloseImageReader(imgFmtReader);
}
if (nullptr != img)
{
2022-11-24 09:02:26 +00:00
ret = HGImgFmt_SaveImage(img, 0, nullptr, getStdString(p->m_fileList[i]).c_str());
if (HGBASE_ERR_OK == ret)
{
emit p->updateImageFile(p->m_fileList[i]);
}
HGBase_DestroyImage(img);
}
2022-11-24 09:02:26 +00:00
if (ret != HGBASE_ERR_OK)
{
break;
}
2022-05-03 10:25:52 +00:00
}
2022-11-24 10:14:56 +00:00
emit p->finish((int)ret);
2022-05-03 10:25:52 +00:00
}
void Dialog_MultiRotateImageFile::on_updateProgress(int value)
{
ui->progressBar->setValue(value);
}
void Dialog_MultiRotateImageFile::on_updateImageFile(QString fileName)
{
emit refreshImageFile(fileName);
}
2022-11-24 10:14:56 +00:00
void Dialog_MultiRotateImageFile::on_finish(int ret)
2022-05-03 10:25:52 +00:00
{
2022-11-24 09:45:01 +00:00
QString str = (ret == HGBASE_ERR_OK) ? tr("operation success") : tr("multirotate operation failed: ") + MainWindow::getLogInfo(ret);
2022-11-24 09:02:26 +00:00
QMessageBox msg(QMessageBox::Information, tr("tip"), str, QMessageBox::Ok, this);
msg.setButtonText(QMessageBox::Ok, tr("ok"));
msg.exec();
2022-05-03 10:25:52 +00:00
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;
}