Hello Augusto,

I tried to handle the blue pixel as a page change.
Additional lines will be skipped until the blue pixel is found.
But now the scanimage tool will not terminate properly, maybe because just
skipping lines like I do is not the correct way to do this.

See attached patch.

Given the complexity of the sane code and limited spare time I tend more to
write a new frontend  to handle the page change marker. It could then also
handle the mirrored backsides.

I tested it with duplex and 300 dpi.

BTW, have you tried using the ADF with 150 dpi? For me the scanned images are
all bad.

- Rainer
From 32de155c98e39aab6011190da08025711b40e464 Mon Sep 17 00:00:00 2001
From: Rainer Keller <[email protected]>
Date: Sat, 8 Nov 2014 11:28:05 +0100
Subject: [PATCH] hp5590: skip additional lines from ADF

---
 backend/hp5590.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 77 insertions(+), 3 deletions(-)

diff --git a/backend/hp5590.c b/backend/hp5590.c
index 978c7f7..f932e09 100644
--- a/backend/hp5590.c
+++ b/backend/hp5590.c
@@ -216,7 +216,77 @@ calc_image_params (struct hp5590_scanner *scanner,

   return SANE_STATUS_GOOD;
 }
-
+
+/******************************************************************************/
+static void
+count_lines (struct hp5590_scanner *scanner, SANE_Byte *data, SANE_Int *size)
+{
+      static int status = 2;
+      static unsigned int countedLines = 0;
+      unsigned int bytes_per_line;
+      unsigned int pixels_per_line;
+      unsigned int lines_per_page;
+      int lines;
+      int j;
+      int skipped;
+      SANE_Byte *write, *read;
+
+      write = data;
+      read = data;
+      skipped = 0;
+
+      /* status 1 == wait for blue pixel
+         status 2 == scan
+         */
+
+      if (calc_image_params( scanner, NULL, &pixels_per_line, &bytes_per_line, &lines_per_page, NULL) != SANE_STATUS_GOOD)
+          return;
+
+
+      lines = *size / bytes_per_line;
+
+      for (j = 1; j <= lines; ++j) {
+        if (scanner->depth == DEPTH_COLOR_24) {
+
+          if (countedLines >= lines_per_page && status != 1) {
+                    /* too many lines per page */
+                    status = 1;
+          }
+
+#if 0
+          if ( data[j * bytes_per_line -1] != 0)
+              printf("pixel %d\n", data[j * bytes_per_line -1]);
+#endif
+
+          if (data[j * bytes_per_line -3] == 0 && data[j * bytes_per_line -2] == 0 && data[j * bytes_per_line -1] == 170) {
+            /* blue pixel */
+            printf("blue pixel at line %d\n", countedLines);
+            status = 2;
+            countedLines = 0;
+          }
+
+          if (status == 2) {
+                  if (skipped > 0) {
+                      memcpy(write, read, bytes_per_line);
+                  }
+                  read += bytes_per_line;
+                  write += bytes_per_line;
+                  ++countedLines;
+          } else {
+                  ++skipped;
+                  read += bytes_per_line;
+          }
+        } else {
+          printf("currently unsupported depth\n");
+        }
+      }
+
+#if 0
+      printf("line %d\n", countedLines);
+#endif
+      *size -= skipped * bytes_per_line;
+}
+
 /******************************************************************************/
 static SANE_Status
 attach_usb_device (SANE_String_Const devname,
@@ -1321,8 +1391,6 @@ sane_read (SANE_Handle handle, SANE_Byte * data,
       return ret;
     }

-  scanner->transferred_image_size -= *length;
-
   ret = convert_to_rgb (scanner, data, *length);
   if (ret != SANE_STATUS_GOOD)
     {
@@ -1330,6 +1398,12 @@ sane_read (SANE_Handle handle, SANE_Byte * data,
       return ret;
     }

+  if (scanner->source == SOURCE_ADF || scanner->source == SOURCE_ADF_DUPLEX) {
+     count_lines(scanner, data, length);
+  }
+
+  scanner->transferred_image_size -= *length;
+
   ret = convert_lineart (scanner, data, *length);
   if (ret != SANE_STATUS_GOOD)
     return ret;
--
2.0.4

Attachment: signature.asc
Description: This is a digitally signed message part.

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

Reply via email to