Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "texception.h"
Toshihiro Shimizu 890ddd
//#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Shinya Kitaoka 120a6e
TPixel32 unmultiply(const TPixel32 &pix) {
Shinya Kitaoka 120a6e
  if (!pix.m) return pix;
Shinya Kitaoka 120a6e
  double depremult = 255.0 / pix.m;
Shinya Kitaoka 120a6e
  return TPixel32((UCHAR)(pix.r * depremult), (UCHAR)(pix.g * depremult),
Shinya Kitaoka 120a6e
                  (UCHAR)(pix.b * depremult), pix.m);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka d1f6c4
class UnmultiplyFx final : public TStandardRasterFx {
Shinya Kitaoka 120a6e
  FX_PLUGIN_DECLARATION(UnmultiplyFx)
Shinya Kitaoka 120a6e
  TRasterFxPort m_input;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  UnmultiplyFx() { addInputPort("Source", m_input); }
Shinya Kitaoka 120a6e
  ~UnmultiplyFx(){};
Toshihiro Shimizu 890ddd
Shinya Kitaoka 38fd86
  bool doGetBBox(double frame, TRectD &bBox,
Shinya Kitaoka 38fd86
                 const TRenderSettings &info) override {
Shinya Kitaoka 120a6e
    if (m_input.isConnected())
Shinya Kitaoka 120a6e
      return m_input->doGetBBox(frame, bBox, info);
Shinya Kitaoka 120a6e
    else {
Shinya Kitaoka 120a6e
      bBox = TRectD();
Shinya Kitaoka 120a6e
      return false;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 473e70
  void doCompute(TTile &tile, double frame, const TRenderSettings &ri) override;
Shinya Kitaoka 38fd86
  bool canHandle(const TRenderSettings &info, double frame) override {
Shinya Kitaoka 38fd86
    return true;
Shinya Kitaoka 38fd86
  }
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//------------------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
void UnmultiplyFx::doCompute(TTile &tile, double frame,
Shinya Kitaoka 120a6e
                             const TRenderSettings &ri) {
Shinya Kitaoka 120a6e
  if (!m_input.isConnected()) return;
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  m_input->compute(tile, frame, ri);
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRaster32P raster32 = tile.getRaster();
Shinya Kitaoka 120a6e
  assert(raster32);  // per ora gestisco solo i Raster32
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  int j;
Shinya Kitaoka 120a6e
  raster32->lock();
Shinya Kitaoka 120a6e
  for (j = 0; j < raster32->getLy(); j++) {
Shinya Kitaoka 120a6e
    TPixel32 *pix    = raster32->pixels(j);
Shinya Kitaoka 120a6e
    TPixel32 *endPix = pix + raster32->getLx();
Shinya Kitaoka 120a6e
    while (pix < endPix) {
Shinya Kitaoka 120a6e
      if (pix->m) {
Shinya Kitaoka 120a6e
        double depremult = 255.0 / pix->m;
Shinya Kitaoka 120a6e
        pix->r           = (UCHAR)(pix->r * depremult);
Shinya Kitaoka 120a6e
        pix->g           = (UCHAR)(pix->g * depremult);
Shinya Kitaoka 120a6e
        pix->b           = (UCHAR)(pix->b * depremult);
Shinya Kitaoka 120a6e
      }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
      //*pix=unmultiply(*pix);
Shinya Kitaoka 120a6e
      pix++;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  raster32->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(UnmultiplyFx, "unmultiplyFx");