1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 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/bitmapaccess.hxx>
#include <vcl/BitmapGaussianSeparableBlurFilter.hxx>
#include <vcl/BitmapSeparableUnsharpenFilter.hxx>
#include <bitmapwriteaccess.hxx>
BitmapEx BitmapSeparableUnsharpenFilter::execute(BitmapEx const& rBitmapEx) const
{
Bitmap aBitmap(rBitmapEx.GetBitmap());
const long nWidth = aBitmap.GetSizePixel().Width();
const long 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), 24);
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 (long y = 0; y < nHeight; y++)
{
Scanline pScanline = pWriteAcc->GetScanline(y);
for (long 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: */
|