调整SANE协议流程,纸张、分辨率、对比度、亮度、单双面采用固定名称

This commit is contained in:
gb 2022-05-20 14:46:25 +08:00
parent f0a59a3445
commit 2693f5cf59
10 changed files with 229 additions and 21 deletions

View File

@ -114,6 +114,27 @@ g_img_quality[] =
{OPTION_VALUE_HZ_HZYX, IMG_QUALITY}
};
static struct paper_size
{
int paper;
SIZE size;
}g_paper_size[] =
{
{PAPER_A3, {297, 420}},
{PAPER_A4, {210, 297}},
{PAPER_A5, {148, 210}},
{PAPER_A6, {105, 148}},
{PAPER_B4, {257, 364}},
{PAPER_B5, {176, 250}}, // {PAPER_B5, {182, 257}},
{PAPER_B6, {125, 176}},
{PAPER_8K, {297, 420}},
{PAPER_16K, {210, 285}}, // {PAPER_16K, {185, 260}}
{PAPER_A4_LATERAL, {297, 210}},
{PAPER_A5_LATERAL, {210, 148}},
{PAPER_A6_LATERAL, {148, 105}},
{PAPER_B5_LATERAL, {250, 176}}, // {PAPER_B5, {182, 257}},
{PAPER_B6_LATERAL, {176, 125}}
};
static int match_best(struct _fixed_option* arr, size_t num, std::string& val, bool& exact)
{
@ -179,6 +200,16 @@ int match_best_rid_color(std::string& val, bool* exact)
return ind;
}
SIZE paper_size(int paper)
{
for (size_t i = 0; i < ARRAY_SIZE(g_paper_size); ++i)
{
if (g_paper_size[i].paper == paper)
return g_paper_size[i].size;
}
return SIZE{ 2338, 3307 };
}
int match_best_paper(std::string& val, bool* exact)
{
bool yes = true;

View File

@ -7,11 +7,29 @@
#include <string>
#include "char_const.h"
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 硬件配置项定义
//
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
typedef struct hg_tag_SIZE
{
long cx;
long cy;
}CSSIZE, * PCSSIZE, * LPCSSIZE;
typedef CSSIZE CSSIZEL;
typedef CSSIZE* PCSSIZEL, * LPCSSIZEL;
#ifdef WIN32
#include <Windows.h>
#else
typedef CSSIZE Size;
typedef CSSIZE SIZE;
typedef unsigned long DWORD;
typedef long LONG;
#endif
enum hg_scanner_type
{
HG_SCANNER_TYPE_NONE = 0,
@ -206,6 +224,7 @@ enum
PAPER_MAX_SIZE_CLIP,
PAPER_TRIGEMINY,
};
SIZE paper_size(int paper); // unit: mm
int match_best_paper(std::string& val, bool* exact);
std::string paper_string(int paper);
bool is_lateral(int paper);
@ -379,16 +398,6 @@ typedef struct tag_USBCB {
//DSP设备USB读写协议结构 - OVER
typedef struct hg_tag_SIZE
{
long cx;
long cy;
}CSSIZE, *PCSSIZE, *LPCSSIZE;
typedef CSSIZE CSSIZEL;
typedef CSSIZE *PCSSIZEL, *LPCSSIZEL;
enum PaperAlign :unsigned char {
Rot0 = 0,
Rot270 = 3,

View File

@ -1761,7 +1761,7 @@ void hg_scanner::copy_to_sane_image_header(SANE_Parameters* header, int w, int h
else
header->format = SANE_FRAME_GRAY;
header->depth = 8; // 此处指每一个颜色分量的位深我们的扫描仪固定为“8”
header->last_frame = true; // 一幅图片如果各个分量相互分离则最后一个分量的时候设置为true。彩色图像RGB时也只有一“帧”所以也为true
header->last_frame = SANE_TRUE; // 一幅图片如果各个分量相互分离则最后一个分量的时候设置为true。彩色图像RGB时也只有一“帧”所以也为true
header->pixels_per_line = w;
header->lines = h;
header->bytes_per_line = line_bytes;
@ -2162,6 +2162,7 @@ int hg_scanner::get_image_info(SANE_Parameters* ii)
IMH imh;
bzero(&imh, sizeof(imh));
bzero(ii, sizeof(*ii));
while ((!wait_img_.is_waiting() || !wait_usb_.is_waiting()) && final_imgs_.Size() <= 0)
this_thread::sleep_for(chrono::milliseconds(10));
@ -2174,6 +2175,30 @@ int hg_scanner::get_image_info(SANE_Parameters* ii)
else
copy_to_sane_image_header(ii, imh.width, imh.height, imh.line_bytes, imh.channels);
}
if (ret == SCANNER_ERR_NO_DATA && final_img_index_ == 0)
{
if (status_ != SCANNER_ERR_OK)
ret = status_;
else
{
ii->depth = 8;
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;
}
}
HG_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::strerr((scanner_err)ret).c_str());
return ret;

View File

@ -348,7 +348,7 @@ public:
};
#ifdef OEM_HANWANG
static const std::string helpfile_ ="/opt/apps/com.hanvonchina.hanvonscan/entries/help/HanvonScan_App_Help_manual.pdf";//帮助文档路径
static const std::string helpfile_ ="/opt/apps/com.hanvonchina.hanvonscan/entries/help/HanVonScan_App_Help_manual.pdf";//帮助文档路径
#else
static const std::string helpfile_ ="/opt/apps/com.huagaochina.huagoscan/entries/help/HuaGoScan_App_Help_manual.pdf";//帮助文档路径
#endif

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -19,6 +19,8 @@
#include "../sdk/hginclude/hg_log.h"
#include "ini_file.h"
#include "../../sdk/include/sane/sane_option_definitions.h"
#ifndef VERSION_BUILD
#define VERSION_BUILD 22030
#endif
@ -1013,7 +1015,7 @@ scanner_err hg_scanner_control(scanner_handle h, unsigned long code, void* data,
hg_sane_middleware* hg_sane_middleware::inst_ = NULL;
const SANE_Device** hg_sane_middleware::dev_list_ = NULL;
hg_sane_middleware::hg_sane_middleware(void)
hg_sane_middleware::hg_sane_middleware(void) : opt_0_(nullptr)
{
signal(SIGUSR1, &hg_sane_middleware::device_pnp);
local_utility::char_transfer_init();
@ -1030,6 +1032,8 @@ hg_sane_middleware::~hg_sane_middleware()
for (size_t i = 0; i < openning_.size(); ++i)
hg_scanner_close(openning_[i].handle, true);
hg_scanner_uninitialize();
if (opt_0_)
local_utility::free_memory(opt_0_);
}
const SANE_Device** hg_sane_middleware::to_sane_device(ScannerInfo* hgscanner, int count)
@ -1753,6 +1757,65 @@ bool hg_sane_middleware::get_current_value(scanner_handle handle, int option, vo
return ret;
}
void* hg_sane_middleware::get_default_value(scanner_handle handle, int option)
{
std::string val(get_option_json(handle, option));
void* data = nullptr;
json* jsn = new json();
if (jsn->attach_text(&val[0]) &&
jsn->get_value("type", val))
{
if (val == "bool")
{
bool v = false;
jsn->get_value("default", v);
data = local_utility::acquire_memory(sizeof(v), "");
memcpy(data, &v, sizeof(v));
HG_VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "option %d default value is: %s\n", option, v ? "true" : "false");
}
else if (val == "int")
{
int v = 0;
jsn->get_value("default", v);
data = local_utility::acquire_memory(sizeof(v), "");
memcpy(data, &v, sizeof(v));
HG_VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "option %d default value is: %d\n", option, v);
}
else if (val == "float")
{
double v = .0f;
jsn->get_value("default", v);
data = local_utility::acquire_memory(sizeof(v), "");
memcpy(data, &v, sizeof(v));
HG_VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "option %d default value is: %f\n", option, v);
}
else if (val == "string")
{
int size = 0;
jsn->get_value("size", size);
val = "";
jsn->get_value("default", val);
if (size < val.length())
size = val.length();
data = local_utility::acquire_memory(size + 4, "");
strcpy((char*)data, val.c_str());
HG_VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "option %d default value is: %s\n", option, (char*)data);
}
else
{
HG_VLOG_MINI_2(LOG_LEVEL_DEBUG_INFO, "option %d type is '%s' and cannot be set value.\n", option, val.c_str());
}
}
delete jsn;
return data;
}
void hg_sane_middleware::reload_current_value(scanner_handle handle, std::vector<int>* changed)
{
long count = 0;
@ -1899,6 +1962,22 @@ SANE_Option_Descriptor* hg_sane_middleware::get_option_descriptor(SANE_Handle h,
if (!handle)
return NULL;
if (option == 0)
{
if (!opt_0_)
{
opt_0_ = (SANE_Option_Descriptor*)local_utility::acquire_memory(sizeof(SANE_Option_Descriptor), "");
opt_0_->cap = SANE_CAP_SOFT_DETECT;
opt_0_->name = "option-count";
opt_0_->title = "";
opt_0_->desc = "Number of options";
opt_0_->type = SANE_TYPE_INT;
opt_0_->size = sizeof(SANE_TYPE_INT);
}
HG_LOG(LOG_LEVEL_DEBUG_INFO, "get_option_descriptor(0)\n");
return opt_0_;
}
ret = find_stored_descriptor(dev.dev_name.c_str(), option);
if (!ret)
{
@ -1949,6 +2028,7 @@ SANE_Status hg_sane_middleware::set_option(SANE_Handle h, SANE_Int option, SANE_
hg_scanner_get_parameter(handle, option, NULL, &count);
*((SANE_Int*)value) = count;
ret = SANE_STATUS_GOOD;
HG_VLOG_MINI_1(LOG_LEVEL_WARNING, "get option count = %d.\n", count);
}
else
{
@ -1961,18 +2041,40 @@ SANE_Status hg_sane_middleware::set_option(SANE_Handle h, SANE_Int option, SANE_
else
{
SANE_Option_Descriptor* desc = find_stored_descriptor(dev.dev_name.c_str(), option);
bool release_value = false;
if (!desc)
{
HG_VLOG_MINI_1(LOG_LEVEL_WARNING, "Option descriptor %d not found.\n", option);
HG_VLOG_MINI_1(LOG_LEVEL_FATAL, "Option descriptor %d not found.\n", option);
return SANE_STATUS_UNSUPPORTED;
}
else if (!value && desc->type != SANE_TYPE_BUTTON)
{
if (action == SANE_ACTION_SET_AUTO) // we assume the driver can set the option properbly, and no work to do
{
HG_VLOG_MINI_2(LOG_LEVEL_WARNING, "Option %d(%s) call SANE_ACTION_SET_AUTO, we set default value.\n", option, desc->title);
value = get_default_value(handle, option);
if(!value)
return SANE_STATUS_GOOD;
release_value = true;
}
else
{
HG_VLOG_MINI_2(LOG_LEVEL_WARNING, "Option descriptor %d(%s) need a value!.\n", option, desc->title);
return SANE_STATUS_INVAL;
}
}
if (desc->name == "duplex") // conver SANE_Bool to char*
{
bool dup = (*(SANE_Bool*)value) == SANE_TRUE;
value = local_utility::acquire_memory(desc->size + 4, "");
strcpy((char*)value, dup ? OPTION_VALUE_SMYM_SM : OPTION_VALUE_SMYM_DM);
release_value = true;
}
SANE_Status status = SANE_STATUS_GOOD;
std::string v(hg_sane_middleware::option_value_2_string(desc->type, value));
@ -2038,6 +2140,9 @@ SANE_Status hg_sane_middleware::set_option(SANE_Handle h, SANE_Int option, SANE_
if (after_do)
*after_do = err;
if (release_value)
local_utility::free_memory(value);
return status;
}
}

View File

@ -34,6 +34,7 @@ class hg_sane_middleware
SANE_Option_Descriptor* desc;
}DEVOPT;
std::vector<DEVOPT> opts_;
SANE_Option_Descriptor* opt_0_;
typedef struct _openning_scanner_option
{
@ -78,6 +79,7 @@ class hg_sane_middleware
SANE_Option_Descriptor* find_stored_descriptor(SANE_Handle handle, int option);
bool get_current_value(scanner_handle handle, int option, void* value, SANE_Value_Type *type = NULL);
void* get_default_value(scanner_handle handle, int option); // caller should call local_utility::free_memory to free the returned value
void reload_current_value(scanner_handle handle, std::vector<int>* changed = NULL);
/// <summary>