|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#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"
|
|
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)
|
|
Toshihiro Shimizu |
890ddd |
#define COPY_RASTER(inr, outr, border) tP.copy_raster(inr, outr, border, border, inr->lx - border - 1, inr->ly - border - 1, 0, 0)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// ----- CALLIGRAPH for UCHAR pixels (range 0-255) --------------------------
|
|
Toshihiro Shimizu |
890ddd |
void calligraphUC(const RASTER *inr, RASTER *outr, CCallParam &par,
|
|
Toshihiro Shimizu |
890ddd |
const int border, bool isOutBorder) //throw(SMemAllocError,SWriteRasterError)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
try {
|
|
Toshihiro Shimizu |
890ddd |
SRECT rect = {border, border, inr->lx - border - 1, inr->ly - border - 1};
|
|
Toshihiro Shimizu |
890ddd |
SPOINT p = {0, 0};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CSTColSelPic<uc_pixel> ipUC;</uc_pixel>
|
|
Toshihiro Shimizu |
890ddd |
ipUC.read(inr);
|
|
Toshihiro Shimizu |
890ddd |
ipUC.initSel();
|
|
Toshihiro Shimizu |
890ddd |
// Selection of pixels using CM
|
|
Toshihiro Shimizu |
890ddd |
int nbSel = ipUC.makeSelectionCMAP(par.m_ink, par.m_paint);
|
|
Toshihiro Shimizu |
890ddd |
if (nbSel > 0) {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Calculation of 'DIRECTION MAP'
|
|
Toshihiro Shimizu |
890ddd |
double fSize = par.m_accuracy / 5.0;
|
|
Toshihiro Shimizu |
890ddd |
fSize = D_CUT(fSize, 1.0, 20.0);
|
|
Toshihiro Shimizu |
890ddd |
// CSDirection dir(ipUC.m_lX,ipUC.m_lY,ipUC.m_sel,I_ROUND(fSize));
|
|
Toshihiro Shimizu |
890ddd |
// Only on border (thickness of border is 3 )
|
|
Toshihiro Shimizu |
890ddd |
CSDirection dir(ipUC.m_lX, ipUC.m_lY, ipUC.m_sel, I_ROUND(fSize), 3);
|
|
Toshihiro Shimizu |
890ddd |
dir.doDir();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Calculation of 'RADIUS MAP' based on the 'DIRECTION MAP'
|
|
Toshihiro Shimizu |
890ddd |
// doRadius(rH,rLR,rV,rRL,radiusBlur)
|
|
Toshihiro Shimizu |
890ddd |
fSize = par.m_accuracy / 10.0;
|
|
Toshihiro Shimizu |
890ddd |
fSize = D_CUT(fSize, 1.0, 10.0);
|
|
Toshihiro Shimizu |
890ddd |
;
|
|
Toshihiro Shimizu |
890ddd |
dir.doRadius(par.m_rH, par.m_rLR, par.m_rV, par.m_rRL, I_ROUND(fSize));
|
|
Toshihiro Shimizu |
890ddd |
dir.getResult(ipUC.m_sel);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Draws the circles
|
|
Toshihiro Shimizu |
890ddd |
CCallCircle cc(par.m_thickness);
|
|
Toshihiro Shimizu |
890ddd |
cc.draw(ipUC, (par.m_ink.m_nb == 1), par.m_randomness);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// ipUC.showSelection();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (isOutBorder)
|
|
Toshihiro Shimizu |
890ddd |
ipUC.writeOutBorder(inr, border, outr, rect, p);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
ipUC.write(outr, rect, p);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} catch (SMemAllocError) {
|
|
Toshihiro Shimizu |
890ddd |
// SMemAllocError();
|
|
Toshihiro Shimizu |
890ddd |
} catch (SWriteRasterError) {
|
|
Toshihiro Shimizu |
890ddd |
//SWriteRasterError();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// ----- CALLIGRAPH for USHORT pixels (range 0-65535) ------------------------
|
|
Toshihiro Shimizu |
890ddd |
void calligraphUS(const RASTER *inr, RASTER *outr, CCallParam &par,
|
|
Toshihiro Shimizu |
890ddd |
const int border, bool isOutBorder) //throw(SMemAllocError,SWriteRasterError)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
try {
|
|
Toshihiro Shimizu |
890ddd |
SRECT rect = {border, border, inr->lx - border - 1, inr->ly - border - 1};
|
|
Toshihiro Shimizu |
890ddd |
SPOINT p = {0, 0};
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
CSTColSelPic<us_pixel> ipUS;</us_pixel>
|
|
Toshihiro Shimizu |
890ddd |
ipUS.read(inr);
|
|
Toshihiro Shimizu |
890ddd |
ipUS.initSel();
|
|
Toshihiro Shimizu |
890ddd |
// Selection of pixels using CM
|
|
Toshihiro Shimizu |
890ddd |
int nbSel = ipUS.makeSelectionCMAP(par.m_ink, par.m_paint);
|
|
Toshihiro Shimizu |
890ddd |
if (nbSel > 0) {
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Calculation of 'DIRECTION MAP'
|
|
Toshihiro Shimizu |
890ddd |
double fSize = par.m_accuracy / 5.0;
|
|
Toshihiro Shimizu |
890ddd |
fSize = D_CUT(fSize, 1.0, 20.0);
|
|
Toshihiro Shimizu |
890ddd |
// CSDirection dir(ipUS.m_lX,ipUS.m_lY,ipUS.m_sel,I_ROUND(fSize));
|
|
Toshihiro Shimizu |
890ddd |
// Only on border (thickness of border is 3 )
|
|
Toshihiro Shimizu |
890ddd |
CSDirection dir(ipUS.m_lX, ipUS.m_lY, ipUS.m_sel, I_ROUND(fSize), 3);
|
|
Toshihiro Shimizu |
890ddd |
dir.doDir();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Calculation of 'RADIUS MAP' based on the 'DIRECTION MAP'
|
|
Toshihiro Shimizu |
890ddd |
// doRadius(rH,rLR,rV,rRL,radiusBlur)
|
|
Toshihiro Shimizu |
890ddd |
fSize = par.m_accuracy / 10.0;
|
|
Toshihiro Shimizu |
890ddd |
fSize = D_CUT(fSize, 1.0, 10.0);
|
|
Toshihiro Shimizu |
890ddd |
;
|
|
Toshihiro Shimizu |
890ddd |
dir.doRadius(par.m_rH, par.m_rLR, par.m_rV, par.m_rRL, I_ROUND(fSize));
|
|
Toshihiro Shimizu |
890ddd |
dir.getResult(ipUS.m_sel);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// Draws the circles
|
|
Toshihiro Shimizu |
890ddd |
CCallCircle cc(par.m_thickness);
|
|
Toshihiro Shimizu |
890ddd |
cc.draw(ipUS, (par.m_ink.m_nb == 1), par.m_randomness);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
// ipUC.showSelection();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (isOutBorder)
|
|
Toshihiro Shimizu |
890ddd |
ipUS.writeOutBorder(inr, border, outr, rect, p);
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
ipUS.write(outr, rect, p);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} catch (SMemAllocError) {
|
|
Toshihiro Shimizu |
890ddd |
//SMemAllocError();
|
|
Toshihiro Shimizu |
890ddd |
} catch (SWriteRasterError) {
|
|
Toshihiro Shimizu |
890ddd |
//SWriteRasterError();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int calligraph(const RASTER *inr, RASTER *outr, const int border,
|
|
Toshihiro Shimizu |
890ddd |
int argc, const char *argv[], const int shrink, bool isOutBorder)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
// The input raster must be RAS_CM16 or RAS_CM32!!!!
|
|
Toshihiro Shimizu |
890ddd |
CSTPic<uc_pixel> tP;</uc_pixel>
|
|
Toshihiro Shimizu |
890ddd |
if (inr->type != RAS_CM32) {
|
|
Toshihiro Shimizu |
890ddd |
COPY_RASTER(inr, outr, border);
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
try {
|
|
Toshihiro Shimizu |
890ddd |
CCallParam callP(argc, argv, shrink);
|
|
Toshihiro Shimizu |
890ddd |
if (!callP.isOK()) {
|
|
Toshihiro Shimizu |
890ddd |
COPY_RASTER(inr, outr, border);
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
srand(10);
|
|
Toshihiro Shimizu |
890ddd |
if (outr->type == RAS_RGBM) {
|
|
Toshihiro Shimizu |
890ddd |
calligraphUC(inr, outr, callP, border, isOutBorder);
|
|
Toshihiro Shimizu |
890ddd |
} else if (outr->type == RAS_RGBM64) {
|
|
Toshihiro Shimizu |
890ddd |
calligraphUS(inr, outr, callP, border, isOutBorder);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
COPY_RASTER(inr, outr, border);
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} catch (SMemAllocError e) {
|
|
Toshihiro Shimizu |
890ddd |
e.debug_print();
|
|
Toshihiro Shimizu |
890ddd |
COPY_RASTER(inr, outr, border);
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
} catch (SWriteRasterError e) {
|
|
Toshihiro Shimizu |
890ddd |
e.debug_print();
|
|
Toshihiro Shimizu |
890ddd |
COPY_RASTER(inr, outr, border);
|
|
Toshihiro Shimizu |
890ddd |
return 0;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
return 1;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef __cplusplus
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#endif
|