diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-11-20 09:32:32 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-11-20 10:58:51 +0100 |
commit | 6d528515c5ed809da7ecfe27d105cfb173c9f768 (patch) | |
tree | d503bfa817fc9ad615f4437f9fb69d92b9dfaf13 /extensions/source | |
parent | 867abf5b8eff8733dd7ad020d16724ed8eda3885 (diff) |
Don't loose scanned image's resolution precision
Change-Id: I526dcf8db880615308cfb228eaa06d1a5a0e5cac
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125584
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'extensions/source')
-rw-r--r-- | extensions/source/scanner/twain32shim.cxx | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/extensions/source/scanner/twain32shim.cxx b/extensions/source/scanner/twain32shim.cxx index ab99ab332572..beca35f4f26b 100644 --- a/extensions/source/scanner/twain32shim.cxx +++ b/extensions/source/scanner/twain32shim.cxx @@ -36,10 +36,7 @@ namespace { -TW_INT32 FixToInt32(const TW_FIX32& rFix) -{ - return static_cast<TW_INT32>(floor(rFix.Whole + rFix.Frac / 65536. + 0.5)); -} +double FixToDouble(const TW_FIX32& rFix) { return rFix.Whole + rFix.Frac / 65536.; } const wchar_t sTwainWndClass[] = L"TwainClass"; @@ -383,12 +380,12 @@ void ImpTwain::ImplXfer() { TW_IMAGEINFO aInfo; HANDLE hDIB = nullptr; - TW_INT32 nXRes, nYRes; + double nXRes, nYRes; if (m_pDSM(&m_aAppId, &m_aSrcId, DG_IMAGE, DAT_IMAGEINFO, MSG_GET, &aInfo) == TWRC_SUCCESS) { - nXRes = FixToInt32(aInfo.XResolution); - nYRes = FixToInt32(aInfo.YResolution); + nXRes = FixToDouble(aInfo.XResolution); + nYRes = FixToDouble(aInfo.YResolution); } else nXRes = nYRes = -1; @@ -411,15 +408,15 @@ void ImpTwain::ImplXfer() { if (LPVOID pBmpMem = GlobalLock(hGlob)) { - if ((nXRes != -1) && (nYRes != -1)) + if ((nXRes > 0) && (nYRes > 0)) { // set resolution of bitmap BITMAPINFOHEADER* pBIH = static_cast<BITMAPINFOHEADER*>(pBmpMem); - static const auto[m, d] + const auto[m, d] = getConversionMulDiv(o3tl::Length::in, o3tl::Length::m); - pBIH->biXPelsPerMeter = o3tl::convert(nXRes, d, m); - pBIH->biYPelsPerMeter = o3tl::convert(nYRes, d, m); + pBIH->biXPelsPerMeter = std::round(o3tl::convert(nXRes, d, m)); + pBIH->biYPelsPerMeter = std::round(o3tl::convert(nYRes, d, m)); } HANDLE hMap = CreateFileMappingW(INVALID_HANDLE_VALUE, nullptr, |