fix BUG-891(TWAIN驱动中,采用的回调机制回传图像,此处改动不影响TWAIN)

This commit is contained in:
gb 2024-01-30 17:26:12 +08:00
parent 784428566a
commit 1db67753b5
1 changed files with 12 additions and 8 deletions

View File

@ -4267,7 +4267,7 @@ int hg_scanner::start(void)
}
int hg_scanner::get_image_info(SANE_Parameters* ii, int len)
{
int ret = SCANNER_ERR_OK;
int ret = SCANNER_ERR_OK, channels = 3;
IMH imh;
SANE_Image* iiex = len == sizeof(SANE_Image) ? (SANE_Image*)ii : nullptr;
@ -4280,8 +4280,13 @@ int hg_scanner::get_image_info(SANE_Parameters* ii, int len)
while ((!wait_img_.is_waiting() || !wait_usb_.is_waiting()) && final_imgs_.size() <= 0)
this_thread::sleep_for(chrono::milliseconds(10));
if (final_imgs_.size() <= 0)
if (final_imgs_.size() <= 0
|| user_cancel_) // for BUG-891 !!!
{
ret = SCANNER_ERR_NO_DATA;
if(user_cancel_ && final_imgs_.size())
VLOG_MINI_1(LOG_LEVEL_DEBUG_INFO, "Get image info after user cancelled scanning and %u image(s) left in queue, we discard the images and return current parameter.\n", final_imgs_.size());
}
else
{
if (!final_imgs_.front(&imh))
@ -4289,6 +4294,7 @@ int hg_scanner::get_image_info(SANE_Parameters* ii, int len)
else
{
copy_to_sane_image_header(ii, imh.width, imh.height, imh.line_bytes, imh.channels, imh.bits);
channels = imh.channels;
fetching_id_ = imh.src_id;
if (iiex)
{
@ -4315,15 +4321,13 @@ int hg_scanner::get_image_info(SANE_Parameters* ii, int len)
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;
if (ii->format != SANE_FRAME_RGB)
channels = 1;
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;
ii->bytes_per_line = ii->pixels_per_line * channels;
if (iiex)
{
@ -4335,7 +4339,7 @@ int hg_scanner::get_image_info(SANE_Parameters* ii, int len)
ret = SCANNER_ERR_OK;
}
}
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_err_name(ret));
VLOG_MINI_4(LOG_LEVEL_DEBUG_INFO, "Get image info(%d * %d * %d) = %s\n", ii->pixels_per_line, ii->lines, ii->depth * channels, hg_scanner_err_name(ret));
return ret;
}