<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">On 02/08/2013 19:39, viresh wrote:<br>
    </div>
    <blockquote cite="mid:51FBEEDD.4000906@yahoo.co.uk" type="cite">On
      Wednesday 17 July 2013 07:17 AM, m. allan noah wrote:
      <br>
      <blockquote type="cite">I can confirm your findings- i think this
        is a bug in sanei_constrain_value.c.
        <br>
        <br>
        allan
        <br>
        <br>
        On Tue, Jul 16, 2013 at 8:46 PM, Bureau
        <a class="moz-txt-link-rfc2396E" href="mailto:viresh_shirol@yahoo.co.uk"><viresh_shirol@yahoo.co.uk></a> wrote:
        <br>
        <blockquote type="cite">Hi all,
          <br>
          <br>
          During my backend testing efforts with tstbackend.c frontend
          that is available in the distribution ,I observed an issue in
          the sanei_constrain_value function.
          <br>
          <br>
          The details are as below.
          <br>
          1)I believe the specifications for SANE_Range are simple
          enough and there are no further rules on the values for
          min,max and quant members.
          <br>
          <br>
          2)assuming #1 above is correct, my observation is that the
          constrain_value function returns values that are greater than
          the max specified for the range.
          <br>
          <br>
          3)I am assuming that #2 item is either unknown or known but
          not fixed/valid scenario.
          <br>
          <br>
          <br>
          4)the issue
          <br>
          <br>
          the issue happens for constraint type RANGE  when following
          condition is satisfied
          <br>
          <br>
          (max-min)%quant >=(quant/2)
          <br>
          <br>
          AND
          <br>
          <br>
          value to be set >=max
          <br>
          <br>
          <br>
          Cause:Due to rounding done using quant/2 value,the final value
          put in array[i] overshoots the max value by at the max quant/2
          units.
          <br>
          <br>
          <br>
          5>Why this is an issue for me
          <br>
          <br>
          for few reasons
          <br>
          a)I blindly believed the value returned by constrain_value is
          actually constrained to the max. By this assumption,I did not
          have to check the values everywhere for their
          constraint-wise-correctness.
          <br>
          <br>
          b)the machine that I am writing the backend for seems to take
          tl br values in mm and seems to do some kind of validation
          using which it decides the actual scan size.So offset of
          value/s for tl br options would lead to heavy offsets when
          large resolution scan is done.
          <br>
          <br>
          c)the issue is very dominant,I believe,when the range type is
          SANE_Fixed. Note that in this case the quant value is
          sufficiently large leading to larger offsets.
          <br>
          <br>
          6)Solutions possible
          <br>
          a)temporary fix can just check whether the adjusted value is
          larger than Max for the range and set it to either max or one
          quant level lesser.
          <br>
          Also,I can temporarily fix it in a local function.
          <br>
          b)not very sure but If the rounding via quant/2 is removed we
          can safely say that the value is always safe. I think it's a
          subjective item and can not discuss further but I think
          flooring isn't that bad.
          <br>
          <br>
          <br>
          <br>
          7)My test values(sorry to put them at the end)
          <br>
          max=SANE_FIX(431.8);//ledger width
          <br>
          min=SANE_FIX(0.0);
          <br>
          quant=SANE_FIX(0.01);//tried .1,1.0 too
          <br>
          <br>
          value to be set (actually the issue was found when testing
          with tstbkend.c fronted) is 431.8. (or more ...as constrain
          value reduces it to max in that case)
          <br>
          <br>
          <br>
          Query:how do I proceed with this?My main question is "am I
          doing something wrong??"
          <br>
          <br>
          8)Additional:
          <br>
          this is my first post.I wanna thank you all and especially the
          ones who have authored the tstbackend frontend.Also,please
          note that I may ve wrong in using fractional quant values etc
          but i think there was no limitation w.r.t. in the spec. I
          apologize in advance if anyone feels any sentence in this post
          seems to show impoliteness in any way.  ...I am newbie/noob u
          knw!!!!
          <br>
          <br>
          <br>
          Thanks and regards,
          <br>
          Viresh
          <br>
          <br>
          <br>
          <br>
          <br>
          <br>
          <br>
          <br>
          <br>
          Sent from my iPhone
          <br>
          --
          <br>
          sane-devel mailing list: <a class="moz-txt-link-abbreviated" href="mailto:sane-devel@lists.alioth.debian.org">sane-devel@lists.alioth.debian.org</a>
          <br>
<a class="moz-txt-link-freetext" href="http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel">http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel</a>
          <br>
          Unsubscribe: Send mail with subject "unsubscribe
          your_password"
          <br>
                        to <a class="moz-txt-link-abbreviated" href="mailto:sane-devel-request@lists.alioth.debian.org">sane-devel-request@lists.alioth.debian.org</a>
          <br>
        </blockquote>
        <br>
        <br>
      </blockquote>
      Hi Allan,
      <br>
      <br>
      Thanks for the quick response that day. And I am sorry for the
      late reply from my side.
      <br>
      <br>
      I am attaching the updated code based on the temporary solutions
      that I had mentioned in my original mail.
      <br>
      <br>
      I am not sure if this is the correct procedure to send the updated
      code but I am new to git as well.
      <br>
      Also I believe newbies like me can not update the code tree
      directly anyway.
      <br>
      Could you please review and include the changes in the next
      release?
      <br>
      <br>
      Please note that  the changes in my backend code were external to
      sanei_constrain_value.c.
      <br>
      i.e. though the logic was same as the attached file, the patch was
      external to constrain_value function.
      <br>
      <br>
      <br>
      <br>
      Apart from this, I would like to know if I could help the efforts
      in any way. I dont have any hardware to test any backends etc  but
      I have some experience with opencv-v4l configuration which I think
      can be helpful in improving the v4l backend. (At least the man
      page says it is not so stable)
      <br>
      Also as a plus point w.r.t scanners ,I have some 3+ years of
      experience on multi functional peripherals controller
      development(for one of the brands which do not have a sane backend
      of their own yet) which included work on  UI to middleware.
      <br>
      Let me know if I can be of any help in any way.
      <br>
      <br>
      Regards,
      <br>
      Viresh M.Shirol
      <br>
      P.S: rather large comment for 1 if block addition in the code but
      I think it explains why the changes were done clearly.
      <br>
      <br>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
    </blockquote>
        Hello,<br>
    <br>
        I have commit the fix in git tree. I have also added test cases
    in sanei_constrain_test.c which detected the problem before fix, and
    are now 'passing' with the fix.<br>
        I don't think there is a better way to change this. Since sane
    'fixed' values are float values multiplied by 65536, there will be
    always rounding issues. For instance the SANE_Range you used
    resolved to min=0, max=28298444 and quant=655, so min+k*quant will
    always be different from max.<br>
        <br>
    Regards,<br>
        Stef<br>
  </body>
</html>