信息画质切换

This commit is contained in:
mo1027728827@qq.com 2022-05-09 19:27:10 +08:00
parent 14bd4dc0df
commit 384dc794b5
4 changed files with 60 additions and 27 deletions

View File

@ -1531,17 +1531,15 @@ int hg_scanner::setting_custom_area_bottom(void* data)
int hg_scanner::setting_img_quality(void *data)
{
std::string str((char*)data);
bool exact = check_range(setting_map_[HG_BASE_SETTING_INDEX_IMG_QUALITY], str);
int ret = exact ? HG_ERR_OK : HG_ERR_NOT_EXACT;
HG_VLOG_MINI_3(HG_LOG_LEVEL_DEBUG_INFO, "Change text direction from '%s' to '%s' = %s\n", is_img_quality(is_quality_).c_str()
HG_VLOG_MINI_3(HG_LOG_LEVEL_DEBUG_INFO, "Change quality from '%s' to '%s' = %s\n", is_img_quality(is_quality_).c_str()
, (char*)data, hg_scanner::strerr((hg_err)ret).c_str());
is_quality_ = match_best_img_quality(str,NULL);
on_resolution_changed(resolution_);
return HG_ERR_OK;
}

View File

@ -663,6 +663,11 @@ void hg_scanner_239::image_process(std::shared_ptr<std::vector<char>>& buff)
{
//err = hg_imgproc::multi_out(handle,image_prc_param_.bits.multi_out - 1); 非法指令 暂时屏蔽
}
if (is_quality_ == IMG_SPEED && resolution_ >= 300)
{
err = hg_imgproc::quality(handle,resolution_);
}
if (image_prc_param_.bits.split && !user_cancel_)
{
@ -688,6 +693,7 @@ void hg_scanner_239::image_process(std::shared_ptr<std::vector<char>>& buff)
}
hg_imgproc::final(handle);
while (hg_imgproc::get_final_data(handle, &ih, &buf, index++) == HG_ERR_OK && !user_cancel_)
{
HG_VLOG_MINI_5(HG_LOG_LEVEL_DEBUG_INFO, "Final picture %d (%d * %d * %d) with %u bytes!\n", index
@ -783,7 +789,22 @@ int hg_scanner_239::writedown_image_configuration(void)
ic.automaticcolor = is_auto_matic_color;
ic.automaticcolortype = 1;// ic.pixtype; //存疑
ic.resolution_dst = resolution_;
if (resolution_ >= 300)
{
if(is_quality_ == IMG_SPEED)
{
ic.resolution_dst = 200;
}
else if(is_quality_ ==IMG_QUALITY)
{
ic.resolution_dst = resolution_;
}
}
else
{
ic.resolution_dst = resolution_;
}
ic.resolution_native = 200.0f;
ic.gamma = (float)gamma_;
ic.contrast = (contrast_ - 4) * 333.0;
@ -1085,7 +1106,7 @@ void hg_scanner_239::init_setting_map(int* setting_map, int count)
setting_map[HG_BASE_SETTING_INDEX_PAGE] = HG_239_SETTING_PAGE;
setting_map[HG_BASE_SETTING_INDEX_PAGE_OMIT_EMPTY_LEVEL] = HG_239_SETTING_SKIP_NILL;
setting_map[HG_BASE_SETTING_INDEX_RESOLUTION] = HG_239_SETTING_RESOLUTION;
setting_map[HG_BASE_SETTING_INDEX_IMG_QUALITY] =
setting_map[HG_BASE_SETTING_INDEX_IMG_QUALITY] = HG_239_SETTING_IMG_QUALITY;
setting_map[HG_BASE_SETTING_INDEX_EXCHANGE] = HG_239_SETTING_REVERSE;
setting_map[HG_BASE_SETTING_INDEX_SPLIT] = HG_239_SETTING_SPLIT;
setting_map[HG_BASE_SETTING_INDEX_AUTO_CORRECT] = HG_239_SETTING_CORRECT;
@ -1220,38 +1241,26 @@ int hg_scanner_239::on_resolution_changed(int& dpi)
bool exact = true;
int ind = settings::match_best_resolution(dpi, &exact),
ret = exact ? HG_ERR_OK : HG_ERR_NOT_EXACT;
int old = 0;
if (dev_conf_.g200params.dpi != settings::resolution_map[ind].dev_value)
{
old = dev_conf_.g200params.dpi;
int old = dev_conf_.g200params.dpi;
dev_conf_.g200params.dpi = settings::resolution_map[ind].dev_value;
}
if (resolution_ >= 300 )
{
if (is_quality_ == IMG_SPEED)
{
dev_conf_.g200params.dpi = 1;
}
else
{
dev_conf_.g200params.dpi = 0;
}
}
printf("dev_conf_.g200params.dpi = %d\r\n",dev_conf_.g200params.dpi);
dev_conf_.g200params.dpi = 1;
ret = writedown_device_configuration();
if (ret)
{
dev_conf_.g200params.dpi = old;
}
else if (!exact)
ret = HG_ERR_NOT_EXACT;
}
if (ret == HG_ERR_NOT_EXACT)
dpi = settings::resolution_map[ind].resolution;
return ret;
}
@ -1387,7 +1396,7 @@ void hg_scanner_239::thread_handle_usb_read(void)
{
status_ = ret;
notify_ui_working_status("通信超时", SANE_EVENT_ERROR, ret);
stop();
//stop();
break;
}
std::this_thread::sleep_for(std::chrono::milliseconds(500));

View File

@ -666,7 +666,29 @@ namespace hg_imgproc
return ret;
}
//画质
int quality(int dpi_dst)
{
int ret = HG_ERR_OK;
std::vector<cv::Mat> mats(mats_);
mats_.clear();
//mats_.resize(mats.size());
float xy = (float)dpi_dst/200.0;
printf("dpi_dst = %d xy= %f\r\n",dpi_dst,xy);
for (size_t i = 0; i < mats.size(); ++i)
{
cv::Mat out;
cv::resize(mats[i],out, cv::Size(),xy,xy);
mats_.push_back(out);
printf("mats_[i] = %d mats_[2] =%d\r\n",mats_[i].cols,mats_[i].rows);
}
return HG_ERR_OK;
}
// final
public:
int final(void)
{
@ -701,8 +723,7 @@ namespace hg_imgproc
pimh->total_bytes = mats_[index].total() * pimh->channels;
pimh->line_bytes = pimh->height ? pimh->total_bytes / pimh->height : pimh->width * pimh->channels;
*buf = mats_[index].data;
//cv::imwrite(to_string(index)+"_final.jpg",mats_[index]);
//printf("pimh->channels = %d \r\n",pimh->channels);
return HG_ERR_OK;
}
@ -879,6 +900,10 @@ namespace hg_imgproc
{
return ((imgproc*)himg)->fold();
}
int quality(HIMGPRC himg,int dpi)
{
return ((imgproc*)himg)->quality(dpi);
}
int final(HIMGPRC himg)
{
return ((imgproc*)himg)->final();

View File

@ -191,6 +191,7 @@ namespace hg_imgproc
int imgtypechange(HIMGPRC himg,std::string img_type_,void *buf,std::vector<unsigned char> &bmpdata);
int fold(HIMGPRC himg);
int quality(HIMGPRC himg,int dpi);
int final(HIMGPRC himg);
// pimh must not to be NULL, and pimh->total_bytes indicates the length of 'buf'