From aadb472a6d37d57279f91038f28047af4278bbbc Mon Sep 17 00:00:00 2001 From: Hossein Date: Fri, 19 Nov 2021 22:39:10 +0100 Subject: 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 --- extensions/source/scanner/twain32shim.cxx | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'extensions') 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 #include +#include #define WM_TWAIN_FALLBACK (WM_SHIM_INTERNAL + 0) @@ -416,10 +417,11 @@ void ImpTwain::ImplXfer() { // set resolution of bitmap BITMAPINFOHEADER* pBIH = static_cast(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, -- cgit