xref: /third_party/backends/backend/epsonds.h (revision 141cc406)
1/*
2 * epsonds.c - Epson ESC/I-2 driver.
3 *
4 * Copyright (C) 2015 Tower Technologies
5 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 *
7 * This file is part of the SANE package.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation, version 2.
12 */
13
14#ifndef epsonds_h
15#define epsonds_h
16
17#undef BACKEND_NAME
18#define BACKEND_NAME epsonds
19#define DEBUG_NOT_STATIC
20
21#define mode_params epsonds_mode_params
22#define source_list epsonds_source_list
23
24#ifdef HAVE_SYS_IOCTL_H
25#include <sys/ioctl.h>
26#endif
27
28#ifdef HAVE_STDDEF_H
29#include <stddef.h>
30#endif
31
32#ifdef HAVE_STDLIB_H
33#include <stdlib.h>
34#endif
35
36#ifdef NEED_SYS_TYPES_H
37#include <sys/types.h>
38#endif
39
40#include <string.h> /* for memset and memcpy */
41#include <stdio.h>
42
43#include "sane/sane.h"
44#include "sane/sanei_backend.h"
45#include "sane/sanei_debug.h"
46#include "sane/sanei_usb.h"
47#include "sane/sanei_jpeg.h"
48
49#define EPSONDS_CONFIG_FILE "epsonds.conf"
50
51#ifndef PATH_MAX
52#define PATH_MAX (1024)
53#endif
54
55#ifndef XtNumber
56#define XtNumber(x)  (sizeof(x) / sizeof(x[0]))
57#define XtOffset(p_type, field)  ((size_t)&(((p_type)NULL)->field))
58#define XtOffsetOf(s_type, field)  XtOffset(s_type*, field)
59#endif
60
61#define ACK	0x06
62#define NAK	0x15
63#define	FS	0x1C
64
65#define FBF_STR SANE_I18N("Flatbed")
66#define TPU_STR SANE_I18N("Transparency Unit")
67#define ADF_STR SANE_I18N("Automatic Document Feeder")
68
69#define STRING_FLATBED SANE_I18N("Flatbed")
70#define STRING_ADFFRONT SANE_I18N("ADF Front")
71#define STRING_ADFDUPLEX SANE_I18N("ADF Duplex")
72
73enum {
74	OPT_NUM_OPTS = 0,
75	OPT_STANDARD_GROUP,
76	OPT_SOURCE,
77	OPT_MODE,
78	OPT_DEPTH,
79	OPT_RESOLUTION,
80	OPT_GEOMETRY_GROUP,
81	OPT_TL_X,
82	OPT_TL_Y,
83	OPT_BR_X,
84	OPT_BR_Y,
85	OPT_EQU_GROUP,
86	OPT_EJECT,
87	OPT_LOAD,
88	OPT_ADF_SKEW,
89	OPT_ADF_CRP,
90	NUM_OPTIONS
91};
92
93typedef enum
94{	/* hardware connection to the scanner */
95	SANE_EPSONDS_NODEV,	/* default, no HW specified yet */
96	SANE_EPSONDS_USB,	/* USB interface */
97	SANE_EPSONDS_NET	/* network interface */
98} epsonds_conn_type;
99
100/* hardware description */
101
102struct epsonds_device
103{
104	struct epsonds_device *next;
105
106	epsonds_conn_type connection;
107
108	char *name;
109	char *model;
110
111	unsigned int model_id;
112
113	SANE_Device sane;
114	SANE_Range *x_range;
115	SANE_Range *y_range;
116	SANE_Range dpi_range;
117	SANE_Byte alignment;
118
119
120	SANE_Int *res_list;		/* list of resolutions */
121	SANE_Int *depth_list;
122	SANE_Int max_depth;		/* max. color depth */
123
124	SANE_Bool has_raw;		/* supports RAW format */
125
126	SANE_Bool has_mono;  /*supprt M001*/
127
128	SANE_Bool has_fb;		/* flatbed */
129	SANE_Range fbf_x_range;	        /* x range */
130	SANE_Range fbf_y_range;	        /* y range */
131	SANE_Byte fbf_alignment;	/* left, center, right */
132	SANE_Bool fbf_has_skew;		/* supports skew correction */
133
134	SANE_Bool has_adf;		/* adf */
135	SANE_Range adf_x_range;	        /* x range */
136	SANE_Range adf_y_range;	        /* y range */
137	SANE_Bool adf_is_duplex;	/* supports duplex mode */
138	SANE_Bool adf_singlepass;	/* supports single pass duplex */
139	SANE_Bool adf_has_skew;		/* supports skew correction */
140	SANE_Bool adf_has_load;		/* supports load command */
141	SANE_Bool adf_has_eject;	/* supports eject command */
142	SANE_Byte adf_alignment;	/* left, center, right */
143	SANE_Byte adf_has_dfd;		/* supports double feed detection */
144
145	SANE_Byte adf_has_crp;		/* supports crp */
146
147	SANE_Bool has_tpu;		/* tpu */
148	SANE_Range tpu_x_range;	        /* transparency unit x range */
149	SANE_Range tpu_y_range;	        /* transparency unit y range */
150
151	SANE_Int lut_id;
152};
153
154typedef struct epsonds_device epsonds_device;
155
156typedef struct ring_buffer
157{
158	SANE_Byte *ring, *wp, *rp, *end;
159	SANE_Int fill, size;
160
161} ring_buffer;
162
163/* an instance of a scanner */
164
165struct epsonds_scanner
166{
167	struct epsonds_scanner *next;
168	struct epsonds_device *hw;
169
170	int fd;
171
172	SANE_Option_Descriptor opt[NUM_OPTIONS];
173	Option_Value val[NUM_OPTIONS];
174	SANE_Parameters params;
175
176	size_t bsz;		/* transfer buffer size */
177	SANE_Byte *buf, *line_buffer;
178	ring_buffer *current, front, back;
179
180	SANE_Bool eof, scanning, canceling, locked, backside, mode_jpeg;
181
182	SANE_Int left, top, pages, dummy;
183
184	SANE_Int width_front, height_front;
185	SANE_Int width_back , height_back;
186	SANE_Int width_temp, height_temp;
187
188	/* jpeg stuff */
189
190	djpeg_dest_ptr jdst;
191	struct jpeg_decompress_struct jpeg_cinfo;
192	struct jpeg_error_mgr jpeg_err;
193	SANE_Bool jpeg_header_seen;
194
195	/* network buffers */
196	unsigned char *netbuf, *netptr;
197	size_t netlen;
198
199	SANE_Byte *frontJpegBuf, *backJpegBuf;
200	SANE_Int   frontJpegBufLen, backJpegBufLen;
201	SANE_Int   acquirePage;
202
203	SANE_Int   isflatbedScan;
204	SANE_Int   isDuplexScan;
205
206	SANE_Int   needToConvertBW;
207
208	SANE_Int   scanEnd;
209 };
210
211typedef struct epsonds_scanner epsonds_scanner;
212
213struct mode_param
214{
215	int color;
216	int flags;
217	int dropout_mask;
218	int depth;
219};
220
221enum {
222	MODE_BINARY, MODE_GRAY, MODE_COLOR
223};
224
225#endif
226