From 6fc622d55e106e973525462432ce178afd83b02e Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Fri, 4 Aug 2023 13:03:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DpendingXfer=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=EF=BC=9B=E5=9C=A8pendingXfer-EndXfer=E5=8D=8F=E8=AE=AE?= =?UTF-8?q?=E4=B8=AD=E6=8A=9B=E5=BC=83=E9=A6=96=E5=BC=A0=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sane/s2t_api.h | 1 + sane/scanner.cpp | 18 ++++++++++++++++-- sane/scanner.h | 1 + twain/load_sane.cpp | 2 +- twain/twain/huagaods.cpp | 28 ++++++++++++++++++++++++++-- 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/sane/s2t_api.h b/sane/s2t_api.h index 921ef6d..5c2d756 100644 --- a/sane/s2t_api.h +++ b/sane/s2t_api.h @@ -161,6 +161,7 @@ struct __declspec(novtable) ISaneInvoker : public IRef 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, int *dpi = NULL)); + COM_API_DECLARE(bool, discard_first_image(void)); COM_API_DECLARE(bool, is_online(void)); COM_API_DECLARE(bool, is_paper_on(void)); COM_API_DECLARE(int, last_error(void)); diff --git a/sane/scanner.cpp b/sane/scanner.cpp index 4b95b5e..a099a55 100644 --- a/sane/scanner.cpp +++ b/sane/scanner.cpp @@ -2670,11 +2670,12 @@ COM_API_IMPLEMENT(scanner, int, get_scanned_images(DWORD milliseconds)) } COM_API_IMPLEMENT(scanner, IScanImg*, take_first_image(twain_xfer xfer)) { - scanned_img* img = images_.take(); + scanned_img* img = images_.take(false); if (img) { - //img->prepare_data_for_transfer(xfer); + img->prepare_data_for_transfer(xfer); + img->add_ref(); wchar_t msg[128] = { 0 }; swprintf_s(msg, _countof(msg) - 1, L"Begin transferring image %d of %p\r\n", fetch_imgs_ + 1, img); @@ -2687,6 +2688,19 @@ COM_API_IMPLEMENT(scanner, bool, get_first_image_header(SANE_Parameters* header, { return images_.get_header(header, bytes, dpi); } +COM_API_IMPLEMENT(scanner, bool, discard_first_image(void)) +{ + scanned_img* img = images_.take(); + if (img) + { + img->release(); + return true; + } + else + { + return false; + } +} COM_API_IMPLEMENT(scanner, bool, is_online(void)) { std::string sn(""); diff --git a/sane/scanner.h b/sane/scanner.h index b33f2a6..982ff43 100644 --- a/sane/scanner.h +++ b/sane/scanner.h @@ -218,6 +218,7 @@ public: 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, int* dpi = NULL)); + COM_API_OVERRIDE(bool, discard_first_image(void)); // call 'release' on returned value, plz COM_API_OVERRIDE(bool, is_online(void)); COM_API_OVERRIDE(bool, is_paper_on(void)); COM_API_OVERRIDE(int, last_error(void)); diff --git a/twain/load_sane.cpp b/twain/load_sane.cpp index 36deebf..a82595a 100644 --- a/twain/load_sane.cpp +++ b/twain/load_sane.cpp @@ -114,7 +114,7 @@ namespace load_sane_util 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 || ret == ERROR_BAD_EXE_FORMAT)) + if (!h && (ret == ERROR_MOD_NOT_FOUND || ret == ERROR_BAD_EXE_FORMAT || ret == 0)) { std::wstring dir(path_dll); size_t pos = dir.rfind(L'\\'); diff --git a/twain/twain/huagaods.cpp b/twain/twain/huagaods.cpp index 61f1f32..131c448 100644 --- a/twain/twain/huagaods.cpp +++ b/twain/twain/huagaods.cpp @@ -776,11 +776,18 @@ static bool __stdcall got_fixed_id(uint32_t id, void* param) // huagao_ds ... #include "../../../sdk/include/huagao/brand.h" +/* static Identity* srcIdent = new Identity( Version(VERSION_MAIN, VERSION_SUB, Language::English, Country::China, VERSION_STR(VERSION_MAIN, VERSION_SUB, VERSION_BUILD1, VERSION_PATCH)), DataGroup::Image, PRODUCT_VENDOR, PRODUCT_FAMILY, PRODUCT_NAME); -static const SCANNERID scanner_guid = MAKE_SCANNER_ID(PRODUCT_PID, PRODUCT_VID); +/*/ +static Identity myIdent( + Version(VERSION_MAIN, VERSION_SUB, Language::English, Country::China, VERSION_STR(VERSION_MAIN, VERSION_SUB, VERSION_BUILD1, VERSION_PATCH)), + DataGroup::Image, PRODUCT_VENDOR, PRODUCT_FAMILY, PRODUCT_NAME); +static Identity* srcIdent = &myIdent; +///////////*//////////////////////////////////// +static const SCANNERID scanner_guid = MAKE_SCANNER_ID(PRODUCT_PID, PRODUCT_VID); static std::once_flag oc; huagao_ds::huagao_ds() : cur_head_(NULL), dpi_(200), xfer_ready_failed_(false), log_all_triple_(false), scanner_status_(SCANNER_STATUS_NOT_INIT) @@ -1088,13 +1095,28 @@ Result huagao_ds::pendingXfersGet(const Identity&, PendingXfers& data) } Result huagao_ds::pendingXfersEnd(const Identity& id, PendingXfers& data) { + // complete transferring of current image ... + pending_xfer_.clear(); + if (scanner_.get()) + { + scanner_->discard_first_image(); + } + return pendingXfersGet(id, data); } Result huagao_ds::pendingXfersReset(const Identity& id, PendingXfers& data) { pending_xfer_.clear(); + if (scanner_.get()) + { + scanner_->stop(); + while (scanner_->discard_first_image()); + } + data.setCount(0); - return pendingXfersGet(id, data); + return success(); + + //return pendingXfersGet(id, data); } Result huagao_ds::setupMemXferGet(const Identity& id, SetupMemXfer& data) { @@ -1369,6 +1391,8 @@ Result huagao_ds::imageMemXferGet(const Identity& origin, ImageMemXfer& data) if (rows == 0) return badValue(); + else if (rows > img->height()) + rows = img->height(); if (pending_xfer_.img) {