SANE Standard Version 2.0 proposal 0.08 - rauch/beck

Dec 8, 2002

Contents

1 Preface 6

1.1 About This Document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 1.1.1 Typographic Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

2 Introduction 7 2.1 Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

3 The SANE Environment 8 3.1 Attaching to a SANE backend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 3.2 Image Data Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

3.2.1 Pixel oriented frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 3.2.2 Arbitrary data frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

4 The SANE Application Programmer Interface (API) 13 4.1 Version Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 4.2 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

4.2.1 Base Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 4.2.2 Boolean Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 4.2.3 Integer Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 4.2.4 Fixed-point Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 4.2.5 Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 4.2.6 Scanner Handle Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 4.2.7 Status Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 4.2.8 Device Descriptor Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 4.2.9 Option Descriptor Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 4.2.10 Internationalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

4.3 Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 4.3.1 sane init . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 4.3.2 sane exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 4.3.3 sane get devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 4.3.4 sane open . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 4.3.5 sane close . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 4.3.6 sane get option descriptor . . . . . . . . . . . . . . . . . . . . . . . . . 28 4.3.7 sane control option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 4.3.8 sane get parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 4.3.9 sane start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 4.3.10 sane read . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 4.3.11 sane cancel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35 4.3.12 sane set io mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 4.3.13 sane get select fd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 4.3.14 sane strstatus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

4.4 Code Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 4.5 Well-Known Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

4.5.1 Option Number Count . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4.5.2 Scan Resolution Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4.5.3 Preview Mode Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 4.5.4 Scan Area Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 4.5.5 Depth Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 4.5.6 Scan Mode Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 4.5.7 Scan Source Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 4.5.8 Threshold Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 4.5.9 Gamma Table Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 4.5.10 Analog Gamma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 4.5.11 Shadow Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 4.5.12 Highlight Option . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 4.5.13 Lamp Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 4.5.14 Scanner Button Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 4.5.15 Batch Scan Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

5 Network Protocol 48

5.1 Data Type Encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 5.1.1 Primitive Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 5.1.2 Type Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

5.2 Remote Procedure Call Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 5.2.1 SANE NET INIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 5.2.2 SANE NET GET DEVICES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 5.2.3 SANE NET OPEN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 5.2.4 SANE NET CLOSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 5.2.5 SANE NET GET OPTION DESCRIPTORS . . . . . . . . . . . . . . . . . . . . . . 52 5.2.6 SANE NET CONTROL OPTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 5.2.7 SANE NET GET PARAMETERS . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 5.2.8 SANE NET START . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 5.2.9 SANE NET CANCEL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 5.2.10 SANE NET AUTHORIZE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 5.2.11 SANE NET EXIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

6 Contact Information 56

List of Figures

3.1 Example SANE Hiearchy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 3.2 Transfer order of image data bytes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 3.3 Bit and byte order of image data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

4.1 Code flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 4.2 Scan area options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

List of Tables

4.1 Status Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 4.2 Predefined Device Information Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 4.3 Option Value Types (SANE Value Type) . . . . . . . . . . . . . . . . . . . . . . . . . . 21 4.4 Physical Units (SANE Unit) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 4.5 Option Capabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 4.6 Option Value Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 4.7 Action Values (SANE Action) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 4.8 Additional Information Returned When Setting an Option . . . . . . . . . . . . . . . . . . . 30 4.9 Frame Format (SANE Frame) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

Chapter 1

Preface

The SANE standard is being developed by a group of free-software developers. The process is open to the public and comments as well as suggestions for improvements are welcome. Information on how to join the SANE development process can be found in Chapter 6.

The SANE standard is intended to streamline software development by providing a standard application programming interface to access raster scanner hardware. This should reduce the number of different driver implementations, thereby reducing the need for reimplementing similar code.

1.1 About This Document

This document is intended for developers who are creating either an application that requires access to raster scanner hardware and for developers who are implementing a SANE driver. It does not cover specific implementations of SANE components. Its sole purpose is to describe and define the SANE application interface that will enable any application on any platform to interoperate with any SANE backend for that platform.

The remainder of this document is organized as follows. Chapter 2 provides introductional material. Chapter 3 presents the environment SANE is designed for. Chapter 4 details the SANE Application Programmer Interface. Chapter 5 specifies the network protocol that can be used to implement the SANE API in a network transparent fashion. Finally, Chapter 6 gives information on how to join the SANE development process.

1.1.1 Typographic Conventions

Changes since the last revision of this document are highlighted like this:

Paragraphs that changed since the last revision of the documention are marked like this paragraph.

Introduction

SANE is an application programming interface (API) that provides standardized access to any raster image scanner hardware. The standardized interface allows to write just one driver for each scanner device instead of one driver for each scanner and application. The reduction in the number of required drivers provides significant savings in development time. More importantly, SANE raises the level at which applications can work. As such, it will enable applications that were previously unheard of in the UNIX world. While SANE is primarily targeted at a UNIX environment, the standard has been carefully designed to make it possible to implement the API on virtually any hardware or operating system.

SANE is an acronym for “Scanner Access Now Easy.” Also, the hope is that SANE is sane in the sense that it will allow easy implementation of the API while accommodating all features required by today’s scanner hardware and applications. Specifically, SANE should be broad enough to accommodate devices such as scanners, digital still and video cameras, as well as virtual devices like image file filters.

2.1 Terminology

An application that uses the SANE interface is called a SANE frontend. A driver that implements the SANE interface is called a SANE backend. A meta backend provides some means to manage one or more other backends.

The SANE Environment

SANE is defined as a C-callable library interface. Accessing a raster scanner device typically consists of two phases: first, various controls of the scanner need to be setup or queried. In the second phase, one or more images are acquired.

Since the device controls are widely different from device to device, SANE provides a generic interface that makes it easy for a frontend to give a user access to all controls without having to understand each and every device control. The design principle used here is to abstract each device control into a SANE option. An option is a self-describing name/value pair. For example, the brightness control of a camera might be represented by an option called brightness whose value is an integer in the range from 0 to 255.

With self-describing options, a backend need not be concerned with presentation issues: the backend simply provides a list of options that describe all the controls available in the device. Similarly, there are benefits to the frontend: it need not be concerned with the meaning of each option. It simply provides means to present and alter the options defined by the backend.

3.1 Attaching to a SANE backend

The process through which a SANE frontend connects to a backend is platform dependent. Several possibilities exist:

• Static linking: A SANE backend may be linked directly into a frontend. While the simplest method of attaching to a backend, it is somewhat limited in functionality since the available devices is limited to the ones for which support has been linked in when the frontend was built. But even so static linking can be quite useful, particularly when combined with a backend that can access scanners via a network. Also, it is possible to support multiple backends simultaneously by implementing a meta backend that manages several backends that have been compiled in such a manner that they export unique function names. For example, a backend called be would normally export a function called sane read(). If each backend would provide such a function, static linking would fail due to multiple conflicting definitions of the same symbol. This can be resolved by having backend be include a header file that has lines of the form:

    #define sane_read be_sane_read

With definitions of this kind, backend be will export function name be sane read(). Thus, all backends will export unique names. As long as a meta backend knows about these names, it is possible to combine several backends at link time and select and use them dynamically at runtime.

• Dynamic linking: A simpler yet more powerful way to support multiple backends is to exploit dynamic linking on platforms that support it. In this case, a frontend is linked against a shared library that implements any SANE backend. Since each dynamically linked backend exports the same set of global symbols (all starting with the prefix sane ), the dynamic library that gets loaded at runtime does not necessarily have to be the same one as one the frontend got linked against. In other words, it is possible to switch the backend by installing the appropriate backend dynamic library.

More importantly, dynamic linking makes it easy to implement a meta backend that loads other backends on demand. This is a powerful mechanism since it allows adding new backends merely by installing a shared library and updating a configuration file.

• Network connection: Arguably the ultimate way to attach to a scanner is by using the network to connect to a backend on a remote machine. This makes it possible to scan images from any host in the universe, as long as there is a network connection to that host and provided the user is permitted to access that scanner.

Figure 3.1: Example SANE Hiearchy

The above discussion lists just a few ways for frontends to attach to a backend. It is of course possible to combine these solutions to provide an entire hierarchy of SANE backends. Such a hierarchy is depicted in Figure 3.1. The figure shows that machine A uses a dynamic-linking based meta backend called dll to access the backends called pnm, mustek, and net. The first two are real backends, whereas the last one is a meta backend that provides network transparent access to remote scanners. In the figure, machine B provides non-local access to its scanners through the SANE frontend called saned. The saned in turn has access to the hp and autolum backends through another instance of the dll backend. The autolum meta backend is used to automatically adjust the luminance (brightness) of the image data acquired by the camera backend called qcam.

Note that a meta backend really is both a frontend and a backend at the same time. It is a frontend from the viewpoint of the backends that it manages and a backend from the viewpoint of the frontends that access it. The name “meta backend” was chosen primarily because the SANE standard describes the interface from the viewpoint of a (real) frontend.

3.2 Image Data Format

Arguably the most important aspect of an image acquisition system is how images are represented. The SANE approach is to define a simple yet powerful representation that is sufficient for vast majority of applications and devices. While the representation is simple, the interface has been defined carefully to allow extending it in the future without breaking backwards compatibility. Thus, it will be possible to accommodate future applications or devices that were not anticipated at the time this standard was created.

A SANE image is a rectangular area. The rectangular area is subdivided into a number of rows and columns. At the intersection of each row and column is a (preferable quadratic) pixel. A pixel consists of one or more sample values. Each sample value represents one channel (e.g., the red channel).

The SANE API transmits an image as a sequence of frames. Each frame covers the same rectangular area as the entire image, but may contain only a subset of the channels in the final image. For example, a red/green/blue image could either be transmitted as a single frame that contains the sample values for all three channels or it could be transmitted as a sequence of three frames: the first frame containing the red channel, the second the green channel, and the third the blue channel.

When transmitting an image frame by frame, the frontend needs to know what part of the image a frame represents (and how many frames it should expect). For that purpose, the SANE API tags every frame with a type and a format descriptor.

There are two different types of frames: pixel oriented frames SANE FRAME RAW and arbitrary data frames SANE FRAME MIME. These types are discussed in detail in the following sections. The frame types used by the previous version 1 of this standard (SANE FRAME GRAY, SANE FRAME RGB, SANE FRAME RED,

SANE FRAME GREEN, and SANE FRAME BLUE) are obsolete and superseded by SANE FRAME RAW.

3.2.1 Pixel oriented frames

The type of pixel oriented frames is SANE FRAME RAW. The frame contains one or more channels of data in a channel-interleaved format, that represents sample values from a property of the individual pixels that is subject to further description in the format desc member of the SANE Parameters structured type. See section 4.3.8 on page 29 for details about the format descriptions.

Each sample value has a certain bit depth. The bit depth is fixed for the entire image and can be as small as one bit. Valid bit depths are 1, 8, or 16 bits per sample. If a device’s natural bit depth is something else, it is up to the driver to scale the sample values appropriately (e.g., a 4 bit sample could be scaled by a factor of four to represent a sample value of depth 8).

The complete image may consist of several different channels. The number of channels is defined by member channels per image of SANE Parameters. The image may be transmitted in an arbitrary number of frames which can be determined by watching the SANE PFLAG LAST FRAME flag in said type (or by counting the channels). Note: This frame type replaces all frame types of the SANE standard version 1.

Conceptually, each pixel oriented frame is transmitted a byte at a time. Each byte may contain 8 sample values (for an image bit depth of 1), one full sample value (for an image bit depth of 8), or a partial sample value (for an image bit depth of 16 or bigger). In the latter case, the bytes of each sample value are transmitted in the machine’s native byte order.

Backend Implementation Note A network-based meta backend will have to ensure that the byte order in image data is adjusted appropriately if necessary. For example, when the meta backend attaches to the server proxy, the proxy may inform the backend of the server’s byte order. The backend can then apply the adjustment if necessary. In essence, this implements a “receiver-makes-right” approach.

Figure 3.2: Transfer order of image data bytes

The order in which the sample values in a frame are transmitted is illustrated in Figure 3.2. As can be seen, the values are transmitted row by row and each row is transmitted from left-most to right-most column. The left-to-right, top-to-bottom transmission order applies when the image is viewed in its normal orientation (as it would be displayed on a screen, for example).

If a frame contains multiple channels, then the channels are transmitted in an interleaved fashion. Figure 3.3 illustrates this for the case where a frame contains a complete red/green/blue image with a bit-depth of 8.

For a bit depth of 1, each byte contains 8 sample values of a single channel. In other words, a bit depth 1 frame is transmitted in a byte interleaved fashion. The first sample of each byte is represented by the most significant bit.

For gray channels at a bit depth of 1 only two sample values are possible: 1 represents minimum intensity (black) and 0 represents maximum intensity (white). For all other channel types and bit depths a sample value of 0 represents minimum intensity and larger values represent increasing intensity.

Figure 3.3: Bit and byte order of image data

3.2.2 Arbitrary data frames

It also is possible to transmit arbitrary (not necessaryly pixel oriented) data. This allows transmission of compressed images like jpeg, tiff, etc.

The type of arbitrary data frames is SANE FRAME MIME. The frame contains arbitrary data of the MIME (see RFC 1521/1522) type that is given in the format desc member of the SANE Parameters structured type (see section 4.3.8 on page 29). As such, it is assumed to be incomprehensible to the frontend, except for selected types the frontend is specifically capable of handling internally. The frontend is free to ignore those frames, or employ any appropriate means to otherwise handle this data (like saving them to disk or spawning an external viewer).

The SANE Application Programmer Interface (API)

This Section defines version 2 of the SANE application programmer interface (API). Any SANE frontend must depend on the interface defined in this section only. Converseley, any SANE backend must implement its functionality in accordance with this specification. The interface as documented here is declared as a C callable interface in a file called sane/sane-2.h. This file should normally be included via a C pre-processor directive of the form:

  #include <sane/sane-2.h>

4.1 Version Control

The SANE standard is expected to evolve over time. Whenever a change to the SANE standard is made that may render an existing frontend or backend incompatible with the new standard, the major version number must be increased. Thus, any frontend/backend pair is compatible provided the major version number of the SANE standard they implement is the same. A frontend may implement backwards compatiblity by allowing major numbers that are smaller than the expected major number (provided the frontend really can cope with the older version). In contrast, a backend always provides support for one and only one version of the standard. If a specific application does require that two different versions of the same backend are accessible at the same time, it is possible to do so by installing the two versions under different names.

SANE version control also includes a minor version number and a build revision. While control of these numbers remains with the implementor of a backend, the recommended use is as follows. The minor version is incremented with each official release of a backend. The build revision is increased with each build of a backend.

The SANE API provides the following five macros to manage version numbers.

SANE CURRENT MAJOR: The value of this macro is the number of the SANE standard that the interface implements.

SANE VERSION CODE(maj,min,bld): This macro can be used to build a monotonically increasing version code. A SANE version code consists of the SANE standard major version number (maj), the minor version number min, and the build revision of a backend (bld). The major and minor version numbers must be in the range 0… 255 and the build revision must be in the range 0… 65535. Version codes are monotonic in the sense that it is possible to apply relational operators (e.g., equality or less-than test) directly on the version code rather than individually on the three components of the version code. Note that the major version number alone determines whether a frontend/backend pair is compatible. The minor version and the build revision are used for informational and bug-fixing purposes only.

SANE VERSION MAJOR(vc): This macro returns the major version number component of the version code passed in argument vc.

SANE VERSION MINOR(vc): This macro returns the minor version number component of the version code passed in argument vc.

SANE VERSION BUILD(vc): This macro returns the build revision component of the version code passed in argument vc.

4.2 Data Types

4.2.1 Base Types

The SANE standard is based on just two SANE-specific base types: the SANE byte and word.

typedef some-scalar-type SANE Byte;
typedef some-scalar-type SANE Word;

SANE_Byte must correspond to some scalar C type that is capable of holding values in the range 0 to 255. SANE_Word must be capable of holding any of the following:

• the truth values SANE_FALSE and SANE_TRUE

• signed integers in the range −2^{31} … 2^{31} − 1

• fixed point values in the range −32768 … 32767.9999 with a resolution of 1/65536

• 32 bits (for bit sets)

Note that the SANE standard does not define what C type SANE_Byte and SANE_Word map to. For example, on some platforms, the latter may map to long int whereas on others it may map to int. A portable SANE frontend or backend must therefore not depend on a particular mapping.

4.2.2 Boolean Type

SANE Bool is used for variables that can take one of the two truth values SANE FALSE and SANE TRUE. The former value is defined to be 0, whereas the latter is 1.^{1} The C declarations for this type are given below.

     #define SANE_FALSE       0
     #define SANE_TRUE        1
     typedef SANE_Word SANE_Bool;

Note that SANE_Bool is simply an alias of SANE_Word. It is therefore always legal to use the latter type in place of the former. However, for clarity, it is recommended to use SANE_Bool whenever a given variable or formal argument has a fixed interpretation as a boolean object.

4.2.3 Integer Type

SANE Int is used for variables that can take integer values in the range −2^{32} to 2^{31} − 1. Its C declaration is given below.

     typedef SANE_Word SANE_Int;

Note that SANE_Int is simply an alias of SANE_Word. It is therefore always legal to use the latter type in place of the former. However, for clarity, it is recommended to use SANE_Int whenever a given variable or formal argument has a fixed interpretation as an integer object.

4.2.4 Fixed-point Type

SANE Fixed is used for variables that can take fixed point values in the range −32768 to 32767.9999 with a resolution of 1/65535. The C declarations relating to this type are given below.

     #define SANE_FIXED_SCALE_SHIFT  16
     typedef SANE_Word SANE_Fixed;

The macro SANE FIXED SCALE SHIFT gives the location of the fixed binary point. This standard defines that value to be 16, which yields a resolution of 1/65536.

Note that SANE_Fixed is simply an alias of SANE_Word. It is therefore always legal to use the latter type in place of the former. However, for clarity, it is recommended to use SANE_Fixed whenever a given variable or formal argument has a fixed interpretation as a fixed-point object.

For convenience, SANE also defines two macros that convert fixed-point values to and from C double floating point values.

1This is different from ANSI C where any non-zero integer value represents logical TRUE.

SANE FIX(d): Returns the largest SANE fixed-point value that is smaller than the double value d. No range checking is performed. If the value of d is out of range, the result is undefined.

SANE UNFIX(w): Returns the nearest double machine number that corresponds to fixedpoint value w.

SANE does not require that the following two expressions hold true (even if the values of w and d are in range):

     SANE_UNFIX(SANE_FIX(d)) == d
     SANE_FIX(SANE_UNFIX(w)) == w

In other words, conversion between fixed and double values may be lossy. It is therefore recommended to avoid repeated conversions between the two representations.

4.2.5 Text

Character Type

Type SANE Char represents a single text character or symbol. At present, this type maps directly to the underlying C char type (typically one byte). The encoding for such characters is currently fixed as ISO LATIN-1. Future versions of this standard may map this type to a wider type and allow multi-byte encodings to support internationalization. As a result of this, care should be taken to avoid the assumption that

sizeof(SANE_Char)==sizeof(char).
     typedef char SANE_Char;

String Type

Type SANE String represents a text string as a sequence of C char values. The end of the sequence is indicated by a '\0' (NUL) character.

     typedef SANE_Char *SANE_String;
     typedef const SANE_Char *SANE_String_Const;

The type SANE String Const is provided by SANE to enable declaring strings whose contents is unchangable. Note that in ANSI C, the declaration

     const SANE_String str;

declares a string pointer that is constant (not a string pointer that points to a constant value).

4.2.6 Scanner Handle Type

Access to a scanner is provided through an opaque type called SANE Handle. The C declaration of this type is given below.

typedef void *SANE_Handle;

While this type is declared to be a void pointer, an application must not attempt to interpret the value of a SANE_Handle. In particular, SANE does not require that a value of this type is a legal pointer value.

4.2.7 Status Type

Most SANE operations return a value of type SANE Status to indicate whether the completion status of the operation. If an operation completes successfully, SANE_STATUS_GOOD is returned. In case of an error, a value is returned that indicates the nature of the problem. The complete list of available status codes is listed in Table 4.1. It is recommended to use function sane strstatus() to convert status codes into a legible string.

Symbol  Code  Description
SANE STATUS GOOD  0 Operation completed succesfully.
SANE STATUS UNSUPPORTED  1 Operation is not supported.
SANE STATUS CANCELLED  2 Operation was cancelled.
SANE STATUS DEVICE BUSY  3 Device is busy—retry later.
SANE STATUS INVAL  4 Data or argument is invalid.
SANE STATUS EOF  5 No more data available (end-of-file).
SANE STATUS JAMMED  6 Document feeder jammed.
SANE STATUS NO DOCS  7 Document feeder out of documents.
SANE STATUS COVER OPEN  8 Scanner cover is open.
SANE STATUS IO ERROR  9 Error during device I/O.

SANE STATUS NO MEM  10 Out of memory.

SANE STATUS ACCESS DENIED  11 Access to resource has been denied.

Table 4.1: Status Codes

4.2.8 Device Descriptor Type

Each SANE device is represented by a structure of type SANE Device. The C declaration of this type is given below.

typedef struct
{
SANE_String_Const name;

  SANE_String_Const vendor;
  SANE_String_Const model;
  SANE_String_Const type;
  SANE_String_Const email_backend_author;
  SANE_String_Const backend_website;
  SANE_String_Const device_location;
  SANE_String_Const comment;
  SANE_String_Const reserved_string;
  SANE_Int backend_version_code;
  SANE_Int backend_capablity_flags;
  SANE_Int reserved_int;
}
SANE_Device;

The structure provides the unique name of the scanner in member name. It is this unique name that should be passed in a call to sane open(). The format of this name is completely up to the backend. The only constraints are that the name is unique among all devices supported by the backend and that the name is a legal SANE text string. To simplify presentation of unique names, their length should not be excessive. It is recommended that backends keep unique names below 32 characters in length. However, applications must be able to cope with arbitrary length unique names.

The next three members in the device structure provide additional information on the device corresponding to the unique name. Specifically, members vendor, model, and type are single-line strings that give information on the vendor (manufacturer), model, and the type of the device. For consistency’s sake, the following strings should be used when appropriate (the lists will be expanded as need arises):

Vendor Strings

AGFA               Microtek
Abaton             Minolta
Acer               Mustek
Apple              NEC
Artec              Nikon
Avision            Plustek
CANON              Polaroid
Connectix          Ricoh
Epson              Sharp
Fujitsu            Siemens
Hewlett-Packard    Tamarack
IBM                UMAX
Kodak              Noname

Logitech

Type Strings

                                      film scanner
                                      flatbed scanner
                                      frame grabber
                                      handheld scanner
                                      multi-function peripheral
                                      sheetfed scanner
                                      still camera
                                      video camera
                                      virtual device

Table 4.2: Predefined Device Information Strings

Note that vendor string Noname can be used for virtual devices that have no physical vendor associated. Also, there are no predefined model name strings since those are vendor specific and therefore completely under control of the respective backends.

The backend has to set up the string email backend author with the name and the email address of the backend author or a contact person in the format:

Firstname Lastname <name@domain.org>

The string backend website should be set up by the backend with the website or ftp address of the backend in the format:

http://www.domain.org/sane-hello/index.html

The backend should fill the string device location with a text that describes where a user can find this device. The text should be configurable by the administrator. This could e.g. look like this:

building 93, 2nd plane, room 2124

The string comment can be used to display any comment about the device to the user. The text should be configurable by the administrator.

The string reserved string is unused currently but planned for future use.

All unused strings must be set to “” by the backend.

With member backend version code a frontend can find out the version of a backend it is connected to via one or more meta backends.

The member backend capability flags contains 32 bits that are planned to give the backend the chance to inform the frontend about its capabilities. The meaning of the flags will be defined when there is the need for it. The backend has to set all not defined bits (in the moment all 32 bits) to 0.

The member reserved int is planned for future use, the backend has to set the value of the integer to 0.

4.2.9 Option Descriptor Type

Option descriptors are at the same time the most intricate and powerful type in the SANE standard. Options are used to control virtually all aspects of device operation. Much of the power of the SANE API stems from the fact that most device controls are completely described by their respective option descriptor. Thus, a frontend can control a scanner abstractly, without requiring knowledge as to what the purpose of any given option is. Conversely, a scanner can describe its controls without requiring knowledge of how the frontend operates. The C declaration of the SANE Option Descriptor type is given below.

     typedef struct
       {
         SANE_String_Const name;
         SANE_String_Const title;
         SANE_String_Const desc;

         SANE_Value_Type type;
         SANE_Unit unit;
         SANE_Int size;
         SANE_Int cap;
         SANE_Constraint_Type constraint_type;
         union
            {
              const SANE_String_Const *string_list;
              const SANE_Word *word_list;
              const SANE_Range *range;
            }
         constraint;
       }
     SANE_Option_Descriptor;

Option Name

Member name is a string that uniquely identifies the option. The name must be unique for a given device (i.e., the option names across different backends or devices need not be unique). The option name must consist of lower-case ASCII letters (a–z), digits (0–9), or the dash character (-) only. The first character must be a lower-case ASCII character (i.e., not a digit or a dash).

Option Title

Member title is a single-line string that can be used by the frontend as a title string. This should typically be a short (one or two-word) string that is chosen based on the function of the option.

Option Description

Member desc is a (potentially very) long string that can be used as a help text to describe the option. It is the responsibility of the frontend to break the string into managable-length lines. Newline characters in this string should be interpreted as paragraph breaks.

Option Value Type

Member type specifies the type of the option value. The possible values for type SANE Value Type are described in Table 4.3.

Option Value Unit

Member unit specifies what the physical unit of the option value is. The possible values for type SANE Unit are described in Table 4.4. Note that the specified unit is what the SANE backend expects. It is entirely

Symbol  Code  Description

SANE TYPE BOOL  0  Option value is of type SANE_Bool.

SANE TYPE INT  1  Option value is of type SANE_Int.

SANE TYPE FIXED  2  Option value is of type SANE_Fixed.
SANE TYPE STRING  3  Option value is of type SANE_String.

SANE TYPE BUTTON  4  An option of this type has no value. Instead, setting an option

of this type has an option-specific side-effect. For example, a button-typed option could be used by a backend to provide a means to select default values or to the tell an automatic document feeder to advance to the next sheet of paper.

SANE TYPE GROUP 5 An option of this type has no value. This type is used to group logically related options. A group option is in effect up to the point where another group option is encountered (or up to the end of the option list, if there are no other group options). For group options, only members title and type are valid in the option descriptor.

Table 4.3: Option Value Types (SANE Value Type)

up to a frontend as to how these units a presented to the user. For example, SANE expresses all lengths in millimeters. A frontend is generally expected to provide appropriate conversion routines so that a user can express quantities in a customary unit (e.g., inches or centimeters).

Symbol  Code  Description
SANE UNIT NONE  0  Value is unit-less (e.g., page count).
SANE UNIT PIXEL  1  Value is in number of pixels.
SANE UNIT BIT  2  Value is in number of bits.
SANE UNIT MM  3  Value is in millimeters.
SANE UNIT DPI  4  Value is a resolution in dots/inch.
SANE UNIT PERCENT  5  Value is a percentage.
SANE UNIT MICROSECOND  6  Value is time in μ-seconds.

Table 4.4: Physical Units (SANE Unit)

Option Value Size

Member size specifies the size of the option value (in bytes). This member has a slightly different interpretation depending on the type of the option value:

SANE TYPE STRING: The size is the maximum size of the string. For the purpose of string size calcuations, the terminating NUL character is considered to be part of the string. Note that the terminating NUL character must always be present in string option values.

SANE TYPE INT, SANE TYPE FIXED: The size must be a positive integer multiple of the size of a SANE_Word. The option value is a vector of length

                                size/sizeof(SANE Word).
     SANE TYPE BOOL: The size must be set to sizeof(SANE Word).
     SANE TYPE BUTTON, SANE TYPE GROUP:  The option size is ignored.

Option Capabilities

Member cap describes what capabilities the option posseses. This is a bitset that is formed as the inclusive logical OR of the capabilities described in Table 4.5. The SANE API provides the following to macros to test certain features of a given capability bitset:

SANE OPTION IS ACTIVE(cap): This macro returns SANE TRUE if and only if the option

with the capability set cap is currently active. SANE OPTION IS SETTABLE(cap): This macro returns SANE TRUE if and only if the op-

tion with the capability set cap is software settable.

Option Value Constraints

It is often useful to constrain the values that an option can take. For example, constraints can be used by a frontend to determine how to represent a given option. Member constraint type indicates what constraint is in effect for the option. The constrained values that are allowed for the option are described by one of the union members of member constraint. The possible values of type SANE Constraint Type and the interpretation of the constraint union is described in Table 4.6.

4.2.10 Internationalization

All backend texts should be written in english. Localization (translation of backend texts) has to be done in the frontend. To automatically prepare translation tables (e.g. english to german) it is necessary to mark the texts that shall be translated.

How is a text marked for translation

The keyword SANE I18N is used to mark a text for translation. SANE I18N has to be defined as a dummy prototype:

     #ifndef SANE_I18N
     #  define SANE_I18N(text) text
     #endif

Symbol  Code  Description

SANE CAP SOFT SELECT  1 The option value can be set by a call to sane control opt-
ion().

SANE CAP HARD SELECT 2 The option value can be set by user-intervention (e.g., by flipping a switch). The user-interface should prompt the user to execute the appropriate action to set such an option. This capability is mutually exclusive with SANE CAP SOFT SELECT (either one of them can be set, but not both simultaneously).

SANE CAP SOFT DETECT 4 The option value can be detected by software. If SANE - CAP SOFT SELECT is set, this capability must be set. If SANE CAP HARD SELECT is set, this capability may or may not be set. If this capability is set but neither SANE CAP SO-

FT SELECT nor SANE CAP HARD SELECT are, then there is

no way to control the option. That is, the option provides readout of the current value only.

SANE CAP EMULATED 8 If set, this capability indicates that an option is not directly supported by the device and is instead emulated in the backend. A sophisticated frontend may elect to use its own (presumably better) emulation in lieu of an emulated option.

SANE CAP AUTOMATIC 16 If set, this capability indicates that the backend (or the device) is capable to picking a reasonable option value automatically. For such options, it is possible to select automatic operation by calling sane control option() with an action value of

SANE ACTION SET AUTO.

SANE CAP INACTIVE 32 If set, this capability indicates that the option is not currently active (e.g., because it’s meaningful only if another option is set to some other value).

SANE CAP ADVANCED 64 If set, this capability indicates that the option should be considered an “advanced user option”. If this capability is set for an option of type SANE TYPE GROUP, all options belonging to the group are also advanced, even if they don’t set the capabilty themselves. A frontend typically displays such options in a less conspicuous way than regular options (e.g., a command line interface may list such options last or a graphical interface may make them available in a seperate “advanced settings” dialog).

SANE CAP HIDDEN  128

If set, this capability indicates that the option shouldn’t be displayed to and used by the user directly. Instead a hidden option is supposed to be automatically used by the frontend, like e.g. the “preview” option. If this capability is set for an option of type SANE TYPE GROUP, all options belonging to the group are also hidden, even if they don’t set the capabilty themselves. A frontend typically doesn’t display such options by default but there should be a way to override this default behaviour.

SANE CAP ALWAYS SETTABLE  256

If set, this capability indicates that the option may be at any time between sane open() and sane close(). I.e. it’s allowed to set it even while an image is acquired.

Table 4.5: Option Capabilities 23

Symbol  Code  Description

SANE CONSTRAINT NONE 0 The value is unconstrained. The option can take any

of the values possible for the option’s type.

SANE CONSTRAINT RANGE 1 This constraint is applicable to integer and fixed-point valued options only. It constrains the option value to a possibly quantized range of numbers. Option descriptor member constraint.range points to a range of the type SANE Range. This type is illustrated below:

     typedef struct
       {
         SANE_Word min;
         SANE_Word max;
         SANE_Word quant;
       }
     SANE_Range;

All three members in this structure are interpreted according to the option value type (SANE_TYPE_INT

or SANE_TYPE_FIXED). Members min and max

specify the minimum and maximum values, respectively. If member quant is non-zero, it specifies the quantization value. If l is the minimum value, u the maximum value and q the (non-zero) quantization of a range, then the legal values are v = k · q + l for all non-negative integer values of k such that v <= u.

SANE CONSTRAINT WORD LIST 2 This constraint is applicable to integer and fixed-point valued options only. It constrains the option value to a list of numeric values. Option descriptor member constraint.word list points to a list of words that enumerates the legal values. The first element in that list is an integer (SANE_Int) that specifies the length of the list (not counting the length itself). The remaining elements in the list are interpreted according to the type of the option value (SANE_TYPE_INT

or SANE_TYPE_FIXED).

SANE CONSTRAINT STRING LIST 3 This constraint is applicable to string-valued options only. It constrains the option value to a list of strings. The option descriptor member constraint.string list points to a NULL terminated list of strings that enumerate the legal values for the option value.

Table 4.6: Option Value Constraints You should not mark prototypes or variables with SANE I18N because it is not possible (or very hard) to find out the texts that are covered by prototypes (SANE_I18N(START_SCAN_TEXT)) and variables

(SANE_I18N(option[7].name)).

A correct marked text can look like this:

snprintf(buf, sizeof(buf), SANE_I18N("Start scan")

or

#define START_SCAN_TEXT SANE_I18N("Start scan").

It also is allowed to mark texts in structs because the prototype SANE I18N has no effect to the compiler.

Which texts shall be marked for translation?

All option texts that are visible for the user should be marked for translation. This is:

• member title

• member desc

   • member string list
of SANE Option Descriptor.

It is not allowed to mark/translate member name. Please also do not mark any error or debug messages that are displayed by the backend.

File formats and translation functions

The recommended file formats for translation tables are the po files and mo or gmo files. The po file contains the original text marked with the keyword msgid and the translated text marked with the keyword msgstr. A po file that contains all needed msgids can be created e.g. by the gnu gettext tool xgettext with the option -k SANE_I18N. The translator adds the translated texts to the po files. The gettext tool msgfmt converts the po files to the mo or gmo files.

Translation is done in the frontend. A backend has nothing to do with the translation of texts. The frontend should use the function gettext to translate the texts. This e.g. can look like this:

snprintf(buf, sizeof(buf), gettext("english text"));

If a frontend author decides to use translation functions that need different translation tables, then the frontend is responsible to create/convert the translation tables. In this case it should use the po files to create its own translation tables from it.

Note that it is strongly recommended to use the gettext tools.

4.3 Operations

4.3.1 sane init

This function must be called before any other SANE function can be called. The behavior of a SANE backend is undefined if this function is not called first or if the status code returned by sane init is different from SANE STATUS GOOD. The version code of the backend is returned in the value pointed to by version code. If that pointer is NULL, no version code is returned. Argument authorize is either a pointer to a function that is invoked when the backend requires authentication for a specific resource or NULL if the frontend does not support authentication.

     SANE_Status sane_init (SANE_Int * version_code,
                               SANE_Authorization_Callback authorize);

The authorization function may be called by a backend in response to any of the following calls:

     sane open, sane control option, sane start

If a backend was initialized without authorization function, then authorization requests that cannot be handled by the backend itself will fail automatically and the user may be prevented from accessing protected resources. Backends are encouraged to implement means of authentication that do not require user assistance. E.g., on a multi-user system that authenticates users through a login process a backend could automatically lookup the apporpriate password based on resource- and user-name.

The authentication function type has the following declaration:

     #define SANE_MAX_USERNAME_LEN   128
     #define SANE_MAX_PASSWORD_LEN   128
     typedef void (*SANE_Authorization_Callback)
         (SANE_String_Const resource,
          SANE_Char username[SANE_MAX_USERNAME_LEN],
          SANE_Char password[SANE_MAX_PASSWORD_LEN]);

Three arguments are passed to the authorization function: resource is a string specifying the name of the resource that requires authorization. A frontend should use this string to build a user-prompt requesting a username and a password. The username and password arguments are (pointers to) an array of SANE MAX USERNAME LEN and SANE MAX PASSWORD LEN characters, respectively. The authorization call should place the entered username and password in these arrays. The returned strings must be ASCII-NUL terminated.

4.3.2 sane exit

This function must be called to terminate use of a backend. The function will first close all device handles that still might be open (it is recommended to close device handles explicitly through a call to sane close(), but backends are required to release all resources upon a call to this function). After this function returns, no function other than sane init() may be called (regardless of the status value returned by sane exit(). Neglecting to call this function may result in some resources not being released properly.

     void sane_exit (void);

4.3.3 sane get devices

This function can be used to query the list of devices that are available. If the function executes successfully, it stores a pointer to a NULL terminated array of pointers to SANE_Device structures in *device list. The returned list is guaranteed to remain unchanged and valid until (a) another call to this function is performed or (b) a call to sane exit() is performed. This function can be called repeatedly to detect when new devices become available. If argument local only is true, only local devices are returned (devices directly attached to the machine that SANE is running on). If it is false, the device list includes all remote devices that are accessible to the SANE library.

     SANE_Status sane_get_devices (const SANE_Device *** device_list,
                                       SANE_Bool local_only);

This function may fail with SANE STATUS NO MEM if an insufficient amount of memory is available.

Backend Implementation Note

SANE does not require that this function is called before a sane open() call is performed. A device name may be specified explicitly by a user which would make it unnecessary and undesirable to call this function first. The same information about a device has to be returned when sane open is called.

4.3.4 sane open

This function is used to establish a connection to a particular device. The name of the device to be opened is passed in argument name. If the call completes successfully, a handle for the device is returned in *h. The description of the device is returned in **device description. This is the same description that is returned in the list by sane get devices. The returned data *h and *device description is guaranteed to remain unchanged and valid until a call to sane close() is performed. As a special case, specifying a zero-length string as the device requests opening the first available device (if there is such a device).

     SANE_Status sane_open (SANE_String_Const name, SANE_Handle * h,
     const SANE_Device ** device_description);

This function may fail with one of the following status codes.

SANE STATUS DEVICE BUSY: The device is currently busy (in use by somebody else).

SANE STATUS INVAL: The device name is not valid.

SANE STATUS IO ERROR: An error occured while communicating with the device.

SANE STATUS NO MEM: An insufficent amount of memory is available.

SANE STATUS ACCESS DENIED: Access to the device has been denied due to insufficient or invalid authentication.

4.3.5 sane close

This function terminates the association between the device handle passed in argument h and the device it represents. If the device is presently active, a call to sane cancel() is performed first. After this function returns, handle h must not be used anymore.

     void sane_close (SANE_Handle h);

4.3.6 sane get option descriptor

This function is used to access option descriptors. The function returns the option descriptor for option number n of the device represented by handle h. Option number 0 is guaranteed to be a valid option. Its value is an integer that specifies the number of options that are available for device handle h (the count includes option 0). If n is not a valid option index, the function returns NULL. The returned option descriptor is guaranteed to remain valid (and at the returned address) until the device is closed.

     const SANE_Option_Descriptor *
         sane_get_option_descriptor (SANE_Handle h, SANE_Int n);

4.3.7 sane control option

This function is used to set or inquire the current value of option number n of the device represented by handle h. The manner in which the option is controlled is specified by parameter a. The possible values of this parameter are described in more detail below. The value of the option is passed through argument v. It is a pointer to the memory that holds the option value. The memory area pointed to by v must be big enough to hold the entire option value (determined by member size in the corresponding option descriptor). The only exception to this rule is that when setting the value of a string option, the string pointed to by argument v may be shorter since the backend will stop reading the option value upon encountering the first NUL terminator in the string. If argument i is not NULL, the value of *i will be set to provide details on how well the request has been met. The meaning of this argument is described in more detail below.

     SANE_Status sane_control_option (SANE_Handle h, SANE_Int n,
                                          SANE_Action a, void *v,
                                          SANE_Int * i);

The way the option is affected by a call to this function is controlled by parameter a which is a value of type SANE Action. The possible values and their meaning is described in Table 4.7.

Symbol  Code  Description

SANE ACTION GET VALUE 0 Get current option value.

SANE ACTION SET VALUE 1 Set option value. The option value passed through argument v may be modified by the backend if the value cannot be set exactly.

SANE ACTION SET AUTO 2 Turn on automatic mode. Backend or device will automatically select an appropriate value. This mode remains effective until overridden by an explicit set value request. The value of parameter v is completely ignored in this case and may be NULL.

Table 4.7: Action Values (SANE Action)

After setting a value via an action value of SANE_ACTION_SET_VALUE, additional information on how well the request has been met is returned in *i (if i is non-NULL). The returned value is a bitset that may contain any combination of the values described in Table 4.8.

This function may fail with one of the following status codes.

SANE STATUS UNSUPPORTED: The operation is not supported for the specified handle and option number.

SANE STATUS INVAL: The option value is not valid.

SANE STATUS IO ERROR: An error occured while communicating with the device.

SANE STATUS NO MEM: An insufficent amount of memory is available.

SANE STATUS ACCESS DENIED: Access to the option has been denied due to insufficient or invalid authentication.

4.3.8 sane get parameters

This function is used to obtain the current scan parameters. The returned parameters are guaranteed to be accurate between the time a scan has been started (sane start() has been called) and the completion of that request. Outside of that window, the returned values are best-effort estimates of what the parameters will be when sane start() gets invoked. Calling this function before a scan has actually started allows, for example, to get an estimate of how big the scanned image will be. The parameters passed to this function are the handle h of the device for which the parameters should be obtained and a pointer p to a parameter structure. The parameter structure is described in more detail below.

Symbol  Code  Description

SANE INFO INEXACT 1 This value is returned when setting an option value resulted in a value being selected that does not exactly match the requested value. For example, if a scanner can adjust the resolution in increments of 30dpi only, setting the resolution to 307dpi may result in an actual setting of 300dpi. When this happens, the bitset returned in *i has this member set. In addition, the option value is modified to reflect the actual (rounded) value that was used by the backend. Note that inexact values are admissible for strings as well. A backend may choose to “round” a string to the closest matching legal string for a constrained string value.

SANE INFO RELOAD OPTIONS 2 The setting of an option may affect the value, the availability, or the constraint of one or more other options. When this happens, the SANE backend sets this member in *i to indicate that the application should reload all options. This member may be set if and only if at least one option changed.

SANE INFO RELOAD PARAMS 4 The setting of an option may affect the parameter values (see sane get parameters()). If setting an option affects the parameter values, this member will be set in *i. Note that this member may be set even if the parameters did not actually change. However, it is guaranteed that the parameters never change without this member being set.

SANE INFO INVALIDATE PREVIEW 8 The setting of an option may affect the validity of the preview that was acquired by the frontend earlier. When the preview image would change significantly if it was scanned again, the SANE backend sets this member in *i to indicate that the application should inform the user of the invalidity of the preview. Examples for such option settings may include setting a different scan source or significantly changing the exposure.

Table 4.8: Additional Information Returned When Setting an Option

SANE_Status sane_get_parameters (SANE_Handle h,
                                 SANE_Parameters * p);

The scan parameters are returned in a structure of type SANE Parameters. The C declaration of this structure is given below.

typedef struct
{
SANE_Frame format;
SANE_Int flags;
SANE_Int lines;
SANE_Int depth;
SANE_Int pixels_per_line;
SANE_Int bytes_per_line;
SANE_Int channels_per_image;
SANE_String format_desc;
SANE_String proposed_filename;
SANE_String proposed_comment;
SANE_Int dpi_x;
SANE_Int dpi_y;
char reserved[32]; /* 32 bytes for future use */
}
SANE_Parameters;

Member format specifies the format of the next frame to be returned. The possible values for type SANE Frame are described in Table 4.9. The meaning of these values is described in more detail in section 3.2. The frame types used by version 1 of this standard (SANE FRAME GRAY, SANE FRAME RGB,

SANE FRAME RED, SANE FRAME GREEN, and SANE FRAME BLUE) are obsolete and superseded by the
frame type SANE FRAME RAW.

Symbol  Code  Description
SANE FRAME RAW  5 Arbitrary pixel property transmission.
SANE FRAME MIME  6 Data described by a mime descriptor.

Table 4.9: Frame Format (SANE Frame)

The flags member is a 32 bit bitfield, for which up to now 4 informational bits are defined, all unused bits have to be set to 0:

• SANE PFLAG LAST FRAME (bit 0, bitvalue 1) is set to 1 if and only if the frame that is currently being acquired (or the frame that will be acquired next if there is no current frame) is the only frame or the last frame of a multi frame image (e.g., the current frame is the blue component of a red, green, blue image).

• SANE PFLAG MORE IMAGES (bit 1, bitvalue 2) is set to 1 to indicate further pending images. The frontend is expected to call sane start again after the end of the current scan to get more images, e.g. from an automatic document feeder. It is permissible to set that value to 1 “in good faith”, as it has to be determined at a very early time, where it might not be detectable, if there actually are more images to transfer. E.g. you will usually not know if the document feeder contains further pages when starting to scan the current one. Thus you are allowed to set that bit but later fail at sane start().

• SANE PFLAG NEW PAGE (bit 2, bitvalue 4) is set to 1 to indicate that the current frame comes from a new physical page. This bit is of informational character only to help frontends to group multi-image scans.

• SANE PFLAG BACKSIDE (bit 3, bitvalue 8) tells if the current image was acquired from the front (0) or backside (1) of the currently processed sheet. It is of informational character and allows to group and order multi-image transfers regardless of scanner acquisition order (front first/back first).

Note, that flags is compatible to member last frame of SANE Parameters of SANE standard version 1 (same size and only bit 0 (bitvalue 1) was used with same function).

Member lines specifies how many scan lines the frame is comprised of. If this value is -1, the number of lines is not known a priori and the frontend should call sane read() until it returns a status of SANE STATUS EOF. Note, that even when transferring formats that have this information inband, it is recommended to set that member, if available. If unavailable or not applicable, set to -1 as mentioned above.

Member bytes per line specifies the number of bytes that comprise one scan line. If this value is not applicable for image data of type SANE FRAME MIME, it must be set to -1. In this case the frontend should just call sane read until SANE STATUS EOF is returned.

Member depth specifies the number of bits per sample. Note, that only -1 (for not applicable), 1, and multiples of 8 are allowed values. Data with other depths has to be scaled up accordingly. Depth 1 is only allowed if the image consists of a single channel (lineart or halftone modes).

Member pixels per line specifies the number of pixels that comprise one scan line. If unavailable or not applicable, set to -1.

Assume B is the number of channels in the frame, then the bit depth d (as given by member depth) and the number of pixels per line n (as given by this member pixels per line) are related to c, the number of bytes per line (as given by member bytes per line) as follows:

c >= \{ \begin{matrix}⌈B · n/8⌉ & if d = 1 \\ B · n · d/8 & if d > 1 \end{matrix}

Note that the number of bytes per line can be larger than the minimum value imposed by the right side of this equation. A frontend must be able to properly cope with such “padded” image formats.

Member channels per image specifies the number of channels the image consists of. When the image is transmitted in more than one frame channels per image has to be the same for all frames for this image.

Member format desc is used to describe the details of the frame formats. Its meaning differs between the two formats:

• SANE FRAME RAW: The format desc contains a description of the channel data and an optional depth information separated by a colon(:).

A plane is descibed by one channel, e.g. “gray” or “gray:12”.

Channel interleaved data is described by a comma separated list of channel descriptions, for example “red,green,blue” or “red:8,green:8,blue:8”, the channel data is sent in the given order.

The depth information does not define the size of the transmitted channel data, it is only an information for the frontend. The channel data has to be sent in the size defined by member depth.

Well known channels are red, green, blue and gray. It also is allowed to use other channel descriptions, e.g. if you use an infrared camera or scanner it could be infrared or a wavelength description like 1100nm, but be aware that a frontend may not be able to display such channels with useful colors.

Note that an image can be sent in single planes, in one interleaved frame that contains all channels or in several frames that contain one or more (interleaved) channels. When an RGB image is sent it is prefered to send the image data in one interleaved frame that consist of red, green and blue data in this order. The number of channels is defined in member channels per image.

• SANE FRAME MIME:

format desc contains the MIME Content-Type: header field as described in RFC 1521 (section 4) without the prefixing ”Content-Type:”. MIME Types and subtypes should be either chosen from the RFC or from the list of IANA-approved values. The data stream must be compliant with the corresponding specification.

When data is transmitted with the frame type SANE FRAME MIME all data has to be transmitted within one frame, multiple frames are not allowed (so the flag last frame has to be set when using this frame type).

A SANE backend must be able to at least optionally transmit SANE FRAME RAW (possibly with the help of a meta backend), if the hardware supports delivering image data at all. For data that doesn’t comprise images, it’s admisable to only provide MIME frames. As a general principle, if there are several choices in MIME types, the format that is most widely implemented should be used.

The member proposed filename can be used to suggest a reasonable default filename or -extension in case the backend can make such a suggestion, like e.g. an image database. If no such suggestion is intended, set the field to “”.

In the case of raw frames, proposed filename is expected to hold the basename for the image, with the extension determined by the save function of the frontend, as the frontend can fully understand the data and is thus able to encode it in any format it wishes.

For MIME frames proposed filename can contain either:

• A name with a leading dot, which is considered to be a proposed filename extension. This could also be gotten from the mime database, but for systems lacking it, this might be convenient. Or:

• A complete filename, including extension.

Note, that for frontends that are able to parse a given MIME type internally, it is perfectly permissible to ignore the extension part of the proposed filename and only make use of the basename, when using internal save algorithms for different formats.

The string proposed comment can be used to transmit additional image information, that can be stored in the comment areas several file formats offer. It can contain any textual information the backend wishes to convey to the user, like date/time of exposure, enganged filters, etc. Set to “” if unused.

The members dpi x and dpi y encode the horizontal and vertical resolution. Note, that multiple-image scans may have different resolutions of each image. It is not permissible to change resolution between frames of the same image. If not applicable, set to -1.

The member reserved is an array of 32 bytes (char) to keep the size of the struct unchanged when future extensions are done. The backend has to set the reserved bytes to 0.

4.3.9 sane start

This function initiates aquisition of an image from the device represented by handle h.

     SANE_Status sane_start (SANE_Handle h);

This function may fail with one of the following status codes.

SANE STATUS CANCELLED: The operation was cancelled through a call to sane cancel. SANE STATUS DEVICE BUSY: The device is busy. The operation should be retried later. SANE STATUS JAMMED: The document feeder is jammed. SANE STATUS NO DOCS: The document feeder is out of documents. SANE STATUS COVER OPEN: The scanner cover is open. SANE STATUS IO ERROR: An error occurred while communicating with the device. SANE STATUS NO MEM: An insufficent amount of memory is available. SANE STATUS INVAL: The scan cannot be started with the current set of options. The frontend should reload the option descriptors, as if SANE INFO RELOAD OPTIONS had been returned from a call to sane control option(), since the device’s capabilities may have changed.

4.3.10 sane read

This function is used to read image data from the device represented by handle h. Argument buf is a pointer to a memory area that is at least maxlen bytes long. The number of bytes returned is stored in *len. A backend must set this to zero when a status other than SANE STATUS GOOD is returned). When the call succeeds, the number of bytes returned can be anywhere in the range from 0 to maxlen bytes.

     SANE_Status sane_read (SANE_Handle h, SANE_Byte * buf,
                               SANE_Int maxlen, SANE_Int * len);

For efficiency reasons, medium to large block sizes (in the range of a few kilobytes) should be used. Returning short reads is allowed to allow for small buffers in the backend. If this function is called when no data is available, one of two things may happen, depending on the I/O mode that is in effect for handle h.

1. If the device is in blocking I/O mode (the default mode), the call blocks until at least one data byte is available (or until some error occurs).

2. If the device is in non-blocking I/O mode, the call returns immediately with status SANE STA-TUS GOOD and with *len set to zero.

The I/O mode of handle h can be set via a call to sane set io mode().

This function may fail with one of the following status codes.

SANE STATUS CANCELLED: The operation was cancelled through a call to sane cancel.

SANE STATUS EOF: No more data is available for the current frame. If sane read sends back any image data it is not allowed to return with SANE STATUS EOF.

SANE STATUS JAMMED: The document feeder is jammed.

SANE STATUS NO DOCS: The document feeder is out of documents.

SANE STATUS COVER OPEN: The scanner cover is open.

SANE STATUS IO ERROR: An error occurred while communicating with the device.

SANE STATUS NO MEM: An insufficent amount of memory is available.

SANE STATUS ACCESS DENIED: Access to the device has been denied due to insufficient or invalid authentication.

4.3.11 sane cancel

This function is used to immediately or as quickly as possible cancel the currently pending operation of the device represented by handle h.

     void sane_cancel (SANE_Handle h);

This function can be called at any time (as long as handle h is a valid handle) but usually affects longrunning operations only (such as image is acquisition). It is safe to call this function asynchronously (e.g., from within a signal handler). It is important to note that completion of this operaton does not imply that the currently pending operation has been cancelled. It only guarantees that cancellation has been initiated. Cancellation completes only when the cancelled call returns (typically with a status value of SANE STATUS CANCELLED). Since the SANE API does not require any other operations to be re-entrant, this implies that a frontend must not call any other operation until the cancelled operation has returned.

4.3.12 sane set io mode

This function is used to set the I/O mode of handle h. The I/O mode can be either blocking or non-blocking. If argument m is SANE TRUE, the mode is set to non-blocking mode, otherwise it’s set to blocking mode. This function can be called only after a call to sane start() has been performed.

     SANE_Status sane_set_io_mode (SANE_Handle h, SANE_Bool m);

By default, newly opened handles operate in blocking mode. A backend may elect not to support nonblocking I/O mode. In such a case the status value SANE STATUS UNSUPPORTED is returned. Blocking I/O must be supported by all backends, so calling this function with argument m set to SANE FALSE is guaranteed to complete successfully.

This function may fail with one of the following status codes:

SANE STATUS INVAL: No image acquisition is pending.

SANE STATUS UNSUPPORTED: The backend does not support the requested I/O mode.

4.3.13 sane get select fd

This function is used to obtain a (platform-specific) file-descriptor for handle h that is readable if and only if image data is available (i.e., when a call to sane read() will return at least one byte of data). If the call completes successfully, the select file-descriptor is returned in *fd.

     SANE_Status sane_get_select_fd (SANE_Handle h, SANE_Int *fd);

This function can be called only after a call to sane start() has been performed and the returned file-descriptor is guaranteed to remain valid for the duration of the current image acquisition (i.e., until sane cancel() or sane start() get called again or until sane read() returns with status SANE STATUS EOF). Indeed, a backend must guarantee to close the returned select file descriptor at the point when the next sane read() call would return SANE STATUS EOF. This is necessary to ensure the application can detect when this condition occurs without actually having to call sane read().

A backend may elect not to support this operation. In such a case, the function returns with status code

SANE STATUS UNSUPPORTED.

Note that the only operation supported by the returned file-descriptor is a host operating-system dependent test whether the file-descriptor is readable (e.g., this test can be implemented using select() or poll() under UNIX). If any other operation is performed on the file descriptor, the behavior of the backend becomes unpredictable. Once the file-descriptor signals “readable” status, it will remain in that state until a call to sane read() is performed. Since many input devices are very slow, support for this operation is strongly encouraged as it permits an application to do other work while image acquisition is in progress.

This function may fail with one of the following status codes:

SANE STATUS INVAL: No image acquisition is pending.

SANE STATUS UNSUPPORTED: The backend does not support this operation.

4.3.14 sane strstatus

This function can be used to translate a SANE status code into a printable string. The returned string is a single line of text that forms a complete sentence, but without the trailing period (full-stop). The function is guaranteed to never return NULL. The returned pointer is valid at least until the next call to this function is performed.

     SANE_String_Const sane_strstatus (SANE_Status status);

4.4 Code Flow

The code flow for the SANE API is illustrated in Figure 4.1. Functions sane init() and sane exit() initialize and exit the backend, respectively. All other calls must be performed after initialization and before exiting the backend.

Figure 4.1: Code flow

Function sane get devices() can be called any time after sane init() has been called. It returns the list of the devices that are known at the time of the call. This list may change over time since some devices may be turned on or off or a remote host may boot or shutdown between different calls. It should be noted that this operation may be relatively slow since it requires contacting all configured devices (some of which may be on remote hosts). A frontend may therefore want to provide the ability for a user to directly select a desired device without requiring a call to this function.

Once a device has been chosen, it is opened using a call to sane open(). Multiple devices can be open at any given time. A SANE backend must not impose artificial constraints on how many devices can be open at any given time.

An opened device can be setup through the corresponding device handle using functions sane get option descriptor() and sane control option(). While setting up a device, obtaining option descriptors and setting and reading of option values can be mixed freely. It is typical for a frontend to read out all available options at the beginning and then build a dialog (either graphical or a command-line oriented option list) that allows to control the available options. It should be noted that the number of options is fixed for a given handle. However, as options are set, other options may become active or inactive or their constraint may change. Thus, after setting an option, it may be necessary to re-read the descriptors. While setting up the device, it is also admissible to call sane get parameters() to get an estimate of what the image parameters will look like once image acquisition begins.

The device handle can be put in blocking or non-blocking mode by a call to sane set io mode(). Devices are required to support blocking mode (which is the default mode), but support for non-blocking I/O is strongly encouraged for operating systems such as UNIX.

After the device is setup properly, image acquisition can be started by a call to sane start(). The backend calculates the exact image parameters at this point. So future calls to sane get parameters() will return the exact values, rather than estimates. Whether the physical image acquisition starts at this point or during the first call to sane read() is unspecified by the SANE API. If non-blocking I/O and/or a select-style interface is desired, the frontend may attempt to call sane set io mode() and/or sane get select fd() at this point. Either of these functions may fail if the backend does not support the requested operation.

Image data is collected by repeatedly calling sane read() until this function will return an end-of-file status (SANE STATUS EOF). This indicates the end of the current frame. If the frontend expects additional frames (e.g., the individual channels of a red/green/blue image or multiple images), it can call sane start() again. If the SANE PFLAG LAST FRAME bit is set in flags, the current image is complete. In this case, it should be tested, if flags has the SANE PFLAG MORE IMAGES bit set. If yes, further calls to sane start() can be made to acquire more images. Please note, that as this bit has to be set at the beginning of a the transmission of the last frame before the new image, it is possible, that no reliable decision can be made at this time. It is thus permissible for a backend to set this bit, and then later at the actual call to sane start() return an error like SANE STATUS NO DOCS. Such a sequence is permitted to transmit multiple images from a single page as well as multiple pages. This behaviour should be controlled by backend options as required, to allow single-page scanning as well as ADF-batch-scanning. The frontend should always continue reading all images until a frame with SANE PFLAG LAST FRAME on and SANE PFLAG MORE IMAGES off is encountered, or an error other than SANE STATUS EOF occurs in a SANE function. Note that SANE STATUS NO DOCS also is an allowed way for the backend to indicate the end of a multiple image scan.

A frontend may choose to skip frames (e.g. because it cannot parse them), which is accomplished by simply calling sane start again, which will get you to the next frame, without having to read and discard the current one.

In order to prematurely stop scanning and to reset the backend state, sane cancel() can be called at any time. This call is required as well after normal termination of a multiple image scan as described above.

When done using the device, the handle should be closed by a call to sane close(). Finally, before exiting the application, function sane exit() must be called. It is important not to forget to call this function since otherwise some resources (e.g., temporary files or locks) may remain unclaimed.

The following C sample code implements a reference loop for acquiring multiple images:

SANE_Parameters parms;
SANE_Status      status;
do
  {
     do
       {
         /* Now start acquiring the next frame. */
         status = sane_start (handle);
         /* if that failed, we have a problem, and no more frames can be
          * read at this time. Due to SANE_PFLAG_MORE_IMAGES still
          * being clear, this will break out of _BOTH_loops.
          */
         if (status != SANE_STATUS_GOOD)
           break;
         /* Now let us see what the next frame brings. */
         status = sane_get_parameters (handle, &parms);
         /* This actually should not fail, but maybe the doc feeder
          * jammed or something, so we break as well, if something
          * is wrong.
          */
         if (status != SANE_STATUS_GOOD)
           break;
         /* Now we check the announced parameters, if we can make use
          * of the frame data. If not, we skip over to the next frame.
          */
         if (do_i_like_that (&parms) == NO)
           continue;
         /* Set up for reading the data here. Mangle filenames,

* allocate memory, rewind multiframe files, ask user
* for confirmation, ...
*/
setup_for_transfer (...);
/* Now we read in the frame data and process it. This should
* return SANE_STATUS_GOOD, until the frame is complete,
* what causes SANE_STATUS_EOF to be returned.
*/
while (SANE_STATUS_GOOD == (status = sane_read (...)))
 read_in_and_process_data_as_required ();
/* If transfer was broken due to anything but EOF, break out. */
if (status != SANE_STATUS_EOF)
 break;
/* Now loop until we have all frames of an image. */
}
while (!(parms.flag & SANE_PFLAG_LAST_FRAME));
/* O.K. - we now have a complete image. Fit it together, save it,
* flush buffers, transmit it, increment filenames, etc.
*/
/* Now check for more pending images. If we have more, redo from start.
* Some backends might cheat here and send us for an extra round which
* will fail at sane_start, as they were not able to determine if they
* would have more data at the start of the last frame we read.
*/
}
while (parms.flags & SANE_PFLAG_MORE_IMAGES);
/* No more data. Fine. Reset the backend and go back to option-control
* loop.
*/
sane_cancel (handle);

4.5 Well-Known Options

While most backend options are completely self-describing, there are cases where a user interface might want to special-case the handling of certain options. For example, the scan area is typically defined by four options that specify the top-left and bottom-right corners of the area. With a graphical user interface, it would be tedious to force the user to type in these four numbers. Instead, most such interfaces will want to present to the user a preview (low-resolution scan of the full scanner surface or a high(er) resolution scan of a subpart of the scanner surface) and let the user pick the scan area by dragging a rectangle into the desired position. For this reason, the SANE API specifies a small number of option names that have well-defined meanings.

4.5.1 Option Number Count

Option number 0 has an empty string as its name. The value of this option is of type SANE TYPE INT and it specifies the total number of options available for a given device (the count includes option number 0). This means that there are two ways of counting the number of options available: a frontend can either cycle through all option numbers starting at one until sane get option descriptor() returns NULL, or a frontend can directly read out the value of option number 0.

4.5.2 Scan Resolution Options

Option resolution is used to select the resolution at which an image should be acquired. When the backend wants to allow different values for x- and y-resolution it has to define the options x-resolution and y-resolution. Note that only the option resolution or the options x-resolution and y-resolution may be active at the same time.

The type of this option is either SANE TYPE INT or SANE TYPE FIXED. The unit is SANE UNIT DPI (dots/inch).

These options are not mandatory, but if a backend does support them, it must implement them in a manner consistent with the above definition.

4.5.3 Preview Mode Option

The boolean option preview is used by a frontend to inform the backend when image acquisition should be optimized for speed, rather than quality (“preview mode”). When set to SANE TRUE, preview mode is in effect, when set to SANE FALSE image acquisition should proceed in normal quality mode. The setting of this option must not affect any other option. That is, as far as the other options are concerned, the preview mode is completely side effect free. A backend can assume that the frontend will take care of appropriately setting the scan resolution for preview mode (through option resolution). A backend is free to override the resolution value with its own choice for preview mode, but it is advised to leave this choice to the frontend wherever possible. When the preview option is set the backend should transfer the image in frame type SANE FRAME RAW if possible.

This option is not mandatory, but if a backend does support it, it must implement it in a manner consistent with the above definition.

Figure 4.2: Scan area options

4.5.4 Scan Area Options

The four most important well-known options are the ones that define the scan area. The scan area is defined by two points (x/y coordinate pairs) that specify the top-left and the bottom-right corners. This is illustrated in Figure 4.2. Note that the origin of the coordinate system is at the top-left corner of the scan surface as seen by the sensor (which typically is a mirror image of the scan surface seen by the user). For this reason, the top-left corner is the corner for which the abscissa and ordinate values are simultaneously the smallest and the bottom-right corner is the corner for which the abscissa and ordinate values are simulatenously the largest. If this coordinate system is not natural for a given device, it is the job of the backend to perform the necessary conversions.

The names of the four options that define the scan area are given in the table below:

Name Description
tl-x Top-left x coordinate value
tl-y Top-left y coordinate value
br-x Bottom-right x coordinate value
br-y Bottom-right y coordinate value

There are several rules that should be followed by front and backends regarding these options:

• Backends must attach a unit of either pixels (SANE UNIT PIXEL) or millimeters (SANE UNIT MM) to these options. The unit of all four options must be identical.

• Whenever meaningful, a backend should attach a range or a word-list constraint to these options.

• A frontend can determine the size of the scan surface by first checking that the options have range constraints associated. If a range or word-list constraints exist, the frontend can take the minimum and maximum values of one of the x and y option range-constraints to determine the scan surface size.

• A frontend must work properly with any or all of these options missing.

• A frontend may temporarily set the values in a way that tl-x is larger than br-x and tl-y is larger than br-y.

These options are not mandatory, but if a backend does support them, it must implement them in a manner consistent with the above definition.

4.5.5 Depth Option

Option depth is used to select the image depth in bits/sample in multi bit mode (e.g. for 24 bit RGB mode this value must be 8). The type of this option is SANE TYPE INT. The unit is SANE UNIT BIT. For 1 bit modes (Lineart or Halftone) this option has to be inactive. For selection of 1 bit modes (Lineart or Halftone) the backend should use the well-known option mode.

This option is not mandatory, but if a backend does support it, it must implement it in a manner consistent with the above definition.

4.5.6 Scan Mode Options

The option mode defines a SANE CONSTRAINT STRING LIST of type SANE TYPE STRING. It is used

to select the scanmode (e.g. Color or Gray). Well known modes are: Color, Gray, Halftone and Lineart. Color and Gray are multi bit modes (8 or 16 bits/sample), Halftone and Lineart are single bit modes. When well-known scan modes are used, a frontend is able to automatically decide which mode is appropriate for a specific task, e.g the mode Gray for scanning a fax.

This option is not mandatory, but if a backend does support it, it must implement it in a manner consistent with the above definition.

4.5.7 Scan Source Options

The option source is used to select the scan source (e.g. Automatic Document Feeder). It defines a

SANE CONSTRAINT STRING LIST of type SANE TYPE STRING. Well known sources are: Flatbed,
Transparancy Adapter and Automatic Document Feeder.

This option is not mandatory, but if a backend does support it, it must implement it in a manner consistent with the above definition.

4.5.8 Threshold Option

The option threshold is used to define the threshold for Lineart and maybe Halftone mode. In multi bit modes this option should be set inactive. The type of this option is SANE TYPE FIXED. The unit is SANE UNIT PERCENT. The value range should be 0.0… 100.0 if possible. It defines the minimum intensity to get a white point / full intensity.

The backend has to scale the values in the following way: A value of 0.0 means all pixels get white / full intensity. A value of 50.0 means intensities brighter than medium gray get white / full intensity. A value of 100.0 means all pixels get black. If the scanner is not able to cover the full range the backend has to define a reduced value range (e.g. 30… 70 percent).

This option is not mandatory, but if a backend does support it, it must implement it in a manner consistent with the above definition.

4.5.9 Gamma Table Options

The gamma-table option defines a SANE CONSTRAINT RANGE of the type SANE TYPE INT which

represents the gamma correction table for gray. In color mode the gamma-table may be used to set a common gamma correction for red, green and blue. The options red-gamma-table, green-gamma-table and blue-gamma-table are used in color mode to set a gamma correction for each color separately. In color mode the backend is free to use only the gamma-table option, only the red-, green- and blue-gamma-table or all four options. When all four options are used then the color tables should do a gamma correction with the same input and output bit depth and the gray gamma table should reduce (if necessary) the bit depth from the scanner internal bit depth to the output bit depth. This should e.g. look like this:

red_value   = gamma-table(red-gamma-table(value))
green_value = gamma-table(green-gamma-table(value))
blue_value  = gamma-table(blue-gamma-table(value))

The backend should not use the gamma tables to emulate other functions or options like highlight, shadow, contrast, brightness, threshold, analog gamma. These functions are common for all backends and should be added to the frontend or a meta-backend.

It is also discouraged to emulate gamma tables in the backend. The backend should disable (or not define) this option when the scanner does not support gamma tables in hardware.

This option is not mandatory, but if a backend does support it, it must implement it in a manner consistent with the above definition.

4.5.10 Analog Gamma

The option analog-gamma is used to define the gamma value for an analog gamma function of the scanner in multi bit modes. In 1 bit modes this option should be set inactive. The type of this option is SANE TYPE FIXED. The unit is SANE UNIT NONE. The value range can be defined by the backend as supported. The values have to be positive. A gamma value of 1.0 means that the gamma correction has no effect. A value larger than 1.0 increases the brightness of the image. In color mode there also can be options

analog-gamma-red, analog-gamma-green and analog-gamma-blue. It is not allowed to em-

ulate an analog gamma function by a digital gamma table. The backend has to disable (or not define) this option when the scanner does not support an analog (hardware) gamma function.

When analog gamma, highlight and shadow functions are available at the same time then the backend author has to care about the order in which the functions are implemented in the scanner hardware. The SANE standard expects that changing the analog gamma value has no effect on the shadow and highlight function. When the analog gamma function is executed in the scanner hardware before the shadow and highlight functions then the backend should do a compensation. For this the shadow and highlight values have to be gamma corrected with the relevant analog gamma value.

This option is not mandatory, but if a backend does support it, it must implement it in a manner consistent with the above definition.

4.5.11 Shadow Option

The option shadow is used to define the shadow level / black point level. The type of this option is SANE TYPE FIXED. The unit is SANE UNIT PERCENT. The value range should be 0.0… 100.0 if possible. It is used to define the maximum intensity level that creates an image data value of 0 (black).

The backend has to scale the values in the following way: A value of 0.0 means that the sensitivity range is not reduced, only the minimum intensity produces an image data value of 0 (black). A value of 50.0 means that that a medium intensity and everything that is darker produces an image data value of 0 (black). A value of 100.0 means the sensitivity range is reduced to 0, all image data values are 0 (black). If the scanner is not able to cover the full range the backend has to define a reduced value range (e.g. 30… 70 percent). In color

mode there can be options shadow-red, shadow-green and shadow-blue, in this case the shadow

function has to be disabled. It is not allowed to emulate a shadow function by a digital gamma table. The backend has to disable (or not define) this option when the scanner does not support an analog (hardware) shadow function.

This option is not mandatory, but if a backend does support it, it must implement it in a manner consistent with the above definition.

4.5.12 Highlight Option

The option highlight is used to define the highlight level / white point level. The type of this option is SANE TYPE FIXED. The unit is SANE UNIT PERCENT. The value range should be 0.0… 100.0 if possible. It is used to define the minimum intensity level that creates the maximum possible image data value (white/full intensity).

The backend has to scale the values in the following way: A value of 0.0 means the sensitivity range is reduced to 0, all image data have maximum value (white / full intensity). A value of 50.0 means that a medium intensity and everything that is brighter produces the maximum possible image data value (white / full intensity). A value of 100.0 means that the sensitivity range is not reduced, only the maximum intensity produces an image data with maximum possible value (white / full intensity). If the scanner is not able to cover the full range the backend has to define a reduced value range (e.g. 30… 70 percent). In color

mode there can be options highlight-red, highlight-green and highlight-blue, in this

case highlight has to be disabled. It is not allowed to emulate a highlight function by a digital gamma table. The backend has to disable (or not define) this option when the scanner does not support an analog (hardware) highlight function.

This option is not mandatory, but if a backend does support it, it must implement it in a manner consistent with the above definition.

4.5.13 Lamp Options

The options lamp-on and lamp-off are button options (SANE TYPE BUTTON) and don’t have a unit

(SANE UNIT NONE).

Option lamp-on is used to turn on the lamp of the scanner while lamp-off turns it off.

These options are not mandatory, but if a backend does support them, it must implement them in a manner consistent with the above definition.

4.5.14 Scanner Button Options

Some scanners have buttons which state can be read by the scanner driver. It is necessary to implement a locking function for the buttons because it is possible that several frontends try to connect to the same backend/scanner at the same time. Imagine what could happen when no locking would be implemented: Five people have started a scanning application which is connected via network to the scanner you want to use. You start a frontend, put a paper to the scanner and press the scan-button on the scanner. The scanner does scan three times (because three frontends asked the button status when you pressed the button). For three people the image is saved to the harddisk, but it is not sure that your frontend did scan the image.

A backend that does make available the scanner-buttons has to implement the following options:

scanner-buttons-lock is of type SANE TYPE BOOL, default = SANE FALSE
scanner-buttons-status is of type SANE TYPE INT, default = 0
scanner-buttons-status-update is of type SANE TYPE BUTTON

When setting these options the backend does not set SANE INFO RELOAD OPTIONS or SANE INFO RELOAD PARAMS if not explictly defined.

A frontend has to disable the usage of the scanner-buttons by default. This is important because other frontends will not be able to use the buttons when the button-functions are locked. Another important thing is that some scanners do not turn off their lamp when the driver does frequently talk to the scanner (what is done when reading the button status from the scanner).

• A frontend that wants to read the button status has to lock the button functions at first. For this it does set the option scanner-buttons-lock to SANE TRUE. While setting the value of option scanner-buttons-lock to SANE TRUE the backend does check if a lockfile (e.g. “backend”- buttons.lock) does exist. The lockfile has to be placed in a directory where every user has read and write access to.

– If the lockfile does not exist then the backend creates the lockfile and writes the process ID (PID) of the backend to the file. Button access is allowed: the value of option scanner-buttons-lock

         is set to SANE TRUE

– If the file does exist and the backend PID is not the file PID then the backend has to check if the process with the PID stored in the lockfile still is running. If yes then the button access is not allowed: the value of option scanner-buttons-lock is set to SANE FALSE. If not then the lockfile is recreated and the PID of the backend is stored in the lockfile, button access is allowed: the value of option scanner-buttons-lock is set to SANE TRUE

• The frontend does read the value of option scanner-buttons-lock. If it is SANE TRUE then the frontend has access to the scanner buttons. If it is SANE FALSE then access has been denied.

• If the button access is allowed the frontend has to do the following about once per second (while not scanning):

– The frontend does set option scanner-buttons-status-update. The backend checks if access to the buttons is allowed by comparing the backend PID with the lockfile PID. If access is allowed it does read the button status from the scanner and stores it in the option scanner-buttons-status, each bit represents a button, a value of 0 means the button is not pressed, a value of 1 means that the button is pressed. When the scanner is busy the backend must not wait, it has to return immediately and the button state keeps unchanged. The backend has to implement a timeout function. When no button has been pressed within a predefined time (e.g. 15 minutes) then the access permission is lost. In this case the backend does set option

scanner-buttons-lock to SANE FALSE and does set SANE INFO RELOAD OPTIONS

to inform the frontend that it has lost permission to access the scanner-button functions. If access is not allowed it does set the scanner-buttons-status to 0.

– The frontend does read the value of option scanner-buttons-status

• When the frontend does exit or it does not want to use the buttons it does set option scanner-buttons-lock to SANE FALSE. The backend does check if the backend PID and the lockfile PID are the same. If this is true then it removes the lockfile and sets the value of scanner-buttons-lock to

SANE FALSE.
sane close() should do the same as setting option scanner-buttons-lock to SANE FALSE.

4.5.15 Batch Scan Options

The batch scan options can be used by a frontend to indicate that more than one image will be scanned in a batch. The backend can optimize for such scans by e.g. avoiding calibration and not moving home the sensor array in this case. The backend provides the options batch-scan, batch-scan-next-tl-x,

batch-scan-next-tl-y, batch-scan-next-br-x, and batch-scan-next-br-y. The op-

tion batch-scan provides a string list with the values of No if batch scanning isn’t used, Start for the first, End for the last and Loop for any other (intermediate) image. The batch-scan-next options specify the coordinates of the next scan and follow the same rules as the scan area options (see section 4.5.4).

These options are not mandatory, but if a backend does support them, it must implement them in a manner consistent with the above definition. In this case, all options must be implemented.

Network Protocol

The SANE interface has been designed to facilitate network access to image acquisition devices. In particular, most SANE implementations are expected to support a network backend (net client) and a corresponding network daemon (net server) that allows accessing image acquisition devices through a network connection. Network access is useful in several situations:

• To provide controlled access to resources that are inaccessible to a regular user. For example, a user may want to access a device on a host where she has no account on. With the network protocol, it is possible to allow certain users to access scanners without giving them full access to the system.

Controlling access through the network daemon can be useful even in the local case: for example, certain backends may require root privileges to access a device. Rather than installing each frontend as setuid-root, a system administrator could instead install the SANE network daemon as setuidroot. This enables regular users to access the privileged device through the SANE daemon (which, presumably, supports a more fine-grained access control mechanism than the simple setuid approach). This has the added benefit that the system administrator only needs to trust the SANE daemon, not each and every frontend that may need access to the privileged device.

• Network access provides a sense of ubiquity of the available image acquisition devices. For example, in a local area network environment, this allows a user to log onto any machine and have convenient access to any resource available to any machine on the network (subject to permission constraints).

• For devices that do not require physical access when used (e.g., video cameras), network access allows a user to control and use these devices without being in physical proximity. Indeed, if such devices are connected to the Internet, access from any place in the world is possible.

The network protocol described in this chapter has been design with the following goals in mind:

1. Image transmission should be efficient (have low encoding overhead).

2. Accessing option descriptors on the client side must be efficient (since this is a very common operation).

3. Other operations, such as setting or inquiring the value of an option are less performance critical since they typically require explicit user action.

4. The network protocol should be simple and easy to implement on any host architecture and any programming language.

The SANE protocol can be run across any transport protocol that provides reliable data delivery. While SANE does not specify a specific transport protocol, it is expected that TCP/IP will be among the most commonly used protocols.

5.1 Data Type Encoding

5.1.1 Primitive Data Types

The four primitive types of the SANE standard are encoded as follows:

SANE Byte: A byte is encoded as an 8 bit value. Since the transport protocol is assumed to be byte-orientd, the bit order is irrelevant.

SANE Word: A word is encoded as 4 bytes (32 bits). The bytes are ordered from most-significant to leastsignificant byte (big-endian byte-order).

SANE Char: A character is currently encoded as an 8-bit ISO LATIN-1 value. An extension to support wider character sets (16 or 32 bits) is planned for the future, but not supported at this point.

SANE String: A string pointer is encoded as a SANE Char array. The trailing NUL byte is considered part of the array and a NULL pointer is encoded as a zero-length array.

SANE Handle: A handle is encoded like a word. The network backend needs to take care of converting these integer values to the opaque pointer values that are presented to the user of the network backend. Similarly, the SANE daemon needs to take care of converting the opaque pointer values it receives from its backends into 32-bit integers suitable for use for network encoding.

enumeration types: Enumeration types are encoded like words.

5.1.2 Type Constructors

Closely following the type constructors of the C language, the SANE network protocol supports the following four constructors:

pointer: A pointer is encoded by a word that indicates whether the pointer is a NULL-pointer which is then followed by the value that the pointer points to (in the case of a non-NULL pointer; in the case of a NULL pointer, no bytes are encoded for the pointer value). array: An array is encoded by a word that indicates the length of the array followed by the values of the

elements in the array. The length may be zero in which case no bytes are encoded for the element values.

structure: A structure is encoded by simply encoding the structure members in the order in which they appear in the corresponding C type declaration.

union: A union must always be accompanied by a tag value that indicates which of the union members is the currently the active one. For this reason, the union itself is encoded simply by encoding the value of the currently active member.

Note that for type constructors, the pointer, element, or member values themselves may have a constructed type. Thus, the above rules should be applied recursively until a sequence of primitive types has been found.

Also SANE had no need for encoding of circular structures. This greatly simplifies the network protocol.

5.2 Remote Procedure Call Requests

The SANE network protocol is a client/server-style remote procedure call (RPC) protocol. This means that all activity is initiated by the client side (the network backend)—a server is restricted to answering request by the client.

5.2.1 SANE NET INIT

This RPC establishes a connection to a particular SANE network daemon. It must be the first call in a SANE network session. The parameter and reply arguments for this call are shown in the table below:

request:  reply:

                SANE Word version code     SANE Word status
                SANE String user name      SANE Word version code

The version code argument in the request is the SANE version-code of the network backend that is contacting the network daemon (see Section 4.1). The “build-revision” in the version code is used to hold the network protocol version. The SANE network daemon receiving such a request must make sure that the network protocol version corresponds to a supported version since otherwise the encoding of the network stream may be incompatible (even though the SANE interface itself may be compatible). The user name argument is the name of the user on whose behalf this call is being performed. If the network backend cannot determine a user-name, it passes a NULL pointer for this argument. No trust should be placed in the authenticity of this user-name. The intent of this string is to provide more convenience to the user. E.g., it could be used as the default-user name in subsequent authentication calls.

In the reply, status indicates the completion status. If the value is anything other than SANE STA-TUS SUCCESS, the remainder of the reply has undefined values.^{1} The version code argument returns the SANE version-code that the network daemon supports. See the comments in the previous paragraph on the meaning of the build-revision in this version code.

1The sane network daemon should be careful not to leak information in the undefined portion of the reply.

5.2.2 SANE NET GET DEVICES

This RPC is used to obtain the list of devices accessible by the SANE daemon.

request: reply:

                      void     SANE Word status

                               SANE Device ***device list

There are no arguments in the request for this call.

In the reply, status indicates the completion status. If the value is anything other than SANE STA-TUS SUCCESS, the remainder of the reply has undefined values. The device list argument is a pointer to a NULL-terminated array of SANE Device pointers.

5.2.3 SANE NET OPEN

This RPC is used to open a connection to a remote SANE device.

request:  reply:

                SANE String device name     SANE Word status

                                           SANE Word handle
                                           SANE String resource

The device name argument specifies the name of the device to open.

In the reply, status indicates the completion status. If the value is anything other than SANE STA-TUS SUCCESS, the remainder of the reply has undefined values. The handle argument specifies the device handle that uniquely identifies the connection. The resource argument is used to request authentication. If it has a non-NULL value, the network backend should authenticate the specified resource and then retry this operation (see Section 5.2.10 for details on how to authorize a resource).

5.2.4 SANE NET CLOSE

This RPC is used to close a connection to a remote SANE device.

request:  reply:

                       SANE Word handle    SANE Word dummy

The handle argument identifies the connection that should be closed.

In the reply, the dummy argument is unused. Its purpose is to ensure proper synchronization (without it, a net client would not be able to determine when the RPC has completed).

5.2.5 SANE NET GET OPTION DESCRIPTORS

This RPC is used to obtain all the option descriptors for a remote SANE device.

request:  reply:

               SANE Word handle    Option Descriptor Array odesc

The handle argument identifies the remote device whose option descriptors should be obtained.

In the reply, the odesc argument is used to return the array of option descriptors. The option descriptor array has the following structure:

     struct Option_Descriptor_Array
       {
         SANE_Word num_options;
         SANE_Option_Descriptor **desc;
       };

5.2.6 SANE NET CONTROL OPTION

This RPC is used to control (inquire, set, or set to automatic) a specific option of a remote SANE device.

request:  reply:

                 SANE Word handle        SANE Status status
                 SANE Word option        SANE Word info
                 SANE Word action        SANE Word value type
                 SANE Word value type     SANE Word value size
                 SANE Word value size     void *value
                 void *value             SANE String *resource

The handle argument identifies the remote device whose option should be controlled. Argument option is the number (index) of the option that should be controlled. Argument action specifies what action should be taken (get, set, or set automatic). Argument value type specifies the type of the option

value (must be one of SANE TYPE BOOL, SANE TYPE INT, SANE TYPE FIXED, SANE TYPE STR-

ING, SANE TYPE BUTTON). Argument value size specifies the size of the option value in number of bytes (see Section 4.2.9 for the precise meaning of this value). Finally, argument value is a pointer to the option value. It must be a writeable area that is at least value size bytes large. (Note that this area must be writable even if the action is to set the option value. This is because the backend may not be able to set the exact option value, in which case the option value is used to return the next best value that the backend has chosen.)

In the reply, argument resource is set to the name of the resource that must be authorized before this call can be retried. If this value is non-NULL, all other arguments have undefined values (see Section 5.2.10 for details on how to authorize a resource). Argument status indicates the completion status. If the value is anything other than SANE STATUS SUCCESS, the remainder of the reply has undefined values. The info argument returns the information on how well the backend was able to satisfy the request. For details, see the description of the corresponding argument in Section 4.3.7. Arguments value type and value size have the same values as the arguments by the same name in corresponding request. The values are repeated here to ensure that both the request and the reply are self-contained (i.e., they can be encoded and decoded independently). Argument value is holds the value of the option that has become effective as a result of this RPC.

5.2.7 SANE NET GET PARAMETERS

This RPC is used to obtain the scan parameters of a remote SANE device.

request:  reply:

                   SANE Word handle    SANE Status status

                                      SANE Parameters params

The handle argument identifies the connection to the remote device whose scan parameters should be returned.

In the reply, status indicates the completion status. If the value is anything other than SANE STA-TUS SUCCESS, the remainder of the reply has undefined values. The argument params is used to return the scan parameters.

5.2.8 SANE NET START

This RPC is used to start image acquisition (scanning).

request:  reply:

                    SANE Word handle    SANE Status status

                                        SANE Word port
                                        SANE Word byte order
                                        SANE String resource

The handle argument identifies the connection to the remote device from which the image should be acquired.

In the reply, argument resource is set to the name of the resource that must be authorized before this call can be retried. If this value is non-NULL, all other arguments have undefined values (see Section 5.2.10 for details on how to authorize a resource). Argument, status indicates the completion status. If the value is anything other than SANE STATUS SUCCESS, the remainder of the reply has undefined values. The argument port returns the port number from which the image data will be available. To read the image data, a network client must connect to the remote host at the indicated port number. Through this port, the image data is transmitted as a sequence of data records. Each record starts with the data length in bytes. The data length is transmitted as a sequence of four bytes. These bytes should be interpreted as an unsigned integer in big-endian format. The four length bytes are followed by the number of data bytes indicated by the length. Except for byte-order, the data is in the same format as defined for sane read(). Since some records may contain no data at all, a length value of zero is perfectly valid. The special length value of 0xffffffff is used to indicate the end of the data stream. That is, after receiving a record length of 0xffffffff, the network client should close the data connection and stop reading data.

Argument byte order specifies the byte-order of the image data. A value of 0x1234 indicates littleendian format, a value of 0x4321 indicates big-endian format. All other values are presently undefined and reserved for future enhancements of this protocol. The intent is that a network server sends data in its own byte-order and the client is responsible for adjusting the byte-order, if necessary. This approach causes no unnecessary overheads in the case where the server and client byte-order match and puts the extra burden on the client side when there is a byte-order mismatch. Putting the burden on the client-side improves the scalability properties of this protocol.

5.2.9 SANE NET CANCEL

This RPC is used to cancel the current operation of a remote SANE device.

request:  reply:

                       SANE Word handle    SANE Word dummy

The handle argument identifies the connection whose operation should be cancelled.

In the reply, the dummy argument is unused. Its purpose is to ensure proper synchronization (without it, a net client would not be able to determine when the RPC has completed).

5.2.10 SANE NET AUTHORIZE

This RPC is used to pass authorization data from the net client to the net server.

request:  reply:

                    SANE String resource     SANE Word dummy

                    SANE String username
                    SANE String password

The resource argument specifies the name of the resource to be authorized. This argument should be set to the string returned in the resource argument of the RPC reply that required this authorization call. The username and password are the name of the user that is accessing the resource and the password for the specified resource/user pair.

Since the password is not encrypted during network transmission, it is recommended to use the following extension:

If the server adds the string ‘$MD5$’ to the resource-name followed by a random string not longer then 128 bytes, the client may answer with the MD5 digest of the concatenation of the password and the random string. To differentiate between the MD5 digest and a strange password the client prepends the MD5 digest with the string ‘$MD5$’.

In the reply, dummy is completely unused. Note that there is no direct failure indication. This is unnecessary since a net client will retry the RPC that resulted in the authorization request until that call succeeds (or until the request is cancelled). The RPC that resulted in the authorization request continues after the reply from the client and may fail with SANE STATUS ACCESS DENIED.

5.2.11 SANE NET EXIT

This RPC is used to disconnect a net client from a net server. There are no request or reply arguments in this call. As a result of this call, the connection between the client and the server that was established by the SANE NET INIT call will be closed.

Contact Information

The SANE standard is discussed and evolved via a mailing list. Anybody with email access to the Internet can automatically join and leave the discussion group by sending mail to the following address.

     sane-devel-request@mostang.com

To subscribe, send a mail with the body “subscribe sane-devel” to the above address. A complete list of commands supported can be obtained by sending a mail with a subject of “help” to the above address. The mailing list is archived and available through the SANE home page at URL:

     http://www.mostang.com/sane/

Index

analog gamma option, 42 array, 48

Batch Scan Options, 45 bit depth option, 41 br-x, 40 br-y, 40

code flow, 35

device-name, 16 domain, 24

enumeration types, 47

gamma table options, 42

hightlight options, 43

image data format, 8

lamp-off option, 44 lamp-on option, 44

mailing list, 54 mode options, 41

network authorization, 52 NUL, 14

option count, 39 Option Descriptor Array, 50

password, 24 pointer, 47 preview mode, 39

resolution option, 39

SANE Action, 27 SANE ACTION GET VALUE, 27 SANE ACTION SET AUTO, 27 SANE ACTION SET VALUE, 27 SANE Authorization Callback, 24 SANE Bool, 13 SANE Byte, 12, 47 sane cancel, 33 SANE CAP ADVANCED, 21 SANE CAP ALWAYS SETTABLE, 21 SANE CAP AUTOMATIC, 21 SANE CAP EMULATED, 21 SANE CAP HARD SELECT, 21 SANE CAP HIDDEN, 21 SANE CAP INACTIVE, 21 SANE CAP SOFT DETECT, 21 SANE CAP SOFT SELECT, 21 SANE Char, 14, 47 sane close, 26 SANE CONSTRAINT NONE, 22 SANE CONSTRAINT RANGE, 22 SANE CONSTRAINT STRING LIST, 22 SANE Constraint Type, 20 SANE CONSTRAINT WORD LIST, 22 sane control option, 27 SANE CURRENT MAJOR, 11 SANE Device, 15 sane exit, 25 SANE FALSE, 13 SANE FIX, 14 SANE Fixed, 13 SANE FIXED SCALE SHIFT, 13 SANE Frame, 29 SANE FRAME BLUE, 8, 29 SANE FRAME GRAY, 8, 29 SANE FRAME GREEN, 8, 29 SANE FRAME MIME, 8, 10, 29 SANE FRAME RAW, 8, 29 SANE FRAME RED, 8, 29 SANE FRAME RGB, 8, 29 sane get devices, 25 sane get option descriptor, 26 sane get parameters, 29 sane get select fd, 34 SANE Handle, 15, 47 SANE INFO INEXACT, 28 SANE INFO INVALIDATE PREVIEW, 28 SANE INFO RELOAD OPTIONS, 28, 32 SANE INFO RELOAD PARAMS, 28 sane init, 24 SANE Int, 13 SANE NET AUTHORIZE, 52 SANE NET CANCEL, 52 SANE NET CLOSE, 49 SANE NET CONTROL OPTION, 50 SANE NET EXIT, 53 SANE NET GET DEVICES, 49 SANE NET GET OPTION DESCRIPTORS, 50 SANE NET GET PARAMETERS, 51 SANE NET INIT, 48 SANE NET OPEN, 49 SANE NET START, 51 sane open, 25 SANE Option Descriptor, 17 SANE OPTION IS ACTIVE, 20 SANE OPTION IS SETTABLE, 20 SANE Parameters, 29 SANE Range, 22 sane read, 32 sane set io mode, 34 sane start, 32 SANE Status, 15 SANE STATUS ACCESS DENIED, 15 SANE STATUS CANCELLED, 15 SANE STATUS COVER OPEN, 15 SANE STATUS DEVICE BUSY, 15 SANE STATUS EOF, 15 SANE STATUS GOOD, 15, 24 SANE STATUS INVAL, 15 SANE STATUS IO ERROR, 15 SANE STATUS JAMMED, 15 SANE STATUS NO DOCS, 15 SANE STATUS NO MEM, 15 SANE STATUS UNSUPPORTED, 15 SANE String, 14, 47 SANE String Const, 14 sane strstatus, 35 SANE TRUE, 13 SANE TYPE BOOL, 19 SANE TYPE BUTTON, 19 SANE TYPE FIXED, 19 SANE TYPE GROUP, 19 SANE TYPE INT, 19 SANE TYPE STRING, 19 SANE Unit, 18 SANE UNFIX, 14 SANE UNIT BIT, 19 SANE UNIT DPI, 19 SANE UNIT MICROSECOND, 19 SANE UNIT MM, 19 SANE UNIT NONE, 19 SANE UNIT PERCENT, 19 SANE UNIT PIXEL, 19 SANE Value Type, 18 SANE VERSION CODE, 12 SANE VERSION MAJOR, 12 SANE Word, 12, 47 scan area options, 40 scan resolution, 39 scanner button options, 44 shadow options, 43 source options, 41 structure, 48

threshold option, 41

tl-x, 40 tl-y, 40 Type Strings, 16

union, 48 username, 24

Vendor Strings, 16

well-known options, 38