From c835f6dd4a77df6483af24f21fef06974094d628 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Fri, 15 Jul 2022 16:04:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=8E=9F=E5=9B=BE=E5=83=8F?= =?UTF-8?q?=E5=A4=84=E7=90=86customgamma=E5=8F=82=E6=95=B0=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hgdriver/hgdev/hg_scanner.cpp | 52 +++++++++++++++++++++- hgdriver/hgdev/hg_scanner.h | 4 ++ hgdriver/hgdev/hg_scanner_200.cpp | 57 ++---------------------- hgdriver/hgdev/hg_scanner_239.cpp | 74 +++++++++++++------------------ hgdriver/hgdev/hg_scanner_300.cpp | 64 +++----------------------- hgdriver/hgdev/hg_scanner_400.cpp | 57 ++---------------------- hgdriver/hgdev/hg_scanner_402.cpp | 55 ++--------------------- hgdriver/hgdev/image_process.cpp | 15 ++++--- hgdriver/hgdev/image_process.h | 2 +- 9 files changed, 113 insertions(+), 267 deletions(-) diff --git a/hgdriver/hgdev/hg_scanner.cpp b/hgdriver/hgdev/hg_scanner.cpp index 2b55096..c0fe12f 100644 --- a/hgdriver/hgdev/hg_scanner.cpp +++ b/hgdriver/hgdev/hg_scanner.cpp @@ -92,7 +92,7 @@ hg_scanner::hg_scanner(ScannerSerial serial , fractate_level_(50), ui_ev_cb_(ui_default_callback), scan_life_(NULL) , notify_setting_result_(false), user_cancel_(false), cb_mem_(true), test_1_paper_(false) , setting_count_(0),img_type_(""), online_(false),is_quality_(-1),is_color_fill(false),is_multiout(false),save_multiout(OPTION_VALUE_DLSC_CS_HD_HB) - , final_img_index_(0), custom_area_(false),save_sizecheck(false), bw_threshold_(128) + , final_img_index_(0), custom_area_(false),save_sizecheck(false), bw_threshold_(128), custom_gamma_(false) { final_path_ = hg_log::ini_get("paths", "final_img"); if(final_path_.empty()) @@ -1664,6 +1664,56 @@ void hg_scanner::thread_handle_usb_read(void) { } +void hg_scanner::adjust_color(hg_imgproc::HIMGPRC handle) +{ + int tableLength = 0; // ZERO length perform color-adjust only + unsigned char buffer1[256 * 3]; + + if (custom_gamma_) + { + if (img_conf_.pixtype == COLOR_MODE_BLACK_WHITE || img_conf_.pixtype == COLOR_MODE_256_GRAY) + { + tableLength = 256; + memcpy(buffer1, custom_gamma_val_->table, tableLength); + } + else + { + // convert R[256] + G[256] + B[256] to BGR[256] ... + tableLength = 256 * 3; + for (int i = 0; i < 256; ++i) + { + buffer1[i * 3 + 0] = custom_gamma_val_->table[256 * 2 + i]; + buffer1[i * 3 + 1] = custom_gamma_val_->table[256 * 1 + i]; + buffer1[i * 3 + 2] = custom_gamma_val_->table[256 * 0 + i]; + } + } + } + hg_imgproc::adjust_color(handle, buffer1, tableLength); +} +hg_imgproc::HIMGPRC hg_scanner::get_image_process_object(int model) +{ + hg_imgproc::IMGPRCPARAM param; + hg_imgproc::HIMGPRC handle = nullptr; + float bright = img_conf_.brightness, + contrast = img_conf_.contrast; + + bzero(¶m, sizeof(param)); + param.bits = 8; + param.black_white = img_conf_.pixtype == COLOR_MODE_BLACK_WHITE; + param.channels = img_conf_.pixtype == COLOR_MODE_24_BITS ? 3 : 1; + param.color_mode = img_conf_.pixtype; + param.double_side = img_conf_.is_duplex; + param.dpi = img_conf_.resolution_dst; + + img_conf_.brightness = (float)bright_; + img_conf_.contrast = (float)contrast_; + handle = hg_imgproc::init(&img_conf_, ¶m, model); + img_conf_.brightness = bright; + img_conf_.contrast = contrast; + + return handle; +} + void hg_scanner::init_settings(const char* json_setting_text) { setting_jsn_ = jsonconfig::load_json_from_text(json_setting_text); diff --git a/hgdriver/hgdev/hg_scanner.h b/hgdriver/hgdev/hg_scanner.h index 026d958..9ea4569 100644 --- a/hgdriver/hgdev/hg_scanner.h +++ b/hgdriver/hgdev/hg_scanner.h @@ -164,6 +164,10 @@ protected: virtual void thread_handle_usb_read(void) = 0; virtual void image_process(std::shared_ptr& buff) = 0; + // adjust color or apply custom gamma + void adjust_color(hg_imgproc::HIMGPRC handle); + hg_imgproc::HIMGPRC get_image_process_object(int model); + protected: volatile bool run_; volatile bool user_cancel_; diff --git a/hgdriver/hgdev/hg_scanner_200.cpp b/hgdriver/hgdev/hg_scanner_200.cpp index d0e15c3..c204add 100644 --- a/hgdriver/hgdev/hg_scanner_200.cpp +++ b/hgdriver/hgdev/hg_scanner_200.cpp @@ -538,28 +538,12 @@ int hg_scanner_200::get_img_data(unsigned int bytes) void hg_scanner_200::image_process(std::shared_ptr& buffer) { int ret = SCANNER_ERR_OK; - hg_imgproc::IMGPRCPARAM param; - hg_imgproc::HIMGPRC handle = NULL; + hg_imgproc::HIMGPRC handle = get_image_process_object(pid_); hg_imgproc::IMGHEAD ih; int err = SCANNER_ERR_OK, index = 0; void* buf = NULL; - param.bits = 8; - param.black_white = img_conf_.pixtype == COLOR_MODE_BLACK_WHITE; - param.channels = img_conf_.pixtype == COLOR_MODE_24_BITS ? 3 : 1; - param.color_mode = img_conf_.pixtype; - param.double_side = img_conf_.is_duplex; - param.dpi = img_conf_.resolution_dst; - - //VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"param.black_white :%d\r\n",param.black_white); - //VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"param.channels :%d\r\n",param.channels); - //VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"param.color_mode :%d\r\n",param.color_mode); - //VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"param.double_side :%d\r\n",param.double_side); - //VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"param.dpi :%d\r\n",param.dpi); - - - handle = hg_imgproc::init(&img_conf_,¶m,pid_); hg_imgproc::load_buffer(handle, buffer); hg_imgproc::decode(handle,pid_); @@ -579,7 +563,7 @@ void hg_scanner_200::image_process(std::shared_ptr& buffer) } if(img_conf_.fadeback) { - hg_imgproc::fadeback(handle,img_conf_.fadebackrange,param.double_side); + hg_imgproc::fadeback(handle,img_conf_.fadebackrange, img_conf_.is_duplex); //HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"背景除色开启\r\n"); } if (img_conf_.resolution_dst != img_conf_.resolution_native) @@ -599,42 +583,7 @@ void hg_scanner_200::image_process(std::shared_ptr& buffer) //HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"除色开启\r\n"); } /////////////////////////////////////2222222222222222222222222222222222222////////////////////////////////// - int tableLength ;//= sizeof(custom_gamma_val_->table)/sizeof(custom_gamma_val_->table[0]); - - unsigned char buffer1[256 *3]; - if (img_conf_.pixtype == COLOR_MODE_BLACK_WHITE || img_conf_.pixtype == COLOR_MODE_256_GRAY) - tableLength = 256; - else - { - - tableLength = 768; - int index=0; - const int buffersize = 256; - - unsigned char buf_01[buffersize]; - memcpy(buf_01,custom_gamma_val_->table + index,buffersize); - index += buffersize; - - unsigned char buf_02[buffersize]; - memcpy(buf_02,custom_gamma_val_->table + index,buffersize); - index += buffersize; - - unsigned char buf_03[buffersize]; - memcpy(buf_03,custom_gamma_val_->table + index,buffersize); - index += buffersize; - - int j =0; - for (size_t i = 0; i < buffersize; i++) - { - memcpy(buffer1 + j,buf_01 + i,1); - memcpy(buffer1 + (++j),buf_02 + i,1); - memcpy(buffer1 + (++j),buf_03 + i,1); - ++j; - } - } - - - hg_imgproc::customgamma(handle,custom_gamma_,buffer1,tableLength); + adjust_color(handle); if (img_conf_.pixtype == COLOR_MODE_24_BITS && img_conf_.hsvcorrect) { diff --git a/hgdriver/hgdev/hg_scanner_239.cpp b/hgdriver/hgdev/hg_scanner_239.cpp index bd8129c..7a0a016 100644 --- a/hgdriver/hgdev/hg_scanner_239.cpp +++ b/hgdriver/hgdev/hg_scanner_239.cpp @@ -646,24 +646,12 @@ void hg_scanner_239::image_process(std::shared_ptr& buff) { VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Process image with %u bytes content ...\n", buff->size()); - hg_imgproc::IMGPRCPARAM param; - hg_imgproc::HIMGPRC handle = NULL; + hg_imgproc::HIMGPRC handle = get_image_process_object(pid_); hg_imgproc::IMGHEAD ih; int err = SCANNER_ERR_OK, index = 0; void* buf = NULL; - bzero(¶m, sizeof(param)); - - param.bits = 8; - param.black_white = img_conf_.pixtype == COLOR_MODE_BLACK_WHITE; - param.channels = img_conf_.pixtype == COLOR_MODE_24_BITS ? 3 : 1; - param.color_mode = img_conf_.pixtype; - param.double_side = img_conf_.is_duplex; - param.dpi = img_conf_.resolution_dst; - - - handle = hg_imgproc::init(&img_conf_,¶m,pid_); err = hg_imgproc::load_buffer(handle, buff); err = hg_imgproc::decode(handle,pid_); @@ -791,47 +779,47 @@ int hg_scanner_239::writedown_image_configuration(void) ic.papertype = paper_size_; -if (is_lateral(image_prc_param_.bits.paper)) - ic.paperAlign = Rot270; -// else if (image_prc_param_.bits.text_direction == TEXT_DIRECTION_AUTO) -// ic.paperAlign = AutoTextOrientation; -else - ic.paperAlign = Rot0; + if (is_lateral(image_prc_param_.bits.paper)) + ic.paperAlign = Rot270; + // else if (image_prc_param_.bits.text_direction == TEXT_DIRECTION_AUTO) + // ic.paperAlign = AutoTextOrientation; + else + ic.paperAlign = Rot0; - ic.en_sizecheck = dev_conf_.g200params.enable_sizecheck; + ic.en_sizecheck = dev_conf_.g200params.enable_sizecheck; -if (image_prc_param_.bits.text_direction != TEXT_DIRECTION_AUTO) - ic.imageRotateDegree = (float)image_prc_param_.bits.text_direction; -else - ic.imageRotateDegree = 0; + if (image_prc_param_.bits.text_direction != TEXT_DIRECTION_AUTO) + ic.imageRotateDegree = (float)image_prc_param_.bits.text_direction; + else + ic.imageRotateDegree = 0; - ic.imageRotateDegree *= 90.0f; + ic.imageRotateDegree *= 90.0f; - ic.is_duplex = (image_prc_param_.bits.page == PAGE_DOUBLE - || image_prc_param_.bits.page == PAGE_OMIT_EMPTY - || image_prc_param_.bits.page == PAGE_OMIT_EMPTY_RECEIPT - || image_prc_param_.bits.page ==PAGE_FOLIO); + ic.is_duplex = (image_prc_param_.bits.page == PAGE_DOUBLE + || image_prc_param_.bits.page == PAGE_OMIT_EMPTY + || image_prc_param_.bits.page == PAGE_OMIT_EMPTY_RECEIPT + || image_prc_param_.bits.page ==PAGE_FOLIO); - ic.en_fold = (image_prc_param_.bits.page == PAGE_FOLIO); - ic.pixtype = image_prc_param_.bits.color_mode == COLOR_MODE_AUTO_MATCH ? 2 : image_prc_param_.bits.color_mode; - ic.automaticcolor = is_auto_matic_color; + ic.en_fold = (image_prc_param_.bits.page == PAGE_FOLIO); + ic.pixtype = image_prc_param_.bits.color_mode == COLOR_MODE_AUTO_MATCH ? 2 : image_prc_param_.bits.color_mode; + ic.automaticcolor = is_auto_matic_color; - ic.automaticcolortype = 1;// ic.pixtype; //存疑 -if (resolution_ >= 300) -{ - if(is_quality_ == IMG_SPEED) + ic.automaticcolortype = 1;// ic.pixtype; //存疑 + if (resolution_ >= 300) { - ic.resolution_dst = 200; + if(is_quality_ == IMG_SPEED) + { + ic.resolution_dst = 200; + } + else if(is_quality_ ==IMG_QUALITY) + { + ic.resolution_dst = resolution_; + } } - else if(is_quality_ ==IMG_QUALITY) + else { ic.resolution_dst = resolution_; } -} -else -{ - ic.resolution_dst = resolution_; -} ic.resolution_native = 200.0f; ic.gamma = (float)gamma_; diff --git a/hgdriver/hgdev/hg_scanner_300.cpp b/hgdriver/hgdev/hg_scanner_300.cpp index 9e40c4f..930cb94 100644 --- a/hgdriver/hgdev/hg_scanner_300.cpp +++ b/hgdriver/hgdev/hg_scanner_300.cpp @@ -487,28 +487,12 @@ int hg_scanner_300::get_img_data(std::shared_ptr &imagedata) void hg_scanner_300::image_process(std::shared_ptr& buffer) { int ret = SCANNER_ERR_OK; - hg_imgproc::IMGPRCPARAM param; - hg_imgproc::HIMGPRC handle = NULL; + hg_imgproc::HIMGPRC handle = get_image_process_object(pid_); hg_imgproc::IMGHEAD ih; int err = SCANNER_ERR_OK, index = 0; void* buf = NULL; - param.bits = 8; - param.black_white = img_conf_.pixtype == COLOR_MODE_BLACK_WHITE; - param.channels = img_conf_.pixtype == COLOR_MODE_24_BITS ? 3 : 1; - param.color_mode = img_conf_.pixtype; - param.double_side = img_conf_.is_duplex; - param.dpi = img_conf_.resolution_dst; - - VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"param.black_white :%d\r\n",param.black_white); - VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"param.channels :%d\r\n",param.channels); - VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"param.color_mode :%d\r\n",param.color_mode); - VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"param.double_side :%d\r\n",param.double_side); - - - - handle = hg_imgproc::init(&img_conf_,¶m,pid_); hg_imgproc::load_buffer(handle, buffer); hg_imgproc::decode(handle,pid_); @@ -546,7 +530,7 @@ void hg_scanner_300::image_process(std::shared_ptr& buffer) } if(img_conf_.fadeback) { - hg_imgproc::fadeback(handle,img_conf_.fadebackrange,param.double_side); + hg_imgproc::fadeback(handle,img_conf_.fadebackrange, img_conf_.is_duplex); //HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"背景除色开启\r\n"); } if (img_conf_.resolution_dst != img_conf_.resolution_native) @@ -565,41 +549,7 @@ void hg_scanner_300::image_process(std::shared_ptr& buffer) //HG_LOGHG_LOG_LEVEL_DEBUG_INFO,"除色开启\r\n"); } /////////////////////////////////////2222222222222222222222222222222222222////////////////////////////////// - int tableLength ;//= sizeof(custom_gamma_val_->table)/sizeof(custom_gamma_val_->table[0]); - - unsigned char buffer_re[256 *3]; - if (img_conf_.pixtype == COLOR_MODE_BLACK_WHITE || img_conf_.pixtype == COLOR_MODE_256_GRAY) - tableLength = 256; - else - { - - tableLength = 768; - int index=0; - const int buffersize = 256; - - unsigned char buf_01[buffersize]; - memcpy(buf_01,custom_gamma_val_->table + index,buffersize); - index += buffersize; - - unsigned char buf_02[buffersize]; - memcpy(buf_02,custom_gamma_val_->table + index,buffersize); - index += buffersize; - - unsigned char buf_03[buffersize]; - memcpy(buf_03,custom_gamma_val_->table + index,buffersize); - index += buffersize; - - int j = 0; - for (size_t i = 0;i < buffersize;i++) - { - memcpy(buffer_re + j,buf_01 + i,1); - memcpy(buffer_re + (++j),buf_02 + i,1); - memcpy(buffer_re + (++j),buf_03 + i,1); - ++j; - } - } - - hg_imgproc::customgamma(handle,custom_gamma_,buffer_re,tableLength); + adjust_color(handle); if (img_conf_.pixtype == COLOR_MODE_24_BITS && img_conf_.hsvcorrect) { @@ -910,10 +860,10 @@ void hg_scanner_300::writedown_image_configuration(void) ic.en_sizecheck = dsp_config.params.sizedetece; -if (image_prc_param_.bits.text_direction != TEXT_DIRECTION_AUTO) - ic.imageRotateDegree = image_prc_param_.bits.text_direction; -else - ic.imageRotateDegree = 0; + if (image_prc_param_.bits.text_direction != TEXT_DIRECTION_AUTO) + ic.imageRotateDegree = image_prc_param_.bits.text_direction; + else + ic.imageRotateDegree = 0; ic.is_duplex = (image_prc_param_.bits.page == PAGE_DOUBLE || image_prc_param_.bits.page == PAGE_OMIT_EMPTY || image_prc_param_.bits.page == PAGE_OMIT_EMPTY_RECEIPT || image_prc_param_.bits.page ==PAGE_FOLIO); diff --git a/hgdriver/hgdev/hg_scanner_400.cpp b/hgdriver/hgdev/hg_scanner_400.cpp index c5f9cda..a7c1239 100644 --- a/hgdriver/hgdev/hg_scanner_400.cpp +++ b/hgdriver/hgdev/hg_scanner_400.cpp @@ -487,28 +487,12 @@ int hg_scanner_400::get_img_data(std::shared_ptr &imagedata) void hg_scanner_400::image_process(std::shared_ptr& buffer) { int ret = SCANNER_ERR_OK; - hg_imgproc::IMGPRCPARAM param; - hg_imgproc::HIMGPRC handle = NULL; + hg_imgproc::HIMGPRC handle = get_image_process_object(pid_); hg_imgproc::IMGHEAD ih; int err = SCANNER_ERR_OK, index = 0; void* buf = NULL; - param.bits = 8; - param.black_white = img_conf_.pixtype == COLOR_MODE_BLACK_WHITE; - param.channels = img_conf_.pixtype == COLOR_MODE_24_BITS ? 3 : 1; - param.color_mode = img_conf_.pixtype; - param.double_side = img_conf_.is_duplex; - param.dpi = img_conf_.resolution_dst; - - VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"param.black_white :%d\r\n",param.black_white); - VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"param.channels :%d\r\n",param.channels); - VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"param.color_mode :%d\r\n",param.color_mode); - VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"param.double_side :%d\r\n",param.double_side); - VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO,"param.dpi :%d\r\n",param.dpi); - - - handle = hg_imgproc::init(&img_conf_,¶m,pid_); hg_imgproc::load_buffer(handle, buffer); hg_imgproc::decode(handle,pid_); @@ -530,7 +514,7 @@ void hg_scanner_400::image_process(std::shared_ptr& buffer) } if(img_conf_.fadeback) { - hg_imgproc::fadeback(handle,img_conf_.fadebackrange,param.double_side); + hg_imgproc::fadeback(handle,img_conf_.fadebackrange, img_conf_.is_duplex); //printf("背景除色开启\r\n"); //VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "背景除色开启:%s\n",hg_scanner_err_name(ret)); } @@ -554,42 +538,7 @@ void hg_scanner_400::image_process(std::shared_ptr& buffer) //VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "除色开启:%s\n",hg_scanner_err_name(ret)); } /////////////////////////////////////2222222222222222222222222222222222222////////////////////////////////// - int tableLength ;//= sizeof(custom_gamma_val_->table)/sizeof(custom_gamma_val_->table[0]); - - unsigned char buffer1[256 *3]; - if (img_conf_.pixtype == COLOR_MODE_BLACK_WHITE || img_conf_.pixtype == COLOR_MODE_256_GRAY) - tableLength = 256; - else - { - - tableLength = 768; - int index=0; - const int buffersize = 256; - - unsigned char buf_01[buffersize]; - memcpy(buf_01,custom_gamma_val_->table + index,buffersize); - index += buffersize; - - unsigned char buf_02[buffersize]; - memcpy(buf_02,custom_gamma_val_->table + index,buffersize); - index += buffersize; - - unsigned char buf_03[buffersize]; - memcpy(buf_03,custom_gamma_val_->table + index,buffersize); - index += buffersize; - - int j =0; - for (size_t i = 0; i < buffersize; i++) - { - memcpy(buffer1 + j,buf_01 + i,1); - memcpy(buffer1 + (++j),buf_02 + i,1); - memcpy(buffer1 + (++j),buf_03 + i,1); - ++j; - } - } - - - hg_imgproc::customgamma(handle,custom_gamma_,buffer1,tableLength); + adjust_color(handle); if (img_conf_.pixtype == COLOR_MODE_24_BITS && img_conf_.hsvcorrect) { diff --git a/hgdriver/hgdev/hg_scanner_402.cpp b/hgdriver/hgdev/hg_scanner_402.cpp index b73af85..f34d834 100644 --- a/hgdriver/hgdev/hg_scanner_402.cpp +++ b/hgdriver/hgdev/hg_scanner_402.cpp @@ -652,24 +652,12 @@ void hg_scanner_402::image_process(std::shared_ptr& buff) { VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Process image with %u bytes content ...\n", buff->size()); - hg_imgproc::IMGPRCPARAM param; - hg_imgproc::HIMGPRC handle = NULL; + hg_imgproc::HIMGPRC handle = get_image_process_object(pid_); hg_imgproc::IMGHEAD ih; int err = SCANNER_ERR_OK, index = 0; void* buf = NULL; - bzero(¶m, sizeof(param)); - - param.bits = 8; - param.black_white = img_conf_.pixtype == COLOR_MODE_BLACK_WHITE; - param.channels = img_conf_.pixtype == COLOR_MODE_24_BITS ? 3 : 1; - param.color_mode = img_conf_.pixtype; - param.double_side = img_conf_.is_duplex; - param.dpi = img_conf_.resolution_dst; - - - handle = hg_imgproc::init(&img_conf_,¶m,pid_); err = hg_imgproc::load_buffer(handle, buff); err = hg_imgproc::decode(handle,pid_); @@ -692,7 +680,7 @@ void hg_scanner_402::image_process(std::shared_ptr& buff) } if (img_conf_.fadeback) { - hg_imgproc::fadeback(handle, img_conf_.fadebackrange, param.double_side); + hg_imgproc::fadeback(handle, img_conf_.fadebackrange, img_conf_.is_duplex); //printf("背景除色开启\r\n"); //VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "背景除色开启:%s\n",hg_scanner_err_name(ret)); } @@ -716,42 +704,7 @@ void hg_scanner_402::image_process(std::shared_ptr& buff) //VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "除色开启:%s\n",hg_scanner_err_name(ret)); } /////////////////////////////////////2222222222222222222222222222222222222////////////////////////////////// - int tableLength;//= sizeof(custom_gamma_val_->table)/sizeof(custom_gamma_val_->table[0]); - - unsigned char buffer1[256 * 3]; - if (img_conf_.pixtype == COLOR_MODE_BLACK_WHITE || img_conf_.pixtype == COLOR_MODE_256_GRAY) - tableLength = 256; - else - { - - tableLength = 768; - int index = 0; - const int buffersize = 256; - - unsigned char buf_01[buffersize]; - memcpy(buf_01, custom_gamma_val_->table + index, buffersize); - index += buffersize; - - unsigned char buf_02[buffersize]; - memcpy(buf_02, custom_gamma_val_->table + index, buffersize); - index += buffersize; - - unsigned char buf_03[buffersize]; - memcpy(buf_03, custom_gamma_val_->table + index, buffersize); - index += buffersize; - - int j = 0; - for (size_t i = 0; i < buffersize; i++) - { - memcpy(buffer1 + j, buf_01 + i, 1); - memcpy(buffer1 + (++j), buf_02 + i, 1); - memcpy(buffer1 + (++j), buf_03 + i, 1); - ++j; - } - } - - - hg_imgproc::customgamma(handle, custom_gamma_, buffer1, tableLength); + adjust_color(handle); if (img_conf_.pixtype == COLOR_MODE_24_BITS && img_conf_.hsvcorrect) { @@ -1725,7 +1678,7 @@ int hg_scanner_402::stop(void) int hg_scanner_402::reset(void) { final_imgs_.clear(); - discard_all_images(); + //discard_all_images(); return status_; } diff --git a/hgdriver/hgdev/image_process.cpp b/hgdriver/hgdev/image_process.cpp index 2f4d929..43e2d27 100644 --- a/hgdriver/hgdev/image_process.cpp +++ b/hgdriver/hgdev/image_process.cpp @@ -520,16 +520,19 @@ namespace hg_imgproc return ret; } - int customgamma(bool is_customgamma,unsigned char* table,int tableLength) + int adjust_color(unsigned char* gamma_table = nullptr, int tableLength = 0) { int ret = SCANNER_ERR_OK; std::vector mats(mats_); mats_.clear(); - if(is_customgamma) + VLOG_MINI_4(LOG_LEVEL_DEBUG_INFO, "adjust_color: table len = %d, brightness = %f, contrast = %f, gamma = %f\n", tableLength + , img_conf_.brightness, img_conf_.contrast, img_conf_.gamma); + if(gamma_table && tableLength) { - CImageApplyCustomGamma gamme(table,tableLength); - gamme.apply(mats,img_conf_.is_duplex); + CImageApplyCustomGamma gamme(gamma_table, tableLength); + + gamme.apply(mats, img_conf_.is_duplex); } else { @@ -968,9 +971,9 @@ namespace hg_imgproc { return ((imgproc*)himg)->channel(); } - int customgamma(HIMGPRC himg,bool is_custogamma,unsigned char* table,int tableLength) + int adjust_color(HIMGPRC himg, unsigned char* table, int tableLength) { - return ((imgproc*)himg)->customgamma(is_custogamma,table,tableLength); + return ((imgproc*)himg)->adjust_color(table, tableLength); } int antiInflow(HIMGPRC himg,int permeate_lv) { diff --git a/hgdriver/hgdev/image_process.h b/hgdriver/hgdev/image_process.h index 5440a0b..31650af 100644 --- a/hgdriver/hgdev/image_process.h +++ b/hgdriver/hgdev/image_process.h @@ -180,7 +180,7 @@ namespace hg_imgproc int resolution_change(HIMGPRC himg); int croprect(HIMGPRC himg); int channel(HIMGPRC himg); - int customgamma(HIMGPRC himg,bool is_custogamma,unsigned char* table,int tableLength); + int adjust_color(HIMGPRC himg, unsigned char* table = nullptr, int tableLength = 0/*default value is to adjust color, or apply custom gamma*/); int antiInflow(HIMGPRC himg,int permeate_lv); int colorCorrection(HIMGPRC himg); int orentation(HIMGPRC himg);