xref: /third_party/backends/backend/gt68xx_mid.h (revision 141cc406)
1/* sane - Scanner Access Now Easy.
2
3   Copyright (C) 2002 Sergey Vlasov <vsu@altlinux.ru>
4
5   This file is part of the SANE package.
6
7   This program is free software; you can redistribute it and/or
8   modify it under the terms of the GNU General Public License as
9   published by the Free Software Foundation; either version 2 of the
10   License, or (at your option) any later version.
11
12   This program is distributed in the hope that it will be useful, but
13   WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15   General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with this program.  If not, see <https://www.gnu.org/licenses/>.
19
20   As a special exception, the authors of SANE give permission for
21   additional uses of the libraries contained in this release of SANE.
22
23   The exception is that, if you link a SANE library with other files
24   to produce an executable, this does not by itself cause the
25   resulting executable to be covered by the GNU General Public
26   License.  Your use of that executable is in no way restricted on
27   account of linking the SANE library code into it.
28
29   This exception does not, however, invalidate any other reasons why
30   the executable file might be covered by the GNU General Public
31   License.
32
33   If you submit changes to SANE to the maintainers to be included in
34   a subsequent release, you agree by submitting the changes that
35   those changes may be distributed with this exception intact.
36
37   If you write modifications of your own for SANE, it is your choice
38   whether to permit this exception to apply to your modifications.
39   If you do not wish that, delete this exception notice.
40*/
41
42#ifndef GT68XX_MID_H
43#define GT68XX_MID_H
44
45/** @file
46 * @brief Image data unpacking.
47 */
48
49#include "gt68xx_low.h"
50#include "../include/sane/sane.h"
51
52typedef struct GT68xx_Delay_Buffer GT68xx_Delay_Buffer;
53typedef struct GT68xx_Line_Reader GT68xx_Line_Reader;
54
55struct GT68xx_Delay_Buffer
56{
57  SANE_Int line_count;
58  SANE_Int read_index;
59  SANE_Int write_index;
60  unsigned int **lines;
61  SANE_Byte *mem_block;
62};
63
64/**
65 * Object for reading image data line by line, with line distance correction.
66 *
67 * This object handles reading the image data from the scanner line by line and
68 * converting it to internal format.  Internally each image sample is
69 * represented as <code>unsigned int</code> value, scaled to 16-bit range
70 * (0-65535).  For color images the data for each primary color is stored as
71 * separate lines.
72 */
73struct GT68xx_Line_Reader
74{
75  GT68xx_Device *dev;			/**< Low-level interface object */
76  GT68xx_Scan_Parameters params;	/**< Scan parameters */
77
78#if 0
79  /** Number of bytes in the returned scanlines */
80  SANE_Int bytes_per_line;
81
82  /** Number of bytes per pixel in the returned scanlines */
83  SANE_Int bytes_per_pixel;
84#endif
85
86  /** Number of pixels in the returned scanlines */
87  SANE_Int pixels_per_line;
88
89  SANE_Byte *pixel_buffer;
90
91  GT68xx_Delay_Buffer r_delay;
92  GT68xx_Delay_Buffer g_delay;
93  GT68xx_Delay_Buffer b_delay;
94  SANE_Bool delays_initialized;
95
96    SANE_Status (*read) (GT68xx_Line_Reader * reader,
97			 unsigned int **buffer_pointers_return);
98};
99
100/**
101 * Create a new GT68xx_Line_Reader object.
102 *
103 * @param dev           The low-level scanner interface object.
104 * @param params        Scan parameters prepared by gt68xx_device_setup_scan().
105 * @param final_scan    SANE_TRUE for the final scan, SANE_FALSE for
106 *                      calibration scans.
107 * @param reader_return Location for the returned object.
108 *
109 * @return
110 * - SANE_STATUS_GOOD   - on success
111 * - SANE_STATUS_NO_MEM - cannot allocate memory for object or buffers
112 * - other error values - failure of some internal functions
113 */
114static SANE_Status
115gt68xx_line_reader_new (GT68xx_Device * dev,
116			GT68xx_Scan_Parameters * params,
117			SANE_Bool final_scan,
118			GT68xx_Line_Reader ** reader_return);
119
120/**
121 * Destroy the GT68xx_Line_Reader object.
122 *
123 * @param reader  The GT68xx_Line_Reader object to destroy.
124 */
125static SANE_Status gt68xx_line_reader_free (GT68xx_Line_Reader * reader);
126
127/**
128 * Read a scanline from the GT68xx_Line_Reader object.
129 *
130 * @param reader      The GT68xx_Line_Reader object.
131 * @param buffer_pointers_return Array of pointers to image lines (1 or 3
132 * elements)
133 *
134 * This function reads a full scanline from the device, unpacks it to internal
135 * buffers and returns pointer to these buffers in @a
136 * buffer_pointers_return[i].  For monochrome scan, only @a
137 * buffer_pointers_return[0] is filled; for color scan, elements 0, 1, 2 are
138 * filled with pointers to red, green, and blue data.  The returned pointers
139 * are valid until the next call to gt68xx_line_reader_read(), or until @a
140 * reader is destroyed.
141 *
142 * @return
143 * - SANE_STATUS_GOOD  - read completed successfully
144 * - other error value - an error occurred
145 */
146static SANE_Status
147gt68xx_line_reader_read (GT68xx_Line_Reader * reader,
148			 unsigned int **buffer_pointers_return);
149
150#endif /* not GT68XX_MID_H */
151
152/* vim: set sw=2 cino=>2se-1sn-1s{s^-1st0(0u0 smarttab expandtab: */
153