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