Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// TnzBase includes
Toshihiro Shimizu 890ddd
#include "trasterfx.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "ttzpimagefx.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************************
Toshihiro Shimizu 890ddd
//    Global  functions
Toshihiro Shimizu 890ddd
//**********************************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void parseIndexes(std::string indexes, std::vector<std::string> &items) {</std::string>
9f92bb
#ifdef _MSC_VER
Shinya Kitaoka 120a6e
  char seps[] = " ,;";
Shinya Kitaoka 120a6e
  char *token;
Shinya Kitaoka 120a6e
  if (indexes == "all" || indexes == "All" || indexes == "ALL")
Shinya Kitaoka 120a6e
    indexes     = "0-4095";
Shinya Kitaoka 120a6e
  char *context = 0;
Shinya Kitaoka 120a6e
  token         = strtok_s((char *)(indexes.c_str()), seps, &context);
Shinya Kitaoka 120a6e
  while (token != NULL) {
Shinya Kitaoka 120a6e
    items.push_back(token);
Shinya Kitaoka 120a6e
    token = strtok_s(NULL, seps, &context);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  char seps[] = " ,;";
Shinya Kitaoka 120a6e
  char *token;
Shinya Kitaoka 120a6e
  if (indexes == "all" || indexes == "All" || indexes == "ALL")
Shinya Kitaoka 120a6e
    indexes = "0-4095";
Shinya Kitaoka 120a6e
  token     = strtok((char *)(indexes.c_str()), seps);
Shinya Kitaoka 120a6e
  while (token != NULL) {
Shinya Kitaoka 120a6e
    items.push_back(token);
Shinya Kitaoka 120a6e
    token = strtok(NULL, seps);
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void insertIndexes(std::vector<std::string> items,</std::string>
Shinya Kitaoka 120a6e
                   PaletteFilterFxRenderData *t) {
9f92bb
#ifdef _MSC_VER
Shinya Kitaoka 120a6e
  for (int i = 0; i < (int)items.size(); i++) {
Shinya Kitaoka 120a6e
    char *starttoken, *endtoken;
Shinya Kitaoka 120a6e
    char subseps[]  = "-";
Shinya Kitaoka 120a6e
    std::string tmp = items[i];
Shinya Kitaoka 120a6e
    char *context   = 0;
Shinya Kitaoka 120a6e
    starttoken      = strtok_s((char *)tmp.c_str(), subseps, &context);
Shinya Kitaoka 120a6e
    endtoken        = strtok_s(NULL, subseps, &context);
Shinya Kitaoka 120a6e
    if (!endtoken && isInt(starttoken)) {
Shinya Kitaoka 120a6e
      int index;
Shinya Kitaoka 120a6e
      index = std::stoi(starttoken);
Shinya Kitaoka 120a6e
      t->m_colors.insert(index);
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      if (isInt(starttoken) && isInt(endtoken)) {
Shinya Kitaoka 120a6e
        int start, end;
Shinya Kitaoka 120a6e
        start = std::stoi(starttoken);
Shinya Kitaoka 120a6e
        end   = std::stoi(endtoken);
Shinya Kitaoka 120a6e
        for (int i = start; i <= end; i++) t->m_colors.insert(i);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
#else
Shinya Kitaoka 120a6e
  for (int i = 0; i < (int)items.size(); i++) {
Shinya Kitaoka 120a6e
    char *starttoken, *endtoken;
Shinya Kitaoka 120a6e
    char subseps[]  = "-";
Shinya Kitaoka 120a6e
    std::string tmp = items[i];
Shinya Kitaoka 120a6e
    starttoken      = strtok((char *)tmp.c_str(), subseps);
Shinya Kitaoka 120a6e
    endtoken        = strtok(NULL, subseps);
Shinya Kitaoka 120a6e
    if (!endtoken && isInt(starttoken)) {
Shinya Kitaoka 120a6e
      int index;
Shinya Kitaoka 120a6e
      index = std::stoi(starttoken);
Shinya Kitaoka 120a6e
      t->m_colors.insert(index);
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      if (isInt(starttoken) && isInt(endtoken)) {
Shinya Kitaoka 120a6e
        int start, end;
Shinya Kitaoka 120a6e
        start = std::stoi(starttoken);
Shinya Kitaoka 120a6e
        end   = std::stoi(endtoken);
Shinya Kitaoka 120a6e
        for (int i = start; i <= end; i++) t->m_colors.insert(i);
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************************
Toshihiro Shimizu 890ddd
//    ExternalPaletteFxRenderData  implementation
Toshihiro Shimizu 890ddd
//**********************************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
ExternalPaletteFxRenderData::ExternalPaletteFxRenderData(
Shinya Kitaoka 120a6e
    TPaletteP palette, const std::string &name)
Shinya Kitaoka 120a6e
    : m_palette(palette), m_name(name) {}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool ExternalPaletteFxRenderData::operator==(
Shinya Kitaoka 120a6e
    const TRasterFxRenderData &data) const {
Shinya Kitaoka 120a6e
  return false;  // non sono capace. non ho i pezzi per browsare nell'albero da
Shinya Kitaoka 120a6e
                 // qui.
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
std::string ExternalPaletteFxRenderData::toString() const { return m_name; }
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************************
Toshihiro Shimizu 890ddd
//    PaletteFilterFxRenderData  implementation
Toshihiro Shimizu 890ddd
//**********************************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
PaletteFilterFxRenderData::PaletteFilterFxRenderData() {
Shinya Kitaoka 120a6e
  m_keep = false;
Shinya Kitaoka 120a6e
  m_type = eApplyToInksAndPaints;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool PaletteFilterFxRenderData::operator==(
Shinya Kitaoka 120a6e
    const TRasterFxRenderData &data) const {
Shinya Kitaoka 120a6e
  const PaletteFilterFxRenderData *theData =
Shinya Kitaoka 120a6e
      dynamic_cast<const *="" palettefilterfxrenderdata="">(&data);</const>
Shinya Kitaoka 120a6e
  if (!theData) return false;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  return (theData->m_colors == m_colors && theData->m_type == m_type &&
Shinya Kitaoka 120a6e
          theData->m_keep == m_keep);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
std::string PaletteFilterFxRenderData::toString() const {
Shinya Kitaoka 120a6e
  std::string alias;
Shinya Kitaoka 120a6e
  std::set<int>::const_iterator it = m_colors.begin();</int>
Shinya Kitaoka 120a6e
  for (; it != m_colors.end(); ++it) alias += std::to_string(*it);
Shinya Kitaoka 120a6e
  alias += "keep=" + std::to_string(m_keep);
Shinya Kitaoka 120a6e
  alias += "type=" + std::to_string(m_type);
Shinya Kitaoka 120a6e
  return alias;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//**********************************************************************************************
Toshihiro Shimizu 890ddd
//    SandorFxRenderData  implementation
Toshihiro Shimizu 890ddd
//**********************************************************************************************
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
SandorFxRenderData::SandorFxRenderData(Type type, int argc, const char *argv[],
Shinya Kitaoka 120a6e
                                       int border, int shrink,
Shinya Kitaoka 120a6e
                                       const TRectD &controllerBBox,
Shinya Kitaoka 120a6e
                                       const TRasterP &controller)
Shinya Kitaoka 120a6e
    : m_type(type)
Shinya Kitaoka 120a6e
    , m_border(border)
Shinya Kitaoka 120a6e
    , m_shrink(shrink)
Shinya Kitaoka 120a6e
    , m_blendParams()
Shinya Kitaoka 120a6e
    , m_callParams()
Shinya Kitaoka 120a6e
    , m_contourParams()
Shinya Kitaoka 120a6e
    , m_argc(argc)
Shinya Kitaoka 120a6e
    , m_controllerBBox(controllerBBox)
Shinya Kitaoka 120a6e
    , m_controller(controller)
Shinya Kitaoka 120a6e
    , m_controllerAlias() {
Shinya Kitaoka 120a6e
  for (int i = 0; i < argc; i++) m_argv[i] = argv[i];
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
bool SandorFxRenderData::operator==(const TRasterFxRenderData &data) const {
Shinya Kitaoka 120a6e
  const SandorFxRenderData *theData =
Shinya Kitaoka 120a6e
      dynamic_cast<const *="" sandorfxrenderdata="">(&data);</const>
Shinya Kitaoka 120a6e
  if (!theData) return false;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_type == BlendTz)
Shinya Kitaoka 120a6e
    return (theData->m_blendParams.m_colorIndex == m_blendParams.m_colorIndex &&
Shinya Kitaoka 120a6e
            theData->m_blendParams.m_noBlending == m_blendParams.m_noBlending &&
Shinya Kitaoka 120a6e
            theData->m_blendParams.m_amount == m_blendParams.m_amount &&
Shinya Kitaoka 120a6e
            theData->m_blendParams.m_smoothness == m_blendParams.m_smoothness);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_type == Calligraphic || m_type == OutBorder)
Shinya Kitaoka 120a6e
    return (theData->m_callParams.m_colorIndex == m_callParams.m_colorIndex &&
Shinya Kitaoka 120a6e
            theData->m_callParams.m_thickness == m_callParams.m_thickness &&
Shinya Kitaoka 120a6e
            theData->m_callParams.m_doWDiagonal == m_callParams.m_doWDiagonal &&
Shinya Kitaoka 120a6e
            theData->m_callParams.m_noise == m_callParams.m_noise &&
Shinya Kitaoka 120a6e
            theData->m_callParams.m_horizontal == m_callParams.m_horizontal &&
Shinya Kitaoka 120a6e
            theData->m_callParams.m_vertical == m_callParams.m_vertical &&
Shinya Kitaoka 120a6e
            theData->m_callParams.m_accuracy == m_callParams.m_accuracy &&
Shinya Kitaoka 120a6e
            theData->m_callParams.m_upWDiagonal == m_callParams.m_upWDiagonal);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_type == ArtAtContour)
Shinya Kitaoka 120a6e
    return (
Shinya Kitaoka 120a6e
        theData->m_contourParams.m_density == m_contourParams.m_density &&
Shinya Kitaoka 120a6e
        theData->m_contourParams.m_colorIndex == m_contourParams.m_colorIndex &&
Shinya Kitaoka 120a6e
        theData->m_contourParams.m_keepLine == m_contourParams.m_keepLine &&
Shinya Kitaoka 120a6e
        theData->m_contourParams.m_maxOrientation ==
Shinya Kitaoka 120a6e
            m_contourParams.m_maxOrientation &&
Shinya Kitaoka 120a6e
        theData->m_contourParams.m_maxDistance ==
Shinya Kitaoka 120a6e
            m_contourParams.m_maxDistance &&
Shinya Kitaoka 120a6e
        theData->m_contourParams.m_maxSize == m_contourParams.m_maxSize &&
Shinya Kitaoka 120a6e
        theData->m_contourParams.m_minOrientation ==
Shinya Kitaoka 120a6e
            m_contourParams.m_minOrientation &&
Shinya Kitaoka 120a6e
        theData->m_contourParams.m_minDistance ==
Shinya Kitaoka 120a6e
            m_contourParams.m_minDistance &&
Shinya Kitaoka 120a6e
        theData->m_contourParams.m_minSize == m_contourParams.m_minSize &&
Shinya Kitaoka 120a6e
        theData->m_contourParams.m_randomness == m_contourParams.m_randomness &&
Shinya Kitaoka 120a6e
        theData->m_contourParams.m_keepColor == m_contourParams.m_keepColor &&
Shinya Kitaoka 120a6e
        theData->m_contourParams.m_includeAlpha ==
Shinya Kitaoka 120a6e
            m_contourParams.m_includeAlpha &&
Shinya Kitaoka 120a6e
        theData->m_controllerAlias == m_controllerAlias);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return false;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
std::string SandorFxRenderData::toString() const {
Shinya Kitaoka 120a6e
  std::string alias;
Shinya Kitaoka 120a6e
  if (m_type == BlendTz) {
Shinya Kitaoka 120a6e
    alias += ::to_string(m_blendParams.m_colorIndex) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_blendParams.m_smoothness) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_blendParams.m_amount) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_blendParams.m_noBlending);
Shinya Kitaoka 120a6e
    return alias;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_type == Calligraphic || m_type == OutBorder) {
Shinya Kitaoka 120a6e
    alias += ::to_string(m_callParams.m_colorIndex) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_callParams.m_noise) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_callParams.m_accuracy) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_callParams.m_upWDiagonal) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_callParams.m_vertical) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_callParams.m_upWDiagonal) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_callParams.m_horizontal) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_callParams.m_thickness);
Shinya Kitaoka 120a6e
    return alias;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (m_type == ArtAtContour) {
Shinya Kitaoka 120a6e
    alias += std::to_string(m_contourParams.m_maxSize) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_contourParams.m_minSize) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_contourParams.m_maxOrientation) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_contourParams.m_minOrientation) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_contourParams.m_randomness) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_contourParams.m_maxDistance) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_contourParams.m_minDistance) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_contourParams.m_density) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_contourParams.m_keepLine) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_contourParams.m_keepColor) + " ";
Shinya Kitaoka 120a6e
    alias += std::to_string(m_contourParams.m_includeAlpha) + " ";
Shinya Kitaoka 120a6e
    alias += ::to_string(m_contourParams.m_colorIndex) + " ";
Shinya Kitaoka 120a6e
    alias += m_controllerAlias;
Shinya Kitaoka 120a6e
    return alias;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  return alias;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
TRectD SandorFxRenderData::getBBoxEnlargement(const TRectD &bbox) {
Shinya Kitaoka 120a6e
  switch (m_type) {
Shinya Kitaoka 120a6e
  case BlendTz: {
Shinya Kitaoka 120a6e
    // Nothing happen, unless we have color 0 among the blended ones. In such
Shinya Kitaoka 120a6e
    // case,
Shinya Kitaoka 120a6e
    // we have to enlarge the bbox proportionally to the amount param.
Shinya Kitaoka 120a6e
    std::vector<std::string> items;</std::string>
Shinya Kitaoka 120a6e
    std::string indexes = std::string(m_argv[0]);
Shinya Kitaoka 120a6e
    parseIndexes(indexes, items);
Shinya Kitaoka 120a6e
    PaletteFilterFxRenderData paletteFilterData;
Shinya Kitaoka 120a6e
    insertIndexes(items, &paletteFilterData);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    if (paletteFilterData.m_colors.size() > 0 &&
Shinya Kitaoka 120a6e
        *paletteFilterData.m_colors.begin() == 0)
Shinya Kitaoka 120a6e
      return bbox.enlarge(m_blendParams.m_amount);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    return bbox;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case Calligraphic:
Shinya Kitaoka 120a6e
  case OutBorder:
Shinya Kitaoka 120a6e
    return bbox.enlarge(m_callParams.m_thickness);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  case ArtAtContour:
Shinya Kitaoka 120a6e
    return bbox.enlarge(std::max(tceil(m_controllerBBox.getLx()),
Shinya Kitaoka 120a6e
                                 tceil(m_controllerBBox.getLy())) *
Shinya Kitaoka 120a6e
                        m_contourParams.m_maxSize);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  default:
Shinya Kitaoka 120a6e
    assert(false);
Shinya Kitaoka 120a6e
    return bbox;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}