1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
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 long nWidth
= aBitmap
.GetSizePixel().Width();
25 const 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
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 (long y
= 0; y
< nHeight
; y
++)
47 Scanline pScanline
= pWriteAcc
->GetScanline(y
);
48 for (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,
59 static_cast<sal_uInt8
>(
60 MinMax(aColor
.GetBlue() + (aColor
.GetBlue() - aColorBlur
.GetBlue()) * aAmount
,
63 pWriteAcc
->SetPixelOnData(pScanline
, x
, aResultColor
);
70 aBitmap
.ReassignWithSize(aResultBitmap
);
72 return BitmapEx(aBitmap
);
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */