1141cc406Sopenharmony_ci/* sane - Scanner Access Now Easy. 2141cc406Sopenharmony_ci Copyright (C) 1997 Geoffrey T. Dairiki 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 This file is part of a SANE backend for HP Scanners supporting 40141cc406Sopenharmony_ci HP Scanner Control Language (SCL). 41141cc406Sopenharmony_ci*/ 42141cc406Sopenharmony_ci 43141cc406Sopenharmony_ci#ifndef HP_H_INCLUDED 44141cc406Sopenharmony_ci#define HP_H_INCLUDED 45141cc406Sopenharmony_ci#include <limits.h> 46141cc406Sopenharmony_ci#include <sys/types.h> 47141cc406Sopenharmony_ci#include "../include/sane/sane.h" 48141cc406Sopenharmony_ci 49141cc406Sopenharmony_ci#undef BACKEND_NAME 50141cc406Sopenharmony_ci#define BACKEND_NAME hp 51141cc406Sopenharmony_ci#define DEBUG_NOT_STATIC 52141cc406Sopenharmony_ci#include "../include/sane/sanei_debug.h" 53141cc406Sopenharmony_ci 54141cc406Sopenharmony_ci/* FIXME: these should be options? */ 55141cc406Sopenharmony_ci#undef ENABLE_7x12_TONEMAPS 56141cc406Sopenharmony_ci#define ENABLE_16x16_DITHERS 57141cc406Sopenharmony_ci#define ENABLE_10BIT_MATRIXES 58141cc406Sopenharmony_ci 59141cc406Sopenharmony_ci#define FAKE_COLORSEP_MATRIXES 60141cc406Sopenharmony_ci 61141cc406Sopenharmony_ci#undef ENABLE_CUSTOM_MATRIX 62141cc406Sopenharmony_ci 63141cc406Sopenharmony_ci#define HP_CONFIG_FILE STRINGIFY(BACKEND_NAME) ".conf" 64141cc406Sopenharmony_ci 65141cc406Sopenharmony_ci#define DEVPIX_PER_INCH 300.0 66141cc406Sopenharmony_ci#define MM_PER_DEVPIX (MM_PER_INCH / DEVPIX_PER_INCH) 67141cc406Sopenharmony_ci 68141cc406Sopenharmony_ci/* 69141cc406Sopenharmony_ci * Macros for testing return values of functions which 70141cc406Sopenharmony_ci * return SANE_Status types. 71141cc406Sopenharmony_ci */ 72141cc406Sopenharmony_ci#define FAILED(status) (status != SANE_STATUS_GOOD) 73141cc406Sopenharmony_ci#define UNSUPPORTED(status) (status == SANE_STATUS_UNSUPPORTED) 74141cc406Sopenharmony_ci#define RETURN_IF_FAIL(try) do { \ 75141cc406Sopenharmony_ci SANE_Status status = (try); \ 76141cc406Sopenharmony_ci if (FAILED(status)) \ 77141cc406Sopenharmony_ci return status; \ 78141cc406Sopenharmony_ci} while (0) 79141cc406Sopenharmony_ci#define CATCH_RET_FAIL(try, catch) do { \ 80141cc406Sopenharmony_ci SANE_Status status = (try); \ 81141cc406Sopenharmony_ci if (FAILED(status)) { (catch); return status; } \ 82141cc406Sopenharmony_ci} while (0) 83141cc406Sopenharmony_ci 84141cc406Sopenharmony_ci#ifndef DBG_LEVEL 85141cc406Sopenharmony_ci#define DBG_LEVEL PASTE(sanei_debug_, BACKEND_NAME) 86141cc406Sopenharmony_ci#endif 87141cc406Sopenharmony_ci#ifndef NDEBUG 88141cc406Sopenharmony_ci# define DBGDUMP(level, buf, size) \ 89141cc406Sopenharmony_ci do { if (DBG_LEVEL >= (level)) sanei_hp_dbgdump(buf, size); } while (0) 90141cc406Sopenharmony_ci#else 91141cc406Sopenharmony_ci# define DBGDUMP(level, buf, size) 92141cc406Sopenharmony_ci#endif 93141cc406Sopenharmony_ci 94141cc406Sopenharmony_ci 95141cc406Sopenharmony_ci /* 96141cc406Sopenharmony_ci * 97141cc406Sopenharmony_ci */ 98141cc406Sopenharmony_ci 99141cc406Sopenharmony_citypedef unsigned int hp_bool_t; 100141cc406Sopenharmony_citypedef unsigned char hp_byte_t; 101141cc406Sopenharmony_ci 102141cc406Sopenharmony_citypedef enum { HP_CONNECT_SCSI, HP_CONNECT_DEVICE, 103141cc406Sopenharmony_ci HP_CONNECT_PIO, HP_CONNECT_USB, HP_CONNECT_RESERVE } HpConnect; 104141cc406Sopenharmony_ci 105141cc406Sopenharmony_citypedef struct 106141cc406Sopenharmony_ci{ 107141cc406Sopenharmony_ci HpConnect connect; 108141cc406Sopenharmony_ci hp_bool_t got_connect_type; 109141cc406Sopenharmony_ci hp_bool_t use_scsi_request; 110141cc406Sopenharmony_ci hp_bool_t use_image_buffering; 111141cc406Sopenharmony_ci hp_bool_t dumb_read; 112141cc406Sopenharmony_ci} HpDeviceConfig; 113141cc406Sopenharmony_ci 114141cc406Sopenharmony_ci#define HP_SCL_INQID_MIN 10306 115141cc406Sopenharmony_ci#define HP_SCL_INQID_MAX 10971 116141cc406Sopenharmony_ci 117141cc406Sopenharmony_citypedef struct 118141cc406Sopenharmony_ci{ 119141cc406Sopenharmony_ci hp_bool_t checked, is_supported; 120141cc406Sopenharmony_ci int minval, maxval; 121141cc406Sopenharmony_ci} HpSclSupport; 122141cc406Sopenharmony_ci 123141cc406Sopenharmony_citypedef struct 124141cc406Sopenharmony_ci{ /* Flags for simulated commands */ 125141cc406Sopenharmony_ci hp_bool_t sclsimulate[HP_SCL_INQID_MAX - HP_SCL_INQID_MIN + 1]; 126141cc406Sopenharmony_ci hp_bool_t gamma_simulate; 127141cc406Sopenharmony_ci unsigned char brightness_map[256]; /* Map to simulate brightness level */ 128141cc406Sopenharmony_ci unsigned char contrast_map[256]; /* Map to simulate contrast level */ 129141cc406Sopenharmony_ci unsigned char gamma_map[256]; /* Map to simulate custom gamma table */ 130141cc406Sopenharmony_ci} HpSimulate; 131141cc406Sopenharmony_ci 132141cc406Sopenharmony_ci/* Information about a connected device */ 133141cc406Sopenharmony_citypedef struct 134141cc406Sopenharmony_ci{ 135141cc406Sopenharmony_ci char devname[64]; /* unique device name */ 136141cc406Sopenharmony_ci 137141cc406Sopenharmony_ci hp_bool_t config_is_up; /* flag if config-struct is valid */ 138141cc406Sopenharmony_ci HpDeviceConfig config; /* device configuration*/ 139141cc406Sopenharmony_ci /* List of command support */ 140141cc406Sopenharmony_ci HpSclSupport sclsupport[HP_SCL_INQID_MAX - HP_SCL_INQID_MIN + 1]; 141141cc406Sopenharmony_ci 142141cc406Sopenharmony_ci HpSimulate simulate; /* Info about simulations */ 143141cc406Sopenharmony_ci 144141cc406Sopenharmony_ci hp_bool_t unload_after_scan; 145141cc406Sopenharmony_ci int active_xpa; 146141cc406Sopenharmony_ci int max_model; 147141cc406Sopenharmony_ci} HpDeviceInfo; 148141cc406Sopenharmony_ci 149141cc406Sopenharmony_ciHpDeviceInfo *sanei_hp_device_info_get (const char *dev_name); 150141cc406Sopenharmony_ci 151141cc406Sopenharmony_ci/* hp-scl.c */ 152141cc406Sopenharmony_ci#if INT_MAX > 30000 153141cc406Sopenharmony_citypedef int HpScl; 154141cc406Sopenharmony_ci#else 155141cc406Sopenharmony_citypedef long int HpScl; 156141cc406Sopenharmony_ci#endif 157141cc406Sopenharmony_ci 158141cc406Sopenharmony_civoid sanei_hp_init_openfd (void); 159141cc406Sopenharmony_ci 160141cc406Sopenharmony_citypedef struct 161141cc406Sopenharmony_ci{ 162141cc406Sopenharmony_ci int lines; 163141cc406Sopenharmony_ci int bytes_per_line; /* as received from scanner */ 164141cc406Sopenharmony_ci int bits_per_channel; 165141cc406Sopenharmony_ci hp_bool_t out8; /* This flag is set and only set, when data with */ 166141cc406Sopenharmony_ci /* depths > 8 is to be mapped to 8 bit output. */ 167141cc406Sopenharmony_ci hp_bool_t mirror_vertical; 168141cc406Sopenharmony_ci hp_bool_t invert; 169141cc406Sopenharmony_ci HpScl startscan; 170141cc406Sopenharmony_ci} HpProcessData; 171141cc406Sopenharmony_ci 172141cc406Sopenharmony_ci/* hp-option.c */ 173141cc406Sopenharmony_citypedef SANE_Option_Descriptor * HpSaneOption; 174141cc406Sopenharmony_ci 175141cc406Sopenharmony_citypedef const struct hp_choice_s * HpChoice; 176141cc406Sopenharmony_citypedef struct hp_option_s * HpOption; 177141cc406Sopenharmony_citypedef const struct hp_option_descriptor_s * HpOptionDescriptor; 178141cc406Sopenharmony_citypedef struct hp_optset_s * HpOptSet; 179141cc406Sopenharmony_ci 180141cc406Sopenharmony_ci/* hp-accessor.c */ 181141cc406Sopenharmony_citypedef struct hp_data_s * HpData; 182141cc406Sopenharmony_citypedef struct hp_accessor_s * HpAccessor; 183141cc406Sopenharmony_citypedef struct hp_accessor_vector_s * HpAccessorVector; 184141cc406Sopenharmony_citypedef struct hp_accessor_choice_s * HpAccessorChoice; 185141cc406Sopenharmony_ci 186141cc406Sopenharmony_ci/* hp-device.c */ 187141cc406Sopenharmony_citypedef struct hp_device_s * HpDevice; 188141cc406Sopenharmony_cihp_bool_t sanei_hp_device_simulate_get (const char *devname, HpScl scl); 189141cc406Sopenharmony_ciHpDevice sanei_hp_device_get (const char *dev_name); 190141cc406Sopenharmony_ci 191141cc406Sopenharmony_ci/* hp-handle.c */ 192141cc406Sopenharmony_citypedef struct hp_handle_s * HpHandle; 193141cc406Sopenharmony_ci 194141cc406Sopenharmony_ci/* hp-scsi.c */ 195141cc406Sopenharmony_citypedef struct hp_scsi_s * HpScsi; 196141cc406Sopenharmony_ci 197141cc406Sopenharmony_ci/* hp-scl.c */ 198141cc406Sopenharmony_cihp_bool_t sanei_hp_is_active_xpa (HpScsi scsi); 199141cc406Sopenharmony_ciint sanei_hp_get_max_model (HpScsi scsi); 200141cc406Sopenharmony_ciint sanei_hp_is_flatbed_adf (HpScsi scsi); 201141cc406Sopenharmony_ciHpConnect sanei_hp_get_connect (const char *devname); 202141cc406Sopenharmony_ciHpConnect sanei_hp_scsi_get_connect (HpScsi this); 203141cc406Sopenharmony_ci 204141cc406Sopenharmony_ci/* hp.c */ 205141cc406Sopenharmony_ci#ifndef NDEBUG 206141cc406Sopenharmony_civoid sanei_hp_dbgdump (const void * bufp, size_t len); 207141cc406Sopenharmony_ci#endif 208141cc406Sopenharmony_ci 209141cc406Sopenharmony_ci/* hp-hpmem.c */ 210141cc406Sopenharmony_civoid * sanei_hp_alloc(size_t sz); 211141cc406Sopenharmony_civoid * sanei_hp_allocz(size_t sz); 212141cc406Sopenharmony_civoid * sanei_hp_memdup(const void * src, size_t sz); 213141cc406Sopenharmony_cichar * sanei_hp_strdup(const char * str); 214141cc406Sopenharmony_civoid * sanei_hp_realloc(void * ptr, size_t sz); 215141cc406Sopenharmony_civoid sanei_hp_free(void * ptr); 216141cc406Sopenharmony_civoid sanei_hp_free_all(void); 217141cc406Sopenharmony_ci 218141cc406Sopenharmony_ci#endif /* HP_H_INCLUDED */ 219