newtx/imgproc/algs/stretch.cpp

83 lines
2.6 KiB
C++

#include "stretch.h"
#include <huagao/hgscanner_error.h>
#include <sane/sane_ex.h>
#include <base/utils.h>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
static std::string device_opt_json[] = {
"{\"resolution\":{\"cat\":\"imgp\",\"group\":\"base\",\"title\":\"\\u5206\\u8fa8\\u7387\",\"desc\":\"\\u8bbe\\u7f6e\\u626b\\u63cf\\u56fe\\u50cf\\u7684\\u5206\\u8fa8\\u7387\",\"type\":\"int\",\"pos\":20,\"fix-id\":34840,\"ui-pos\":20,\"auth\":0,\"affect\":6,\"unit\":\"DPI\",\"size\":4,\"cur\":200,\"default\":200,\"range\":{\"min\":100,\"max\":{\"default\":600,\"paper==\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8\\u81ea\\u52a8\\u88c1\\u5207 || paper==\\u6700\\u5927\\u626b\\u63cf\\u5c3a\\u5bf8 || paper==\\u4e09\\u8054\\u8bd5\\u5377\":500},\"step\":1}}}"
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
stretch::stretch(bool weaker) : image_processor("stretch")
{
if(weaker)
return;
ADD_THIS_JSON();
}
stretch::~stretch()
{}
int stretch::set_value(const char* name/*nullptr for all options*/, void* val/*nullptr for restore*/)
{
int ret = SCANNER_ERR_OK;
if(strcmp(name, SANE_OPT_NAME(RESOLUTION)) == 0)
dpi_ = *(int*)val;
else
ret = SCANNER_ERR_DEVICE_NOT_SUPPORT;
return ret;
}
image_processor* stretch::copy_weaker(void)
{
stretch *weaker = new stretch(true);
weaker->pos_ = pos_;
weaker->enabled_ = enabled_;
weaker->dpi_ = dpi_;
return weaker;
}
int stretch::process(std::vector<PROCIMGINFO>& in, std::vector<PROCIMGINFO>& out)
{
for(auto& v: in)
{
if(v.info.resolution_x == dpi_ &&
v.info.resolution_y == dpi_)
{
out.push_back(v);
out[out.size() - 1].info.prc_stage = get_position();
out[out.size() - 1].info.prc_time = 0;
}
else
{
PROCIMGINFO o;
chronograph watch;
o.info = v.info;
o.info.prc_stage = get_position();
cv::resize(v.img, o.img, cv::Size(0, 0), dpi_ * 1.0f / v.info.resolution_x, dpi_ * 1.0f / v.info.resolution_y);
o.info.prc_time = watch.elapse_ms();
o.info.resolution_x = o.info.resolution_y = dpi_;
o.info.width = o.img.cols;
o.info.height = o.img.rows;
o.info.info_size = 0;
o.info.data_size = o.info.width * o.info.height * o.info.channels;
out.push_back(o);
}
}
return SCANNER_ERR_OK;
}