code_production/app/HGProductionTool/hgscanner.cpp

106 lines
2.7 KiB
C++

#include "hgscanner.h"
#include <QMessageBox>
#include "form_maininterface.h"
#include "dialog_userinput.h"
#include <QDebug>
hgscanner::hgscanner(Form_mainInterface *form, SANE_Handle h)
: m_interface(form)
, devHandle_(h)
{
cb_ = nullptr;
}
hgscanner::~hgscanner()
{
}
parameter* hgscanner::get_user_input(data_from from, value_type type, const wchar_t* title, const wchar_t* desc)
{
if (from == DATA_FROM_USER)
{
Dialog_UserInput dlg(type, QString::fromStdWString(title), desc, m_interface);
if (dlg.exec())
{
return dlg.getParam();
}
}
return nullptr;
}
void hgscanner::test_callback(const wchar_t* name, test_event ev, void* data, size_t flag)
{
if (ev == TEST_EVENT_TIPS)
{
}
else if (ev == TEST_EVENT_RESULT)
{
QString ret;
QString info = QString::fromStdWString((const wchar_t*)data);
if (flag)
ret = QObject::tr("success: ") + info;
else
ret = QObject::tr("failed: ") + info;
emit m_interface->testResult(ret);
}
else if (ev == TEST_EVENT_NOT_FIND_TEST)
{
QString info = QObject::tr("Not find test item");
emit m_interface->testResult(info);
}
else if (ev == TEST_EVENT_DISTORTION)
{
QString title = QString::fromStdWString(name);
emit m_interface->testDistortion(title, data);
}
else if (ev == TEST_EVENT_HAVE_IMAGE)
{
SANE_Image *sane_img = (SANE_Image *)data;
HGUInt imgType = 0;
if (sane_img->header.format == SANE_FRAME_GRAY)
{
if (1 == sane_img->header.depth)
imgType = HGBASE_IMGTYPE_BINARY;
else if (8 == sane_img->header.depth)
imgType = HGBASE_IMGTYPE_GRAY;
}
else if (sane_img->header.format == SANE_FRAME_RGB)
{
imgType = HGBASE_IMGTYPE_RGB;
}
HGByte *imgData = sane_img->data;
HGImageInfo imgInfo = {(HGUInt)sane_img->header.pixels_per_line, (HGUInt)sane_img->header.lines,
imgType, (HGUInt)sane_img->header.bytes_per_line, HGBASE_IMGORIGIN_TOP};
HGImage img = nullptr;
HGBase_CreateImageFromData(imgData, &imgInfo, nullptr, imgType, HGBASE_IMGORIGIN_TOP, &img);
if (nullptr != img)
{
emit m_interface->testResultImg(img);
}
}
}
int hgscanner::register_sane_callback(sane_callback cb, void* param)
{
cb_ = cb;
return 0;
}
int hgscanner::unregister_sane_callback(sane_callback cb)
{
return 0;
}
int hgscanner::io_control(unsigned long code, void* data, unsigned* len)
{
sane_io_control(devHandle_, code, data, len);
return 0;
}