diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /vcl/source/bitmap/BitmapSeparableUnsharpenFilter.cxx | |
parent | Initial commit. (diff) | |
download | libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | vcl/source/bitmap/BitmapSeparableUnsharpenFilter.cxx | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/vcl/source/bitmap/BitmapSeparableUnsharpenFilter.cxx b/vcl/source/bitmap/BitmapSeparableUnsharpenFilter.cxx new file mode 100644 index 000000000..bbf5950dc --- /dev/null +++ b/vcl/source/bitmap/BitmapSeparableUnsharpenFilter.cxx @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + */ + +#include <tools/helpers.hxx> + +#include <vcl/bitmap.hxx> +#include <vcl/bitmapex.hxx> +#include <vcl/BitmapGaussianSeparableBlurFilter.hxx> +#include <vcl/BitmapSeparableUnsharpenFilter.hxx> + +#include <bitmap/BitmapWriteAccess.hxx> + +BitmapEx BitmapSeparableUnsharpenFilter::execute(BitmapEx const& rBitmapEx) const +{ + Bitmap aBitmap(rBitmapEx.GetBitmap()); + + const sal_Int32 nWidth = aBitmap.GetSizePixel().Width(); + const sal_Int32 nHeight = aBitmap.GetSizePixel().Height(); + + Bitmap aBlur(aBitmap); + BitmapEx aBlurEx(aBlur); + + BitmapFilter::Filter(aBlurEx, BitmapGaussianSeparableBlurFilter(-mfRadius)); + aBlur = aBlurEx.GetBitmap(); + + // Amount of unsharpening effect on image - currently set to a fixed value + double aAmount = 2.0; + + Bitmap aResultBitmap(Size(nWidth, nHeight), vcl::PixelFormat::N24_BPP); + + Bitmap::ScopedReadAccess pReadAccBlur(aBlur); + Bitmap::ScopedReadAccess pReadAcc(aBitmap); + BitmapScopedWriteAccess pWriteAcc(aResultBitmap); + + BitmapColor aColor, aColorBlur; + + // For all pixels in original image subtract pixels values from blurred image + for (sal_Int32 y = 0; y < nHeight; y++) + { + Scanline pScanline = pWriteAcc->GetScanline(y); + for (sal_Int32 x = 0; x < nWidth; x++) + { + aColorBlur = pReadAccBlur->GetColor(y, x); + aColor = pReadAcc->GetColor(y, x); + + BitmapColor aResultColor( + static_cast<sal_uInt8>(MinMax( + aColor.GetRed() + (aColor.GetRed() - aColorBlur.GetRed()) * aAmount, 0, 255)), + static_cast<sal_uInt8>(MinMax( + aColor.GetGreen() + (aColor.GetGreen() - aColorBlur.GetGreen()) * aAmount, 0, + 255)), + static_cast<sal_uInt8>( + MinMax(aColor.GetBlue() + (aColor.GetBlue() - aColorBlur.GetBlue()) * aAmount, + 0, 255))); + + pWriteAcc->SetPixelOnData(pScanline, x, aResultColor); + } + } + + pWriteAcc.reset(); + pReadAcc.reset(); + pReadAccBlur.reset(); + aBitmap.ReassignWithSize(aResultBitmap); + + return BitmapEx(aBitmap); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |