完善Native/file传输
This commit is contained in:
parent
e579975168
commit
1581c452ca
|
@ -115,6 +115,12 @@ enum multiout_value
|
|||
MULTI_OUT_COLOR_BW,
|
||||
MULTI_OUT_GRAY_BW,
|
||||
};
|
||||
enum twain_xfer
|
||||
{
|
||||
TWAIN_XFER_Native = 0, // BITMAPINFOHEADER + bits
|
||||
TWAIN_XFER_File = 1, // BITMAPFILEHEADER + TWAIN_XFER_Native
|
||||
TWAIN_XFER_Memory = 2, // to be implementing ...
|
||||
};
|
||||
|
||||
typedef bool(__stdcall* set_opt_value)(void* val, value_role role, void* param); // return false to stop the callback
|
||||
__declspec(novtable) struct IRef
|
||||
|
@ -143,7 +149,7 @@ __declspec(novtable) struct ISaneInvoker : public IRef
|
|||
COM_API_DECLARE(void, set_event_callback(void(*cb)(int ev_type, void* data, unsigned int* len, void* param), void* param));
|
||||
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(void)); // 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));
|
||||
COM_API_DECLARE(bool, is_online(void));
|
||||
COM_API_DECLARE(bool, is_paper_on(void));
|
||||
|
|
|
@ -304,10 +304,11 @@ unsigned int mapping_buf::mapped_bytes(void)
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// class scanned_img
|
||||
scanned_img::scanned_img(SANE_Parameters head, SANE_Handle dev, int dpi, const wchar_t* tmp_file) : head_(head), dpi_(dpi)
|
||||
scanned_img::scanned_img(SANE_Parameters head, SANE_Handle dev, int dpi
|
||||
, const wchar_t* tmp_file, twain_xfer xfer) : head_(head), dpi_(dpi)
|
||||
{
|
||||
size_t bytes = line_bytes() * height();
|
||||
std::string h(file_header(SANE_IMAGE_TYPE_BMP, dpi));
|
||||
std::string h(file_header(SANE_IMAGE_TYPE_BMP, dpi, xfer));
|
||||
unsigned char* dst = NULL;
|
||||
bool ok = false;
|
||||
|
||||
|
@ -400,7 +401,7 @@ scanned_img::~scanned_img()
|
|||
delete data_;
|
||||
}
|
||||
|
||||
std::string scanned_img::file_header(SANE_ImageType type, float resolution)
|
||||
std::string scanned_img::file_header(SANE_ImageType type, float resolution, twain_xfer xfer)
|
||||
{
|
||||
std::string h("");
|
||||
|
||||
|
@ -417,7 +418,17 @@ std::string scanned_img::file_header(SANE_ImageType type, float resolution)
|
|||
bih.biCompression = BI_RGB;
|
||||
bih.biXPelsPerMeter = bih.biYPelsPerMeter = resolution * 39.37f + .5f;
|
||||
|
||||
h = std::string((char*)&bih, sizeof(bih));
|
||||
if (xfer == TWAIN_XFER_File)
|
||||
{
|
||||
BITMAPFILEHEADER fh = { 0 };
|
||||
fh.bfType = MAKEWORD('B', 'M');
|
||||
fh.bfSize = sizeof(fh) + bih.biSizeImage + sizeof(bih);
|
||||
fh.bfOffBits = sizeof(fh) + sizeof(bih);
|
||||
|
||||
h = std::string((char*)&fh, sizeof(fh));
|
||||
}
|
||||
|
||||
h += std::string((char*)&bih, sizeof(bih));
|
||||
}
|
||||
|
||||
return h;
|
||||
|
|
|
@ -55,10 +55,11 @@ class scanned_img : public IScanImg, virtual public refer
|
|||
mapping_buf* data_;
|
||||
int dpi_;
|
||||
|
||||
std::string file_header(SANE_ImageType type, float resolution);
|
||||
std::string file_header(SANE_ImageType type, float resolution, twain_xfer xfer);
|
||||
|
||||
public:
|
||||
scanned_img(SANE_Parameters head, SANE_Handle dev, int dpi, const wchar_t* tmp_file);
|
||||
scanned_img(SANE_Parameters head, SANE_Handle dev, int dpi, const wchar_t* tmp_file
|
||||
, twain_xfer xfer = TWAIN_XFER_Native);
|
||||
|
||||
|
||||
protected:
|
||||
|
|
|
@ -1409,7 +1409,7 @@ COM_API_IMPLEMENT(scanner, int, get_scanned_images(DWORD milliseconds))
|
|||
|
||||
return count;
|
||||
}
|
||||
COM_API_IMPLEMENT(scanner, IScanImg*, take_first_image(void))
|
||||
COM_API_IMPLEMENT(scanner, IScanImg*, take_first_image(twain_xfer xfer))
|
||||
{
|
||||
scanned_img* img = NULL;
|
||||
SANE_Parameters head;
|
||||
|
@ -1418,7 +1418,7 @@ COM_API_IMPLEMENT(scanner, IScanImg*, take_first_image(void))
|
|||
{
|
||||
wchar_t name[40] = { 0 };
|
||||
swprintf_s(name, _countof(name) - 1, L"img_%05u.bmp", ++img_ind_);
|
||||
img = new scanned_img(head, handle_, dpi_, (tmp_path_ + name).c_str());
|
||||
img = new scanned_img(head, handle_, dpi_, (tmp_path_ + name).c_str(), xfer);
|
||||
}
|
||||
|
||||
return dynamic_cast<IScanImg*>(img);
|
||||
|
|
|
@ -172,7 +172,7 @@ public:
|
|||
COM_API_OVERRIDE(void, set_event_callback(void(*cb)(int ev_type, void* data, unsigned int* len, void* param), void* param));
|
||||
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(void)); // 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));
|
||||
COM_API_OVERRIDE(bool, is_online(void));
|
||||
COM_API_OVERRIDE(bool, is_paper_on(void));
|
||||
|
|
|
@ -803,9 +803,9 @@ Result huagao_ds::pendingXfersEnd(const Identity& id, PendingXfers& data)
|
|||
}
|
||||
Result huagao_ds::pendingXfersReset(const Identity&, PendingXfers& data)
|
||||
{
|
||||
data.setCount(0);
|
||||
if (scanner_.get())
|
||||
scanner_->stop();
|
||||
data.setCount(scanner_->get_scanned_images(-1));
|
||||
//if (scanner_.get())
|
||||
// scanner_->stop();
|
||||
|
||||
//if (scanner.get())
|
||||
//{
|
||||
|
@ -825,9 +825,10 @@ Result huagao_ds::setupMemXferGet(const Identity&, SetupMemXfer& data)
|
|||
|
||||
if (scanner_->get_first_image_header(&head))
|
||||
{
|
||||
int line_bytes = (head.bytes_per_line + 3) / 4 * 4;
|
||||
data.setMinSize(head.bytes_per_line);
|
||||
data.setPreferredSize(head.bytes_per_line * head.lines);
|
||||
data.setMaxSize(head.bytes_per_line * head.lines);
|
||||
data.setPreferredSize(line_bytes * head.lines);
|
||||
data.setMaxSize(line_bytes * head.lines);
|
||||
|
||||
return success();
|
||||
}
|
||||
|
@ -925,7 +926,7 @@ Result huagao_ds::imageMemXferGet(const Identity& origin, ImageMemXfer& data)
|
|||
if (!scanner_.get() || scanner_->get_scanned_images() == 0)
|
||||
return seqError();
|
||||
|
||||
IScanImg *img = scanner_->take_first_image();
|
||||
IScanImg *img = scanner_->take_first_image(TWAIN_XFER_Memory);
|
||||
unsigned long long off = 0;
|
||||
unsigned int total = img->bytes();
|
||||
unsigned char *src = img->data(off, &total),
|
||||
|
@ -958,7 +959,7 @@ Result huagao_ds::imageNativeXferGet(const Identity& id, ImageNativeXfer& data)
|
|||
if (!scanner_.get() || scanner_->get_scanned_images() == 0)
|
||||
return seqError();
|
||||
|
||||
IScanImg* img = scanner_->take_first_image();
|
||||
IScanImg* img = scanner_->take_first_image(TWAIN_XFER_Native);
|
||||
|
||||
if (!img)
|
||||
return seqError();
|
||||
|
@ -996,7 +997,7 @@ Twpp::Result huagao_ds::imageFileXferGet(const Twpp::Identity& origin)
|
|||
if (!scanner_.get() || scanner_->get_scanned_images() == 0)
|
||||
return seqError();
|
||||
|
||||
IScanImg *img = scanner_->take_first_image();
|
||||
IScanImg *img = scanner_->take_first_image(TWAIN_XFER_File);
|
||||
Twpp::Result ret = seqError();
|
||||
FILE* dst = NULL;
|
||||
|
||||
|
@ -1614,7 +1615,7 @@ void huagao_ds::init_support_caps(void)
|
|||
i = std::distance(vals.begin(), std::find(vals.begin(), vals.end(), Init));
|
||||
n = std::distance(vals.begin(), std::find(vals.begin(), vals.end(), Now));
|
||||
|
||||
return cap_get_enum_values<ImageFileFormat, CapType::IRotation>(msg, data, vals, Now, Init, n, i);
|
||||
return cap_get_enum_values<ImageFileFormat, CapType::IImageFileFormat>(msg, data, vals, Now, Init, n, i);
|
||||
};
|
||||
|
||||
m_query[CapType::IAutomaticDeskew] = msgSupportGetAllSetReset;
|
||||
|
|
Loading…
Reference in New Issue