[sane-devel] Canon Lide 50 (Genesys) - Added threshold for BW
(lineart)
Laurent Charpentier
laurent_pubs at yahoo.com
Fri Mar 24 00:56:53 UTC 2006
Hi Everyone,
I would like to submit a patch for the genesys backend (Canon LIDE 50). The
patch adds the threshold feature for black/white mode (in 1.0.17 the threshold
is set to 50% and can't be changed).
The attached patch is relative to "sane-backends-1.0.17" (files genesys.c,
genesys.h, genesys_gl841.c, genesys_low.h).
Thank you to apply this patch.
Regards,
Laurent
--- sane-backends-1.0.17/backend/genesys.c 2005-12-06 22:46:01.000000000 +0100
+++ sane-backends-1.0.17_patched/backend/genesys.c 2006-03-20
22:03:33.000000000 +0100
@@ -120,6 +120,11 @@
0 /* quantization */
};
+static const SANE_Range threshold_percentage_range = {
+ SANE_FIX( 0), /* minimum */
+ SANE_FIX( 100), /* maximum */
+ SANE_FIX( 1) /* quantization */
+};
/* ------------------------------------------------------------------------ */
/* functions calling ASIC specific functions */
@@ -4423,6 +4428,9 @@
s->dev->settings.tl_x = tl_x;
s->dev->settings.tl_y = tl_y;
+ /* threshold setting */
+ s->dev->settings.threshold = 2.55 * (SANE_UNFIX (s->val[OPT_THRESHOLD].w));
+
return status;
}
@@ -4601,6 +4609,17 @@
s->opt[OPT_EXTRAS_GROUP].size = 0;
s->opt[OPT_EXTRAS_GROUP].constraint_type = SANE_CONSTRAINT_NONE;
+ /* BW threshold */
+ s->opt[OPT_THRESHOLD].name = SANE_NAME_THRESHOLD;
+ s->opt[OPT_THRESHOLD].title = SANE_TITLE_THRESHOLD;
+ s->opt[OPT_THRESHOLD].desc = SANE_DESC_THRESHOLD;
+ s->opt[OPT_THRESHOLD].type = SANE_TYPE_FIXED;
+ s->opt[OPT_THRESHOLD].unit = SANE_UNIT_PERCENT;
+ s->opt[OPT_THRESHOLD].cap |= SANE_CAP_INACTIVE;
+ s->opt[OPT_THRESHOLD].constraint_type = SANE_CONSTRAINT_RANGE;
+ s->opt[OPT_THRESHOLD].constraint.range = &threshold_percentage_range;
+ s->val[OPT_THRESHOLD].w = SANE_FIX(50);
+
/* Powersave time (turn lamp off) */
s->opt[OPT_LAMP_OFF_TIME].name = "lamp-off-time";
s->opt[OPT_LAMP_OFF_TIME].title = SANE_I18N ("Lamp off time");
@@ -5132,6 +5151,7 @@
case OPT_TL_Y:
case OPT_BR_X:
case OPT_BR_Y:
+ case OPT_THRESHOLD:
case OPT_LAMP_OFF_TIME:
*(SANE_Word *) val = s->val[option].w;
break;
@@ -5178,6 +5198,7 @@
break;
case OPT_RESOLUTION:
case OPT_BIT_DEPTH:
+ case OPT_THRESHOLD:
case OPT_PREVIEW:
s->val[option].w = *(SANE_Word *) val;
RIE (calc_parameters (s));
@@ -5212,12 +5233,12 @@
s->val[option].s = strdup (val);
if (strcmp (s->val[option].s, "Lineart") == 0)
{
- /* ENABLE (OPT_THRESHOLD); */
+ ENABLE (OPT_THRESHOLD);
DISABLE (OPT_BIT_DEPTH);
}
else
{
- /* DISABLE (OPT_THRESHOLD); */
+ DISABLE (OPT_THRESHOLD);
if (strcmp (s->val[option].s, "Gray") == 0)
create_bpp_list (s, s->dev->model->bpp_gray_values);
else
--- sane-backends-1.0.17/backend/genesys.h 2005-12-06 22:46:01.000000000 +0100
+++ sane-backends-1.0.17_patched/backend/genesys.h 2006-03-20
21:49:01.000000000 +0100
@@ -82,6 +82,7 @@
OPT_EXTRAS_GROUP,
OPT_LAMP_OFF_TIME,
+ OPT_THRESHOLD,
/* must come last: */
NUM_OPTIONS
};
--- sane-backends-1.0.17/backend/genesys_gl841.c 2005-12-06 22:46:03.000000000
+0100
+++ sane-backends-1.0.17_patched/backend/genesys_gl841.c 2006-03-20
21:52:55.000000000 +0100
@@ -1396,6 +1396,7 @@
/*
* Set all registers to default values
+ * (function called only once at the beginning)
*/
static void
gl841_init_registers (Genesys_Device * dev)
@@ -1475,10 +1476,10 @@
dev->reg[reg_0x29].value = 0xff;
/*BWHI*/
- dev->reg[reg_0x2e].value = 0x80;
+ dev->reg[reg_0x2e].value = 0xC0;
/*BWLOW*/
- dev->reg[reg_0x2f].value = 0x80;
+ dev->reg[reg_0x2f].value = 0xC0;
/*LPERIOD*/
dev->reg[reg_0x38].value = 0x4f;
@@ -2448,6 +2449,13 @@
r = sanei_genesys_get_address (reg, 0x03);
r->value |= REG03_AVEENB | REG03_LAMPPWR;
+ /* BW threshold */
+ r = sanei_genesys_get_address (reg, 0x2e);
+ r->value = dev->settings.threshold;
+ r = sanei_genesys_get_address (reg, 0x2f);
+ r->value = dev->settings.threshold;
+
+
/* monochrome / color scan */
r = sanei_genesys_get_address (reg, 0x04);
switch (depth) {
@@ -3916,6 +3924,7 @@
float move;
int move_dpi;
float start;
+ int threshold;
SANE_Status status;
@@ -3927,6 +3936,9 @@
gl841_slow_back_home(dev,1);
+/* BW threshold */
+ threshold = dev->settings.threshold;
+
/* channels */
if (dev->settings.scan_mode == 4) /* single pass color */
channels = 3;
--- sane-backends-1.0.17/backend/genesys_low.h 2005-12-06 22:46:03.000000000
+0100
+++ sane-backends-1.0.17_patched/backend/genesys_low.h 2006-03-20
21:49:24.000000000 +0100
@@ -400,6 +400,9 @@
int exposure_time;
unsigned int color_filter; /* todo: check, may be make it an advanced option
*/
+
+ /* BW threshold */
+ int threshold;
} Genesys_Settings;
typedef struct Genesys_Current_Setup
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the sane-devel
mailing list