extensions/source/scanner/twain32shim.cxx |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

New commits:
commit aadb472a6d37d57279f91038f28047af4278bbbc
Author:     Hossein <[email protected]>
AuthorDate: Fri Nov 19 22:39:10 2021 +0100
Commit:     Mike Kaganski <[email protected]>
CommitDate: Sat Nov 20 07:13:14 2021 +0100

    Use o3tl::convert
    
    Used o3tl::convert on nXRes and nYRes to calculate biXPelsPerMeter
    and biYPelsPerMeter for the bitmap information header structure pBIH:
    
https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapinfoheader
    
    The values of biXPelsPerMeter and biYPelsPerMeter are always ignored
    by the GDI when loading the bitmaps, but in theory they can be
    recommendations for the pysical size of a bitmap in some applications.
    https://devblogs.microsoft.com/oldnewthing/20130515-00/?p=4363
    
    Change-Id: Ia40f17b7d1c27c094158af89bf15ed2f11bdfc05
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125109
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/extensions/source/scanner/twain32shim.cxx 
b/extensions/source/scanner/twain32shim.cxx
index eab704fcb8db..254ed747281d 100644
--- a/extensions/source/scanner/twain32shim.cxx
+++ b/extensions/source/scanner/twain32shim.cxx
@@ -30,6 +30,7 @@
 #include "twain32shim.hxx"
 #include <tools/helpers.hxx>
 #include <twain/twain.h>
+#include <o3tl/unit_conversion.hxx>
 
 #define WM_TWAIN_FALLBACK (WM_SHIM_INTERNAL + 0)
 
@@ -416,10 +417,11 @@ void ImpTwain::ImplXfer()
                             {
                                 // set resolution of bitmap
                                 BITMAPINFOHEADER* pBIH = 
static_cast<BITMAPINFOHEADER*>(pBmpMem);
-                                static const double fFactor = 100.0 / 2.54;
 
-                                pBIH->biXPelsPerMeter = FRound(fFactor * 
nXRes);
-                                pBIH->biYPelsPerMeter = FRound(fFactor * 
nYRes);
+                                static 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);
                             }
 
                             HANDLE hMap = 
CreateFileMappingW(INVALID_HANDLE_VALUE, nullptr,

Reply via email to