Add software page de-rotate and white page skip

merge-requests/1/head
Stphane Voltz 2011-06-05 21:08:37 +02:00
rodzic 2f656293c3
commit c67786154f
3 zmienionych plików z 105 dodań i 8 usunięć

Wyświetl plik

@ -163,7 +163,7 @@ static const SANE_Range u16_range = {
0 /* quantization */
};
static const SANE_Range threshold_percentage_range = {
static const SANE_Range percentage_range = {
SANE_FIX (0), /* minimum */
SANE_FIX (100), /* maximum */
SANE_FIX (1) /* quantization */
@ -175,7 +175,6 @@ static const SANE_Range threshold_curve_range = {
1 /* quantization */
};
void
sanei_genesys_init_structs (Genesys_Device * dev)
{
@ -5841,8 +5840,13 @@ calc_parameters (Genesys_Scanner * s)
/* some digital processing requires the whole picture to be buffered */
/* no digital processing takes place when doing preview, or when bit depth is
* higher than 8 bits */
if ((s->val[OPT_SWDESPECK].b || s->val[OPT_SWCROP].b || s->val[OPT_SWDESKEW].b)
&& (!s->val[OPT_PREVIEW].b) && (s->val[OPT_BIT_DEPTH].w <= 8))
if ((s->val[OPT_SWDESPECK].b
|| s->val[OPT_SWCROP].b
|| s->val[OPT_SWDESKEW].b
|| s->val[OPT_SWDEROTATE].b
||(SANE_UNFIX(s->val[OPT_SWSKIP].w)>0))
&& (!s->val[OPT_PREVIEW].b)
&& (s->val[OPT_BIT_DEPTH].w <= 8))
{
s->dev->buffer_image=SANE_TRUE;
}
@ -6167,12 +6171,33 @@ init_options (Genesys_Scanner * s)
/* crop by software */
s->opt[OPT_SWCROP].name = "swcrop";
s->opt[OPT_SWCROP].title = "Software crop";
s->opt[OPT_SWCROP].desc = "Request backend to remove border from pages digitally";
s->opt[OPT_SWCROP].title = SANE_I18N ("Software crop");
s->opt[OPT_SWCROP].desc = SANE_I18N ("Request backend to remove border from pages digitally");
s->opt[OPT_SWCROP].type = SANE_TYPE_BOOL;
s->opt[OPT_SWCROP].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
s->opt[OPT_SWCROP].unit = SANE_UNIT_NONE;
s->val[OPT_SWCROP].b = SANE_FALSE;
/* Software blank page skip */
s->opt[OPT_SWSKIP].name = "swskip";
s->opt[OPT_SWSKIP].title = SANE_I18N ("Software blank skip percentage");
s->opt[OPT_SWSKIP].desc = SANE_I18N("Request driver to discard pages with low numbers of dark pixels");
s->opt[OPT_SWSKIP].type = SANE_TYPE_FIXED;
s->opt[OPT_SWSKIP].unit = SANE_UNIT_PERCENT;
s->opt[OPT_SWSKIP].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_SWSKIP].constraint.range = &(percentage_range);
/* disable by default */
s->val[OPT_SWSKIP].w = 0;
/* Software Derotate */
s->opt[OPT_SWDEROTATE].name = "swderotate";
s->opt[OPT_SWDEROTATE].title = SANE_I18N ("Software derotate");
s->opt[OPT_SWDEROTATE].desc = SANE_I18N("Request driver to detect and correct 90 degree image rotation");
s->opt[OPT_SWDEROTATE].type = SANE_TYPE_BOOL;
s->opt[OPT_SWCROP].cap = SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT | SANE_CAP_ADVANCED;
s->opt[OPT_SWDEROTATE].unit = SANE_UNIT_NONE;
s->val[OPT_SWDEROTATE].b = SANE_FALSE;
/* "Extras" group: */
s->opt[OPT_EXTRAS_GROUP].title = SANE_I18N ("Extras");
s->opt[OPT_EXTRAS_GROUP].desc = "";
@ -6188,7 +6213,7 @@ init_options (Genesys_Scanner * s)
s->opt[OPT_THRESHOLD].type = SANE_TYPE_FIXED;
s->opt[OPT_THRESHOLD].unit = SANE_UNIT_PERCENT;
s->opt[OPT_THRESHOLD].constraint_type = SANE_CONSTRAINT_RANGE;
s->opt[OPT_THRESHOLD].constraint.range = &threshold_percentage_range;
s->opt[OPT_THRESHOLD].constraint.range = &percentage_range;
s->val[OPT_THRESHOLD].w = SANE_FIX (50);
/* BW threshold curve */
@ -7327,6 +7352,8 @@ get_option_value (Genesys_Scanner * s, int option, void *val)
case OPT_SWDESKEW:
case OPT_SWCROP:
case OPT_SWDESPECK:
case OPT_SWDEROTATE:
case OPT_SWSKIP:
case OPT_DESPECK:
*(SANE_Word *) val = s->val[option].w;
break;
@ -7442,6 +7469,8 @@ set_option_value (Genesys_Scanner * s, int option, void *val,
case OPT_SWCROP:
case OPT_SWDESKEW:
case OPT_DESPECK:
case OPT_SWDEROTATE:
case OPT_SWSKIP:
case OPT_DISABLE_INTERPOLATION:
case OPT_PREVIEW:
s->val[option].w = *(SANE_Word *) val;
@ -7470,6 +7499,8 @@ set_option_value (Genesys_Scanner * s, int option, void *val,
DISABLE(OPT_SWDESPECK);
DISABLE(OPT_SWCROP);
DISABLE(OPT_DESPECK);
DISABLE(OPT_SWDEROTATE);
DISABLE(OPT_SWSKIP);
}
else
{
@ -7477,6 +7508,8 @@ set_option_value (Genesys_Scanner * s, int option, void *val,
ENABLE(OPT_SWDESPECK);
ENABLE(OPT_SWCROP);
ENABLE(OPT_DESPECK);
ENABLE(OPT_SWDEROTATE);
ENABLE(OPT_SWSKIP);
}
RIE (calc_parameters (s));
*myinfo |= SANE_INFO_RELOAD_PARAMS | SANE_INFO_RELOAD_OPTIONS;
@ -7888,6 +7921,24 @@ sane_start (SANE_Handle handle)
if (s->dev->buffer_image)
{
RIE(genesys_buffer_image(s));
/* check if we need to skip this page, sheetfed scanners
* can go to next doc while flatbed ones can't */
if (s->val[OPT_SWSKIP].w && IS_ACTIVE(OPT_SWSKIP))
{
status = sanei_magic_isBlank(&s->params,
s->dev->img_buffer,
SANE_UNFIX(s->val[OPT_SWSKIP].w));
if(status == SANE_STATUS_NO_DOCS)
{
if (s->dev->model->is_sheetfed == SANE_TRUE)
{
DBG (DBG_info, "sane_start: blank page, recurse\n");
return sane_start(handle);
}
return status;
}
}
/* deskew image if required */
if(s->val[OPT_SWDESKEW].b == SANE_TRUE)
@ -7906,6 +7957,12 @@ sane_start (SANE_Handle handle)
{
RIE(genesys_crop(s));
}
/* de-rotate image if required */
if(s->val[OPT_SWDEROTATE].b == SANE_TRUE)
{
RIE(genesys_derotate(s));
}
}
DBG (DBG_proc, "sane_start: exit\n");

Wyświetl plik

@ -1,7 +1,7 @@
/* sane - Scanner Access Now Easy.
Copyright (C) 2003, 2004 Henning Meier-Geinitz <henning@meier-geinitz.de>
Copyright (C) 2005-2010 Stephane Voltz <stef.dev@free.fr>
Copyright (C) 2005-2011 Stephane Voltz <stef.dev@free.fr>
Copyright (C) 2006 Laurent Charpentier <laurent_pubs@yahoo.com>
Copyright (C) 2009 Pierre Willenbrock <pierre@pirsoft.dnsalias.org>
@ -102,6 +102,8 @@ enum Genesys_Option
OPT_SWCROP,
OPT_SWDESPECK,
OPT_DESPECK,
OPT_SWSKIP,
OPT_SWDEROTATE,
OPT_EXTRAS_GROUP,
OPT_LAMP_OFF_TIME,

Wyświetl plik

@ -1,6 +1,7 @@
/* sane - Scanner Access Now Easy.
Copyright (C) 2005, 2006 Pierre Willenbrock <pierre@pirsoft.dnsalias.org>
Copyright (C) 2010-2011 Stéphane Voltz <stef.dev@free.fr>
This file is part of the SANE package.
@ -383,5 +384,42 @@ genesys_despeck(Genesys_Scanner *s)
return SANE_STATUS_GOOD;
}
/** Look if image needs rotation and apply it
* */
static SANE_Status
genesys_derotate (Genesys_Scanner * s)
{
SANE_Status status = SANE_STATUS_GOOD;
int angle = 0;
int resolution = s->val[OPT_RESOLUTION].w;
DBGSTART;
status = sanei_magic_findTurn (&s->params,
s->dev->img_buffer,
resolution,
resolution,
&angle);
if (status)
{
DBG (DBG_warn, "%s: failed : %d\n", __FUNCTION__, status);
DBGCOMPLETED;
return SANE_STATUS_GOOD;
}
/* apply rotation angle found */
status = sanei_magic_turn (&s->params, s->dev->img_buffer, angle);
if (status)
{
DBG (DBG_warn, "%s: failed : %d\n", __FUNCTION__, status);
DBGCOMPLETED;
return SANE_STATUS_GOOD;
}
/* update counters to new image size */
s->dev->total_bytes_to_read = s->params.bytes_per_line * s->params.lines;
DBGCOMPLETED;
return SANE_STATUS_GOOD;
}
/* vim: set sw=2 cino=>2se-1sn-1s{s^-1st0(0u0 smarttab expandtab: */