[sane-devel] sane_read() parameters

m. allan noah kitno455 at gmail.com
Wed Mar 9 12:17:03 UTC 2016


Yes- the value of maxlen is determined by the frontend. You cannot
change it, and you certainly cannot re-alloc. You should have your own
buffer in the backend, and read bytes from it into the buffer provided
by the frontend. This type of double buffering will allow you to read
from the scanner in whatever block size is best, and then respond to
the frontend however it wants. I recommend that you not make your
backend buffer very large (to save memory), but you then have to be
careful not to overflow it when the frontend is draining it slowly.

allan

On Wed, Mar 9, 2016 at 1:14 AM, ky gcp <kygcpsample at gmail.com> wrote:
> Thank you for such quick response, allan. Do you mean to say that the value
> of maxlen is determined by the frontend? On xsane application, maxlen value
> is 8192 when using acquire preview and then value of maxlen is 65536 when
> using scan function. Our external backend currently reads images by row on
> sane_read(). Issue occurs when using acquire preview on colored A3 original
> because the number of bytes per row is more than the value of maxlen. If I
> reallocate the argument buf to a much bigger size, xsane closes and I get
> this error message below:
> *** stack smashing detected ***: xsane terminated
> Aborted (core dumped)
>
> Since our external backend currently reads images by row on sane_read(), is
> it better to just change our implementation on sane_read() ?
>
> On Wed, Mar 9, 2016 at 9:39 AM, m. allan noah <kitno455 at gmail.com> wrote:
>>
>> Because different frontends have different requirements. Some try to
>> save memory, some try to maximize speed by using large buffers, some
>> try to fill a network packet exactly. You can (and should expect) to
>> get any value of maxlen from 1 byte to perhaps a 1M, maybe more.
>>
>> allan
>>
>> On Tue, Mar 8, 2016 at 8:23 PM, ky gcp <kygcpsample at gmail.com> wrote:
>> > why does the value of maxlen vary from various frontends?
>> >
>> > On Tue, Mar 8, 2016 at 9:06 PM, m. allan noah <kitno455 at gmail.com>
>> > wrote:
>> >>
>> >> maxlen is provided by the caller of the function, to tell the backend
>> >> how much memory the caller has allocated for image data.
>> >>
>> >> allan
>> >>
>> >> On Tue, Mar 8, 2016 at 3:09 AM, ky gcp <kygcpsample at gmail.com> wrote:
>> >> > hi,
>> >> >
>> >> > how is the argument maxlen determined in sane_read() function?
>> >> >
>> >> > SANE_Status sane_read (SANE_Handle h, SANE_Byte * buf, SANE_Int
>> >> > maxlen,
>> >> > SANE_Int * len);
>> >> >
>> >> > Thanks for your help.
>> >> >
>> >> > --
>> >> > sane-devel mailing list: sane-devel at 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-request at lists.alioth.debian.org
>> >>
>> >>
>> >>
>> >> --
>> >> "well, I stand up next to a mountain- and I chop it down with the edge
>> >> of my hand"
>> >
>> >
>>
>>
>>
>> --
>> "well, I stand up next to a mountain- and I chop it down with the edge
>> of my hand"
>
>



-- 
"well, I stand up next to a mountain- and I chop it down with the edge
of my hand"



More information about the sane-devel mailing list