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) {
Shinya Kitaoka 120a6e
      if (invRed) pixIn->r   = pixIn->m - pixIn->r;
Shinya Kitaoka 120a6e
      if (invGreen) pixIn->g = pixIn->m - pixIn->g;
Shinya Kitaoka 120a6e
      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
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
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;
Shinya Kitaoka 120a6e
  ras->lock();
Shinya Kitaoka 120a6e
  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>
Shinya Kitaoka 120a6e
  else {
Shinya Kitaoka 120a6e
    TRaster64P ras64 = ras;
Shinya Kitaoka 120a6e
    if (ras64)
Shinya Kitaoka 120a6e
      if (flag)
Shinya Kitaoka 120a6e
        do_invert<tpixel64>(ras64);</tpixel64>
Shinya Kitaoka 120a6e
      else
Shinya Kitaoka 120a6e
        do_invert<tpixel64>(ras64, invRed, invGreen, invBlue, invMatte);</tpixel64>
Shinya Kitaoka 120a6e
    else {
Shinya Kitaoka 120a6e
      TRasterGR8P ras8 = ras;
Shinya Kitaoka 120a6e
      if (ras8)
Shinya Kitaoka 120a6e
        do_invert<tpixelgr8>(ras8);</tpixelgr8>
Shinya Kitaoka 120a6e
      else {
Shinya Kitaoka 120a6e
        ras->unlock();
Shinya Kitaoka 120a6e
        throw TRopException("unsupported pixel type");
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  ras->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------