From 1e56c23fcbc9ac8afdbc2d8206bbe3e537781684 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Sat, 24 Sep 2022 12:33:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DRange-step=E8=BD=AC=E6=8D=A2B?= =?UTF-8?q?UG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sane/s2t_api.h | 1 + twain/twain/huagaods.cpp | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/sane/s2t_api.h b/sane/s2t_api.h index 36e28ac..3c7846d 100644 --- a/sane/s2t_api.h +++ b/sane/s2t_api.h @@ -383,6 +383,7 @@ namespace sane_opts { \ sane_opts::get_opts op(cur, init, NULL, NULL, low, up, step); \ object->get_value(ind, sane_opts::set_opt_value, &op);\ + if(step && fabs(*step) < .000001) *step = 1; \ } \ } #define SET_SANE_OPT(ret, object, id_name, val) \ diff --git a/twain/twain/huagaods.cpp b/twain/twain/huagaods.cpp index fc2ca27..c67b1a1 100644 --- a/twain/twain/huagaods.cpp +++ b/twain/twain/huagaods.cpp @@ -577,13 +577,21 @@ int to_sane_enhance(Filter twain) return FILTER_NONE; } -float trans_range(float val, float min_from, float max_from, float min_to, float max_to) +float trans_range(float val, float min_from, float max_from, float min_to, float max_to, bool for_step = false) { // transfer val in range [min_from, max_from] to value in range [min_to, max_to] - val -= min_from; - val /= max_from - min_from; - val *= max_to - min_to; - val += min_to; + if (for_step) + { + val /= max_from - min_from; + val *= max_to - min_to; + } + else + { + val -= min_from; + val /= max_from - min_from; + val *= max_to - min_to; + val += min_to; + } return val; } @@ -2064,7 +2072,7 @@ void huagao_ds::init_support_caps(void) int init = 128, l = 1, u = 255, step = 1, now = 128; int ret = SCANNER_ERR_OK; GET_SANE_OPT_RANGE(int, scanner_, bright, &now, &init, &l, &u, &step); - float sf = trans_range((float)step, (float)l, (float)u, -1000.0f, 1000.0f), + float sf = trans_range((float)step, (float)l, (float)u, -1000.0f, 1000.0f, true), nf = trans_range((float)now, (float)l, (float)u, -1000.0f, 1000.0f), initf = trans_range((float)init, (float)l, (float)u, -1000.0f, 1000.0f); switch (msg) { @@ -2098,7 +2106,7 @@ void huagao_ds::init_support_caps(void) int init = 4, l = 1, u = 7, step = 1, now = 4; int ret = SCANNER_ERR_OK; GET_SANE_OPT_RANGE(int, scanner_, contrast, &now, &init, &l, &u, &step); - float sf = trans_range((float)step, (float)l, (float)u, -1000.0f, 1000.0f), + float sf = trans_range((float)step, (float)l, (float)u, -1000.0f, 1000.0f, true), nf = trans_range((float)now, (float)l, (float)u, -1000.0f, 1000.0f), initf = trans_range((float)init, (float)l, (float)u, -1000.0f, 1000.0f); switch (msg) {