调整自定义gamma参数

This commit is contained in:
gb 2022-05-06 14:37:52 +08:00
parent 89b46cc387
commit ac6c138fb3
2 changed files with 19 additions and 31 deletions

View File

@ -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]);
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;
}

View File

@ -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坐标