修复保存BMP图片文件BUG;打开设备后获取配置失败,则等待最多100ms

This commit is contained in:
gb 2024-01-24 17:55:26 +08:00
parent d514c6dc1e
commit 5dd444b458
3 changed files with 28 additions and 2 deletions

View File

@ -190,6 +190,17 @@ void hg_scanner::init(void)
for (auto& v : device_opt_json)
pc += v;
ret = scanner_->option_get_all(opts);
if (ret != SCANNER_ERR_OK)
{
int times = 0, err = ret;
do
{
std::this_thread::sleep_for(std::chrono::milliseconds(5));
ret = scanner_->option_get_all(opts);
} while (ret != SCANNER_ERR_OK && times++ < 20);
utils::to_log(LOG_LEVEL_WARNING, "Failed to get options from device with err %d. wait %d times(%ums) and result = %d\n"
, err, times, times * 5, ret);
}
if (ret == SCANNER_ERR_OK)
{
// merge two JSON texts ...

View File

@ -69,7 +69,7 @@ class scanner_handler : public refer
{
MUTEX lock_reply_;
std::vector<cmd_result*> reply_;
async_usb_host* usb_;
async_usb_host* usb_;
volatile uint32_t status_;
std::function<void(uint32_t)> status_notify_;

View File

@ -163,7 +163,21 @@ int image_holder::save_2_file(const char* root_dir, const char* alg)
{
fwrite(bfh.c_str(), 1, bfh.length(), dst);
fwrite(bih.c_str(), 1, bih.length(), dst);
fwrite(data() + head_.info_size, 1, head_.data_size, dst);
if(head_.data_size == ((LPBITMAPINFOHEADER)&bih[0])->biSizeImage)
fwrite(data() + head_.info_size, 1, head_.data_size, dst);
else
{
int l = BMP_LINE_BYTES(head_.width * head_.bpp * head_.channels),
dif = l - (head_.width * head_.bpp * head_.channels + 7) / 8;
char pad[4] = { 0 };
uint8_t *ptr = data() + head_.info_size;
for (int i = 0; i < head_.height; ++i)
{
fwrite(ptr, 1, l - dif, dst);
fwrite(pad, 1, dif, dst);
ptr += l - dif;
}
}
}
}
@ -385,6 +399,7 @@ dyn_mem::dyn_mem(void* buf, size_t size)
dyn_mem::~dyn_mem()
{
notify_progress(space_, len_, 0);
if (buf_)
{
free(buf_);