diff --git a/sane/s2t_api.h b/sane/s2t_api.h index 977078f..a322f46 100644 --- a/sane/s2t_api.h +++ b/sane/s2t_api.h @@ -135,6 +135,7 @@ struct __declspec(novtable) IScanImg : public IRef COM_API_DECLARE(int, height(void)); COM_API_DECLARE(int, depth(void)); COM_API_DECLARE(int, channel(void)); + COM_API_DECLARE(int, dpi(void)); COM_API_DECLARE(SANE_Frame, type(void)); COM_API_DECLARE(unsigned int, bytes(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(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(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_paper_on(void)); diff --git a/sane/scanned_img.cpp b/sane/scanned_img.cpp index 04c20b1..a186f1c 100644 --- a/sane/scanned_img.cpp +++ b/sane/scanned_img.cpp @@ -679,6 +679,10 @@ COM_API_IMPLEMENT(scanned_img, int, channel(void)) { 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)) { return head_.format; @@ -747,7 +751,7 @@ void __stdcall safe_img_queue::free_image(scanned_img* img) 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); bool ok = false; @@ -760,6 +764,8 @@ bool safe_img_queue::get_header(SANE_Parameters* header, size_t* bytes) img->copy_header(header); if(bytes) *bytes = img->bytes(); + if (dpi) + *dpi = img->dpi(); ok = true; img->release(); } diff --git a/sane/scanned_img.h b/sane/scanned_img.h index 3ae1905..b3f2a39 100644 --- a/sane/scanned_img.h +++ b/sane/scanned_img.h @@ -91,6 +91,7 @@ public: COM_API_OVERRIDE(int, height(void)); COM_API_OVERRIDE(int, depth(void)); COM_API_OVERRIDE(int, channel(void)); + COM_API_OVERRIDE(int, dpi(void)); COM_API_OVERRIDE(SANE_Frame, type(void)); COM_API_OVERRIDE(unsigned int, bytes(void)); COM_API_OVERRIDE(unsigned int, header_size(void)); @@ -168,7 +169,7 @@ public: ~safe_img_queue(); 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(); }; diff --git a/sane/scanner.cpp b/sane/scanner.cpp index ae20501..4f6f98c 100644 --- a/sane/scanner.cpp +++ b/sane/scanner.cpp @@ -2273,9 +2273,9 @@ COM_API_IMPLEMENT(scanner, IScanImg*, take_first_image(twain_xfer xfer)) return dynamic_cast(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)) { @@ -2724,7 +2724,7 @@ int scanner::handle_device_event(int ev_code, void* data, unsigned int* len) wchar_t name[40] = { 0 }; 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*/) { img->set_image_status((SANE_Image_Statu)simg->flag.statu); diff --git a/sane/scanner.h b/sane/scanner.h index 999551e..292f567 100644 --- a/sane/scanner.h +++ b/sane/scanner.h @@ -212,7 +212,7 @@ public: COM_API_OVERRIDE(bool, wait_image(DWORD milliseconds = -1)); 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(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_paper_on(void)); COM_API_OVERRIDE(bool, get_option_info(int sn, value_type* type, value_limit* limit, int* bytes)); diff --git a/twain/twain/huagaods.cpp b/twain/twain/huagaods.cpp index 133a280..c476cb4 100644 --- a/twain/twain/huagaods.cpp +++ b/twain/twain/huagaods.cpp @@ -636,7 +636,7 @@ static const SCANNERID scanner_guid = MAKE_SCANNER_ID(PRODUCT_PID, PRODUCT_VID); 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(); }); } @@ -963,6 +963,7 @@ Result huagao_ds::imageInfoGet(const Identity&, ImageInfo& data) { SANE_Parameters head; bool ok = false; + int res = 200; if (!scanner_.get()) return seqError(); @@ -971,6 +972,7 @@ Result huagao_ds::imageInfoGet(const Identity&, ImageInfo& data) memcpy(&head, cur_head_, sizeof(head)); ok = true; cur_head_->lines = 0; + res = dpi_; } else { @@ -979,7 +981,9 @@ Result huagao_ds::imageInfoGet(const Identity&, ImageInfo& data) notifyCloseOk(); return success(); // 好分数需要返回成功 } - ok = scanner_->get_first_image_header(&head); + ok = scanner_->get_first_image_header(&head, NULL, &res); + if(ok) + dpi_ = res; } if (ok) @@ -1009,8 +1013,6 @@ Result huagao_ds::imageInfoGet(const Identity&, ImageInfo& data) data.setPlanar(false); data.setWidth(head.pixels_per_line); - int res = 200; - GET_SANE_OPT(int, scanner_, resolution, &res, NULL, NULL, NULL); data.setXResolution((float)res); data.setYResolution((float)res); data.compression(m_compression); @@ -1026,9 +1028,8 @@ Result huagao_ds::imageLayoutGet(const Identity&, ImageLayout& data) return seqError(); 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.setFrameNumber(1); data.setPageNumber(1); @@ -1667,8 +1668,8 @@ void huagao_ds::init_support_caps(void) float init = 10.0f; int cur = 200; SANE_Parameters param = { 0 }; - GET_SANE_OPT(int, scanner_, resolution, &cur, NULL, NULL, NULL); - if (scanner_.get() && scanner_->get_first_image_header(¶m)) + // GET_SANE_OPT(int, scanner_, resolution, &cur, NULL, NULL, NULL); + if (scanner_.get() && scanner_->get_first_image_header(¶m, NULL, &cur)) init = param.bytes_per_line * 1.0f / cur; data = Capability::createOneValue(data.type(), Fix32(init)); return success(); @@ -1689,8 +1690,8 @@ void huagao_ds::init_support_caps(void) float init = 10.0f; int cur = 200; SANE_Parameters param = { 0 }; - GET_SANE_OPT(int, scanner_, resolution, &cur, NULL, NULL, NULL); - if (scanner_.get() && scanner_->get_first_image_header(¶m)) + // GET_SANE_OPT(int, scanner_, resolution, &cur, NULL, NULL, NULL); + if (scanner_.get() && scanner_->get_first_image_header(¶m, NULL, &cur)) init = param.lines * 1.0f / cur; data = Capability::createOneValue(data.type(), Fix32(init)); return success(); diff --git a/twain/twain/huagaods.hpp b/twain/twain/huagaods.hpp index 3e245de..e6156b0 100644 --- a/twain/twain/huagaods.hpp +++ b/twain/twain/huagaods.hpp @@ -41,6 +41,7 @@ class huagao_ds : public Twpp::SourceFromThis { int m_jpegQuality = 80; Twpp::Compression m_compression = Twpp::Compression::None; SANE_Parameters* cur_head_; + int dpi_; static std::string get_hidedlg_path(void); static void showmsg(const char* msg, int err);