DPI可直接从图像信息获取
This commit is contained in:
parent
21fb4330e6
commit
de718d727e
|
@ -135,6 +135,7 @@ struct __declspec(novtable) IScanImg : public IRef
|
||||||
COM_API_DECLARE(int, height(void));
|
COM_API_DECLARE(int, height(void));
|
||||||
COM_API_DECLARE(int, depth(void));
|
COM_API_DECLARE(int, depth(void));
|
||||||
COM_API_DECLARE(int, channel(void));
|
COM_API_DECLARE(int, channel(void));
|
||||||
|
COM_API_DECLARE(int, dpi(void));
|
||||||
COM_API_DECLARE(SANE_Frame, type(void));
|
COM_API_DECLARE(SANE_Frame, type(void));
|
||||||
COM_API_DECLARE(unsigned int, bytes(void));
|
COM_API_DECLARE(unsigned int, bytes(void));
|
||||||
COM_API_DECLARE(unsigned int, header_size(void));
|
COM_API_DECLARE(unsigned int, header_size(void));
|
||||||
|
@ -154,7 +155,7 @@ struct __declspec(novtable) ISaneInvoker : public IRef
|
||||||
COM_API_DECLARE(bool, wait_image(DWORD milliseconds = -1));
|
COM_API_DECLARE(bool, wait_image(DWORD milliseconds = -1));
|
||||||
COM_API_DECLARE(int, get_scanned_images(DWORD milliseconds = 0));
|
COM_API_DECLARE(int, get_scanned_images(DWORD milliseconds = 0));
|
||||||
COM_API_DECLARE(IScanImg*, take_first_image(twain_xfer xfer = TWAIN_XFER_Native)); // call 'release' on returned value, plz
|
COM_API_DECLARE(IScanImg*, take_first_image(twain_xfer xfer = TWAIN_XFER_Native)); // call 'release' on returned value, plz
|
||||||
COM_API_DECLARE(bool, get_first_image_header(SANE_Parameters* header, size_t* bytes = NULL));
|
COM_API_DECLARE(bool, get_first_image_header(SANE_Parameters* header, size_t* bytes = NULL, int *dpi = NULL));
|
||||||
COM_API_DECLARE(bool, is_online(void));
|
COM_API_DECLARE(bool, is_online(void));
|
||||||
COM_API_DECLARE(bool, is_paper_on(void));
|
COM_API_DECLARE(bool, is_paper_on(void));
|
||||||
|
|
||||||
|
|
|
@ -679,6 +679,10 @@ COM_API_IMPLEMENT(scanned_img, int, channel(void))
|
||||||
{
|
{
|
||||||
return head_.format == SANE_FRAME_RGB ? 3 : 1;
|
return head_.format == SANE_FRAME_RGB ? 3 : 1;
|
||||||
}
|
}
|
||||||
|
COM_API_IMPLEMENT(scanned_img, int, dpi(void))
|
||||||
|
{
|
||||||
|
return dpi_;
|
||||||
|
}
|
||||||
COM_API_IMPLEMENT(scanned_img, SANE_Frame, type(void))
|
COM_API_IMPLEMENT(scanned_img, SANE_Frame, type(void))
|
||||||
{
|
{
|
||||||
return head_.format;
|
return head_.format;
|
||||||
|
@ -747,7 +751,7 @@ void __stdcall safe_img_queue::free_image(scanned_img* img)
|
||||||
img->release();
|
img->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool safe_img_queue::get_header(SANE_Parameters* header, size_t* bytes)
|
bool safe_img_queue::get_header(SANE_Parameters* header, size_t* bytes, int* dpi)
|
||||||
{
|
{
|
||||||
scanned_img *img = take(false, &safe_img_queue::access_image);
|
scanned_img *img = take(false, &safe_img_queue::access_image);
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
|
@ -760,6 +764,8 @@ bool safe_img_queue::get_header(SANE_Parameters* header, size_t* bytes)
|
||||||
img->copy_header(header);
|
img->copy_header(header);
|
||||||
if(bytes)
|
if(bytes)
|
||||||
*bytes = img->bytes();
|
*bytes = img->bytes();
|
||||||
|
if (dpi)
|
||||||
|
*dpi = img->dpi();
|
||||||
ok = true;
|
ok = true;
|
||||||
img->release();
|
img->release();
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,6 +91,7 @@ public:
|
||||||
COM_API_OVERRIDE(int, height(void));
|
COM_API_OVERRIDE(int, height(void));
|
||||||
COM_API_OVERRIDE(int, depth(void));
|
COM_API_OVERRIDE(int, depth(void));
|
||||||
COM_API_OVERRIDE(int, channel(void));
|
COM_API_OVERRIDE(int, channel(void));
|
||||||
|
COM_API_OVERRIDE(int, dpi(void));
|
||||||
COM_API_OVERRIDE(SANE_Frame, type(void));
|
COM_API_OVERRIDE(SANE_Frame, type(void));
|
||||||
COM_API_OVERRIDE(unsigned int, bytes(void));
|
COM_API_OVERRIDE(unsigned int, bytes(void));
|
||||||
COM_API_OVERRIDE(unsigned int, header_size(void));
|
COM_API_OVERRIDE(unsigned int, header_size(void));
|
||||||
|
@ -168,7 +169,7 @@ public:
|
||||||
~safe_img_queue();
|
~safe_img_queue();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool get_header(SANE_Parameters* header, size_t* bytes = NULL);
|
bool get_header(SANE_Parameters* header, size_t* bytes = NULL, int *dpi = NULL);
|
||||||
void clear();
|
void clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2273,9 +2273,9 @@ COM_API_IMPLEMENT(scanner, IScanImg*, take_first_image(twain_xfer xfer))
|
||||||
|
|
||||||
return dynamic_cast<IScanImg*>(img);
|
return dynamic_cast<IScanImg*>(img);
|
||||||
}
|
}
|
||||||
COM_API_IMPLEMENT(scanner, bool, get_first_image_header(SANE_Parameters* header, size_t* bytes))
|
COM_API_IMPLEMENT(scanner, bool, get_first_image_header(SANE_Parameters* header, size_t* bytes, int* dpi))
|
||||||
{
|
{
|
||||||
return images_.get_header(header, bytes);
|
return images_.get_header(header, bytes, dpi);
|
||||||
}
|
}
|
||||||
COM_API_IMPLEMENT(scanner, bool, is_online(void))
|
COM_API_IMPLEMENT(scanner, bool, is_online(void))
|
||||||
{
|
{
|
||||||
|
@ -2724,7 +2724,7 @@ int scanner::handle_device_event(int ev_code, void* data, unsigned int* len)
|
||||||
wchar_t name[40] = { 0 };
|
wchar_t name[40] = { 0 };
|
||||||
|
|
||||||
swprintf_s(name, _countof(name) - 1, L"img_%05u.bmp", ++img_ind_);
|
swprintf_s(name, _countof(name) - 1, L"img_%05u.bmp", ++img_ind_);
|
||||||
img = new scanned_img(handle_, simg->header, simg->data, simg->bytes, dpi_, (tmp_path_ + name).c_str(), xfer_, &img_fmt_);
|
img = new scanned_img(handle_, simg->header, simg->data, simg->bytes, simg->flag.dpi, (tmp_path_ + name).c_str(), xfer_, &img_fmt_);
|
||||||
if (img->bytes() /*>= simg->bytes*/)
|
if (img->bytes() /*>= simg->bytes*/)
|
||||||
{
|
{
|
||||||
img->set_image_status((SANE_Image_Statu)simg->flag.statu);
|
img->set_image_status((SANE_Image_Statu)simg->flag.statu);
|
||||||
|
|
|
@ -212,7 +212,7 @@ public:
|
||||||
COM_API_OVERRIDE(bool, wait_image(DWORD milliseconds = -1));
|
COM_API_OVERRIDE(bool, wait_image(DWORD milliseconds = -1));
|
||||||
COM_API_OVERRIDE(int, get_scanned_images(DWORD milliseconds = 0));
|
COM_API_OVERRIDE(int, get_scanned_images(DWORD milliseconds = 0));
|
||||||
COM_API_OVERRIDE(IScanImg*, take_first_image(twain_xfer xfer = TWAIN_XFER_Native)); // call 'release' on returned value, plz
|
COM_API_OVERRIDE(IScanImg*, take_first_image(twain_xfer xfer = TWAIN_XFER_Native)); // call 'release' on returned value, plz
|
||||||
COM_API_OVERRIDE(bool, get_first_image_header(SANE_Parameters* header, size_t* bytes = NULL));
|
COM_API_OVERRIDE(bool, get_first_image_header(SANE_Parameters* header, size_t* bytes = NULL, int* dpi = NULL));
|
||||||
COM_API_OVERRIDE(bool, is_online(void));
|
COM_API_OVERRIDE(bool, is_online(void));
|
||||||
COM_API_OVERRIDE(bool, is_paper_on(void));
|
COM_API_OVERRIDE(bool, is_paper_on(void));
|
||||||
COM_API_OVERRIDE(bool, get_option_info(int sn, value_type* type, value_limit* limit, int* bytes));
|
COM_API_OVERRIDE(bool, get_option_info(int sn, value_type* type, value_limit* limit, int* bytes));
|
||||||
|
|
|
@ -636,7 +636,7 @@ static const SCANNERID scanner_guid = MAKE_SCANNER_ID(PRODUCT_PID, PRODUCT_VID);
|
||||||
|
|
||||||
|
|
||||||
static std::once_flag oc;
|
static std::once_flag oc;
|
||||||
huagao_ds::huagao_ds() : cur_head_(NULL)
|
huagao_ds::huagao_ds() : cur_head_(NULL), dpi_(200)
|
||||||
{
|
{
|
||||||
//std::call_once(oc, [&]() { log4cplus::Initializer(); });
|
//std::call_once(oc, [&]() { log4cplus::Initializer(); });
|
||||||
}
|
}
|
||||||
|
@ -963,6 +963,7 @@ Result huagao_ds::imageInfoGet(const Identity&, ImageInfo& data)
|
||||||
{
|
{
|
||||||
SANE_Parameters head;
|
SANE_Parameters head;
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
|
int res = 200;
|
||||||
|
|
||||||
if (!scanner_.get())
|
if (!scanner_.get())
|
||||||
return seqError();
|
return seqError();
|
||||||
|
@ -971,6 +972,7 @@ Result huagao_ds::imageInfoGet(const Identity&, ImageInfo& data)
|
||||||
memcpy(&head, cur_head_, sizeof(head));
|
memcpy(&head, cur_head_, sizeof(head));
|
||||||
ok = true;
|
ok = true;
|
||||||
cur_head_->lines = 0;
|
cur_head_->lines = 0;
|
||||||
|
res = dpi_;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -979,7 +981,9 @@ Result huagao_ds::imageInfoGet(const Identity&, ImageInfo& data)
|
||||||
notifyCloseOk();
|
notifyCloseOk();
|
||||||
return success(); // ºÃ·ÖÊýÐèÒª·µ»Ø³É¹¦
|
return success(); // ºÃ·ÖÊýÐèÒª·µ»Ø³É¹¦
|
||||||
}
|
}
|
||||||
ok = scanner_->get_first_image_header(&head);
|
ok = scanner_->get_first_image_header(&head, NULL, &res);
|
||||||
|
if(ok)
|
||||||
|
dpi_ = res;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ok)
|
if (ok)
|
||||||
|
@ -1009,8 +1013,6 @@ Result huagao_ds::imageInfoGet(const Identity&, ImageInfo& data)
|
||||||
data.setPlanar(false);
|
data.setPlanar(false);
|
||||||
data.setWidth(head.pixels_per_line);
|
data.setWidth(head.pixels_per_line);
|
||||||
|
|
||||||
int res = 200;
|
|
||||||
GET_SANE_OPT(int, scanner_, resolution, &res, NULL, NULL, NULL);
|
|
||||||
data.setXResolution((float)res);
|
data.setXResolution((float)res);
|
||||||
data.setYResolution((float)res);
|
data.setYResolution((float)res);
|
||||||
data.compression(m_compression);
|
data.compression(m_compression);
|
||||||
|
@ -1026,9 +1028,8 @@ Result huagao_ds::imageLayoutGet(const Identity&, ImageLayout& data)
|
||||||
return seqError();
|
return seqError();
|
||||||
|
|
||||||
int res = 200;
|
int res = 200;
|
||||||
GET_SANE_OPT(int, scanner_, resolution, &res, NULL, NULL, NULL);
|
|
||||||
|
|
||||||
scanner_->get_first_image_header(&head);
|
scanner_->get_first_image_header(&head, NULL, &res);
|
||||||
data.setDocumentNumber(1);
|
data.setDocumentNumber(1);
|
||||||
data.setFrameNumber(1);
|
data.setFrameNumber(1);
|
||||||
data.setPageNumber(1);
|
data.setPageNumber(1);
|
||||||
|
@ -1667,8 +1668,8 @@ void huagao_ds::init_support_caps(void)
|
||||||
float init = 10.0f;
|
float init = 10.0f;
|
||||||
int cur = 200;
|
int cur = 200;
|
||||||
SANE_Parameters param = { 0 };
|
SANE_Parameters param = { 0 };
|
||||||
GET_SANE_OPT(int, scanner_, resolution, &cur, NULL, NULL, NULL);
|
// GET_SANE_OPT(int, scanner_, resolution, &cur, NULL, NULL, NULL);
|
||||||
if (scanner_.get() && scanner_->get_first_image_header(¶m))
|
if (scanner_.get() && scanner_->get_first_image_header(¶m, NULL, &cur))
|
||||||
init = param.bytes_per_line * 1.0f / cur;
|
init = param.bytes_per_line * 1.0f / cur;
|
||||||
data = Capability::createOneValue<Fix32>(data.type(), Fix32(init));
|
data = Capability::createOneValue<Fix32>(data.type(), Fix32(init));
|
||||||
return success();
|
return success();
|
||||||
|
@ -1689,8 +1690,8 @@ void huagao_ds::init_support_caps(void)
|
||||||
float init = 10.0f;
|
float init = 10.0f;
|
||||||
int cur = 200;
|
int cur = 200;
|
||||||
SANE_Parameters param = { 0 };
|
SANE_Parameters param = { 0 };
|
||||||
GET_SANE_OPT(int, scanner_, resolution, &cur, NULL, NULL, NULL);
|
// GET_SANE_OPT(int, scanner_, resolution, &cur, NULL, NULL, NULL);
|
||||||
if (scanner_.get() && scanner_->get_first_image_header(¶m))
|
if (scanner_.get() && scanner_->get_first_image_header(¶m, NULL, &cur))
|
||||||
init = param.lines * 1.0f / cur;
|
init = param.lines * 1.0f / cur;
|
||||||
data = Capability::createOneValue<Fix32>(data.type(), Fix32(init));
|
data = Capability::createOneValue<Fix32>(data.type(), Fix32(init));
|
||||||
return success();
|
return success();
|
||||||
|
|
|
@ -41,6 +41,7 @@ class huagao_ds : public Twpp::SourceFromThis<huagao_ds> {
|
||||||
int m_jpegQuality = 80;
|
int m_jpegQuality = 80;
|
||||||
Twpp::Compression m_compression = Twpp::Compression::None;
|
Twpp::Compression m_compression = Twpp::Compression::None;
|
||||||
SANE_Parameters* cur_head_;
|
SANE_Parameters* cur_head_;
|
||||||
|
int dpi_;
|
||||||
|
|
||||||
static std::string get_hidedlg_path(void);
|
static std::string get_hidedlg_path(void);
|
||||||
static void showmsg(const char* msg, int err);
|
static void showmsg(const char* msg, int err);
|
||||||
|
|
Loading…
Reference in New Issue