From ee0d99607c14cb63d3ebdb3a970b508949fa8219 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Fri, 22 Nov 2024 18:41:30 +0900 Subject: Rename 'digikam' folder to 'src' Signed-off-by: Michele Calgaro --- src/imageplugins/emboss/emboss.cpp | 127 +++++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 src/imageplugins/emboss/emboss.cpp (limited to 'src/imageplugins/emboss/emboss.cpp') diff --git a/src/imageplugins/emboss/emboss.cpp b/src/imageplugins/emboss/emboss.cpp new file mode 100644 index 00000000..d4225148 --- /dev/null +++ b/src/imageplugins/emboss/emboss.cpp @@ -0,0 +1,127 @@ +/* ============================================================ + * + * This file is a part of digiKam project + * http://www.digikam.org + * + * Date : 2005-05-25 + * Description : Emboss threaded image filter. + * + * Copyright (C) 2005-2007 by Gilles Caulier + * Copyright (C) 2006-2007 by Marcel Wiesweg + * + * Original Emboss algorithm copyrighted 2004 by + * Pieter Z. Voloshyn . + * + * This program is free software; you can redistribute it + * and/or modify it under the terms of the GNU General + * Public License as published by the Free Software Foundation; + * either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * ============================================================ */ + +// C++ includes. + +#include +#include + +// Local includes. + +#include "dimg.h" +#include "dimgimagefilters.h" +#include "emboss.h" + +namespace DigikamEmbossImagesPlugin +{ + +Emboss::Emboss(Digikam::DImg *orgImage, TQObject *parent, int depth) + : Digikam::DImgThreadedFilter(orgImage, parent, "Emboss") +{ + m_depth = depth; + initFilter(); +} + +void Emboss::filterImage(void) +{ + embossImage(&m_orgImage, &m_destImage, m_depth); +} + +// This method have been ported from Pieter Z. Voloshyn algorithm code. + +/* Function to apply the Emboss effect + * + * data => The image data in RGBA mode. + * Width => Width of image. + * Height => Height of image. + * d => Emboss value + * + * Theory => This is an amazing effect. And the theory is very simple to + * understand. You get the diference between the colors and + * increase it. After this, get the gray tone + */ + +void Emboss::embossImage(Digikam::DImg *orgImage, Digikam::DImg *destImage, int d) +{ + int Width = orgImage->width(); + int Height = orgImage->height(); + uchar* data = orgImage->bits(); + bool sixteenBit = orgImage->sixteenBit(); + int bytesDepth = orgImage->bytesDepth(); + uchar* Bits = destImage->bits(); + + // Initial copy + memcpy (Bits, data, destImage->numBytes()); + + double Depth = d / 10.0; + + int progress; + int red, green, blue, gray; + Digikam::DColor color, colorOther; + int offset, offsetOther; + + for (int h = 0 ; !m_cancel && (h < Height) ; h++) + { + for (int w = 0 ; !m_cancel && (w < Width) ; w++) + { + offset = getOffset(Width, w, h, bytesDepth); + offsetOther = getOffset(Width, w + Lim_Max (w, 1, Width), h + Lim_Max (h, 1, Height), bytesDepth); + + color.setColor(Bits + offset, sixteenBit); + colorOther.setColor(Bits + offsetOther, sixteenBit); + + if (sixteenBit) + { + red = abs ((int)((color.red() - colorOther.red()) * Depth + 32768)); + green = abs ((int)((color.green() - colorOther.green()) * Depth + 32768)); + blue = abs ((int)((color.blue() - colorOther.blue()) * Depth + 32768)); + + gray = CLAMP065535 ((red + green + blue) / 3); + } + else + { + red = abs ((int)((color.red() - colorOther.red()) * Depth + 128)); + green = abs ((int)((color.green() - colorOther.green()) * Depth + 128)); + blue = abs ((int)((color.blue() - colorOther.blue()) * Depth + 128)); + + gray = CLAMP0255 ((red + green + blue) / 3); + } + + // Overwrite RGB values to destination. Alpha remains unchanged. + color.setRed(gray); + color.setGreen(gray); + color.setBlue(gray); + color.setPixel(Bits + offset); + } + + progress = (int) (((double)h * 100.0) / Height); + if ( progress%5 == 0 ) + postProgress( progress ); + } +} + +} // NameSpace DigikamEmbossImagesPlugin -- cgit v1.2.1