#include "color_correct.h" #include #include #include #include "ImageProcess_Public.h" //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // static std::string device_opt_json[] = { "{\"clr-correct\":{\"cat\":\"imgp\",\"group\":\"advance\",\"title\":\"\\u989c\\u8272\\u6821\\u6b63\",\"desc\":\"\\u6839\\u636e\\u6821\\u6b63\\u53c2\\u6570\\uff0c\\u8c03\\u6574\\u4eceCIS\\u51fa\\u6765\\u7684\\u539f\\u59cb\\u56fe\\u50cf\\u989c\\u8272\",\"type\":\"bool\",\"pos\":24,\"ui-pos\":15,\"auth\":100,\"size\":4,\"cur\":true,\"default\":true},\"lut-file\":{\"cat\":\"imgp\",\"group\":\"advance\",\"title\":\"\\u6821\\u6b63\\u6a21\\u677f\",\"desc\":\"\\u989c\\u8272\\u6821\\u6b63\\u4f7f\\u7528\\u7684\\u57fa\\u51c6\\u56fe\\u50cf\\u6570\\u636e\",\"type\":\"string\",\"pos\":25,\"ui-pos\":16,\"auth\":100,\"bind\":true,\"size\":80,\"default\":{\"cis-mode==\\u5f69\\u8272&&resolution>200&&resolution<400\":\"\\/usr\\/local\\/huago\\/Textlut300clr.bmp\",\"cis-mode==\\u5f69\\u8272&&resolution>=400\":\"\\/usr\\/local\\/huago\\/Textlut600clr.bmp\",\"cis-mode==\\u7070\\u5ea6&&resolution<=200\":\"\\/usr\\/local\\/huago\\/Textlut200gray.bmp\",\"cis-mode==\\u7070\\u5ea6&&resolution>200&&resolution<400\":\"\\/usr\\/local\\/huago\\/Textlut300gray.bmp\",\"cis-mode==\\u7070\\u5ea6&&resolution>=400\":\"\\/usr\\/local\\/huago\\/Textlut600gray.bmp\",\"default\":\"\\/usr\\/local\\/huago\\/Textlut200clr.bmp\"}},\"cis-mode\":{\"cat\":\"none\",\"group\":\"CIS\",\"title\":\"CIS\\u989c\\u8272\\u6a21\\u5f0f\",\"desc\":\"\\u9009\\u62e9\\u955c\\u5934\\u8272\\u5f69\\u5de5\\u4f5c\\u6a21\\u5f0f\",\"type\":\"string\",\"pos\":1000,\"ui-pos\":10,\"auth\":0,\"bind\":true,\"size\":12,\"default\":{\"(mode.enabled&&(mode==256\\u7ea7\\u7070\\u5ea6||mode==\\u9ed1\\u767d)) || (multiout-type.enabled&&multiout-type==\\u7070\\u5ea6+\\u9ed1\\u767d)\":\"\\u7070\\u5ea6\",\"default\":\"\\u5f69\\u8272\"},\"range\":[\"\\u5f69\\u8272\",\"\\u7070\\u5ea6\"]}}" }; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // color_correct::color_correct(bool weaker) : image_processor("color_correct") { if(weaker) return; ADD_THIS_JSON(); lut_ = hg::loadLUT(lut_path_); } color_correct::~color_correct() {} int color_correct::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(COLOR_CORRECT)) == 0) enabled_ = correct_ = *(bool*)val; else if(strcmp(name, SANE_OPT_NAME(LUT_FILE)) == 0) { if(lut_path_ != (char*)val) { lut_path_ = (char*)val; lut_ = hg::loadLUT(lut_path_); } } else if(strcmp(name, SANE_OPT_NAME(CIS_MODE)) == 0) { bool pre = clr_; clr_ = strcmp((char*)val, WORDS_COLOR_COLOR) == 0; } else ret = SCANNER_ERR_DEVICE_NOT_SUPPORT; return ret; } image_processor* color_correct::copy_weaker(void) { color_correct *weaker = new color_correct(true); weaker->pos_ = pos_; weaker->enabled_ = enabled_; weaker->correct_ = correct_; weaker->clr_ = clr_; weaker->lut_ = lut_.clone(); return weaker; } int color_correct::process(std::vector& in, std::vector& out) { int ret = SCANNER_ERR_OK; if(correct_) { for(auto& v: in) { PROCIMGINFO o = v; chronograph watch; // hg::correctColor(o.img, o.info.resolution_x, 1, true); cv::Mat image_temp(o.img.rows, o.img.cols * o.img.channels() / lut_.channels(), CV_8UC(lut_.channels()), o.img.data); for (size_t i = 0; i < image_temp.cols; i++) cv::LUT(image_temp(cv::Rect(i, 0, 1, image_temp.rows)), lut_(cv::Rect(0, i, 256, 1)), image_temp(cv::Rect(i, 0, 1, image_temp.rows))); o.info.prc_time = watch.elapse_ms(); o.info.prc_stage = get_position(); o.info.width = o.img.cols; o.info.height = o.img.rows; out.push_back(o); } } else { out = in; for(auto& v: out) { v.info.prc_stage = get_position(); v.info.prc_time = 0; } } return ret; }