Shinya Kitaoka 810553
#pragma once
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// YOMBParam.h: interface for the CYOMBParam class.
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//////////////////////////////////////////////////////////////////////
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#if !defined(AFX_YOMBPARAM_H__41D42152_F2EE_11D5_B92D_0040F674BE6A__INCLUDED_)
Toshihiro Shimizu 890ddd
#define AFX_YOMBPARAM_H__41D42152_F2EE_11D5_B92D_0040F674BE6A__INCLUDED_
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <vector></vector>
Toshihiro Shimizu 890ddd
#include "STColSelPic.h"
Toshihiro Shimizu 890ddd
#include "SDef.h"
Toshihiro Shimizu 890ddd
#include "InputParam.h"
Campbell Barton d0e335
#include "YOMBInputParam.h"
Toshihiro Shimizu 890ddd
#include "BlurMatrix.h"
Toshihiro Shimizu 890ddd
//#pragma warning(disable: 4786)
Toshihiro Shimizu 890ddd
//#include "tmsg.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define P(d) tmsg_info(" - %d -\n", d)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
class CYOMBParam {
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  bool m_isRandomSampling;
Shinya Kitaoka 120a6e
  bool m_isShowSelection;
Shinya Kitaoka 120a6e
  bool m_isStopAtContour;
Shinya Kitaoka 120a6e
  bool m_isBlurOnPair;
Shinya Kitaoka 120a6e
  double m_dSample;
Shinya Kitaoka 120a6e
  int m_nbSample;
Shinya Kitaoka 120a6e
  double m_dA, m_dAB;
Shinya Kitaoka 120a6e
  std::string m_name;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  bool m_isCM;
Shinya Kitaoka 120a6e
  // for RGBM color groups
Shinya Kitaoka 120a6e
  std::vector<i_pixel> m_color;</i_pixel>
Shinya Kitaoka 120a6e
  // for CMAP color indides
Shinya Kitaoka 120a6e
  COLOR_INDEX_LIST m_ink, m_paint;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  CYOMBParam()
Shinya Kitaoka 120a6e
      : m_isRandomSampling(false)
Shinya Kitaoka 120a6e
      , m_isShowSelection(false)
Shinya Kitaoka 120a6e
      , m_isStopAtContour(false)
Shinya Kitaoka 120a6e
      , m_isBlurOnPair(false)
Shinya Kitaoka 120a6e
      , m_dSample(0.0)
Shinya Kitaoka 120a6e
      , m_nbSample(0)
Shinya Kitaoka 120a6e
      , m_dA(0.0)
Shinya Kitaoka 120a6e
      , m_dAB(0.0)
Shinya Kitaoka 120a6e
      , m_name("")
Shinya Kitaoka 120a6e
      , m_isCM(false)
Shinya Kitaoka 120a6e
      , m_color(0) {
Shinya Kitaoka 120a6e
    m_ink.nb = m_paint.nb = 0;
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  CYOMBParam(const CYOMBParam &bp)
Shinya Kitaoka 120a6e
      : m_color(bp.m_color)
Shinya Kitaoka 120a6e
      , m_isRandomSampling(bp.m_isRandomSampling)
Shinya Kitaoka 120a6e
      , m_isShowSelection(bp.m_isShowSelection)
Shinya Kitaoka 120a6e
      , m_isStopAtContour(bp.m_isStopAtContour)
Shinya Kitaoka 120a6e
      , m_isBlurOnPair(bp.m_isBlurOnPair)
Shinya Kitaoka 120a6e
      , m_dSample(bp.m_dSample)
Shinya Kitaoka 120a6e
      , m_nbSample(bp.m_nbSample)
Shinya Kitaoka 120a6e
      , m_dA(bp.m_dA)
Shinya Kitaoka 120a6e
      , m_dAB(bp.m_dAB)
Shinya Kitaoka 120a6e
      , m_name(bp.m_name)
Shinya Kitaoka 120a6e
      , m_isCM(bp.m_isCM) {
Shinya Kitaoka 120a6e
    if (m_isCM) {
Shinya Kitaoka 120a6e
      m_ink.nb = bp.m_ink.nb;
Shinya Kitaoka 120a6e
      int i    = 0;
Shinya Kitaoka 120a6e
      for (i = 0; i < m_ink.nb; i++) m_ink.ci[i] = bp.m_ink.ci[i];
Shinya Kitaoka 120a6e
      m_paint.nb                                 = bp.m_paint.nb;
Shinya Kitaoka 120a6e
      for (i = 0; i < m_paint.nb; i++) m_paint.ci[i] = bp.m_paint.ci[i];
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  };
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  virtual ~CYOMBParam(){};
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  void print();
Shinya Kitaoka 120a6e
  void null();
Shinya Kitaoka 120a6e
  void read(const CInputParam &ip);
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Shinya Kitaoka 120a6e
  bool read(std::basic_ifstream<char> &in);</char>
Toshihiro Shimizu 890ddd
#endif
Shinya Kitaoka 120a6e
  void makeColorsUS();
Shinya Kitaoka 120a6e
  void makeItUS();
Shinya Kitaoka 120a6e
  static void adjustToMatte(I_PIXEL &p);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  //	void blurPixel(CSTColSelPic<uc_pixel>& pic, const int xx, const int yy,</uc_pixel>
Shinya Kitaoka 38fd86
  //				   const CBlurMatrix& bm, UC_PIXEL& col,const
Shinya Kitaoka d1f6c4
  // UCHAR
Shinya Kitaoka 38fd86
  // osel);
Shinya Kitaoka 120a6e
  //	bool isContourOnPath(const int xx, const int yy,
Shinya Kitaoka 120a6e
  //						 std::vector<blursection>::const_iterator</blursection>
Shinya Kitaoka 38fd86
  // pBS,
Shinya Kitaoka 120a6e
  //						 CSTColSelPic<uc_pixel>& pic);</uc_pixel>
Shinya Kitaoka 120a6e
  //	void addPixel(I_PIXEL& p, const UC_PIXEL* pic);
Shinya Kitaoka 120a6e
  //	void addPixel(I_PIXEL& p, const CSTColSelPic<uc_pixel>& pic,</uc_pixel>
Shinya Kitaoka 120a6e
  //                 const int xxyy, const int xy );
Shinya Kitaoka 120a6e
  void addPixel(I_PIXEL &p, const I_PIXEL &pp);
Shinya Kitaoka 120a6e
  int getColorIndex(const UCHAR c);
Shinya Kitaoka 120a6e
  void scale(const double d);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  template <class p=""></class>
Shinya Kitaoka 120a6e
  void addPixel(I_PIXEL &p, const P *pic) {
Shinya Kitaoka 120a6e
    p.r += ((int)pic->r);
Shinya Kitaoka 120a6e
    p.g += ((int)pic->g);
Shinya Kitaoka 120a6e
    p.b += ((int)pic->b);
Shinya Kitaoka 120a6e
    p.m += ((int)pic->m);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  // Checks the path from blurred pixel to the sample pixel.
Shinya Kitaoka 120a6e
  template <class p=""></class>
Shinya Kitaoka 120a6e
  bool isContourOnPath(const int xx, const int yy,
Shinya Kitaoka 120a6e
                       std::vector<blursection>::const_iterator pBS,</blursection>
Shinya Kitaoka 120a6e
                       CSTColSelPic

&pic) {

Shinya Kitaoka 120a6e
    for (std::vector<sxyd>::const_iterator p = pBS->begin(); p != pBS->end();</sxyd>
Shinya Kitaoka 120a6e
         ++p) {
Shinya Kitaoka 120a6e
      int x  = xx + p->x;
Shinya Kitaoka 120a6e
      int y  = yy + p->y;
Shinya Kitaoka 120a6e
      int xy = y * pic.m_lX + x;
Shinya Kitaoka 120a6e
      if (x >= 0 && y >= 0 && x < pic.m_lX && y < pic.m_lY)
Shinya Kitaoka 120a6e
        if (*(pic.m_sel + xy) == (UCHAR)0) return true;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  template <class p=""></class>
Shinya Kitaoka 120a6e
  void addPixel(I_PIXEL &ip, const CSTColSelPic

&pic, const int xxyy,

Shinya Kitaoka 120a6e
                const int xy) {
Shinya Kitaoka 120a6e
    if (!m_isBlurOnPair) {
Shinya Kitaoka 120a6e
      addPixel(ip, pic.m_pic + xy);
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      int i  = getColorIndex(*(pic.m_sel + xy));
Shinya Kitaoka 120a6e
      int ii = getColorIndex(*(pic.m_sel + xxyy));
Shinya Kitaoka 120a6e
      int l  = m_color.size() / 2;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      if (i == ii || abs(ii - i) == l) {
Shinya Kitaoka 120a6e
        addPixel(ip, pic.m_pic + xy);
Shinya Kitaoka 120a6e
      } else {
Shinya Kitaoka 120a6e
        if (ii < l) {
Shinya Kitaoka 120a6e
          if (i < l) {
Shinya Kitaoka 120a6e
            addPixel(ip, m_color[ii]);
Shinya Kitaoka 120a6e
          } else
Shinya Kitaoka 120a6e
            addPixel(ip, m_color[ii + l]);
Shinya Kitaoka 120a6e
        } else {
Shinya Kitaoka 120a6e
          if (i < l) {
Shinya Kitaoka 120a6e
            addPixel(ip, m_color[ii - l]);
Shinya Kitaoka 120a6e
          } else
Shinya Kitaoka 120a6e
            addPixel(ip, m_color[ii]);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  template <class p=""></class>
Shinya Kitaoka 120a6e
  void blurPixel(CSTColSelPic

&pic, const int xx, const int yy,

Shinya Kitaoka 120a6e
                 const CBlurMatrix &bm, I_PIXEL &col, const int iBm) {
Shinya Kitaoka 120a6e
    I_PIXEL p = {0, 0, 0, 0};
Shinya Kitaoka 120a6e
    int nb    = 0;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    int xxyy = yy * pic.m_lX + xx;
Shinya Kitaoka 120a6e
    for (std::vector<blursection>::const_iterator pBS = bm.m_m[iBm].begin();</blursection>
Shinya Kitaoka 120a6e
         pBS != bm.m_m[iBm].end(); ++pBS) {
Shinya Kitaoka 120a6e
      //		const SXYD* xyd=pBS->begin();
Shinya Kitaoka 120a6e
      BLURSECTION::const_iterator xyd = pBS->begin();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      int x = xx + xyd->x;
Shinya Kitaoka 120a6e
      int y = yy + xyd->y;
Shinya Kitaoka 120a6e
      if (x >= 0 && y >= 0 && x < pic.m_lX && y < pic.m_lY) {
Shinya Kitaoka 120a6e
        int xy = y * pic.m_lX + x;
Shinya Kitaoka 120a6e
        if (*(pic.m_sel + xy) > (UCHAR)0)
Shinya Kitaoka 120a6e
          if (bm.m_isSAC) {
Shinya Kitaoka 120a6e
            if (!isContourOnPath(xx, yy, pBS, pic)) {
Shinya Kitaoka 120a6e
              addPixel(p, pic, xxyy, xy);
Shinya Kitaoka 120a6e
              nb++;
Shinya Kitaoka 120a6e
            }
Shinya Kitaoka 120a6e
          } else {
Shinya Kitaoka 120a6e
            addPixel(p, pic, xxyy, xy);
Shinya Kitaoka 120a6e
            nb++;
Shinya Kitaoka 120a6e
          }
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (nb > 0) {
Shinya Kitaoka 120a6e
      double r = (double)p.r / (double)nb;
Shinya Kitaoka 120a6e
      double g = (double)p.g / (double)nb;
Shinya Kitaoka 120a6e
      double b = (double)p.b / (double)nb;
Shinya Kitaoka 120a6e
      double m = (double)p.m / (double)nb;
Shinya Kitaoka 120a6e
      col.r    = I_ROUND(r);
Shinya Kitaoka 120a6e
      col.g    = I_ROUND(g);
Shinya Kitaoka 120a6e
      col.b    = I_ROUND(b);
Shinya Kitaoka 120a6e
      col.m    = I_ROUND(m);
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      P *pPic = pic.m_pic + yy * pic.m_lX + xx;
Shinya Kitaoka 120a6e
      col.r   = (int)(pPic->r);
Shinya Kitaoka 120a6e
      col.g   = (int)(pPic->g);
Shinya Kitaoka 120a6e
      col.b   = (int)(pPic->b);
Shinya Kitaoka 120a6e
      col.m   = (int)(pPic->m);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  template <class p=""></class>
Shinya Kitaoka 120a6e
  bool isRealMixture(CSTColSelPic

&pic, const int xx, const int yy,

Shinya Kitaoka 120a6e
                     const CBlurMatrix &bm, const int iBm,
Shinya Kitaoka 120a6e
                     const UCHAR osel) const {
Shinya Kitaoka 120a6e
    for (std::vector<blursection>::const_iterator pBS = bm.m_m[iBm].begin();</blursection>
Shinya Kitaoka 120a6e
         pBS != bm.m_m[iBm].end(); ++pBS) {
Shinya Kitaoka 120a6e
      //		const SXYD* xyd= pBS->begin();
Shinya Kitaoka 120a6e
      BLURSECTION::const_iterator xyd = pBS->begin();
Shinya Kitaoka 120a6e
      int x                           = xx + xyd->x;
Shinya Kitaoka 120a6e
      int y                           = yy + xyd->y;
Shinya Kitaoka 120a6e
      if (x >= 0 && x < pic.m_lX && y >= 0 && y < pic.m_lY) {
Shinya Kitaoka 120a6e
        int xy      = y * pic.m_lX + x;
Shinya Kitaoka 120a6e
        UCHAR *pSel = pic.m_sel + xy;
Shinya Kitaoka 120a6e
        if (*pSel > (UCHAR)0 && *pSel != osel) return true;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    return false;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  template <class p=""></class>
Shinya Kitaoka 120a6e
  void doIt(CSTColSelPic

&ipic, CSTColSelPic

&opic) {

Shinya Kitaoka 120a6e
    CBlurMatrix bm(m_dSample, m_nbSample, m_isStopAtContour,
Shinya Kitaoka 120a6e
                   m_isRandomSampling);
Shinya Kitaoka 120a6e
    UCHAR *pSel = ipic.m_sel;
Shinya Kitaoka 120a6e
    for (int y = 0; y < ipic.m_lY; y++)
Shinya Kitaoka 120a6e
      for (int x = 0; x < ipic.m_lX; x++, pSel++)
Shinya Kitaoka 120a6e
        if (*pSel > (UCHAR)0) {
Shinya Kitaoka 120a6e
          I_PIXEL col;
Shinya Kitaoka 120a6e
          int iBm = bm.m_isRS ? rand() % NBRS : 0;
Shinya Kitaoka 120a6e
          if (isRealMixture(ipic, x, y, bm, iBm, *pSel))
Shinya Kitaoka 120a6e
            blurPixel(ipic, x, y, bm, col, iBm);
Shinya Kitaoka 120a6e
          else
Shinya Kitaoka 120a6e
            ipic.getPixel(x, y, col);
Shinya Kitaoka 120a6e
          opic.setRGBM(x, y, col);
Shinya Kitaoka 120a6e
        }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
#endif  // !defined(AFX_YOMBPARAM_H__41D42152_F2EE_11D5_B92D_0040F674BE6A__INCLUDED_)