Get the style color and number just once
[LibreOffice.git] / vcl / source / bitmap / BitmapSeparableUnsharpenFilter.cxx
blob91a3b5483a7f2444440a6f6b568fc5c9702165e9
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 */
11 #include <tools/helpers.hxx>
13 #include <vcl/bitmap/BitmapGaussianSeparableBlurFilter.hxx>
14 #include <vcl/bitmap/BitmapSeparableUnsharpenFilter.hxx>
15 #include <vcl/BitmapWriteAccess.hxx>
17 BitmapEx BitmapSeparableUnsharpenFilter::execute(BitmapEx const& rBitmapEx) const
19 Bitmap aBitmap(rBitmapEx.GetBitmap());
21 const sal_Int32 nWidth = aBitmap.GetSizePixel().Width();
22 const sal_Int32 nHeight = aBitmap.GetSizePixel().Height();
24 Bitmap aBlur(aBitmap);
25 BitmapEx aBlurEx(aBlur);
27 BitmapFilter::Filter(aBlurEx, BitmapGaussianSeparableBlurFilter(-mfRadius));
28 aBlur = aBlurEx.GetBitmap();
30 // Amount of unsharpening effect on image - currently set to a fixed value
31 double aAmount = 2.0;
33 Bitmap aResultBitmap(Size(nWidth, nHeight), vcl::PixelFormat::N24_BPP);
35 BitmapScopedReadAccess pReadAccBlur(aBlur);
36 BitmapScopedReadAccess pReadAcc(aBitmap);
37 BitmapScopedWriteAccess pWriteAcc(aResultBitmap);
39 BitmapColor aColor, aColorBlur;
41 // For all pixels in original image subtract pixels values from blurred image
42 for (sal_Int32 y = 0; y < nHeight; y++)
44 Scanline pScanline = pWriteAcc->GetScanline(y);
45 for (sal_Int32 x = 0; x < nWidth; x++)
47 aColorBlur = pReadAccBlur->GetColor(y, x);
48 aColor = pReadAcc->GetColor(y, x);
50 BitmapColor aResultColor(
51 static_cast<sal_uInt8>(
52 std::clamp(aColor.GetRed() + (aColor.GetRed() - aColorBlur.GetRed()) * aAmount,
53 0.0, 255.0)),
54 static_cast<sal_uInt8>(std::clamp(
55 aColor.GetGreen() + (aColor.GetGreen() - aColorBlur.GetGreen()) * aAmount, 0.0,
56 255.0)),
57 static_cast<sal_uInt8>(std::clamp(
58 aColor.GetBlue() + (aColor.GetBlue() - aColorBlur.GetBlue()) * aAmount, 0.0,
59 255.0)));
61 pWriteAcc->SetPixelOnData(pScanline, x, aResultColor);
65 pWriteAcc.reset();
66 pReadAcc.reset();
67 pReadAccBlur.reset();
68 aBitmap.ReassignWithSize(aResultBitmap);
70 return BitmapEx(aBitmap);
73 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */