|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "trop.h"
|
|
Toshihiro Shimizu |
890ddd |
#include "tpixelutils.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#define FLOOR(x) ((int)(x) > (x) ? (int)(x)-1 : (int)(x))
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
inline bool isInFirstColor(const TDimensionD &dim,int x, int y,const TPointD &offset)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
int lx=dim.lx;
|
|
Toshihiro Shimizu |
890ddd |
int ly=dim.ly;
|
|
Toshihiro Shimizu |
890ddd |
int offX,offY;
|
|
Toshihiro Shimizu |
890ddd |
offX = offset.x>=0 ? (int)offset.x : (int)(lx-offset.x);
|
|
Toshihiro Shimizu |
890ddd |
offY = offset.y>=0 ? (int)offset.y : (int)(ly-offset.y);
|
|
Toshihiro Shimizu |
890ddd |
if ((( ((int)(offX+x))/lx + ((int)(offY+y))/ly )%2 ) == 0)
|
|
Toshihiro Shimizu |
890ddd |
return false;
|
|
Toshihiro Shimizu |
890ddd |
return true;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
template <typename pixel=""></typename>
|
|
Toshihiro Shimizu |
890ddd |
void do_checkBoard(TRasterPT<pixel> rout, const PIXEL &pix1, const PIXEL &pix2,</pixel>
|
|
Toshihiro Shimizu |
890ddd |
const TDimensionD &dim, const TPointD &offset)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
assert(dim.lx > 0);
|
|
Toshihiro Shimizu |
890ddd |
assert(dim.ly > 0);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double freqX = 0.5 / dim.lx;
|
|
Toshihiro Shimizu |
890ddd |
double freqY = 0.5 / dim.ly;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double phaseX = 0;
|
|
Toshihiro Shimizu |
890ddd |
if (offset.x >= 0) {
|
|
Toshihiro Shimizu |
890ddd |
double q = offset.x * freqX;
|
|
Toshihiro Shimizu |
890ddd |
phaseX = (q - floor(q));
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
double q = (-offset.x * freqX);
|
|
Toshihiro Shimizu |
890ddd |
phaseX = 1.0 - (q - floor(q));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double phaseY = 0;
|
|
Toshihiro Shimizu |
890ddd |
if (offset.y >= 0) {
|
|
Toshihiro Shimizu |
890ddd |
double q = offset.y * freqY;
|
|
Toshihiro Shimizu |
890ddd |
phaseY = (q - floor(q));
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
double q = (-offset.y * freqY);
|
|
Toshihiro Shimizu |
890ddd |
phaseY = 1.0 - (q - floor(q));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
int lx = rout->getLx();
|
|
Toshihiro Shimizu |
890ddd |
int ly = rout->getLy();
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
for (int y = 0; y < ly; y++) {
|
|
Toshihiro Shimizu |
890ddd |
double yy = 2.0 * (phaseY + y * freqY);
|
|
Toshihiro Shimizu |
890ddd |
int iy = FLOOR(yy);
|
|
Toshihiro Shimizu |
890ddd |
assert(iy == (int)floor(yy));
|
|
Toshihiro Shimizu |
890ddd |
rout->lock();
|
|
Toshihiro Shimizu |
890ddd |
PIXEL *pix = rout->pixels(y);
|
|
Toshihiro Shimizu |
890ddd |
for (int x = 0; x < lx; x++) {
|
|
Toshihiro Shimizu |
890ddd |
double xx = 2.0 * (phaseX + x * freqX);
|
|
Toshihiro Shimizu |
890ddd |
int ix = FLOOR(xx);
|
|
Toshihiro Shimizu |
890ddd |
assert(ix == (int)floor(xx));
|
|
Toshihiro Shimizu |
890ddd |
if ((ix ^ iy) & 1)
|
|
Toshihiro Shimizu |
890ddd |
*pix++ = pix1;
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
*pix++ = pix2;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
rout->unlock();
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
} //namespace
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//-----------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void TRop::checkBoard(TRasterP rout, const TPixel32 &pix1, const TPixel32 &pix2,
|
|
Toshihiro Shimizu |
890ddd |
const TDimensionD &dim, const TPointD &offset)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
//assert(offset.x<=dim.lx && offset.y<=dim.ly);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
TRaster32P rout32 = rout;
|
|
Toshihiro Shimizu |
890ddd |
if (rout32)
|
|
Toshihiro Shimizu |
890ddd |
do_checkBoard<tpixel32>(rout32, pix1, pix2, dim, offset);</tpixel32>
|
|
Toshihiro Shimizu |
890ddd |
else {
|
|
Toshihiro Shimizu |
890ddd |
TRaster64P rout64 = rout;
|
|
Toshihiro Shimizu |
890ddd |
if (rout64)
|
|
Toshihiro Shimizu |
890ddd |
do_checkBoard<tpixel64>(rout64, toPixel64(pix1), toPixel64(pix2), dim, offset);</tpixel64>
|
|
Toshihiro Shimizu |
890ddd |
else
|
|
Toshihiro Shimizu |
890ddd |
throw TRopException("unsupported pixel type");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|