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
/*
Shinya Kitaoka 120a6e
inline bool isInFirstColor(const TDimensionD &dim,int x, int y,const TPointD
Shinya Kitaoka 120a6e
&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
Shinya Kitaoka 120a6e
namespace {
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>
Shinya Kitaoka 120a6e
                   const TDimensionD &dim, const TPointD &offset) {
Shinya Kitaoka 120a6e
  assert(dim.lx > 0);
Shinya Kitaoka 120a6e
  assert(dim.ly > 0);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double freqX = 0.5 / dim.lx;
Shinya Kitaoka 120a6e
  double freqY = 0.5 / dim.ly;
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double phaseX = 0;
Shinya Kitaoka 120a6e
  if (offset.x >= 0) {
Shinya Kitaoka 120a6e
    double q = offset.x * freqX;
Shinya Kitaoka 120a6e
    phaseX   = (q - floor(q));
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    double q = (-offset.x * freqX);
Shinya Kitaoka 120a6e
    phaseX   = 1.0 - (q - floor(q));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  double phaseY = 0;
Shinya Kitaoka 120a6e
  if (offset.y >= 0) {
Shinya Kitaoka 120a6e
    double q = offset.y * freqY;
Shinya Kitaoka 120a6e
    phaseY   = (q - floor(q));
Shinya Kitaoka 120a6e
  } else {
Shinya Kitaoka 120a6e
    double q = (-offset.y * freqY);
Shinya Kitaoka 120a6e
    phaseY   = 1.0 - (q - floor(q));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int lx = rout->getLx();
Shinya Kitaoka 120a6e
  int ly = rout->getLy();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  for (int y = 0; y < ly; y++) {
Shinya Kitaoka 120a6e
    double yy = 2.0 * (phaseY + y * freqY);
Shinya Kitaoka 120a6e
    int iy    = FLOOR(yy);
Shinya Kitaoka 120a6e
    assert(iy == (int)floor(yy));
Shinya Kitaoka 120a6e
    rout->lock();
Shinya Kitaoka 120a6e
    PIXEL *pix = rout->pixels(y);
Shinya Kitaoka 120a6e
    for (int x = 0; x < lx; x++) {
Shinya Kitaoka 120a6e
      double xx = 2.0 * (phaseX + x * freqX);
Shinya Kitaoka 120a6e
      int ix    = FLOOR(xx);
Shinya Kitaoka 120a6e
      assert(ix == (int)floor(xx));
Shinya Kitaoka 120a6e
      if ((ix ^ iy) & 1)
Shinya Kitaoka 120a6e
        *pix++ = pix1;
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        *pix++ = pix2;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    rout->unlock();
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-----------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void TRop::checkBoard(TRasterP rout, const TPixel32 &pix1, const TPixel32 &pix2,
Shinya Kitaoka 120a6e
                      const TDimensionD &dim, const TPointD &offset) {
Shinya Kitaoka 120a6e
  // assert(offset.x<=dim.lx && offset.y<=dim.ly);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  TRaster32P rout32 = rout;
Shinya Kitaoka 120a6e
  if (rout32)
Shinya Kitaoka 120a6e
    do_checkBoard<tpixel32>(rout32, pix1, pix2, dim, offset);</tpixel32>
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    TRaster64P rout64 = rout;
Shinya Kitaoka 120a6e
    if (rout64)
Shinya Kitaoka 120a6e
      do_checkBoard<tpixel64>(rout64, toPixel64(pix1), toPixel64(pix2), dim,</tpixel64>
Shinya Kitaoka 120a6e
                              offset);
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      throw TRopException("unsupported pixel type");
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}