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 #include <vcl/bitmap.hxx>
13 #include <vcl/bitmapex.hxx>
14 #include <vcl/bitmapaccess.hxx>
17 
18 #include <bitmapwriteaccess.hxx>
19 
21 {
22  Bitmap aBitmap(rBitmapEx.GetBitmap());
23 
24  const long nWidth = aBitmap.GetSizePixel().Width();
25  const long 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), 24);
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 (long y = 0; y < nHeight; y++)
46  {
47  Scanline pScanline = pWriteAcc->GetScanline(y);
48  for (long 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: */
long Width() const
sal_uInt8 GetRed() const
Scanline GetScanline(long nY) const
Size GetSizePixel() const
float x
static bool Filter(BitmapEx &rBmpEx, BitmapFilter const &rFilter)
void SetPixelOnData(sal_uInt8 *pData, long nX, const BitmapColor &rBitmapColor)
virtual BitmapEx execute(BitmapEx const &rBitmapEx) const override
sal_uInt8 GetBlue() const
float y
Bitmap GetBitmap(const Color *pTransReplaceColor=nullptr) const
Definition: bitmapex.cxx:236
sal_uInt8 * Scanline
Definition: Scanline.hxx:25
sal_uInt8 GetGreen() const
BitmapColor GetColor(long nY, long nX) const
std::enable_if< std::is_signed< T >::value||std::is_floating_point< T >::value, long >::type MinMax(T nVal, long nMin, long nMax)