Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// YOMBParam.cpp: implementation of the CYOMBParam class.
Toshihiro Shimizu 890ddd
//
Toshihiro Shimizu 890ddd
//////////////////////////////////////////////////////////////////////
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
#include "Windows.h"
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#include <iostream></iostream>
Toshihiro Shimizu 890ddd
#include <fstream></fstream>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <vector></vector>
Toshihiro Shimizu 890ddd
//#include <stdio.h></stdio.h>
Toshihiro Shimizu 890ddd
#include <string.h></string.h>
Toshihiro Shimizu 890ddd
#include "YOMBParam.h"
Toshihiro Shimizu 890ddd
#include "InputParam.h"
Campbell Barton d0e335
#include "YOMBInputParam.h"
Toshihiro Shimizu 890ddd
#include "STColSelPic.h"
Toshihiro Shimizu 890ddd
#include "BlurMatrix.h"
Toshihiro Shimizu 890ddd
#include "SDef.h"
Toshihiro Shimizu 890ddd
#include "STColSelPic.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//////////////////////////////////////////////////////////////////////
Toshihiro Shimizu 890ddd
// Construction/Destruction
Toshihiro Shimizu 890ddd
//////////////////////////////////////////////////////////////////////
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace std;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void CYOMBParam::print() {
Shinya Kitaoka 120a6e
  /*
Shinya Kitaoka 120a6e
  char s[1024];
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  OutputDebugString("   ----- YOMB Param -----\n");
Shinya Kitaoka 120a6e
  sprintf(s,"   Name=%s\n",m_name.c_str());
Shinya Kitaoka 120a6e
  OutputDebugString(s);
Shinya Kitaoka 120a6e
  sprintf(s,"   RandomSampling=%d\n",m_isRandomSampling);
Shinya Kitaoka 120a6e
  OutputDebugString(s);
Shinya Kitaoka 120a6e
  sprintf(s,"   ShowSelection=%d\n",m_isShowSelection);
Shinya Kitaoka 120a6e
  OutputDebugString(s);
Shinya Kitaoka 120a6e
  sprintf(s,"   StopAtContour=%d\n",m_isStopAtContour);
Shinya Kitaoka 120a6e
  OutputDebugString(s);
Shinya Kitaoka 120a6e
  sprintf(s,"   dSample=%f\n",m_dSample);
Shinya Kitaoka 120a6e
  OutputDebugString(s);
Shinya Kitaoka 120a6e
  sprintf(s,"   nbSample=%d\n",m_nbSample);
Shinya Kitaoka 120a6e
  OutputDebugString(s);
Shinya Kitaoka 120a6e
  sprintf(s,"   dA=%f\n",m_dA);
Shinya Kitaoka 120a6e
  OutputDebugString(s);
Shinya Kitaoka 120a6e
  sprintf(s,"   dAB=%f\n",m_dAB);
Shinya Kitaoka 120a6e
  OutputDebugString(s);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for( vector<i_pixel>::iterator p=m_color.begin();</i_pixel>
Shinya Kitaoka 120a6e
           p!=m_color.end();
Shinya Kitaoka 120a6e
           ++p ) {
Shinya Kitaoka 120a6e
          sprintf(s,"   RGBM=(%d,%d,%d,%d)\n",p->r,p->g,p->b,p->m);
Shinya Kitaoka 120a6e
          OutputDebugString(s);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  OutputDebugString("   ----------------------\n");
Toshihiro Shimizu 890ddd
*/
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void CYOMBParam::null() {
Shinya Kitaoka 120a6e
  m_name             = "";
Shinya Kitaoka 120a6e
  m_isRandomSampling = false;
Shinya Kitaoka 120a6e
  m_isShowSelection  = false;
Shinya Kitaoka 120a6e
  m_isStopAtContour  = 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_color.resize(0);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Shinya Kitaoka 120a6e
bool CYOMBParam::read(basic_ifstream<char> &in) {</char>
Shinya Kitaoka 120a6e
  char token[1000] = "";
Shinya Kitaoka 120a6e
  bool isBegin     = false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  in >> token;
Shinya Kitaoka 120a6e
  while (in.good() || (!in.good() && isBegin && strcmp(token, "END") == 0)) {
Shinya Kitaoka 120a6e
    if (strcmp(token, "BEGIN_YOMB") == 0) isBegin = true;
Shinya Kitaoka 120a6e
    if (isBegin && strcmp(token, "NAME") == 0) in >> m_name;
Shinya Kitaoka 120a6e
    if (isBegin && strcmp(token, "STOP_AT_CONTOUR") == 0)
Shinya Kitaoka 120a6e
      m_isStopAtContour = true;
Shinya Kitaoka 120a6e
    if (isBegin && strcmp(token, "RANDOM_SAMPLING") == 0)
Shinya Kitaoka 120a6e
      m_isRandomSampling = true;
Shinya Kitaoka 120a6e
    if (isBegin && strcmp(token, "SHOW_SELECTION") == 0)
Shinya Kitaoka 120a6e
      m_isShowSelection = true;
Shinya Kitaoka 120a6e
    if (isBegin && strcmp(token, "BLUR_ON_PAIR") == 0) m_isBlurOnPair = true;
Shinya Kitaoka 120a6e
    if (isBegin && strcmp(token, "DSAMPLE") == 0) in >> m_dSample;
Shinya Kitaoka 120a6e
    if (isBegin && strcmp(token, "NBSAMPLE") == 0) in >> m_nbSample;
Shinya Kitaoka 120a6e
    if (isBegin && strcmp(token, "DA") == 0) in >> m_dA;
Shinya Kitaoka 120a6e
    if (isBegin && strcmp(token, "DAB") == 0) in >> m_dAB;
Shinya Kitaoka 120a6e
    if (isBegin && strcmp(token, "END") == 0) return true;
Shinya Kitaoka 120a6e
    if (isBegin && strcmp(token, "COLOR") == 0) {
Shinya Kitaoka 120a6e
      m_color.resize(m_color.size() + 1);
Shinya Kitaoka 120a6e
      vector<i_pixel>::iterator p = m_color.end();</i_pixel>
Shinya Kitaoka 120a6e
      p--;
Shinya Kitaoka 120a6e
      p->r = p->g = p->b = p->m = 0;
Shinya Kitaoka 120a6e
      if (in.good()) in >> p->r;
Shinya Kitaoka 120a6e
      if (in.good()) in >> p->g;
Shinya Kitaoka 120a6e
      if (in.good()) in >> p->b;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (in.good()) {
Shinya Kitaoka 120a6e
      token[0] = '\0';
Shinya Kitaoka 120a6e
      in >> token;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void CYOMBParam::adjustToMatte(I_PIXEL &p) {
Shinya Kitaoka 120a6e
  double q = (double)p.m / 255.0;
Shinya Kitaoka 120a6e
  double r = (double)p.r * q;
Shinya Kitaoka 120a6e
  double g = (double)p.g * q;
Shinya Kitaoka 120a6e
  double b = (double)p.b * q;
Shinya Kitaoka 120a6e
  p.r      = I_ROUNDP(r);
Shinya Kitaoka 120a6e
  p.g      = I_ROUNDP(g);
Shinya Kitaoka 120a6e
  p.b      = I_ROUNDP(b);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void CYOMBParam::read(const CInputParam &ip) {
Shinya Kitaoka 120a6e
  const CYOMBInputParam *yombIP;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  yombIP             = static_cast<const *="" cyombinputparam="">(&ip);</const>
Shinya Kitaoka 120a6e
  m_name             = "";
Shinya Kitaoka 120a6e
  m_isRandomSampling = yombIP->m_isRandomSampling;
Shinya Kitaoka 120a6e
  m_isShowSelection  = yombIP->m_isShowSelection;
Shinya Kitaoka 120a6e
  m_isStopAtContour  = yombIP->m_isStopAtContour;
Shinya Kitaoka 120a6e
  m_dSample          = yombIP->m_dSample;
Shinya Kitaoka 120a6e
  m_nbSample         = yombIP->m_nbSample;
Shinya Kitaoka 120a6e
  m_dA               = yombIP->m_dA;
Shinya Kitaoka 120a6e
  m_dAB              = yombIP->m_dAB;
Shinya Kitaoka 120a6e
  m_isCM             = yombIP->m_isCM;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_isCM) {
Shinya Kitaoka 120a6e
    m_ink.nb = yombIP->m_ink.nb;
Shinya Kitaoka 120a6e
    int i;
Shinya Kitaoka 120a6e
    for (i = 0; i < m_ink.nb; i++) m_ink.ci[i] = yombIP->m_ink.ci[i];
Shinya Kitaoka 120a6e
    m_paint.nb                                 = yombIP->m_paint.nb;
Shinya Kitaoka 120a6e
    for (i = 0; i < m_paint.nb; i++) m_paint.ci[i] = yombIP->m_paint.ci[i];
Shinya Kitaoka 120a6e
  } else if (yombIP->m_nbColor > 1) {
Shinya Kitaoka 120a6e
    m_color.resize(yombIP->m_nbColor);
Shinya Kitaoka 120a6e
    for (int i = 0; i < yombIP->m_nbColor; i++) {
Shinya Kitaoka 120a6e
      m_color[i].r = yombIP->m_color[i][0];
Shinya Kitaoka 120a6e
      m_color[i].g = yombIP->m_color[i][1];
Shinya Kitaoka 120a6e
      m_color[i].b = yombIP->m_color[i][2];
Shinya Kitaoka 120a6e
      m_color[i].m = yombIP->m_color[i][3];
Shinya Kitaoka 120a6e
      adjustToMatte(m_color[i]);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void CYOMBParam::addPixel(I_PIXEL &p, const I_PIXEL &pp) {
Shinya Kitaoka 120a6e
  p.r += pp.r;
Shinya Kitaoka 120a6e
  p.g += pp.g;
Shinya Kitaoka 120a6e
  p.b += pp.b;
Shinya Kitaoka 120a6e
  p.m += pp.m;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int CYOMBParam::getColorIndex(const UCHAR c) {
Shinya Kitaoka 120a6e
  return (c > (UCHAR)155 ? 255 - (int)c : 155 - (int)c + m_color.size() / 2);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void CYOMBParam::scale(const double d) {
Shinya Kitaoka 120a6e
  if (d >= 0) {
Shinya Kitaoka 120a6e
    m_dSample *= d;
Shinya Kitaoka 120a6e
    int s = (int)((double)m_nbSample * d + 0.5);
Shinya Kitaoka 120a6e
    if (d < 0.99) {
Shinya Kitaoka 120a6e
      m_nbSample = s <= 1 ? 3 : m_nbSample;
Shinya Kitaoka 120a6e
    } else
Shinya Kitaoka 120a6e
      m_nbSample = s <= 1 ? 1 : m_nbSample;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void CYOMBParam::makeItUS() {
Shinya Kitaoka 120a6e
  m_dA *= 200.0;
Shinya Kitaoka 120a6e
  m_dAB *= 200.0;
Shinya Kitaoka 120a6e
  makeColorsUS();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void CYOMBParam::makeColorsUS() {
Shinya Kitaoka 120a6e
  for (vector<i_pixel>::iterator p = m_color.begin(); p != m_color.end(); ++p) {</i_pixel>
Shinya Kitaoka 120a6e
    p->r = PIX_USHORT_FROM_BYTE((UCHAR)p->r);
Shinya Kitaoka 120a6e
    p->g = PIX_USHORT_FROM_BYTE((UCHAR)p->g);
Shinya Kitaoka 120a6e
    p->b = PIX_USHORT_FROM_BYTE((UCHAR)p->b);
Shinya Kitaoka 120a6e
    p->m = PIX_USHORT_FROM_BYTE((UCHAR)p->m);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}