Hi,

I have attached three patches for the xerox_mfp driver. The first one is for general support of the Samsung SCX-4521F scanner. The second is some minor code cleanup only. The last one fixes some (general?) issue for the driver in halftone and lineart mode.

I have tested the new driver with the Samsung SCX-4521F exhaustively with all resolutions and modes as well as from ADF and flatbed source. I have uploaded some of the results:

https://postimg.org/image/ct3wrct8j/2ded59ef/
https://postimg.org/image/sfpdr1bn3/db3135a8/
https://postimg.org/image/d0qft1qkv/9519c5ca/
https://postimg.org/image/stxoxvq1v/f0b7e72c/
https://postimg.org/image/quyvdhycj/cc9458cf/
https://postimg.org/image/rte34rvgp/3a32686b/
https://postimg.org/image/x1ubcg06r/d4b223af/
https://postimg.org/image/wgsfilr5j/1da4da06/

In my opinion the device can now be stated at least as "Good" in the list of supported devices.

Best regards,
Marc
>From 885ee1537520fbc1eefe3cc29f156a97cb577e4c Mon Sep 17 00:00:00 2001
From: Marc Schink <sane-...@marcschink.de>
Date: Sun, 15 Jan 2017 18:59:06 +0100
Subject: [PATCH 1/3] xerox_mfp: Add support for Samsung SCX-4521F

The acquisition with the xerox_mfp driver works almost out of the box
for the Samsung SCX-4521F but the process stops just before the end
of the document until an USB transfer timeout expires. The very last
part of the scanned document is missing then.

Do not request more data from the device than available for the last
USB transfer to overcome this problem and to be conform with the
properties of the vendor driver.

The driver was tested for all resolutions supported by the device
with color and grayscale mode.
No regression test with other devices supported by the xerox_mfp
driver was done because of lack of devices.
---
 backend/xerox_mfp.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/backend/xerox_mfp.c b/backend/xerox_mfp.c
index 8b8c895..47d925e 100644
--- a/backend/xerox_mfp.c
+++ b/backend/xerox_mfp.c
@@ -1281,7 +1281,7 @@ sane_read(SANE_Handle h, SANE_Byte *buf, SANE_Int maxlen, SANE_Int *lenp)
         return SANE_STATUS_EOF;
 
     /* if there is no data to read or output from buffer */
-    if (!dev->blocklen && dev->datalen <= PADDING_SIZE) {
+    if (!dev->blocklen && (dev->datalen <= PADDING_SIZE || dev->final_block)) {
 
         /* copying uncompressed data */
         if (dev->composition == MODE_RGB24 &&
@@ -1344,23 +1344,27 @@ sane_read(SANE_Handle h, SANE_Byte *buf, SANE_Int maxlen, SANE_Int *lenp)
         int olen; /* output len */
 
         /* read as much data into the buffer */
-        datalen = DATAROOM(dev) & USB_BLOCK_MASK;
+        datalen = MIN(dev->blocklen, DATAROOM(dev) & USB_BLOCK_MASK);
         while (datalen && dev->blocklen) {
             SANE_Byte *rbuf = dev->data + DATATAIL(dev);
 
             DBG(9, "<> request len: %lu, [%d, %d; %d]\n",
                 (u_long)datalen, dev->dataoff, DATATAIL(dev), dev->datalen);
+
             if ((status = dev->io->dev_request(dev, NULL, 0, rbuf, &datalen)) !=
                 SANE_STATUS_GOOD)
                 return status;
+
             dev->datalen += datalen;
             dev->blocklen -= datalen;
+
             DBG(9, "<> got %lu, [%d, %d; %d]\n",
                 (u_long)datalen, dev->dataoff, DATATAIL(dev), dev->datalen);
+
             if (dev->blocklen < 0)
                 return ret_cancel(dev, SANE_STATUS_IO_ERROR);
 
-            datalen = DATAROOM(dev) & USB_BLOCK_MASK;
+            datalen = MIN(dev->blocklen, DATAROOM(dev) & USB_BLOCK_MASK);
         }
 
         if (buf && lenp) { /* read mode */
-- 
2.7.4

>From e038c320f07013b18b0c421bcccba8835136f1ac Mon Sep 17 00:00:00 2001
From: Marc Schink <sane-...@marcschink.de>
Date: Sun, 15 Jan 2017 18:59:14 +0100
Subject: [PATCH 2/3] xerox_mfp: Fix various format specifiers

---
 backend/xerox_mfp.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/backend/xerox_mfp.c b/backend/xerox_mfp.c
index 47d925e..945c385 100644
--- a/backend/xerox_mfp.c
+++ b/backend/xerox_mfp.c
@@ -231,7 +231,7 @@ static void dbg_dump(struct device *dev)
     for (i = 0; i < dlen; i++, dptr += 3)
         sprintf(dptr, " %02x", dev->res[i]);
 
-    DBG(5, "[%lu]%s%s\n", (u_long)dev->reslen, dbuf,
+    DBG(5, "[%zu]%s%s\n", dev->reslen, dbuf,
         (dlen < (int)dev->reslen)? "..." : "");
 }
 
@@ -258,8 +258,8 @@ static int dev_command(struct device *dev, SANE_Byte *cmd, size_t reqlen)
     }
 
     dev->state = 0;
-    DBG(4, ":: dev_command(%s[%#x], %lu)\n", str_cmd(cmd[2]), cmd[2],
-        (u_long)reqlen);
+    DBG(4, ":: dev_command(%s[%#x], %zu)\n", str_cmd(cmd[2]), cmd[2],
+        reqlen);
     status = dev->io->dev_request(dev, cmd, sendlen, res, &dev->reslen);
     if (status != SANE_STATUS_GOOD) {
         DBG(1, "%s: dev_request: %s\n", __func__, sane_strstatus(status));
@@ -274,8 +274,8 @@ static int dev_command(struct device *dev, SANE_Byte *cmd, size_t reqlen)
 
     /* normal command reply, some sanity checking */
     if (dev->reslen < reqlen) {
-        DBG(1, "%s: illegal response len %lu, need %lu\n",
-            __func__, (u_long)dev->reslen, (u_long)reqlen);
+        DBG(1, "%s: illegal response len %zu, need %zu\n",
+            __func__, dev->reslen, reqlen);
         dev->state = SANE_STATUS_IO_ERROR;
         return 0;
     } else {
@@ -291,14 +291,14 @@ static int dev_command(struct device *dev, SANE_Byte *cmd, size_t reqlen)
         }
         pktlen = dev->res[2] + 3;
         if (dev->reslen != pktlen) {
-            DBG(2, "%s: illegal response len %lu, should be %lu\n",
-                __func__, (u_long)pktlen, (u_long)dev->reslen);
+            DBG(2, "%s: illegal response len %zu, should be %zu\n",
+                __func__, pktlen, dev->reslen);
             dev->state = SANE_STATUS_IO_ERROR;
             return 0;
         }
         if (dev->reslen > reqlen)
-            DBG(2, "%s: too big packet len %lu, need %lu\n",
-                __func__, (u_long)dev->reslen, (u_long)reqlen);
+            DBG(2, "%s: too big packet len %zu, need %zu\n",
+                __func__, dev->reslen, reqlen);
     }
 
     dev->state = 0;
@@ -1348,8 +1348,8 @@ sane_read(SANE_Handle h, SANE_Byte *buf, SANE_Int maxlen, SANE_Int *lenp)
         while (datalen && dev->blocklen) {
             SANE_Byte *rbuf = dev->data + DATATAIL(dev);
 
-            DBG(9, "<> request len: %lu, [%d, %d; %d]\n",
-                (u_long)datalen, dev->dataoff, DATATAIL(dev), dev->datalen);
+            DBG(9, "<> request len: %zu, [%d, %d; %d]\n",
+                datalen, dev->dataoff, DATATAIL(dev), dev->datalen);
 
             if ((status = dev->io->dev_request(dev, NULL, 0, rbuf, &datalen)) !=
                 SANE_STATUS_GOOD)
@@ -1358,8 +1358,8 @@ sane_read(SANE_Handle h, SANE_Byte *buf, SANE_Int maxlen, SANE_Int *lenp)
             dev->datalen += datalen;
             dev->blocklen -= datalen;
 
-            DBG(9, "<> got %lu, [%d, %d; %d]\n",
-                (u_long)datalen, dev->dataoff, DATATAIL(dev), dev->datalen);
+            DBG(9, "<> got %zu, [%d, %d; %d]\n",
+                datalen, dev->dataoff, DATATAIL(dev), dev->datalen);
 
             if (dev->blocklen < 0)
                 return ret_cancel(dev, SANE_STATUS_IO_ERROR);
-- 
2.7.4

>From 8537f48e7fd5248d47430f4b887a8b58b0471f07 Mon Sep 17 00:00:00 2001
From: Marc Schink <sane-...@marcschink.de>
Date: Sun, 15 Jan 2017 18:59:17 +0100
Subject: [PATCH 3/3] xerox_mfp: Fix lineart and halftone mode

Halftone and lineart mode do not work properly except for a
resolution of 600 dpi. The very last part of a scanned document is
missing and displayed as black stripe. This problem was found with a
Samsung SCX-4521F, but is assumed to affect other devices, too.

Decode the data received from the device in halftone and lineart mode
to fix this problem.

This patch was tested with a Samsung SCX-4521F device for all
resolutions supported by the device with color, grayscale, lineart
and halftone mode.
No regression test with other devices supported by the xerox_mfp
driver was done because of lack of devices.
---
 backend/xerox_mfp.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/backend/xerox_mfp.c b/backend/xerox_mfp.c
index 945c385..0c604f1 100644
--- a/backend/xerox_mfp.c
+++ b/backend/xerox_mfp.c
@@ -1294,6 +1294,13 @@ sane_read(SANE_Handle h, SANE_Byte *buf, SANE_Int maxlen, SANE_Int *lenp)
                 dev->total_out_size += *lenp;
                 return SANE_STATUS_GOOD;
             }
+        } else if (dev->composition != MODE_RGB24) {
+            int diff = dev->total_img_size - dev->total_out_size;
+            int bufLen = (diff < maxlen) ? diff : maxlen;
+            if (diff > 0 && copy_plain_trim(dev, buf, bufLen, lenp) > 0) {
+                dev->total_out_size += *lenp;
+                return SANE_STATUS_GOOD;
+            }
         }
 
         /* and we don't need to acquire next block */
-- 
2.7.4

-- 
sane-devel mailing list: sane-devel@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel
Unsubscribe: Send mail with subject "unsubscribe your_password"
             to sane-devel-requ...@lists.alioth.debian.org

Reply via email to