From ac6c138fb3835770cfb61099a4689baf50af46cd Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Fri, 6 May 2022 14:37:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=87=AA=E5=AE=9A=E4=B9=89ga?= =?UTF-8?q?mma=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hgdriver/hgdev/hg_scanner.cpp | 48 +++++++++++++---------------------- hgdriver/hgdev/hg_scanner.h | 2 +- 2 files changed, 19 insertions(+), 31 deletions(-) diff --git a/hgdriver/hgdev/hg_scanner.cpp b/hgdriver/hgdev/hg_scanner.cpp index 32376ca..667a4d9 100644 --- a/hgdriver/hgdev/hg_scanner.cpp +++ b/hgdriver/hgdev/hg_scanner.cpp @@ -26,8 +26,9 @@ hg_scanner::hg_scanner(ScannerSerial serial { paper_size_mm_.cx = 210; paper_size_mm_.cy = 297; - for (int i = 0; i < sizeof(custom_gamma_val_); ++i) - custom_gamma_val_[i] = i; + custom_gamma_val_.pt_count = 0; + for (int i = 0; i < ARRAY_SIZE(custom_gamma_val_.table); ++i) + custom_gamma_val_.table[i] = i & 0x0ff; HG_VLOG_MINI_2(HG_LOG_LEVEL_DEBUG_INFO, "%s(%s) constructed\n", name_.c_str(), hg_log::format_ptr(this).c_str()); image_prc_param_.value = 0; @@ -454,8 +455,9 @@ int hg_scanner::restore(int setting_no) setting_jsn_.at(key).at("name").get_to(val); if (val == KNOWN_OPT_NAME_CUSTOM_GAMMA) { - for (size_t i = 0; i < sizeof(custom_gamma_val_); ++i) - custom_gamma_val_[i] = i; + custom_gamma_val_.pt_count = 0; + for (int i = 0; i < ARRAY_SIZE(custom_gamma_val_.table); ++i) + custom_gamma_val_.table[i] = i & 0x0ff; return HG_ERR_OK; } @@ -1353,16 +1355,9 @@ int hg_scanner::setting_is_custom_gamma(void* data) } int hg_scanner::setting_custom_gamma_data(void* data) { - SANE_Int* v = (SANE_Int*)data; - int len = 256; + SANE_Gamma* gamma = (SANE_Gamma*)data; - if (image_prc_param_.bits.color_mode == COLOR_MODE_24_BITS || - image_prc_param_.bits.color_mode == COLOR_MODE_AUTO_MATCH) - { - len = 3 * 256; - } - for (int i = 0; i < len; ++i) - custom_gamma_val_[i] = v[i]; + memcpy(&custom_gamma_val_, gamma, sizeof(custom_gamma_val_)); return HG_ERR_OK; } @@ -1903,17 +1898,12 @@ int hg_scanner::get_setting(int setting_no, char* json_txt_buf, int* len) if (is_gamma) { name = ""; - add = 256; - if (image_prc_param_.bits.color_mode == COLOR_MODE_24_BITS || - image_prc_param_.bits.color_mode == COLOR_MODE_AUTO_MATCH) - { - add = 3 * 256; - } - sprintf(sn, "[%u", custom_gamma_val_[0]); + add = 3 * 256; + sprintf(sn, "[%u", custom_gamma_val_.table[0]); name += sn; for (int i = 1; i < add; ++i) { - sprintf(sn, ",%u", custom_gamma_val_[i]); + sprintf(sn, ",%u", custom_gamma_val_.table[i]); name += sn; } name += "]"; @@ -2196,19 +2186,17 @@ int hg_scanner::device_io_control(unsigned long code, void* data, unsigned* len) } else if (code == IO_CTRL_CODE_GET_CUSTOM_GAMMA) { - SANE_Int* v = (SANE_Int*)data; - int count = *len; - for (int i = 0; i < count && i < sizeof(custom_gamma_val_); ++i) - v[i] = custom_gamma_val_[i]; + SANE_Gamma* v = (SANE_Gamma*)data; + + memcpy(v, &custom_gamma_val_, sizeof(custom_gamma_val_)); return HG_ERR_OK; } - else if (code == IO_CTRL_CODE_GET_CUSTOM_GAMMA) + else if (code == IO_CTRL_CODE_SET_CUSTOM_GAMMA) { - SANE_Int* v = (SANE_Int*)data; - int count = *len; - for (int i = 0; i < count && i < sizeof(custom_gamma_val_); ++i) - custom_gamma_val_[i] = v[i]; + SANE_Gamma* v = (SANE_Gamma*)data; + + memcpy(&custom_gamma_val_, v, sizeof(custom_gamma_val_)); return HG_ERR_OK; } diff --git a/hgdriver/hgdev/hg_scanner.h b/hgdriver/hgdev/hg_scanner.h index fe88ed7..f5fad5f 100644 --- a/hgdriver/hgdev/hg_scanner.h +++ b/hgdriver/hgdev/hg_scanner.h @@ -253,7 +253,7 @@ protected: //////////////////////////////////////////////////////////////// // 新增自定义伽玛曲线及扫描区域属性 - 2022-05-05 bool custom_gamma_; // 为true时,应用custom_gamma_val_阵列调整图像色彩;为false时,保持原来的处理方式 - uint8_t custom_gamma_val_[3 * 256]; // 当为RGB或者彩色时,为三组256字节的数据;当为黑白或灰度时,只有一组256字节 + SANE_Gamma custom_gamma_val_; // 当为RGB或者彩色时,为三组256字节的数据;当为黑白或灰度时,只有一组256字节 bool custom_area_; // 是否启用自定义区域,为true时才使用下列4个数据;为false时保持原来的处理方式 double custom_area_lt_x_; // 自定义区域左上角x坐标 double custom_area_lt_y_; // 自定义区域左上角y坐标