Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "trop.h"
Toshihiro Shimizu 890ddd
#include "tpixelgr.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Toshihiro Shimizu 890ddd
template <typename pixtype=""></typename>
Shinya Kitaoka 120a6e
inline void do_invert(TRasterPT<pixtype> ras) {</pixtype>
Shinya Kitaoka 120a6e
  int wrap         = ras->getWrap();
Shinya Kitaoka 120a6e
  int lx           = ras->getLx();
Shinya Kitaoka 120a6e
  PixType *rowIn   = ras->pixels();
Shinya Kitaoka 120a6e
  PixType *lastPix = rowIn + wrap * ras->getLy();
Shinya Kitaoka 120a6e
  PixType *pixIn   = 0;
Shinya Kitaoka 120a6e
  PixType *endPix  = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  while (pixIn < lastPix) {
Shinya Kitaoka 120a6e
    pixIn  = rowIn;
Shinya Kitaoka 120a6e
    endPix = pixIn + lx;
Shinya Kitaoka 120a6e
    while (pixIn < endPix) {
Shinya Kitaoka 120a6e
      pixIn->r = pixIn->m - pixIn->r;
Shinya Kitaoka 120a6e
      pixIn->g = pixIn->m - pixIn->g;
Shinya Kitaoka 120a6e
      pixIn->b = pixIn->m - pixIn->b; /*pixIn->m = pixIn->m;*/
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      ++pixIn;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    rowIn += wrap;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename pixtype=""></typename>
Shinya Kitaoka 120a6e
inline void do_invert(TRasterPT<pixtype> ras, bool invRed, bool invGreen,</pixtype>
Shinya Kitaoka 120a6e
                      bool invBlue, bool invMatte) {
Shinya Kitaoka 120a6e
  int wrap         = ras->getWrap();
Shinya Kitaoka 120a6e
  int lx           = ras->getLx();
Shinya Kitaoka 120a6e
  PixType *rowIn   = ras->pixels();
Shinya Kitaoka 120a6e
  PixType *lastPix = rowIn + wrap * ras->getLy();
Shinya Kitaoka 120a6e
  PixType *pixIn   = 0;
Shinya Kitaoka 120a6e
  PixType *endPix  = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  while (pixIn < lastPix) {
Shinya Kitaoka 120a6e
    pixIn  = rowIn;
Shinya Kitaoka 120a6e
    endPix = pixIn + lx;
Shinya Kitaoka 120a6e
    while (pixIn < endPix) {
shun-iwasawa 481b59
      if (invRed) pixIn->r = pixIn->m - pixIn->r;
Shinya Kitaoka 120a6e
      if (invGreen) pixIn->g = pixIn->m - pixIn->g;
shun-iwasawa 481b59
      if (invBlue) pixIn->b = pixIn->m - pixIn->b;
Shinya Kitaoka 120a6e
      if (invMatte) pixIn->m = ~pixIn->m;
Shinya Kitaoka 120a6e
      ++pixIn;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    rowIn += wrap;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <>
Shinya Kitaoka 120a6e
inline void do_invert<tpixelgr8>(TRasterPT<tpixelgr8> ras) {</tpixelgr8></tpixelgr8>
Shinya Kitaoka 120a6e
  int wrap           = ras->getWrap();
Shinya Kitaoka 120a6e
  int lx             = ras->getLx();
Shinya Kitaoka 120a6e
  TPixelGR8 *rowIn   = ras->pixels();
Shinya Kitaoka 120a6e
  TPixelGR8 *lastPix = rowIn + wrap * ras->getLy();
Shinya Kitaoka 120a6e
  TPixelGR8 *pixIn   = 0;
Shinya Kitaoka 120a6e
  TPixelGR8 *endPix  = 0;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  while (pixIn < lastPix) {
Shinya Kitaoka 120a6e
    pixIn  = rowIn;
Shinya Kitaoka 120a6e
    endPix = pixIn + lx;
Shinya Kitaoka 120a6e
    while (pixIn < endPix) {
Shinya Kitaoka 120a6e
      pixIn->value = 255 - pixIn->value;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      ++pixIn;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    rowIn += wrap;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
shun-iwasawa 481b59
shun-iwasawa 481b59
//------------------------------------------------------------------------------
shun-iwasawa 481b59
shun-iwasawa 481b59
template <>
shun-iwasawa 481b59
inline void do_invert<tpixelf>(TRasterFP ras, bool invRed, bool invGreen,</tpixelf>
shun-iwasawa 481b59
                               bool invBlue, bool invMatte) {
shun-iwasawa 481b59
  int wrap         = ras->getWrap();
shun-iwasawa 481b59
  int lx           = ras->getLx();
shun-iwasawa 481b59
  TPixelF *rowIn   = ras->pixels();
shun-iwasawa 481b59
  TPixelF *lastPix = rowIn + wrap * ras->getLy();
shun-iwasawa 481b59
  TPixelF *pixIn   = 0;
shun-iwasawa 481b59
  TPixelF *endPix  = 0;
shun-iwasawa 481b59
shun-iwasawa 481b59
  while (pixIn < lastPix) {
shun-iwasawa 481b59
    pixIn  = rowIn;
shun-iwasawa 481b59
    endPix = pixIn + lx;
shun-iwasawa 481b59
    while (pixIn < endPix) {
shun-iwasawa 481b59
      if (invRed) pixIn->r = pixIn->m - pixIn->r;
shun-iwasawa 481b59
      if (invGreen) pixIn->g = pixIn->m - pixIn->g;
shun-iwasawa 481b59
      if (invBlue) pixIn->b = pixIn->m - pixIn->b;
shun-iwasawa 481b59
      if (invMatte) pixIn->m = 1.f - pixIn->m;
shun-iwasawa 481b59
      ++pixIn;
shun-iwasawa 481b59
    }
shun-iwasawa 481b59
    rowIn += wrap;
shun-iwasawa 481b59
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
shun-iwasawa 481b59
}  // namespace
shun-iwasawa 481b59
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void TRop::invert(TRasterP ras, bool invRed, bool invGreen, bool invBlue,
Shinya Kitaoka 120a6e
                  bool invMatte) {
Shinya Kitaoka 120a6e
  if (!invRed && !invGreen && !invBlue) return;
Shinya Kitaoka 120a6e
  bool flag = invRed && invGreen && invBlue && !invMatte;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRaster32P ras32 = ras;
shun-iwasawa 481b59
  TRaster64P ras64 = ras;
shun-iwasawa 481b59
  TRasterFP rasF   = ras;
shun-iwasawa 481b59
  TRasterGR8P ras8 = ras;
Shinya Kitaoka 120a6e
  ras->lock();
shun-iwasawa 481b59
shun-iwasawa 481b59
  if (ras32) {
Shinya Kitaoka 120a6e
    if (flag)
Shinya Kitaoka 120a6e
      do_invert<tpixel32>(ras32);</tpixel32>
Shinya Kitaoka 120a6e
    else
Shinya Kitaoka 120a6e
      do_invert<tpixel32>(ras, invRed, invGreen, invBlue, invMatte);</tpixel32>
shun-iwasawa 481b59
  } else if (ras64) {
shun-iwasawa 481b59
    if (flag)
shun-iwasawa 481b59
      do_invert<tpixel64>(ras64);</tpixel64>
shun-iwasawa 481b59
    else
shun-iwasawa 481b59
      do_invert<tpixel64>(ras64, invRed, invGreen, invBlue, invMatte);</tpixel64>
shun-iwasawa 481b59
  } else if (rasF) {
shun-iwasawa 481b59
    if (flag)
shun-iwasawa 481b59
      do_invert<tpixelf>(rasF);</tpixelf>
shun-iwasawa 481b59
    else
shun-iwasawa 481b59
      do_invert<tpixelf>(rasF, invRed, invGreen, invBlue, invMatte);</tpixelf>
shun-iwasawa 481b59
  } else if (ras8)
shun-iwasawa 481b59
    do_invert<tpixelgr8>(ras8);</tpixelgr8>
Shinya Kitaoka 120a6e
  else {
shun-iwasawa 481b59
    ras->unlock();
shun-iwasawa 481b59
    throw TRopException("unsupported pixel type");
Shinya Kitaoka 120a6e
  }
shun-iwasawa 481b59
Shinya Kitaoka 120a6e
  ras->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------