1141cc406Sopenharmony_ci/* sane - Scanner Access Now Easy. 2141cc406Sopenharmony_ci 3141cc406Sopenharmony_ci This file is part of the SANE package. 4141cc406Sopenharmony_ci 5141cc406Sopenharmony_ci This program is free software; you can redistribute it and/or 6141cc406Sopenharmony_ci modify it under the terms of the GNU General Public License as 7141cc406Sopenharmony_ci published by the Free Software Foundation; either version 2 of the 8141cc406Sopenharmony_ci License, or (at your option) any later version. 9141cc406Sopenharmony_ci 10141cc406Sopenharmony_ci This program is distributed in the hope that it will be useful, but 11141cc406Sopenharmony_ci WITHOUT ANY WARRANTY; without even the implied warranty of 12141cc406Sopenharmony_ci MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13141cc406Sopenharmony_ci General Public License for more details. 14141cc406Sopenharmony_ci 15141cc406Sopenharmony_ci You should have received a copy of the GNU General Public License 16141cc406Sopenharmony_ci along with this program. If not, see <https://www.gnu.org/licenses/>. 17141cc406Sopenharmony_ci 18141cc406Sopenharmony_ci As a special exception, the authors of SANE give permission for 19141cc406Sopenharmony_ci additional uses of the libraries contained in this release of SANE. 20141cc406Sopenharmony_ci 21141cc406Sopenharmony_ci The exception is that, if you link a SANE library with other files 22141cc406Sopenharmony_ci to produce an executable, this does not by itself cause the 23141cc406Sopenharmony_ci resulting executable to be covered by the GNU General Public 24141cc406Sopenharmony_ci License. Your use of that executable is in no way restricted on 25141cc406Sopenharmony_ci account of linking the SANE library code into it. 26141cc406Sopenharmony_ci 27141cc406Sopenharmony_ci This exception does not, however, invalidate any other reasons why 28141cc406Sopenharmony_ci the executable file might be covered by the GNU General Public 29141cc406Sopenharmony_ci License. 30141cc406Sopenharmony_ci 31141cc406Sopenharmony_ci If you submit changes to SANE to the maintainers to be included in 32141cc406Sopenharmony_ci a subsequent release, you agree by submitting the changes that 33141cc406Sopenharmony_ci those changes may be distributed with this exception intact. 34141cc406Sopenharmony_ci 35141cc406Sopenharmony_ci If you write modifications of your own for SANE, it is your choice 36141cc406Sopenharmony_ci whether to permit this exception to apply to your modifications. 37141cc406Sopenharmony_ci If you do not wish that, delete this exception notice. */ 38141cc406Sopenharmony_ci 39141cc406Sopenharmony_ci 40141cc406Sopenharmony_ci 41141cc406Sopenharmony_ci#ifndef ibm_h 42141cc406Sopenharmony_ci#define ibm_h 1 43141cc406Sopenharmony_ci 44141cc406Sopenharmony_ci#include <sys/types.h> 45141cc406Sopenharmony_ci 46141cc406Sopenharmony_ci#include "../include/sane/config.h" 47141cc406Sopenharmony_ci 48141cc406Sopenharmony_ci/* defines for scan_image_mode field */ 49141cc406Sopenharmony_ci#define IBM_BINARY_MONOCHROME 0 50141cc406Sopenharmony_ci#define IBM_DITHERED_MONOCHROME 1 51141cc406Sopenharmony_ci#define IBM_GRAYSCALE 2 52141cc406Sopenharmony_ci 53141cc406Sopenharmony_ci/* defines for paper field */ 54141cc406Sopenharmony_ci#define IBM_PAPER_USER_DEFINED 0 55141cc406Sopenharmony_ci#define IBM_PAPER_A3 1 56141cc406Sopenharmony_ci#define IBM_PAPER_A4 2 57141cc406Sopenharmony_ci#define IBM_PAPER_A4L 3 58141cc406Sopenharmony_ci#define IBM_PAPER_A5 4 59141cc406Sopenharmony_ci#define IBM_PAPER_A5L 5 60141cc406Sopenharmony_ci#define IBM_PAPER_A6 6 61141cc406Sopenharmony_ci#define IBM_PAPER_B4 7 62141cc406Sopenharmony_ci#define IBM_PAPER_B5 8 63141cc406Sopenharmony_ci#define IBM_PAPER_LEGAL 9 64141cc406Sopenharmony_ci#define IBM_PAPER_LETTER 10 65141cc406Sopenharmony_ci 66141cc406Sopenharmony_ci/* sizes for mode parameter's base_measurement_unit */ 67141cc406Sopenharmony_ci#define INCHES 0 68141cc406Sopenharmony_ci#define MILLIMETERS 1 69141cc406Sopenharmony_ci#define POINTS 2 70141cc406Sopenharmony_ci#define DEFAULT_MUD 1200 71141cc406Sopenharmony_ci#define MEASUREMENTS_PAGE (SANE_Byte)(0x03) 72141cc406Sopenharmony_ci 73141cc406Sopenharmony_ci/* Mode Page Control */ 74141cc406Sopenharmony_ci#define PC_CURRENT 0x00 75141cc406Sopenharmony_ci#define PC_CHANGE 0x40 76141cc406Sopenharmony_ci#define PC_DEFAULT 0x80 77141cc406Sopenharmony_ci#define PC_SAVED 0xc0 78141cc406Sopenharmony_ci 79141cc406Sopenharmony_cistatic const SANE_String_Const mode_list[] = 80141cc406Sopenharmony_ci { 81141cc406Sopenharmony_ci SANE_VALUE_SCAN_MODE_LINEART, 82141cc406Sopenharmony_ci SANE_VALUE_SCAN_MODE_HALFTONE, 83141cc406Sopenharmony_ci SANE_VALUE_SCAN_MODE_GRAY, 84141cc406Sopenharmony_ci 0 85141cc406Sopenharmony_ci }; 86141cc406Sopenharmony_ci 87141cc406Sopenharmony_cistatic const SANE_String_Const paper_list[] = 88141cc406Sopenharmony_ci { 89141cc406Sopenharmony_ci "User", 90141cc406Sopenharmony_ci "A3", 91141cc406Sopenharmony_ci "A4", "A4R", 92141cc406Sopenharmony_ci "A5", "A5R", 93141cc406Sopenharmony_ci "A6", 94141cc406Sopenharmony_ci "B4", "B5", 95141cc406Sopenharmony_ci "Legal", "Letter", 96141cc406Sopenharmony_ci 0 97141cc406Sopenharmony_ci }; 98141cc406Sopenharmony_ci 99141cc406Sopenharmony_ci#define PAPER_A3_W 14032 100141cc406Sopenharmony_ci#define PAPER_A3_H 19842 101141cc406Sopenharmony_ci#define PAPER_A4_W 9921 102141cc406Sopenharmony_ci#define PAPER_A4_H 14032 103141cc406Sopenharmony_ci#define PAPER_A4R_W 14032 104141cc406Sopenharmony_ci#define PAPER_A4R_H 9921 105141cc406Sopenharmony_ci#define PAPER_A5_W 7016 106141cc406Sopenharmony_ci#define PAPER_A5_H 9921 107141cc406Sopenharmony_ci#define PAPER_A5R_W 9921 108141cc406Sopenharmony_ci#define PAPER_A5R_H 7016 109141cc406Sopenharmony_ci#define PAPER_A6_W 4960 110141cc406Sopenharmony_ci#define PAPER_A6_H 7016 111141cc406Sopenharmony_ci#define PAPER_B4_W 11811 112141cc406Sopenharmony_ci#define PAPER_B4_H 16677 113141cc406Sopenharmony_ci#define PAPER_B5_W 8598 114141cc406Sopenharmony_ci#define PAPER_B5_H 12142 115141cc406Sopenharmony_ci#define PAPER_LEGAL_W 10200 116141cc406Sopenharmony_ci#define PAPER_LEGAL_H 16800 117141cc406Sopenharmony_ci#define PAPER_LETTER_W 10200 118141cc406Sopenharmony_ci#define PAPER_LETTER_H 13200 119141cc406Sopenharmony_ci 120141cc406Sopenharmony_cistatic const SANE_Range u8_range = 121141cc406Sopenharmony_ci { 122141cc406Sopenharmony_ci 0, /* minimum */ 123141cc406Sopenharmony_ci 255, /* maximum */ 124141cc406Sopenharmony_ci 0 /* quantization */ 125141cc406Sopenharmony_ci }; 126141cc406Sopenharmony_ci 127141cc406Sopenharmony_cistatic const SANE_Range ibm2456_res_range = 128141cc406Sopenharmony_ci { 129141cc406Sopenharmony_ci 100, /* minimum */ 130141cc406Sopenharmony_ci 600, /* maximum */ 131141cc406Sopenharmony_ci 0 /* quantization */ 132141cc406Sopenharmony_ci }; 133141cc406Sopenharmony_ci 134141cc406Sopenharmony_cistatic const SANE_Range default_x_range = 135141cc406Sopenharmony_ci { 136141cc406Sopenharmony_ci 0, /* minimum */ 137141cc406Sopenharmony_ci/* (SANE_Word) ( * DEFAULT_MUD), maximum */ 138141cc406Sopenharmony_ci 14032, /* maximum (found empirically for Gray mode) */ 139141cc406Sopenharmony_ci /* in Lineart mode it works till 14062 */ 140141cc406Sopenharmony_ci 2 /* quantization */ 141141cc406Sopenharmony_ci }; 142141cc406Sopenharmony_ci 143141cc406Sopenharmony_cistatic const SANE_Range default_y_range = 144141cc406Sopenharmony_ci { 145141cc406Sopenharmony_ci 0, /* minimum */ 146141cc406Sopenharmony_ci/* (SANE_Word) (14 * DEFAULT_MUD), maximum */ 147141cc406Sopenharmony_ci 20410, /* maximum (found empirically) */ 148141cc406Sopenharmony_ci 2 /* quantization */ 149141cc406Sopenharmony_ci }; 150141cc406Sopenharmony_ci 151141cc406Sopenharmony_ci 152141cc406Sopenharmony_ci 153141cc406Sopenharmony_cistatic inline void 154141cc406Sopenharmony_ci_lto2b(SANE_Int val, SANE_Byte *bytes) 155141cc406Sopenharmony_ci 156141cc406Sopenharmony_ci{ 157141cc406Sopenharmony_ci 158141cc406Sopenharmony_ci bytes[0] = (val >> 8) & 0xff; 159141cc406Sopenharmony_ci bytes[1] = val & 0xff; 160141cc406Sopenharmony_ci} 161141cc406Sopenharmony_ci 162141cc406Sopenharmony_cistatic inline void 163141cc406Sopenharmony_ci_lto3b(SANE_Int val, SANE_Byte *bytes) 164141cc406Sopenharmony_ci 165141cc406Sopenharmony_ci{ 166141cc406Sopenharmony_ci 167141cc406Sopenharmony_ci bytes[0] = (val >> 16) & 0xff; 168141cc406Sopenharmony_ci bytes[1] = (val >> 8) & 0xff; 169141cc406Sopenharmony_ci bytes[2] = val & 0xff; 170141cc406Sopenharmony_ci} 171141cc406Sopenharmony_ci 172141cc406Sopenharmony_cistatic inline void 173141cc406Sopenharmony_ci_lto4b(SANE_Int val, SANE_Byte *bytes) 174141cc406Sopenharmony_ci{ 175141cc406Sopenharmony_ci 176141cc406Sopenharmony_ci bytes[0] = (val >> 24) & 0xff; 177141cc406Sopenharmony_ci bytes[1] = (val >> 16) & 0xff; 178141cc406Sopenharmony_ci bytes[2] = (val >> 8) & 0xff; 179141cc406Sopenharmony_ci bytes[3] = val & 0xff; 180141cc406Sopenharmony_ci} 181141cc406Sopenharmony_ci 182141cc406Sopenharmony_cistatic inline SANE_Int 183141cc406Sopenharmony_ci_2btol(SANE_Byte *bytes) 184141cc406Sopenharmony_ci{ 185141cc406Sopenharmony_ci SANE_Int rv; 186141cc406Sopenharmony_ci 187141cc406Sopenharmony_ci rv = (bytes[0] << 8) | 188141cc406Sopenharmony_ci bytes[1]; 189141cc406Sopenharmony_ci return (rv); 190141cc406Sopenharmony_ci} 191141cc406Sopenharmony_ci 192141cc406Sopenharmony_cistatic inline SANE_Int 193141cc406Sopenharmony_ci_3btol(SANE_Byte *bytes) 194141cc406Sopenharmony_ci{ 195141cc406Sopenharmony_ci SANE_Int rv; 196141cc406Sopenharmony_ci 197141cc406Sopenharmony_ci rv = (bytes[0] << 16) | 198141cc406Sopenharmony_ci (bytes[1] << 8) | 199141cc406Sopenharmony_ci bytes[2]; 200141cc406Sopenharmony_ci return (rv); 201141cc406Sopenharmony_ci} 202141cc406Sopenharmony_ci 203141cc406Sopenharmony_cistatic inline SANE_Int 204141cc406Sopenharmony_ci_4btol(SANE_Byte *bytes) 205141cc406Sopenharmony_ci{ 206141cc406Sopenharmony_ci SANE_Int rv; 207141cc406Sopenharmony_ci 208141cc406Sopenharmony_ci rv = (bytes[0] << 24) | 209141cc406Sopenharmony_ci (bytes[1] << 16) | 210141cc406Sopenharmony_ci (bytes[2] << 8) | 211141cc406Sopenharmony_ci bytes[3]; 212141cc406Sopenharmony_ci return (rv); 213141cc406Sopenharmony_ci} 214141cc406Sopenharmony_ci 215141cc406Sopenharmony_citypedef enum 216141cc406Sopenharmony_ci { 217141cc406Sopenharmony_ci OPT_NUM_OPTS = 0, 218141cc406Sopenharmony_ci 219141cc406Sopenharmony_ci OPT_MODE_GROUP, 220141cc406Sopenharmony_ci OPT_MODE, 221141cc406Sopenharmony_ci OPT_X_RESOLUTION, 222141cc406Sopenharmony_ci OPT_Y_RESOLUTION, 223141cc406Sopenharmony_ci OPT_ADF, 224141cc406Sopenharmony_ci 225141cc406Sopenharmony_ci OPT_GEOMETRY_GROUP, 226141cc406Sopenharmony_ci OPT_PAPER, /* predefined formats */ 227141cc406Sopenharmony_ci OPT_TL_X, /* top-left x */ 228141cc406Sopenharmony_ci OPT_TL_Y, /* top-left y */ 229141cc406Sopenharmony_ci OPT_BR_X, /* bottom-right x */ 230141cc406Sopenharmony_ci OPT_BR_Y, /* bottom-right y */ 231141cc406Sopenharmony_ci 232141cc406Sopenharmony_ci OPT_ENHANCEMENT_GROUP, 233141cc406Sopenharmony_ci OPT_BRIGHTNESS, 234141cc406Sopenharmony_ci OPT_CONTRAST, 235141cc406Sopenharmony_ci 236141cc406Sopenharmony_ci /* must come last: */ 237141cc406Sopenharmony_ci NUM_OPTIONS 238141cc406Sopenharmony_ci } 239141cc406Sopenharmony_ciIbm_Option; 240141cc406Sopenharmony_ci 241141cc406Sopenharmony_citypedef struct Ibm_Info 242141cc406Sopenharmony_ci { 243141cc406Sopenharmony_ci SANE_Range xres_range; 244141cc406Sopenharmony_ci SANE_Range yres_range; 245141cc406Sopenharmony_ci SANE_Range x_range; 246141cc406Sopenharmony_ci SANE_Range y_range; 247141cc406Sopenharmony_ci SANE_Range brightness_range; 248141cc406Sopenharmony_ci SANE_Range contrast_range; 249141cc406Sopenharmony_ci 250141cc406Sopenharmony_ci SANE_Int xres_default; 251141cc406Sopenharmony_ci SANE_Int yres_default; 252141cc406Sopenharmony_ci SANE_Int image_mode_default; 253141cc406Sopenharmony_ci SANE_Int paper_default; 254141cc406Sopenharmony_ci SANE_Int brightness_default; 255141cc406Sopenharmony_ci SANE_Int contrast_default; 256141cc406Sopenharmony_ci SANE_Int adf_default; 257141cc406Sopenharmony_ci 258141cc406Sopenharmony_ci SANE_Int bmu; 259141cc406Sopenharmony_ci SANE_Int mud; 260141cc406Sopenharmony_ci } 261141cc406Sopenharmony_ciIbm_Info; 262141cc406Sopenharmony_ci 263141cc406Sopenharmony_citypedef struct Ibm_Device 264141cc406Sopenharmony_ci { 265141cc406Sopenharmony_ci struct Ibm_Device *next; 266141cc406Sopenharmony_ci SANE_Device sane; 267141cc406Sopenharmony_ci Ibm_Info info; 268141cc406Sopenharmony_ci } 269141cc406Sopenharmony_ciIbm_Device; 270141cc406Sopenharmony_ci 271141cc406Sopenharmony_citypedef struct Ibm_Scanner 272141cc406Sopenharmony_ci { 273141cc406Sopenharmony_ci /* all the state needed to define a scan request: */ 274141cc406Sopenharmony_ci struct Ibm_Scanner *next; 275141cc406Sopenharmony_ci int fd; /* SCSI filedescriptor */ 276141cc406Sopenharmony_ci 277141cc406Sopenharmony_ci SANE_Option_Descriptor opt[NUM_OPTIONS]; 278141cc406Sopenharmony_ci Option_Value val[NUM_OPTIONS]; 279141cc406Sopenharmony_ci SANE_Parameters params; 280141cc406Sopenharmony_ci /* scanner dependent/low-level state: */ 281141cc406Sopenharmony_ci Ibm_Device *hw; 282141cc406Sopenharmony_ci 283141cc406Sopenharmony_ci SANE_Int xres; 284141cc406Sopenharmony_ci SANE_Int yres; 285141cc406Sopenharmony_ci SANE_Int ulx; 286141cc406Sopenharmony_ci SANE_Int uly; 287141cc406Sopenharmony_ci SANE_Int width; 288141cc406Sopenharmony_ci SANE_Int length; 289141cc406Sopenharmony_ci SANE_Int brightness; 290141cc406Sopenharmony_ci SANE_Int contrast; 291141cc406Sopenharmony_ci SANE_Int image_composition; 292141cc406Sopenharmony_ci SANE_Int bpp; 293141cc406Sopenharmony_ci SANE_Bool reverse; 294141cc406Sopenharmony_ci/* next lines by mf */ 295141cc406Sopenharmony_ci SANE_Int adf_state; 296141cc406Sopenharmony_ci#define ADF_UNUSED 0 /* scan from flatbed, not ADF */ 297141cc406Sopenharmony_ci#define ADF_ARMED 1 /* scan from ADF, everything's set up */ 298141cc406Sopenharmony_ci#define ADF_CLEANUP 2 /* eject paper from ADF on close */ 299141cc406Sopenharmony_ci/* end lines by mf */ 300141cc406Sopenharmony_ci size_t bytes_to_read; 301141cc406Sopenharmony_ci int scanning; 302141cc406Sopenharmony_ci } 303141cc406Sopenharmony_ciIbm_Scanner; 304141cc406Sopenharmony_ci 305141cc406Sopenharmony_cistruct inquiry_data { 306141cc406Sopenharmony_ci SANE_Byte devtype; 307141cc406Sopenharmony_ci SANE_Byte byte2; 308141cc406Sopenharmony_ci SANE_Byte byte3; 309141cc406Sopenharmony_ci SANE_Byte byte4; 310141cc406Sopenharmony_ci SANE_Byte byte5; 311141cc406Sopenharmony_ci SANE_Byte res1[2]; 312141cc406Sopenharmony_ci SANE_Byte flags; 313141cc406Sopenharmony_ci SANE_Byte vendor[8]; 314141cc406Sopenharmony_ci SANE_Byte product[8]; 315141cc406Sopenharmony_ci SANE_Byte revision[4]; 316141cc406Sopenharmony_ci SANE_Byte byte[60]; 317141cc406Sopenharmony_ci}; 318141cc406Sopenharmony_ci 319141cc406Sopenharmony_ci#define IBM_WINDOW_DATA_SIZE 320 320141cc406Sopenharmony_cistruct ibm_window_data { 321141cc406Sopenharmony_ci /* header */ 322141cc406Sopenharmony_ci SANE_Byte reserved[6]; 323141cc406Sopenharmony_ci SANE_Byte len[2]; 324141cc406Sopenharmony_ci /* data */ 325141cc406Sopenharmony_ci SANE_Byte window_id; /* must be zero */ 326141cc406Sopenharmony_ci SANE_Byte reserved0; 327141cc406Sopenharmony_ci SANE_Byte x_res[2]; 328141cc406Sopenharmony_ci SANE_Byte y_res[2]; 329141cc406Sopenharmony_ci SANE_Byte x_org[4]; 330141cc406Sopenharmony_ci SANE_Byte y_org[4]; 331141cc406Sopenharmony_ci SANE_Byte width[4]; 332141cc406Sopenharmony_ci SANE_Byte length[4]; 333141cc406Sopenharmony_ci SANE_Byte brightness; 334141cc406Sopenharmony_ci SANE_Byte threshold; 335141cc406Sopenharmony_ci SANE_Byte contrast; 336141cc406Sopenharmony_ci SANE_Byte image_comp; /* image composition (data type) */ 337141cc406Sopenharmony_ci SANE_Byte bits_per_pixel; 338141cc406Sopenharmony_ci SANE_Byte halftone_code; /* halftone_pattern[0] in ricoh.h */ 339141cc406Sopenharmony_ci SANE_Byte halftone_id; /* halftone_pattern[1] in ricoh.h */ 340141cc406Sopenharmony_ci SANE_Byte pad_type; 341141cc406Sopenharmony_ci SANE_Byte bit_ordering[2]; 342141cc406Sopenharmony_ci SANE_Byte compression_type; 343141cc406Sopenharmony_ci SANE_Byte compression_arg; 344141cc406Sopenharmony_ci SANE_Byte res3[6]; 345141cc406Sopenharmony_ci 346141cc406Sopenharmony_ci /* Vendor Specific parameter byte(s) */ 347141cc406Sopenharmony_ci /* Ricoh specific, follow the scsi2 standard ones */ 348141cc406Sopenharmony_ci SANE_Byte byte1; 349141cc406Sopenharmony_ci SANE_Byte byte2; 350141cc406Sopenharmony_ci SANE_Byte mrif_filtering_gamma_id; 351141cc406Sopenharmony_ci SANE_Byte byte3; 352141cc406Sopenharmony_ci SANE_Byte byte4; 353141cc406Sopenharmony_ci SANE_Byte binary_filter; 354141cc406Sopenharmony_ci SANE_Byte reserved2[18]; 355141cc406Sopenharmony_ci 356141cc406Sopenharmony_ci SANE_Byte reserved3[256]; 357141cc406Sopenharmony_ci 358141cc406Sopenharmony_ci}; 359141cc406Sopenharmony_ci 360141cc406Sopenharmony_cistruct measurements_units_page { 361141cc406Sopenharmony_ci SANE_Byte page_code; /* 0x03 */ 362141cc406Sopenharmony_ci SANE_Byte parameter_length; /* 0x06 */ 363141cc406Sopenharmony_ci SANE_Byte bmu; 364141cc406Sopenharmony_ci SANE_Byte res1; 365141cc406Sopenharmony_ci SANE_Byte mud[2]; 366141cc406Sopenharmony_ci SANE_Byte res2[2]; /* anybody know what `COH' may mean ??? */ 367141cc406Sopenharmony_ci/* next 4 lines by mf */ 368141cc406Sopenharmony_ci SANE_Byte adf_page_code; 369141cc406Sopenharmony_ci SANE_Byte adf_parameter_length; 370141cc406Sopenharmony_ci SANE_Byte adf_control; 371141cc406Sopenharmony_ci SANE_Byte res3[5]; 372141cc406Sopenharmony_ci}; 373141cc406Sopenharmony_ci 374141cc406Sopenharmony_cistruct mode_pages { 375141cc406Sopenharmony_ci SANE_Byte page_code; 376141cc406Sopenharmony_ci SANE_Byte parameter_length; 377141cc406Sopenharmony_ci SANE_Byte rest[14]; /* modified by mf; it was 6; see above */ 378141cc406Sopenharmony_ci#if 0 379141cc406Sopenharmony_ci SANE_Byte more_pages[243]; /* maximum size 255 bytes (incl header) */ 380141cc406Sopenharmony_ci#endif 381141cc406Sopenharmony_ci}; 382141cc406Sopenharmony_ci 383141cc406Sopenharmony_ci 384141cc406Sopenharmony_ci#endif /* ibm_h */ 385