From 046441ad6c7b4837601191be4865a851bb03275c Mon Sep 17 00:00:00 2001 From: Mike Kelly Date: Tue, 21 Dec 2010 16:38:13 +0900 Subject: [PATCH] Rewrote indirect "adf_mode" code to be more direct Replaced the clever, yet totally confusing, code using the "adf_mode" variable. This variable was used with a complex interaction of bit shifts and subtraction indirectly influnced by the value of s->source_mode. The replacement code direct references s->source_mode instead, simplifying things greatly. This change is functionally identical. As a side note, the adf_mode code allowed "ADF Rear" scanners, in addition to "ADF Duplex" scanners, to enter the section of code normally used for (HP) duplex scanners. It's not clear if this was the intended effect, or if, as the comments suggest, this was an unnoticed side effect caused by the confusing code. The point is moot, however, because prior in the code, the ADF Duplex flag is set anytime the ADF Rear flag is set. As long as all ADF Rear scanners are duplex scanners this shouldn't be a problem. --- backend/avision.c | 51 +++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/backend/avision.c b/backend/avision.c index 4e837ef11..865294e99 100644 --- a/backend/avision.c +++ b/backend/avision.c @@ -5549,41 +5549,30 @@ set_window (Avision_Scanner* s) /* ADF scan? */ DBG (3, "set_window: source mode %d source mode dim %d\n", s->source_mode, s->source_mode_dim); - { - int adf_mode = 0; /* offset by 1 to save a is_adf bool */ - switch (s->source_mode) { - case AV_ADF: - adf_mode = 1; - break; - case AV_ADF_REAR: - adf_mode = 2; - break; - case AV_ADF_DUPLEX: - adf_mode = 3; - break; - default: - ; /* silence GCC */ - } - if (adf_mode) { - DBG (3, "set_window: filling ADF bits\n"); - SET_BIT (cmd.window.avision.bitset1, 7); - adf_mode--; - /* normal, interlaced duplex scanners */ - if (dev->inquiry_duplex_interlaced) { - DBG (3, "set_window: interlaced duplex type\n"); - cmd.window.avision.type.normal.bitset3 |= (adf_mode << 3); + if (s->source_mode == AV_ADF || + s->source_mode == AV_ADF_REAR || + s->source_mode == AV_ADF_DUPLEX) { + DBG (3, "set_window: filling ADF bits\n"); + SET_BIT (cmd.window.avision.bitset1, 7); + + /* normal, interlaced duplex scanners */ + if (dev->inquiry_duplex_interlaced) { + DBG (3, "set_window: interlaced duplex type\n"); + if (s->source_mode == AV_ADF_REAR) { + SET_BIT(cmd.window.avision.type.normal.bitset3, 3); /* 0x08 */ } - else /* HP 2-pass duplex */ - { - if (adf_mode) /* if duplex */ - { - DBG (3, "set_window: non-interlaced duplex type (HP)\n"); - /* MIRR 0x04 | FLIP 0x02 | DPLX 0x01 ... */ - cmd.window.avision.type.normal.bitset3 |= 7; - } + if (s->source_mode == AV_ADF_DUPLEX) { + SET_BIT(cmd.window.avision.type.normal.bitset3, 4); /* 0x10 */ } } + else if (s->source_mode == AV_ADF_DUPLEX) /* HP 2-pass duplex */ + { + DBG (3, "set_window: non-interlaced duplex type (HP)\n"); + SET_BIT(cmd.window.avision.type.normal.bitset3, 0); /* DPLX 0x01 */ + SET_BIT(cmd.window.avision.type.normal.bitset3, 1); /* FLIP 0x02 */ + SET_BIT(cmd.window.avision.type.normal.bitset3, 2); /* MIRR 0x04 */ + } } /* Newer scanners can utilize this paper length to detect double feeds.