nss: upgrade to release 3.73
[LibreOffice.git] / vcl / source / bitmap / BitmapSeparableUnsharpenFilter.cxx
blob9a8b462e47a25730f67f7a0aca79cc89804fcaa0
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>
12 #include <vcl/bitmap.hxx>
13 #include <vcl/bitmapex.hxx>
14 #include <vcl/bitmapaccess.hxx>
15 #include <vcl/BitmapGaussianSeparableBlurFilter.hxx>
16 #include <vcl/BitmapSeparableUnsharpenFilter.hxx>
18 #include <bitmapwriteaccess.hxx>
20 BitmapEx BitmapSeparableUnsharpenFilter::execute(BitmapEx const& rBitmapEx) const
22 Bitmap aBitmap(rBitmapEx.GetBitmap());
24 const tools::Long nWidth = aBitmap.GetSizePixel().Width();
25 const tools::Long nHeight = aBitmap.GetSizePixel().Height();
27 Bitmap aBlur(aBitmap);
28 BitmapEx aBlurEx(aBlur);
30 BitmapFilter::Filter(aBlurEx, BitmapGaussianSeparableBlurFilter(-mfRadius));
31 aBlur = aBlurEx.GetBitmap();
33 // Amount of unsharpening effect on image - currently set to a fixed value
34 double aAmount = 2.0;
36 Bitmap aResultBitmap(Size(nWidth, nHeight), 24);
38 Bitmap::ScopedReadAccess pReadAccBlur(aBlur);
39 Bitmap::ScopedReadAccess pReadAcc(aBitmap);
40 BitmapScopedWriteAccess pWriteAcc(aResultBitmap);
42 BitmapColor aColor, aColorBlur;
44 // For all pixels in original image subtract pixels values from blurred image
45 for (tools::Long y = 0; y < nHeight; y++)
47 Scanline pScanline = pWriteAcc->GetScanline(y);
48 for (tools::Long x = 0; x < nWidth; x++)
50 aColorBlur = pReadAccBlur->GetColor(y, x);
51 aColor = pReadAcc->GetColor(y, x);
53 BitmapColor aResultColor(
54 static_cast<sal_uInt8>(MinMax(
55 aColor.GetRed() + (aColor.GetRed() - aColorBlur.GetRed()) * aAmount, 0, 255)),
56 static_cast<sal_uInt8>(MinMax(
57 aColor.GetGreen() + (aColor.GetGreen() - aColorBlur.GetGreen()) * aAmount, 0,
58 255)),
59 static_cast<sal_uInt8>(
60 MinMax(aColor.GetBlue() + (aColor.GetBlue() - aColorBlur.GetBlue()) * aAmount,
61 0, 255)));
63 pWriteAcc->SetPixelOnData(pScanline, x, aResultColor);
67 pWriteAcc.reset();
68 pReadAcc.reset();
69 pReadAccBlur.reset();
70 aBitmap.ReassignWithSize(aResultBitmap);
72 return BitmapEx(aBitmap);
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */