2022-11-03 02:55:37 +00:00
# include " hg_scanner.h "
2022-05-30 03:04:26 +00:00
# include "../wrapper/hg_log.h"
2022-05-09 08:59:22 +00:00
# include "sane/sane_option_definitions.h"
2022-08-13 01:29:00 +00:00
# include "scanner_setting.h"
2022-09-23 02:26:04 +00:00
# include "scanner_manager.h"
2022-05-03 03:56:07 +00:00
2022-07-18 08:56:03 +00:00
# if defined(WIN32) || defined(_WIN64)
2022-05-10 00:27:31 +00:00
# include <direct.h>
2022-05-03 03:56:07 +00:00
# endif
2022-12-05 15:01:13 +00:00
# if defined(WIN32) || defined(_WIN64)
static int load_dll ( const wchar_t * path_dll , HMODULE * dll )
{
HMODULE h = LoadLibraryW ( path_dll ) ;
int ret = GetLastError ( ) ;
wchar_t info [ 128 ] = { 0 } ;
swprintf_s ( info , _countof ( info ) - 1 , L " = %d \r \n " , ret ) ;
OutputDebugStringW ( ( L " [TWAIN]Load: " + std : : wstring ( path_dll ) + info ) . c_str ( ) ) ;
if ( ! h & & ret = = ERROR_MOD_NOT_FOUND )
{
std : : wstring dir ( path_dll ) ;
size_t pos = dir . rfind ( L ' \\ ' ) ;
wchar_t path [ MAX_PATH ] = { 0 } ;
GetDllDirectoryW ( _countof ( path ) - 1 , path ) ;
if ( pos ! = std : : wstring : : npos )
dir . erase ( pos ) ;
OutputDebugStringW ( ( L " [TWAIN]Load: try change directory to " + dir + L " \r \n " ) . c_str ( ) ) ;
SetDllDirectoryW ( dir . c_str ( ) ) ;
h = LoadLibraryW ( path_dll ) ;
ret = GetLastError ( ) ;
swprintf_s ( info , _countof ( info ) - 1 , L " = %d \r \n " , ret ) ;
OutputDebugStringW ( ( L " [TWAIN]Load: " + std : : wstring ( path_dll ) + info ) . c_str ( ) ) ;
OutputDebugStringW ( ( L " [TWAIN]Load: restore directory to " + std : : wstring ( path ) + L " \r \n " ) . c_str ( ) ) ;
SetDllDirectoryW ( path ) ;
}
2022-05-03 03:56:07 +00:00
2022-12-05 15:01:13 +00:00
if ( dll )
* dll = h ;
return ret ;
}
static int strToWchar ( string str , wchar_t * s )
{
if ( str . empty ( ) | | ! s )
{
return - 1 ;
}
size_t size = str . length ( ) ;
//获取缓冲区大小,并申请空间,缓冲区大小按字符计算
int len = MultiByteToWideChar ( CP_ACP , 0 , str . c_str ( ) , size , NULL , 0 ) ;
wchar_t * buffer = new wchar_t [ size + 1 ] ;
MultiByteToWideChar ( CP_ACP , 0 , str . c_str ( ) , size , buffer , len ) ;
buffer [ len ] = ' \0 ' ;
wcscpy ( s , buffer ) ;
if ( ! buffer | | ! s )
return - 1 ;
delete [ ] buffer ;
buffer = NULL ;
return 0 ;
}
# endif
2022-05-03 03:56:07 +00:00
static int ui_default_callback ( scanner_handle , int , void * , unsigned int * , void * )
{
return 0 ;
}
2022-09-28 12:00:03 +00:00
static std : : string bmp_821 ( unsigned char * bits /*bits data*/ , int w , int h , int * lbytes /*in/out 行字节*/ , bool line_align_4 /*是否行对齐4字节*/ , int threashold /*黑白像素阈值*/ , bool reverse /*是否反色输出*/ )
2022-05-30 06:46:37 +00:00
{
static unsigned int g_bmp8_pallete [ ] = {
2022-06-28 09:16:03 +00:00
0x00000000 , 0x00800000 , 0x00008000 , 0x00808000 , 0x00000080 , 0x00800080 , 0x00008080 , 0x00c0c0c0 , 0x00c0dcc0 , 0x00a6caf0 , 0x00402000 , 0x00602000 , 0x00802000 , 0x00a02000 , 0x00c02000 , 0x00e02000
, 0x00004000 , 0x00204000 , 0x00404000 , 0x00604000 , 0x00804000 , 0x00a04000 , 0x00c04000 , 0x00e04000 , 0x00006000 , 0x00206000 , 0x00406000 , 0x00606000 , 0x00806000 , 0x00a06000 , 0x00c06000 , 0x00e06000
, 0x00008000 , 0x00208000 , 0x00408000 , 0x00608000 , 0x00808000 , 0x00a08000 , 0x00c08000 , 0x00e08000 , 0x0000a000 , 0x0020a000 , 0x0040a000 , 0x0060a000 , 0x0080a000 , 0x00a0a000 , 0x00c0a000 , 0x00e0a000
, 0x0000c000 , 0x0020c000 , 0x0040c000 , 0x0060c000 , 0x0080c000 , 0x00a0c000 , 0x00c0c000 , 0x00e0c000 , 0x0000e000 , 0x0020e000 , 0x0040e000 , 0x0060e000 , 0x0080e000 , 0x00a0e000 , 0x00c0e000 , 0x00e0e000
, 0x00000040 , 0x00200040 , 0x00400040 , 0x00600040 , 0x00800040 , 0x00a00040 , 0x00c00040 , 0x00e00040 , 0x00002040 , 0x00202040 , 0x00402040 , 0x00602040 , 0x00802040 , 0x00a02040 , 0x00c02040 , 0x00e02040
, 0x00004040 , 0x00204040 , 0x00404040 , 0x00604040 , 0x00804040 , 0x00a04040 , 0x00c04040 , 0x00e04040 , 0x00006040 , 0x00206040 , 0x00406040 , 0x00606040 , 0x00806040 , 0x00a06040 , 0x00c06040 , 0x00e06040
, 0x00008040 , 0x00208040 , 0x00408040 , 0x00608040 , 0x00808040 , 0x00a08040 , 0x00c08040 , 0x00e08040 , 0x0000a040 , 0x0020a040 , 0x0040a040 , 0x0060a040 , 0x0080a040 , 0x00a0a040 , 0x00c0a040 , 0x00e0a040
, 0x0000c040 , 0x0020c040 , 0x0040c040 , 0x0060c040 , 0x0080c040 , 0x00a0c040 , 0x00c0c040 , 0x00e0c040 , 0x0000e040 , 0x0020e040 , 0x0040e040 , 0x0060e040 , 0x0080e040 , 0x00a0e040 , 0x00c0e040 , 0x00e0e040
, 0x00000080 , 0x00200080 , 0x00400080 , 0x00600080 , 0x00800080 , 0x00a00080 , 0x00c00080 , 0x00e00080 , 0x00002080 , 0x00202080 , 0x00402080 , 0x00602080 , 0x00802080 , 0x00a02080 , 0x00c02080 , 0x00e02080
, 0x00004080 , 0x00204080 , 0x00404080 , 0x00604080 , 0x00804080 , 0x00a04080 , 0x00c04080 , 0x00e04080 , 0x00006080 , 0x00206080 , 0x00406080 , 0x00606080 , 0x00806080 , 0x00a06080 , 0x00c06080 , 0x00e06080
, 0x00008080 , 0x00208080 , 0x00408080 , 0x00608080 , 0x00808080 , 0x00a08080 , 0x00c08080 , 0x00e08080 , 0x0000a080 , 0x0020a080 , 0x0040a080 , 0x0060a080 , 0x0080a080 , 0x00a0a080 , 0x00c0a080 , 0x00e0a080
, 0x0000c080 , 0x0020c080 , 0x0040c080 , 0x0060c080 , 0x0080c080 , 0x00a0c080 , 0x00c0c080 , 0x00e0c080 , 0x0000e080 , 0x0020e080 , 0x0040e080 , 0x0060e080 , 0x0080e080 , 0x00a0e080 , 0x00c0e080 , 0x00e0e080
, 0x000000c0 , 0x002000c0 , 0x004000c0 , 0x006000c0 , 0x008000c0 , 0x00a000c0 , 0x00c000c0 , 0x00e000c0 , 0x000020c0 , 0x002020c0 , 0x004020c0 , 0x006020c0 , 0x008020c0 , 0x00a020c0 , 0x00c020c0 , 0x00e020c0
, 0x000040c0 , 0x002040c0 , 0x004040c0 , 0x006040c0 , 0x008040c0 , 0x00a040c0 , 0x00c040c0 , 0x00e040c0 , 0x000060c0 , 0x002060c0 , 0x004060c0 , 0x006060c0 , 0x008060c0 , 0x00a060c0 , 0x00c060c0 , 0x00e060c0
, 0x000080c0 , 0x002080c0 , 0x004080c0 , 0x006080c0 , 0x008080c0 , 0x00a080c0 , 0x00c080c0 , 0x00e080c0 , 0x0000a0c0 , 0x0020a0c0 , 0x0040a0c0 , 0x0060a0c0 , 0x0080a0c0 , 0x00a0a0c0 , 0x00c0a0c0 , 0x00e0a0c0
, 0x0000c0c0 , 0x0020c0c0 , 0x0040c0c0 , 0x0060c0c0 , 0x0080c0c0 , 0x00a0c0c0 , 0x00fffbf0 , 0x00a0a0a4 , 0x00808080 , 0x00ff0000 , 0x0000ff00 , 0x00ffff00 , 0x000000ff , 0x00ff00ff , 0x0000ffff , 0x00ffffff
2022-05-30 06:46:37 +00:00
} ;
int l = ( w + 31 ) / 32 * 4 ,
size = l * h ,
line_bytes = ( w + 3 ) / 4 * 4 ;
std : : string f ( " " ) ;
2022-09-07 07:47:30 +00:00
unsigned char * data = nullptr , mask = reverse ? - 1 : 0 ;
2022-05-30 06:46:37 +00:00
unsigned int * pallete = g_bmp8_pallete ;
if ( ! line_align_4 )
{
l = ( w + 7 ) / 8 ;
size = l * h ;
}
if ( lbytes & & * lbytes )
line_bytes = * lbytes ;
f . resize ( size ) ;
data = ( unsigned char * ) & f [ 0 ] ;
for ( int i = 0 ; i < h ; + + i )
{
unsigned char v = 0 ,
* dst = data ;
for ( int j = 0 ; j < w ; + + j )
{
v < < = 1 ;
unsigned char pixel = ( ( pallete [ bits [ j ] ] & 0x0ff ) + ( ( pallete [ bits [ j ] ] > > 8 ) & 0x0ff ) + ( ( pallete [ bits [ j ] ] > > 16 ) & 0x0ff ) ) / 3 ;
2022-06-28 09:16:03 +00:00
if ( pixel > = threashold )
2022-05-30 06:46:37 +00:00
v | = 1 ;
if ( ( j + 1 ) % 8 = = 0 )
{
2022-08-31 01:40:46 +00:00
* dst + + = v ^ mask ;
2022-05-30 06:46:37 +00:00
v = 0 ;
}
}
2022-06-28 09:16:03 +00:00
if ( w % 8 )
2022-05-30 06:46:37 +00:00
{
2022-08-31 01:40:46 +00:00
v ^ = mask ;
2022-05-30 06:46:37 +00:00
v < < = 8 - ( w % 8 ) ;
* dst + + = v ;
}
data + = l ;
bits + = line_bytes ;
}
if ( lbytes )
* lbytes = l ;
2022-10-18 08:23:22 +00:00
2022-05-30 06:46:37 +00:00
return f ;
}
2022-05-03 03:56:07 +00:00
2022-12-06 00:42:46 +00:00
static bool is_firstopen_ = true ; //第二次打开设备就不在去获取和设置设备锁定状态
2022-05-03 03:56:07 +00:00
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// hg_scanner
2023-01-17 07:07:58 +00:00
hg_scanner : : hg_scanner ( ScannerSerial serial , const char * dev_name , usb_io * io , int pid )
2022-09-21 08:43:42 +00:00
: name_ ( dev_name ? dev_name : " " ) , io_ ( io ) , status_ ( SCANNER_ERR_NOT_START ) , serial_ ( serial )
2022-09-23 02:26:04 +00:00
, scan_count_ ( - 1 ) , run_ ( true ) , paper_size_ ( TwSS : : A4 ) , erase_bkg_range_ ( 10 ) , read_over_with_no_data_ ( false )
2022-09-12 04:27:25 +00:00
, noise_range_ ( 30 ) , omit_empty_level_ ( 50 ) , resolution_ ( 200 ) , rid_hole_range_ ( 10.0f )
2022-05-03 03:56:07 +00:00
, bright_ ( 128 ) , contrast_ ( 4 ) , gamma_ ( 1.0f ) , threshold_ ( 40 ) , anti_noise_ ( 8 ) , margin_ ( 5 )
, fractate_level_ ( 50 ) , ui_ev_cb_ ( ui_default_callback ) , scan_life_ ( NULL )
, notify_setting_result_ ( false ) , user_cancel_ ( false ) , cb_mem_ ( true ) , test_1_paper_ ( false )
2023-01-18 10:08:47 +00:00
, img_type_ ( " " ) , online_ ( false ) , is_quality_ ( - 1 ) , is_color_fill ( false ) , is_multiout ( false ) , save_multiout ( hg_log : : lang_load ( ID_OPTION_VALUE_DLSCLX_CS_HD_HB ) )
2022-07-23 11:08:18 +00:00
, final_img_index_ ( 0 ) , custom_area_ ( false ) , save_sizecheck ( false ) , bw_threshold_ ( 128 ) , custom_gamma_ ( false )
2022-08-04 07:01:27 +00:00
, double_paper_handle_ ( 0 ) , keep_watermark_ ( false ) , save_feedmode_type_ ( false ) , feedmode_ ( 1 ) , sleeptime_ ( - 1 ) , split3399_ ( 0 )
2022-09-11 15:56:27 +00:00
, async_io_ ( false ) , is_white_0_ ( true ) , isremove_left_hole ( false ) , isremove_right_hole ( false ) , isremove_top_hole ( false ) , isremove_low_hole ( false )
2022-09-11 15:58:50 +00:00
, isremove_left_hole_threshold ( 0 ) , isremove_right_hole_threshold ( 0 ) , isremove_top_hole_threshold ( 0 ) , isremove_low_hole_threshold ( 0 )
2023-01-17 07:07:58 +00:00
, dump_usb_path_ ( " " ) , is_kernelsnap_211209_ ( false ) , dump_img_ ( & hg_scanner : : dump_image_empty ) , is_kernelsnap_220830_ ( false ) , is_kernelsnap3288_221106_ ( false )
2022-12-30 10:56:24 +00:00
, is_kernelsnap_221027_ ( false ) , memory_size_ ( 2000 /*USB+JPEG压缩及图像处理图队列, 总共1GB*/ ) , isx86_Advan_ ( true ) , stop_fatal_ ( SCANNER_ERR_OK ) , is_auto_paper_scan ( false )
2022-12-28 01:56:54 +00:00
, size_check ( false ) , save_sleeptime_type_ ( false ) , is_kernelsnap_devsislock ( false ) , is_checksum_strat_scan ( false ) , is_cis_image ( false )
2023-01-16 08:03:14 +00:00
, is_dpi_color_check ( false ) , save_dpi_color_check_val ( 0.0f ) , is_auto_falt ( false ) , HGVersion_mgr_ ( NULL ) , HGVersion_Init_ ( NULL )
2023-01-28 07:19:10 +00:00
, HGVersion_Islock_ ( NULL ) , HGVersion_Postlog_ ( NULL ) , HGVersion_Free_ ( NULL ) , Dynamicopen_HGVersion_pHandle_ ( NULL ) , pid_ ( pid ) , fetching_id_ ( - 1 )
2022-11-24 08:57:31 +00:00
{
2022-11-24 09:18:58 +00:00
# if !defined(_WIN32) && !defined(_WIN64) &&defined(x86_64)
2022-11-24 09:21:41 +00:00
isx86_Advan_ = false ;
2022-11-24 08:57:31 +00:00
# endif
init_setting_func_map ( ) ;
final_path_ = hg_log : : ini_get ( " path " , " final_img " ) ;
if ( final_path_ . empty ( ) )
final_path_ = hg_log : : local_data_path ( ) + PATH_SEPARATOR + " imgs " ;
if ( hg_log : : ini_get ( " dump " , " dumpusb " ) = = " 1 " )
{
dump_usb_path_ = hg_log : : ini_get ( " dump " , " usb_path " ) ;
if ( dump_usb_path_ . empty ( ) )
dump_usb_path_ = final_path_ ;
if ( ! dump_usb_path_ . empty ( ) )
dump_img_ = & hg_scanner : : dump_image_real ;
}
2022-11-24 09:18:58 +00:00
std : : string mem = hg_log : : ini_get ( " mem " , " max_img " ) ;
2022-11-24 08:57:31 +00:00
if ( ! mem . empty ( ) )
{
memory_size_ = std : : stoi ( mem ) ;
2022-11-24 09:18:58 +00:00
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " Get the config file --->memory_size_ set is :%lld " , memory_size_ ) ;
2022-11-24 08:57:31 +00:00
}
2022-11-24 09:18:58 +00:00
std : : string adv = hg_log : : ini_get ( " cpu " , " advanced " ) ;
2022-11-24 08:57:31 +00:00
if ( ! adv . empty ( ) )
{
2022-11-24 09:18:58 +00:00
isx86_Advan_ = adv = = " 0 " ? false : true ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " Get the config file --->isx86_Advan_ set is :%d " , isx86_Advan_ ) ;
2022-11-24 08:57:31 +00:00
}
2022-05-30 09:36:42 +00:00
if ( hg_log : : create_folder ( final_path_ . c_str ( ) ) )
2022-06-06 04:03:24 +00:00
{
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " temporary image folder: %s \n " , final_path_ . c_str ( ) ) ;
2022-06-01 03:04:10 +00:00
final_path_ + = PATH_SEPARATOR ;
2022-06-06 04:03:24 +00:00
}
2022-05-30 09:36:42 +00:00
else
2022-06-06 04:03:24 +00:00
{
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " create temporary image folder failed: %s \n " , final_path_ . c_str ( ) ) ;
2022-05-30 09:36:42 +00:00
final_path_ = " " ;
2022-06-06 04:03:24 +00:00
}
2022-05-30 09:36:42 +00:00
2022-05-06 08:39:00 +00:00
custom_gamma_val_ = new SANE_Gamma ;
memset ( custom_gamma_val_ , 0 , sizeof ( SANE_Gamma ) ) ;
2022-05-06 05:37:14 +00:00
paper_size_mm_ . cx = 210 ;
paper_size_mm_ . cy = 297 ;
2022-05-06 08:39:00 +00:00
custom_gamma_val_ - > pt_count_r = custom_gamma_val_ - > pt_count_g = custom_gamma_val_ - > pt_count_b = 0 ;
for ( int i = 0 ; i < ARRAY_SIZE ( custom_gamma_val_ - > table ) ; + + i )
custom_gamma_val_ - > table [ i ] = i & 0x0ff ;
2022-05-06 05:37:14 +00:00
2022-05-30 03:04:26 +00:00
VLOG_MINI_2 ( LOG_LEVEL_DEBUG_INFO , " %s(%s) constructed \n " , name_ . c_str ( ) , hg_log : : format_ptr ( this ) . c_str ( ) ) ;
2022-05-03 03:56:07 +00:00
image_prc_param_ . value = 0 ;
if ( io_ )
{
io_ - > add_ref ( ) ;
status_ = io_ - > last_error ( ) ;
2022-05-17 07:04:55 +00:00
online_ = status_ = = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
wait_usb_ . set_debug_info ( " USB " ) ;
wait_img_ . set_debug_info ( " Image " ) ;
2022-05-23 03:52:53 +00:00
wait_usb_result_ . set_debug_info ( " start " ) ;
2022-12-05 15:01:13 +00:00
wait_usb_ . set_debug_info ( " Devsislock " ) ;
2022-05-03 03:56:07 +00:00
thread_usb_read_ . reset ( new std : : thread ( & hg_scanner : : thread_handle_usb , this ) ) ;
thread_img_handle_ . reset ( new std : : thread ( & hg_scanner : : thread_image_handle , this ) ) ;
2023-01-04 05:53:04 +00:00
# ifdef OEM_HUAGAO
2022-12-05 15:01:13 +00:00
thread_devslock_handle_ . reset ( new std : : thread ( & hg_scanner : : thread_devslock_handle , this ) ) ;
2023-01-04 05:53:04 +00:00
# endif
2022-11-24 09:18:58 +00:00
ImagePrc_pHandle_ = hg_imgproc : : init ( pid_ , isx86_Advan_ ) ; ;
2022-05-03 03:56:07 +00:00
}
hg_scanner : : ~ hg_scanner ( )
{
close ( true ) ;
2023-01-16 08:14:50 +00:00
hg_version_free_handle ( ) ;
2022-05-03 03:56:07 +00:00
if ( thread_usb_read_ . get ( ) & & thread_usb_read_ - > joinable ( ) )
thread_usb_read_ - > join ( ) ;
if ( thread_img_handle_ . get ( ) & & thread_img_handle_ - > joinable ( ) )
thread_img_handle_ - > join ( ) ;
2023-01-04 05:53:04 +00:00
# ifdef OEM_HUAGAO
2022-12-05 15:01:13 +00:00
if ( thread_devslock_handle_ . get ( ) & & thread_devslock_handle_ - > joinable ( ) )
thread_devslock_handle_ - > join ( ) ;
2023-01-04 05:53:04 +00:00
# endif
2022-05-06 08:39:00 +00:00
delete custom_gamma_val_ ;
2022-11-01 09:20:57 +00:00
hg_imgproc : : release ( ImagePrc_pHandle_ ) ;
2022-12-05 15:01:13 +00:00
2023-01-18 10:08:47 +00:00
name_ . insert ( 0 , hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_DEVS ) ) ;
name_ + = hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_IS_CLOSE ) ;
2022-05-03 03:56:07 +00:00
notify_ui_working_status ( name_ . c_str ( ) , SANE_EVENT_SCANNER_CLOSED ) ;
2022-05-30 03:04:26 +00:00
VLOG_MINI_2 ( LOG_LEVEL_DEBUG_INFO , " %s(%s) destroyed. \n " , name_ . c_str ( ) , hg_log : : format_ptr ( this ) . c_str ( ) ) ;
2022-05-17 07:04:55 +00:00
}
2022-05-03 03:56:07 +00:00
std : : string hg_scanner : : temporary_file ( char * tail , char * head )
{
2022-05-10 00:27:31 +00:00
std : : string path ( " /tmp/ " ) ;
char buf [ 128 ] ;
FILE * src = NULL ;
unsigned int ind = 1 ;
2022-05-03 03:56:07 +00:00
if ( ! head | | * head = = 0 )
head = ( char * ) " scan " ;
if ( ! tail )
tail = ( char * ) " " ;
2022-07-18 08:56:03 +00:00
# if defined(WIN32) || defined(_WIN64)
2022-05-10 00:27:31 +00:00
char me [ MAX_PATH ] = { 0 } , * n = NULL ;
GetModuleFileNameA ( NULL , me , _countof ( me ) - 1 ) ;
n = strrchr ( me , ' \\ ' ) ;
if ( n + + = = NULL )
n = me ;
* n = 0 ;
path = me ;
path + = " img_tmp \\ " ;
mkdir ( path . c_str ( ) ) ;
# endif
2022-05-03 03:56:07 +00:00
srand ( time ( NULL ) ) ;
2022-05-10 00:27:31 +00:00
sprintf ( buf , " %s%s " , head , tail ) ;
while ( ( src = fopen ( ( path + buf ) . c_str ( ) , " rb " ) ) )
2022-05-03 03:56:07 +00:00
{
fclose ( src ) ;
2022-05-10 00:27:31 +00:00
sprintf ( buf , " %s(%u)%s " , head , ind + + , tail ) ;
2022-05-03 03:56:07 +00:00
}
2022-05-10 00:27:31 +00:00
return path + buf ;
2022-05-03 03:56:07 +00:00
}
2022-05-10 00:27:31 +00:00
int hg_scanner : : save_2_tempory_file ( std : : shared_ptr < std : : vector < char > > data , std : : string * path_file , unsigned int index )
2022-05-03 03:56:07 +00:00
{
2022-05-10 00:27:31 +00:00
char head [ 40 ] = { 0 } ;
std : : string file ( " " ) ;
FILE * dst = nullptr ;
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
2022-06-01 03:04:10 +00:00
sprintf ( head , " usb_%05u " , index ) ;
if ( ! path_file | | path_file - > empty ( ) )
file = hg_scanner : : temporary_file ( ( char * ) " .jpg " , ( char * ) head ) ;
dst = fopen ( file . c_str ( ) , " wb " ) ;
2022-05-03 03:56:07 +00:00
if ( dst )
{
size_t wrote = fwrite ( data - > data ( ) , 1 , data - > size ( ) , dst ) ;
if ( wrote = = data - > size ( ) )
{
if ( path_file )
* path_file = file ;
2022-05-30 03:04:26 +00:00
VLOG_MINI_2 ( LOG_LEVEL_DEBUG_INFO , " --->Wrote %u bytes to file '%s' \n " , wrote , file . c_str ( ) ) ;
2022-05-03 03:56:07 +00:00
}
else
{
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_WRITE_FILE_FAILED ;
2022-05-30 03:04:26 +00:00
VLOG_MINI_3 ( LOG_LEVEL_FATAL , " Failed in writting file(%u/%u) '%s' \n " , wrote , data - > size ( ) , file . c_str ( ) ) ;
2022-05-03 03:56:07 +00:00
}
fclose ( dst ) ;
}
else
{
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_CREATE_FILE_FAILED ;
2022-05-30 03:04:26 +00:00
VLOG_MINI_1 ( LOG_LEVEL_FATAL , " Failed in creating file '%s' \n " , file . c_str ( ) ) ;
2022-05-03 03:56:07 +00:00
}
return ret ;
}
2022-12-05 15:01:13 +00:00
void hg_scanner : : thread_devslock_handle ( void )
{
int ret = SCANNER_ERR_OK ;
2022-12-06 00:44:22 +00:00
wait_devsislock_ . wait ( ) ;
2022-12-06 09:47:27 +00:00
while ( is_firstopen_ & & is_kernelsnap_devsislock )
2022-12-05 15:01:13 +00:00
{
2022-12-12 10:18:53 +00:00
std : : this_thread : : sleep_for ( std : : chrono : : milliseconds ( 500 ) ) ;
2022-12-06 09:47:27 +00:00
ret = set_server_blacklist_lock ( ) ;
2022-12-05 15:01:13 +00:00
hg_version_free_handle ( ) ;
2022-12-06 00:42:46 +00:00
is_firstopen_ = false ;
2022-12-05 15:01:13 +00:00
}
}
2022-05-03 03:56:07 +00:00
void hg_scanner : : thread_handle_usb ( void )
{
while ( run_ )
{
wait_usb_ . wait ( ) ;
if ( ! run_ )
break ;
if ( scan_life_ )
{
std : : this_thread : : sleep_for ( std : : chrono : : milliseconds ( 3000 ) ) ;
if ( scan_life_ )
{
2022-05-30 03:04:26 +00:00
LOG_INFO ( LOG_LEVEL_FATAL , " image process is still running! \n " ) ;
2022-05-03 03:56:07 +00:00
continue ;
}
}
scan_life_ = new do_when_born_and_dead < hg_scanner > ( this , & hg_scanner : : working_begin , & hg_scanner : : working_done , NULL ) ;
2022-05-10 00:27:31 +00:00
usb_img_index_ = 0 ;
2022-05-03 03:56:07 +00:00
thread_handle_usb_read ( ) ;
if ( scan_life_ - > release ( ) = = 0 )
scan_life_ = NULL ;
}
}
void hg_scanner : : thread_image_handle ( void )
{
while ( run_ )
{
wait_img_ . wait ( ) ;
if ( ! run_ )
break ;
scan_life_ - > add_ref ( ) ;
thread_handle_image_process ( ) ;
if ( scan_life_ - > release ( ) = = 0 )
scan_life_ = NULL ;
}
}
2022-12-05 15:01:13 +00:00
int hg_scanner : : hg_version_init_handle ( )
{
int ret = SCANNER_ERR_OK ;
# ifndef WIN32
# ifdef OEM_HANWANG
string libname = " libhwdriver.so " ;
# elif defined(OEM_LISICHENG)
string libname = " liblscdriver.so " ;
# elif defined(OEM_CANGTIAN)
string libname = " libctsdriver.so " ;
# else
string libname = " libhgdriver.so " ;
# endif
string scanner_path = hg_log : : get_module_full_path ( libname . c_str ( ) ) ;
if ( scanner_path . empty ( ) )
{
return SCANNER_ERR_OUT_OF_RANGE ;
}
scanner_path = scanner_path . substr ( 0 , scanner_path . size ( ) - libname . size ( ) ) ;
string HGVersionlib_path = scanner_path + HGVERSION_LIBNANE ;
if ( access ( HGVersionlib_path . c_str ( ) , F_OK ) ! = 0 )
{
return SCANNER_ERR_OUT_OF_RANGE ;
}
printf ( " HGVersionlib_path: %s \r \n " , HGVersionlib_path . c_str ( ) ) ;
Dynamicopen_HGVersion_pHandle_ = dlopen ( HGVersionlib_path . c_str ( ) , RTLD_LAZY ) ;
if ( ! Dynamicopen_HGVersion_pHandle_ )
{
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " HGVersionlib_path open dll is error: %s \n " , hg_scanner_err_name ( SCANNER_ERR_INSUFFICIENT_MEMORY ) ) ;
return SCANNER_ERR_INSUFFICIENT_MEMORY ;
}
HGVersion_Init_ = ( SDKHGVersion_Init_ ) dlsym ( Dynamicopen_HGVersion_pHandle_ , " HGVersion_CreateMgr " ) ;
2022-12-13 10:13:46 +00:00
HGVersion_Islock_ = ( SDKHGVersion_Islock_ ) dlsym ( Dynamicopen_HGVersion_pHandle_ , " HGVersion_BlackListCheck " ) ;
HGVersion_Postlog_ = ( SDKHGVersion_Postlog_ ) dlsym ( Dynamicopen_HGVersion_pHandle_ , " HGVersion_PostDeviceLockInfo " ) ;
2022-12-05 15:01:13 +00:00
HGVersion_Free_ = ( SDKHGVersion_Free_ ) dlsym ( Dynamicopen_HGVersion_pHandle_ , " HGVersion_DestroyMgr " ) ;
# else
string scanner_path = hg_log : : get_module_full_path ( " scanner.dll " ) ;
scanner_path = scanner_path . substr ( 0 , scanner_path . size ( ) - strlen ( " scanner.dll " ) ) ;
string HGVersionlib_path = scanner_path + HGVERSION_LIBNANE ;
wchar_t * Prclibbuffer = new wchar_t [ HGVersionlib_path . length ( ) + 1 ] ;
ret = strToWchar ( HGVersionlib_path , Prclibbuffer ) ;
if ( ret = = - 1 )
return SCANNER_ERR_INSUFFICIENT_MEMORY ;
load_dll ( Prclibbuffer , & Dynamicopen_HGVersion_pHandle_ ) ; //windows下可能会找不到他所在的依赖库导致直接打开动态库的时候找不到模块
2022-12-06 09:47:27 +00:00
if ( Prclibbuffer )
{
delete [ ] Prclibbuffer ;
Prclibbuffer = NULL ;
}
2022-12-05 15:01:13 +00:00
//int l = GetLastError();
if ( ! Dynamicopen_HGVersion_pHandle_ )
{
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " Dynamicopen_HGVersion_pHandle_ open dll is error: %s \n " , hg_scanner_err_name ( SCANNER_ERR_INSUFFICIENT_MEMORY ) ) ;
return SCANNER_ERR_INSUFFICIENT_MEMORY ;
}
HGVersion_Init_ = ( SDKHGVersion_Init_ ) GetProcAddress ( Dynamicopen_HGVersion_pHandle_ , " HGVersion_CreateMgr " ) ;
HGVersion_Islock_ = ( SDKHGVersion_Islock_ ) GetProcAddress ( Dynamicopen_HGVersion_pHandle_ , " HGVersion_BlackListCheck " ) ;
HGVersion_Postlog_ = ( SDKHGVersion_Postlog_ ) GetProcAddress ( Dynamicopen_HGVersion_pHandle_ , " HGVersion_PostDeviceLockInfo " ) ;
HGVersion_Free_ = ( SDKHGVersion_Free_ ) GetProcAddress ( Dynamicopen_HGVersion_pHandle_ , " HGVersion_DestroyMgr " ) ;
# endif
if ( ! HGVersion_Init_ | | ! HGVersion_Islock_ | | ! HGVersion_Postlog_ | | ! HGVersion_Free_ )
{
return SCANNER_ERR_INVALID_PARAMETER ;
}
HGVersion_Init_ ( & HGVersion_mgr_ ) ;
return ret ;
}
2022-12-06 09:47:27 +00:00
int hg_scanner : : set_server_blacklist_lock ( )
2022-12-05 15:01:13 +00:00
{
if ( ! HGVersion_mgr_ )
{
return SCANNER_ERR_INVALID_PARAMETER ;
}
char snbuffer [ 20 ] ;
char fvbuffer [ 15 ] ;
char pidbuffer [ 5 ] ;
SANE_Bool scan_islock = false ;
memset ( snbuffer , 0 , sizeof ( snbuffer ) ) ;
memset ( fvbuffer , 0 , sizeof ( fvbuffer ) ) ;
memset ( pidbuffer , 0 , sizeof ( pidbuffer ) ) ;
2023-01-16 09:26:07 +00:00
HGBool islock = false ;
2022-12-05 15:01:13 +00:00
string sn = get_serial_num ( ) ;
string fv = get_firmware_version ( ) ;
strcpy ( snbuffer , sn . c_str ( ) ) ;
strcpy ( fvbuffer , fv . c_str ( ) ) ;
sprintf ( pidbuffer , " %0x " , pid_ ) ;
2022-12-12 10:18:53 +00:00
//优先从机器设备上进行校验
int ret = HGVersion_Islock_ ( HGVersion_mgr_ , snbuffer , & islock ) ;
int islock_file = 0 ;
if ( ret ! = 0 ) //服务器没有连接到网络
2022-12-05 15:01:13 +00:00
{
2022-12-12 10:18:53 +00:00
ret = get_dev_islock_file ( islock_file ) ;
2022-12-13 10:13:46 +00:00
is_checksum_strat_scan = islock_file < = 0 ? true : false ; //使用校验码来进行扫描,以后只会使用这种方法进行扫描
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " net is 404 , devs list is:%d \n " , islock_file ) ;
2022-12-05 15:01:13 +00:00
}
2022-12-13 10:13:46 +00:00
else if ( ! islock )
2022-12-05 15:01:13 +00:00
{
2022-12-13 10:13:46 +00:00
ret = HGVersion_Postlog_ ( HGVersion_mgr_ , pidbuffer , snbuffer , fv . substr ( 0 , 4 ) . c_str ( ) , fvbuffer , islock ) ; //发送日志到服务,第三个参数随意字符串但不能为NULL
is_checksum_strat_scan = true ;
set_dev_islock_file ( 0 ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " use checksum start scan:%d \n " , islock ) ;
2022-12-05 15:01:13 +00:00
}
2022-12-13 10:13:46 +00:00
else
2022-12-05 15:01:13 +00:00
{
2022-12-13 10:13:46 +00:00
ret = HGVersion_Postlog_ ( HGVersion_mgr_ , pidbuffer , snbuffer , fv . substr ( 0 , 4 ) . c_str ( ) , fvbuffer , islock ) ; //发送日志到服务,第三个参数随意字符串但不能为NULL
is_checksum_strat_scan = false ;
set_dev_islock_file ( 1 ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " devs is lock:%d \n " , islock ) ;
2022-12-05 15:01:13 +00:00
}
2022-12-13 10:13:46 +00:00
return 0 ;
2022-12-05 15:01:13 +00:00
}
void hg_scanner : : hg_version_free_handle ( )
{
int ret = 0 ;
if ( HGVersion_mgr_ )
{
int ret = HGVersion_Free_ ( HGVersion_mgr_ ) ;
HGVersion_mgr_ = NULL ;
}
if ( Dynamicopen_HGVersion_pHandle_ )
{
# if (!defined WIN32)
ret = dlclose ( Dynamicopen_HGVersion_pHandle_ ) ;
# else
ret = FreeLibrary ( Dynamicopen_HGVersion_pHandle_ ) ;
# endif
Dynamicopen_HGVersion_pHandle_ = NULL ;
}
}
2022-10-22 01:46:30 +00:00
void hg_scanner : : dump_image_empty ( hg_imgproc : : HIMGPRC himg , const char * desc )
{ }
void hg_scanner : : dump_image_real ( hg_imgproc : : HIMGPRC himg , const char * desc )
{
char sn [ 40 ] = { 0 } ;
sprintf ( sn , " _%03d.jpg " , final_img_index_ + 1 ) ;
hg_imgproc : : dump_2_file ( himg , ( dump_usb_path_ + PATH_SEPARATOR + desc + sn ) . c_str ( ) ) ;
}
2022-11-10 02:02:52 +00:00
void hg_scanner : : init_setting_func_map ( void )
{
setting_map_ [ SANE_STD_OPT_NAME_RESTORE ] = & hg_scanner : : setting_restore ;
setting_map_ [ SANE_STD_OPT_NAME_HELP ] = & hg_scanner : : setting_help ;
setting_map_ [ SANE_STD_OPT_NAME_COLOR_MODE ] = & hg_scanner : : setting_color_mode ;
setting_map_ [ SANE_STD_OPT_NAME_IS_MULTI_OUT ] = & hg_scanner : : setting_multi_out ;
setting_map_ [ SANE_STD_OPT_NAME_MULTI_OUT_TYPE ] = & hg_scanner : : setting_multi_out_type ;
setting_map_ [ SANE_STD_OPT_NAME_FILTER ] = & hg_scanner : : setting_rid_color ;
setting_map_ [ SANE_STD_OPT_NAME_RID_MULTIOUT_RED ] = & hg_scanner : : setting_rid_multi_red ;
setting_map_ [ SANE_STD_OPT_NAME_RID_ANSWER_SHEET_RED ] = & hg_scanner : : setting_rid_answer_red ;
setting_map_ [ SANE_STD_OPT_NAME_ERASE_BACKGROUND ] = & hg_scanner : : setting_erase_background ;
setting_map_ [ SANE_STD_OPT_NAME_BKG_COLOR_RANGE ] = & hg_scanner : : setting_erase_background_range ;
setting_map_ [ SANE_STD_OPT_NAME_NOISE_OPTIMIZE ] = & hg_scanner : : setting_noise_optimize ;
setting_map_ [ SANE_STD_OPT_NAME_NOISE_SIZE ] = & hg_scanner : : setting_noise_optimize_range ;
setting_map_ [ SANE_STD_OPT_NAME_PAPER ] = & hg_scanner : : setting_paper ;
setting_map_ [ SANE_STD_OPT_NAME_SIZE_CHECK ] = & hg_scanner : : setting_paper_check ;
setting_map_ [ SANE_STD_OPT_NAME_PAGE ] = & hg_scanner : : setting_page ;
setting_map_ [ SANE_STD_OPT_NAME_DISCARD_BLANK_SENS ] = & hg_scanner : : setting_page_omit_empty ;
setting_map_ [ SANE_STD_OPT_NAME_RESOLUTION ] = & hg_scanner : : setting_resolution ;
setting_map_ [ SANE_STD_OPT_NAME_EXCHANGE ] = & hg_scanner : : setting_exchagnge ;
setting_map_ [ SANE_STD_OPT_NAME_SPLIT ] = & hg_scanner : : setting_split_image ;
setting_map_ [ SANE_STD_OPT_NAME_ANTI_SKEW ] = & hg_scanner : : setting_automatic_skew ;
setting_map_ [ SANE_STD_OPT_NAME_RID_HOLE ] = & hg_scanner : : setting_rid_hole ;
setting_map_ [ SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE ] = & hg_scanner : : setting_rid_hoe_range ;
setting_map_ [ SANE_STD_OPT_NAME_BRIGHTNESS ] = & hg_scanner : : setting_bright ;
setting_map_ [ SANE_STD_OPT_NAME_CONTRAST ] = & hg_scanner : : setting_contrast ;
setting_map_ [ SANE_STD_OPT_NAME_GAMMA ] = & hg_scanner : : setting_gamma ;
setting_map_ [ SANE_STD_OPT_NAME_SHARPEN ] = & hg_scanner : : setting_sharpen ;
setting_map_ [ SANE_STD_OPT_NAME_DARK_SAMPLE ] = & hg_scanner : : setting_dark_sample ;
setting_map_ [ SANE_STD_OPT_NAME_ERASE_BLACK_FRAME ] = & hg_scanner : : setting_erase_black_frame ;
setting_map_ [ SANE_STD_OPT_NAME_THRESHOLD ] = & hg_scanner : : setting_threshold ;
setting_map_ [ SANE_STD_OPT_NAME_ANTI_NOISE_LEVEL ] = & hg_scanner : : setting_anti_noise ;
setting_map_ [ SANE_STD_OPT_NAME_MARGIN ] = & hg_scanner : : setting_margin ;
setting_map_ [ SANE_STD_OPT_NAME_FILL_BKG_MODE ] = & hg_scanner : : setting_filling_background ;
setting_map_ [ SANE_STD_OPT_NAME_IS_ANTI_PERMEATE ] = & hg_scanner : : setting_is_permeate ;
setting_map_ [ SANE_STD_OPT_NAME_ANTI_PERMEATE_LEVEL ] = & hg_scanner : : setting_is_permeate_lv ;
setting_map_ [ SANE_STD_OPT_NAME_RID_MORR ] = & hg_scanner : : setting_remove_morr ;
setting_map_ [ SANE_STD_OPT_NAME_ERROR_EXTENSION ] = & hg_scanner : : setting_error_extention ;
setting_map_ [ SANE_STD_OPT_NAME_RID_GRID ] = & hg_scanner : : setting_remove_texture ;
setting_map_ [ SANE_STD_OPT_NAME_IS_ULTROSONIC_CHECK ] = & hg_scanner : : setting_ultrasonic_check ;
setting_map_ [ SANE_STD_OPT_NAME_DOUBLE_FEED_HANDLE ] = & hg_scanner : : setting_go_on_when_double_checked ;
setting_map_ [ SANE_STD_OPT_NAME_IS_CHECK_STAPLE ] = & hg_scanner : : setting_staple_check ;
setting_map_ [ SANE_STD_OPT_NAME_SCAN_MODE ] = & hg_scanner : : setting_scan_mode ;
setting_map_ [ SANE_STD_OPT_NAME_SCAN_COUNT ] = & hg_scanner : : setting_scan_count ;
setting_map_ [ SANE_STD_OPT_NAME_TEXT_DIRECTION ] = & hg_scanner : : setting_text_direction ;
setting_map_ [ SANE_STD_OPT_NAME_IS_ROTATE_BKG_180 ] = & hg_scanner : : setting_rotate_bkg_180 ;
setting_map_ [ SANE_STD_OPT_NAME_IS_CHECK_DOG_EAR ] = & hg_scanner : : setting_fractate_check ;
setting_map_ [ SANE_STD_OPT_NAME_DOG_EAR_SIZE ] = & hg_scanner : : setting_fractate_check_level ;
setting_map_ [ SANE_STD_OPT_NAME_IS_CHECK_ASKEW ] = & hg_scanner : : setting_skew_check ;
setting_map_ [ SANE_STD_OPT_NAME_ASKEW_RANGE ] = & hg_scanner : : setting_skew_check_level ;
setting_map_ [ SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA ] = & hg_scanner : : setting_is_custom_gamma ;
setting_map_ [ SANE_STD_OPT_NAME_CUSTOM_AREA ] = & hg_scanner : : setting_is_custom_area ;
setting_map_ [ SANE_STD_OPT_NAME_CUSTOM_AREA_LEFT ] = & hg_scanner : : setting_custom_area_left ;
setting_map_ [ SANE_STD_OPT_NAME_CUSTOM_AREA_RIGHT ] = & hg_scanner : : setting_custom_area_right ;
setting_map_ [ SANE_STD_OPT_NAME_CUSTOM_AREA_TOP ] = & hg_scanner : : setting_custom_area_top ;
setting_map_ [ SANE_STD_OPT_NAME_CUSTOM_AREA_BOTTOM ] = & hg_scanner : : setting_custom_area_bottom ;
setting_map_ [ SANE_STD_OPT_NAME_IMAGE_QUALITY ] = & hg_scanner : : setting_img_quality ;
setting_map_ [ SANE_STD_OPT_NAME_IS_FILL_COLOR ] = & hg_scanner : : setting_color_fill ;
setting_map_ [ SANE_STD_OPT_NAME_IS_PHOTO_MODE ] = & hg_scanner : : setting_keep_watermark ;
setting_map_ [ SANE_STD_OPT_NAME_BINARY_THRESHOLD ] = & hg_scanner : : setting_black_white_threshold ;
setting_map_ [ SANE_STD_OPT_NAME_REVERSE_01 ] = & hg_scanner : : setting_white_pixel_0 ;
2022-11-14 01:16:55 +00:00
setting_map_ [ SANE_STD_OPT_NAME_FEED_STRENGTH ] = & hg_scanner : : setting_feedmode ;
setting_map_ [ SANE_STD_OPT_NAME_TIME_TO_SLEEP ] = & hg_scanner : : setting_sleeptime ;
setting_map_ [ SANE_STD_OPT_NAME_IS_AUTO_FEED_STRENGTH ] = & hg_scanner : : setting_auto_pick_paper ;
setting_map_ [ SANE_STD_OPT_NAME_FEED_STRENGTH_VALUE ] = & hg_scanner : : setting_auto_pick_paper_threshold ;
setting_map_ [ SANE_STD_OPT_NAME_WAIT_TO_SCAN ] = & hg_scanner : : setting_auto_paper_scan ;
setting_map_ [ SANE_STD_OPT_NAME_RID_HOLE_L ] = & hg_scanner : : setting_isremove_left_hole ;
setting_map_ [ SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_L ] = & hg_scanner : : setting_isremove_left_hole_threshold ;
setting_map_ [ SANE_STD_OPT_NAME_RID_HOLE_R ] = & hg_scanner : : setting_isremove_right_hole ;
setting_map_ [ SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_R ] = & hg_scanner : : setting_isremove_right_hole_threshold ;
setting_map_ [ SANE_STD_OPT_NAME_RID_HOLE_T ] = & hg_scanner : : setting_isremove_top_hole ;
setting_map_ [ SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_T ] = & hg_scanner : : setting_isremove_top_hole_threshold ;
setting_map_ [ SANE_STD_OPT_NAME_RID_HOLE_B ] = & hg_scanner : : setting_isremove_low_hole ;
setting_map_ [ SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE_B ] = & hg_scanner : : setting_isremove_low_hole_threshold ;
setting_map_ [ SANE_STD_OPT_NAME_FOLD_TYPE ] = & hg_scanner : : setting_fold_type ;
2022-11-10 02:02:52 +00:00
}
2023-01-10 06:21:39 +00:00
std : : string hg_scanner : : setting_name_from ( const char * n_or_id , int * id )
2022-11-10 02:02:52 +00:00
{
if ( IS_PTR_NUMBER ( n_or_id ) )
{
2023-01-10 06:21:39 +00:00
if ( id )
2023-01-11 06:47:50 +00:00
* id = ( long long ) n_or_id ;
2023-01-10 06:21:39 +00:00
2022-11-10 02:02:52 +00:00
if ( ( unsigned long ) n_or_id < jsn_children_ . size ( ) )
return jsn_children_ [ ( unsigned long ) n_or_id ] ;
else
return " " ;
}
2023-01-10 06:21:39 +00:00
else if ( id )
{
* id = std : : distance ( jsn_children_ . begin ( ) , std : : find ( jsn_children_ . begin ( ) , jsn_children_ . end ( ) , n_or_id ) ) ;
}
2022-11-10 02:02:52 +00:00
return n_or_id ;
}
void hg_scanner : : get_range ( const char * name , std : : vector < std : : string > & range , std : : string & def_val , bool & is_range /*range or list*/ )
2022-05-03 03:56:07 +00:00
{
std : : string type ( " " ) ;
2022-11-10 02:02:52 +00:00
2022-05-03 03:56:07 +00:00
range . clear ( ) ;
2022-11-10 02:02:52 +00:00
if ( setting_jsn_ . at ( name ) . contains ( " range " ) )
2022-05-03 03:56:07 +00:00
{
2022-11-10 02:02:52 +00:00
setting_jsn_ . at ( name ) . at ( " type " ) . get_to ( type ) ;
is_range = ! setting_jsn_ . at ( name ) . at ( " range " ) . is_array ( ) ;
2022-05-03 03:56:07 +00:00
if ( is_range )
{
if ( type = = " int " )
{
int l = 0 , u = 0 ;
2022-11-10 02:02:52 +00:00
setting_jsn_ . at ( name ) . at ( " range " ) . at ( " min " ) . get_to ( l ) ;
setting_jsn_ . at ( name ) . at ( " range " ) . at ( " max " ) . get_to ( u ) ;
2022-05-03 03:56:07 +00:00
char str [ 20 ] ;
sprintf ( str , " %d " , l ) ;
range . push_back ( str ) ;
sprintf ( str , " %d " , u ) ;
range . push_back ( str ) ;
}
else
{
double l = .0f , u = .0f ;
2022-11-10 02:02:52 +00:00
setting_jsn_ . at ( name ) . at ( " range " ) . at ( " min " ) . get_to ( l ) ;
setting_jsn_ . at ( name ) . at ( " range " ) . at ( " max " ) . get_to ( u ) ;
2022-05-03 03:56:07 +00:00
char str [ 40 ] ;
sprintf ( str , " %f " , l ) ;
range . push_back ( str ) ;
sprintf ( str , " %f " , u ) ;
range . push_back ( str ) ;
}
}
else
{
char str [ 40 ] ;
2022-11-10 02:02:52 +00:00
for ( int i = 0 ; i < setting_jsn_ . at ( name ) . at ( " range " ) . size ( ) ; + + i )
2022-05-03 03:56:07 +00:00
{
if ( type = = " int " )
{
int v = 0 ;
2022-11-10 02:02:52 +00:00
setting_jsn_ . at ( name ) . at ( " range " ) . at ( i ) . get_to ( v ) ;
2022-05-03 03:56:07 +00:00
sprintf ( str , " %d " , v ) ;
range . push_back ( str ) ;
}
else if ( type = = " float " )
{
double v = 0 ;
2022-11-10 02:02:52 +00:00
setting_jsn_ . at ( name ) . at ( " range " ) . at ( i ) . get_to ( v ) ;
2022-05-03 03:56:07 +00:00
sprintf ( str , " %f " , v ) ;
range . push_back ( str ) ;
}
else
{
std : : string v ( " " ) ;
2023-01-28 07:19:10 +00:00
if ( setting_jsn_ . at ( name ) . at ( " range " ) . at ( i ) . is_number ( ) )
{
int id = 0 ;
setting_jsn_ . at ( name ) . at ( " range " ) . at ( i ) . get_to ( id ) ;
v = hg_log : : lang_load ( id ) ;
}
else
setting_jsn_ . at ( name ) . at ( " range " ) . at ( i ) . get_to ( v ) ;
2022-05-03 03:56:07 +00:00
range . push_back ( v ) ;
}
}
}
}
if ( type = = " int " )
{
int v = 0 ;
2022-11-10 02:02:52 +00:00
char sn [ 20 ] = { 0 } ;
setting_jsn_ . at ( name ) . at ( " default " ) . get_to ( v ) ;
2022-05-03 03:56:07 +00:00
sprintf ( sn , " %d " , v ) ;
def_val = sn ;
}
else if ( type = = " float " )
{
double v = 0 ;
2022-11-10 02:02:52 +00:00
char sn [ 20 ] = { 0 } ;
setting_jsn_ . at ( name ) . at ( " default " ) . get_to ( v ) ;
2022-05-03 03:56:07 +00:00
sprintf ( sn , " %f " , v ) ;
def_val = sn ;
}
2023-01-28 07:19:10 +00:00
else if ( type = = " string " )
{
def_val = get_setting_item_string ( name , " default " ) ;
}
2022-07-07 09:29:12 +00:00
//VLOG_MINI_3(LOG_LEVEL_DEBUG_INFO, "setting %d has %d range(s) and default value is '%s'\n", setting_no, range.size(), def_val.c_str());
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
bool hg_scanner : : check_range ( const char * name , bool & val )
2022-05-03 03:56:07 +00:00
{
std : : vector < std : : string > range ;
std : : string init ( " " ) , in ( val ? " true " : " false " ) ;
bool is_range = false ; ;
2022-11-10 02:02:52 +00:00
get_range ( name , range , init , is_range ) ;
2022-05-03 03:56:07 +00:00
if ( range . size ( ) = = 0 )
return true ;
for ( int i = 0 ; i < range . size ( ) ; + + i )
{
if ( in = = range [ i ] )
return true ;
}
val = init = = " true " ? true : false ;
return false ;
}
2022-11-10 02:02:52 +00:00
bool hg_scanner : : check_range ( const char * name , int & val )
2022-05-03 03:56:07 +00:00
{
std : : vector < std : : string > range ;
std : : string init ( " " ) ;
bool is_range = false ; ;
2022-11-10 02:02:52 +00:00
get_range ( name , range , init , is_range ) ;
2022-05-03 03:56:07 +00:00
if ( range . size ( ) = = 0 )
return true ;
if ( is_range & & range . size ( ) = = 2 )
{
if ( val > = atoi ( range [ 0 ] . c_str ( ) ) & & val < = atoi ( range [ 1 ] . c_str ( ) ) )
return true ;
if ( val < atoi ( range [ 0 ] . c_str ( ) ) )
val = atoi ( range [ 0 ] . c_str ( ) ) ;
else
val = atoi ( range [ 1 ] . c_str ( ) ) ;
return false ;
}
else if ( ! is_range )
{
for ( int i = 0 ; i < range . size ( ) ; + + i )
{
if ( atoi ( range [ i ] . c_str ( ) ) = = val )
return true ;
}
}
val = atoi ( init . c_str ( ) ) ;
return false ;
}
2022-11-10 02:02:52 +00:00
bool hg_scanner : : check_range ( const char * name , double & val )
2022-05-03 03:56:07 +00:00
{
std : : vector < std : : string > range ;
std : : string init ( " " ) ;
bool is_range = false ; ;
2022-11-10 02:02:52 +00:00
get_range ( name , range , init , is_range ) ;
2022-05-03 03:56:07 +00:00
if ( range . size ( ) = = 0 )
return true ;
if ( is_range & & range . size ( ) = = 2 )
{
if ( val > = atof ( range [ 0 ] . c_str ( ) ) & & val < = atof ( range [ 1 ] . c_str ( ) ) )
return true ;
if ( val < atof ( range [ 0 ] . c_str ( ) ) )
val = atof ( range [ 0 ] . c_str ( ) ) ;
else
val = atof ( range [ 1 ] . c_str ( ) ) ;
return false ;
}
else if ( ! is_range )
{
for ( int i = 0 ; i < range . size ( ) ; + + i )
{
if ( fabs ( atof ( range [ i ] . c_str ( ) ) - val ) < .000001 )
return true ;
}
}
val = atof ( init . c_str ( ) ) ;
return false ;
}
2022-11-10 02:02:52 +00:00
bool hg_scanner : : check_range ( const char * name , std : : string & val )
2022-05-03 03:56:07 +00:00
{
std : : vector < std : : string > range ;
std : : string init ( " " ) , in ( val ) ;
bool is_range = false ; ;
2022-11-10 02:02:52 +00:00
get_range ( name , range , init , is_range ) ;
2022-05-03 03:56:07 +00:00
if ( range . size ( ) = = 0 )
return true ;
for ( int i = 0 ; i < range . size ( ) ; + + i )
{
if ( in = = range [ i ] )
return true ;
}
val = init ;
return false ;
}
2022-08-02 03:14:58 +00:00
bool hg_scanner : : check_paper_and_resolution ( int res , int paper )
{
if ( res = = 600 )
{
if ( paper = = PAPER_MAX_SIZE | |
paper = = PAPER_MAX_SIZE_CLIP | |
paper = = PAPER_TRIGEMINY )
{
VLOG_MINI_2 ( LOG_LEVEL_WARNING , " resolution '%d' is in-compatible with paper '%s' \n " , res , paper_string ( paper ) . c_str ( ) ) ;
return false ;
}
}
return true ;
}
bool hg_scanner : : check_resolution_and_quality ( int res , const char * quality )
{
2023-01-18 10:08:47 +00:00
if ( res = = 600 & & strcmp ( quality , hg_log : : lang_load ( ID_OPTION_VALUE_HZ_SDYX ) ) = = 0 )
2022-08-02 03:14:58 +00:00
{
VLOG_MINI_2 ( LOG_LEVEL_WARNING , " resolution '%d' is in-compatible with quality '%s' \n " , res , quality ) ;
return false ;
}
return true ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : restore ( const char * name )
2022-05-03 03:56:07 +00:00
{
std : : string val ( " " ) ;
2022-11-10 02:02:52 +00:00
int ret = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
2022-11-10 02:02:52 +00:00
setting_jsn_ . at ( name ) . at ( " type " ) . get_to ( val ) ;
2022-05-03 03:56:07 +00:00
if ( val = = " string " )
{
2023-01-28 07:19:10 +00:00
val = get_setting_item_string ( name , " default " ) ;
2022-05-03 03:56:07 +00:00
char * buf = NULL ;
int size = 0 ;
2022-11-10 02:02:52 +00:00
setting_jsn_ . at ( name ) . at ( " size " ) . get_to ( size ) ;
2022-05-03 03:56:07 +00:00
buf = ( char * ) malloc ( size + 4 ) ;
2022-11-16 10:20:10 +00:00
if ( buf )
{
bzero ( buf , size + 4 ) ;
strcpy ( buf , val . c_str ( ) ) ;
ret = set_setting ( name , buf , val . length ( ) ) ;
free ( buf ) ;
}
else
return SCANNER_ERR_INSUFFICIENT_MEMORY ;
2022-05-03 03:56:07 +00:00
}
else if ( val = = " int " )
{
int v = 0 ;
2022-11-10 02:02:52 +00:00
setting_jsn_ . at ( name ) . at ( " default " ) . get_to ( v ) ;
ret = set_setting ( name , ( char * ) & v , sizeof ( v ) ) ;
2022-05-03 03:56:07 +00:00
}
else if ( val = = " float " )
{
double v = .0f ;
2022-11-10 02:02:52 +00:00
setting_jsn_ . at ( name ) . at ( " default " ) . get_to ( v ) ;
ret = set_setting ( name , ( char * ) & v , sizeof ( v ) ) ;
2022-05-03 03:56:07 +00:00
}
else if ( val = = " bool " )
{
bool v = false ;
2022-11-10 02:02:52 +00:00
setting_jsn_ . at ( name ) . at ( " default " ) . get_to ( v ) ;
ret = set_setting ( name , ( char * ) & v , sizeof ( v ) ) ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
return ret ;
2022-05-03 03:56:07 +00:00
}
bool hg_scanner : : get_default_value ( void * buf , json * jsn )
{
std : : string type ( " " ) ;
jsn - > at ( " type " ) . get_to ( type ) ;
if ( type = = " bool " )
{
bool v = false ;
jsn - > at ( " default " ) . get_to ( v ) ;
* ( ( SANE_Bool * ) buf ) = v ;
}
else if ( type = = " int " )
{
int v = 0 ;
jsn - > at ( " default " ) . get_to ( v ) ;
* ( ( SANE_Int * ) buf ) = v ;
}
else if ( type = = " float " )
{
double v = 0 ;
jsn - > at ( " default " ) . get_to ( v ) ;
* ( ( SANE_Fixed * ) buf ) = SANE_FIX ( v ) ;
}
else if ( type = = " string " )
{
type = " " ;
2023-01-28 07:19:10 +00:00
if ( jsn - > at ( " default " ) . is_number ( ) )
{
int n = 0 ;
jsn - > at ( " default " ) . get_to ( n ) ;
type = hg_log : : lang_load ( n ) ;
}
else
jsn - > at ( " default " ) . get_to ( type ) ;
2022-05-03 03:56:07 +00:00
strcpy ( ( char * ) buf , type . c_str ( ) ) ;
}
else
return false ;
return true ;
}
bool hg_scanner : : is_to_file ( void )
{
return resolution_ > 200
| | paper_size_ = = TwSS : : USStatement
| | paper_size_ = = TwSS : : MaxSize
| | paper_size_ = = TwSS : : Trigeminy ;
}
void hg_scanner : : thread_handle_image_process ( void )
{
2022-08-04 01:36:46 +00:00
//while (run_ && !user_cancel_)
while ( run_ )
2022-05-03 03:56:07 +00:00
{
2022-06-01 03:04:10 +00:00
std : : shared_ptr < tiny_buffer > tiny_buffer ;
if ( imgs_ . Size ( ) = = 0 )
2022-05-03 03:56:07 +00:00
{
if ( wait_usb_ . is_waiting ( ) )
break ;
this_thread : : sleep_for ( chrono : : milliseconds ( 30 ) ) ;
continue ;
}
2023-01-28 07:19:10 +00:00
uint32_t id = - 1 ;
tiny_buffer = imgs_ . Take ( & id ) ;
2022-08-24 09:27:45 +00:00
if ( tiny_buffer - > swap ( ) )
{
try
{
2023-01-16 08:03:14 +00:00
if ( ! ImagePrc_pHandle_ )
2022-11-01 09:20:57 +00:00
{
2023-01-16 08:03:14 +00:00
2022-11-01 09:20:57 +00:00
VLOG_MINI_1 ( LOG_LEVEL_FATAL , " Get Image Process is NULL pid is %d. \n " , pid_ ) ;
2022-11-26 02:00:40 +00:00
stop_fatal_ = SCANNER_ERR_INSUFFICIENT_MEMORY ;
2022-11-01 09:20:57 +00:00
stop ( ) ;
break ;
}
2023-01-28 07:19:10 +00:00
image_process ( tiny_buffer , id ) ;
2022-08-24 09:27:45 +00:00
}
2022-12-31 03:06:46 +00:00
catch ( const std : : exception & e )
{
if ( is_dpi_color_check )
2022-12-31 04:08:44 +00:00
{
is_dpi_color_check = false ;
2022-12-31 03:06:46 +00:00
stop_fatal_ = SCANNER_ERR_DEVICE_DISTORTION ;
2022-12-31 04:08:44 +00:00
}
2022-12-31 03:06:46 +00:00
else
stop_fatal_ = SCANNER_ERR_INSUFFICIENT_MEMORY ;
VLOG_MINI_1 ( LOG_LEVEL_ALL , " is opencv Fatal: %s \n " , e . what ( ) ) ;
2023-01-28 07:19:10 +00:00
stop ( ) ;
2022-12-31 03:06:46 +00:00
break ;
}
2022-08-24 09:27:45 +00:00
catch ( . . . )
{
2022-08-25 01:07:38 +00:00
VLOG_MINI_1 ( LOG_LEVEL_FATAL , " FATAL: Insufficient memory when proecss image with %d bytes. \n " , tiny_buffer - > size ( ) ) ;
2022-11-26 02:00:40 +00:00
stop_fatal_ = SCANNER_ERR_INSUFFICIENT_MEMORY ;
2022-10-22 06:46:54 +00:00
stop ( ) ;
2022-08-24 09:27:45 +00:00
}
}
2022-05-03 03:56:07 +00:00
else
{
2022-06-01 03:04:10 +00:00
VLOG_MINI_1 ( LOG_LEVEL_FATAL , " Reload USB data '%s' failed! \n " , tiny_buffer - > file ( ) . c_str ( ) ) ;
2022-05-03 03:56:07 +00:00
}
}
}
void hg_scanner : : working_begin ( void * )
{
2022-11-26 02:00:40 +00:00
stop_fatal_ = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
final_img_index_ = 0 ;
2022-08-06 06:18:53 +00:00
status_ = SCANNER_ERR_OK ;
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCAN_WORKING ) , SANE_EVENT_WORKING , SCANNER_ERR_OK ) ;
2022-06-01 03:04:10 +00:00
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " [%s] scanning ... \n " , hg_log : : current_time ( ) . c_str ( ) ) ;
2022-05-03 03:56:07 +00:00
}
void hg_scanner : : working_done ( void * )
{
imgs_ . Clear ( ) ;
2022-06-07 10:06:28 +00:00
if ( user_cancel_ )
final_imgs_ . clear ( ) ;
2022-05-03 03:56:07 +00:00
2022-11-26 02:00:40 +00:00
if ( status_ = = SCANNER_ERR_OK & & stop_fatal_ )
status_ = stop_fatal_ ;
2022-05-03 03:56:07 +00:00
switch ( status_ )
{
2022-05-17 07:04:55 +00:00
case SCANNER_ERR_OK :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCAN_STOPPED ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-05-03 03:56:07 +00:00
break ;
2022-05-17 07:04:55 +00:00
case SCANNER_ERR_DEVICE_BUSY :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_PC_BUSY ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-05-03 03:56:07 +00:00
break ;
2022-05-17 07:04:55 +00:00
case SCANNER_ERR_DEVICE_STOPPED :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCAN_STOPPED ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-05-03 03:56:07 +00:00
break ;
2022-05-17 07:04:55 +00:00
case SCANNER_ERR_DEVICE_COVER_OPENNED :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_COVER_OPENNED ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-05-03 03:56:07 +00:00
break ;
2022-05-17 07:04:55 +00:00
case SCANNER_ERR_DEVICE_NO_PAPER :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_NO_PAPER ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-05-03 03:56:07 +00:00
break ;
2022-05-17 07:04:55 +00:00
case SCANNER_ERR_DEVICE_FEEDING_PAPER :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_FEEDING_PAPER ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-05-03 03:56:07 +00:00
break ;
2022-05-17 07:04:55 +00:00
case SCANNER_ERR_DEVICE_NOT_FOUND :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_NOT_FOUND ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-05-03 03:56:07 +00:00
break ;
2022-05-17 07:04:55 +00:00
case SCANNER_ERR_DEVICE_SLEEPING :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_SLEEPING ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-05-03 03:56:07 +00:00
break ;
2022-05-17 07:04:55 +00:00
case SCANNER_ERR_DEVICE_COUNT_MODE :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_COUNT_MODE ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-05-03 03:56:07 +00:00
break ;
2022-05-17 07:04:55 +00:00
case SCANNER_ERR_DEVICE_DOUBLE_FEEDING :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_DOUBLE_FEEDING ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-05-03 03:56:07 +00:00
break ;
2022-05-17 07:04:55 +00:00
case SCANNER_ERR_DEVICE_PAPER_JAMMED :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_PAPER_JAMMED ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-05-03 03:56:07 +00:00
break ;
2022-05-17 07:04:55 +00:00
case SCANNER_ERR_DEVICE_STAPLE_ON :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_STAPLE_ON ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-05-03 03:56:07 +00:00
break ;
2022-05-17 07:04:55 +00:00
case SCANNER_ERR_DEVICE_PAPER_SKEW :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_PAPER_SKEW ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-05-03 03:56:07 +00:00
break ;
2022-05-17 07:04:55 +00:00
case SCANNER_ERR_DEVICE_SIZE_CHECK :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_SIZE_CHECK ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-05-03 03:56:07 +00:00
break ;
2022-05-17 07:04:55 +00:00
case SCANNER_ERR_DEVICE_DOGEAR :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_DOGEAR ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-05-03 03:56:07 +00:00
break ;
2022-05-17 07:04:55 +00:00
case SCANNER_ERR_DEVICE_NO_IMAGE :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_NO_IMAGE ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-05-03 03:56:07 +00:00
break ;
2022-05-17 07:04:55 +00:00
case SCANNER_ERR_DEVICE_SCANN_ERROR :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_SCANN_ERROR ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-05-03 03:56:07 +00:00
break ;
2022-05-17 07:04:55 +00:00
case SCANNER_ERR_DEVICE_PC_BUSY :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_PC_BUSY ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-05-03 03:56:07 +00:00
break ;
2022-05-23 06:10:18 +00:00
case SCANNER_ERR_INSUFFICIENT_MEMORY :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_INSUFFICIENT_MEMORY ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-10-28 03:01:01 +00:00
break ;
2022-05-23 06:40:52 +00:00
case SCANNER_ERR_TIMEOUT :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_TIMEOUT ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-10-28 03:01:01 +00:00
break ;
case SCANNER_ERR_DEVICE_ISLOCK :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_ISLOCK ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-10-28 03:01:01 +00:00
break ;
2022-12-30 09:14:49 +00:00
case SCANNER_ERR_DEVICE_AUTO_FAIL_OVER :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_AUTO_FAIL_OVER ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-12-30 09:14:49 +00:00
break ;
2022-12-31 03:06:46 +00:00
case SCANNER_ERR_DEVICE_DISTORTION :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_DISTORTION ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-12-31 03:06:46 +00:00
break ;
2022-05-03 03:56:07 +00:00
default :
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( user_cancel_ ? hg_log : : lang_load ( ID_STATU_DESC_SCAN_CANCELED ) : hg_log : : lang_load ( ID_STATU_DESC_SCAN_STOPPED ) , SANE_EVENT_SCAN_FINISHED , status_ ) ;
2022-05-03 03:56:07 +00:00
break ;
}
if ( test_1_paper_ )
{
2022-05-30 03:04:26 +00:00
LOG_INFO ( LOG_LEVEL_DEBUG_INFO , " scanning mode: finished testing ONE paper, restore to normal scanning. \n " ) ;
2022-05-03 03:56:07 +00:00
}
else
{
2022-06-01 03:04:10 +00:00
VLOG_MINI_3 ( LOG_LEVEL_DEBUG_INFO , " [%s] scanned %d picture(s) and finished with error %s. \n " , hg_log : : current_time ( ) . c_str ( ) , final_img_index_ , hg_scanner_err_name ( status_ ) ) ;
2022-05-03 03:56:07 +00:00
}
test_1_paper_ = false ;
}
2022-05-06 05:37:14 +00:00
void hg_scanner : : reset_custom_area_range ( int paper )
{
if ( paper = = PAPER_A3 )
{
paper_size_mm_ . cx = 297 ;
paper_size_mm_ . cy = 420 ;
}
else if ( paper = = PAPER_A4 )
{
paper_size_mm_ . cx = 210 ;
paper_size_mm_ . cy = 297 ;
}
else if ( paper = = PAPER_A4_LATERAL )
{
paper_size_mm_ . cx = 297 ;
paper_size_mm_ . cy = 210 ;
}
else if ( paper = = PAPER_A5 )
{
paper_size_mm_ . cx = 148 ;
paper_size_mm_ . cy = 210 ;
}
else if ( paper = = PAPER_A5_LATERAL )
{
paper_size_mm_ . cx = 210 ;
paper_size_mm_ . cy = 148 ;
}
else if ( paper = = PAPER_A6 )
{
paper_size_mm_ . cx = 105 ;
paper_size_mm_ . cy = 148 ;
}
else if ( paper = = PAPER_A6_LATERAL )
{
paper_size_mm_ . cx = 148 ;
paper_size_mm_ . cy = 105 ;
}
else if ( paper = = PAPER_B4 )
{
paper_size_mm_ . cx = 250 ;
paper_size_mm_ . cy = 353 ;
}
else if ( paper = = PAPER_B5 )
{
paper_size_mm_ . cx = 176 ;
paper_size_mm_ . cy = 250 ;
}
else if ( paper = = PAPER_B6 )
{
paper_size_mm_ . cx = 125 ;
paper_size_mm_ . cy = 176 ;
}
else if ( paper = = PAPER_B5_LATERAL )
{
paper_size_mm_ . cx = 250 ;
paper_size_mm_ . cy = 176 ;
}
else if ( paper = = PAPER_B6_LATERAL )
{
paper_size_mm_ . cx = 176 ;
paper_size_mm_ . cy = 125 ;
}
else
{
2022-05-06 10:02:06 +00:00
paper_size_mm_ . cx = 210 ;
paper_size_mm_ . cy = 297 ;
2022-05-06 05:37:14 +00:00
}
2022-11-10 02:02:52 +00:00
// adjust custom area data ...
float v = reset_custom_area_jsn_value ( SANE_STD_OPT_NAME_CUSTOM_AREA_LEFT , custom_area_lt_x_ , .0f , paper_size_mm_ . cx , .0f , paper_size_mm_ . cx ) ;
reset_custom_area_jsn_value ( SANE_STD_OPT_NAME_CUSTOM_AREA_RIGHT , custom_area_br_x_ , .0f , paper_size_mm_ . cx , v , paper_size_mm_ . cx ) ;
v = reset_custom_area_jsn_value ( SANE_STD_OPT_NAME_CUSTOM_AREA_TOP , custom_area_lt_y_ , .0f , paper_size_mm_ . cy , .0f , paper_size_mm_ . cy ) ;
reset_custom_area_jsn_value ( SANE_STD_OPT_NAME_CUSTOM_AREA_BOTTOM , custom_area_br_y_ , .0f , paper_size_mm_ . cy , v , paper_size_mm_ . cy ) ;
}
float hg_scanner : : reset_custom_area_jsn_value ( const char * name , double & var , float range_l , float range_u , float value_l , float value_u )
{
custom_area_br_y_ ;
if ( setting_jsn_ . contains ( name ) )
{
float v = .0f , tmp = .0f ;
setting_jsn_ . at ( name ) . at ( " cur " ) . get_to ( v ) ;
tmp = v ;
if ( v < value_l )
v = value_l ;
else if ( v > value_u )
v = value_u ;
if ( ! IS_DOUBLE_EQUAL ( tmp , v ) )
setting_jsn_ . at ( name ) . at ( " cur " ) = v ;
value_l = v ;
setting_jsn_ . at ( name ) . at ( " default " ) . get_to ( v ) ;
tmp = v ;
if ( v < range_l )
v = range_l ;
else if ( v > range_u )
v = range_u ;
if ( ! IS_DOUBLE_EQUAL ( tmp , v ) )
setting_jsn_ . at ( name ) . at ( " default " ) = v ;
if ( var < range_l )
var = range_l ;
else if ( var > range_u )
var = range_u ;
if ( setting_jsn_ . at ( name ) . contains ( " range " ) )
{
float lower = range_l , upper = range_u ;
if ( setting_jsn_ . at ( name ) . at ( " range " ) . contains ( " min " ) )
{
setting_jsn_ . at ( name ) . at ( " range " ) . at ( " min " ) . get_to ( lower ) ;
tmp = lower ;
if ( lower < range_l )
lower = range_l ;
else if ( lower > range_u )
lower = range_u ;
if ( ! IS_DOUBLE_EQUAL ( lower , tmp ) )
setting_jsn_ . at ( name ) . at ( " range " ) . at ( " min " ) = lower ;
}
if ( setting_jsn_ . at ( name ) . at ( " range " ) . contains ( " max " ) )
{
setting_jsn_ . at ( name ) . at ( " range " ) . at ( " max " ) . get_to ( upper ) ;
tmp = upper ;
if ( upper < lower )
upper = lower ;
else if ( upper > range_u )
upper = range_u ;
if ( ! IS_DOUBLE_EQUAL ( upper , tmp ) )
setting_jsn_ . at ( name ) . at ( " range " ) . at ( " max " ) = upper ;
}
}
}
return value_l ;
2022-05-06 05:37:14 +00:00
}
2022-06-14 09:02:19 +00:00
int hg_scanner : : set_color_change ( void )
{
// if (/* condition */)
// {
// /* code */
// }
return SCANNER_ERR_OK ;
}
2022-10-18 08:23:22 +00:00
int hg_scanner : : hgpaper_to_devspaper ( Paper_Map papermap [ ] , int len , int & paper , bool * exact , TwSS * type )
{
int ind = 0 ;
bool good = true , * r = exact ? exact : & good ;
for ( int i = 0 ; i < len ; + + i )
{
if ( paper = = papermap [ i ] . paper )
{
ind = i ;
break ;
}
}
if ( paper = = papermap [ ind ] . paper )
* r = true ;
else
* r = false ;
paper = papermap [ ind ] . paper ;
if ( type )
* type = papermap [ ind ] . type ;
return ind ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : invoke_setting_xxx ( int ( hg_scanner : : * func ) ( void * ) , void * data )
2022-06-28 09:16:03 +00:00
{
int ret = SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-07-08 02:33:05 +00:00
auto it = setting_map_ . begin ( ) ;
2022-06-28 09:16:03 +00:00
while ( it ! = setting_map_ . end ( ) )
{
2022-07-08 02:33:05 +00:00
if ( it - > second = = func )
2022-06-28 09:16:03 +00:00
{
2022-11-10 02:02:52 +00:00
ret = set_setting ( it - > first . c_str ( ) , data , 0 ) ;
2022-06-28 09:16:03 +00:00
break ;
}
2022-07-08 02:33:05 +00:00
+ + it ;
2022-06-28 09:16:03 +00:00
}
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_restore ( void * data )
2022-05-03 03:56:07 +00:00
{
// restore ...
notify_setting_result_ = false ;
2022-11-10 02:02:52 +00:00
for ( auto & v : setting_map_ )
{
if ( setting_jsn_ . contains ( v . first . c_str ( ) ) )
{
std : : string t ( " " ) ;
setting_jsn_ . at ( v . first . c_str ( ) ) . at ( " type " ) . get_to ( t ) ;
if ( t ! = " group " & & t ! = " button " )
restore ( v . first . c_str ( ) ) ;
}
}
2022-05-03 03:56:07 +00:00
notify_setting_result_ = true ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_CONFIGURATION_CHANGED ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_help ( void * data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
std : : string helpfile = helpfile_ ;
std : : string com = " xdg-open " ; //注意空格保留
2022-05-20 07:53:40 +00:00
printf ( " helpfile = %s \r \n " , helpfile . c_str ( ) ) ;
2022-07-18 08:56:03 +00:00
# if defined(WIN32) || defined(_WIN64)
2022-05-27 01:24:28 +00:00
com = " " ;
2022-06-01 03:04:10 +00:00
helpfile . insert ( 0 , hg_log : : get_scanner_path ( ) ) ;
2022-05-03 03:56:07 +00:00
FILE * src = fopen ( helpfile . c_str ( ) , " rb " ) ;
if ( src )
fclose ( src ) ;
else
# else
if ( access ( helpfile . c_str ( ) , F_OK ) = = - 1 )
# endif
{
2022-05-30 03:04:26 +00:00
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " App_Help_pdf path is:%s system is:%d \r \n " , helpfile . c_str ( ) ) ;
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_OPEN_FILE_FAILED ;
2022-05-03 03:56:07 +00:00
return ret ;
}
com + = helpfile ;
2022-08-20 03:32:07 +00:00
# if defined(WIN32) || defined(_WIN64)
ShellExecuteA ( NULL , " Open " , com . c_str ( ) , NULL , NULL , SW_SHOWNORMAL ) ;
# else
2022-05-03 03:56:07 +00:00
system ( com . c_str ( ) ) ;
2022-08-20 03:32:07 +00:00
# endif
2022-05-30 03:04:26 +00:00
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " App_Help_pdf path is:%s system is:%d \r \n " , helpfile . c_str ( ) ) ;
2022-05-03 03:56:07 +00:00
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_color_mode ( void * data )
2022-05-03 03:56:07 +00:00
{
std : : string str ( ( char * ) data ) ;
int old = image_prc_param_ . bits . color_mode ,
2022-05-17 07:04:55 +00:00
sub = SCANNER_ERR_OK ,
2022-05-03 03:56:07 +00:00
val = 0 ,
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_OK ;
2022-11-10 02:02:52 +00:00
bool exact = check_range ( SANE_STD_OPT_NAME_COLOR_MODE , str ) ;
2022-05-03 03:56:07 +00:00
val = image_prc_param_ . bits . color_mode = match_best_color_mode ( str , NULL ) ;
sub = on_color_mode_changed ( val ) ;
image_prc_param_ . bits . color_mode = val ;
2022-05-17 07:04:55 +00:00
if ( sub = = SCANNER_ERR_NOT_EXACT )
2022-05-03 03:56:07 +00:00
{
image_prc_param_ . bits . color_mode = old ;
str = color_mode_string ( image_prc_param_ . bits . color_mode ) ;
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
}
else if ( sub )
{
ret = sub ;
image_prc_param_ . bits . color_mode = old ;
}
else if ( ! exact )
{
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
}
is_auto_matic_color = image_prc_param_ . bits . color_mode = = COLOR_MODE_AUTO_MATCH ? true : false ; // 等于COLOR_MODE_AUTO_MATCH 的时候颜色模式需要变为2 彩色模式图像参数和硬件参数都如此
2022-05-30 03:42:16 +00:00
VLOG_MINI_4 ( LOG_LEVEL_DEBUG_INFO , " Change color mode from %s to %s = %s color is =%s \n " , color_mode_string ( old ) . c_str ( ) , ( char * ) data , hg_scanner_err_name ( ret ) , str . c_str ( ) ) ;
2022-05-17 07:04:55 +00:00
if ( ret = = SCANNER_ERR_NOT_EXACT )
2022-05-03 03:56:07 +00:00
strcpy ( ( char * ) data , str . c_str ( ) ) ;
return ret ;
}
2022-11-26 01:30:23 +00:00
int hg_scanner : : setting_multi_out ( void * data )
2022-05-21 08:56:14 +00:00
{
is_multiout = * ( ( bool * ) data ) ;
2022-06-02 03:47:44 +00:00
int val = image_prc_param_ . bits . color_mode ;
2022-11-10 02:02:52 +00:00
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " image_prc_param_.bits.multi_out %d \n " , image_prc_param_ . bits . multi_out ) ;
2022-06-02 03:47:44 +00:00
2022-11-19 10:16:43 +00:00
//if (is_multiout)
//{
// if (image_prc_param_.bits.multi_out == MULTI_GRAY_AND_BW)
// val = COLOR_MODE_256_GRAY;
// else
// val = COLOR_MODE_24_BITS;
//}
//on_color_mode_changed(val);
2022-06-14 09:02:19 +00:00
2022-05-21 08:56:14 +00:00
return SCANNER_ERR_OK ;
}
2022-11-26 01:30:23 +00:00
int hg_scanner : : setting_multi_out_type ( void * data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
2022-06-02 03:47:44 +00:00
std : : string str ( ( char * ) data ) ;
2022-06-06 04:03:24 +00:00
2022-11-10 02:02:52 +00:00
bool exact = check_range ( SANE_STD_OPT_NAME_MULTI_OUT_TYPE , str ) ;
2022-05-16 09:56:07 +00:00
int color ;
2022-05-03 03:56:07 +00:00
image_prc_param_ . bits . multi_out = match_best_multi_out ( str , NULL ) ;
2022-06-02 03:47:44 +00:00
save_multiout = str ;
2022-05-30 03:42:16 +00:00
VLOG_MINI_3 ( LOG_LEVEL_DEBUG_INFO , " set multi_out type from %s to %s = %s \n " , multi_out_string ( image_prc_param_ . bits . multi_out ) . c_str ( ) , ( char * ) data , hg_scanner_err_name ( ret ) ) ;
2022-05-17 01:46:26 +00:00
2022-11-19 10:16:43 +00:00
/*if (image_prc_param_.bits.multi_out == MULTI_GRAY_AND_BW)
2022-05-16 09:56:07 +00:00
color = COLOR_MODE_256_GRAY ;
else
color = COLOR_MODE_24_BITS ;
2022-06-06 04:03:24 +00:00
2022-11-19 10:16:43 +00:00
on_color_mode_changed ( color ) ; */
2022-05-03 03:56:07 +00:00
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_rid_color ( void * data )
2022-05-03 03:56:07 +00:00
{
std : : string str ( ( char * ) data ) ;
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ,
2022-05-03 03:56:07 +00:00
old = image_prc_param_ . bits . rid_color ;
2022-11-10 02:02:52 +00:00
bool exact = check_range ( SANE_STD_OPT_NAME_FILTER , str ) ;
2022-05-03 03:56:07 +00:00
image_prc_param_ . bits . rid_color = match_best_rid_color ( str , NULL ) ;
2022-11-24 13:58:29 +00:00
int color = image_prc_param_ . bits . color_mode ;
on_color_mode_changed ( color ) ;
2022-05-03 03:56:07 +00:00
if ( ! exact )
{
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
strcpy ( ( char * ) data , str . c_str ( ) ) ;
}
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_rid_multi_red ( void * data )
2022-05-03 03:56:07 +00:00
{
image_prc_param_ . bits . rid_red = * ( ( bool * ) data ) ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_rid_answer_red ( void * data )
2022-05-03 03:56:07 +00:00
{
image_prc_param_ . bits . rid_answer_red = * ( ( bool * ) data ) ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_erase_background ( void * data )
2022-05-03 03:56:07 +00:00
{
image_prc_param_ . bits . erase_bakground = * ( ( bool * ) data ) ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_erase_background_range ( void * data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
erase_bkg_range_ = * ( ( int * ) data ) ;
2022-11-10 02:02:52 +00:00
if ( ! check_range ( SANE_STD_OPT_NAME_BKG_COLOR_RANGE , erase_bkg_range_ ) )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
* ( ( int * ) data ) = erase_bkg_range_ ;
}
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_noise_optimize ( void * data )
2022-05-03 03:56:07 +00:00
{
image_prc_param_ . bits . noise_optimize = * ( ( bool * ) data ) ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_noise_optimize_range ( void * data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
noise_range_ = * ( ( int * ) data ) ;
2022-11-10 02:02:52 +00:00
if ( ! check_range ( SANE_STD_OPT_NAME_NOISE_SIZE , noise_range_ ) )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
* ( ( int * ) data ) = noise_range_ ;
}
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_paper ( void * data )
2022-05-03 03:56:07 +00:00
{
std : : string paper ( ( char * ) data ) ;
2022-11-10 02:02:52 +00:00
bool exact = check_range ( SANE_STD_OPT_NAME_PAPER , paper ) ;
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK , sub = SCANNER_ERR_OK ,
2022-05-03 03:56:07 +00:00
val = 0 ,
old = image_prc_param_ . bits . paper ;
val = image_prc_param_ . bits . paper = match_best_paper ( paper , NULL ) ;
2022-08-02 03:14:58 +00:00
// check 600 dpi ...
if ( ! check_paper_and_resolution ( resolution_ , val ) )
{
image_prc_param_ . bits . paper = old ;
strcpy ( ( char * ) data , paper_string ( old ) . c_str ( ) ) ;
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
}
2022-05-03 03:56:07 +00:00
sub = on_paper_changed ( val ) ;
image_prc_param_ . bits . paper = val ;
2022-05-17 07:04:55 +00:00
if ( sub = = SCANNER_ERR_NOT_EXACT )
2022-05-03 03:56:07 +00:00
{
ret = sub ;
paper = paper_string ( image_prc_param_ . bits . paper ) ;
}
else if ( sub )
{
ret = sub ;
image_prc_param_ . bits . paper = old ;
}
else if ( ! exact )
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NOT_EXACT ;
2022-06-08 10:33:49 +00:00
if ( save_sizecheck )
{
2022-07-08 02:33:05 +00:00
//setting_paper_check(0,(void*)&save_sizecheck);
invoke_setting_xxx ( & hg_scanner : : setting_paper_check , & save_sizecheck ) ;
2022-06-08 10:33:49 +00:00
}
2022-05-30 03:42:16 +00:00
VLOG_MINI_3 ( LOG_LEVEL_DEBUG_INFO , " Change paper from %s to %s = %s \n " , paper_string ( old ) . c_str ( ) , ( char * ) data , hg_scanner_err_name ( ret ) ) ;
2022-05-03 03:56:07 +00:00
2023-01-28 07:19:10 +00:00
if ( ret = = SCANNER_ERR_NOT_EXACT )
strcpy ( ( char * ) data , paper . c_str ( ) ) ;
2022-05-06 05:37:14 +00:00
if ( old ! = image_prc_param_ . bits . paper )
reset_custom_area_range ( image_prc_param_ . bits . paper ) ;
2022-05-03 03:56:07 +00:00
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_paper_check ( void * data )
2022-05-03 03:56:07 +00:00
{
bool use = * ( ( bool * ) data ) ;
2022-06-08 10:33:49 +00:00
2022-05-03 03:56:07 +00:00
int ret = on_paper_check_changed ( use ) ;
2022-05-30 03:42:16 +00:00
VLOG_MINI_2 ( LOG_LEVEL_DEBUG_INFO , " Change paper size-checking %s = %s \n " , * ( ( bool * ) data ) ? " enabled " : " disabled " , hg_scanner_err_name ( ret ) ) ;
2022-05-03 03:56:07 +00:00
* ( ( bool * ) data ) = use ;
2022-06-08 10:33:49 +00:00
save_sizecheck = use ;
2022-05-03 03:56:07 +00:00
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_page ( void * data )
2022-05-03 03:56:07 +00:00
{
std : : string val ( ( char * ) data ) ;
2022-11-10 02:02:52 +00:00
bool exact = check_range ( SANE_STD_OPT_NAME_PAGE , val ) ;
2022-05-17 07:04:55 +00:00
int ret = exact ? SCANNER_ERR_OK : SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
2022-05-30 03:42:16 +00:00
VLOG_MINI_3 ( LOG_LEVEL_DEBUG_INFO , " Change page from %s to %s = %s \n " , page_string ( image_prc_param_ . bits . page ) . c_str ( ) , ( char * ) data , hg_scanner_err_name ( ret ) ) ;
2022-05-03 03:56:07 +00:00
image_prc_param_ . bits . page = match_best_page ( val , NULL ) ;
if ( ! exact )
strcpy ( ( char * ) data , val . c_str ( ) ) ;
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_page_omit_empty ( void * data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
omit_empty_level_ = * ( ( int * ) data ) ;
2022-11-10 02:02:52 +00:00
if ( ! check_range ( SANE_STD_OPT_NAME_DISCARD_BLANK_SENS , omit_empty_level_ ) )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
* ( ( int * ) data ) = omit_empty_level_ ;
}
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_resolution ( void * data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ,
2022-05-03 03:56:07 +00:00
old = resolution_ ,
2022-05-17 07:04:55 +00:00
sub = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
resolution_ = * ( ( int * ) data ) ;
2022-11-10 02:02:52 +00:00
if ( ! check_range ( SANE_STD_OPT_NAME_RESOLUTION , resolution_ ) )
2023-01-28 07:19:10 +00:00
{
* ( int * ) data = resolution_ ;
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NOT_EXACT ;
2023-01-28 07:19:10 +00:00
}
2022-08-02 03:14:58 +00:00
// check paper ...
if ( ! check_paper_and_resolution ( resolution_ , image_prc_param_ . bits . paper ) )
{
2023-01-13 06:24:37 +00:00
resolution_ = old ;
* ( ( int * ) data ) = old ;
2022-08-02 03:14:58 +00:00
2023-01-13 06:24:37 +00:00
return SCANNER_ERR_NOT_EXACT ;
2022-08-02 03:14:58 +00:00
}
2022-11-19 03:46:01 +00:00
/*if (!check_resolution_and_quality(resolution_, is_img_quality(is_quality_).c_str()))
2022-08-02 03:14:58 +00:00
{
if ( resolution_ = = 600 & & old < 300 )
{
char buf [ 128 ] = { 0 } ;
strcpy ( buf , OPTION_VALUE_HZ_HZYX ) ;
resolution_ = old ;
invoke_setting_xxx ( & hg_scanner : : setting_img_quality , buf ) ;
resolution_ = 600 ;
ret = SCANNER_ERR_CONFIGURATION_CHANGED ;
}
else
{
resolution_ = old ;
* ( ( int * ) data ) = old ;
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
}
2022-11-19 03:46:01 +00:00
} */
2022-08-02 03:14:58 +00:00
2022-05-03 03:56:07 +00:00
sub = on_resolution_changed ( resolution_ ) ;
2022-05-17 07:04:55 +00:00
if ( sub = = SCANNER_ERR_NOT_EXACT )
2022-05-03 03:56:07 +00:00
ret = sub ;
else if ( sub )
ret = sub ;
2022-05-30 03:42:16 +00:00
VLOG_MINI_3 ( LOG_LEVEL_DEBUG_INFO , " Change resolution from %d to %d = %s \n " , old , * ( ( int * ) data ) , hg_scanner_err_name ( ret ) ) ;
2022-11-19 03:46:01 +00:00
//*((int*)data) = resolution_;
2022-05-03 03:56:07 +00:00
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_exchagnge ( void * data )
2022-05-03 03:56:07 +00:00
{
image_prc_param_ . bits . exchange = * ( ( bool * ) data ) ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_split_image ( void * data )
2022-05-03 03:56:07 +00:00
{
image_prc_param_ . bits . split = * ( ( bool * ) data ) ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_automatic_skew ( void * data )
2022-05-03 03:56:07 +00:00
{
// automatic_skew_detection_ = *((bool*)data);
image_prc_param_ . bits . automatic_skew = * ( ( bool * ) data ) ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_rid_hole ( void * data )
2022-05-03 03:56:07 +00:00
{
image_prc_param_ . bits . rid_hole = * ( ( bool * ) data ) ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_rid_hoe_range ( void * data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
rid_hole_range_ = * ( ( double * ) data ) ;
2022-11-10 02:02:52 +00:00
if ( ! check_range ( SANE_STD_OPT_NAME_SEARCH_HOLE_RANGE , rid_hole_range_ ) )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
* ( ( int * ) data ) = rid_hole_range_ ;
}
rid_hole_range_ * = 100 ;
2022-05-30 03:04:26 +00:00
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " rid_hole_range_ = %f \r \n " , rid_hole_range_ ) ;
2022-05-03 03:56:07 +00:00
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_bright ( void * data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
bright_ = * ( ( int * ) data ) ;
2022-11-10 02:02:52 +00:00
if ( ! check_range ( SANE_STD_OPT_NAME_BRIGHTNESS , bright_ ) )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
* ( ( int * ) data ) = bright_ ;
}
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_contrast ( void * data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
contrast_ = * ( ( int * ) data ) ;
2022-11-10 02:02:52 +00:00
if ( ! check_range ( SANE_STD_OPT_NAME_CONTRAST , contrast_ ) )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
* ( ( int * ) data ) = contrast_ ;
}
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_gamma ( void * data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
gamma_ = * ( ( double * ) data ) ;
2022-11-10 02:02:52 +00:00
if ( ! check_range ( SANE_STD_OPT_NAME_GAMMA , gamma_ ) )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
* ( ( double * ) data ) = gamma_ ;
}
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_sharpen ( void * data )
2022-05-03 03:56:07 +00:00
{
std : : string str ( ( char * ) data ) ;
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ;
2022-11-10 02:02:52 +00:00
bool exact = check_range ( SANE_STD_OPT_NAME_SHARPEN , str ) ;
2022-05-03 03:56:07 +00:00
2022-05-30 03:04:26 +00:00
VLOG_MINI_2 ( LOG_LEVEL_DEBUG_INFO , " Change sharpen from %s to %s = " , sharpen_string ( image_prc_param_ . bits . sharpen ) . c_str ( ) , ( char * ) data ) ;
2022-05-03 03:56:07 +00:00
image_prc_param_ . bits . sharpen = match_best_sharpen ( str , NULL ) ;
if ( ! exact )
{
strcpy ( ( char * ) data , str . c_str ( ) ) ;
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
}
2022-05-30 03:04:26 +00:00
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " %d \n " , ret ) ;
2022-05-03 03:56:07 +00:00
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_dark_sample ( void * data )
2022-05-03 03:56:07 +00:00
{
image_prc_param_ . bits . dark_sample = * ( ( bool * ) data ) ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_erase_black_frame ( void * data )
2022-05-03 03:56:07 +00:00
{
image_prc_param_ . bits . erase_black_frame = * ( ( bool * ) data ) ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_threshold ( void * data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
threshold_ = * ( ( int * ) data ) ;
2022-11-10 02:02:52 +00:00
if ( ! check_range ( SANE_STD_OPT_NAME_THRESHOLD , threshold_ ) )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
* ( ( int * ) data ) = threshold_ ;
}
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_anti_noise ( void * data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
anti_noise_ = * ( ( int * ) data ) ;
2022-11-10 02:02:52 +00:00
if ( ! check_range ( SANE_STD_OPT_NAME_ANTI_NOISE_LEVEL , anti_noise_ ) )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
* ( ( int * ) data ) = anti_noise_ ;
}
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_margin ( void * data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
margin_ = * ( ( int * ) data ) ;
2022-11-10 02:02:52 +00:00
if ( ! check_range ( SANE_STD_OPT_NAME_MARGIN , margin_ ) )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
* ( ( int * ) data ) = margin_ ;
}
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_filling_background ( void * data )
2022-05-03 03:56:07 +00:00
{
std : : string str ( ( char * ) data ) ;
2022-11-10 02:02:52 +00:00
bool exact = check_range ( SANE_STD_OPT_NAME_FILL_BKG_MODE , str ) ;
2022-05-17 07:04:55 +00:00
int ret = exact ? SCANNER_ERR_OK : SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
image_prc_param_ . bits . fill_background = match_best_fill_background ( str , NULL ) ;
if ( ! exact )
{
strcpy ( ( char * ) data , str . c_str ( ) ) ;
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
}
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_is_permeate ( void * data )
2022-05-03 03:56:07 +00:00
{
image_prc_param_ . bits . is_permeate = * ( ( bool * ) data ) ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_is_permeate_lv ( void * data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
std : : string str ( ( char * ) data ) ;
2022-11-10 02:02:52 +00:00
bool exact = check_range ( SANE_STD_OPT_NAME_ANTI_PERMEATE_LEVEL , str ) ;
2022-05-03 03:56:07 +00:00
2022-05-30 03:04:26 +00:00
VLOG_MINI_2 ( LOG_LEVEL_DEBUG_INFO , " Change is_permeate_lv from %s to %s = " , is_permaeate_string ( image_prc_param_ . bits . is_permeate_lv_ ) . c_str ( ) , ( char * ) data ) ;
2022-05-03 03:56:07 +00:00
image_prc_param_ . bits . is_permeate_lv_ = match_best_permaeate_lv ( str , NULL ) ;
if ( ! exact )
{
strcpy ( ( char * ) data , str . c_str ( ) ) ;
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
}
2022-05-30 03:04:26 +00:00
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " %d \n " , ret ) ;
2022-05-03 03:56:07 +00:00
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_remove_morr ( void * data )
2022-05-03 03:56:07 +00:00
{
image_prc_param_ . bits . remove_morr = * ( ( bool * ) data ) ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_error_extention ( void * data )
2022-05-03 03:56:07 +00:00
{
image_prc_param_ . bits . error_extention = * ( ( bool * ) data ) ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_remove_texture ( void * data )
2022-05-03 03:56:07 +00:00
{
image_prc_param_ . bits . remove_txtture = * ( ( bool * ) data ) ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_ultrasonic_check ( void * data )
2022-05-03 03:56:07 +00:00
{
bool use = * ( ( bool * ) data ) ;
int ret = on_ultrasonic_check_changed ( use ) ;
if ( ret )
* ( ( bool * ) data ) = use ;
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_go_on_when_double_checked ( void * data )
2022-07-23 05:42:34 +00:00
{
bool ok = true ;
std : : string val ( ( char * ) data ) ;
double_paper_handle_ = double_paper_flag_from_option_value ( val , & ok ) ;
2022-07-23 11:46:24 +00:00
// 此处需要通知设备双张处理方式 ! ! !
// OPTION_VALUE_SZTPCL_xxx 共4种选择,目前只支持出现双张后停止的两种方式
// 若要上传出现双张的图片,请确保双张信号在图片之前发出来 ! ! !
2022-07-23 05:42:34 +00:00
if ( ok )
return SCANNER_ERR_OK ;
else
{
strcpy ( ( char * ) data , val . c_str ( ) ) ;
return SCANNER_ERR_NOT_EXACT ;
}
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_staple_check ( void * data )
2022-05-03 03:56:07 +00:00
{
bool use = * ( ( bool * ) data ) ;
int ret = on_staple_check_changed ( use ) ;
if ( ret )
* ( ( bool * ) data ) = use ;
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_scan_mode ( void * data )
2022-05-03 03:56:07 +00:00
{
std : : string str ( ( char * ) data ) ;
2022-11-10 02:02:52 +00:00
bool exact = check_range ( SANE_STD_OPT_NAME_SCAN_MODE , str ) ;
2022-05-17 07:04:55 +00:00
int ret = exact ? SCANNER_ERR_OK : SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
2023-01-18 10:08:47 +00:00
if ( strcmp ( str . c_str ( ) , hg_log : : lang_load ( ID_OPTION_VALUE_SMZS_LXSM ) ) = = 0 )
2022-05-03 03:56:07 +00:00
{
scan_count_ = - 1 ;
}
else
{
2022-11-10 02:02:52 +00:00
setting_jsn_ . at ( SANE_STD_OPT_NAME_SCAN_COUNT ) . at ( " cur " ) . get_to ( scan_count_ ) ;
2022-05-03 03:56:07 +00:00
}
2022-05-30 03:04:26 +00:00
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " set scanning pages to %d \n " , scan_count_ ) ;
2022-05-03 03:56:07 +00:00
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_scan_count ( void * data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ;
2023-01-28 07:19:10 +00:00
std : : string val ( get_setting_item_string ( SANE_STD_OPT_NAME_SCAN_MODE , " cur " ) ) ;
2022-05-03 03:56:07 +00:00
2023-01-18 10:08:47 +00:00
if ( val = = hg_log : : lang_load ( ID_OPTION_VALUE_SMZS_LXSM ) )
2022-05-03 03:56:07 +00:00
{
scan_count_ = - 1 ;
}
else
{
scan_count_ = * ( ( int * ) data ) ;
}
2022-05-30 03:04:26 +00:00
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " set scanning pages to %d \n " , scan_count_ ) ;
2022-05-03 03:56:07 +00:00
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_text_direction ( void * data )
2022-05-03 03:56:07 +00:00
{
std : : string str ( ( char * ) data ) ;
2022-11-10 02:02:52 +00:00
bool exact = check_range ( SANE_STD_OPT_NAME_TEXT_DIRECTION , str ) ;
2022-05-17 07:04:55 +00:00
int ret = exact ? SCANNER_ERR_OK : SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
2022-05-30 03:04:26 +00:00
VLOG_MINI_3 ( LOG_LEVEL_DEBUG_INFO , " Change text direction from '%s' to '%s' = %s \n " , text_direction_string ( image_prc_param_ . bits . text_direction ) . c_str ( )
2022-05-30 03:42:16 +00:00
, ( char * ) data , hg_scanner_err_name ( ret ) ) ;
2022-05-03 03:56:07 +00:00
image_prc_param_ . bits . text_direction = match_best_text_direction ( str , NULL ) ;
2022-11-01 09:20:57 +00:00
2022-05-03 03:56:07 +00:00
if ( ! exact )
strcpy ( ( char * ) data , str . c_str ( ) ) ;
2022-11-01 09:20:57 +00:00
if ( image_prc_param_ . bits . text_direction = = TEXT_DIRECTION_AUTO & & ImagePrc_pHandle_ )
{
hg_imgproc : : init_auto_txt_hanld ( ImagePrc_pHandle_ ) ;
}
else if ( image_prc_param_ . bits . text_direction ! = TEXT_DIRECTION_AUTO & & ImagePrc_pHandle_ )
{
hg_imgproc : : free_auto_txt_hanld ( ImagePrc_pHandle_ ) ;
}
2022-05-03 03:56:07 +00:00
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_rotate_bkg_180 ( void * data )
2022-05-03 03:56:07 +00:00
{
image_prc_param_ . bits . rotate_back_180 = * ( ( bool * ) data ) ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_fractate_check ( void * data )
2022-05-03 03:56:07 +00:00
{
image_prc_param_ . bits . fractate_check = * ( ( bool * ) data ) ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_fractate_check_level ( void * data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
fractate_level_ = * ( ( int * ) data ) ;
2022-11-10 02:02:52 +00:00
if ( ! check_range ( SANE_STD_OPT_NAME_DOG_EAR_SIZE , fractate_level_ ) )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NOT_EXACT ;
2022-05-03 03:56:07 +00:00
* ( ( int * ) data ) = fractate_level_ ;
}
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_skew_check ( void * data )
2022-05-03 03:56:07 +00:00
{
bool use = * ( ( bool * ) data ) ;
int ret = on_skew_check_changed ( use ) ;
if ( ret )
* ( ( bool * ) data ) = use ;
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_skew_check_level ( void * data )
2022-05-03 03:56:07 +00:00
{
int level = * ( ( int * ) data ) ;
2022-11-10 02:02:52 +00:00
bool exact = check_range ( SANE_STD_OPT_NAME_ASKEW_RANGE , level ) ;
2022-05-17 07:04:55 +00:00
int ret = exact ? SCANNER_ERR_OK : SCANNER_ERR_NOT_EXACT ,
2022-05-03 03:56:07 +00:00
sub = on_skew_check_level_changed ( level ) ;
if ( sub )
{
ret = sub ;
}
if ( ret )
* ( ( int * ) data ) = level ;
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_is_custom_gamma ( void * data )
2022-05-06 05:37:14 +00:00
{
2022-06-08 08:42:27 +00:00
custom_gamma_ = * ( ( bool * ) data ) ;
2022-05-06 05:37:14 +00:00
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-06 05:37:14 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_custom_gamma_data ( void * data )
2022-05-06 05:37:14 +00:00
{
2022-05-06 06:37:52 +00:00
SANE_Gamma * gamma = ( SANE_Gamma * ) data ;
2022-05-06 05:37:14 +00:00
2022-05-06 08:39:00 +00:00
memcpy ( custom_gamma_val_ , gamma , sizeof ( * custom_gamma_val_ ) ) ;
2022-05-06 05:37:14 +00:00
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-06 05:37:14 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_is_custom_area ( void * data )
2022-05-06 05:37:14 +00:00
{
2022-06-08 08:42:27 +00:00
custom_area_ = * ( ( bool * ) data ) ;
2022-05-06 05:37:14 +00:00
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-06 05:37:14 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_custom_area_left ( void * data )
2022-05-06 05:37:14 +00:00
{
SANE_Fixed * v = ( SANE_Fixed * ) data ;
2022-05-06 09:34:17 +00:00
custom_area_lt_x_ = * ( ( double * ) data ) ;
2022-05-06 05:37:14 +00:00
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-06 05:37:14 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_custom_area_top ( void * data )
2022-05-06 05:37:14 +00:00
{
SANE_Fixed * v = ( SANE_Fixed * ) data ;
2022-05-06 09:34:17 +00:00
custom_area_lt_y_ = * ( ( double * ) data ) ;
2022-05-06 05:37:14 +00:00
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-06 05:37:14 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_custom_area_right ( void * data )
2022-05-06 05:37:14 +00:00
{
SANE_Fixed * v = ( SANE_Fixed * ) data ;
2022-05-06 09:34:17 +00:00
custom_area_br_x_ = * ( ( double * ) data ) ;
2022-05-06 05:37:14 +00:00
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-06 05:37:14 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_custom_area_bottom ( void * data )
2022-05-06 05:37:14 +00:00
{
SANE_Fixed * v = ( SANE_Fixed * ) data ;
2022-05-06 09:34:17 +00:00
custom_area_br_y_ = * ( ( double * ) data ) ;
2022-05-06 05:37:14 +00:00
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-06 05:37:14 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_img_quality ( void * data )
2022-05-09 07:02:00 +00:00
{
std : : string str ( ( char * ) data ) ;
2022-11-10 02:02:52 +00:00
bool exact = check_range ( SANE_STD_OPT_NAME_IMAGE_QUALITY , str ) ;
2022-05-17 07:04:55 +00:00
int ret = exact ? SCANNER_ERR_OK : SCANNER_ERR_NOT_EXACT ;
2022-08-02 03:14:58 +00:00
int old = is_quality_ ;
2022-05-30 03:04:26 +00:00
VLOG_MINI_3 ( LOG_LEVEL_DEBUG_INFO , " Change quality from '%s' to '%s' = %s \n " , is_img_quality ( is_quality_ ) . c_str ( )
2022-05-30 03:42:16 +00:00
, ( char * ) data , hg_scanner_err_name ( ret ) ) ;
2022-05-09 07:02:00 +00:00
is_quality_ = match_best_img_quality ( str , NULL ) ;
2022-11-19 03:46:01 +00:00
/*if (!check_resolution_and_quality(resolution_, is_img_quality(is_quality_).c_str()))
2022-08-02 03:14:58 +00:00
{
is_quality_ = old ;
strcpy ( ( char * ) data , is_img_quality ( is_quality_ ) . c_str ( ) ) ;
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-11-19 03:46:01 +00:00
} */
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-09 07:02:00 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_color_fill ( void * data )
2022-05-20 07:53:40 +00:00
{
is_color_fill = * ( ( bool * ) data ) ;
return SCANNER_ERR_OK ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_keep_watermark ( void * data )
2022-07-23 11:08:18 +00:00
{
keep_watermark_ = * ( bool * ) data ;
2022-07-30 03:19:20 +00:00
on_pic_type ( keep_watermark_ ) ;
2022-07-23 11:08:18 +00:00
return SCANNER_ERR_OK ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_black_white_threshold ( void * data )
2022-06-28 08:37:45 +00:00
{
2022-06-28 09:16:03 +00:00
bw_threshold_ = ( unsigned char ) ( * ( SANE_Int * ) data ) ;
2022-06-28 08:37:45 +00:00
return SCANNER_ERR_OK ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : setting_white_pixel_0 ( void * data )
2022-09-07 07:47:30 +00:00
{
is_white_0_ = * ( bool * ) data ;
return SCANNER_ERR_OK ;
}
2022-11-14 01:16:55 +00:00
int hg_scanner : : setting_feedmode ( void * data )
2022-07-23 10:01:44 +00:00
{
2022-08-08 10:15:51 +00:00
std : : string str ( ( char * ) data ) ;
int val = match_best_paper_strength ( str , NULL ) ;
if ( val = = feedmode_ )
return SCANNER_ERR_OK ;
2022-07-25 10:19:40 +00:00
2022-08-08 10:15:51 +00:00
int ret = on_set_feedmode ( val ) ;
2022-07-25 10:19:40 +00:00
if ( ret = = SCANNER_ERR_OK )
feedmode_ = val ;
2022-08-09 07:59:01 +00:00
2022-08-08 10:15:51 +00:00
VLOG_MINI_3 ( LOG_LEVEL_DEBUG_INFO , " setfeedmode from '%s' to '%s' = %s \n " , is_paper_strength ( feedmode_ ) . c_str ( )
, ( char * ) data , hg_scanner_err_name ( ret ) ) ;
2022-07-23 13:02:00 +00:00
return ret ;
2022-07-23 10:01:44 +00:00
}
2022-11-14 01:16:55 +00:00
int hg_scanner : : setting_sleeptime ( void * data )
2022-07-23 13:02:00 +00:00
{
2022-08-08 10:15:51 +00:00
std : : string str ( ( char * ) data ) ;
int val = match_best_sleep_time ( str , 0 ) ;
2022-08-13 07:14:23 +00:00
int mintosec = 0 ;
2022-08-08 10:15:51 +00:00
switch ( val )
{
case SLEEP_TIME_0MIN :
val = - 1 ; //不休眠 -1
break ;
case SLEEP_TIME_5MIN :
val = 5 ;
break ;
case SLEEP_TIME_10MIN :
val = 10 ;
break ;
case SLEEP_TIME_30MIN :
val = 30 ;
break ;
case SLEEP_TIME_60MIN :
val = 60 ;
break ;
case SLEEP_TIME_120MIN :
val = 120 ;
break ;
case SLEEP_TIME_240MIN :
val = 240 ;
break ;
}
if ( val = = sleeptime_ )
return SCANNER_ERR_OK ;
2022-08-13 07:14:23 +00:00
mintosec = val ;
if ( val ! = - 1 )
{
mintosec = val * 60 ;
}
2022-08-13 01:07:29 +00:00
int ret = set_sleep_time ( mintosec ) ;
2022-07-25 10:19:40 +00:00
if ( ret = = SCANNER_ERR_OK )
2022-08-08 10:15:51 +00:00
sleeptime_ = val ;
2022-07-23 13:02:00 +00:00
2022-08-13 01:07:29 +00:00
VLOG_MINI_3 ( LOG_LEVEL_DEBUG_INFO , " set sleeptime from (%s)min to (%s)min = %s \n " , is_sleep_time ( sleeptime_ ) . c_str ( )
2022-08-08 10:15:51 +00:00
, ( char * ) data , hg_scanner_err_name ( ret ) ) ;
2022-07-23 13:02:00 +00:00
return ret ;
}
2022-11-14 01:16:55 +00:00
int hg_scanner : : setting_auto_pick_paper ( void * data )
2022-08-09 07:59:01 +00:00
{
int ret = SCANNER_ERR_OK ;
bool isautopic = * ( ( bool * ) data ) ;
ret = on_pick_paper ( isautopic ) ;
return ret ;
}
2022-12-05 07:33:56 +00:00
int hg_scanner : : setting_auto_pick_paper_threshold ( void * data )
2022-08-09 07:59:01 +00:00
{
int ret = SCANNER_ERR_OK ;
double threshold = * ( ( double * ) data ) ;
ret = on_pick_paper_threshold ( threshold ) ;
return ret ;
}
2022-12-05 07:33:56 +00:00
int hg_scanner : : setting_auto_paper_scan ( void * data )
2022-08-11 09:19:24 +00:00
{
is_auto_paper_scan = * ( ( bool * ) data ) ;
2022-11-26 09:48:10 +00:00
if ( ! is_kernelsnap_220430_ & & is_auto_paper_scan )
{
is_auto_paper_scan = * ( bool * ) data = false ;
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_DEVICE_NOT_SUPPORTED ) , SANE_EVENT_ERROR , status_ ) ;
2022-11-26 09:48:10 +00:00
2022-11-29 08:13:56 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-11-26 09:48:10 +00:00
}
2022-08-11 09:19:24 +00:00
if ( ! is_auto_paper_scan )
{
on_is_auto_paper ( is_auto_paper_scan ) ;
}
return SCANNER_ERR_OK ;
}
2022-11-14 01:16:55 +00:00
int hg_scanner : : setting_isremove_left_hole ( void * data )
2022-09-11 15:56:27 +00:00
{
isremove_left_hole = * ( ( bool * ) data ) ;
return SCANNER_ERR_OK ;
}
2022-11-14 01:16:55 +00:00
int hg_scanner : : setting_isremove_right_hole ( void * data )
2022-09-11 15:56:27 +00:00
{
isremove_right_hole = * ( ( bool * ) data ) ;
return SCANNER_ERR_OK ;
}
2022-11-14 01:16:55 +00:00
int hg_scanner : : setting_isremove_top_hole ( void * data )
2022-09-11 15:56:27 +00:00
{
isremove_top_hole = * ( ( bool * ) data ) ;
return SCANNER_ERR_OK ;
}
2022-11-14 01:16:55 +00:00
int hg_scanner : : setting_isremove_low_hole ( void * data )
2022-09-11 15:56:27 +00:00
{
isremove_low_hole = * ( ( bool * ) data ) ;
return SCANNER_ERR_OK ;
}
2022-11-14 01:16:55 +00:00
int hg_scanner : : setting_isremove_left_hole_threshold ( void * data )
2022-09-11 15:56:27 +00:00
{
isremove_left_hole_threshold = * ( ( double * ) data ) ;
return SCANNER_ERR_OK ;
}
2022-11-14 01:16:55 +00:00
int hg_scanner : : setting_isremove_right_hole_threshold ( void * data )
2022-09-11 15:56:27 +00:00
{
isremove_right_hole_threshold = * ( ( double * ) data ) ;
return SCANNER_ERR_OK ;
}
2022-11-14 01:16:55 +00:00
int hg_scanner : : setting_isremove_top_hole_threshold ( void * data )
2022-09-11 15:56:27 +00:00
{
isremove_top_hole_threshold = * ( ( double * ) data ) ;
return SCANNER_ERR_OK ;
}
2022-11-14 01:16:55 +00:00
int hg_scanner : : setting_isremove_low_hole_threshold ( void * data )
2022-09-11 15:56:27 +00:00
{
isremove_low_hole_threshold = * ( ( double * ) data ) ;
return SCANNER_ERR_OK ;
}
2022-11-14 01:16:55 +00:00
int hg_scanner : : setting_fold_type ( void * data )
2022-10-22 08:18:13 +00:00
{
string str ( ( char * ) data ) ;
bool exact = NULL ;
int val = match_best_fold_type ( str , 0 ) ;
fold_type_ = val ;
return SCANNER_ERR_OK ;
}
2022-05-03 03:56:07 +00:00
int hg_scanner : : on_color_mode_changed ( int & color_mode )
{
2022-12-09 01:47:42 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
int hg_scanner : : on_paper_changed ( int & paper )
{
2022-12-09 01:47:42 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
int hg_scanner : : on_paper_check_changed ( bool & check )
{
2022-12-09 01:47:42 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
int hg_scanner : : on_resolution_changed ( int & dpi )
{
2022-12-09 01:47:42 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
int hg_scanner : : on_ultrasonic_check_changed ( bool & check )
{
2022-12-09 01:47:42 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
int hg_scanner : : on_staple_check_changed ( bool & check )
{
2022-12-09 01:47:42 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
int hg_scanner : : on_skew_check_changed ( bool & check )
{
2022-12-09 01:47:42 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
int hg_scanner : : on_skew_check_level_changed ( int & check )
{
2022-12-09 01:47:42 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
2022-07-23 10:01:44 +00:00
int hg_scanner : : on_set_feedmode ( int feedmode )
{
2022-12-09 01:47:42 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-07-23 10:01:44 +00:00
}
int hg_scanner : : on_get_feedmode ( int & feedmode )
{
2022-12-09 01:47:42 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-07-23 10:01:44 +00:00
}
2022-07-30 03:19:20 +00:00
int hg_scanner : : on_pic_type ( bool & pic )
{
2022-12-09 01:47:42 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-07-30 03:19:20 +00:00
}
2022-08-09 07:59:01 +00:00
int hg_scanner : : on_pick_paper ( bool autostrength )
{
2022-12-09 01:47:42 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-08-09 07:59:01 +00:00
}
int hg_scanner : : on_pick_paper_threshold ( double threshold )
{
2022-12-09 01:47:42 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-08-09 07:59:01 +00:00
}
2022-08-11 09:19:24 +00:00
int hg_scanner : : on_is_auto_paper ( bool isautopaper )
{
2022-12-09 01:47:42 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-08-11 09:19:24 +00:00
}
2022-12-28 01:56:54 +00:00
int hg_scanner : : on_cis_get_image ( bool isautopaper )
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
}
2022-05-03 03:56:07 +00:00
void hg_scanner : : on_device_reconnected ( void )
{
std : : lock_guard < std : : mutex > lock ( io_lock_ ) ;
2022-05-30 03:04:26 +00:00
VLOG_MINI_2 ( LOG_LEVEL_DEBUG_INFO , " %04x:%04x reconnected. \n " , io_ - > get_vid ( ) , io_ - > get_pid ( ) ) ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : set_setting_value ( const char * name , void * data , int len )
2022-05-03 03:56:07 +00:00
{
2022-12-09 01:47:42 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
int hg_scanner : : on_scanner_closing ( bool force )
{
2022-12-09 01:47:42 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
2022-11-26 02:17:48 +00:00
2022-05-03 03:56:07 +00:00
void hg_scanner : : thread_handle_usb_read ( void )
{
}
2022-12-05 15:01:13 +00:00
void hg_scanner : : thread_handle_islock_read ( void )
{
}
2022-07-15 08:04:09 +00:00
void hg_scanner : : adjust_color ( hg_imgproc : : HIMGPRC handle )
{
int tableLength = 0 ; // ZERO length perform color-adjust only
unsigned char buffer1 [ 256 * 3 ] ;
if ( custom_gamma_ )
{
if ( img_conf_ . pixtype = = COLOR_MODE_BLACK_WHITE | | img_conf_ . pixtype = = COLOR_MODE_256_GRAY )
{
tableLength = 256 ;
memcpy ( buffer1 , custom_gamma_val_ - > table , tableLength ) ;
}
else
{
// convert R[256] + G[256] + B[256] to BGR[256] ...
tableLength = 256 * 3 ;
for ( int i = 0 ; i < 256 ; + + i )
{
buffer1 [ i * 3 + 0 ] = custom_gamma_val_ - > table [ 256 * 2 + i ] ;
buffer1 [ i * 3 + 1 ] = custom_gamma_val_ - > table [ 256 * 1 + i ] ;
buffer1 [ i * 3 + 2 ] = custom_gamma_val_ - > table [ 256 * 0 + i ] ;
}
}
}
hg_imgproc : : adjust_color ( handle , buffer1 , tableLength ) ;
}
2022-11-01 09:20:57 +00:00
hg_imgproc : : IMGPRCPARAM hg_scanner : : get_image_process_object ( int model )
2022-07-15 08:04:09 +00:00
{
hg_imgproc : : IMGPRCPARAM param ;
hg_imgproc : : HIMGPRC handle = nullptr ;
2022-11-23 14:31:53 +00:00
//float bright = img_conf_.brightness,
// contrast = img_conf_.contrast;
2022-07-15 08:04:09 +00:00
bzero ( & param , sizeof ( param ) ) ;
param . bits = 8 ;
2022-11-23 14:31:53 +00:00
//image_prc_param_.bits.color_mode == COLOR_MODE_256_GRAY || image_prc_param_.bits.color_mode == COLOR_MODE_BLACK_WHITE
param . black_white = image_prc_param_ . bits . color_mode = = COLOR_MODE_BLACK_WHITE ;
2022-11-24 09:56:20 +00:00
if ( image_prc_param_ . bits . multi_out = = MULTI_GRAY_AND_BW & & is_multiout )
2022-11-24 09:38:31 +00:00
param . channels = 1 ;
2022-11-24 09:56:20 +00:00
else if ( ( image_prc_param_ . bits . multi_out = = MULTI_OUT_ALL
| | image_prc_param_ . bits . multi_out = = MULTI_COLOR_AND_GRAY
| | image_prc_param_ . bits . multi_out = = MULTI_COLOR_AND_BW ) & & is_multiout )
param . channels = 3 ;
2022-11-24 09:38:31 +00:00
else
param . channels = ( image_prc_param_ . bits . color_mode = = COLOR_MODE_24_BITS | | image_prc_param_ . bits . color_mode = = COLOR_MODE_AUTO_MATCH ) ? 3 : 1 ;
2022-11-24 08:57:31 +00:00
param . color_mode = image_prc_param_ . bits . color_mode = = COLOR_MODE_AUTO_MATCH ? 2 : image_prc_param_ . bits . color_mode ;
2022-07-15 08:04:09 +00:00
param . double_side = img_conf_ . is_duplex ;
param . dpi = img_conf_ . resolution_dst ;
2022-12-30 10:56:24 +00:00
param . cis_image = is_cis_image ;
2022-11-23 14:31:53 +00:00
//img_conf_.brightness = (float)bright_;
//img_conf_.contrast = (float)contrast_;
2022-07-15 08:04:09 +00:00
2022-11-01 09:20:57 +00:00
return param ;
2022-07-15 08:04:09 +00:00
}
2022-07-23 05:42:34 +00:00
SANE_Image_Statu hg_scanner : : last_usb_image_statu ( int err )
{
SANE_Image_Statu statu = SANE_Image_Statu_OK ;
if ( ! is_continue_when_double_paper ( double_paper_handle_ ) & &
is_save_img_when_double_paper ( double_paper_handle_ ) )
{
if ( err = = SCANNER_ERR_DEVICE_DOUBLE_FEEDING )
statu = SANE_Image_Statu_Double ;
2022-12-22 10:37:53 +00:00
//else if (err == SCANNER_ERR_DEVICE_PAPER_JAMMED)
//statu = SANE_Image_Statu_Jammed;
2022-07-23 05:42:34 +00:00
}
return statu ;
}
2022-05-03 03:56:07 +00:00
void hg_scanner : : init_settings ( const char * json_setting_text )
{
2022-11-10 02:02:52 +00:00
jsn_children_ . clear ( ) ;
setting_jsn_ = jsonconfig : : load_json_from_text ( json_setting_text , & jsn_children_ ) ;
2022-05-03 03:56:07 +00:00
2022-11-10 02:02:52 +00:00
VLOG_MINI_1 ( LOG_LEVEL_ALL , " Initialize %d settings ... \n " , jsn_children_ . size ( ) - 1 ) ;
2022-05-03 03:56:07 +00:00
notify_setting_result_ = false ;
2022-11-10 02:02:52 +00:00
for ( size_t i = 1 ; i < jsn_children_ . size ( ) ; + + i )
2022-05-03 03:56:07 +00:00
{
2022-11-10 02:02:52 +00:00
std : : string v ( jsn_children_ [ i ] ) ;
2022-05-03 03:56:07 +00:00
2022-11-10 02:02:52 +00:00
if ( ! setting_jsn_ . contains ( v . c_str ( ) ) )
continue ;
2022-05-09 08:59:22 +00:00
2022-11-10 02:02:52 +00:00
std : : string val ( " " ) ;
2023-01-28 07:19:10 +00:00
change_string_2_lang_id ( v . c_str ( ) , " title " ) ;
change_string_2_lang_id ( v . c_str ( ) , " desc " ) ;
2022-05-09 08:59:22 +00:00
2022-11-10 02:02:52 +00:00
setting_jsn_ . at ( v . c_str ( ) ) . at ( " type " ) . get_to ( val ) ;
2022-05-03 03:56:07 +00:00
if ( val = = " string " )
{
2023-01-28 07:19:10 +00:00
change_string_2_lang_id ( v . c_str ( ) , " cur " ) ;
change_string_2_lang_id ( v . c_str ( ) , " default " ) ;
if ( setting_jsn_ . at ( v . c_str ( ) ) . contains ( " range " ) )
{
for ( int i = 0 ; i < setting_jsn_ . at ( v . c_str ( ) ) . at ( " range " ) . size ( ) ; + + i )
{
int id = - 1 ;
setting_jsn_ . at ( v . c_str ( ) ) . at ( " range " ) . at ( i ) . get_to ( val ) ;
id = lang_get_string_id ( val . c_str ( ) , true ) ;
if ( id = = - 1 )
{
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " LANGUAGE-ERR: lost item ID of '%s' \n " , val . c_str ( ) ) ;
}
else
setting_jsn_ . at ( v . c_str ( ) ) . at ( " range " ) [ i ] = id ;
}
}
val = get_setting_item_string ( v . c_str ( ) , " default " ) ;
2022-05-03 03:56:07 +00:00
char * buf = NULL ;
int size = 0 ;
2022-11-10 02:02:52 +00:00
setting_jsn_ . at ( v . c_str ( ) ) . at ( " size " ) . get_to ( size ) ;
2022-05-03 03:56:07 +00:00
buf = ( char * ) malloc ( size + 4 ) ;
bzero ( buf , size + 4 ) ;
strcpy ( buf , val . c_str ( ) ) ;
2022-11-10 02:02:52 +00:00
set_setting ( v . c_str ( ) , buf , val . length ( ) ) ;
2022-05-03 03:56:07 +00:00
free ( buf ) ;
}
else if ( val = = " int " )
{
2022-11-10 02:02:52 +00:00
int n = 0 ;
setting_jsn_ . at ( v . c_str ( ) ) . at ( " default " ) . get_to ( n ) ;
set_setting ( v . c_str ( ) , ( char * ) & n , sizeof ( n ) ) ;
2022-05-03 03:56:07 +00:00
}
else if ( val = = " float " )
{
2022-11-10 02:02:52 +00:00
double d = .0f ;
setting_jsn_ . at ( v . c_str ( ) ) . at ( " default " ) . get_to ( d ) ;
set_setting ( v . c_str ( ) , ( char * ) & d , sizeof ( d ) ) ;
2022-05-03 03:56:07 +00:00
}
else if ( val = = " bool " )
{
2022-11-10 02:02:52 +00:00
bool b = false ;
setting_jsn_ . at ( v . c_str ( ) ) . at ( " default " ) . get_to ( b ) ;
set_setting ( v . c_str ( ) , ( char * ) & b , sizeof ( b ) ) ;
2022-05-03 03:56:07 +00:00
}
}
2022-11-10 02:02:52 +00:00
VLOG_MINI_1 ( LOG_LEVEL_ALL , " Initialize %d settings ... OK \n " , jsn_children_ . size ( ) - 1 ) ;
2022-05-03 03:56:07 +00:00
notify_setting_result_ = true ;
}
2022-08-13 01:29:00 +00:00
int hg_scanner : : init_settings ( int pid )
{
char rel_path [ 80 ] = { 0 } ;
std : : string root ( hg_log : : get_scanner_path ( ) ) , jsn ( " " ) ;
int ret = 0 ;
sprintf ( rel_path , " %ssettings%s%04x.hsc " , PATH_SEPARATOR , PATH_SEPARATOR , pid ) ;
root + = rel_path ;
ret = load_scanner_setting ( root . c_str ( ) , jsn ) ;
VLOG_MINI_2 ( LOG_LEVEL_WARNING , " Apply '%s' setting: %d \n " , root . c_str ( ) , ret ) ;
if ( ret )
return SCANNER_ERR_DATA_DAMAGED ;
init_settings ( jsn . c_str ( ) ) ;
return SCANNER_ERR_OK ;
}
2023-01-28 07:19:10 +00:00
void hg_scanner : : change_string_2_lang_id ( const char * name , const char * key )
{
std : : string val ( " " ) ;
int id = - 1 ;
if ( setting_jsn_ . at ( name ) . contains ( key ) )
{
setting_jsn_ . at ( name ) . at ( key ) . get_to ( val ) ;
id = lang_get_string_id ( val . c_str ( ) , true ) ;
if ( id = = - 1 )
{
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " LANGUAGE-ERR: lost item ID of '%s' \n " , val . c_str ( ) ) ;
}
else
setting_jsn_ . at ( name ) . at ( key ) = id ;
}
}
std : : string hg_scanner : : get_setting_item_string ( const char * name , const char * key )
{
std : : string ret ( " " ) ;
if ( setting_jsn_ . at ( name ) . at ( key ) . is_number ( ) )
{
int n = - 1 ;
setting_jsn_ . at ( name ) . at ( key ) . get_to ( n ) ;
ret = hg_log : : lang_load ( n ) ;
}
else
{
setting_jsn_ . at ( name ) . at ( key ) . get_to ( ret ) ;
}
return std : : move ( ret ) ;
}
2022-05-03 03:56:07 +00:00
int hg_scanner : : on_scann_error ( int err )
{
status_ = err ;
2022-05-30 03:04:26 +00:00
VLOG_MINI_1 ( LOG_LEVEL_FATAL , " [xxx]Device status: 0x%x \n " , err ) ;
2022-05-03 03:56:07 +00:00
unsigned int e = err ;
2022-05-30 03:42:16 +00:00
return ui_ev_cb_ ( ( scanner_handle ) this , SANE_EVENT_ERROR , ( void * ) hg_scanner_err_name ( err ) , & e , NULL ) ;
2022-05-03 03:56:07 +00:00
}
2022-05-20 09:11:50 +00:00
int hg_scanner : : try_third_app_handle_start ( bool & handled )
{
int ret = SCANNER_ERR_OK ;
handled = ! async_io_ ;
if ( handled )
{
2022-05-23 03:52:53 +00:00
while ( wait_usb_result_ . try_wait ( ) )
std : : this_thread : : sleep_for ( std : : chrono : : milliseconds ( 3 ) ) ;
2022-06-01 03:04:10 +00:00
if ( ! wait_img_ . is_waiting ( ) | | ! wait_usb_ . is_waiting ( ) | | final_imgs_ . size ( ) )
2022-06-06 10:29:09 +00:00
{
while ( final_imgs_ . size ( ) = = 0 )
{
if ( wait_img_ . is_waiting ( ) & & wait_usb_ . is_waiting ( ) )
break ;
std : : this_thread : : sleep_for ( std : : chrono : : milliseconds ( 3 ) ) ;
}
if ( final_imgs_ . size ( ) = = 0 )
{
final_img_index_ = 0 ;
if ( user_cancel_ )
handled = false ;
else
ret = SCANNER_ERR_DEVICE_NO_PAPER ;
}
}
2022-05-20 09:11:50 +00:00
else if ( final_img_index_ )
{
final_img_index_ = 0 ;
2022-06-01 04:00:00 +00:00
if ( user_cancel_ )
handled = false ;
else
ret = SCANNER_ERR_DEVICE_NO_PAPER ;
2022-05-20 09:11:50 +00:00
}
else
handled = false ;
}
return ret ;
}
2022-05-23 03:52:53 +00:00
int hg_scanner : : try_third_app_after_start ( int err )
{
if ( ! async_io_ )
{
2022-06-01 09:16:09 +00:00
while ( wait_img_ . is_waiting ( ) & & ! wait_usb_ . is_waiting ( ) )
std : : this_thread : : sleep_for ( std : : chrono : : milliseconds ( 10 ) ) ;
if ( wait_img_ . is_waiting ( ) & & wait_usb_ . is_waiting ( ) )
err = status_ ;
2022-05-23 03:52:53 +00:00
}
return err ;
}
2022-06-01 03:04:10 +00:00
std : : shared_ptr < tiny_buffer > hg_scanner : : aquire_memory ( int size , bool from_usb )
2022-05-23 06:10:18 +00:00
{
2022-06-01 03:04:10 +00:00
std : : string lead ( from_usb ? " usb " : " imgp " ) , ext ( from_usb ? " jpg " : " dat " ) ;
unsigned int ind = from_usb ? usb_img_index_ : final_img_index_ ;
std : : shared_ptr < tiny_buffer > mem ( new tiny_buffer ( size , final_path_ . c_str ( ) , lead . c_str ( ) , ext . c_str ( ) , ind ) ) ;
2022-05-23 06:10:18 +00:00
2022-06-06 04:03:24 +00:00
if ( ! mem - > data ( 0 , ( unsigned int * ) & size ) )
2022-05-23 06:10:18 +00:00
{
mem . reset ( ) ;
2022-06-01 03:04:10 +00:00
LOG_INFO ( LOG_LEVEL_FATAL , " Can't aquire enough memory, working must be stopped! \n " ) ;
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_SCANNER_ERR_INSUFFICIENT_MEMORY ) , SANE_EVENT_ERROR , SCANNER_ERR_INSUFFICIENT_MEMORY ) ;
2022-06-01 03:04:10 +00:00
stop ( ) ;
2022-05-23 06:10:18 +00:00
}
return mem ;
}
2022-05-03 03:56:07 +00:00
int hg_scanner : : notify_ui_working_status ( const char * msg , int ev , int status )
{
unsigned int s = status ;
return ui_ev_cb_ ( ( scanner_handle ) this , ev , ( void * ) msg , & s , NULL ) ;
}
bool hg_scanner : : waiting_for_memory_enough ( unsigned need_bytes )
{
return true ; // disable the memory control - added on 2022-03-22
bool ret = true ;
if ( cb_mem_ )
{
int ret = ui_ev_cb_ ( ( scanner_handle ) this , SANE_EVENT_IS_MEMORY_ENOUGH , NULL , & need_bytes , NULL ) ;
2022-05-17 07:04:55 +00:00
if ( ret = = SCANNER_ERR_INSUFFICIENT_MEMORY )
2022-05-03 03:56:07 +00:00
{
user_cancel_ = true ;
2022-05-17 07:04:55 +00:00
status_ = SCANNER_ERR_INSUFFICIENT_MEMORY ;
2022-05-03 03:56:07 +00:00
ret = false ;
}
2022-05-17 07:04:55 +00:00
else if ( ret = = SCANNER_ERR_NOT_ANY_MORE )
2022-05-03 03:56:07 +00:00
cb_mem_ = false ;
}
else
{
need_bytes * = 4 ;
void * buf = malloc ( need_bytes ) ;
bool first = true ;
while ( ! buf & & ! user_cancel_ )
{
if ( first )
{
2022-05-30 03:04:26 +00:00
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " Memory is too small for aquiring image(%u bytes), wait for ENOUGH ... \n " , need_bytes ) ;
2023-01-18 10:08:47 +00:00
notify_ui_working_status ( hg_log : : lang_load ( ID_STATU_DESC_WAIT_FOR_MEM ) ) ;
2022-05-03 03:56:07 +00:00
first = false ;
}
std : : this_thread : : sleep_for ( std : : chrono : : milliseconds ( 30 ) ) ;
buf = malloc ( need_bytes ) ;
}
if ( ! first )
{
if ( buf )
{
2022-05-30 03:04:26 +00:00
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " waited for memory need(%u) \n " , need_bytes ) ;
2022-05-03 03:56:07 +00:00
}
else
{
2022-05-30 03:04:26 +00:00
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " canceled by user while waiting for memory need(%u) \n " , need_bytes ) ;
2022-05-03 03:56:07 +00:00
}
}
ret = ( ! user_cancel_ ) & & ( buf ! = NULL ) ;
if ( buf )
free ( buf ) ;
}
return ret ;
}
2022-05-30 06:46:37 +00:00
void hg_scanner : : copy_to_sane_image_header ( SANE_Parameters * header , int w , int h , int line_bytes , int channels , int bits )
2022-05-03 03:56:07 +00:00
{
if ( channels = = 3 )
header - > format = SANE_FRAME_RGB ;
else
header - > format = SANE_FRAME_GRAY ;
2022-05-30 06:46:37 +00:00
header - > depth = bits > = 8 ? 8 : bits ; // 此处指每一个颜色分量的位深, 我们的扫描仪固定为“8”
header - > last_frame = SANE_TRUE ; // 一幅图片如果各个分量相互分离, 则最后一个分量的时候设置为true。彩色图像RGB时也只有一“帧”, 所以也为true
2022-05-03 03:56:07 +00:00
header - > pixels_per_line = w ;
header - > lines = h ;
header - > bytes_per_line = line_bytes ;
}
2022-06-01 03:04:10 +00:00
int hg_scanner : : save_usb_data ( std : : shared_ptr < tiny_buffer > data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ;
2022-10-11 06:41:49 +00:00
unsigned int bytes = data - > size ( ) ;
2022-05-03 03:56:07 +00:00
2022-05-10 00:27:31 +00:00
usb_img_index_ + + ;
2022-05-30 03:04:26 +00:00
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " USB read one picture with %u bytes \n " , data - > size ( ) ) ;
2022-10-11 06:41:49 +00:00
if ( dump_usb_path_ . length ( ) )
{
char name [ 80 ] = { 0 } ;
FILE * dst = nullptr ;
sprintf ( name , " %susb_img_%03u.jpg " , PATH_SEPARATOR , usb_img_index_ ) ;
if ( ( dst = fopen ( ( dump_usb_path_ + name ) . c_str ( ) , " wb " ) ) )
{
unsigned int off = 0 , len = bytes ;
unsigned char * buf = data - > data ( off , & len ) ;
while ( buf )
{
fwrite ( buf , 1 , len , dst ) ;
off + = len ;
if ( off > = bytes )
break ;
len = bytes - off ;
buf = data - > data ( off , & len ) ;
}
fclose ( dst ) ;
}
}
2022-06-01 03:04:10 +00:00
if ( ! data - > swap ( ) )
2022-05-03 03:56:07 +00:00
{
2022-06-01 03:04:10 +00:00
ret = SCANNER_ERR_OPEN_FILE_FAILED ;
2022-05-03 03:56:07 +00:00
}
else
{
2022-11-24 12:30:18 +00:00
int num = 0 ;
2022-11-25 06:19:15 +00:00
float Memoryusae = .0f ; // hg_log::GetAppMemoryUsage();;
size_t que_size = 0 ;
imgs_ . Size ( & que_size ) ;
Memoryusae = que_size / 1024.0f / 1024.0f ;
2022-11-26 02:00:40 +00:00
if ( async_io_ )
Memoryusae * = 10 ;
else
Memoryusae + = final_imgs_ . mem_usage ( ) / 1024.0f / 1024.0f ;
2022-11-25 06:19:15 +00:00
while ( Memoryusae > = memory_size_ & & ! user_cancel_ & & num < 20 ) //三个条件以防止卡死
2022-11-24 08:57:31 +00:00
{
std : : this_thread : : sleep_for ( std : : chrono : : milliseconds ( 500 ) ) ;
2022-11-25 06:19:15 +00:00
//Memoryusae = hg_log::GetAppMemoryUsage();
imgs_ . Size ( & que_size ) ;
Memoryusae = que_size / 1024.0f / 1024.0f ;
2022-11-26 02:00:40 +00:00
if ( async_io_ )
Memoryusae * = 10 ;
else
Memoryusae + = final_imgs_ . mem_usage ( ) / 1024.0f / 1024.0f ;
2022-11-25 06:19:15 +00:00
if ( num + + = = 0 )
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " Memory Usage is Too big:%f ,Please wait -_- ... \r \n " , Memoryusae ) ;
2022-11-24 08:57:31 +00:00
}
2022-11-25 06:19:15 +00:00
if ( num & & Memoryusae > = memory_size_ & & ! user_cancel_ )
{
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " Warning: memory usage(%.2fMB) maybe leading exception! \r \n " , Memoryusae ) ;
}
2023-01-28 07:19:10 +00:00
imgs_ . Put ( data , data - > size ( ) , hg_scanner_mgr : : unique_id ( ) ) ;
2022-06-01 03:04:10 +00:00
if ( wait_img_ . is_waiting ( ) )
wait_img_ . notify ( ) ;
2022-05-03 03:56:07 +00:00
}
2022-10-11 06:41:49 +00:00
2022-09-21 08:43:42 +00:00
if ( ( serial_ ! = G10039Serial & & serial_ ! = G20039Serial ) | | ( usb_img_index_ & 1 ) )
2022-07-21 09:54:58 +00:00
ui_ev_cb_ ( ( scanner_handle ) this , SANE_EVENT_USB_DATA_RECEIVED , NULL , & bytes , NULL ) ;
2022-05-03 03:56:07 +00:00
return ret ;
}
2023-01-28 07:19:10 +00:00
int hg_scanner : : save_final_image ( hg_imgproc : : LPIMGHEAD head , void * buf , uint32_t id )
2022-05-03 03:56:07 +00:00
{
2022-05-30 06:46:37 +00:00
std : : string bw ( " " ) ;
2022-05-03 03:56:07 +00:00
final_img_index_ + + ;
2022-06-02 03:47:44 +00:00
bool is_1bit = false ;
if ( image_prc_param_ . bits . multi_out = = MULTI_OUT_ALL & & is_multiout )
{
if ( final_img_index_ % 3 = = 0 )
is_1bit = true ;
}
else if ( ( image_prc_param_ . bits . multi_out = = MULTI_GRAY_AND_BW | | image_prc_param_ . bits . multi_out = = MULTI_COLOR_AND_BW ) & & is_multiout )
{
if ( final_img_index_ % 2 = = 0 )
is_1bit = true ;
}
2023-01-13 06:24:37 +00:00
if ( ( image_prc_param_ . bits . color_mode = = COLOR_MODE_BLACK_WHITE & & ! is_multiout ) | | ( is_1bit & & is_multiout ) )
2022-05-30 06:46:37 +00:00
{
int old = head - > line_bytes ;
2022-09-28 12:00:03 +00:00
/*/
2022-09-07 07:47:30 +00:00
bw = bmp_821 ( ( unsigned char * ) buf , head - > width , head - > height , & head - > line_bytes , async_io_ , bw_threshold_ , is_white_0_ ) ;
2022-09-28 12:00:03 +00:00
/*/
bw = hg_imgproc : : bmp8_2_1bit ( ( unsigned char * ) buf , head - > width , head - > height , head - > line_bytes , bw_threshold_ , is_white_0_ , async_io_ ) ;
head - > line_bytes = bw . length ( ) / head - > height ; ////////*//////////
2022-05-30 06:46:37 +00:00
buf = & bw [ 0 ] ;
head - > channels = head - > bits = 1 ;
head - > total_bytes = head - > line_bytes * head - > height ;
2022-06-28 09:16:03 +00:00
VLOG_MINI_5 ( LOG_LEVEL_DEBUG_INFO , " convert to 1-bit bmp(%d * %d), total = %u, len = %u , black_white_image_threshold_ =%d \n " , head - > width , head - > height , head - > total_bytes , bw . length ( ) , bw_threshold_ ) ;
2022-05-30 06:46:37 +00:00
}
2022-05-03 03:56:07 +00:00
if ( async_io_ )
{
SANE_Image img ;
2022-07-23 05:42:34 +00:00
ZERO_STRUCT ( & img ) ;
2022-05-30 06:46:37 +00:00
copy_to_sane_image_header ( & img . header , head - > width , head - > height , head - > line_bytes , head - > channels , head - > bits ) ;
2022-05-03 03:56:07 +00:00
img . data = ( unsigned char * ) buf ;
img . bytes = head - > total_bytes ;
2022-07-23 05:42:34 +00:00
img . flag . statu = head - > statu ;
2022-11-06 08:48:38 +00:00
img . flag . dpi = resolution_ ;
2023-01-28 07:19:10 +00:00
img . src_id = id ;
2022-07-23 05:42:34 +00:00
if ( img . flag . statu )
{
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " some error with final image: %s \n " , hg_scanner_image_statu_name ( img . flag . statu ) ) ;
}
2022-05-03 03:56:07 +00:00
return ui_ev_cb_ ( ( scanner_handle ) this , SANE_EVENT_IMAGE_OK , & img , & final_img_index_ , NULL ) ;
}
2022-06-01 03:04:10 +00:00
if ( final_imgs_ . put ( head - > width , head - > height , head - > bits , head - > channels , head - > line_bytes , buf , head - > total_bytes
2023-01-28 07:19:10 +00:00
, final_path_ . c_str ( ) , " final " , " dat " , final_img_index_ , id ) )
2022-05-30 09:36:42 +00:00
return SCANNER_ERR_OK ;
else
2022-06-01 03:04:10 +00:00
return SCANNER_ERR_INSUFFICIENT_MEMORY ;
2022-05-03 03:56:07 +00:00
}
2022-09-12 04:27:25 +00:00
void hg_scanner : : adjust_filling_hole ( LPSCANCONF conf )
{
int maxval = 0 ;
# define SET_FILL_HOLE(member, me) \
conf - > fillholeratio_ # # member = isremove_ # # me # # _hole ? isremove_ # # me # # _hole_threshold * 100 + .5f : 0 ; \
if ( conf - > fillholeratio_ # # member < 0 ) \
conf - > fillholeratio_ # # member = 0 ; \
else if ( conf - > fillholeratio_ # # member > 50 ) \
conf - > fillholeratio_ # # member = 50 ; \
if ( maxval < conf - > fillholeratio_ # # member ) \
maxval = conf - > fillholeratio_ # # member ;
SET_FILL_HOLE ( up , top ) ;
SET_FILL_HOLE ( down , low ) ;
SET_FILL_HOLE ( left , left ) ;
SET_FILL_HOLE ( right , right ) ;
2022-09-12 06:17:12 +00:00
2022-09-12 04:27:25 +00:00
if ( maxval )
{
conf - > fillhole . is_fillhole = true ;
conf - > fillhole . fillholeratio = maxval ;
}
}
2022-05-17 01:46:26 +00:00
int hg_scanner : : is_running ( void )
{
if ( ! scan_life_ )
return THREAD_RUNNING_IDLE ;
int run = THREAD_RUNNING_IDLE ;
if ( ! wait_usb_ . is_waiting ( ) )
run | = THREAD_RUNNING_USB ;
if ( ! wait_img_ . is_waiting ( ) )
run | = THREAD_RUNNING_IMAGE ;
return run ;
}
2022-05-03 03:56:07 +00:00
int hg_scanner : : reset_io ( usb_io * io )
{
online_ = false ;
if ( ! io )
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_INVALID_PARAMETER ;
2022-05-03 03:56:07 +00:00
{
std : : lock_guard < std : : mutex > lock ( io_lock_ ) ;
usb_io * old = io_ ;
io - > add_ref ( ) ;
io_ = io ;
status_ = io_ - > last_error ( ) ;
2022-05-17 07:04:55 +00:00
online_ = status_ = = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
if ( old )
old - > release ( ) ;
}
on_device_reconnected ( ) ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
int hg_scanner : : io_disconnected ( void )
{
std : : lock_guard < std : : mutex > lock ( io_lock_ ) ;
online_ = false ;
io_ - > on_disconnected ( ) ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
void hg_scanner : : set_ui_callback ( sane_callback cb , bool enable_async_io )
{
ui_ev_cb_ = cb ? cb : ui_default_callback ;
async_io_ = enable_async_io ;
2022-09-07 07:47:30 +00:00
is_white_0_ = ! async_io_ ;
2022-05-03 03:56:07 +00:00
}
2022-09-23 02:26:04 +00:00
void hg_scanner : : set_read_over_with_no_data ( bool no_data )
{
read_over_with_no_data_ = no_data ;
}
2022-05-03 03:56:07 +00:00
int hg_scanner : : get_pid ( void )
{
std : : lock_guard < std : : mutex > lock ( io_lock_ ) ;
return io_ - > get_pid ( ) ;
}
int hg_scanner : : get_vid ( void )
{
std : : lock_guard < std : : mutex > lock ( io_lock_ ) ;
return io_ - > get_vid ( ) ;
}
int hg_scanner : : close ( bool force )
{
int ret = on_scanner_closing ( force ) ;
online_ = false ;
2022-05-17 07:04:55 +00:00
if ( ret = = SCANNER_ERR_OK )
2022-05-03 03:56:07 +00:00
{
run_ = false ;
wait_usb_ . notify ( ) ;
wait_img_ . notify ( ) ;
2022-12-23 09:37:10 +00:00
wait_devsislock_ . notify ( ) ;
2022-05-03 03:56:07 +00:00
if ( ! scan_life_ )
{
std : : lock_guard < std : : mutex > lock ( io_lock_ ) ;
if ( io_ )
{
io_ - > close ( ) ;
io_ - > release ( ) ;
io_ = NULL ;
}
}
else if ( io_ )
{
2022-05-30 03:04:26 +00:00
LOG_INFO ( LOG_LEVEL_WARNING , " close scanner: USB thread or Image thread is still running. \n " ) ;
2022-05-03 03:56:07 +00:00
io_ - > close ( ) ;
2022-10-10 10:07:57 +00:00
while ( scan_life_ )
std : : this_thread : : sleep_for ( std : : chrono : : milliseconds ( 5 ) ) ;
2022-05-03 03:56:07 +00:00
io_ - > release ( ) ;
io_ = NULL ;
}
2022-05-17 07:04:55 +00:00
status_ = SCANNER_ERR_NOT_OPEN ;
2022-05-03 03:56:07 +00:00
}
return ret ;
}
2022-11-10 02:02:52 +00:00
int hg_scanner : : set_setting ( const char * name , void * data , int len )
2022-05-03 03:56:07 +00:00
{
2022-11-10 02:02:52 +00:00
int ret = SCANNER_ERR_OUT_OF_RANGE ;
bool hit = false ;
std : : string real_n ( setting_name_from ( name ) ) ;
if ( real_n . empty ( ) )
return ret ;
2022-05-03 03:56:07 +00:00
2022-11-10 02:02:52 +00:00
hit = setting_map_ . count ( real_n ) > 0 ;
2022-06-28 09:16:03 +00:00
if ( hit )
2022-05-03 03:56:07 +00:00
{
2022-11-10 02:02:52 +00:00
ret = ( this - > * setting_map_ [ real_n ] ) ( data ) ;
2022-05-03 03:56:07 +00:00
}
2022-06-28 09:16:03 +00:00
else
2022-05-03 03:56:07 +00:00
{
2022-11-10 02:02:52 +00:00
VLOG_MINI_1 ( LOG_LEVEL_WARNING , " Setting '%s' is not found in base setting functions. \n " , name ) ;
ret = set_setting_value ( real_n . c_str ( ) , data , len ) ;
2022-05-03 03:56:07 +00:00
}
2022-05-17 07:04:55 +00:00
if ( ret = = SCANNER_ERR_OK | | ret = = SCANNER_ERR_NOT_EXACT | | ret = = SCANNER_ERR_CONFIGURATION_CHANGED )
2022-05-03 03:56:07 +00:00
{
2023-01-28 07:19:10 +00:00
std : : string type ( " " ) , name ( get_setting_item_string ( real_n . c_str ( ) , " title " ) ) ;
2022-05-03 03:56:07 +00:00
2022-11-10 02:02:52 +00:00
setting_jsn_ . at ( real_n ) . at ( " type " ) . get_to ( type ) ;
2023-01-28 07:19:10 +00:00
// setting_jsn_.at(real_n).at("title").get_to(name);
2022-05-03 03:56:07 +00:00
if ( type = = " string " )
{
2023-01-29 07:01:38 +00:00
int id = lang_get_string_id ( ( char * ) data , false ) ;
if ( id = = - 1 )
setting_jsn_ . at ( real_n ) . at ( " cur " ) = ( char * ) data ;
else
setting_jsn_ . at ( real_n ) . at ( " cur " ) = id ;
2022-05-03 03:56:07 +00:00
type = ( char * ) data ;
}
else if ( type = = " int " )
{
2022-11-10 02:02:52 +00:00
char sn [ 20 ] = { 0 } ;
setting_jsn_ . at ( real_n ) . at ( " cur " ) = * ( ( int * ) data ) ;
2022-05-03 03:56:07 +00:00
sprintf ( sn , " %d " , * ( ( int * ) data ) ) ;
type = sn ;
}
else if ( type = = " float " )
{
2022-11-10 02:02:52 +00:00
char sn [ 20 ] = { 0 } ;
setting_jsn_ . at ( real_n ) . at ( " cur " ) = * ( ( double * ) data ) ;
2022-05-03 03:56:07 +00:00
sprintf ( sn , " %f " , * ( ( double * ) data ) ) ;
type = sn ;
}
else if ( type = = " bool " )
{
2022-11-10 02:02:52 +00:00
setting_jsn_ . at ( real_n ) . at ( " cur " ) = * ( ( bool * ) data ) ;
2022-05-03 03:56:07 +00:00
type = * ( ( bool * ) data ) ? " true " : " false " ;
}
2023-01-16 08:03:14 +00:00
/*if (notify_setting_result_)
2022-05-03 03:56:07 +00:00
{
2022-05-20 07:18:49 +00:00
name . insert ( 0 , " \350 \256 \276 \347 \275 \256 \" " ) ;
name + = " \" \345 \200 \274 \344 \270 \272 \" " ;
name + = type + " \" \346 \210 \220 \345 \212 \237 \343 \200 \202 " ;
2022-05-03 03:56:07 +00:00
notify_ui_working_status ( name . c_str ( ) ) ;
2023-01-16 08:03:14 +00:00
} */
2022-05-03 03:56:07 +00:00
}
else if ( notify_setting_result_ )
{
2023-01-16 08:03:14 +00:00
/*std::string n("");
2022-11-10 02:02:52 +00:00
if ( setting_jsn_ . contains ( real_n ) )
2022-05-03 03:56:07 +00:00
{
2022-11-10 02:02:52 +00:00
setting_jsn_ . at ( real_n ) . at ( " title " ) . get_to ( n ) ;
2022-05-03 03:56:07 +00:00
}
else
2022-11-10 02:02:52 +00:00
n = std : : string ( " \350 \256 \276 \347 \275 \256 \351 \241 \271 " ) + real_n ;
n . insert ( 0 , " \350 \256 \276 \347 \275 \256 \" " ) ;
n + = std : : string ( " \" \345 \200 \274 \345 \244 \261 \350 \264 \245 : " ) + hg_scanner_err_name ( ret ) ;
2023-01-16 08:03:14 +00:00
notify_ui_working_status ( n . c_str ( ) ) ; */
2022-05-03 03:56:07 +00:00
}
return ret ;
}
2023-01-10 06:21:39 +00:00
int hg_scanner : : get_setting ( const char * name , char * json_txt_buf , int * len , int * id )
2022-05-03 03:56:07 +00:00
{
if ( ! len )
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_INVALID_PARAMETER ;
2022-05-03 03:56:07 +00:00
2023-01-10 06:21:39 +00:00
std : : string real_n ( setting_name_from ( name , id ) ) ;
2022-11-10 02:02:52 +00:00
if ( name = = nullptr )
2022-05-03 03:56:07 +00:00
{
2022-11-10 02:02:52 +00:00
* len = setting_jsn_ . size ( ) ;
2022-05-03 03:56:07 +00:00
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
2022-11-10 02:02:52 +00:00
else if ( real_n . empty ( ) )
2022-07-23 10:01:44 +00:00
{
2022-11-10 02:02:52 +00:00
return SCANNER_ERR_OUT_OF_RANGE ;
2022-08-11 09:19:24 +00:00
}
2022-11-10 02:02:52 +00:00
else if ( ! setting_jsn_ . contains ( real_n ) )
2022-09-14 01:52:49 +00:00
{
2022-11-10 02:02:52 +00:00
VLOG_MINI_1 ( LOG_LEVEL_FATAL , " !!!option(%s) is not found. \n " , real_n . c_str ( ) ) ;
return SCANNER_ERR_OUT_OF_RANGE ;
2022-09-14 01:52:49 +00:00
}
2022-11-10 02:02:52 +00:00
else
2022-05-03 03:56:07 +00:00
{
2023-01-18 10:08:47 +00:00
//json_name.find(real_n)
2023-01-28 07:19:10 +00:00
//auto it = json_name.find(real_n);
//if (it != json_name.end())
//{
// int i = it->second;
//
// const char* load = hg_log::lang_load(i);
// if (*load)
// {
// setting_jsn_.at(real_n).at("title") = load;
// }
//
//}
2022-11-10 02:02:52 +00:00
std : : string text ( setting_jsn_ . at ( real_n ) . dump ( ) ) ;
2022-05-03 03:56:07 +00:00
2022-11-10 02:02:52 +00:00
text . insert ( 0 , " \" " + real_n + " \" : " ) ;
if ( * len < = text . length ( ) )
2022-05-06 05:37:14 +00:00
{
2022-11-10 02:02:52 +00:00
* len = text . length ( ) + 8 ;
return SCANNER_ERR_INSUFFICIENT_MEMORY ;
2022-05-06 05:37:14 +00:00
}
2022-11-10 02:02:52 +00:00
else
2022-05-06 05:37:14 +00:00
{
2022-11-10 02:02:52 +00:00
strcpy ( json_txt_buf , text . c_str ( ) ) ;
* len = text . length ( ) ;
return SCANNER_ERR_OK ;
2022-05-06 05:37:14 +00:00
}
}
2022-05-03 03:56:07 +00:00
}
std : : string hg_scanner : : name ( void )
{
return name_ ;
}
int hg_scanner : : status ( void )
{
2022-06-01 09:16:09 +00:00
if ( ! wait_usb_ . is_waiting ( ) | | ! wait_img_ . is_waiting ( ) )
return SCANNER_ERR_DEVICE_BUSY ;
else
return status_ ;
2022-05-03 03:56:07 +00:00
}
bool hg_scanner : : is_online ( void )
{
return online_ ;
}
2023-01-29 07:01:38 +00:00
void hg_scanner : : on_language_changed ( void )
{
// change the 'size' member of string settings ...
for ( size_t i = 1 ; i < jsn_children_ . size ( ) ; + + i )
{
std : : string v ( jsn_children_ [ i ] ) ;
if ( ! setting_jsn_ . contains ( v . c_str ( ) ) )
continue ;
std : : string val ( " " ) ;
setting_jsn_ . at ( v . c_str ( ) ) . at ( " type " ) . get_to ( val ) ;
if ( val ! = " string " )
continue ;
if ( setting_jsn_ . at ( v . c_str ( ) ) . contains ( " range " ) )
{
int old = 0 , now = 0 ;
setting_jsn_ . at ( v . c_str ( ) ) . at ( " size " ) . get_to ( old ) ;
for ( int i = 0 ; i < setting_jsn_ . at ( v . c_str ( ) ) . at ( " range " ) . size ( ) ; + + i )
{
int id = - 1 ;
if ( setting_jsn_ . at ( v . c_str ( ) ) . at ( " range " ) . at ( i ) . is_number ( ) )
{
setting_jsn_ . at ( v . c_str ( ) ) . at ( " range " ) . at ( i ) . get_to ( id ) ;
val = hg_log : : lang_load ( id ) ;
}
else
setting_jsn_ . at ( v . c_str ( ) ) . at ( " range " ) . at ( i ) . get_to ( val ) ;
if ( now < val . length ( ) )
now = val . length ( ) ;
}
now + = 8 ;
if ( now > old )
{
setting_jsn_ . at ( v . c_str ( ) ) . at ( " size " ) = now ;
VLOG_MINI_3 ( LOG_LEVEL_DEBUG_INFO , " Change size of '%s' from %d to %d \n " , v . c_str ( ) , old , now ) ;
}
}
}
}
2022-05-03 03:56:07 +00:00
int hg_scanner : : start ( void )
{
user_cancel_ = false ;
return status_ ;
}
int hg_scanner : : get_image_info ( SANE_Parameters * ii )
{
2022-05-17 07:04:55 +00:00
int ret = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
IMH imh ;
2023-01-28 07:19:10 +00:00
fetching_id_ = - 1 ;
2022-05-03 03:56:07 +00:00
bzero ( & imh , sizeof ( imh ) ) ;
2022-05-20 06:46:25 +00:00
bzero ( ii , sizeof ( * ii ) ) ;
2022-06-01 03:04:10 +00:00
while ( ( ! wait_img_ . is_waiting ( ) | | ! wait_usb_ . is_waiting ( ) ) & & final_imgs_ . size ( ) < = 0 )
2022-05-03 03:56:07 +00:00
this_thread : : sleep_for ( chrono : : milliseconds ( 10 ) ) ;
2022-06-01 03:04:10 +00:00
if ( final_imgs_ . size ( ) < = 0 )
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NO_DATA ;
2022-05-03 03:56:07 +00:00
else
{
if ( ! final_imgs_ . front ( & imh ) )
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_NO_DATA ;
2022-05-03 03:56:07 +00:00
else
2023-01-28 07:19:10 +00:00
{
2022-05-30 06:46:37 +00:00
copy_to_sane_image_header ( ii , imh . width , imh . height , imh . line_bytes , imh . channels , imh . bits ) ;
2023-01-28 07:19:10 +00:00
fetching_id_ = imh . src_id ;
}
2022-05-03 03:56:07 +00:00
}
2022-05-20 06:46:25 +00:00
2022-05-20 09:11:50 +00:00
if ( ret = = SCANNER_ERR_NO_DATA /*&& final_img_index_ == 0*/ )
2022-05-20 06:46:25 +00:00
{
2022-08-01 08:41:58 +00:00
//if (status_ != SCANNER_ERR_OK && status_ != SCANNER_ERR_DEVICE_BUSY)
// ret = SCANNER_ERR_NO_DATA;
//else
2022-05-20 06:46:25 +00:00
{
2022-05-30 06:46:37 +00:00
ii - > depth = image_prc_param_ . bits . color_mode = = COLOR_MODE_BLACK_WHITE ? 1 : 8 ;
2022-05-20 06:46:25 +00:00
ii - > last_frame = SANE_TRUE ;
ii - > format = image_prc_param_ . bits . color_mode = = COLOR_MODE_24_BITS | | image_prc_param_ . bits . color_mode = = COLOR_MODE_AUTO_MATCH ?
SANE_FRAME_RGB : SANE_FRAME_GRAY ;
SIZE paper = paper_size ( image_prc_param_ . bits . paper ) ;
ii - > pixels_per_line = paper . cx * 1.0f / 25.4 * resolution_ + .5f ;
ii - > lines = paper . cy * 1.0f / 25.4 * resolution_ + .5f ;
ii - > bytes_per_line = ii - > format = = SANE_FRAME_RGB ? ii - > pixels_per_line * 3 : ii - > pixels_per_line ;
if ( ii - > bytes_per_line > ii - > pixels_per_line )
imh . bits = 24 ;
else
imh . bits = 8 ;
ret = SCANNER_ERR_OK ;
}
}
2022-05-30 03:42:16 +00:00
VLOG_MINI_4 ( LOG_LEVEL_DEBUG_INFO , " Get image info(%d * %d * %d) = %s \n " , ii - > pixels_per_line , ii - > lines , imh . bits , hg_scanner_err_name ( ret ) ) ;
2022-05-03 03:56:07 +00:00
return ret ;
}
int hg_scanner : : read_image_data ( unsigned char * buf , int * len )
{
if ( ! len )
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_INVALID_PARAMETER ;
2022-05-03 03:56:07 +00:00
if ( ! buf )
{
IMH imh ;
final_imgs_ . front ( & imh ) ;
* len = imh . bytes ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_INSUFFICIENT_MEMORY ;
2022-05-03 03:56:07 +00:00
}
2022-06-01 03:04:10 +00:00
if ( final_imgs_ . size ( ) > 0 )
2022-05-03 03:56:07 +00:00
{
int fetch = * len ;
bool over = false ;
final_imgs_ . fetch_front ( buf , len , & over ) ;
2022-09-23 02:26:04 +00:00
if ( over )
{
if ( read_over_with_no_data_ )
return SCANNER_ERR_NO_DATA ;
}
2022-05-03 03:56:07 +00:00
2022-09-23 02:26:04 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
else
2022-06-18 00:55:15 +00:00
{
* len = 0 ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_NO_DATA ;
2022-06-18 00:55:15 +00:00
}
2022-05-03 03:56:07 +00:00
}
int hg_scanner : : stop ( void )
{
user_cancel_ = true ;
return status_ ;
}
int hg_scanner : : reset ( void )
{
return status_ ;
}
int hg_scanner : : device_io_control ( unsigned long code , void * data , unsigned * len )
{
2023-01-04 07:34:54 +00:00
//SANE_Bool devs_status = false;
//int ret = get_scan_is_sleep(devs_status);
//if (ret == SCANNER_ERR_OK)
//{
// if (!devs_status)
// {
// if (pid_ == 0x239 || pid_ == 0x402)
// {
// set_notify_sleep();
// }
// return SCANNER_ERR_DEVICE_SLEEPING;
// }
//}
2022-05-03 03:56:07 +00:00
if ( code = = IO_CTRL_CODE_RESTORE_SETTINGS )
{
2022-06-28 09:16:03 +00:00
int ret = invoke_setting_xxx ( & hg_scanner : : setting_restore , data ) ;
2022-05-03 03:56:07 +00:00
2022-06-28 09:16:03 +00:00
if ( ret = = SCANNER_ERR_OK )
ret = SCANNER_ERR_CONFIGURATION_CHANGED ;
return ret ;
2022-05-03 03:56:07 +00:00
}
else if ( code = = IO_CTRL_CODE_GET_DEFAULT_VALUE )
{
2022-11-10 02:02:52 +00:00
if ( * len = = 0 )
2022-05-03 03:56:07 +00:00
{
2022-11-10 02:02:52 +00:00
* len = setting_jsn_ . size ( ) ;
return SCANNER_ERR_OK ;
}
else if ( * len > setting_jsn_ . size ( ) )
{
return SCANNER_ERR_OUT_OF_RANGE ;
}
2022-11-11 09:59:08 +00:00
else if ( * len < jsn_children_ . size ( ) )
2022-11-10 02:02:52 +00:00
{
2022-11-11 09:59:08 +00:00
if ( get_default_value ( data , & setting_jsn_ . at ( jsn_children_ [ * len ] ) ) )
2022-11-10 02:02:52 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
else
2022-11-10 02:02:52 +00:00
return SCANNER_ERR_DATA_DAMAGED ;
}
else
{
return SCANNER_ERR_DATA_DAMAGED ;
2022-05-03 03:56:07 +00:00
}
}
2022-12-08 10:11:04 +00:00
else if ( code = = IO_CTRL_CODE_SET_CLEAR_ROLLER_COUNT )
2022-05-03 03:56:07 +00:00
{
2022-11-11 09:59:08 +00:00
int val = 0 , ret = get_roller_num ( val ) ;
2022-05-03 03:56:07 +00:00
if ( len )
2022-11-11 09:59:08 +00:00
* len = val ;
2022-05-03 03:56:07 +00:00
2022-12-22 10:37:53 +00:00
return set_clear_roller_num ( ) ;
2022-05-03 03:56:07 +00:00
}
2022-06-15 03:05:36 +00:00
else if ( code = = IO_CTRL_CODE_GET_FINAL_IMAGE_FORMAT )
{
SANE_FinalImgFormat * fmt = ( SANE_FinalImgFormat * ) data ;
if ( ! fmt )
{
* len = sizeof ( SANE_FinalImgFormat ) ;
return SCANNER_ERR_INSUFFICIENT_MEMORY ;
}
if ( img_type_ = = " .bmp " )
fmt - > img_format = SANE_IMAGE_TYPE_BMP ;
else if ( img_type_ = = " .jpg " )
fmt - > img_format = SANE_IMAGE_TYPE_JPG ;
else if ( img_type_ = = " .png " )
fmt - > img_format = SANE_IMAGE_TYPE_PNG ;
else if ( img_type_ = = " .gif " )
fmt - > img_format = SANE_IMAGE_TYPE_GIF ;
else
fmt - > img_format = SANE_IMAGE_TYPE_BMP ;
return SCANNER_ERR_OK ;
}
2022-05-03 03:56:07 +00:00
else if ( code = = IO_CTRL_CODE_SET_FINAL_IMAGE_FORMAT )
{
SANE_FinalImgFormat * fmt = ( SANE_FinalImgFormat * ) data ;
return set_final_image_format ( fmt ) ;
}
2022-06-15 03:05:36 +00:00
else if ( code = = IO_CTRL_CODE_GET_FINAL_COMPRESSION )
{
* ( int * ) data = SANE_COMPRESSION_NONE ;
return SCANNER_ERR_OK ;
}
else if ( code = = IO_CTRL_CODE_SET_FINAL_COMPRESSION )
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
}
2022-05-03 03:56:07 +00:00
else if ( code = = IO_CTRL_CODE_TEST_SINGLE )
{
return set_leaflet_scan ( ) ;
}
else if ( code = = IO_CTRL_CODE_SET_AUTO_COLOR_TYPE )
{
return set_auto_color_type ( ) ;
}
else if ( code = = IO_CTRL_CODE_GET_HARDWARE_VERSION )
{
std : : string fw = get_firmware_version ( ) ;
2022-08-19 06:22:39 +00:00
if ( * len < fw . size ( ) + 1 )
2022-05-03 03:56:07 +00:00
{
2022-08-19 06:22:39 +00:00
* len = fw . size ( ) + 1 ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_INSUFFICIENT_MEMORY ;
2022-05-03 03:56:07 +00:00
}
2022-08-19 06:22:39 +00:00
if ( data & & fw . length ( ) )
2022-06-18 08:47:21 +00:00
strcpy ( ( char * ) data , fw . c_str ( ) ) ;
2022-05-03 03:56:07 +00:00
2022-06-18 08:47:21 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
else if ( code = = IO_CTRL_CODE_GET_SERIAL )
{
std : : string ser = get_serial_num ( ) ;
2022-08-19 06:22:39 +00:00
if ( * len < ser . size ( ) + 1 )
2022-05-03 03:56:07 +00:00
{
2022-08-19 06:22:39 +00:00
* len = ser . size ( ) + 1 ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_INSUFFICIENT_MEMORY ;
2022-05-03 03:56:07 +00:00
}
2022-08-19 06:22:39 +00:00
if ( data & & ser . length ( ) )
2022-06-18 08:47:21 +00:00
strcpy ( ( char * ) data , ser . c_str ( ) ) ;
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
2023-01-03 03:12:26 +00:00
else if ( code = = IO_CTRL_CODE_GET_IP )
2022-05-03 03:56:07 +00:00
{
std : : string ip = get_ip ( ) ;
2022-08-19 06:22:39 +00:00
if ( * len < ip . size ( ) + 1 )
2022-05-03 03:56:07 +00:00
{
2022-08-19 06:22:39 +00:00
* len = ip . size ( ) + 1 ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_INSUFFICIENT_MEMORY ;
2022-05-03 03:56:07 +00:00
}
2022-08-19 06:22:39 +00:00
if ( data & & ip . length ( ) )
2022-06-18 08:47:21 +00:00
strcpy ( ( char * ) data , ip . c_str ( ) ) ;
2022-05-03 03:56:07 +00:00
2022-06-18 08:47:21 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
else if ( code = = IO_CTRL_CODE_GET_PAPER_ON )
{
2022-12-22 10:37:53 +00:00
return get_scanner_paperon ( * ( SANE_Bool * ) data ) ;
2022-05-03 03:56:07 +00:00
}
else if ( code = = IO_CTRL_CODE_GET_POWER_LEVEL )
{
int val = 0 ,
2022-05-17 07:04:55 +00:00
ret = SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
if ( * len < sizeof ( int * ) )
{
* len = sizeof ( int * ) ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_INSUFFICIENT_MEMORY ;
2022-05-03 03:56:07 +00:00
}
ret = get_sleep_time ( val ) ;
2022-05-17 07:04:55 +00:00
if ( ret = = SCANNER_ERR_OK )
2022-05-03 03:56:07 +00:00
{
* ( ( int * ) data ) = val ;
}
return ret ;
}
else if ( code = = IO_CTRL_CODE_SET_POWER_LEVEL )
{
int val = * ( ( int * ) data ) ;
int sleeptime = 0 ;
switch ( val )
{
2022-12-29 10:05:59 +00:00
case SLEEP_TIME_0MIN :
if ( pid_ = = 0x300 | | pid_ = = 0x400 )
2023-01-03 03:12:26 +00:00
val = INT_MAX ; //3288不休眠
2022-12-29 10:05:59 +00:00
else
val = - 1 ; //不休眠 -1 3399
2022-05-03 03:56:07 +00:00
break ;
2022-12-29 10:05:59 +00:00
case SLEEP_TIME_5MIN :
val = 5 ;
2022-05-03 03:56:07 +00:00
break ;
2022-12-29 10:05:59 +00:00
case SLEEP_TIME_10MIN :
val = 10 ;
2022-05-03 03:56:07 +00:00
break ;
2022-12-29 10:05:59 +00:00
case SLEEP_TIME_30MIN :
val = 30 ;
2022-05-03 03:56:07 +00:00
break ;
2022-12-29 10:05:59 +00:00
case SLEEP_TIME_60MIN :
val = 60 ;
2022-05-03 03:56:07 +00:00
break ;
2022-12-29 10:05:59 +00:00
case SLEEP_TIME_120MIN :
val = 120 ;
2022-05-03 03:56:07 +00:00
break ;
2022-12-29 10:05:59 +00:00
case SLEEP_TIME_240MIN :
val = 240 ;
2022-05-03 03:56:07 +00:00
break ;
2022-10-13 07:11:58 +00:00
case SANE_POWER_SHUTDOWN :
2022-12-28 01:56:54 +00:00
return set_devshtudown ( ) ;
2022-10-13 07:11:58 +00:00
case SANE_POWER_RESTART :
2022-12-28 01:56:54 +00:00
return set_devreboot ( val ) ;
2022-05-03 03:56:07 +00:00
default :
2022-12-29 10:05:59 +00:00
val = - 1 ;
2022-05-03 03:56:07 +00:00
break ;
}
2022-12-29 10:05:59 +00:00
sleeptime = val ;
2023-01-03 03:12:26 +00:00
if ( val ! = - 1 & & val ! = INT_MAX )
2022-12-29 10:05:59 +00:00
{
sleeptime = val * 60 ;
}
2022-05-03 03:56:07 +00:00
return set_sleep_time ( sleeptime ) ;
}
2022-05-06 05:37:14 +00:00
else if ( code = = IO_CTRL_CODE_GET_CUSTOM_GAMMA )
{
2022-05-06 06:37:52 +00:00
SANE_Gamma * v = ( SANE_Gamma * ) data ;
2022-05-06 08:39:00 +00:00
memcpy ( v , custom_gamma_val_ , sizeof ( * custom_gamma_val_ ) ) ;
2022-07-05 09:54:59 +00:00
if ( len )
* len = image_prc_param_ . bits . color_mode ;
2022-05-06 05:37:14 +00:00
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-06 05:37:14 +00:00
}
2022-05-06 06:37:52 +00:00
else if ( code = = IO_CTRL_CODE_SET_CUSTOM_GAMMA )
2022-05-06 05:37:14 +00:00
{
2022-05-06 06:37:52 +00:00
SANE_Gamma * v = ( SANE_Gamma * ) data ;
2022-05-06 08:39:00 +00:00
memcpy ( custom_gamma_val_ , v , sizeof ( * custom_gamma_val_ ) ) ;
2022-05-06 05:37:14 +00:00
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-06 05:37:14 +00:00
}
2022-05-19 10:15:14 +00:00
else if ( code = = IO_CTRL_CODE_DISPLAY_APP_HELP )
{
2022-05-21 01:35:08 +00:00
//setting_help(data);
2022-05-19 10:15:14 +00:00
return SCANNER_ERR_OK ;
}
2022-06-15 03:05:36 +00:00
else if ( code = = IO_CTRL_CODE_GET_IMAGE_QUEUE_COUNT )
{
* len = final_imgs_ . size ( ) ;
return wait_img_ . is_waiting ( ) & & wait_usb_ . is_waiting ( ) ? SCANNER_ERR_NO_DATA : SCANNER_ERR_OK ;
}
2022-06-24 09:06:43 +00:00
else if ( code = = IO_CTRL_CODE_GET_PAPER_SIZE )
{
std : : string name ( ( char * ) data ) ;
int paper = match_best_paper ( name , NULL ) ;
SIZE size = paper_size ( paper ) ;
* len = ( size . cx & 0x0ffff ) | ( ( size . cy & 0x0ffff ) < < 16 ) ;
2022-11-04 04:10:13 +00:00
return SCANNER_ERR_OK ;
2022-06-24 09:06:43 +00:00
}
2022-06-28 09:16:03 +00:00
else if ( code = = IO_CTRL_CODE_CONVERT_IMAGE_FORMAT )
{
SANE_ImageFormatConvert * conv = ( SANE_ImageFormatConvert * ) data ;
void * threshold = conv - > dst . fmt . compress . detail ;
int ret = SCANNER_ERR_OK ;
conv - > dst . fmt . compress . detail = ( void * ) bw_threshold_ ;
ret = hg_imgproc : : convert_image_file ( conv ) ;
conv - > dst . fmt . compress . detail = threshold ;
return ret ;
}
else if ( code = = IO_CTRL_CODE_FREE_MEMORY )
{
free_memory ( data ) ;
return SCANNER_ERR_OK ;
}
2022-07-23 11:46:24 +00:00
else if ( code = = IO_CTRL_CODE_GET_LOG_FILE & & len & & * len = = LOG_FILE_DEVICE )
2022-07-23 10:01:44 +00:00
{
2022-07-26 07:14:29 +00:00
string str ;
int ret = get_device_log ( str ) ;
2022-07-26 07:34:13 +00:00
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " str = %d \n " , str . length ( ) ) ;
2022-07-23 10:01:44 +00:00
2022-07-23 11:46:24 +00:00
* ( char * ) data = 0 ;
2022-07-23 10:01:44 +00:00
if ( ret ! = SCANNER_ERR_OK )
{
return ret ;
2022-07-23 11:46:24 +00:00
}
2022-07-26 07:14:29 +00:00
strcpy ( ( char * ) data , str . c_str ( ) ) ;
return 0 ;
2022-07-23 10:01:44 +00:00
}
2022-10-28 03:01:01 +00:00
else if ( code = = IO_CTRL_CODE_SET_SCAN_LOCK_CHECK_VAL )
{
string str = ( char * ) data ;
2022-11-04 04:10:13 +00:00
return set_scan_lock_check_val ( str ) ;
2022-10-28 03:01:01 +00:00
}
else if ( code = = IO_CTRL_CODE_SET_SCAN_LOCK )
{
SANE_Bool set_islock = * ( ( SANE_Bool * ) data ) ;
2022-12-13 10:13:46 +00:00
//set_scan_islock(set_islock);
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-10-28 03:01:01 +00:00
}
else if ( code = = IO_CTRL_CODE_GET_SCAN_ISLOCK )
{
2022-11-25 08:20:20 +00:00
2022-10-28 03:01:01 +00:00
SANE_Bool islock = * ( ( SANE_Bool * ) data ) ;
2022-11-25 08:20:20 +00:00
int ret = get_scan_islock ( islock ) ;
2022-10-28 03:01:01 +00:00
* ( ( SANE_Bool * ) data ) = islock ;
2022-11-25 08:20:20 +00:00
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " io ctrl islock:%d \r \n " , * ( ( SANE_Bool * ) data ) ) ;
2022-11-04 04:10:13 +00:00
return ret ;
2022-10-28 03:01:01 +00:00
}
2022-11-03 10:09:32 +00:00
else if ( code = = IO_CTRL_CODE_SET_FIRMWARE_UPGRADE )
{
string str = ( char * ) data ;
2022-12-22 10:37:53 +00:00
return set_firmware_upgrade ( str ) ;
2022-11-03 10:09:32 +00:00
}
2022-12-29 10:05:59 +00:00
else if ( code = = IO_CTRL_CODE_GET_HISTORY_SCAN_NUM )
2022-11-11 03:40:05 +00:00
{
int num = 0 ;
2022-12-29 10:05:59 +00:00
int ret = get_history_scan_count ( num ) ;
2022-11-11 03:40:05 +00:00
( * ( int * ) data ) = num ;
return ret ;
}
else if ( code = = IO_CTRL_CODE_GET_CLEAN_PAPER_ROAD )
{
2022-12-22 10:37:53 +00:00
return set_clean_paper_road ( ) ;
2022-11-11 03:40:05 +00:00
}
2022-12-29 10:05:59 +00:00
else if ( code = = IO_CTRL_CODE_GET_ROLLER_NUM )
2022-11-11 10:14:00 +00:00
{
int num = 0 ;
int ret = get_roller_num ( num ) ;
( * ( int * ) data ) = num ;
return ret ;
}
2022-12-09 01:47:42 +00:00
else if ( code = = IO_CTRL_CODE_SET_FEEDMODE )
{
return on_set_feedmode ( * ( ( int * ) data ) ) ;
}
else if ( code = = IO_CTRL_CODE_SET_SKEW_CHECK )
{
2022-12-23 08:51:10 +00:00
return on_skew_check_changed ( * ( ( bool * ) data ) ) ;
2022-12-09 01:47:42 +00:00
}
else if ( code = = IO_CTRL_CODE_SET_SKEW_CHECK_VAL )
{
2022-12-23 08:51:10 +00:00
return on_skew_check_level_changed ( * ( ( int * ) data ) ) ;
}
else if ( code = = IO_CTRL_CODE_GET_IS_MODE )
{
return get_scan_mode ( * ( ( bool * ) data ) ) ;
2022-12-09 01:47:42 +00:00
}
2022-12-28 01:56:54 +00:00
else if ( code = = IO_CTRL_CODE_SET_ULTRASONIC_MODULE )
{
return on_ultrasonic_check_changed ( * ( ( bool * ) data ) ) ;
}
else if ( code = = IO_CTRL_CODE_SET_SPEED_MODE )
{
return set_speed_mode ( * ( ( int * ) data ) ) ;
}
2022-12-29 10:05:59 +00:00
else if ( code = = IO_CTRL_CODE_GET_SPEED_MODE )
{
return get_speed_mode ( * ( ( int * ) data ) ) ;
}
2022-12-28 01:56:54 +00:00
else if ( code = = IO_CTRL_CODE_SET_CIS_IMAGE )
{
return on_cis_get_image ( * ( ( bool * ) data ) ) ;
}
else if ( code = = IO_CTRL_CODE_GET_IMAGE )
{
return start ( ) ; ;
}
2023-01-05 10:18:38 +00:00
else if ( code = = IO_CTRL_CODE_SET_DISTORTION_IMAGE )
2022-12-28 01:56:54 +00:00
{
2023-01-05 10:18:38 +00:00
return set_distortion_image ( * ( ( bool * ) data ) ) ;
}
else if ( code = = IO_CTRL_CODE_GET_DISTORTION_CHECK_VAL )
{
2023-01-09 08:03:12 +00:00
if ( distortion_val . h > 0 )
{
* ( SANE_DISTORTION_VAL * ) data = distortion_val ;
}
return SCANNER_ERR_OK ;
//return get_distortion_check_val(*((int*)data));
2023-01-05 10:18:38 +00:00
}
else if ( code = = IO_CTRL_CODE_SET_DISTORTION_CHECK_VAL )
{
return set_distortion_check_val ( * ( ( int * ) data ) ) ;
}
else if ( code = = IO_CTRL_CODE_GET_DISTORTION_DEVS_CHECK_VAL )
{
return get_devs_distortion_check_val ( * ( ( int * ) data ) ) ;
2022-12-28 01:56:54 +00:00
}
2022-12-29 10:05:59 +00:00
else if ( code = = IO_CTRL_CODE_SET_DEVS_REBOOT )
{
return set_devreboot ( * ( ( int * ) data ) ) ;
}
2022-12-29 16:05:43 +00:00
else if ( code = = IO_CTRL_CODE_SET_AUTO_FALT )
{
2022-12-30 10:16:40 +00:00
is_auto_falt = true ;
2022-12-29 16:05:43 +00:00
return set_auto_flat ( ) ;
}
2022-12-31 09:01:26 +00:00
else if ( code = = IO_CTRL_CODE_SET_COLOR )
{
return setting_color_mode ( data ) ;
}
else if ( code = = IO_CTRL_CODE_SET_DPI )
{
return setting_resolution ( data ) ;
}
2023-01-03 03:12:26 +00:00
else if ( code = = IO_CTRL_CODE_SET_VIDPID )
{
2023-01-04 09:27:02 +00:00
int num = * ( ( int * ) data ) ;
return set_vid_pid ( num ) ;
2023-01-03 03:12:26 +00:00
}
else if ( code = = IO_CTRL_CODE_SET_SERIAL )
{
2023-01-05 10:18:38 +00:00
string str = ( char * ) data ;
2023-01-03 03:12:26 +00:00
return set_serial_num ( ( char * ) data ) ;
}
else if ( code = = IO_CTRL_CODE_GET_VIDPID )
{
2023-01-04 07:34:54 +00:00
int num = 0 ;
int ret = get_vid_pid ( num ) ;
( * ( int * ) data ) = num ;
return ret ;
2023-01-03 03:12:26 +00:00
}
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
std : : string hg_scanner : : get_firmware_version ( void )
{
2022-05-11 01:36:23 +00:00
return BRAND_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
std : : string hg_scanner : : get_serial_num ( void )
{
2022-05-11 01:36:23 +00:00
return BRAND_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
std : : string hg_scanner : : get_ip ( void )
{
2022-05-11 01:36:23 +00:00
return BRAND_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
2022-11-11 09:59:08 +00:00
int hg_scanner : : get_roller_num ( int & val )
2022-05-03 03:56:07 +00:00
{
2022-11-11 09:59:08 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
2022-07-23 10:01:44 +00:00
int hg_scanner : : get_device_log ( string & log )
{
2022-07-23 11:46:24 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-07-23 10:01:44 +00:00
}
2022-12-28 01:56:54 +00:00
int hg_scanner : : set_devreboot ( int data )
2022-10-13 07:11:58 +00:00
{
2022-11-11 09:59:08 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-10-13 07:11:58 +00:00
}
int hg_scanner : : set_devshtudown ( )
{
2022-11-11 09:59:08 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-10-13 07:11:58 +00:00
}
2022-12-22 10:37:53 +00:00
int hg_scanner : : set_clear_roller_num ( void )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
2022-12-29 10:05:59 +00:00
int hg_scanner : : get_history_scan_count ( int & num )
2022-05-13 08:39:21 +00:00
{
2022-11-11 09:59:08 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-13 08:39:21 +00:00
}
2022-10-28 03:01:01 +00:00
int hg_scanner : : set_scan_islock ( SANE_Bool set_islock )
{
2022-11-11 09:59:08 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-10-28 03:01:01 +00:00
}
2022-11-25 08:20:20 +00:00
int hg_scanner : : get_scan_islock ( SANE_Bool & islock )
2022-10-28 03:01:01 +00:00
{
2022-11-11 09:59:08 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-10-28 03:01:01 +00:00
}
int hg_scanner : : set_scan_lock_check_val ( string check_str )
{
2022-11-11 09:59:08 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-10-28 03:01:01 +00:00
}
2022-12-22 10:37:53 +00:00
int hg_scanner : : set_firmware_upgrade ( std : : string filename )
2022-11-03 10:09:32 +00:00
{
2022-11-11 09:59:08 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-11-03 10:09:32 +00:00
}
2022-12-22 10:37:53 +00:00
int hg_scanner : : set_clean_paper_road ( )
2022-11-11 03:40:05 +00:00
{
2022-11-11 09:59:08 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-11-11 03:40:05 +00:00
}
2022-12-12 10:18:53 +00:00
int hg_scanner : : get_dev_islock_file ( int & islockfile )
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
}
int hg_scanner : : set_dev_islock_file ( int islockfile )
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
}
2022-12-22 10:37:53 +00:00
int hg_scanner : : get_scan_mode ( bool & type )
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
}
2022-12-28 01:56:54 +00:00
int hg_scanner : : set_speed_mode ( int data )
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
}
2022-12-29 10:05:59 +00:00
int hg_scanner : : get_speed_mode ( int & data )
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
}
2023-01-05 10:18:38 +00:00
int hg_scanner : : set_distortion_image ( bool type )
2022-12-28 01:56:54 +00:00
{
is_dpi_color_check = type ;
int ret = SCANNER_ERR_OK ;
if ( type )
{
ret = set_leaflet_scan ( ) ;
}
return ret ;
}
2023-01-05 10:18:38 +00:00
int hg_scanner : : get_distortion_check_val ( int & val )
{
val = * ( int * ) & save_dpi_color_check_val ;
//val = ;
if ( val ! = 0 )
{
return SCANNER_ERR_NO_DATA ;
}
return 0 ;
}
int hg_scanner : : set_distortion_check_val ( int data )
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
}
int hg_scanner : : get_devs_distortion_check_val ( int & data )
2022-12-28 01:56:54 +00:00
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
}
2022-12-29 16:05:43 +00:00
int hg_scanner : : set_auto_flat ( void )
{
2022-12-30 10:16:40 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-12-29 16:05:43 +00:00
}
2022-12-31 04:08:44 +00:00
int hg_scanner : : set_serial_num ( string str )
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
}
2023-01-03 03:12:26 +00:00
int hg_scanner : : set_vid_pid ( int data )
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
}
int hg_scanner : : get_vid_pid ( int & data )
{
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
}
2022-05-03 03:56:07 +00:00
//////////////////////////////////////////////////////////////////////////////////////////////////////
int hg_scanner : : set_leaflet_scan ( void )
{
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_NO_DATA ;
2022-05-03 03:56:07 +00:00
}
int hg_scanner : : get_abuot_info ( void )
{
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_NO_DATA ;
2022-05-03 03:56:07 +00:00
}
int hg_scanner : : restore_default_setting ( void )
{
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_NO_DATA ;
2022-05-03 03:56:07 +00:00
}
int hg_scanner : : set_final_image_format ( SANE_FinalImgFormat * fmt )
{
switch ( fmt - > img_format )
{
case SANE_IMAGE_TYPE_BMP :
img_type_ = " .bmp " ;
break ;
case SANE_IMAGE_TYPE_PNG :
img_type_ = " .png " ;
break ;
case SANE_IMAGE_TYPE_JPG :
img_type_ = " .jpg " ;
break ;
case SANE_IMAGE_TYPE_TIFF :
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_INVALID_PARAMETER ;
2022-05-03 03:56:07 +00:00
case SANE_IMAGE_TYPE_WEBP :
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_INVALID_PARAMETER ;
2022-05-03 03:56:07 +00:00
case SANE_IMAGE_TYPE_PDF :
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_INVALID_PARAMETER ;
2022-05-03 03:56:07 +00:00
case SANE_IMAGE_TYPE_GIF :
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_INVALID_PARAMETER ;
2022-05-03 03:56:07 +00:00
case SANE_IMAGE_TYPE_SVG :
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_INVALID_PARAMETER ;
2022-05-03 03:56:07 +00:00
default :
2022-06-15 03:05:36 +00:00
img_type_ = " .bmp " ;
2022-05-03 03:56:07 +00:00
break ;
}
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
int hg_scanner : : get_compression_format ( void )
{
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
int hg_scanner : : set_compression_format ( void )
{
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
int hg_scanner : : set_auto_color_type ( void )
{
is_auto_matic_color = true ;
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_OK ;
2022-05-03 03:56:07 +00:00
}
int hg_scanner : : get_device_code ( void )
{
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
2022-12-22 10:37:53 +00:00
int hg_scanner : : get_sleep_time ( int & data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
2022-12-22 10:37:53 +00:00
int hg_scanner : : set_sleep_time ( int data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
2022-12-22 10:37:53 +00:00
int hg_scanner : : set_notify_sleep ( )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
2022-12-22 10:37:53 +00:00
int hg_scanner : : get_scanner_paperon ( SANE_Bool & paperon )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-05-03 03:56:07 +00:00
}
2022-12-22 10:37:53 +00:00
int hg_scanner : : get_scan_is_sleep ( SANE_Bool & data )
2022-05-03 03:56:07 +00:00
{
2022-05-17 07:04:55 +00:00
return SCANNER_ERR_DEVICE_NOT_SUPPORT ;
2022-06-14 09:02:19 +00:00
}
2023-01-28 07:19:10 +00:00
void hg_scanner : : image_process ( std : : shared_ptr < tiny_buffer > & buffer , uint32_t id )
2022-10-17 10:15:29 +00:00
{
2022-11-01 09:20:57 +00:00
if ( ! buffer . get ( ) | | ! ImagePrc_pHandle_ )
{
return ;
}
2022-10-17 10:15:29 +00:00
int ret = SCANNER_ERR_OK ;
2022-11-01 09:20:57 +00:00
hg_imgproc : : IMGPRCPARAM param = get_image_process_object ( pid_ ) ;
2022-10-17 10:15:29 +00:00
hg_imgproc : : IMGHEAD ih ;
int err = SCANNER_ERR_OK ,
2022-10-20 06:58:26 +00:00
index = 0 ;
2022-10-17 10:15:29 +00:00
void * buf = NULL ;
2022-11-01 09:20:57 +00:00
hg_imgproc : : load_buffer ( ImagePrc_pHandle_ , buffer ) ;
hg_imgproc : : decode ( ImagePrc_pHandle_ , pid_ , & img_conf_ , & param ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " decode " ) ;
2022-10-17 10:15:29 +00:00
2022-12-30 10:56:24 +00:00
if ( is_dpi_color_check )
2022-10-22 01:46:30 +00:00
{
2022-12-30 10:56:24 +00:00
CISTestImageProcess : : CISTestResult res ;
err = hg_imgproc : : cis_test_image ( ImagePrc_pHandle_ , res ) ;
2023-01-09 08:03:12 +00:00
distortion_val . h = res . h ;
distortion_val . w = res . w ;
distortion_val . scaleXY = res . scaleXY ;
save_dpi_color_check_val = res . scaleXY ;
2022-12-31 04:08:44 +00:00
is_dpi_color_check = false ;
2022-12-30 10:56:24 +00:00
}
else if ( param . cis_image )
{
printf ( " cis 原图测试无需任何算法 \r \n " ) ;
2022-10-22 01:46:30 +00:00
}
2022-12-28 01:56:54 +00:00
else
{
if ( ( isremove_left_hole | | isremove_right_hole | | isremove_top_hole | | isremove_low_hole ) & & ( pid_ ! = 0x239 & & pid_ ! = 0x439 ) )
{
ret = hg_imgproc : : fillhole ( ImagePrc_pHandle_ , isremove_top_hole_threshold , isremove_low_hole_threshold , isremove_left_hole_threshold , isremove_right_hole_threshold ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " fillhole " ) ;
}
if ( pid_ ! = 0x239 & & pid_ ! = 0x439 )
{
2023-01-14 01:25:47 +00:00
float dpi3288 = ( img_conf_ . resolution_dst > = 300 & & is_kernelsnap3288_221106_ ) ? 300 : 200 ;
2023-01-13 06:24:37 +00:00
2022-12-28 01:56:54 +00:00
ret = hg_imgproc : : auto_crop ( ImagePrc_pHandle_ , dpi3288 ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " auto_crop " ) ;
}
2022-10-17 10:15:29 +00:00
2022-12-28 01:56:54 +00:00
if ( ( img_conf_ . is_autodiscradblank_normal | | img_conf_ . is_autodiscradblank_vince ) & & ( pid_ ! = 0x239 & & pid_ ! = 0x439 ) )
{
ret = hg_imgproc : : discardBlank ( ImagePrc_pHandle_ ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " discardBlank " ) ;
}
2022-10-20 06:58:26 +00:00
2022-12-28 01:56:54 +00:00
if ( img_conf_ . fadeback ) //239
{
hg_imgproc : : fadeback ( ImagePrc_pHandle_ ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " fadeback " ) ;
}
2022-10-20 06:58:26 +00:00
2023-01-13 06:24:37 +00:00
if ( ( ( img_conf_ . resolution_dst ! = img_conf_ . resolution_native ) & & ( pid_ = = 0x300 | | pid_ = = 0x0400 ) & & ! is_kernelsnap3288_221106_ )
| | ( is_kernelsnap3288_221106_ & & ( img_conf_ . resolution_dst ! = 200 & & img_conf_ . resolution_dst ! = 300 ) ) )
2022-12-28 01:56:54 +00:00
{
2023-01-13 06:24:37 +00:00
float dpi3288 = ( img_conf_ . resolution_dst > 300 & & is_kernelsnap3288_221106_ ) ? 300 : 200 ;
2022-12-02 08:44:52 +00:00
2022-12-28 01:56:54 +00:00
hg_imgproc : : resolution_change ( ImagePrc_pHandle_ , dpi3288 ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " resolution_change " ) ;
}
2022-10-20 06:58:26 +00:00
2022-12-28 01:56:54 +00:00
if ( ( img_conf_ . cropRect . enable & & ! img_conf_ . is_autocrop ) & & ( pid_ ! = 0x239 & & pid_ ! = 0x439 ) )
{
hg_imgproc : : croprect ( ImagePrc_pHandle_ ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " resolution_change " ) ;
}
2022-10-20 06:58:26 +00:00
2022-12-28 01:56:54 +00:00
if ( ( img_conf_ . filter ! = ColorFilter : : FILTER_NONE
& & ( image_prc_param_ . bits . color_mode = = COLOR_MODE_BLACK_WHITE
| | image_prc_param_ . bits . color_mode = = COLOR_MODE_256_GRAY ) )
& & ( pid_ ! = 0x239 & & pid_ ! = 0x439 ) )
{
hg_imgproc : : channel ( ImagePrc_pHandle_ ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " filter " ) ;
}
2022-10-20 06:58:26 +00:00
2022-12-28 01:56:54 +00:00
{
adjust_color ( ImagePrc_pHandle_ ) ; //色调曲线 普通dsp版本需要矫正颜色
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " adjust_color " ) ;
}
2022-10-17 10:15:29 +00:00
2022-12-28 01:56:54 +00:00
if ( ( img_conf_ . pixtype = = COLOR_MODE_24_BITS & & img_conf_ . hsvcorrect ) & & ( pid_ ! = 0x239 & & pid_ ! = 0x439 ) )
{
hg_imgproc : : answerSheetFilterRed ( ImagePrc_pHandle_ ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " answerSheetFilterRed " ) ;
}
2022-10-20 06:58:26 +00:00
2022-12-28 01:56:54 +00:00
if ( ( img_conf_ . refuseInflow ) & & ( pid_ ! = 0x239 & & pid_ ! = 0x439 ) )
{
int lv = 5 ;
2022-10-17 10:15:29 +00:00
2022-12-28 01:56:54 +00:00
if ( image_prc_param_ . bits . is_permeate_lv_ = = 0 )
lv = 5 ;
else if ( image_prc_param_ . bits . is_permeate_lv_ = = 1 )
lv = 15 ;
else if ( image_prc_param_ . bits . is_permeate_lv_ = = 2 )
lv = 25 ;
else if ( image_prc_param_ . bits . is_permeate_lv_ = = 3 )
lv = 35 ;
else if ( image_prc_param_ . bits . is_permeate_lv_ = = 4 )
lv = 45 ;
2022-10-17 10:15:29 +00:00
2022-12-28 01:56:54 +00:00
hg_imgproc : : antiInflow ( ImagePrc_pHandle_ , lv ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " antiInflow " ) ;
}
if ( ( img_conf_ . colorCorrection & & img_conf_ . pixtype ! = COLOR_MODE_BLACK_WHITE ) & & ( pid_ ! = 0x239 & & pid_ ! = 0x439 ) )
{
hg_imgproc : : colorCorrection ( ImagePrc_pHandle_ ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " colorCorrection " ) ;
}
2022-10-20 06:58:26 +00:00
2022-10-17 10:15:29 +00:00
2022-12-28 01:56:54 +00:00
if ( ( ( img_conf_ . imageRotateDegree ! = TEXT_DIRECTION_0 | | img_conf_ . is_backrotate180 ) & & ( ! img_conf_ . is_autotext ) ) & & ( pid_ ! = 0x239 & & pid_ ! = 0x439 ) )
{
hg_imgproc : : orentation ( ImagePrc_pHandle_ ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " orentation " ) ;
}
2022-10-20 06:58:26 +00:00
2022-12-28 01:56:54 +00:00
if ( ( img_conf_ . removeMorr ) & & ( pid_ ! = 0x239 & & pid_ ! = 0x439 ) )
{
hg_imgproc : : textureRemove ( ImagePrc_pHandle_ ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " textureRemove " ) ;
}
2022-10-20 06:58:26 +00:00
2022-12-28 01:56:54 +00:00
if ( ( img_conf_ . detachnoise . is_detachnoise ) & & ( pid_ ! = 0x239 & & pid_ ! = 0x439 ) )
{
hg_imgproc : : nosieDetach ( ImagePrc_pHandle_ ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " nosieDetach " ) ;
}
2022-10-20 06:58:26 +00:00
2022-12-28 01:56:54 +00:00
if ( ( img_conf_ . pixtype = = COLOR_MODE_BLACK_WHITE ) & & ( pid_ ! = 0x239 & & pid_ ! = 0x439 ) )
{
hg_imgproc : : errorextention ( ImagePrc_pHandle_ ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " errorextention " ) ;
}
2022-10-20 06:58:26 +00:00
2022-12-28 01:56:54 +00:00
if ( ( ( img_conf_ . en_fold & & pid_ ! = 0x239 & & pid_ ! = 0x439 ) ) )
{
hg_imgproc : : fold ( ImagePrc_pHandle_ ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " fold " ) ;
}
2022-10-17 10:15:29 +00:00
2022-12-28 01:56:54 +00:00
if ( img_conf_ . multi_output_red & & img_conf_ . pixtype = = COLOR_MODE_24_BITS ) //239
{
err = hg_imgproc : : multi_out_red ( ImagePrc_pHandle_ ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " multi_out_red " ) ;
}
2022-10-17 10:15:29 +00:00
2022-12-28 01:56:54 +00:00
if ( ( img_conf_ . sharpen ) & & ( pid_ ! = 0x239 & & pid_ ! = 0x439 ) )
{
hg_imgproc : : sharpenType ( ImagePrc_pHandle_ ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " sharpenType " ) ;
}
2022-10-17 10:15:29 +00:00
2022-12-28 01:56:54 +00:00
if ( image_prc_param_ . bits . split ) //239
{
split3399_ + + ;
err = hg_imgproc : : split ( ImagePrc_pHandle_ , split3399_ ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " split " ) ;
}
2022-10-17 10:15:29 +00:00
2023-01-13 06:24:37 +00:00
if ( ! img_conf_ . splitImage & & ! img_conf_ . multi_output_red & & ! is_multiout ) //239
2022-10-17 10:15:29 +00:00
{
2022-12-28 01:56:54 +00:00
if ( img_conf_ . automaticcolor )
{
hg_imgproc : : auto_matic_color ( ImagePrc_pHandle_ , img_conf_ . automaticcolortype ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " auto_matic_color " ) ;
}
}
if ( img_conf_ . is_autotext ) //239
{
//hg_imgproc::ocr_auto_txtdirect(ImagePrc_pHandle_);
hg_imgproc : : tesseract_auto_txtdirect ( ImagePrc_pHandle_ ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " ocr_auto_txtdirect " ) ;
2022-10-17 10:15:29 +00:00
}
2022-10-20 06:58:26 +00:00
2022-12-28 01:56:54 +00:00
if ( is_quality_ = = IMG_SPEED & & resolution_ > = 300 ) //239
{
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " set resolution_ is :%d \n " , resolution_ )
err = hg_imgproc : : quality ( ImagePrc_pHandle_ , resolution_ ) ;
2022-11-25 04:45:58 +00:00
2022-12-28 01:56:54 +00:00
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " quality " ) ;
}
2022-10-20 06:58:26 +00:00
2022-12-28 01:56:54 +00:00
if ( is_multiout ) //239
{
int multi_out = img_conf_ . multiOutput ;
err = hg_imgproc : : multi_out ( ImagePrc_pHandle_ , multi_out ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " multi_out " ) ;
}
2022-10-17 10:15:29 +00:00
}
2022-11-01 09:20:57 +00:00
hg_imgproc : : final ( ImagePrc_pHandle_ ) ;
( this - > * dump_img_ ) ( ImagePrc_pHandle_ , " final " ) ;
while ( hg_imgproc : : get_final_data ( ImagePrc_pHandle_ , & ih , & buf , index + + ) = = SCANNER_ERR_OK )
2022-10-17 10:15:29 +00:00
{
VLOG_MINI_5 ( LOG_LEVEL_DEBUG_INFO , " Final picture %d (%d * %d * %d) with %u bytes! \n " , index
, ih . width , ih . height , ih . bits * ih . channels , ih . total_bytes ) ;
if ( ! img_type_ . empty ( ) )
{
std : : vector < unsigned char > bmpdata ;
//cv::imencode(img_type_,*((cv::Mat*)buf),bmpdata);
2022-11-01 09:20:57 +00:00
hg_imgproc : : imgtypechange ( ImagePrc_pHandle_ , img_type_ , buf , bmpdata ) ;
2022-10-17 10:15:29 +00:00
if ( bmpdata . empty ( ) )
{
status_ = SCANNER_ERR_NO_DATA ;
return ;
}
buf = bmpdata . data ( ) ;
ih . total_bytes = bmpdata . size ( ) ;
VLOG_MINI_6 ( LOG_LEVEL_DEBUG_INFO , " Set img type is:%s Final picture %d (%d * %d * %d) with %u bytes! \n " , img_type_ . c_str ( ) , index
, ih . width , ih . height , ih . bits * ih . channels , ih . total_bytes ) ;
}
2023-01-28 07:19:10 +00:00
if ( id = = - 1 )
id = hg_scanner_mgr : : unique_id ( ) ;
save_final_image ( & ih , buf , id ) ;
id = - 1 ;
2022-10-17 10:15:29 +00:00
}
2022-11-19 17:18:04 +00:00
}
int hg_scanner : : image_configuration ( SCANCONF & ic )
{
int ret = 0 ;
ic . papertype = paper_size_ ;
if ( is_lateral ( image_prc_param_ . bits . paper ) )
ic . paperAlign = Rot270 ;
else
ic . paperAlign = Rot0 ;
2022-11-23 11:00:17 +00:00
//{
//子类处理
//ic.en_sizecheck = dev_conf_.params_3399.enable_sizecheck;
//if (image_prc_param_.bits.text_direction != TEXT_DIRECTION_AUTO)
// ic.imageRotateDegree = (float)image_prc_param_.bits.text_direction;
//else
// ic.imageRotateDegree = 0;
2022-11-19 17:18:04 +00:00
2022-11-23 11:00:17 +00:00
//ic.imageRotateDegree *= 90.0f;
//}
2022-11-19 17:18:04 +00:00
ic . is_duplex = ( image_prc_param_ . bits . page = = PAGE_DOUBLE
| | image_prc_param_ . bits . page = = PAGE_OMIT_EMPTY
| | image_prc_param_ . bits . page = = PAGE_OMIT_EMPTY_RECEIPT
| | image_prc_param_ . bits . page = = PAGE_FOLIO ) ;
2022-12-31 03:06:46 +00:00
if ( is_dpi_color_check )
{
ic . is_duplex = false ;
}
2022-11-19 17:18:04 +00:00
ic . en_fold = ( image_prc_param_ . bits . page = = PAGE_FOLIO ) ;
2022-11-23 07:39:13 +00:00
2022-11-19 17:18:04 +00:00
ic . pixtype = image_prc_param_ . bits . color_mode = = COLOR_MODE_AUTO_MATCH ? 2 : image_prc_param_ . bits . color_mode ;
ic . automaticcolor = is_auto_matic_color ;
ic . automaticcolortype = 1 ; // ic.pixtype; //存疑
ic . resolution_dst = ( resolution_ > = 300 ) ? ( is_quality_ = = IMG_SPEED ? 200 : resolution_ ) : resolution_ ;
//if (resolution_ >= 300)
//{
// if (is_quality_ == IMG_SPEED)
// ic.resolution_dst = 200;
// else
// ic.resolution_dst = resolution_;
//}
//else
// ic.resolution_dst = resolution_;
ic . resolution_native = 200.0f ;
ic . gamma = ( float ) gamma_ ;
{
//子类处理
/*ic.contrast = (contrast_ - 4) * 333.0;
ic . brightness = ( bright_ - 128 ) * ( 2000.0 / 254.0 ) ; */
}
ic . threshold = threshold_ ;
ic . is_autocontrast = 0 ; //无参数
ic . is_autocrop = ( ic . papertype = = TwSS : : None | | ic . papertype = = TwSS : : USStatement ) ;
ic . is_autodiscradblank_normal = image_prc_param_ . bits . page = = PAGE_OMIT_EMPTY ;
2022-11-28 08:03:11 +00:00
ic . discardblank_percent = omit_empty_level_ ;
2022-11-19 17:18:04 +00:00
ic . is_autodiscradblank_vince = image_prc_param_ . bits . page = = PAGE_OMIT_EMPTY_RECEIPT ;
ic . is_switchfrontback = image_prc_param_ . bits . exchange ;
ic . autodescrew = image_prc_param_ . bits . automatic_skew ;
2022-11-22 07:31:21 +00:00
ic . multi_output_red = image_prc_param_ . bits . rid_red ; //之前加上可能导致超时,或者未知错误不可描述。
2022-11-19 17:18:04 +00:00
ic . hsvcorrect = image_prc_param_ . bits . rid_answer_red ;
ic . sharpen = image_prc_param_ . bits . sharpen ;
//ic.enhance_color = image_prc_param_.bits.rid_color; //加这个会有问题
ic . fillbackground = image_prc_param_ . bits . erase_black_frame ;
ic . is_convex = ( image_prc_param_ . bits . fill_background = = FILL_BKG_CONVEX_POLYGON ) ;
if ( ic . resolution_dst = = 300 )
ic . noise = anti_noise_ * 1.5 ;
else if ( ic . resolution_dst = = 600 )
ic . noise = anti_noise_ * 3 ;
else
ic . noise = anti_noise_ ;
ic . indent = margin_ ;
ic . AutoCrop_threshold = threshold_ ;
{
//子类处理
//if (test_1_paper_)
//{
// LOG_INFO(LOG_LEVEL_DEBUG_INFO, "scanning mode: testing ONE paper ...\n");
// ic.scannum = ic.is_duplex ? 2 : 1;
//}
//else
//{
// if (scan_count_ == -1)
// ic.scannum = -1;
// else
// ic.scannum = (ic.is_duplex ? scan_count_ * 2 : scan_count_);
//}
}
ic . is_backrotate180 = image_prc_param_ . bits . rotate_back_180 ;
ic . is_dogeardetection = image_prc_param_ . bits . fractate_check ;
{
//子类处理
//ic.hardwarecaps.en_skrewdetect = dev_conf_.params_3399.screw_detect_enable;
//ic.hardwarecaps.en_doublefeed = dev_conf_.params_3399.ultrasonic_enable;
//ic.hardwarecaps.en_stapledetect = dev_conf_.params_3399.staple_enbale;
//ic.hardwarecaps.skrewdetectlevel = dev_conf_.params_3399.screw_detect_level;
//ic.hardwarecaps.is_autopaper = dev_conf_.params_3399.is_autopaper;
}
ic . hardwarecaps . capturepixtype = 0 ; //暂无参数 获取图像类型
ic . hardwarecaps . lowpowermode = LowPowerMode : : Min_None ; //暂无参数 设置休眠时间 两个参数3399未使用
ic . fillhole . is_fillhole = image_prc_param_ . bits . rid_hole ;
ic . fillhole . fillholeratio = rid_hole_range_ ;
ic . detachnoise . is_detachnoise = image_prc_param_ . bits . noise_optimize ;
ic . detachnoise . detachnoise = noise_range_ ;
ic . is_autotext = image_prc_param_ . bits . text_direction = = TEXT_DIRECTION_AUTO ? 1 : 0 ;
ic . isfillcolor = is_color_fill ;
ic . refuseInflow = image_prc_param_ . bits . is_permeate ;
ic . colorCorrection = 0 ;
ic . removeMorr = image_prc_param_ . bits . remove_morr ;
ic . errorExtention = image_prc_param_ . bits . error_extention ; //
ic . textureRemove = image_prc_param_ . bits . remove_txtture ; //
ic . splitImage = image_prc_param_ . bits . split ;
{
ic . cropRect . enable = custom_area_ ;
int height = ( custom_area_br_y_ * ic . resolution_dst ) / 25.4 - ( custom_area_lt_y_ * ic . resolution_dst / 25.4 ) ;
int width = ( custom_area_br_x_ * ic . resolution_dst ) / 25.4 - ( custom_area_lt_x_ * ic . resolution_dst / 25.4 ) ;
ic . cropRect . height = height ;
ic . cropRect . width = width ;
ic . cropRect . x = custom_area_lt_x_ * ic . resolution_dst / 25.4 ;
ic . cropRect . y = custom_area_lt_y_ * ic . resolution_dst / 25.4 ;
}
ic . multiOutput = ( MultiOutput ) image_prc_param_ . bits . multi_out ;
ic . normalCrop = image_prc_param_ . bits . dark_sample ;
ic . dogeardistabce = fractate_level_ ;
ic . fadeback = image_prc_param_ . bits . erase_bakground ;
ic . fadebackrange = erase_bkg_range_ ;
ic . isuoloadexceptionimage = ( double_paper_handle_ & DOUBLE_PAPER_SAVE_IMG ) = = DOUBLE_PAPER_SAVE_IMG ;
adjust_filling_hole ( & ic ) ;
2022-11-23 07:39:13 +00:00
2022-11-19 17:18:04 +00:00
ic . fold_concatmode = fold_type_ ;
//多流输出优先级最高
if ( is_multiout )
{
ic . pixtype = image_prc_param_ . bits . multi_out = = MULTI_GRAY_AND_BW ? COLOR_MODE_256_GRAY : COLOR_MODE_24_BITS ;
ic . filter = 3 ;
ic . hsvcorrect = 0 ;
ic . multi_output_red = 0 ;
ic . fadeback = false ;
ic . sharpen = 0 ;
ic . removeMorr = 0 ;
ic . textureRemove = 0 ;
ic . errorExtention = 0 ;
ic . detachnoise . is_detachnoise = 0 ;
}
else if ( image_prc_param_ . bits . color_mode = = COLOR_MODE_24_BITS )
{
ic . filter = 3 ;
ic . errorExtention = 0 ;
ic . detachnoise . is_detachnoise = 0 ;
}
else if ( image_prc_param_ . bits . color_mode = = COLOR_MODE_256_GRAY )
{
int filter_clr [ ] = { 3 , 0 , 1 , 2 , 5 , 6 , 7 } ;
ic . filter = filter_clr [ image_prc_param_ . bits . rid_color ] ;
if ( ic . filter ! = 3 )
{
ic . pixtype = 2 ;
}
ic . multi_output_red = 0 ;
ic . hsvcorrect = 0 ;
ic . fadeback = false ;
ic . errorExtention = 0 ;
ic . detachnoise . is_detachnoise = 0 ;
}
else if ( image_prc_param_ . bits . color_mode = = COLOR_MODE_BLACK_WHITE )
{
int filter_clr [ ] = { 3 , 0 , 1 , 2 , 5 , 6 , 7 } ;
ic . filter = filter_clr [ image_prc_param_ . bits . rid_color ] ;
if ( ic . filter ! = 3 )
{
ic . pixtype = 2 ;
}
ic . multi_output_red = 0 ;
ic . hsvcorrect = 0 ;
ic . fadeback = false ;
ic . sharpen = 0 ;
ic . removeMorr = 0 ;
ic . textureRemove = 0 ;
}
else if ( image_prc_param_ . bits . color_mode = = COLOR_MODE_AUTO_MATCH )
{
ic . pixtype = 2 ;
ic . filter = 3 ;
ic . hsvcorrect = 0 ;
ic . multi_output_red = 0 ;
ic . fadeback = false ;
ic . sharpen = 0 ;
ic . removeMorr = 0 ;
ic . textureRemove = 0 ;
ic . errorExtention = 0 ;
ic . detachnoise . is_detachnoise = 0 ;
}
//自定义裁切
if ( image_prc_param_ . bits . paper = = PAPER_AUTO_MATCH
| | image_prc_param_ . bits . paper = = PAPER_MAX_SIZE
| | image_prc_param_ . bits . paper = = PAPER_MAX_SIZE_CLIP
| | image_prc_param_ . bits . paper = = PAPER_TRIGEMINY
)
{
ic . cropRect . enable = false ;
}
img_conf_ = ic ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.pixtype=%d " , ic . pixtype ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.papertype=%d " , ic . papertype ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.AutoCrop_threshold=%d " , ic . AutoCrop_threshold ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.autodescrew=%d " , ic . autodescrew ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.automaticcolor=%d " , ic . automaticcolor ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.brightness=%f " , ic . brightness ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.contrast=%f " , ic . contrast ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.en_fold=%d " , ic . en_fold ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.en_sizecheck=%d " , ic . en_sizecheck ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.enhance_color=%d " , ic . enhance_color ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.fillbackground=%d " , ic . fillbackground ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.filter=%d " , ic . filter ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.gamma=%f " , ic . gamma ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.hardwarecaps.capturepixtype=%d " , ic . hardwarecaps . capturepixtype ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.hardwarecaps.en_doublefeed=%d " , ic . hardwarecaps . en_doublefeed ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.hsvcorrect=%d " , ic . hsvcorrect ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.imageRotateDegree=%f " , ic . imageRotateDegree ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.indent=%d " , 5 ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.is_autocontrast=%d " , ic . is_autocontrast ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.is_autocrop=%d " , ic . is_autocrop ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.is_autodiscradblank_normal=%d " , ic . is_autodiscradblank_normal ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.is_autodiscradblank_vince=%d " , ic . is_autodiscradblank_vince ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.is_autotext=%d " , ic . is_autotext ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.is_backrotate180=%d " , ic . is_backrotate180 ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.is_convex=%d " , ic . is_convex ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.is_duplex=%d " , ic . is_duplex ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.is_switchfrontback=%d " , ic . is_switchfrontback ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.is_dogeardetection=%d " , ic . is_dogeardetection ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.fillhole.multi_output_red=%d " , ic . multi_output_red ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.noise=%d " , ic . noise ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.pixtype=%d " , ic . pixtype ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.resolution_dst=%f " , ic . resolution_dst ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.resolution_native=%f " , ic . resolution_native ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.scannum=%d " , ic . scannum ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.sharpen=%d " , ic . sharpen ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.discardblank_percent=%d " , ic . discardblank_percent ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.detachnoise.is_detachnoise=%d " , ic . detachnoise . is_detachnoise ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.detachnoise.detachnoise=%d \r " , ic . detachnoise . detachnoise ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.detachnoise.refuseInflow=%d \r " , ic . refuseInflow ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.detachnoise.refuseInflow=%d \r " , ic . refuseInflow ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.removeMorr=%d \r " , ic . removeMorr ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.errorExtention=%d \r " , ic . errorExtention ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.textureRemove=%d \r \n " , ic . refuseInflow ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.fillhole.is_fillhole=%d \r \n " , ic . fillhole . is_fillhole ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.ic.fillhole.fillholeratio=%d \r \n " , ic . fillhole . fillholeratio ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.fadeback=%d \r \n " , ic . fadeback ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.cropRect.enable=%d \r " , ic . cropRect . enable ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.cropRect.width=%d \r \n " , ic . cropRect . width ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.cropRect.height=%d \r \n " , ic . cropRect . height ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.cropRect.x=%d \r \n " , ic . cropRect . x ) ;
VLOG_MINI_1 ( LOG_LEVEL_DEBUG_INFO , " \n ic.cropRect.y=%d \r \n " , ic . cropRect . y ) ;
return ret ;
2022-10-17 10:15:29 +00:00
}