From 6e9c41a892ed0e0da326e0278b3221ce3f5713b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Mon, 6 Oct 2014 14:00:40 +0200 Subject: Initial import of sane-backends version 1.0.24-1.2 --- backend/artec_eplus48u.h | 596 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 596 insertions(+) create mode 100644 backend/artec_eplus48u.h (limited to 'backend/artec_eplus48u.h') diff --git a/backend/artec_eplus48u.h b/backend/artec_eplus48u.h new file mode 100644 index 0000000..cc30214 --- /dev/null +++ b/backend/artec_eplus48u.h @@ -0,0 +1,596 @@ +#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; /**