xref: /third_party/backends/backend/dc25.h (revision 141cc406)
1/***************************************************************************
2 * SANE - Scanner Access Now Easy.
3
4   dc25.h
5
6   6/1/98
7
8   This file (C) 1998 Peter Fales
9
10   This file is part of the SANE package.
11
12   This program is free software; you can redistribute it and/or
13   modify it under the terms of the GNU General Public License as
14   published by the Free Software Foundation; either version 2 of the
15   License, or (at your option) any later version.
16
17   This program is distributed in the hope that it will be useful, but
18   WITHOUT ANY WARRANTY; without even the implied warranty of
19   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20   General Public License for more details.
21
22   You should have received a copy of the GNU General Public License
23   along with this program.  If not, see <https://www.gnu.org/licenses/>.
24
25   As a special exception, the authors of SANE give permission for
26   additional uses of the libraries contained in this release of SANE.
27
28   The exception is that, if you link a SANE library with other files
29   to produce an executable, this does not by itself cause the
30   resulting executable to be covered by the GNU General Public
31   License.  Your use of that executable is in no way restricted on
32   account of linking the SANE library code into it.
33
34   This exception does not, however, invalidate any other reasons why
35   the executable file might be covered by the GNU General Public
36   License.
37
38   If you submit changes to SANE to the maintainers to be included in
39   a subsequent release, you agree by submitting the changes that
40   those changes may be distributed with this exception intact.
41
42   If you write modifications of your own for SANE, it is your choice
43   whether to permit this exception to apply to your modifications.
44   If you do not wish that, delete this exception notice.
45
46 ***************************************************************************
47
48   This file implements a SANE backend for the Kodak DC-25 (and
49   probably the DC-20) digital cameras.  THIS IS EXTREMELY ALPHA CODE!
50   USE AT YOUR OWN RISK!!
51
52   (feedback to:  dc25-devel@fales-lorenz.net)
53
54   This backend is based heavily on the dc20ctrl package by Ugo
55   Paternostro <paterno@dsi.unifi.it>.  I've attached his header below:
56
57 ***************************************************************************
58
59 *	Copyright (C) 1998 Ugo Paternostro <paterno@dsi.unifi.it>
60 *
61 *	This file is part of the dc20ctrl package. The complete package can be
62 *	downloaded from:
63 *	    http://aguirre.dsi.unifi.it/~paterno/binaries/dc20ctrl.tar.gz
64 *
65 *	This package is derived from the dc20 package, built by Karl Hakimian
66 *	<hakimian@aha.com> that you can find it at ftp.eecs.wsu.edu in the
67 *	/pub/hakimian directory. The complete URL is:
68 *	    ftp://ftp.eecs.wsu.edu/pub/hakimian/dc20.tar.gz
69 *
70 *	This package also includes a slightly modified version of the Comet to ppm
71 *	conversion routine written by YOSHIDA Hideki <hideki@yk.rim.or.jp>
72 *
73 *	This program is free software; you can redistribute it and/or modify
74 *	it under the terms of the GNU General Public License as published
75 *	the Free Software Foundation; either version 2 of the License, or
76 *	(at your option) any later version.
77 *
78 *	This program is distributed in the hope that it will be useful,
79 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
80 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
81 *	GNU General Public License for more details.
82 *
83 *	You should have received a copy of the GNU General Public License
84 *	along with this program; if not, write to the Free Software
85 *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
86 *
87
88 ***************************************************************************/
89
90#include <stdio.h>
91#include <stdlib.h>
92#include <unistd.h>
93#include <fcntl.h>
94#include <termios.h>
95#include <string.h>
96
97#ifndef TRUE
98#define TRUE	(1==1)
99#endif
100
101#ifndef FALSE
102#define FALSE	(!TRUE)
103#endif
104
105#ifndef NULL
106#define NULL	0L
107#endif
108
109typedef struct dc20_info_s {
110	unsigned char model;
111	unsigned char ver_major;
112	unsigned char ver_minor;
113	int pic_taken;
114	int pic_left;
115	struct {
116		unsigned int low_res:1;
117		unsigned int low_batt:1;
118	} flags;
119} Dc20Info, *Dc20InfoPtr;
120
121static Dc20Info *get_info (int);
122
123#define INIT_PCK	{0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1A}
124/*                               ^^^^^^^^^^
125 *                               Baud rate: (see pkt_speed structure)
126 *                                 0x96 0x00 -> 9600 baud
127 *                                 0x19 0x20 -> 19200 baud
128 *                                 0x38 0x40 -> 38400 baud
129 *                                 0x57 0x60 -> 57600 baud
130 *                                 0x11 0x52 -> 115200 baud
131 */
132#define INFO_PCK	{0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1A}
133#define SHOOT_PCK	{0x77, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1A}
134#define ERASE_PCK	{0x7A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1A}
135#define RES_PCK		{0x71, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1A}
136/*                               ^^^^
137 *                               Resolution: 0x00 = high, 0x01 = low
138 */
139#define THUMBS_PCK	{0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1A}
140/*                                     ^^^^
141 *                                     Thumbnail number
142 */
143#define PICS_PCK	{0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1A}
144/*                                     ^^^^
145 *                                     Picture number
146 */
147
148struct pkt_speed {
149	speed_t          baud;
150	unsigned char    pkt_code[2];
151};
152
153#define DEFAULT_TTY_BAUD B38400
154
155#define HIGH_RES		0
156#define LOW_RES			1
157
158/*
159 *	Image parameters
160 */
161
162#define LOW_CAMERA_HEADER	256
163#define HIGH_CAMERA_HEADER	512
164#define CAMERA_HEADER(r)	( (r) ? LOW_CAMERA_HEADER : HIGH_CAMERA_HEADER )
165
166#define LOW_WIDTH			256
167#define HIGH_WIDTH			512
168#define WIDTH(r)			( (r) ? LOW_WIDTH : HIGH_WIDTH )
169
170#define HEIGHT				243
171
172#define LEFT_MARGIN			1
173
174#define LOW_RIGHT_MARGIN	5
175#define HIGH_RIGHT_MARGIN	10
176#define RIGHT_MARGIN(r)		( (r) ? LOW_RIGHT_MARGIN : HIGH_RIGHT_MARGIN )
177
178#define TOP_MARGIN			1
179
180#define BOTTOM_MARGIN		1
181
182#define BLOCK_SIZE			1024
183
184#define LOW_BLOCKS			61
185#define HIGH_BLOCKS			122
186#define BLOCKS(r)			( (r) ? LOW_BLOCKS : HIGH_BLOCKS )
187
188#define	LOW_IMAGE_SIZE		( LOW_BLOCKS * BLOCK_SIZE )
189#define HIGH_IMAGE_SIZE		( HIGH_BLOCKS * BLOCK_SIZE )
190#define IMAGE_SIZE(r)		( (r) ? LOW_IMAGE_SIZE : HIGH_IMAGE_SIZE )
191#define MAX_IMAGE_SIZE		( HIGH_IMAGE_SIZE )
192
193/*
194 *	Comet file
195 */
196
197#define COMET_MAGIC			"COMET"
198#define COMET_HEADER_SIZE	128
199#define COMET_EXT			"cmt"
200
201/*
202 *	Pixmap structure
203 */
204
205struct pixmap {
206	int				 width;
207	int				 height;
208	int				 components;
209	unsigned char	*planes;
210};
211
212/*
213 *	Rotations
214 */
215
216#define ROT_STRAIGHT	0x00
217#define ROT_LEFT		0x01
218#define ROT_RIGHT		0x02
219#define ROT_HEADDOWN	0x03
220
221#define ROT_MASK		0x03
222
223/*
224 *	File formats
225 */
226
227#define SAVE_RAW		0x01
228#define SAVE_GREYSCALE		0x02
229#define SAVE_24BITS		0x04
230#define SAVE_FILES		0x07
231#define SAVE_FORMATS		0x38
232#define SAVE_ADJASPECT		0x80
233
234/*
235 *	External definitions
236 */
237
238extern char		*__progname;		/* Defined in /usr/lib/crt0.o */
239
240
241
242#include <sys/types.h>
243
244FILE * sanei_config_open (const char *filename);
245
246char *sanei_config_read (char *str, int n, FILE * stream);
247
248static int init_dc20 (char *, speed_t);
249
250static void close_dc20 (int);
251
252static int read_data (int fd, unsigned char *buf, int sz);
253
254static int end_of_data (int fd);
255
256static int set_pixel_rgb (struct pixmap *, int, int, unsigned char, unsigned char, unsigned char);
257
258static struct pixmap *alloc_pixmap (int x, int y, int d);
259
260static void free_pixmap (struct pixmap *p);
261
262static int zoom_x (struct pixmap *source, struct pixmap *dest);
263
264static int zoom_y (struct pixmap *source, struct pixmap *dest);
265
266static int comet_to_pixmap (unsigned char *, struct pixmap *);
267