nss: upgrade to release 3.73
[LibreOffice.git] / vcl / source / bitmap / BitmapFastScaleFilter.cxx
blob7c8b63a0f72908366e477047c23e8bc90312533b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/helpers.hxx>
22 #include <vcl/bitmapex.hxx>
23 #include <vcl/bitmapaccess.hxx>
25 #include <bitmapwriteaccess.hxx>
26 #include <BitmapFastScaleFilter.hxx>
27 #include <sal/log.hxx>
29 BitmapEx BitmapFastScaleFilter::execute(BitmapEx const& rBitmapEx) const
31 SAL_INFO("vcl.gdi", "BitmapFastScaleFilter::execute()");
33 Bitmap aBitmap(rBitmapEx.GetBitmap());
35 const Size aSizePix(aBitmap.GetSizePixel());
36 const tools::Long nNewWidth = FRound(aSizePix.Width() * mfScaleX);
37 const tools::Long nNewHeight = FRound(aSizePix.Height() * mfScaleY);
38 bool bRet = false;
40 SAL_INFO("vcl.gdi", "New width: " << nNewWidth << "\nNew height: " << nNewHeight);
42 if (nNewWidth && nNewHeight)
44 Bitmap::ScopedReadAccess pReadAcc(aBitmap);
46 if (pReadAcc)
48 Bitmap aNewBmp(Size(nNewWidth, nNewHeight), aBitmap.GetBitCount(),
49 &pReadAcc->GetPalette());
50 BitmapScopedWriteAccess pWriteAcc(aNewBmp);
52 if (pWriteAcc)
54 const tools::Long nScanlineSize = pWriteAcc->GetScanlineSize();
55 const tools::Long nNewHeight1 = nNewHeight - 1;
57 if (nNewWidth && nNewHeight)
59 const double nWidth = pReadAcc->Width();
60 const double nHeight = pReadAcc->Height();
61 std::unique_ptr<tools::Long[]> pLutX(new tools::Long[nNewWidth]);
62 std::unique_ptr<tools::Long[]> pLutY(new tools::Long[nNewHeight]);
64 for (tools::Long nX = 0; nX < nNewWidth; nX++)
66 pLutX[nX] = tools::Long(nX * nWidth / nNewWidth);
69 for (tools::Long nY = 0; nY < nNewHeight; nY++)
71 pLutY[nY] = tools::Long(nY * nHeight / nNewHeight);
74 tools::Long nActY = 0;
75 while (nActY < nNewHeight)
77 tools::Long nMapY = pLutY[nActY];
78 Scanline pScanline = pWriteAcc->GetScanline(nActY);
79 Scanline pScanlineRead = pReadAcc->GetScanline(nMapY);
81 for (tools::Long nX = 0; nX < nNewWidth; nX++)
83 pWriteAcc->SetPixelOnData(
84 pScanline, nX,
85 pReadAcc->GetPixelFromData(pScanlineRead, pLutX[nX]));
88 while ((nActY < nNewHeight1) && (pLutY[nActY + 1] == nMapY))
90 memcpy(pWriteAcc->GetScanline(nActY + 1), pWriteAcc->GetScanline(nActY),
91 nScanlineSize);
92 nActY++;
94 nActY++;
97 bRet = true;
100 pWriteAcc.reset();
102 pReadAcc.reset();
104 if (bRet)
106 aBitmap.ReassignWithSize(aNewBmp);
107 SAL_INFO("vcl.gdi", "Bitmap size: " << aBitmap.GetSizePixel());
109 else
111 SAL_WARN("vcl.gdi", "no resize");
116 Bitmap aMask(rBitmapEx.GetMask());
118 if (bRet && (rBitmapEx.GetTransparentType() == TransparentType::Bitmap) && !aMask.IsEmpty())
119 bRet = aMask.Scale(maSize, BmpScaleFlag::Fast);
121 SAL_WARN_IF(!aMask.IsEmpty() && aBitmap.GetSizePixel() != aMask.GetSizePixel(), "vcl",
122 "BitmapEx::Scale(): size mismatch for bitmap and alpha mask.");
124 if (bRet)
125 return BitmapEx(aBitmap, aMask);
127 return BitmapEx();
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */