1 /* lexmark_x2600.c: SANE backend for Lexmark x2600 scanners. 2 3 (C) 2023 "Benoit Juin" <benoit.juin@gmail.com> 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 LEXMARK_X2600_H 43 #define LEXMARK_X2600_H 44 #define BACKEND_NAME lexmark_x2600 45 #include "../include/sane/config.h" 46 47 #include <errno.h> 48 #include <signal.h> 49 #include <stdio.h> 50 #include <stdlib.h> 51 #include <string.h> 52 #include <sys/types.h> 53 #include <sys/wait.h> 54 #include <time.h> 55 #include <unistd.h> 56 #include <fcntl.h> 57 #include <ctype.h> 58 #include <sys/time.h> 59 60 #include "../include/_stdint.h" 61 #include "../include/sane/sane.h" 62 #include "../include/sane/sanei.h" 63 #include "../include/sane/saneopts.h" 64 #include "../include/sane/sanei_config.h" 65 #include "../include/sane/sanei_usb.h" 66 #include "../include/sane/sanei_backend.h" 67 68 69 typedef struct Read_Buffer 70 { 71 SANE_Int gray_offset; 72 SANE_Int max_gray_offset; 73 SANE_Int region; 74 SANE_Int red_offset; 75 SANE_Int green_offset; 76 SANE_Int blue_offset; 77 SANE_Int max_red_offset; 78 SANE_Int max_green_offset; 79 SANE_Int max_blue_offset; 80 SANE_Byte *data; 81 SANE_Byte *readptr; 82 SANE_Byte *writeptr; 83 SANE_Byte *max_writeptr; 84 size_t size; 85 size_t linesize; 86 size_t last_line_bytes_read; 87 SANE_Bool empty; 88 SANE_Int image_line_no; 89 SANE_Int write_byte_counter; 90 SANE_Int read_byte_counter; 91 } 92 Read_Buffer; 93 94 95 typedef enum 96 { 97 OPT_NUM_OPTS = 0, 98 OPT_MODE, 99 OPT_RESOLUTION, 100 OPT_PREVIEW, 101 102 OPT_GEOMETRY_GROUP, 103 OPT_TL_X, /* top-left x */ 104 OPT_TL_Y, /* top-left y */ 105 OPT_BR_X, /* bottom-right x */ 106 OPT_BR_Y, /* bottom-right y */ 107 108 /* must come last: */ 109 NUM_OPTIONS 110 } 111 Lexmark_Options; 112 113 typedef enum 114 { 115 READ = 0, 116 WRITE = 1, 117 } 118 Debug_Packet; 119 120 121 typedef struct Lexmark_Device 122 { 123 struct Lexmark_Device *next; 124 SANE_Bool missing; /**< devices has been unplugged or swtiched off */ 125 126 SANE_Device sane; 127 SANE_Option_Descriptor opt[NUM_OPTIONS]; 128 Option_Value val[NUM_OPTIONS]; 129 SANE_Parameters params; 130 SANE_Int devnum; 131 long data_size; 132 SANE_Bool initialized; 133 SANE_Bool eof; 134 SANE_Int x_dpi; 135 SANE_Int y_dpi; 136 long data_ctr; 137 SANE_Bool device_cancelled; 138 SANE_Int cancel_ctr; 139 SANE_Byte *transfer_buffer; 140 size_t bytes_read; 141 size_t bytes_remaining; 142 size_t bytes_in_buffer; 143 SANE_Byte *read_pointer; 144 Read_Buffer *read_buffer; 145 } 146 Lexmark_Device; 147 148 149 void debug_packet(const SANE_Byte * source, SANE_Int source_size, Debug_Packet dp); 150 151 #endif /* LEXMARK_X2600_H */ 152