LibreOffice Module vcl (master) 1
BitmapSeparableUnsharpenFilter.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 */
10
11#include <tools/helpers.hxx>
12
13#include <vcl/bitmap.hxx>
14#include <vcl/bitmapex.hxx>
17
19
21{
22 Bitmap aBitmap(rBitmapEx.GetBitmap());
23
24 const sal_Int32 nWidth = aBitmap.GetSizePixel().Width();
25 const sal_Int32 nHeight = aBitmap.GetSizePixel().Height();
26
27 Bitmap aBlur(aBitmap);
28 BitmapEx aBlurEx(aBlur);
29
31 aBlur = aBlurEx.GetBitmap();
32
33 // Amount of unsharpening effect on image - currently set to a fixed value
34 double aAmount = 2.0;
35
36 Bitmap aResultBitmap(Size(nWidth, nHeight), vcl::PixelFormat::N24_BPP);
37
38 Bitmap::ScopedReadAccess pReadAccBlur(aBlur);
39 Bitmap::ScopedReadAccess pReadAcc(aBitmap);
40 BitmapScopedWriteAccess pWriteAcc(aResultBitmap);
41
42 BitmapColor aColor, aColorBlur;
43
44 // For all pixels in original image subtract pixels values from blurred image
45 for (sal_Int32 y = 0; y < nHeight; y++)
46 {
47 Scanline pScanline = pWriteAcc->GetScanline(y);
48 for (sal_Int32 x = 0; x < nWidth; x++)
49 {
50 aColorBlur = pReadAccBlur->GetColor(y, x);
51 aColor = pReadAcc->GetColor(y, x);
52
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)));
62
63 pWriteAcc->SetPixelOnData(pScanline, x, aResultColor);
64 }
65 }
66
67 pWriteAcc.reset();
68 pReadAcc.reset();
69 pReadAccBlur.reset();
70 aBitmap.ReassignWithSize(aResultBitmap);
71
72 return BitmapEx(aBitmap);
73}
74
75/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt8 * Scanline
Definition: Scanline.hxx:26
Bitmap GetBitmap(Color aTransparentReplaceColor) const
Definition: BitmapEx.cxx:217
static bool Filter(BitmapEx &rBmpEx, BitmapFilter const &rFilter)
BitmapColor GetColor(tools::Long nY, tools::Long nX) const
virtual BitmapEx execute(BitmapEx const &rBitmapEx) const override
SAL_DLLPRIVATE void ReassignWithSize(const Bitmap &rBitmap)
ReassignWithSize and recalculate bitmap.
Size GetSizePixel() const
sal_uInt8 GetBlue() const
sal_uInt8 GetRed() const
sal_uInt8 GetGreen() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
float y
float x
std::enable_if< std::is_signed< T >::value||std::is_floating_point< T >::value, long >::type MinMax(T nVal, tools::Long nMin, tools::Long nMax)
unsigned char sal_uInt8