xref: /aoo41x/main/sane/inc/sane.h (revision 25381912)
1cdf0e10cSrcweir /* sane - Scanner Access Now Easy.
2*25381912SPedro Giffuni    Copyright (C) 1997-1999 David Mosberger-Tang and Andreas Beck
3cdf0e10cSrcweir    This file is part of the SANE package.
4cdf0e10cSrcweir 
5cdf0e10cSrcweir    This file is in the public domain.  You may use and modify it as
6cdf0e10cSrcweir    you see fit, as long as this copyright message is included and
7cdf0e10cSrcweir    that there is an indication as to what modifications have been
8cdf0e10cSrcweir    made (if any).
9cdf0e10cSrcweir 
10cdf0e10cSrcweir    SANE is distributed in the hope that it will be useful, but WITHOUT
11cdf0e10cSrcweir    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12cdf0e10cSrcweir    FITNESS FOR A PARTICULAR PURPOSE.
13cdf0e10cSrcweir 
14cdf0e10cSrcweir    This file declares SANE application interface.  See the SANE
15cdf0e10cSrcweir    standard for a detailed explanation of the interface.  */
16cdf0e10cSrcweir #ifndef sane_h
17cdf0e10cSrcweir #define sane_h
18cdf0e10cSrcweir 
19*25381912SPedro Giffuni #ifdef __cplusplus
20*25381912SPedro Giffuni extern "C" {
21*25381912SPedro Giffuni #endif
22*25381912SPedro Giffuni 
23*25381912SPedro Giffuni /*
24*25381912SPedro Giffuni  * SANE types and defines
25*25381912SPedro Giffuni  */
26*25381912SPedro Giffuni 
27*25381912SPedro Giffuni #define SANE_CURRENT_MAJOR	1
28*25381912SPedro Giffuni #define SANE_CURRENT_MINOR	0
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #define SANE_VERSION_CODE(major, minor, build)	\
31cdf0e10cSrcweir   (  (((SANE_Word) (major) &   0xff) << 24)	\
32cdf0e10cSrcweir    | (((SANE_Word) (minor) &   0xff) << 16)	\
33cdf0e10cSrcweir    | (((SANE_Word) (build) & 0xffff) <<  0))
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #define SANE_VERSION_MAJOR(code)	((((SANE_Word)(code)) >> 24) &   0xff)
36cdf0e10cSrcweir #define SANE_VERSION_MINOR(code)	((((SANE_Word)(code)) >> 16) &   0xff)
37cdf0e10cSrcweir #define SANE_VERSION_BUILD(code)	((((SANE_Word)(code)) >>  0) & 0xffff)
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #define SANE_FALSE	0
40cdf0e10cSrcweir #define SANE_TRUE	1
41cdf0e10cSrcweir 
42*25381912SPedro Giffuni typedef unsigned char  SANE_Byte;
43*25381912SPedro Giffuni typedef int  SANE_Word;
44*25381912SPedro Giffuni typedef SANE_Word  SANE_Bool;
45*25381912SPedro Giffuni typedef SANE_Word  SANE_Int;
46cdf0e10cSrcweir typedef char SANE_Char;
47cdf0e10cSrcweir typedef SANE_Char *SANE_String;
48cdf0e10cSrcweir typedef const SANE_Char *SANE_String_Const;
49cdf0e10cSrcweir typedef void *SANE_Handle;
50cdf0e10cSrcweir typedef SANE_Word SANE_Fixed;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir #define SANE_FIXED_SCALE_SHIFT	16
53cdf0e10cSrcweir #define SANE_FIX(v)	((SANE_Word) ((v) * (1 << SANE_FIXED_SCALE_SHIFT)))
54cdf0e10cSrcweir #define SANE_UNFIX(v)	((double)(v) / (1 << SANE_FIXED_SCALE_SHIFT))
55cdf0e10cSrcweir 
56cdf0e10cSrcweir typedef enum
57cdf0e10cSrcweir   {
58cdf0e10cSrcweir     SANE_STATUS_GOOD = 0,	/* everything A-OK */
59cdf0e10cSrcweir     SANE_STATUS_UNSUPPORTED,	/* operation is not supported */
60cdf0e10cSrcweir     SANE_STATUS_CANCELLED,	/* operation was cancelled */
61cdf0e10cSrcweir     SANE_STATUS_DEVICE_BUSY,	/* device is busy; try again later */
62cdf0e10cSrcweir     SANE_STATUS_INVAL,		/* data is invalid (includes no dev at open) */
63cdf0e10cSrcweir     SANE_STATUS_EOF,		/* no more data available (end-of-file) */
64cdf0e10cSrcweir     SANE_STATUS_JAMMED,		/* document feeder jammed */
65cdf0e10cSrcweir     SANE_STATUS_NO_DOCS,	/* document feeder out of documents */
66cdf0e10cSrcweir     SANE_STATUS_COVER_OPEN,	/* scanner cover is open */
67cdf0e10cSrcweir     SANE_STATUS_IO_ERROR,	/* error during device I/O */
68cdf0e10cSrcweir     SANE_STATUS_NO_MEM,		/* out of memory */
69cdf0e10cSrcweir     SANE_STATUS_ACCESS_DENIED	/* access to resource has been denied */
70cdf0e10cSrcweir   }
71cdf0e10cSrcweir SANE_Status;
72cdf0e10cSrcweir 
73*25381912SPedro Giffuni /* following are for later sane version, older frontends wont support */
74*25381912SPedro Giffuni #if 0
75*25381912SPedro Giffuni #define SANE_STATUS_WARMING_UP 12 /* lamp not ready, please retry */
76*25381912SPedro Giffuni #define SANE_STATUS_HW_LOCKED  13 /* scanner mechanism locked for transport */
77*25381912SPedro Giffuni #endif
78*25381912SPedro Giffuni 
79cdf0e10cSrcweir typedef enum
80cdf0e10cSrcweir   {
81cdf0e10cSrcweir     SANE_TYPE_BOOL = 0,
82cdf0e10cSrcweir     SANE_TYPE_INT,
83cdf0e10cSrcweir     SANE_TYPE_FIXED,
84cdf0e10cSrcweir     SANE_TYPE_STRING,
85cdf0e10cSrcweir     SANE_TYPE_BUTTON,
86cdf0e10cSrcweir     SANE_TYPE_GROUP
87cdf0e10cSrcweir   }
88cdf0e10cSrcweir SANE_Value_Type;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir typedef enum
91cdf0e10cSrcweir   {
92cdf0e10cSrcweir     SANE_UNIT_NONE = 0,		/* the value is unit-less (e.g., # of scans) */
93cdf0e10cSrcweir     SANE_UNIT_PIXEL,		/* value is number of pixels */
94cdf0e10cSrcweir     SANE_UNIT_BIT,		/* value is number of bits */
95cdf0e10cSrcweir     SANE_UNIT_MM,		/* value is millimeters */
96cdf0e10cSrcweir     SANE_UNIT_DPI,		/* value is resolution in dots/inch */
97cdf0e10cSrcweir     SANE_UNIT_PERCENT,		/* value is a percentage */
98cdf0e10cSrcweir     SANE_UNIT_MICROSECOND	/* value is micro seconds */
99cdf0e10cSrcweir   }
100cdf0e10cSrcweir SANE_Unit;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir typedef struct
103cdf0e10cSrcweir   {
104cdf0e10cSrcweir     SANE_String_Const name;	/* unique device name */
105cdf0e10cSrcweir     SANE_String_Const vendor;	/* device vendor string */
106cdf0e10cSrcweir     SANE_String_Const model;	/* device model name */
107cdf0e10cSrcweir     SANE_String_Const type;	/* device type (e.g., "flatbed scanner") */
108cdf0e10cSrcweir   }
109cdf0e10cSrcweir SANE_Device;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir #define SANE_CAP_SOFT_SELECT		(1 << 0)
112cdf0e10cSrcweir #define SANE_CAP_HARD_SELECT		(1 << 1)
113cdf0e10cSrcweir #define SANE_CAP_SOFT_DETECT		(1 << 2)
114cdf0e10cSrcweir #define SANE_CAP_EMULATED		(1 << 3)
115cdf0e10cSrcweir #define SANE_CAP_AUTOMATIC		(1 << 4)
116cdf0e10cSrcweir #define SANE_CAP_INACTIVE		(1 << 5)
117cdf0e10cSrcweir #define SANE_CAP_ADVANCED		(1 << 6)
118cdf0e10cSrcweir 
119cdf0e10cSrcweir #define SANE_OPTION_IS_ACTIVE(cap)	(((cap) & SANE_CAP_INACTIVE) == 0)
120cdf0e10cSrcweir #define SANE_OPTION_IS_SETTABLE(cap)	(((cap) & SANE_CAP_SOFT_SELECT) != 0)
121cdf0e10cSrcweir 
122cdf0e10cSrcweir #define SANE_INFO_INEXACT		(1 << 0)
123cdf0e10cSrcweir #define SANE_INFO_RELOAD_OPTIONS	(1 << 1)
124cdf0e10cSrcweir #define SANE_INFO_RELOAD_PARAMS		(1 << 2)
125cdf0e10cSrcweir 
126cdf0e10cSrcweir typedef enum
127cdf0e10cSrcweir   {
128cdf0e10cSrcweir     SANE_CONSTRAINT_NONE = 0,
129cdf0e10cSrcweir     SANE_CONSTRAINT_RANGE,
130cdf0e10cSrcweir     SANE_CONSTRAINT_WORD_LIST,
131cdf0e10cSrcweir     SANE_CONSTRAINT_STRING_LIST
132cdf0e10cSrcweir   }
133cdf0e10cSrcweir SANE_Constraint_Type;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir typedef struct
136cdf0e10cSrcweir   {
137cdf0e10cSrcweir     SANE_Word min;		/* minimum (element) value */
138cdf0e10cSrcweir     SANE_Word max;		/* maximum (element) value */
139cdf0e10cSrcweir     SANE_Word quant;		/* quantization value (0 if none) */
140cdf0e10cSrcweir   }
141cdf0e10cSrcweir SANE_Range;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir typedef struct
144cdf0e10cSrcweir   {
145cdf0e10cSrcweir     SANE_String_Const name;	/* name of this option (command-line name) */
146cdf0e10cSrcweir     SANE_String_Const title;	/* title of this option (single-line) */
147cdf0e10cSrcweir     SANE_String_Const desc;	/* description of this option (multi-line) */
148cdf0e10cSrcweir     SANE_Value_Type type;	/* how are values interpreted? */
149cdf0e10cSrcweir     SANE_Unit unit;		/* what is the (physical) unit? */
150cdf0e10cSrcweir     SANE_Int size;
151cdf0e10cSrcweir     SANE_Int cap;		/* capabilities */
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     SANE_Constraint_Type constraint_type;
154cdf0e10cSrcweir     union
155cdf0e10cSrcweir       {
156cdf0e10cSrcweir 	const SANE_String_Const *string_list;	/* NULL-terminated list */
157cdf0e10cSrcweir 	const SANE_Word *word_list;	/* first element is list-length */
158cdf0e10cSrcweir 	const SANE_Range *range;
159cdf0e10cSrcweir       }
160cdf0e10cSrcweir     constraint;
161cdf0e10cSrcweir   }
162cdf0e10cSrcweir SANE_Option_Descriptor;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir typedef enum
165cdf0e10cSrcweir   {
166cdf0e10cSrcweir     SANE_ACTION_GET_VALUE = 0,
167cdf0e10cSrcweir     SANE_ACTION_SET_VALUE,
168cdf0e10cSrcweir     SANE_ACTION_SET_AUTO
169cdf0e10cSrcweir   }
170cdf0e10cSrcweir SANE_Action;
171cdf0e10cSrcweir 
172cdf0e10cSrcweir typedef enum
173cdf0e10cSrcweir   {
174*25381912SPedro Giffuni     SANE_FRAME_GRAY,	/* band covering human visual range */
175*25381912SPedro Giffuni     SANE_FRAME_RGB,	/* pixel-interleaved red/green/blue bands */
176*25381912SPedro Giffuni     SANE_FRAME_RED,	/* red band only */
177*25381912SPedro Giffuni     SANE_FRAME_GREEN,	/* green band only */
178*25381912SPedro Giffuni     SANE_FRAME_BLUE 	/* blue band only */
179cdf0e10cSrcweir   }
180cdf0e10cSrcweir SANE_Frame;
181cdf0e10cSrcweir 
182*25381912SPedro Giffuni /* push remaining types down to match existing backends */
183*25381912SPedro Giffuni /* these are to be exposed in a later version of SANE */
184*25381912SPedro Giffuni /* most front-ends will require updates to understand them */
185*25381912SPedro Giffuni #if 0
186*25381912SPedro Giffuni #define SANE_FRAME_TEXT  0x0A  /* backend specific textual data */
187*25381912SPedro Giffuni #define SANE_FRAME_JPEG  0x0B  /* complete baseline JPEG file */
188*25381912SPedro Giffuni #define SANE_FRAME_G31D  0x0C  /* CCITT Group 3 1-D Compressed (MH) */
189*25381912SPedro Giffuni #define SANE_FRAME_G32D  0x0D  /* CCITT Group 3 2-D Compressed (MR) */
190*25381912SPedro Giffuni #define SANE_FRAME_G42D  0x0E  /* CCITT Group 4 2-D Compressed (MMR) */
191*25381912SPedro Giffuni 
192*25381912SPedro Giffuni #define SANE_FRAME_IR    0x0F  /* bare infrared channel */
193*25381912SPedro Giffuni #define SANE_FRAME_RGBI  0x10  /* red+green+blue+infrared */
194*25381912SPedro Giffuni #define SANE_FRAME_GRAYI 0x11  /* gray+infrared */
195*25381912SPedro Giffuni #define SANE_FRAME_XML   0x12  /* undefined schema */
196*25381912SPedro Giffuni #endif
197*25381912SPedro Giffuni 
198cdf0e10cSrcweir typedef struct
199cdf0e10cSrcweir   {
200cdf0e10cSrcweir     SANE_Frame format;
201cdf0e10cSrcweir     SANE_Bool last_frame;
202cdf0e10cSrcweir     SANE_Int bytes_per_line;
203cdf0e10cSrcweir     SANE_Int pixels_per_line;
204cdf0e10cSrcweir     SANE_Int lines;
205cdf0e10cSrcweir     SANE_Int depth;
206cdf0e10cSrcweir   }
207cdf0e10cSrcweir SANE_Parameters;
208cdf0e10cSrcweir 
209cdf0e10cSrcweir struct SANE_Auth_Data;
210cdf0e10cSrcweir 
211*25381912SPedro Giffuni #define SANE_MAX_USERNAME_LEN	128
212*25381912SPedro Giffuni #define SANE_MAX_PASSWORD_LEN	128
213cdf0e10cSrcweir 
214cdf0e10cSrcweir typedef void (*SANE_Auth_Callback) (SANE_String_Const resource,
215*25381912SPedro Giffuni 				    SANE_Char *username,
216*25381912SPedro Giffuni 				    SANE_Char *password);
217cdf0e10cSrcweir 
218cdf0e10cSrcweir extern SANE_Status sane_init (SANE_Int * version_code,
219cdf0e10cSrcweir 			      SANE_Auth_Callback authorize);
220cdf0e10cSrcweir extern void sane_exit (void);
221cdf0e10cSrcweir extern SANE_Status sane_get_devices (const SANE_Device *** device_list,
222cdf0e10cSrcweir 				     SANE_Bool local_only);
223cdf0e10cSrcweir extern SANE_Status sane_open (SANE_String_Const devicename,
224cdf0e10cSrcweir 			      SANE_Handle * handle);
225cdf0e10cSrcweir extern void sane_close (SANE_Handle handle);
226cdf0e10cSrcweir extern const SANE_Option_Descriptor *
227cdf0e10cSrcweir   sane_get_option_descriptor (SANE_Handle handle, SANE_Int option);
228cdf0e10cSrcweir extern SANE_Status sane_control_option (SANE_Handle handle, SANE_Int option,
229cdf0e10cSrcweir 					SANE_Action action, void *value,
230cdf0e10cSrcweir 					SANE_Int * info);
231cdf0e10cSrcweir extern SANE_Status sane_get_parameters (SANE_Handle handle,
232cdf0e10cSrcweir 					SANE_Parameters * params);
233cdf0e10cSrcweir extern SANE_Status sane_start (SANE_Handle handle);
234cdf0e10cSrcweir extern SANE_Status sane_read (SANE_Handle handle, SANE_Byte * data,
235cdf0e10cSrcweir 			      SANE_Int max_length, SANE_Int * length);
236cdf0e10cSrcweir extern void sane_cancel (SANE_Handle handle);
237cdf0e10cSrcweir extern SANE_Status sane_set_io_mode (SANE_Handle handle,
238cdf0e10cSrcweir 				     SANE_Bool non_blocking);
239cdf0e10cSrcweir extern SANE_Status sane_get_select_fd (SANE_Handle handle,
240cdf0e10cSrcweir 				       SANE_Int * fd);
241cdf0e10cSrcweir extern SANE_String_Const sane_strstatus (SANE_Status status);
242cdf0e10cSrcweir 
243*25381912SPedro Giffuni #ifdef __cplusplus
244*25381912SPedro Giffuni }
245*25381912SPedro Giffuni #endif
246*25381912SPedro Giffuni 
247*25381912SPedro Giffuni 
248cdf0e10cSrcweir #endif /* sane_h */
249