kopia lustrzana https://gitlab.com/sane-project/backends
- improved sanei_constrain_value to handle arrays (such as gamma
tables)merge-requests/1/head
rodzic
24fab2e360
commit
777c8f4f6d
|
@ -1,3 +1,9 @@
|
|||
2008-06-10 Stéphane Voltz <stef.dev@free.fr>
|
||||
* backend/sanei_constrain_value.c: add support for arrays of SANE_Word
|
||||
in sanei_constrain_value
|
||||
* backend/umax_pp.c: remove now unneede 'hand made' constrain on
|
||||
gamma tables
|
||||
|
||||
2008-06-09 Stéphane Voltz <stef.dev@free.fr>
|
||||
* backend/rts8891.c: fix for model with 'XPA' sensor
|
||||
|
||||
|
|
|
@ -1458,15 +1458,6 @@ sane_control_option (SANE_Handle handle, SANE_Int option,
|
|||
case OPT_GAMMA_VECTOR_R:
|
||||
case OPT_GAMMA_VECTOR_G:
|
||||
case OPT_GAMMA_VECTOR_B:
|
||||
|
||||
for (i = 0; i < dev->opt[option].size / sizeof (SANE_Word); i++)
|
||||
{
|
||||
if (((SANE_Int *) val)[i] < 0 || ((SANE_Int *) val)[i] > 255)
|
||||
{
|
||||
DBG (2, "Value at index %d out of range\n", i);
|
||||
return SANE_STATUS_INVAL;
|
||||
}
|
||||
}
|
||||
memcpy (val, dev->val[option].wa, dev->opt[option].size);
|
||||
return SANE_STATUS_GOOD;
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
whether to permit this exception to apply to your modifications.
|
||||
If you do not wish that, delete this exception notice. */
|
||||
|
||||
#include "sane/config.h"
|
||||
#include "../include/sane/config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
@ -47,8 +47,8 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "sane/sane.h"
|
||||
#include "sane/sanei.h"
|
||||
#include "../include/sane/sane.h"
|
||||
#include "../include/sane/sanei.h"
|
||||
|
||||
SANE_Status
|
||||
sanei_check_value (const SANE_Option_Descriptor * opt, void *value)
|
||||
|
@ -73,7 +73,8 @@ sanei_check_value (const SANE_Option_Descriptor * opt, void * value)
|
|||
|
||||
if (range->quant)
|
||||
{
|
||||
v = (unsigned int) (w - range->min + range->quant/2) / range->quant;
|
||||
v =
|
||||
(unsigned int) (w - range->min + range->quant / 2) / range->quant;
|
||||
v = v * range->quant + range->min;
|
||||
if (v != w)
|
||||
return SANE_STATUS_INVAL;
|
||||
|
@ -104,7 +105,12 @@ sanei_check_value (const SANE_Option_Descriptor * opt, void * value)
|
|||
return SANE_STATUS_GOOD;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function apply the constraint defined by the option descriptor
|
||||
* to the given value, and update the info flags holder if needed. It
|
||||
* return SANE_STATUS_INVAL if the constraint cannot be applied, else
|
||||
* it returns SANE_STATUS_GOOD.
|
||||
*/
|
||||
SANE_Status
|
||||
sanei_constrain_value (const SANE_Option_Descriptor * opt, void *value,
|
||||
SANE_Word * info)
|
||||
|
@ -113,47 +119,64 @@ sanei_constrain_value (const SANE_Option_Descriptor * opt, void * value,
|
|||
const SANE_Word *word_list;
|
||||
int i, k, num_matches, match;
|
||||
const SANE_Range *range;
|
||||
SANE_Word w, v;
|
||||
SANE_Word w, v, *array;
|
||||
SANE_Bool b;
|
||||
size_t len;
|
||||
|
||||
switch (opt->constraint_type)
|
||||
{
|
||||
case SANE_CONSTRAINT_RANGE:
|
||||
w = *(SANE_Word *) value;
|
||||
|
||||
/* single values are treated as arrays of length 1 */
|
||||
array = (SANE_Word *) value;
|
||||
|
||||
/* compute number of elements */
|
||||
if (opt->size>0)
|
||||
{
|
||||
k = opt->size / sizeof (SANE_Word);
|
||||
}
|
||||
else
|
||||
{
|
||||
k = 1;
|
||||
}
|
||||
|
||||
/* for each element of the array, we apply the constraint */
|
||||
for (i = 0; i < k; i++)
|
||||
{
|
||||
range = opt->constraint.range;
|
||||
|
||||
if (w < range->min)
|
||||
if (array[i] < range->min)
|
||||
{
|
||||
*(SANE_Word *) value = range->min;
|
||||
array[i] = range->min;
|
||||
if (info)
|
||||
{
|
||||
*info |= SANE_INFO_INEXACT;
|
||||
}
|
||||
}
|
||||
|
||||
if (w > range->max)
|
||||
if (array[i] > range->max)
|
||||
{
|
||||
*(SANE_Word *) value = range->max;
|
||||
array[i] = range->max;
|
||||
if (info)
|
||||
{
|
||||
*info |= SANE_INFO_INEXACT;
|
||||
}
|
||||
}
|
||||
|
||||
w = *(SANE_Word *) value;
|
||||
|
||||
if (range->quant)
|
||||
{
|
||||
v = (unsigned int) (w - range->min + range->quant/2) / range->quant;
|
||||
v =
|
||||
(unsigned int) (array[i] - range->min +
|
||||
range->quant / 2) / range->quant;
|
||||
v = v * range->quant + range->min;
|
||||
if (v != w)
|
||||
if (v != array[i])
|
||||
{
|
||||
*(SANE_Word *) value = v;
|
||||
array[i] = v;
|
||||
if (info)
|
||||
*info |= SANE_INFO_INEXACT;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case SANE_CONSTRAINT_WORD_LIST:
|
||||
|
|
Ładowanie…
Reference in New Issue