Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifndef T_COLOR_FUNCTIONS_INCLUDED
Toshihiro Shimizu 890ddd
#define T_COLOR_FUNCTIONS_INCLUDED
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "tpixel.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#undef DVAPI
Toshihiro Shimizu 890ddd
#undef DVVAR
Toshihiro Shimizu 890ddd
#ifdef TCOLOR_EXPORTS
Toshihiro Shimizu 890ddd
#define DVAPI DV_EXPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_EXPORT_VAR
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
#define DVAPI DV_IMPORT_API
Toshihiro Shimizu 890ddd
#define DVVAR DV_IMPORT_VAR
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TColorFunction {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  virtual TPixel32 operator()(
Shinya Kitaoka 120a6e
      const TPixel32 &color) const = 0;  // {return color;};
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  struct Parameters {  // outX = tcrop(inX * m_mX + m_cX, 0, 1); 0<=inX<=1
Shinya Kitaoka 120a6e
    double m_mR, m_mG, m_mB, m_mM;
Shinya Kitaoka 120a6e
    double m_cR, m_cG, m_cB, m_cM;
Shinya Kitaoka 120a6e
    Parameters()
Shinya Kitaoka 120a6e
        : m_mR(1)
Shinya Kitaoka 120a6e
        , m_mG(1)
Shinya Kitaoka 120a6e
        , m_mB(1)
Shinya Kitaoka 120a6e
        , m_mM(1)
Shinya Kitaoka 120a6e
        , m_cR(0)
Shinya Kitaoka 120a6e
        , m_cG(0)
Shinya Kitaoka 120a6e
        , m_cB(0)
Shinya Kitaoka 120a6e
        , m_cM(0) {}
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  virtual TColorFunction *clone() const = 0;
Shinya Kitaoka 120a6e
  virtual bool getParameters(
Shinya Kitaoka 120a6e
      Parameters &p) const = 0;  //{ p = Parameters(); return true; }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  virtual ~TColorFunction() {}
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TGenericColorFunction : public TColorFunction {
Shinya Kitaoka 120a6e
  double m_m[4], m_c[4];
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TGenericColorFunction(const double m[4], const double c[4]);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 38fd86
  TColorFunction *clone() const override {
Shinya Kitaoka 38fd86
    return new TGenericColorFunction(m_m, m_c);
Shinya Kitaoka 38fd86
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  TPixel32 operator()(const TPixel32 &color) const override;
Shinya Kitaoka 473e70
  bool getParameters(Parameters &p) const override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TColorFader : public TColorFunction {
Shinya Kitaoka 120a6e
  TPixel32 m_color;
Shinya Kitaoka 120a6e
  double m_fade;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TColorFader() : m_color(), m_fade(0.5) {}
Shinya Kitaoka 120a6e
  TColorFader(const TPixel32 &color, double fade)
Shinya Kitaoka 120a6e
      : m_color(color), m_fade(fade) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 38fd86
  TColorFunction *clone() const override {
Shinya Kitaoka 38fd86
    return new TColorFader(m_color, m_fade);
Shinya Kitaoka 38fd86
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  TPixel32 operator()(const TPixel32 &color) const override;
Shinya Kitaoka 473e70
  bool getParameters(Parameters &p) const override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TOnionFader : public TColorFunction {
Shinya Kitaoka 120a6e
  TPixel32 m_color;
Shinya Kitaoka 120a6e
  double m_fade;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TOnionFader() : m_color(), m_fade(0.5) {}
Shinya Kitaoka 120a6e
  TOnionFader(const TPixel32 &color, double fade)
Shinya Kitaoka 120a6e
      : m_color(color), m_fade(fade) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 38fd86
  TColorFunction *clone() const override {
Shinya Kitaoka 38fd86
    return new TOnionFader(m_color, m_fade);
Shinya Kitaoka 38fd86
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  TPixel32 operator()(const TPixel32 &color) const override;
Shinya Kitaoka 473e70
  bool getParameters(Parameters &p) const override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class DVAPI TTranspFader : public TColorFunction {
Shinya Kitaoka 120a6e
  double m_transp;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  TTranspFader() : m_transp(0.5) {}
Shinya Kitaoka 120a6e
  TTranspFader(double transp) : m_transp(transp) {}
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  TColorFunction *clone() const override { return new TTranspFader(m_transp); }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  TPixel32 operator()(const TPixel32 &color) const override;
Shinya Kitaoka 473e70
  bool getParameters(Parameters &p) const override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#endif