• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * kodakaio.c - SANE library for Kodak ESP Aio scanners.
3  *
4  * Copyright (C)  2011-2013 Paul Newall
5  *
6  * Based on the Magicolor sane backend:
7  * Based on the epson2 sane backend:
8  * Based on Kazuhiro Sasayama previous
9  * work on epson.[ch] file from the SANE package.
10  * Please see those files for additional copyrights.
11  * Author: Paul Newall
12  *
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License as
16  * published by the Free Software Foundation, version 2.
17 
18 	29/12/12 added KodakAio_Scanner.ack
19 	2/1/13 added KodakAio_Scanner.background[]
20  */
21 
22 #ifndef kodakaio_h
23 #define kodakaio_h
24 
25 #undef BACKEND_NAME
26 #define BACKEND_NAME kodakaio
27 #define DEBUG_NOT_STATIC
28 
29 #include <sys/ioctl.h>
30 
31 #ifdef HAVE_STDDEF_H
32 #include <stddef.h>
33 #endif
34 
35 #ifdef HAVE_STDLIB_H
36 #include <stdlib.h>
37 #endif
38 
39 #ifdef NEED_SYS_TYPES_H
40 #include <sys/types.h>
41 #endif
42 
43 #include <stdio.h>
44 
45 #include "../include/sane/sane.h"
46 #include "../include/sane/sanei_debug.h"
47 #include "../include/sane/sanei_backend.h"
48 
49 /* Silence the compiler for unused arguments */
50 #define NOT_USED(x) ( (void)(x) )
51 
52 #define KODAKAIO_CONFIG_FILE "kodakaio.conf"
53 
54 #define NUM_OF_HEX_ELEMENTS (16)        /* number of hex numbers per line for data dump */
55 #define DEVICE_NAME_LEN (16)    /* length of device name in extended status */
56 
57 #define CAP_DEFAULT 0
58 
59 /* Structure holding the device capabilities */
60 struct KodakaioCap
61 {
62 	SANE_Word id;			/* USB pid */
63 	const char *cmds;		/* may be used for different command sets in future */
64 	const char *model;
65 	SANE_Int out_ep, in_ep;		/* USB bulk out/in endpoints */
66 
67 	SANE_Int optical_res;		/* optical resolution */
68 	SANE_Range dpi_range;		/* max/min resolutions */
69 
70 	SANE_Int *res_list;		/* list of resolutions */
71 	SANE_Int res_list_size;		/* number of entries in this list */
72 
73 	SANE_Int maxDepth;		/* max. color depth */
74 	SANE_Word *depth_list;		/* list of color depths */
75 
76 	 /* SANE_Range brightness;		brightness range */
77 
78 	SANE_Range fbf_x_range;		/* flattbed x range */
79 	SANE_Range fbf_y_range;		/* flattbed y range */
80 
81 	SANE_Bool ADF;			/* ADF is installed */
82 	SANE_Bool adf_duplex;		/* does the ADF handle duplex scanning */
83 	SANE_Range adf_x_range;		/* autom. document feeder x range */
84 	SANE_Range adf_y_range;		/* autom. document feeder y range */
85 };
86 
87 /*
88 Options:OPT_BRIGHTNESS, used to be after BIT_DEPTH
89 */
90 enum {
91 	OPT_NUM_OPTS = 0,
92 	OPT_MODE_GROUP,
93 	OPT_MODE,
94 	OPT_THRESHOLD,
95 	OPT_BIT_DEPTH,
96 	OPT_RESOLUTION,
97 	OPT_TRIALOPT, /* for debuggging */
98 	OPT_PREVIEW,
99 	OPT_SOURCE,
100 	OPT_ADF_MODE,
101 	OPT_PADDING,		/* Selects padding of adf pages to the specified length */
102 	OPT_GEOMETRY_GROUP,
103 	OPT_TL_X,
104 	OPT_TL_Y,
105 	OPT_BR_X,
106 	OPT_BR_Y,
107 	NUM_OPTIONS
108 };
109 
110 typedef enum
111 {	/* hardware connection to the scanner */
112 	SANE_KODAKAIO_NODEV,	/* default, no HW specified yet */
113 	SANE_KODAKAIO_USB,	/* USB interface */
114 	SANE_KODAKAIO_NET	/* network interface */
115 } Kodakaio_Connection_Type;
116 
117 
118 /* Structure holding the hardware description */
119 
120 struct Kodak_Device
121 {
122 	struct Kodak_Device *next;
123 	int missing;
124 
125 	char *name;
126 	char *model;
127 
128 	SANE_Device sane;
129 
130 	SANE_Range *x_range;	/* x range w/out extension */
131 	SANE_Range *y_range;	/* y range w/out extension */
132 
133 	Kodakaio_Connection_Type connection;
134 
135 	struct KodakaioCap *cap;
136 };
137 
138 typedef struct Kodak_Device Kodak_Device;
139 
140 /* Structure holding an instance of a scanner (i.e. scanner has been opened) */
141 struct KodakAio_Scanner
142 {
143 	struct KodakAio_Scanner *next;
144 	struct Kodak_Device *hw;
145 
146 	int fd;
147 
148 	SANE_Option_Descriptor opt[NUM_OPTIONS];
149 	Option_Value val[NUM_OPTIONS];
150 	SANE_Parameters params;
151 
152 	SANE_Bool ack; /* scanner has finished a page (happens early with adf and padding) */
153 	SANE_Bool eof; /* backend has finished a page (after padding with adf) */
154 	SANE_Byte *buf, *end, *ptr;
155 	SANE_Bool canceling;
156 	SANE_Bool scanning; /* scan in progress */
157 	SANE_Bool adf_loaded; /* paper in adf */
158 	SANE_Int background[3]; /* stores background RGB components for padding */
159 
160 	SANE_Int left, top; /* in optres units? */
161 	SANE_Int width, height; /* in optres units? */
162 	/* SANE_Int threshold;  0..255 for lineart*/
163 
164 	/* image block data */
165 	SANE_Int data_len;
166 	SANE_Int block_len;
167 	SANE_Int last_len; /* to be phased out */
168 	SANE_Int blocks;  /* to be phased out */
169 	SANE_Int counter;
170 	SANE_Int bytes_unread; /* to track when to stop */
171 
172 	/* Used to store how many bytes of the current pixel line we have already
173 	 * read in previous read attempts. Since each line will be padded
174 	 * to multiples of 512 bytes, this is needed to know which bytes
175 	 * to ignore. NOT NEEDED FOR KODAKAIO */
176 	SANE_Int bytes_read_in_line;
177 	SANE_Byte *line_buffer;
178 	/* How many bytes are scanned per line */
179 	SANE_Int scan_bytes_per_line;
180 };
181 
182 typedef struct KodakAio_Scanner KodakAio_Scanner;
183 
184 struct mode_param
185 {
186 	int flags;
187 	int colors;
188 	int depth;
189 };
190 
191 enum {
192 	MODE_COLOR, MODE_GRAY, MODE_LINEART
193 };
194 
195 #endif
196