修复Range-step转换BUG
This commit is contained in:
parent
1f52aea78c
commit
1e56c23fcb
|
@ -383,6 +383,7 @@ namespace sane_opts
|
|||
{ \
|
||||
sane_opts::get_opts<type> op(cur, init, NULL, NULL, low, up, step); \
|
||||
object->get_value(ind, sane_opts::set_opt_value<type>, &op);\
|
||||
if(step && fabs(*step) < .000001) *step = 1; \
|
||||
} \
|
||||
}
|
||||
#define SET_SANE_OPT(ret, object, id_name, val) \
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue