Added support for lineart mode with pixels_per_line not divisible by 8. Added

support for padded image formats. Added documentation for all options.
Henning Meier-Geinitz <henning@meier-geinitz.de>
DEVEL_2_0_BRANCH-1
Henning Geinitz 2002-06-09 17:44:20 +00:00
rodzic 155791f2b6
commit 1e582217c0
6 zmienionych plików z 336 dodań i 66 usunięć

Wyświetl plik

@ -53,6 +53,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer,
SANE_Word line_count, b_size;
SANE_Word lines = 0;
SANE_Word bpl = test_device->bytes_per_line;
SANE_Word ppl = test_device->pixels_per_line;
SANE_Byte *b;
SANE_Bool is_little_endian = little_endian ();
@ -126,7 +127,7 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer,
if (buffer)
*buffer = b;
DBG (3, "(child) init_picture_buffer: drawing grid test picture "
"%d bytes, %d bpl, %d lines\n", b_size, bpl, lines);
"%d bytes, %d bpl, %d ppl, %d lines\n", b_size, bpl, ppl, lines);
for (line_count = 0; line_count < lines; line_count++)
{
@ -144,35 +145,40 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer,
SANE_Byte value = 0;
for (x1 = 0; x1 < 8; x1++)
{
if (((SANE_Word)
((x * 8 / increment +
(7 - x1)) / p_size) % 2) ^ (line_count >
(SANE_Word)
(p_size +
0.5)) ^
(test_device->params.format == SANE_FRAME_GRAY))
color = 0x0;
SANE_Word xfull = x * 8 + (7 - x1);
if (xfull < ppl)
{
if ((((SANE_Word) (xfull / p_size)) % 2)
^ !(line_count >
(SANE_Word) (p_size + 0.5)))
color = 0x0;
else
color = 0x1;
}
else
color = 0x1;
color = (rand ()) & 0x01;
value |= (color << x1);
}
for (x1 = 0; x1 < increment; x1++)
b[line_count * bpl + x + x1] = value;
b[line_count * bpl + x] = value;
}
else
else /* SANE_FRAME_RGB */
{
SANE_Byte value = 0;
for (x1 = 0; x1 < 8; x1++)
{
if (((SANE_Word) ((x * 8 / increment + x1) / p_size)
% 2) ^ (line_count >
(SANE_Word) (p_size +
0.5)) ^ (test_device->
params.format ==
SANE_FRAME_GRAY))
color = 0x0;
SANE_Word xfull = x * 8 / 3 + x1;
if (xfull < ppl)
{
if (((SANE_Word) (xfull / p_size) % 2)
^ (line_count > (SANE_Word) (p_size + 0.5)))
color = 0x0;
else
color = 0x1;
}
else
color = 0x1;
color = (rand ()) & 0x01;
value |= (color << x1);
}
for (x1 = 0; x1 < increment; x1++)
@ -181,11 +187,15 @@ init_picture_buffer (Test_Device * test_device, SANE_Byte ** buffer,
}
else /* depth = 8, 16 */
{
if ((((SANE_Int) (x / increment / p_size)) % 2)
^ (line_count > (SANE_Int) (p_size + 0.5)))
color = 0x00;
if (x / increment < ppl)
if ((((SANE_Int) (x / increment / p_size)) % 2)
^ (line_count > (SANE_Int) (p_size + 0.5)))
color = 0x00;
else
color = 0xff;
else
color = 0xff;
color = (rand ()) & 0xff;
for (x1 = 0; x1 < increment; x1++)
b[line_count * bpl + x + x1] = color;
}

Wyświetl plik

@ -41,7 +41,7 @@
This backend is for testing frontends.
*/
#define BUILD 15
#define BUILD 16
#include "../include/sane/config.h"
@ -86,6 +86,12 @@ static SANE_Range resolution_range = {
SANE_FIX (1.0)
};
static SANE_Range ppl_loss_range = {
0,
128,
1
};
static SANE_Range read_limit_size_range = {
1,
64 * 1024, /* 64 KB ought to be enough for everyone :-) */
@ -194,6 +200,7 @@ static SANE_Bool init_read_delay = SANE_FALSE;
static SANE_Word init_read_delay_duration = 1000;
static SANE_String init_read_status_code = "Default";
static SANE_Bool init_fuzzy_parameters = SANE_FALSE;
static SANE_Word init_ppl_loss = 0;
static SANE_Bool init_non_blocking = SANE_FALSE;
static SANE_Bool init_select_fd = SANE_FALSE;
static SANE_Bool init_enable_test_options = SANE_FALSE;
@ -485,8 +492,8 @@ init_options (Test_Device * test_device)
od->title = SANE_I18N ("Return-value of sane_read");
od->desc =
SANE_I18N ("Select the return-value of sane_read(). \"Default\" "
"is the normal handling for scanning. All other status \n"
"codes are for testing how the frontend handles them.\n");
"is the normal handling for scanning. All other status "
"codes are for testing how the frontend handles them.");
od->type = SANE_TYPE_STRING;
od->unit = SANE_UNIT_NONE;
od->size = max_string_size (read_status_code_list);
@ -498,6 +505,21 @@ init_options (Test_Device * test_device)
return SANE_STATUS_NO_MEM;
strcpy (test_device->val[opt_read_status_code].s, init_read_status_code);
/* opt_ppl_loss */
od = &test_device->opt[opt_ppl_loss];
od->name = "ppl-loss";
od->title = SANE_I18N ("Loss of pixels per line");
od->desc =
SANE_I18N ("The number of pixels that are wasted at the end of each "
"line.");
od->type = SANE_TYPE_INT;
od->unit = SANE_UNIT_PIXEL;
od->size = sizeof (SANE_Word);
od->cap = SANE_CAP_SOFT_DETECT | SANE_CAP_SOFT_SELECT;
od->constraint_type = SANE_CONSTRAINT_RANGE;
od->constraint.range = &ppl_loss_range;
test_device->val[opt_ppl_loss].w = init_ppl_loss;
/* opt_fuzzy_parameters */
od = &test_device->opt[opt_fuzzy_parameters];
od->name = "fuzzy-parameters";
@ -1226,7 +1248,7 @@ finish_pass (Test_Device * test_device)
pid = waitpid (test_device->reader_pid, &status, 0);
if (pid < 0)
{
DBG (1, "finish_pass: waitpid failed, already terminated? (%s)\n",
DBG (1, "finish_pass: waitpid failed, already terminated? (%s)\n",
strerror (errno));
}
else if (WIFEXITED (status))
@ -1426,6 +1448,9 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize)
if (read_option (line, "read-status-code", param_string,
&init_read_status_code) == SANE_STATUS_GOOD)
continue;
if (read_option (line, "ppl-loss", param_int,
&init_ppl_loss) == SANE_STATUS_GOOD)
continue;
if (read_option (line, "fuzzy-parameters", param_bool,
&init_fuzzy_parameters) == SANE_STATUS_GOOD)
continue;
@ -1817,6 +1842,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action,
SANE_UNFIX (*(SANE_Fixed *) value));
break;
case opt_read_limit_size: /* Int */
case opt_ppl_loss:
case opt_read_delay_duration:
case opt_int:
case opt_int_constraint_range:
@ -2126,6 +2152,7 @@ sane_control_option (SANE_Handle handle, SANE_Int option, SANE_Action action,
break;
case opt_depth: /* Int + word list options */
case opt_read_limit_size:
case opt_ppl_loss:
case opt_read_delay_duration:
case opt_int:
case opt_int_constraint_range:
@ -2168,6 +2195,7 @@ sane_get_parameters (SANE_Handle handle, SANE_Parameters * params)
SANE_Parameters *p;
double res, tl_x = 0, tl_y = 0, br_x = 0, br_y = 0;
SANE_String text_format, mode;
SANE_Int channels = 1;
DBG (2, "sane_get_parameters: handle=%p, params=%p\n", handle, params);
if (!inited)
@ -2249,28 +2277,26 @@ sane_get_parameters (SANE_Handle handle, SANE_Parameters * params)
}
p->pixels_per_line = (SANE_Int) (res * (br_x - tl_x) / MM_PER_INCH);
if (p->pixels_per_line < 1)
p->pixels_per_line = 1;
if (p->depth == 1)
{
/* Make sure ppl can be divided by 8 */
p->pixels_per_line /= 8;
p->pixels_per_line *= 8;
if (p->pixels_per_line < 8)
p->pixels_per_line = 8;
}
test_device->bytes_per_line = p->pixels_per_line * p->depth / 8;;
if (test_device->val[opt_fuzzy_parameters].w == SANE_TRUE
&& test_device->scanning == SANE_FALSE)
p->pixels_per_line *= random_factor;
if (p->pixels_per_line < 1)
p->pixels_per_line = 1;
p->bytes_per_line = p->pixels_per_line * p->depth / 8;
if (p->format == SANE_FRAME_RGB)
{
p->bytes_per_line *= 3;
test_device->bytes_per_line *= 3;
}
channels = 3;
if (p->depth == 1)
p->bytes_per_line = channels * (p->pixels_per_line + 7) / 8;
else /* depth == 8 || depth == 16 */
p->bytes_per_line = channels * p->pixels_per_line * ((p->depth + 7) / 8);
test_device->bytes_per_line = p->bytes_per_line;
p->pixels_per_line -= test_device->val[opt_ppl_loss].w;
if (p->pixels_per_line < 1)
p->pixels_per_line = 1;
test_device->pixels_per_line = p->pixels_per_line;
switch (p->format)
{
@ -2344,8 +2370,14 @@ sane_start (SANE_Handle handle)
DBG (1, "sane_start: already in last pass of three\n");
return SANE_STATUS_INVAL;
}
test_device->scanning = SANE_TRUE;
test_device->cancelled = SANE_FALSE;
test_device->eof = SANE_FALSE;
test_device->bytes_total = 0;
sane_get_parameters (handle, 0);
if (test_device->params.lines == 0)
{
DBG (1, "sane_start: lines == 0\n");
@ -2364,10 +2396,6 @@ sane_start (SANE_Handle handle)
test_device->scanning = SANE_FALSE;
return SANE_STATUS_INVAL;
}
test_device->scanning = SANE_TRUE;
test_device->cancelled = SANE_FALSE;
test_device->eof = SANE_FALSE;
test_device->bytes_total = 0;
if (pipe (pipe_descriptor) < 0)
{

Wyświetl plik

@ -54,6 +54,9 @@ read-status-code "Default"
# Fuzzy parameters (true, false)
fuzzy-parameters false
# Loss of pixels per line (pixels)
ppl-loss 0
# Non-blocking io (true, false)
non-blocking false

Wyświetl plik

@ -30,8 +30,9 @@ typedef enum
opt_read_delay,
opt_read_delay_duration,
opt_read_status_code,
opt_ppl_loss,
opt_fuzzy_parameters,
opt_non_blocking,
opt_non_blocking,
opt_select_fd,
opt_enable_test_options,
opt_print_options,
@ -91,6 +92,7 @@ typedef struct Test_Device
FILE *pipe_handle;
SANE_Word pass;
SANE_Word bytes_per_line;
SANE_Word pixels_per_line;
SANE_Word lines;
SANE_Int bytes_total;
SANE_Bool open;

Wyświetl plik

@ -10,8 +10,8 @@
;
:backend "test" ; name of backend
:version "1.0-15" ; version of backend
:status :new ; :alpha, :beta, :stable, :new
:version "1.0-16" ; version of backend
:status :beta ; :alpha, :beta, :stable, :new
:manpage "sane-test" ; name of manpage (if it exists)
:url "http://www.meier-geinitz.de/sane/test-backend/" ; backend's web page

Wyświetl plik

@ -1,4 +1,4 @@
.TH sane-test 5 "9 Apr 2002"
.TH sane-test 5 "9 Jun 2002"
.IX sane-test
.SH NAME
sane-test - SANE backend for testing frontends
@ -7,26 +7,254 @@ The
.B sane-test
library implements a SANE (Scanner Access Now Easy) backend that allows
testing the SANE installation and SANE frontends. It provides access to a
(nearly) unlimited number of virtual devices. There is no support for
real scanners or cameras. However, the backend simulates scanning and setting
(nearly) unlimited number of virtual devices. There is no support for real
scanners or cameras. However, the backend simulates scanning and setting
options.
.PP
The idea is not only to find bugs in frontends but also to show all
capabilities of SANE. Therefore
capabilities of SANE. Therefore
.B sane-test
implements functions and options that are not (or seldomly) found in other
backends.
.PP
The backend is commented out in @CONFIGDIR@/dll.conf, so either the comment
sign must be removed or the backend must be called explicitely. E.g.
character must be removed or the backend must be called explicitely. E.g.
`scanimage -d test' or `xscanimage test'.
.SH SANE OPTIONS
The options should be self-explanatory. Have a look at their descriptions.
If a description is too vague, please contact me. Just some comments: The
combination of color and 1-bit mode is quite obscure (8 colors) but allowed
in the SANE standard. However, the meaning of bits is not defined. Currently
1 = high intensity and 0 = low intensity is used.
.SH SCAN MODE OPTIONS
Option
.B mode
selects the scan mode (Gray or Color).
.PP
Option
.B depth
determines the number of bits per sample (1. 8, or 16). Keep in mind, that
this value refers to the sample, not the pixel. So depth=16 results in 48
bits per pixel in color mode. The most usual combinations are mode=Gray,
depth=1 for lineart, mode=Gray, depth=8 for gray and mode=Color, depth=8 for
color mode. The combination of color and 1-bit mode is quite obscure (8
colors) but allowed in the SANE standard. However, the meaning of bits is not
defined. Currently 1 = high intensity and 0 = low intensity is used.
.PP
Setting option
.B hand-scanner
results in the test-backend behaving like a hand-scanner. Hand-scanners do
not know the image height a priori. Instead, they return a height of -1.
Setting this option allows to test whether a frontend can handle this
correctly. This option also enables a fixed width of 11 cm.
.PP
Setting option
.B three-pass
simulates a three-pass scanner. Older color scanners needed to scan the image
once per color (reg/green/blue) to get the full image. Therefore, in this mode
three single frames are transmitted in color mode.
.PP
Option
.B three-pass-order
provides support for changing the order of the three frames (see option
three-pass above). A frontend should support all orders.
.PP
Option
.B resolution
sets the resolution of the image in dots per inch.
.PP
.SH SPECIAL OPTIONS
Option
.B test-picture
allows to set the image that's returned to the frontend. While "Solid white"
and "Solid black" are quite obvious, the other options need some more
explanation. Color patterns are used to determine if all modes and their
colors are reprented correctly by the frontend. The grid should look like the
same in every mode and resolution. A table of all the test pictures can be
found at: http://www.meier-geinitz.de/sane/test-backend/test-pictures.html.
.PP
If option
.B read-limit
is set, the maximum amount of data tranferred with each call to sane_read() is
limited.
.PP
Option
.B read-limit-size
sets the limit for option read-limit. A low limit slows down scanning. It
can be used to detect errors in frontend that occur because of wrong
assumptions on the size of the buffer or timing problems.
.PP
Option
.B read-delay
enables delaying data to the frontend.
.PP
Option
.B read-delay-duration
selects the number of microseconds the backends waits after each transfer of a
buffer. This option is useful to find timing-related bugs, especially if
used over the network.
.PP
If option
.B read-return-value
is different from "Default", the selected status will be returned by every
call to sane_read(). This is useful to test the frontend's handling of the
SANE statii.
.PP
If option
.B ppl-loss
is different from 0, it determines the number of pixels that are "lost" at the
end of each line. That means, lines are padded with unused data.
.PP
Option
.B fuzzy-parameters
selects that fuzzy (inexact) parameters are returned as long as the scan
hasn't been started. This option can be used to test if the frontend uses the
parameters it got before the start of the scan (which it shouldn't).
.PP
Option
.B non-blocking
determines if non-blocking IO for sane_read() should be used if supported by
the frontend.
.PP
If option
.B select-fd
is set, the backend offers a select filedescriptor for detecting if
sane_read() will return data.
.PP
If option
.B enable-test-options
is set, a fairly big list of options for testing the various SANE option
types is enabled.
.PP
Option
.B print-options
can be used to print a list of all options to standard error.
.PP
.SH GEOMETRY OPTIONS
Option
.B tl-x
determines the top-left x position of the scan area.
.PP
Option
.B tl-y
determines the top-left y position of the scan area.
.PP
Option
.B br-x
determines the bottom-right x position of the scan area.
.PP
Option
.B br-y
determines the bottom-right y position of the scan area.
.PP
.SH BOOL TEST OPTIONS
There are 6 bool test options in total. Each option is numbered. (3/6)
means: this is option 3 of 6. The numbering scheme is inetended for easier
detection of options not displayed by the frontend (bevause of missing support
or bugs).
.PP
Option
.B bool-soft-select-soft-detect
(1/6) is a bool test option that has soft select and soft detect (and
advanced) capabilities. That's just a normal bool option.
.PP
Option
.B bool-hard-select-soft-detect
(2/6) is a bool test option that has hard select and soft detect (and
advanced) capabilities. That means the option can't be set by the frontend
but by the user (e.g. by pressing a button at the device).
.PP
Option
.B bool-hard-select
(3/6) is a bool test option that has hard select (and advanced) capabilities.
That means the option can't be set by the frontend but by the user (e.g. by
pressing a button at the device) and can't be read by the frontend.
.PP
Option
.B bool-soft-detect
(4/6) is a bool test option that has soft detect (and advanced)
capabilities. That means the option is read-only.
.PP
Option
.B bool-soft-select-soft-detect-emulated
(5/6) is a Bool test option that has soft select, soft detect, and emulated
(and advanced) capabilities.
.PP
Option
.B bool-soft-select-soft-detect-auto
(6/6) is a Bool test option that has soft select, soft detect, and automatic
(and advanced) capabilities. This option can be automatically set by the
backend.
.PP
.SH INT TEST OPTIONS
There are 6 int test options in total.
.PP
Option
.B int
(1/6) is an int test option with no unit and no constraint set.
.PP
Option
.B int-constraint-range
(2/6) is an int test option with unit pixel and constraint range set. Minimum
is 4, maximum 192, and quant is 2.
.PP
Option
.B int-constraint-word-list
(3/6) is an int test option with unit bits and constraint word list set.
.PP
Option
.B int-constraint-array
(4/6) is an int test option with unit mm and using an array without
constraints.
.PP
Option
.B int-constraint-array-constraint-range
(5/6) is an int test option with unit mm and using an array with a range
constraint. Minimum is 4, maximum 192, and quant is 2.
.PP
Option
.B int-constraint-array-constraint-word-list
(6/6) is an int test option with unit percent and using an array a word list
constraint.
.SH FIXED TEST OPTIONS
There are 3 fixed test options in total.
.PP
Option
.B fixed
(1/3) is a fixed test option with no unit and no constraint set.
.PP
Option
.B fixed-constraint-range
(2/3) is a fixed test option with unit microsecond and constraint range
set. Minimum is -42.17, maximum 32767.9999, and quant is 2.0.
.PP
Option
.B fixed-constraint-word-list
(3/3) is a Fixed test option with no unit and constraint word list set.
.PP
.SH STRING TEST OPTIONS
There are 3 string test options in total.
.PP
Option
.B string
(1/3) is a string test option without constraint.
.PP
Option
.B string-constraint-string-list
(2/3) is a string test option with string list constraint.
.PP
Option
.B string-constraint-long-string-list
(3/3) is a string test option with string list constraint. Contains some more
entries...
.PP
.SH BUTTON TEST OPTION
Option
.B button
(1/1) is a Button test option. Prints some text...
.PP
.SH FILES
.TP
@ -38,7 +266,7 @@ in this file. A template containing all the default values is provided
together with this backend. One of the more interesting values may be
.BR number_of_devices .
It can be used to check the frontend's ability to show a long list of devices.
The config values concerning resolution and geometry can be usefull to test
The config values concerning resolution and geometry can be useful to test
the handling of big file sizes.
.TP
@ -82,4 +310,3 @@ Henning Meier-Geinitz <henning@meier-geinitz.de>
.SH BUGS
- config file values aren't tested for correctness
- man page hasn't been completed yet