2019-06-02 08:47:26 +00:00
 /* sane - Scanner Access Now Easy.
2005-06-27 20:07:45 +00:00
Copyright ( C ) 2003 Oliver Rauch
Copyright ( C ) 2003 , 2004 Henning Meier - Geinitz < henning @ meier - geinitz . de >
Copyright ( C ) 2004 , 2005 Gerhard Jaeger < gerhard @ gjaeger . de >
2016-02-12 07:11:20 +00:00
Copyright ( C ) 2004 - 2013 St é phane Voltz < stef . dev @ free . fr >
2009-02-27 12:37:16 +00:00
Copyright ( C ) 2005 - 2009 Pierre Willenbrock < pierre @ pirsoft . dnsalias . org >
2006-03-27 14:41:30 +00:00
Copyright ( C ) 2006 Laurent Charpentier < laurent_pubs @ yahoo . com >
2005-06-27 20:07:45 +00:00
Parts of the structs have been taken from the gt68xx backend by
Sergey Vlasov < vsu @ altlinux . ru > et al .
2013-12-16 04:45:31 +00:00
2005-06-27 20:07:45 +00:00
This file is part of the SANE package .
2013-12-16 04:45:31 +00:00
2005-06-27 20:07:45 +00:00
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation ; either version 2 of the
License , or ( at your option ) any later version .
2013-12-16 04:45:31 +00:00
2005-06-27 20:07:45 +00:00
This program is distributed in the hope that it will be useful , but
WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
General Public License for more details .
2013-12-16 04:45:31 +00:00
2005-06-27 20:07:45 +00:00
You should have received a copy of the GNU General Public License
along with this program ; if not , write to the Free Software
Foundation , Inc . , 59 Temple Place - Suite 330 , Boston ,
MA 02111 - 1307 , USA .
2013-12-16 04:45:31 +00:00
2005-06-27 20:07:45 +00:00
As a special exception , the authors of SANE give permission for
additional uses of the libraries contained in this release of SANE .
2013-12-16 04:45:31 +00:00
2005-06-27 20:07:45 +00:00
The exception is that , if you link a SANE library with other files
to produce an executable , this does not by itself cause the
resulting executable to be covered by the GNU General Public
License . Your use of that executable is in no way restricted on
account of linking the SANE library code into it .
2013-12-16 04:45:31 +00:00
2005-06-27 20:07:45 +00:00
This exception does not , however , invalidate any other reasons why
the executable file might be covered by the GNU General Public
License .
2013-12-16 04:45:31 +00:00
2005-06-27 20:07:45 +00:00
If you submit changes to SANE to the maintainers to be included in
a subsequent release , you agree by submitting the changes that
those changes may be distributed with this exception intact .
2013-12-16 04:45:31 +00:00
2005-06-27 20:07:45 +00:00
If you write modifications of your own for SANE , it is your choice
whether to permit this exception to apply to your modifications .
2013-12-16 04:45:31 +00:00
If you do not wish that , delete this exception notice .
2005-06-27 20:07:45 +00:00
*/
# ifndef GENESYS_LOW_H
# define GENESYS_LOW_H
2011-11-02 07:33:45 +00:00
# include "../include/sane/config.h"
# include <errno.h>
# include <string.h>
# include <stdlib.h>
# include <unistd.h>
# include <math.h>
2005-06-27 20:07:45 +00:00
# include <stddef.h>
2009-07-09 05:54:58 +00:00
# ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
# endif
2011-11-01 15:10:07 +00:00
# ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
# endif
2013-12-16 04:45:31 +00:00
# ifdef HAVE_MKDIR
2011-11-03 21:47:10 +00:00
# include <sys/stat.h>
# include <sys/types.h>
# endif
2011-11-02 07:33:45 +00:00
2005-06-27 20:07:45 +00:00
# include "../include/sane/sane.h"
2011-11-02 07:33:45 +00:00
# include "../include/sane/sanei.h"
# include "../include/sane/saneopts.h"
# include "../include/sane/sanei_backend.h"
# include "../include/sane/sanei_usb.h"
# include "../include/_stdint.h"
2005-06-27 20:07:45 +00:00
2019-10-01 05:42:08 +00:00
# include "device.h"
# include "enums.h"
# include "error.h"
2019-11-02 15:13:15 +00:00
# include "fwd.h"
2019-10-26 09:38:43 +00:00
# include "usb_device.h"
2019-10-01 05:42:08 +00:00
# include "sensor.h"
# include "serialize.h"
# include "settings.h"
2019-11-23 10:38:47 +00:00
# include "static_init.h"
2019-11-30 17:06:44 +00:00
# include "status.h"
2019-10-01 05:42:08 +00:00
# include "register.h"
2019-07-05 23:10:04 +00:00
2019-05-25 08:15:26 +00:00
# include <algorithm>
# include <array>
2019-05-25 08:15:28 +00:00
# include <cstring>
2019-05-25 08:15:26 +00:00
# include <functional>
2019-07-22 23:00:42 +00:00
# include <iostream>
2019-10-26 10:42:45 +00:00
# include <sstream>
2019-06-08 11:04:14 +00:00
# include <limits>
2019-05-25 07:03:14 +00:00
# include <memory>
# include <stdexcept>
2019-05-25 08:15:42 +00:00
# include <string>
2019-05-25 08:15:26 +00:00
# include <vector>
2019-05-25 07:03:14 +00:00
2012-12-09 14:41:06 +00:00
# define GENESYS_RED 0
# define GENESYS_GREEN 1
# define GENESYS_BLUE 2
2005-06-27 20:07:45 +00:00
/* Flags */
2012-10-24 19:28:42 +00:00
# define GENESYS_FLAG_UNTESTED (1 << 0) /**< Print a warning for these scanners */
# define GENESYS_FLAG_14BIT_GAMMA (1 << 1) /**< use 14bit Gamma table instead of 12 */
2010-02-16 06:24:56 +00:00
# define GENESYS_FLAG_XPA (1 << 3)
2012-10-24 19:28:42 +00:00
# define GENESYS_FLAG_SKIP_WARMUP (1 << 4) /**< skip genesys_warmup() */
2011-11-02 07:33:45 +00:00
/** @brief offset calibration flag
* signals that the scanner does offset calibration . In this case off_calibration ( ) and
2013-12-16 04:45:31 +00:00
* coarse_gain_calibration ( ) functions must be implemented
2011-11-02 07:33:45 +00:00
*/
# define GENESYS_FLAG_OFFSET_CALIBRATION (1 << 5)
2012-10-24 19:28:42 +00:00
# define GENESYS_FLAG_SEARCH_START (1 << 6) /**< do start search before scanning */
2013-12-16 04:45:31 +00:00
# define GENESYS_FLAG_REPARK (1 << 7) / **< repark head (and check for lock) by
2005-06-27 20:07:45 +00:00
moving without scanning */
2012-10-24 19:28:42 +00:00
# define GENESYS_FLAG_DARK_CALIBRATION (1 << 8) /**< do dark calibration */
# define GENESYS_FLAG_STAGGERED_LINE (1 << 9) /**< pixel columns are shifted vertically for hi-res modes */
2005-06-27 20:07:45 +00:00
2012-10-24 19:28:42 +00:00
# define GENESYS_FLAG_MUST_WAIT (1 << 10) /**< tells wether the scanner must wait for the head when parking */
2005-11-19 22:51:01 +00:00
2012-10-24 19:28:42 +00:00
# define GENESYS_FLAG_HAS_UTA (1 << 11) /**< scanner has a transparency adapter */
2005-11-19 22:51:01 +00:00
2012-10-24 19:28:42 +00:00
# define GENESYS_FLAG_DARK_WHITE_CALIBRATION (1 << 12) /**< yet another calibration method. does white and dark shading in one run, depending on a black and a white strip*/
# define GENESYS_FLAG_CUSTOM_GAMMA (1 << 13) /**< allow custom gamma tables */
# define GENESYS_FLAG_NO_CALIBRATION (1 << 14) /**< allow scanners to use skip the calibration, needed for sheetfed scanners */
# define GENESYS_FLAG_SIS_SENSOR (1 << 16) /**< handling of multi-segments sensors in software */
# define GENESYS_FLAG_SHADING_NO_MOVE (1 << 17) /**< scanner doesn't move sensor during shading calibration */
# define GENESYS_FLAG_SHADING_REPARK (1 << 18) /**< repark head between shading scans */
# define GENESYS_FLAG_FULL_HWDPI_MODE (1 << 19) /**< scanner always use maximum hw dpi to setup the sensor */
2019-06-08 11:03:55 +00:00
// scanner has infrared transparency scanning capability
# define GENESYS_FLAG_HAS_UTA_INFRARED (1 << 20)
2019-09-18 00:54:52 +00:00
// scanner calibration is handled on the host side
# define GENESYS_FLAG_CALIBRATION_HOST_SIDE (1 << 21)
2019-10-05 06:01:32 +00:00
# define GENESYS_FLAG_16BIT_DATA_INVERTED (1 << 22)
2009-01-19 05:46:43 +00:00
2012-10-24 19:28:42 +00:00
# define GENESYS_HAS_NO_BUTTONS 0 /**< scanner has no supported button */
# define GENESYS_HAS_SCAN_SW (1 << 0) /**< scanner has SCAN button */
# define GENESYS_HAS_FILE_SW (1 << 1) /**< scanner has FILE button */
# define GENESYS_HAS_COPY_SW (1 << 2) /**< scanner has COPY button */
# define GENESYS_HAS_EMAIL_SW (1 << 3) /**< scanner has EMAIL button */
# define GENESYS_HAS_PAGE_LOADED_SW (1 << 4) /**< scanner has paper in detection */
# define GENESYS_HAS_OCR_SW (1 << 5) /**< scanner has OCR button */
# define GENESYS_HAS_POWER_SW (1 << 6) /**< scanner has power button */
# define GENESYS_HAS_CALIBRATE (1 << 7) /**< scanner has 'calibrate' software button to start calibration */
2013-01-31 05:12:09 +00:00
# define GENESYS_HAS_EXTRA_SW (1 << 8) /**< scanner has extra function button */
2009-01-18 14:20:55 +00:00
2005-06-27 20:07:45 +00:00
/* USB control message values */
# define REQUEST_TYPE_IN (USB_TYPE_VENDOR | USB_DIR_IN)
# define REQUEST_TYPE_OUT (USB_TYPE_VENDOR | USB_DIR_OUT)
# define REQUEST_REGISTER 0x0c
# define REQUEST_BUFFER 0x04
# define VALUE_BUFFER 0x82
# define VALUE_SET_REGISTER 0x83
# define VALUE_READ_REGISTER 0x84
# define VALUE_WRITE_REGISTER 0x85
# define VALUE_INIT 0x87
# define GPIO_OUTPUT_ENABLE 0x89
# define GPIO_READ 0x8a
# define GPIO_WRITE 0x8b
2010-04-25 19:32:44 +00:00
# define VALUE_BUF_ENDACCESS 0x8c
# define VALUE_GET_REGISTER 0x8e
2005-06-27 20:07:45 +00:00
# define INDEX 0x00
/* todo: used?
# define VALUE_READ_STATUS 0x86
*/
/* Read/write bulk data/registers */
# define BULK_OUT 0x01
# define BULK_IN 0x00
# define BULK_RAM 0x00
# define BULK_REGISTER 0x11
# define BULKOUT_MAXSIZE 0xF000
/* AFE values */
# define AFE_INIT 1
# define AFE_SET 2
# define AFE_POWER_SAVE 4
2010-04-25 19:32:44 +00:00
# define LOWORD(x) ((uint16_t)((x) & 0xffff))
# define HIWORD(x) ((uint16_t)((x) >> 16))
2009-02-26 03:15:43 +00:00
# define LOBYTE(x) ((uint8_t)((x) & 0xFF))
# define HIBYTE(x) ((uint8_t)((x) >> 8))
2005-06-27 20:07:45 +00:00
/* Global constants */
2010-11-06 20:12:56 +00:00
/* TODO: emove this leftover of early backend days */
2005-06-27 20:07:45 +00:00
# define MOTOR_SPEED_MAX 350
# define DARK_VALUE 0
# define MAX_RESOLUTIONS 13
# define MAX_DPI 4
2019-10-02 09:01:28 +00:00
namespace genesys {
2019-07-20 06:16:33 +00:00
struct Genesys_USB_Device_Entry {
Genesys_USB_Device_Entry ( unsigned v , unsigned p , const Genesys_Model & m ) :
vendor ( v ) , product ( p ) , model ( m )
{ }
// USB vendor identifier
2019-10-26 10:42:48 +00:00
std : : uint16_t vendor ;
2019-07-20 06:16:33 +00:00
// USB product identifier
2019-10-26 10:42:48 +00:00
std : : uint16_t product ;
2019-07-20 06:16:33 +00:00
// Scanner model information
Genesys_Model model ;
} ;
2005-06-27 20:07:45 +00:00
2011-02-16 06:13:01 +00:00
/**
* structure for motor database
*/
2019-08-04 15:21:08 +00:00
struct Motor_Profile
{
2019-09-30 10:52:03 +00:00
MotorId motor_id ;
2012-10-24 19:28:42 +00:00
int exposure ; /**< exposure for the slope table */
2019-09-30 10:52:04 +00:00
StepType step_type ; // default step type for given exposure
2019-05-18 11:56:02 +00:00
uint32_t * table ; // 0-terminated slope table at full step (i.e. step_type == 0)
2019-08-04 15:21:08 +00:00
} ;
2019-11-23 10:38:48 +00:00
extern StaticInit < std : : vector < Motor_Profile > > gl843_motor_profiles ;
extern StaticInit < std : : vector < Motor_Profile > > gl846_motor_profiles ;
extern StaticInit < std : : vector < Motor_Profile > > gl847_motor_profiles ;
extern StaticInit < std : : vector < Motor_Profile > > gl124_motor_profiles ;
2011-02-16 06:13:01 +00:00
2019-11-23 10:38:46 +00:00
constexpr unsigned SLOPE_TABLE_SIZE = 1024 ;
2011-02-16 06:13:01 +00:00
2005-06-27 20:07:45 +00:00
/*--------------------------------------------------------------------------*/
/* common functions needed by low level specific functions */
/*--------------------------------------------------------------------------*/
2019-06-02 08:47:26 +00:00
inline GenesysRegister * sanei_genesys_get_address ( Genesys_Register_Set * regs , uint16_t addr )
{
auto * ret = regs - > find_reg_address ( addr ) ;
if ( ret = = nullptr ) {
DBG ( DBG_error , " %s: failed to find address for register 0x%02x, crash expected ! \n " ,
__func__ , addr ) ;
}
return ret ;
}
2005-06-27 20:07:45 +00:00
2019-07-14 20:40:57 +00:00
extern void sanei_genesys_init_cmd_set ( Genesys_Device * dev ) ;
2010-11-06 20:12:56 +00:00
2019-11-30 17:06:45 +00:00
// reads the status of the scanner
2019-11-30 17:06:44 +00:00
Status scanner_read_status ( Genesys_Device & dev ) ;
2010-11-06 20:12:56 +00:00
2019-11-30 17:06:45 +00:00
// reads the status of the scanner reliably. This is done by reading the status twice. The first
// read sometimes returns the home sensor as engaged when this is not true.
Status scanner_read_reliable_status ( Genesys_Device & dev ) ;
2019-11-30 17:06:46 +00:00
// reads and prints the scanner status
void scanner_read_print_status ( Genesys_Device & dev ) ;
void debug_print_status ( DebugMessageHelper & dbg , Status status ) ;
2010-11-06 20:12:56 +00:00
2019-07-14 20:40:50 +00:00
extern void sanei_genesys_write_ahb ( Genesys_Device * dev , uint32_t addr , uint32_t size ,
uint8_t * data ) ;
2005-06-27 20:07:45 +00:00
extern void sanei_genesys_init_structs ( Genesys_Device * dev ) ;
2019-06-02 08:47:51 +00:00
const Genesys_Sensor & sanei_genesys_find_sensor_any ( Genesys_Device * dev ) ;
2019-10-13 03:18:50 +00:00
const Genesys_Sensor & sanei_genesys_find_sensor ( Genesys_Device * dev , unsigned dpi ,
unsigned channels , ScanMethod scan_method ) ;
2019-09-12 20:48:16 +00:00
bool sanei_genesys_has_sensor ( Genesys_Device * dev , unsigned dpi , unsigned channels ,
ScanMethod scan_method ) ;
2019-10-13 03:18:50 +00:00
Genesys_Sensor & sanei_genesys_find_sensor_for_write ( Genesys_Device * dev , unsigned dpi ,
unsigned channels , ScanMethod scan_method ) ;
2019-06-02 08:47:51 +00:00
2019-08-03 23:48:29 +00:00
std : : vector < std : : reference_wrapper < const Genesys_Sensor > >
sanei_genesys_find_sensors_all ( Genesys_Device * dev , ScanMethod scan_method ) ;
std : : vector < std : : reference_wrapper < Genesys_Sensor > >
sanei_genesys_find_sensors_all_for_write ( Genesys_Device * dev , ScanMethod scan_method ) ;
2019-07-20 08:01:50 +00:00
extern void sanei_genesys_init_shading_data ( Genesys_Device * dev , const Genesys_Sensor & sensor ,
int pixels_per_line ) ;
2005-06-27 20:07:45 +00:00
2019-07-14 20:40:49 +00:00
extern void sanei_genesys_read_valid_words ( Genesys_Device * dev , unsigned int * steps ) ;
2009-01-19 05:46:43 +00:00
2019-07-14 20:40:48 +00:00
extern void sanei_genesys_read_scancnt ( Genesys_Device * dev , unsigned int * steps ) ;
2009-12-09 19:52:29 +00:00
2019-07-14 20:40:52 +00:00
extern void sanei_genesys_read_feed_steps ( Genesys_Device * dev , unsigned int * steps ) ;
2005-06-27 20:07:45 +00:00
2019-06-08 11:04:24 +00:00
void sanei_genesys_set_lamp_power ( Genesys_Device * dev , const Genesys_Sensor & sensor ,
Genesys_Register_Set & regs , bool set ) ;
2019-06-08 11:04:25 +00:00
void sanei_genesys_set_motor_power ( Genesys_Register_Set & regs , bool set ) ;
2019-10-17 19:30:15 +00:00
bool should_enable_gamma ( const ScanSession & session , const Genesys_Sensor & sensor ) ;
2019-08-04 09:01:51 +00:00
/** Calculates the values of the Z{1,2}MOD registers. They are a phase correction to synchronize
with the line clock during acceleration and deceleration .
two_table is true if moving is done by two tables , false otherwise .
acceleration_steps is the number of steps for acceleration , i . e . the number written to
REG_STEPNO .
move_steps number of steps to move , i . e . the number written to REG_FEEDL .
buffer_acceleration_steps , the number of steps for acceleration when buffer condition is met ,
i . e . the number written to REG_FWDSTEP .
*/
2019-10-01 05:18:45 +00:00
void sanei_genesys_calculate_zmod ( bool two_table ,
2019-08-04 09:01:51 +00:00
uint32_t exposure_time ,
const std : : vector < uint16_t > & slope_table ,
unsigned acceleration_steps ,
unsigned move_steps ,
unsigned buffer_acceleration_steps ,
uint32_t * out_z1 , uint32_t * out_z2 ) ;
2005-06-27 20:07:45 +00:00
2019-07-14 20:40:42 +00:00
extern void sanei_genesys_set_buffer_address ( Genesys_Device * dev , uint32_t addr ) ;
2005-06-27 20:07:45 +00:00
2019-10-26 09:38:40 +00:00
unsigned sanei_genesys_get_bulk_max_size ( AsicType asic_type ) ;
2005-06-27 20:07:45 +00:00
2019-11-23 10:38:42 +00:00
SANE_Int sanei_genesys_exposure_time2 ( Genesys_Device * dev , float ydpi , StepType step_type ,
2019-08-04 09:01:49 +00:00
int endpixel , int led_exposure ) ;
2005-11-19 22:51:01 +00:00
2019-08-04 09:01:50 +00:00
SANE_Int sanei_genesys_generate_slope_table ( std : : vector < uint16_t > & slope_table , unsigned int max_steps ,
2009-02-26 03:15:43 +00:00
unsigned int use_steps , uint16_t stop_at ,
uint16_t vstart , uint16_t vend ,
2009-01-19 05:46:43 +00:00
unsigned int steps , double g ,
unsigned int * used_steps , unsigned int * vfinal ) ;
2005-06-27 20:07:45 +00:00
2019-11-23 10:38:41 +00:00
SANE_Int sanei_genesys_create_slope_table3 ( const Genesys_Motor & motor ,
2019-08-04 09:01:50 +00:00
std : : vector < uint16_t > & slope_table , int max_step ,
2005-11-19 22:51:01 +00:00
unsigned int use_steps ,
2019-11-23 10:38:42 +00:00
StepType step_type , int exposure_time ,
2019-11-23 10:38:41 +00:00
unsigned yres ,
2005-11-19 22:51:01 +00:00
unsigned int * used_steps ,
2019-08-04 09:01:49 +00:00
unsigned int * final_exposure ) ;
2005-11-19 22:51:01 +00:00
2019-06-02 08:47:49 +00:00
void sanei_genesys_create_default_gamma_table ( Genesys_Device * dev ,
std : : vector < uint16_t > & gamma_table , float gamma ) ;
2019-06-02 08:47:50 +00:00
std : : vector < uint16_t > get_gamma_table ( Genesys_Device * dev , const Genesys_Sensor & sensor ,
int color ) ;
2019-07-20 08:02:06 +00:00
void sanei_genesys_send_gamma_table ( Genesys_Device * dev , const Genesys_Sensor & sensor ) ;
2005-06-27 20:07:45 +00:00
2019-07-20 08:01:57 +00:00
extern void sanei_genesys_stop_motor ( Genesys_Device * dev ) ;
2005-06-27 20:07:45 +00:00
2019-07-20 08:02:12 +00:00
extern void sanei_genesys_search_reference_point ( Genesys_Device * dev , Genesys_Sensor & sensor ,
2019-08-03 23:48:28 +00:00
const uint8_t * src_data , int start_pixel , int dpi ,
int width , int height ) ;
2005-06-27 20:07:45 +00:00
2019-10-01 12:41:24 +00:00
extern void sanei_genesys_write_file ( const char * filename , const std : : uint8_t * data ,
std : : size_t length ) ;
2019-05-11 09:12:29 +00:00
2019-09-17 14:20:59 +00:00
extern void sanei_genesys_write_pnm_file ( const char * filename , const std : : uint8_t * data , int depth ,
2019-07-20 08:02:10 +00:00
int channels , int pixels_per_line , int lines ) ;
2005-06-27 20:07:45 +00:00
2019-09-17 14:20:59 +00:00
void sanei_genesys_write_pnm_file ( const char * filename , const Image & image ) ;
2019-09-16 06:50:11 +00:00
extern void sanei_genesys_write_pnm_file16 ( const char * filename , const uint16_t * data , unsigned channels ,
2019-08-17 07:53:55 +00:00
unsigned pixels_per_line , unsigned lines ) ;
2019-10-01 05:18:46 +00:00
void wait_until_buffer_non_empty ( Genesys_Device * dev , bool check_status_twice = false ) ;
2005-06-27 20:07:45 +00:00
2019-07-20 08:02:15 +00:00
extern void sanei_genesys_read_data_from_scanner ( Genesys_Device * dev , uint8_t * data , size_t size ) ;
2005-06-27 20:07:45 +00:00
2019-09-17 14:21:00 +00:00
Image read_unshuffled_image_from_scanner ( Genesys_Device * dev , const ScanSession & session ,
std : : size_t total_bytes ) ;
2019-06-02 08:47:31 +00:00
inline void sanei_genesys_set_exposure ( Genesys_Register_Set & regs , const SensorExposure & exposure )
{
regs . set8 ( 0x10 , ( exposure . red > > 8 ) & 0xff ) ;
regs . set8 ( 0x11 , exposure . red & 0xff ) ;
regs . set8 ( 0x12 , ( exposure . green > > 8 ) & 0xff ) ;
regs . set8 ( 0x13 , exposure . green & 0xff ) ;
regs . set8 ( 0x14 , ( exposure . blue > > 8 ) & 0xff ) ;
regs . set8 ( 0x15 , exposure . blue & 0xff ) ;
}
2019-08-17 07:21:02 +00:00
void sanei_genesys_set_dpihw ( Genesys_Register_Set & regs , const Genesys_Sensor & sensor ,
unsigned dpihw ) ;
2019-06-02 08:47:31 +00:00
inline uint16_t sanei_genesys_fixup_exposure_value ( uint16_t value )
{
if ( ( value & 0xff00 ) = = 0 ) {
value | = 0x100 ;
}
if ( ( value & 0x00ff ) = = 0 ) {
value | = 0x1 ;
}
return value ;
}
inline SensorExposure sanei_genesys_fixup_exposure ( SensorExposure exposure )
{
exposure . red = sanei_genesys_fixup_exposure_value ( exposure . red ) ;
exposure . green = sanei_genesys_fixup_exposure_value ( exposure . green ) ;
exposure . blue = sanei_genesys_fixup_exposure_value ( exposure . blue ) ;
return exposure ;
}
2019-11-30 17:06:43 +00:00
bool get_registers_gain4_bit ( AsicType asic_type , const Genesys_Register_Set & regs ) ;
2019-07-14 20:40:56 +00:00
extern void sanei_genesys_wait_for_home ( Genesys_Device * dev ) ;
2011-01-12 19:51:32 +00:00
2019-10-01 05:18:45 +00:00
extern void sanei_genesys_asic_init ( Genesys_Device * dev , bool cold ) ;
2013-01-28 21:04:37 +00:00
2019-11-23 10:38:50 +00:00
void scanner_start_action ( Genesys_Device & dev , bool start_motor ) ;
2019-11-23 10:38:48 +00:00
const Motor_Profile & sanei_genesys_get_motor_profile ( const std : : vector < Motor_Profile > & motors ,
MotorId motor_id , int exposure ) ;
2011-02-16 06:13:01 +00:00
2019-11-23 10:38:49 +00:00
MotorSlopeTable sanei_genesys_slope_table ( int dpi , int exposure , int base_dpi ,
int factor , const Motor_Profile & motor_profile ) ;
2011-02-16 06:13:01 +00:00
2011-08-23 05:20:52 +00:00
/** @brief find lowest motor resolution for the device.
* Parses the resolution list for motor and
* returns the lowest value .
2012-10-24 19:28:42 +00:00
* @ param dev for which to find the lowest motor resolution
2011-08-23 05:20:52 +00:00
* @ return the lowest available motor resolution for the device
*/
2011-02-16 06:13:01 +00:00
extern
int sanei_genesys_get_lowest_ydpi ( Genesys_Device * dev ) ;
2011-08-23 05:20:52 +00:00
/** @brief find lowest resolution for the device.
* Parses the resolution list for motor and sensor and
* returns the lowest value .
2012-10-24 19:28:42 +00:00
* @ param dev for which to find the lowest resolution
2011-08-23 05:20:52 +00:00
* @ return the lowest available resolution for the device
*/
extern
int sanei_genesys_get_lowest_dpi ( Genesys_Device * dev ) ;
2019-11-10 08:32:11 +00:00
bool sanei_genesys_is_compatible_calibration ( Genesys_Device * dev ,
const ScanSession & session ,
const Genesys_Calibration_Cache * cache ,
bool for_overwrite ) ;
2011-07-31 20:09:46 +00:00
2019-07-20 08:02:39 +00:00
extern void sanei_genesys_load_lut ( unsigned char * lut ,
int in_bits , int out_bits ,
int out_min , int out_max ,
int slope , int offset ) ;
2013-08-11 19:15:25 +00:00
2019-07-14 20:40:54 +00:00
extern void sanei_genesys_generate_gamma_buffer ( Genesys_Device * dev ,
2019-06-02 08:47:51 +00:00
const Genesys_Sensor & sensor ,
2013-08-11 19:15:25 +00:00
int bits ,
int max ,
int size ,
2019-07-14 20:40:54 +00:00
uint8_t * gamma ) ;
2013-08-11 19:15:25 +00:00
2019-11-10 08:32:06 +00:00
void compute_session ( const Genesys_Device * dev , ScanSession & s , const Genesys_Sensor & sensor ) ;
2019-08-17 08:11:14 +00:00
2019-09-13 08:36:54 +00:00
void build_image_pipeline ( Genesys_Device * dev , const ScanSession & session ) ;
2019-09-13 08:01:47 +00:00
std : : uint8_t compute_frontend_gain ( float value , float target_value ,
FrontendType frontend_type ) ;
2019-09-12 19:40:54 +00:00
const SensorProfile & get_sensor_profile ( AsicType asic_type , const Genesys_Sensor & sensor ,
unsigned dpi , unsigned ccd_size_divisor ) ;
2019-08-18 08:13:01 +00:00
template < class T >
inline T abs_diff ( T a , T b )
{
if ( a < b ) {
return b - a ;
} else {
return a - b ;
}
}
2019-09-12 19:11:20 +00:00
inline uint64_t align_multiple_floor ( uint64_t x , uint64_t multiple )
{
return ( x / multiple ) * multiple ;
}
inline uint64_t align_multiple_ceil ( uint64_t x , uint64_t multiple )
{
return ( ( x + multiple - 1 ) / multiple ) * multiple ;
}
2019-09-12 19:21:51 +00:00
inline uint64_t multiply_by_depth_ceil ( uint64_t pixels , uint64_t depth )
2019-09-12 16:49:50 +00:00
{
if ( depth = = 1 ) {
return ( pixels / 8 ) + ( ( pixels % 8 ) ? 1 : 0 ) ;
} else {
return pixels * ( depth / 8 ) ;
}
}
2019-09-13 08:01:46 +00:00
template < class T >
inline T clamp ( const T & value , const T & lo , const T & hi )
{
if ( value < lo )
return lo ;
if ( value > hi )
return hi ;
return value ;
}
2005-06-27 20:07:45 +00:00
/*---------------------------------------------------------------------------*/
/* ASIC specific functions declarations */
/*---------------------------------------------------------------------------*/
2019-05-25 08:15:27 +00:00
extern StaticInit < std : : vector < Genesys_Sensor > > s_sensors ;
2019-08-17 08:02:37 +00:00
extern StaticInit < SensorProfile > s_fallback_sensor_profile_gl124 ;
2019-08-17 08:02:39 +00:00
extern StaticInit < SensorProfile > s_fallback_sensor_profile_gl846 ;
2019-08-17 08:02:38 +00:00
extern StaticInit < SensorProfile > s_fallback_sensor_profile_gl847 ;
2019-08-04 15:21:06 +00:00
extern StaticInit < std : : vector < Genesys_Frontend > > s_frontends ;
extern StaticInit < std : : vector < Genesys_Gpo > > s_gpo ;
extern StaticInit < std : : vector < Genesys_Motor > > s_motors ;
extern StaticInit < std : : vector < Genesys_USB_Device_Entry > > s_usb_devices ;
2019-05-25 08:15:27 +00:00
void genesys_init_sensor_tables ( ) ;
2019-06-02 08:48:03 +00:00
void genesys_init_frontend_tables ( ) ;
2019-08-04 11:01:50 +00:00
void genesys_init_gpo_tables ( ) ;
2019-08-04 09:01:48 +00:00
void genesys_init_motor_tables ( ) ;
2019-11-23 10:38:48 +00:00
void genesys_init_motor_profile_tables ( ) ;
2019-07-20 06:16:33 +00:00
void genesys_init_usb_device_tables ( ) ;
2019-05-25 08:15:27 +00:00
2019-10-26 10:42:45 +00:00
template < class T >
void debug_dump ( unsigned level , const T & value )
{
std : : stringstream out ;
out < < value ;
DBG ( level , " %s \n " , out . str ( ) . c_str ( ) ) ;
}
2019-06-08 11:03:59 +00:00
2019-10-02 09:01:28 +00:00
} // namespace genesys
2005-06-27 20:07:45 +00:00
# endif /* not GENESYS_LOW_H */