Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Shinya Kitaoka 9f5a1b
#ifdef _WIN32
Toshihiro Shimizu 890ddd
#pragma warning(disable : 4996)
Toshihiro Shimizu 890ddd
#include "windows.h"
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
#include <vector></vector>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include <stdio.h></stdio.h>
Toshihiro Shimizu 890ddd
#include <stdlib.h></stdlib.h>
Toshihiro Shimizu 890ddd
#include <time.h></time.h>
Toshihiro Shimizu 890ddd
#include <sys types.h=""></sys>
Toshihiro Shimizu 890ddd
#include <sys timeb.h=""></sys>
Toshihiro Shimizu 890ddd
#include <string.h></string.h>
Toshihiro Shimizu 890ddd
#include <math.h></math.h>
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "Params.h"
Toshihiro Shimizu 890ddd
#include "YOMBParam.h"
Toshihiro Shimizu 890ddd
#include "YOMBInputParam.h"
Toshihiro Shimizu 890ddd
#include "InputParam.h"
Toshihiro Shimizu 890ddd
#include "STColSelPic.h"
Toshihiro Shimizu 890ddd
#include "BlurMatrix.h"
Toshihiro Shimizu 890ddd
#include "SDirection.h"
Toshihiro Shimizu 890ddd
#include "SDef.h"
Toshihiro Shimizu 890ddd
#include "CallCircle.h"
Toshihiro Shimizu 890ddd
#include "CallParam.h"
Campbell Barton 8c6c57
#include "calligraph.h"
Toshihiro Shimizu 890ddd
//#include "tmsg.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
using namespace std;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef __cplusplus
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
extern "C" {
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#define P(d) tmsg_info(" - %d -\n", d)
Shinya Kitaoka 120a6e
#define COPY_RASTER(inr, outr, border)                                         \
Shinya Kitaoka 120a6e
  tP.copy_raster(inr, outr, border, border, inr->lx - border - 1,              \
Shinya Kitaoka 120a6e
                 inr->ly - border - 1, 0, 0)
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// ----- CALLIGRAPH for UCHAR pixels (range 0-255) --------------------------
shun-iwasawa 27b0cf
static void calligraphUC(
shun-iwasawa 27b0cf
    const RASTER *inr, RASTER *outr, CCallParam &par, const int border,
shun-iwasawa 27b0cf
    bool isOutBorder)  // throw(SMemAllocError,SWriteRasterError)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    SRECT rect = {border, border, inr->lx - border - 1, inr->ly - border - 1};
Shinya Kitaoka 120a6e
    SPOINT p   = {0, 0};
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    CSTColSelPic<uc_pixel> ipUC;</uc_pixel>
Shinya Kitaoka 120a6e
    ipUC.read(inr);
Shinya Kitaoka 120a6e
    ipUC.initSel();
Shinya Kitaoka 120a6e
    // Selection of pixels using CM
Shinya Kitaoka 120a6e
    int nbSel = ipUC.makeSelectionCMAP(par.m_ink, par.m_paint);
Shinya Kitaoka 120a6e
    if (nbSel > 0) {
Shinya Kitaoka 120a6e
      // Calculation of 'DIRECTION MAP'
Shinya Kitaoka 120a6e
      double fSize = par.m_accuracy / 5.0;
Shinya Kitaoka 120a6e
      fSize        = D_CUT(fSize, 1.0, 20.0);
Shinya Kitaoka 120a6e
      //			CSDirection
Shinya Kitaoka 38fd86
      // dir(ipUC.m_lX,ipUC.m_lY,ipUC.m_sel,I_ROUND(fSize));
Shinya Kitaoka 120a6e
      // Only on border (thickness of border is 3 )
Shinya Kitaoka 120a6e
      CSDirection dir(ipUC.m_lX, ipUC.m_lY, ipUC.m_sel.get(), I_ROUND(fSize),
Shinya Kitaoka 120a6e
                      3);
Shinya Kitaoka 120a6e
      dir.doDir();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // Calculation of 'RADIUS MAP' based on the 'DIRECTION MAP'
Shinya Kitaoka 120a6e
      // doRadius(rH,rLR,rV,rRL,radiusBlur)
Shinya Kitaoka 120a6e
      fSize = par.m_accuracy / 10.0;
Shinya Kitaoka 120a6e
      fSize = D_CUT(fSize, 1.0, 10.0);
Shinya Kitaoka 120a6e
      ;
Shinya Kitaoka 120a6e
      dir.doRadius(par.m_rH, par.m_rLR, par.m_rV, par.m_rRL, I_ROUND(fSize));
Shinya Kitaoka 120a6e
      dir.getResult(ipUC.m_sel.get());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // Draws the circles
Shinya Kitaoka 120a6e
      CCallCircle cc(par.m_thickness);
Shinya Kitaoka 120a6e
      cc.draw(ipUC, (par.m_ink.m_nb == 1), par.m_randomness);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      //			ipUC.showSelection();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (isOutBorder)
Shinya Kitaoka 120a6e
      ipUC.writeOutBorder(inr, border, outr, rect, p);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      ipUC.write(outr, rect, p);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  } catch (SMemAllocError) {
Shinya Kitaoka 120a6e
    //	SMemAllocError();
Shinya Kitaoka 120a6e
  } catch (SWriteRasterError) {
Shinya Kitaoka 120a6e
    // SWriteRasterError();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
// ----- CALLIGRAPH for USHORT pixels (range 0-65535) ------------------------
shun-iwasawa 27b0cf
static void calligraphUS(
shun-iwasawa 27b0cf
    const RASTER *inr, RASTER *outr, CCallParam &par, const int border,
shun-iwasawa 27b0cf
    bool isOutBorder)  // throw(SMemAllocError,SWriteRasterError)
Toshihiro Shimizu 890ddd
{
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    SRECT rect = {border, border, inr->lx - border - 1, inr->ly - border - 1};
Shinya Kitaoka 120a6e
    SPOINT p   = {0, 0};
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
    CSTColSelPic<us_pixel> ipUS;</us_pixel>
Shinya Kitaoka 120a6e
    ipUS.read(inr);
Shinya Kitaoka 120a6e
    ipUS.initSel();
Shinya Kitaoka 120a6e
    // Selection of pixels using CM
Shinya Kitaoka 120a6e
    int nbSel = ipUS.makeSelectionCMAP(par.m_ink, par.m_paint);
Shinya Kitaoka 120a6e
    if (nbSel > 0) {
Shinya Kitaoka 120a6e
      // Calculation of 'DIRECTION MAP'
Shinya Kitaoka 120a6e
      double fSize = par.m_accuracy / 5.0;
Shinya Kitaoka 120a6e
      fSize        = D_CUT(fSize, 1.0, 20.0);
Shinya Kitaoka 120a6e
      //			CSDirection
Shinya Kitaoka 38fd86
      // dir(ipUS.m_lX,ipUS.m_lY,ipUS.m_sel,I_ROUND(fSize));
Shinya Kitaoka 120a6e
      // Only on border (thickness of border is 3 )
Shinya Kitaoka 120a6e
      CSDirection dir(ipUS.m_lX, ipUS.m_lY, ipUS.m_sel.get(), I_ROUND(fSize),
Shinya Kitaoka 120a6e
                      3);
Shinya Kitaoka 120a6e
      dir.doDir();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // Calculation of 'RADIUS MAP' based on the 'DIRECTION MAP'
Shinya Kitaoka 120a6e
      // doRadius(rH,rLR,rV,rRL,radiusBlur)
Shinya Kitaoka 120a6e
      fSize = par.m_accuracy / 10.0;
Shinya Kitaoka 120a6e
      fSize = D_CUT(fSize, 1.0, 10.0);
Shinya Kitaoka 120a6e
      ;
Shinya Kitaoka 120a6e
      dir.doRadius(par.m_rH, par.m_rLR, par.m_rV, par.m_rRL, I_ROUND(fSize));
Shinya Kitaoka 120a6e
      dir.getResult(ipUS.m_sel.get());
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      // Draws the circles
Shinya Kitaoka 120a6e
      CCallCircle cc(par.m_thickness);
Shinya Kitaoka 120a6e
      cc.draw(ipUS, (par.m_ink.m_nb == 1), par.m_randomness);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
      //			ipUC.showSelection();
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    if (isOutBorder)
Shinya Kitaoka 120a6e
      ipUS.writeOutBorder(inr, border, outr, rect, p);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      ipUS.write(outr, rect, p);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  } catch (SMemAllocError) {
Shinya Kitaoka 120a6e
    // SMemAllocError();
Shinya Kitaoka 120a6e
  } catch (SWriteRasterError) {
Shinya Kitaoka 120a6e
    // SWriteRasterError();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int calligraph(const RASTER *inr, RASTER *outr, const int border, int argc,
Shinya Kitaoka 120a6e
               const char *argv[], const int shrink, bool isOutBorder) {
Shinya Kitaoka 120a6e
  // The input raster must be RAS_CM16 or RAS_CM32!!!!
Shinya Kitaoka 120a6e
  CSTPic<uc_pixel> tP;</uc_pixel>
Shinya Kitaoka 120a6e
  if (inr->type != RAS_CM32) {
Shinya Kitaoka 120a6e
    COPY_RASTER(inr, outr, border);
Shinya Kitaoka 120a6e
    return 0;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  try {
Shinya Kitaoka 120a6e
    CCallParam callP(argc, argv, shrink);
Shinya Kitaoka 120a6e
    if (!callP.isOK()) {
Shinya Kitaoka 120a6e
      COPY_RASTER(inr, outr, border);
Shinya Kitaoka 120a6e
      return 0;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    srand(10);
Shinya Kitaoka 120a6e
    if (outr->type == RAS_RGBM) {
Shinya Kitaoka 120a6e
      calligraphUC(inr, outr, callP, border, isOutBorder);
Shinya Kitaoka 120a6e
    } else if (outr->type == RAS_RGBM64) {
Shinya Kitaoka 120a6e
      calligraphUS(inr, outr, callP, border, isOutBorder);
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      COPY_RASTER(inr, outr, border);
Shinya Kitaoka 120a6e
      return 0;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  } catch (SMemAllocError e) {
Shinya Kitaoka 120a6e
    e.debug_print();
Shinya Kitaoka 120a6e
    COPY_RASTER(inr, outr, border);
Shinya Kitaoka 120a6e
    return 0;
Shinya Kitaoka 120a6e
  } catch (SWriteRasterError e) {
Shinya Kitaoka 120a6e
    e.debug_print();
Shinya Kitaoka 120a6e
    COPY_RASTER(inr, outr, border);
Shinya Kitaoka 120a6e
    return 0;
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return 1;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef __cplusplus
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
#endif