bump product version to 6.4.0.3
[LibreOffice.git] / vcl / source / bitmap / BitmapFastScaleFilter.cxx
blobcff8f314898055c03b93c713d3dde1431d28287b
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 long nNewWidth = FRound(aSizePix.Width() * mfScaleX);
37 const 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 long nScanlineSize = pWriteAcc->GetScanlineSize();
55 const long nNewWidth1 = nNewWidth - 1;
56 const long nNewHeight1 = nNewHeight - 1;
58 if (nNewWidth1 && nNewHeight1)
60 const double nWidth = pReadAcc->Width();
61 const double nHeight = pReadAcc->Height();
62 std::unique_ptr<long[]> pLutX(new long[nNewWidth]);
63 std::unique_ptr<long[]> pLutY(new long[nNewHeight]);
65 for (long nX = 0; nX < nNewWidth; nX++)
67 pLutX[nX] = long(nX * nWidth / nNewWidth);
70 for (long nY = 0; nY < nNewHeight; nY++)
72 pLutY[nY] = long(nY * nHeight / nNewHeight);
75 long nActY = 0;
76 while (nActY < nNewHeight)
78 long nMapY = pLutY[nActY];
79 Scanline pScanline = pWriteAcc->GetScanline(nActY);
80 Scanline pScanlineRead = pReadAcc->GetScanline(nMapY);
82 for (long nX = 0; nX < nNewWidth; nX++)
84 pWriteAcc->SetPixelOnData(
85 pScanline, nX,
86 pReadAcc->GetPixelFromData(pScanlineRead, pLutX[nX]));
89 while ((nActY < nNewHeight1) && (pLutY[nActY + 1] == nMapY))
91 memcpy(pWriteAcc->GetScanline(nActY + 1), pWriteAcc->GetScanline(nActY),
92 nScanlineSize);
93 nActY++;
95 nActY++;
98 bRet = true;
101 pWriteAcc.reset();
103 pReadAcc.reset();
105 if (bRet)
107 aBitmap.ReassignWithSize(aNewBmp);
108 SAL_INFO("vcl.gdi", "Bitmap size: " << aBitmap.GetSizePixel());
110 else
112 SAL_WARN("vcl.gdi", "no resize");
117 Bitmap aMask(rBitmapEx.GetMask());
119 if (bRet && (rBitmapEx.GetTransparentType() == TransparentType::Bitmap) && !aMask.IsEmpty())
120 bRet = aMask.Scale(maSize, BmpScaleFlag::Fast);
122 SAL_WARN_IF(!aMask.IsEmpty() && aBitmap.GetSizePixel() != aMask.GetSizePixel(), "vcl",
123 "BitmapEx::Scale(): size mismatch for bitmap and alpha mask.");
125 if (bRet)
126 return BitmapEx(aBitmap, aMask);
128 return BitmapEx();
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */