<commit_before>/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __otbAlphaBlendingFunction_h
#define __otbAlphaBlendingFunction_h

#include "otbBlendingFunction.h"
#include "otbMath.h"

namespace otb
{
namespace Function
{
/**
 * \class AlphaBlendingFunction
 * \brief Implements simple blending
 * For each channel the blending function is as follows:
 * \f[ P_{o} = \alpha P_{i1} + (1 - \alpha) P_{i2} \f]
 * \alpha is retrieved from the second pixel RGBA
 *  \ingroup Visualization
 */
template <class TInputRGBPixel1, class TInputRGBAPixel2, class TOutputRGBPixel = TInputRGBPixel1>
class AlphaBlendingFunction
  : public BlendingFunction<TInputRGBPixel1,TInputRGBAPixel2,TOutputRGBPixel>
{
public:
  /** Standard class typedefs */
  typedef AlphaBlendingFunction                 Self;
  typedef BlendingFunction<TInputRGBPixel1,
                           TInputRGBAPixel2,
                           TOutputRGBPixel>            Superclass;
  typedef itk::SmartPointer<Self>                      Pointer;
  typedef itk::SmartPointer<const Self>                ConstPointer;

  /** type macro */
  itkTypeMacro(AlphaBlendingFunction,BlendingFunction);

  /** new macro */
  itkNewMacro(Self);

  /** PixelType macros */
  typedef TInputRGBPixel1                        InputPixel1Type;
  typedef TInputRGBAPixel2                        InputPixel2Type;
  typedef TOutputRGBPixel                        OutputRGBPixelType;
  typedef typename OutputRGBPixelType::ValueType OutputValueType;

  /** Evaluate method  */
  inline virtual const OutputRGBPixelType Evaluate(const InputPixel1Type& input1, const InputPixel2Type & input2)
  {
    OutputRGBPixelType resp;
    double alpha = static_cast<double>(input2.GetAlpha())/255.0;

    resp.SetRed(  static_cast<OutputValueType>(vcl_floor((1-alpha) * static_cast<double>(input1.GetRed())   +alpha*static_cast<double>(input2.GetRed())  +0.5)));
    resp.SetGreen(static_cast<OutputValueType>(vcl_floor((1-alpha) * static_cast<double>(input1.GetGreen()) +alpha*static_cast<double>(input2.GetGreen())+0.5)));
    resp.SetBlue( static_cast<OutputValueType>(vcl_floor((1-alpha) * static_cast<double>(input1.GetBlue())  +alpha*static_cast<double>(input2.GetBlue()) +0.5)));
    return resp;
  }

protected:
  /** Constructor */
  AlphaBlendingFunction() {}
  /** Destructor */
  ~AlphaBlendingFunction() {}
private:
  AlphaBlendingFunction(const Self&); //purposely not implemented
  void operator=(const Self&); //purposely not implemented<commit_msg>ENH: add global alpha to AlphaBlendingFunction<commit_after>/*=========================================================================

  Program:   ORFEO Toolbox
  Language:  C++
  Date:      $Date$
  Version:   $Revision$


  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
  See OTBCopyright.txt for details.


     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __otbAlphaBlendingFunction_h
#define __otbAlphaBlendingFunction_h

#include "otbBlendingFunction.h"
#include "otbMath.h"

namespace otb
{
namespace Function
{
/**
 * \class AlphaBlendingFunction
 * \brief Implements simple blending
 * For each channel the blending function is as follows:
 * \f[ P_{o} = (1 - \alpha) P_{i1} + \alpha P_{i2} \f]
 * with
 * \f[ \alpha = \alpha_{pix} * \alpha_{glo} \f]
 * \f$ \alpha_{pix} \f$ is retrieved from the second pixel RGBA
 * \f$ \alpha_{glo} \f$ is provided by the SetAlpha() method (1.0 by default)
 *
 *  \ingroup Visualization
 */
template <class TInputRGBPixel1, class TInputRGBAPixel2, class TOutputRGBPixel = TInputRGBPixel1>
class AlphaBlendingFunction
  : public BlendingFunction<TInputRGBPixel1,TInputRGBAPixel2,TOutputRGBPixel>
{
public:
  /** Standard class typedefs */
  typedef AlphaBlendingFunction                 Self;
  typedef BlendingFunction<TInputRGBPixel1,
                           TInputRGBAPixel2,
                           TOutputRGBPixel>            Superclass;
  typedef itk::SmartPointer<Self>                      Pointer;
  typedef itk::SmartPointer<const Self>                ConstPointer;

  /** type macro */
  itkTypeMacro(AlphaBlendingFunction,BlendingFunction);

  /** new macro */
  itkNewMacro(Self);

  /** PixelType macros */
  typedef TInputRGBPixel1                        InputPixel1Type;
  typedef TInputRGBAPixel2                        InputPixel2Type;
  typedef TOutputRGBPixel                        OutputRGBPixelType;
  typedef typename OutputRGBPixelType::ValueType OutputValueType;

  /** Evaluate method  */
  inline virtual const OutputRGBPixelType Evaluate(const InputPixel1Type& input1, const InputPixel2Type & input2)
  {
    OutputRGBPixelType resp;
    double alpha = static_cast<double>(input2.GetAlpha())/255.0 * m_Alpha;

    resp.SetRed(  static_cast<OutputValueType>(vcl_floor((1-alpha) * static_cast<double>(input1.GetRed())   +alpha*static_cast<double>(input2.GetRed())  +0.5)));
    resp.SetGreen(static_cast<OutputValueType>(vcl_floor((1-alpha) * static_cast<double>(input1.GetGreen()) +alpha*static_cast<double>(input2.GetGreen())+0.5)));
    resp.SetBlue( static_cast<OutputValueType>(vcl_floor((1-alpha) * static_cast<double>(input1.GetBlue())  +alpha*static_cast<double>(input2.GetBlue()) +0.5)));
    return resp;
  }

  /** Set/Get the alpha value */
  itkSetClampMacro(Alpha,double,0.,1.);
  itkGetMacro(Alpha,double);

protected:
  /** Constructor */
  AlphaBlendingFunction() : m_Alpha(1.0) {}
  /** Destructor */
  ~AlphaBlendingFunction() {}
private:
  AlphaBlendingFunction(const Self&); //purposely not implemented
  void operator=(const Self&); //purposely not implemented

  /** Alpha value for blending (should be in the range [0,1] */
  double m_Alpha;
{'fraction_non_alphanumeric': 0.14556470405468386, 'fraction_numerical': 0.013049557247164828, 'mean_word_length': 3.8369646882043575, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2880682', 'n_tokens_mistral': 1910, 'n_tokens_neox': 1833, 'n_words': 438}