|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
9f5a1b |
#ifdef _WIN32
|
|
|
e280ae |
#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 <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 "PatternMapParam.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 "EraseContour.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "PatternPosition.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "Pattern.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "SError.h"
|
|
Toshihiro Shimizu |
890ddd |
//#include "tmsg.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "patternmap.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
using namespace std;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#ifdef __cplusplus
|
|
Toshihiro Shimizu |
890ddd |
extern "C" {
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//#define P(d) tmsg_warning(" - %d -\n",d)
|
|
Shinya Kitaoka |
120a6e |
#define COPY_RASTER(iras, oras, border) \
|
|
Shinya Kitaoka |
120a6e |
tP.copy_raster(iras, oras, border, border, iras->lx - border - 1, \
|
|
Shinya Kitaoka |
120a6e |
iras->ly - border - 1, 0, 0)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define DIRACCURACY 12
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// ----- PatternMapping for UCHAR pixels (range 0-255)
|
|
Shinya Kitaoka |
120a6e |
// --------------------------
|
|
Campbell Barton |
b3bd84 |
static void patternmapUC(
|
|
Shinya Kitaoka |
120a6e |
const RASTER *iras, RASTER *oras, CPatternMapParam &pmP, const int border,
|
|
shun-iwasawa |
27b0cf |
RASTER
|
|
shun-iwasawa |
27b0cf |
*imgContour) // throw (SMemAllocError,SWriteRasterError,SFileReadError)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
120a6e |
try {
|
|
Shinya Kitaoka |
120a6e |
SRECT rect = {border, border, iras->lx - border - 1, iras->ly - border - 1};
|
|
Shinya Kitaoka |
120a6e |
SPOINT p = {0, 0};
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
CSTColSelPic<uc_pixel> ipUC, ipOri;</uc_pixel>
|
|
Shinya Kitaoka |
120a6e |
ipUC.read(iras);
|
|
Shinya Kitaoka |
120a6e |
ipUC.initSel();
|
|
Shinya Kitaoka |
120a6e |
ipOri = ipUC;
|
|
Shinya Kitaoka |
120a6e |
// Selection of pixels using CM
|
|
Shinya Kitaoka |
120a6e |
CCIL emptyCIL;
|
|
Shinya Kitaoka |
120a6e |
int nbContourPixel = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (pmP.m_isKeepContour) {
|
|
Shinya Kitaoka |
120a6e |
CEraseContour ec(ipUC);
|
|
Shinya Kitaoka |
120a6e |
nbContourPixel = ec.makeSelection(pmP.m_ink);
|
|
Shinya Kitaoka |
120a6e |
// nbContourPixel=ipUC.makeSelectionCMAP(pmP.m_ink,emptyCIL);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
CEraseContour ec(ipUC);
|
|
Shinya Kitaoka |
120a6e |
nbContourPixel = ec.doIt(pmP.m_ink);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (nbContourPixel > 0) {
|
|
Shinya Kitaoka |
120a6e |
if (!pmP.m_isRandomDir) {
|
|
Shinya Kitaoka |
120a6e |
CSDirection dir(ipUC.m_lX, ipUC.m_lY, ipUC.m_sel.get(), DIRACCURACY);
|
|
Shinya Kitaoka |
120a6e |
dir.doDir();
|
|
Shinya Kitaoka |
120a6e |
dir.getResult(ipUC.m_sel.get());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
CPatternPosition pPos(ipUC, nbContourPixel, pmP.m_density, pmP.m_minDist,
|
|
Shinya Kitaoka |
120a6e |
pmP.m_maxDist);
|
|
Shinya Kitaoka |
120a6e |
// Reads the pattern
|
|
Shinya Kitaoka |
120a6e |
CPattern pat(imgContour);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
for (vector<spoint>::iterator pp = pPos.m_pos.begin();</spoint>
|
|
Shinya Kitaoka |
120a6e |
pp != pPos.m_pos.end(); pp++) {
|
|
Shinya Kitaoka |
120a6e |
// Calculates the rotation angle
|
|
Shinya Kitaoka |
120a6e |
double angle = 0.0;
|
|
Shinya Kitaoka |
120a6e |
if (pmP.m_isRandomDir)
|
|
Shinya Kitaoka |
120a6e |
angle = pmP.m_minDirAngle +
|
|
Shinya Kitaoka |
120a6e |
(double)(rand() % 1001) * 0.001 *
|
|
Shinya Kitaoka |
120a6e |
(pmP.m_maxDirAngle - pmP.m_minDirAngle);
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
if (pp->x >= 0 && pp->y >= 0 && pp->x < ipUC.m_lX &&
|
|
Shinya Kitaoka |
120a6e |
pp->y < ipUC.m_lY) {
|
|
Shinya Kitaoka |
120a6e |
UCHAR *sel = ipUC.m_sel.get() + pp->y * ipUC.m_lX + pp->x;
|
|
Shinya Kitaoka |
120a6e |
if (*sel > (UCHAR)0) angle = (double)(*sel) - 50.0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
angle += pmP.m_minDirAngle +
|
|
Shinya Kitaoka |
120a6e |
(double)(rand() % 1001) * 0.001 *
|
|
Shinya Kitaoka |
120a6e |
(pmP.m_maxDirAngle - pmP.m_minDirAngle);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Calculates the scale
|
|
Shinya Kitaoka |
120a6e |
double scale = 1.0;
|
|
Shinya Kitaoka |
120a6e |
scale =
|
|
Shinya Kitaoka |
120a6e |
pmP.m_minScale +
|
|
Shinya Kitaoka |
120a6e |
(double)(rand() % 1001) * 0.001 * (pmP.m_maxScale - pmP.m_minScale);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Mapping of Pattern
|
|
Shinya Kitaoka |
120a6e |
pat.mapIt(ipUC, ipOri, pp->x, pp->y, scale, angle, pmP.m_isUseInkColor,
|
|
Shinya Kitaoka |
120a6e |
pmP.m_isIncludeAlpha);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// ipUC.showSelection();
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
ipUC.write(oras, rect, p);
|
|
Shinya Kitaoka |
120a6e |
} catch (SMemAllocError) {
|
|
Shinya Kitaoka |
120a6e |
// SMemAllocError();
|
|
Shinya Kitaoka |
120a6e |
} catch (SWriteRasterError) {
|
|
Shinya Kitaoka |
120a6e |
// SWriteRasterError();
|
|
Shinya Kitaoka |
120a6e |
} catch (SFileReadError) {
|
|
Shinya Kitaoka |
120a6e |
// SFileReadError();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
// ----- PatternMapping for USHORT pixels (range 0-255)
|
|
Shinya Kitaoka |
120a6e |
// --------------------------
|
|
Campbell Barton |
b3bd84 |
static void patternmapUS(
|
|
Shinya Kitaoka |
120a6e |
const RASTER *iras, RASTER *oras, CPatternMapParam &pmP, const int border,
|
|
shun-iwasawa |
27b0cf |
RASTER
|
|
shun-iwasawa |
27b0cf |
*imgContour) // throw (SMemAllocError,SWriteRasterError,SFileReadError)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Shinya Kitaoka |
120a6e |
try {
|
|
Shinya Kitaoka |
120a6e |
SRECT rect = {border, border, iras->lx - border - 1, iras->ly - border - 1};
|
|
Shinya Kitaoka |
120a6e |
SPOINT p = {0, 0};
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
CSTColSelPic<us_pixel> ipUS, ipOri;</us_pixel>
|
|
Shinya Kitaoka |
120a6e |
ipUS.read(iras);
|
|
Shinya Kitaoka |
120a6e |
ipUS.initSel();
|
|
Shinya Kitaoka |
120a6e |
ipOri = ipUS;
|
|
Shinya Kitaoka |
120a6e |
// Selection of pixels using CM
|
|
Shinya Kitaoka |
120a6e |
CCIL emptyCIL;
|
|
Shinya Kitaoka |
120a6e |
int nbContourPixel = 0;
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
if (pmP.m_isKeepContour) {
|
|
Shinya Kitaoka |
120a6e |
CEraseContour ec(ipUS);
|
|
Shinya Kitaoka |
120a6e |
nbContourPixel = ec.makeSelection(pmP.m_ink);
|
|
Shinya Kitaoka |
120a6e |
// a 255-nek utananezni !!!
|
|
Shinya Kitaoka |
120a6e |
// nbContourPixel=ipUS.makeSelectionCMAP(pmP.m_ink,emptyCIL);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
CEraseContour ec(ipUS);
|
|
Shinya Kitaoka |
120a6e |
nbContourPixel = ec.doIt(pmP.m_ink);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
if (nbContourPixel > 0) {
|
|
Shinya Kitaoka |
120a6e |
if (!pmP.m_isRandomDir) {
|
|
Shinya Kitaoka |
120a6e |
CSDirection dir(ipUS.m_lX, ipUS.m_lY, ipUS.m_sel.get(), DIRACCURACY);
|
|
Shinya Kitaoka |
120a6e |
dir.doDir();
|
|
Shinya Kitaoka |
120a6e |
dir.getResult(ipUS.m_sel.get());
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
CPatternPosition pPos(ipUS, nbContourPixel, pmP.m_density, pmP.m_minDist,
|
|
Shinya Kitaoka |
120a6e |
pmP.m_maxDist);
|
|
Shinya Kitaoka |
120a6e |
// Reads the pattern
|
|
Shinya Kitaoka |
120a6e |
CPattern pat(imgContour);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
for (vector<spoint>::iterator pp = pPos.m_pos.begin();</spoint>
|
|
Shinya Kitaoka |
120a6e |
pp != pPos.m_pos.end(); pp++) {
|
|
Shinya Kitaoka |
120a6e |
// Calculates the rotation angle
|
|
Shinya Kitaoka |
120a6e |
double angle = 0.0;
|
|
Shinya Kitaoka |
120a6e |
if (pmP.m_isRandomDir)
|
|
Shinya Kitaoka |
120a6e |
angle = pmP.m_minDirAngle +
|
|
Shinya Kitaoka |
120a6e |
(double)(rand() % 1001) * 0.001 *
|
|
Shinya Kitaoka |
120a6e |
(pmP.m_maxDirAngle - pmP.m_minDirAngle);
|
|
Shinya Kitaoka |
120a6e |
else {
|
|
Shinya Kitaoka |
120a6e |
if (pp->x >= 0 && pp->y >= 0 && pp->x < ipUS.m_lX &&
|
|
Shinya Kitaoka |
120a6e |
pp->y < ipUS.m_lY) {
|
|
Shinya Kitaoka |
120a6e |
UCHAR *sel = ipUS.m_sel.get() + pp->y * ipUS.m_lX + pp->x;
|
|
Shinya Kitaoka |
120a6e |
if (*sel > (UCHAR)0) angle = (double)(*sel) - 50.0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
angle += pmP.m_minDirAngle +
|
|
Shinya Kitaoka |
120a6e |
(double)(rand() % 1001) * 0.001 *
|
|
Shinya Kitaoka |
120a6e |
(pmP.m_maxDirAngle - pmP.m_minDirAngle);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Calculates the scale
|
|
Shinya Kitaoka |
120a6e |
double scale = 1.0;
|
|
Shinya Kitaoka |
120a6e |
scale =
|
|
Shinya Kitaoka |
120a6e |
pmP.m_minScale +
|
|
Shinya Kitaoka |
120a6e |
(double)(rand() % 1001) * 0.001 * (pmP.m_maxScale - pmP.m_minScale);
|
|
Shinya Kitaoka |
120a6e |
|
|
Shinya Kitaoka |
120a6e |
// Mapping of Pattern
|
|
Shinya Kitaoka |
120a6e |
pat.mapIt(ipUS, ipOri, pp->x, pp->y, scale, angle, pmP.m_isUseInkColor,
|
|
Shinya Kitaoka |
120a6e |
pmP.m_isIncludeAlpha);
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
// ipUC.showSelection();
|
|
Shinya Kitaoka |
120a6e |
ipUS.write(oras, rect, p);
|
|
Shinya Kitaoka |
120a6e |
} catch (SMemAllocError) {
|
|
Shinya Kitaoka |
120a6e |
// SMemAllocError();
|
|
Shinya Kitaoka |
120a6e |
} catch (SWriteRasterError) {
|
|
Shinya Kitaoka |
120a6e |
// SWriteRasterError();
|
|
Shinya Kitaoka |
120a6e |
} catch (SFileReadError) {
|
|
Shinya Kitaoka |
120a6e |
// SFileReadError();
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Shinya Kitaoka |
120a6e |
int patternmap(const RASTER *iras, RASTER *oras, const int border, int argc,
|
|
Shinya Kitaoka |
120a6e |
const char *argv[], const int shrink, RASTER *imgContour) {
|
|
Shinya Kitaoka |
120a6e |
// The input raster must be RAS_CM16 or RAS_CM24!!!!
|
|
Shinya Kitaoka |
120a6e |
CSTPic<uc_pixel> tP;</uc_pixel>
|
|
Shinya Kitaoka |
120a6e |
if (iras->type != RAS_CM32) {
|
|
Shinya Kitaoka |
120a6e |
COPY_RASTER(iras, oras, border);
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
try {
|
|
Shinya Kitaoka |
120a6e |
CPatternMapParam pmP(argc, argv, shrink);
|
|
Shinya Kitaoka |
120a6e |
if (!pmP.isOK()) {
|
|
Shinya Kitaoka |
120a6e |
COPY_RASTER(iras, oras, border);
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
Shinya Kitaoka |
120a6e |
srand(10);
|
|
Shinya Kitaoka |
120a6e |
if (oras->type == RAS_RGBM) {
|
|
Shinya Kitaoka |
120a6e |
patternmapUC(iras, oras, pmP, border, imgContour);
|
|
Shinya Kitaoka |
120a6e |
} else if (oras->type == RAS_RGBM64) {
|
|
Shinya Kitaoka |
120a6e |
patternmapUS(iras, oras, pmP, border, imgContour);
|
|
Shinya Kitaoka |
120a6e |
} else {
|
|
Shinya Kitaoka |
120a6e |
COPY_RASTER(iras, oras, 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(iras, oras, border);
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
} catch (SWriteRasterError e) {
|
|
Shinya Kitaoka |
120a6e |
e.debug_print();
|
|
Shinya Kitaoka |
120a6e |
COPY_RASTER(iras, oras, border);
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
} catch (SFileReadError e) {
|
|
Shinya Kitaoka |
120a6e |
e.debug_print();
|
|
Shinya Kitaoka |
120a6e |
COPY_RASTER(iras, oras, border);
|
|
Shinya Kitaoka |
120a6e |
return 0;
|
|
Shinya Kitaoka |
120a6e |
}
|
|
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
|