#ifndef ARTEC48U_H #define ARTEC48U_H #include "../include/sane/sane.h" #include "../include/sane/sanei.h" #include "../include/sane/saneopts.h" #include #ifdef HAVE_SYS_IPC_H #include #endif #include #include #include #include "../include/sane/sanei_usb.h" #include "../include/sane/sanei_thread.h" #define _MAX_ID_LEN 20 /*Uncomment next line for button support. This actually isn't supported by the frontends. */ /*#define ARTEC48U_USE_BUTTONS 1*/ #define ARTEC48U_PACKET_SIZE 64 #define DECLARE_FUNCTION_NAME(name) \ IF_DBG ( static const char function_name[] = name; ) typedef SANE_Byte Artec48U_Packet[ARTEC48U_PACKET_SIZE]; #define XDBG(args) do { IF_DBG ( DBG args ); } while (0) /* calculate the minimum/maximum values */ #define MIN(a, b) (((a) < (b)) ? (a) : (b)) #define MAX(a, b) (((a) > (b)) ? (a) : (b)) /* return the lower/upper 8 bits of a 16 bit word */ #define HIBYTE(w) ((SANE_Byte)(((SANE_Word)(w) >> 8) & 0xFF)) #define LOBYTE(w) ((SANE_Byte)(w)) #define CHECK_DEV_NOT_NULL(dev, func_name) \ do { \ if (!(dev)) \ { \ XDBG ((3, "%s: BUG: NULL device\n", (func_name))); \ return SANE_STATUS_INVAL; \ } \ } while (SANE_FALSE) /** Check that the device is open. * * @param dev Pointer to the device object (Artec48U_Device). * @param func_name Function name (for use in debug messages). */ #define CHECK_DEV_OPEN(dev, func_name) \ do { \ CHECK_DEV_NOT_NULL ((dev), (func_name)); \ if ((dev)->fd == -1) \ { \ XDBG ((3, "%s: BUG: device %p not open\n", (func_name), (void*)(dev)));\ return SANE_STATUS_INVAL; \ } \ } while (SANE_FALSE) #define CHECK_DEV_ACTIVE(dev,func_name) \ do { \ CHECK_DEV_OPEN ((dev), (func_name)); \ if (!(dev)->active) \ { \ XDBG ((3, "%s: BUG: device %p not active\n", \ (func_name), (void*)(dev))); \ return SANE_STATUS_INVAL; \ } \ } while (SANE_FALSE) typedef struct Artec48U_Device Artec48U_Device; typedef struct Artec48U_Scan_Request Artec48U_Scan_Request; typedef struct Artec48U_Scanner Artec48U_Scanner; typedef struct Artec48U_Scan_Parameters Artec48U_Scan_Parameters; typedef struct Artec48U_AFE_Parameters Artec48U_AFE_Parameters; typedef struct Artec48U_Exposure_Parameters Artec48U_Exposure_Parameters; typedef struct Artec48U_Line_Reader Artec48U_Line_Reader; typedef struct Artec48U_Delay_Buffer Artec48U_Delay_Buffer; enum artec_options { OPT_NUM_OPTS = 0, OPT_MODE_GROUP, OPT_SCAN_MODE, OPT_BIT_DEPTH, OPT_BLACK_LEVEL, OPT_RESOLUTION, OPT_ENHANCEMENT_GROUP, OPT_BRIGHTNESS, OPT_CONTRAST, OPT_GAMMA, OPT_GAMMA_R, OPT_GAMMA_G, OPT_GAMMA_B, OPT_DEFAULT_ENHANCEMENTS, OPT_GEOMETRY_GROUP, OPT_TL_X, OPT_TL_Y, OPT_BR_X, OPT_BR_Y, OPT_CALIBRATION_GROUP, OPT_CALIBRATE, OPT_CALIBRATE_SHADING, #ifdef ARTEC48U_USE_BUTTONS OPT_BUTTON_STATE, #endif /* must come last: */ NUM_OPTIONS }; /** Artec48U analog front-end (AFE) parameters. */ struct Artec48U_AFE_Parameters { SANE_Byte r_offset; /**< Red channel offset */ SANE_Byte r_pga; /**< Red channel PGA gain */ SANE_Byte g_offset; /**< Green channel offset (also used for mono) */ SANE_Byte g_pga; /**< Green channel PGA gain (also used for mono) */ SANE_Byte b_offset; /**< Blue channel offset */ SANE_Byte b_pga; /**< Blue channel PGA gain */ }; /** TV9693 exposure time parameters. */ struct Artec48U_Exposure_Parameters { SANE_Int r_time; /**< Red exposure time */ SANE_Int g_time; /**< Red exposure time */ SANE_Int b_time; /**< Red exposure time */ }; struct Artec48U_Device { Artec48U_Device *next; /** Device file descriptor. */ int fd; /** Device activation flag. */ SANE_Bool active; SANE_String_Const name; SANE_Device sane; /** Scanner model data. */ SANE_String_Const firmware_path; double gamma_master; double gamma_r; double gamma_g; double gamma_b; Artec48U_Exposure_Parameters exp_params; Artec48U_AFE_Parameters afe_params; Artec48U_AFE_Parameters artec_48u_afe_params; Artec48U_Exposure_Parameters artec_48u_exposure_params; SANE_Int optical_xdpi; SANE_Int optical_ydpi; SANE_Int base_ydpi; SANE_Int xdpi_offset; /* in optical_xdpi units */ SANE_Int ydpi_offset; /* in optical_ydpi units */ SANE_Int x_size; /* in optical_xdpi units */ SANE_Int y_size; /* in optical_ydpi units */ /* the number of lines, that we move forward before we start reading the shading lines */ int shading_offset; /* the number of lines we read for the black shading buffer */ int shading_lines_b; /* the number of lines we read for the white shading buffer */ int shading_lines_w; SANE_Fixed x_offset, y_offset; SANE_Bool read_active; SANE_Byte *read_buffer; size_t requested_buffer_size; size_t read_pos; size_t read_bytes_in_buffer; size_t read_bytes_left; unsigned int is_epro; unsigned int epro_mult; }; /** Scan parameters for artec48u_device_setup_scan(). * * These parameters describe a low-level scan request; many such requests are * executed during calibration, and they need to have parameters separate from * the main request (Artec48U_Scan_Request). E.g., on the BearPaw 2400 TA the * scan to find the home position is always done at 300dpi 8-bit mono with * fixed width and height, regardless of the high-level scan parameters. */ struct Artec48U_Scan_Parameters { SANE_Int xdpi; /**< Horizontal resolution */ SANE_Int ydpi; /**< Vertical resolution */ SANE_Int depth; /**< Number of bits per channel */ SANE_Bool color; /**< Color mode flag */ SANE_Int pixel_xs; /**< Logical width in pixels */ SANE_Int pixel_ys; /**< Logical height in pixels */ SANE_Int scan_xs; /**< Physical width in pixels */ SANE_Int scan_ys; /**< Physical height in pixels */ SANE_Int scan_bpl; /**< Number of bytes per scan line */ SANE_Bool lineart; /**