FIX: color scanning problems with snapscans in sane 1.0.3

From: Lawrence Glaister (lg@jfm.bc.ca)
Date: Thu Sep 21 2000 - 20:59:04 PDT

  • Next message: Oliver Rauch: "Re: image data format polarity"

    Steve... !
    man are my eyes bloodshot but I seem to have found the problem with the
    RGBRouter
    code... please have a look and see if it works in your config.
    The problem seems to be that there was an early bailout that caused data
    passed through
    the RGBRouter to be dropped (the last line or partial line of pixels in each
    32k input
    buffer). This really messed things up, resulting in totally scrambled images
    that were too short.
    The change is only a 1/2 liner, but I am including the whole routine with
    some
    comments and debugging code that I used to investigate the problem.
    Let me know how it hangs on your end.

    sorry about the formatting, my mailer totally nuked the indenting
    =================cut here
    static SANE_Status
    RGBRouter_get (Source * pself, SANE_Byte * pbuf, SANE_Int * plen)
    {
       RGBRouter *ps = (RGBRouter *) pself;
       SANE_Status status = SANE_STATUS_GOOD;
       SANE_Int remaining = *plen;
       SANE_Byte *s;
       SANE_Int i;
       SANE_Int r;
       SANE_Int g;
       SANE_Int b;

       DBG (1, "RGBRouter_get %d\n", *plen);

       while (remaining > 0 && pself->remaining (pself) > 0)
       {
      /* if someone has emptied the buffer, get some more data */
         if (ps->pos >= ps->cb_line_size)
      {
         /* Try to get more data -- fill buffer or 1 line worth*/
         SANE_Int ndata = (ps->cb_start < 0) ? ps->cb_size : ps->cb_line_size;
         SANE_Int start = (ps->cb_start < 0) ? 0 : ps->cb_start;
         SANE_Int ndata2;
         SANE_Int ndata3;

         ndata2 = ndata;
         ndata3 = 0;
         do
          {
        /* read data from the TxSource and fill our buffer */
             status = TxSource_get (pself, ps->cbuf + start + ndata3, &ndata2);
    // bogus if (status != SANE_STATUS_GOOD || ndata2 == 0)
    <==========line to change
             if (status != SANE_STATUS_GOOD)
        {
         /* I believe we should only return here on bad status */
         DBG (1, "RGBRouter_get OOPS early return %d %d\n",status,ndata2);
           *plen -= remaining;
           return status;
        }
             ndata3 += ndata2; /* total of all collected */
             ndata2 = ndata - ndata3; /* amount left to collect */
          }
         while (ndata3 < ndata); /* loop until we have data asked for */

       /* move 1 row of color data into our buffer (xbuf) */
         ps->cb_start = (start + ndata3) % ps->cb_size;
         s = ps->xbuf;
         r = (ps->cb_start + ps->ch_offset[0]) % ps->cb_size;
         g = (ps->cb_start + ps->ch_offset[1]) % ps->cb_size;
         b = (ps->cb_start + ps->ch_offset[2]) % ps->cb_size;

       DBG (1, "RGBRouter_get Moving line of %d pixels from %d %d %d\n",
         ps->cb_line_size / 3,r,g,b);
         for (i = 0; i < ps->cb_line_size / 3; i++)
          {
             *s++ = ps->cbuf[r++];
             *s++ = ps->cbuf[g++];
             *s++ = ps->cbuf[b++];
          }
         ps->pos = 0;
      }
           /* Repack the whole scan line now */
           while (remaining > 0 && ps->pos < ps->cb_line_size)
      {
         *pbuf++ = ps->xbuf[ps->pos++];
         remaining--;
      }
        }

       *plen -= remaining;
       return status;
    }

    =================end of code

    =======================================================
    Lawrence Glaister VE7IT email: lg@jfm.bc.ca
    1462 Madrona Drive http://jfm.bc.ca
    Nanoose Bay BC Canada
    V9P 9C9
    =======================================================

    --
    Source code, list archive, and docs: http://www.mostang.com/sane/
    To unsubscribe: echo unsubscribe sane-devel | mail majordomo@mostang.com
    



    This archive was generated by hypermail 2b29 : Thu Sep 21 2000 - 20:56:07 PDT