Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "stdfx.h"
Toshihiro Shimizu 890ddd
#include "tfxparam.h"
Toshihiro Shimizu 890ddd
#include "tpixelutils.h"
Toshihiro Shimizu 890ddd
#include "tparamset.h"
Toshihiro Shimizu 890ddd
#include "ttonecurveparam.h"
Toshihiro Shimizu 890ddd
#include "tcurves.h"
shun-iwasawa 8cac36
#include "globalcontrollablefx.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
int getCubicYfromX(TCubic c, int x, double &s0, double &s1) {
Shinya Kitaoka 120a6e
  double s  = (s1 + s0) * 0.5;
Shinya Kitaoka 120a6e
  TPointD p = c.getPoint(s);
Shinya Kitaoka 120a6e
  if (areAlmostEqual(double(x), p.x, 0.001)) return tround(p.y);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (x < p.x)
Shinya Kitaoka 120a6e
    return getCubicYfromX(c, x, s0, s);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return getCubicYfromX(c, x, s, s1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
int getLinearYfromX(TSegment t, int x, double &s0, double &s1) {
Shinya Kitaoka 120a6e
  double s  = (s1 + s0) * 0.5;
Shinya Kitaoka 120a6e
  TPointD p = t.getPoint(s);
Shinya Kitaoka 120a6e
  if (areAlmostEqual(double(x), p.x, 0.001)) return tround(p.y);
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  if (x < p.x)
Shinya Kitaoka 120a6e
    return getLinearYfromX(t, x, s0, s);
Shinya Kitaoka 120a6e
  else
Shinya Kitaoka 120a6e
    return getLinearYfromX(t, x, s, s1);
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
shun-iwasawa 0ed559
void truncateSpeeds(double aFrame, double bFrame, TPointD &aSpeedTrunc,
shun-iwasawa 0ed559
                    TPointD &bSpeedTrunc) {
shun-iwasawa 0ed559
  double deltaX = bFrame - aFrame;
shun-iwasawa 0ed559
  if (aSpeedTrunc.x < 0) aSpeedTrunc.x = 0;
shun-iwasawa 0ed559
  if (bSpeedTrunc.x > 0) bSpeedTrunc.x = 0;
shun-iwasawa 0ed559
shun-iwasawa 0ed559
  if (aFrame + aSpeedTrunc.x > bFrame) {
shun-iwasawa 0ed559
    if (aSpeedTrunc.x != 0) {
shun-iwasawa 0ed559
      aSpeedTrunc = aSpeedTrunc * (deltaX / aSpeedTrunc.x);
shun-iwasawa 0ed559
    }
shun-iwasawa 0ed559
  }
shun-iwasawa 0ed559
shun-iwasawa 0ed559
  if (bFrame + bSpeedTrunc.x < aFrame) {
shun-iwasawa 0ed559
    if (bSpeedTrunc.x != 0) {
shun-iwasawa 0ed559
      bSpeedTrunc = -bSpeedTrunc * (deltaX / bSpeedTrunc.x);
shun-iwasawa 0ed559
    }
shun-iwasawa 0ed559
  }
shun-iwasawa 0ed559
}
shun-iwasawa 0ed559
Toshihiro Shimizu 890ddd
template <typename pixel,="" t="" typename=""></typename>
Shinya Kitaoka 120a6e
void fill_lut(QList<tpointd> points, std::vector<t> &lut, bool isLinear) {</t></tpointd>
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  TPointD p0 = points.at(0);
Shinya Kitaoka 120a6e
  TCubic cubic;
Shinya Kitaoka 120a6e
  TSegment segment;
Shinya Kitaoka 120a6e
  double s0 = 0.0;
Shinya Kitaoka 120a6e
  for (i = 1; i < points.size(); i++) {
Shinya Kitaoka 120a6e
    TPointD p1 = points.at(i);
Shinya Kitaoka 120a6e
    TPointD p2 = points.at(++i);
Shinya Kitaoka 120a6e
    TPointD p3 = points.at(++i);
Shinya Kitaoka 120a6e
    if (!isLinear) {
shun-iwasawa 0ed559
      // truncate speed
shun-iwasawa 0ed559
      TPointD aSpeed(p1 - p0);
shun-iwasawa 0ed559
      TPointD bSpeed(p2 - p3);
shun-iwasawa 0ed559
      truncateSpeeds(p0.x, p3.x, aSpeed, bSpeed);
Shinya Kitaoka 120a6e
      cubic.setP0(p0);
shun-iwasawa 0ed559
      cubic.setP1(p0 + aSpeed);
shun-iwasawa 0ed559
      cubic.setP2(p3 + bSpeed);
Shinya Kitaoka 120a6e
      cubic.setP3(p3);
Shinya Kitaoka 120a6e
      int x = (int)p0.x;
Shinya Kitaoka 120a6e
      while (x < 0) x++;
Shinya Kitaoka 120a6e
      while (x < p3.x && x < PIXEL::maxChannelValue + 1) {
Shinya Kitaoka 120a6e
        double s1 = 1.0;
Shinya Kitaoka 120a6e
        int y     = getCubicYfromX(cubic, x, s0, s1);
shun-iwasawa 0ed559
        if (y > PIXEL::maxChannelValue)
Shinya Kitaoka 120a6e
          y = PIXEL::maxChannelValue;
Shinya Kitaoka 120a6e
        else if (y < 0)
shun-iwasawa 0ed559
          y = 0;
Shinya Kitaoka 120a6e
        lut[x] = y;
Shinya Kitaoka 120a6e
        x++;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    } else {
Shinya Kitaoka 120a6e
      segment.setP0(p0);
Shinya Kitaoka 120a6e
      segment.setP1(p3);
Shinya Kitaoka 120a6e
      int x = (int)p0.x;
Shinya Kitaoka 120a6e
      while (x < 0) x++;
Shinya Kitaoka 120a6e
      while (x < p3.x && x < PIXEL::maxChannelValue + 1) {
Shinya Kitaoka 120a6e
        double s1 = 1.0;
Shinya Kitaoka 120a6e
        int y     = getLinearYfromX(segment, x, s0, s1);
shun-iwasawa 0ed559
        if (y > PIXEL::maxChannelValue)
Shinya Kitaoka 120a6e
          y = PIXEL::maxChannelValue;
Shinya Kitaoka 120a6e
        else if (y < 0)
shun-iwasawa 0ed559
          y = 0;
Shinya Kitaoka 120a6e
        lut[x] = y;
Shinya Kitaoka 120a6e
        x++;
Shinya Kitaoka 120a6e
      }
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
    p0 = p3;
Shinya Kitaoka 120a6e
  }
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
}  // Namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//===================================================================
Toshihiro Shimizu 890ddd
shun-iwasawa 8cac36
class ToneCurveFx final : public GlobalControllableFx {
Shinya Kitaoka 120a6e
  FX_PLUGIN_DECLARATION(ToneCurveFx)
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  TRasterFxPort m_input;
Shinya Kitaoka 120a6e
  TToneCurveParamP m_toneCurve;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
public:
Shinya Kitaoka 120a6e
  ToneCurveFx() : m_toneCurve(new TToneCurveParam()) {
Shinya Kitaoka 120a6e
    bindParam(this, "curve", m_toneCurve);
Shinya Kitaoka 120a6e
    addInputPort("Source", m_input);
shun-iwasawa 481b59
shun-iwasawa 481b59
    enableComputeInFloat(true);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  ~ToneCurveFx(){};
Shinya Kitaoka 120a6e
Shinya Kitaoka 38fd86
  bool canHandle(const TRenderSettings &info, double frame) override {
Shinya Kitaoka 38fd86
    return true;
Shinya Kitaoka 38fd86
  }
Shinya Kitaoka 120a6e
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
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 473e70
  void doCompute(TTile &tile, double frame, const TRenderSettings &ri) override;
Toshihiro Shimizu 890ddd
};
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
namespace {
Shinya Kitaoka 120a6e
void update_param(double ¶m, TRaster32P ras) { return; }
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void update_param(double ¶m, TRaster64P ras) {
Shinya Kitaoka 120a6e
  param = param * 257;
Shinya Kitaoka 120a6e
  return;
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
shun-iwasawa 481b59
void update_param(double ¶m, TRasterFP ras) {
shun-iwasawa 481b59
  param /= double(TPixel32::maxChannelValue);
shun-iwasawa 481b59
  return;
shun-iwasawa 481b59
}
shun-iwasawa 481b59
Shinya Kitaoka 120a6e
QList<tpointd> getParamSetPoints(const TParamSet *paramSet, int frame) {</tpointd>
Shinya Kitaoka 120a6e
  QList<tpointd> points;</tpointd>
Shinya Kitaoka 120a6e
  int i;
Shinya Kitaoka 120a6e
  for (i = 0; i < paramSet->getParamCount(); i++) {
Shinya Kitaoka 120a6e
    TPointParamP pointParam = paramSet->getParam(i);
Shinya Kitaoka 120a6e
    TPointD point           = pointParam->getValue(frame);
Shinya Kitaoka 120a6e
    int x                   = (int)point.x;
Shinya Kitaoka 120a6e
    int y                   = (int)point.y;
Shinya Kitaoka 120a6e
    points.push_back(TPointD(x, y));
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  return points;
Toshihiro Shimizu 890ddd
}
shun-iwasawa 0ed559
}  // namespace
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
template <typename channel_type="" pixel,="" typename=""></typename>
Shinya Kitaoka 120a6e
void doToneCurveFx(TRasterPT<pixel> ras, double frame,</pixel>
Shinya Kitaoka 120a6e
                   const TToneCurveParam *toneCurveParam) {
Shinya Kitaoka 120a6e
  QList<qlist<tpointd>> pointsList;</qlist<tpointd>
Shinya Kitaoka 120a6e
  int e;
Shinya Kitaoka 120a6e
  for (e = 0; e < 6; e++) {
Shinya Kitaoka 120a6e
    TParamSet *paramSet =
Shinya Kitaoka 120a6e
        toneCurveParam->getParamSet(TToneCurveParam::ToneChannel(e))
Shinya Kitaoka 120a6e
            .getPointer();
Shinya Kitaoka 120a6e
    QList<tpointd> points = getParamSetPoints(paramSet, frame);</tpointd>
Shinya Kitaoka 120a6e
    pointsList.push_back(points);
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  bool isLinear = toneCurveParam->isLinear();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int i, t;
Shinya Kitaoka 120a6e
  for (i = 0; i < pointsList.size(); i++) {
Shinya Kitaoka 120a6e
    QList<tpointd> &points = pointsList[i];</tpointd>
Shinya Kitaoka 120a6e
    for (t = 0; t < points.size(); t++) {
Shinya Kitaoka 120a6e
      TPointD &p = points[t];
Shinya Kitaoka 120a6e
      double &x  = p.x;
Shinya Kitaoka 120a6e
      double &y  = p.y;
Shinya Kitaoka 120a6e
      update_param(x, ras);
Shinya Kitaoka 120a6e
      update_param(y, ras);
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  std::vector<channel_type> rgbaLut(PIXEL::maxChannelValue + 1);</channel_type>
Shinya Kitaoka 120a6e
  std::vector<channel_type> rgbLut(PIXEL::maxChannelValue + 1);</channel_type>
Shinya Kitaoka 120a6e
  std::vector<channel_type> rLut(PIXEL::maxChannelValue + 1);</channel_type>
Shinya Kitaoka 120a6e
  std::vector<channel_type> gLut(PIXEL::maxChannelValue + 1);</channel_type>
Shinya Kitaoka 120a6e
  std::vector<channel_type> bLut(PIXEL::maxChannelValue + 1);</channel_type>
Shinya Kitaoka 120a6e
  std::vector<channel_type> aLut(PIXEL::maxChannelValue + 1);</channel_type>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  fill_lut<pixel, channel_type="">(pointsList[0], rgbaLut, isLinear);</pixel,>
Shinya Kitaoka 120a6e
  fill_lut<pixel, channel_type="">(pointsList[1], rgbLut, isLinear);</pixel,>
Shinya Kitaoka 120a6e
  fill_lut<pixel, channel_type="">(pointsList[2], rLut, isLinear);</pixel,>
Shinya Kitaoka 120a6e
  fill_lut<pixel, channel_type="">(pointsList[3], gLut, isLinear);</pixel,>
Shinya Kitaoka 120a6e
  fill_lut<pixel, channel_type="">(pointsList[4], bLut, isLinear);</pixel,>
Shinya Kitaoka 120a6e
  fill_lut<pixel, channel_type="">(pointsList[5], aLut, isLinear);</pixel,>
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int lx = ras->getLx();
Shinya Kitaoka 120a6e
  int ly = ras->getLy();
Shinya Kitaoka 120a6e
Shinya Kitaoka 120a6e
  int j;
Shinya Kitaoka 120a6e
  ras->lock();
Shinya Kitaoka 120a6e
  for (j = 0; j < ly; j++) {
Shinya Kitaoka 120a6e
    PIXEL *pix    = ras->pixels(j);
Shinya Kitaoka 120a6e
    PIXEL *endPix = pix + lx;
Shinya Kitaoka 120a6e
    while (pix < endPix) {
Shinya Kitaoka 120a6e
      if (pix->m != 0 && pix->m != PIXEL::maxChannelValue)
Shinya Kitaoka 120a6e
        *pix = depremultiply(*pix);
Shinya Kitaoka 120a6e
      pix->r = rLut[(int)(pix->r)];
Shinya Kitaoka 120a6e
      pix->g = gLut[(int)(pix->g)];
Shinya Kitaoka 120a6e
      pix->b = bLut[(int)(pix->b)];
Shinya Kitaoka 120a6e
      pix->m = aLut[(int)(pix->m)];
Shinya Kitaoka 120a6e
      pix->r = rgbLut[(int)(pix->r)];
Shinya Kitaoka 120a6e
      pix->g = rgbLut[(int)(pix->g)];
Shinya Kitaoka 120a6e
      pix->b = rgbLut[(int)(pix->b)];
Shinya Kitaoka 120a6e
      pix->r = rgbaLut[(int)(pix->r)];
Shinya Kitaoka 120a6e
      pix->g = rgbaLut[(int)(pix->g)];
Shinya Kitaoka 120a6e
      pix->b = rgbaLut[(int)(pix->b)];
Shinya Kitaoka 120a6e
      pix->m = rgbaLut[(int)(pix->m)];
Shinya Kitaoka 120a6e
      if (pix->m != 0 && pix->m != PIXEL::maxChannelValue)
Shinya Kitaoka 120a6e
        *pix = premultiply(*pix);
Shinya Kitaoka 120a6e
      pix++;
Shinya Kitaoka 120a6e
    }
Shinya Kitaoka 120a6e
  }
Shinya Kitaoka 120a6e
  ras->unlock();
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
shun-iwasawa 481b59
template <>
shun-iwasawa 481b59
void doToneCurveFx<tpixelf, float="">(TRasterFP ras, double frame,</tpixelf,>
shun-iwasawa 481b59
                                   const TToneCurveParam *toneCurveParam) {
shun-iwasawa 481b59
  QList<qlist<tpointd>> pointsList;</qlist<tpointd>
shun-iwasawa 481b59
  int e;
shun-iwasawa 481b59
  for (e = 0; e < 6; e++) {
shun-iwasawa 481b59
    TParamSet *paramSet =
shun-iwasawa 481b59
        toneCurveParam->getParamSet(TToneCurveParam::ToneChannel(e))
shun-iwasawa 481b59
            .getPointer();
shun-iwasawa 481b59
    QList<tpointd> points = getParamSetPoints(paramSet, frame);</tpointd>
shun-iwasawa 481b59
    pointsList.push_back(points);
shun-iwasawa 481b59
  }
shun-iwasawa 481b59
  bool isLinear = toneCurveParam->isLinear();
shun-iwasawa 481b59
shun-iwasawa 481b59
  int i, t;
shun-iwasawa 481b59
  for (i = 0; i < pointsList.size(); i++) {
shun-iwasawa 481b59
    QList<tpointd> &points = pointsList[i];</tpointd>
shun-iwasawa 481b59
    for (t = 0; t < points.size(); t++) {
shun-iwasawa 481b59
      TPointD &p = points[t];
shun-iwasawa 481b59
      double &x  = p.x;
shun-iwasawa 481b59
      double &y  = p.y;
shun-iwasawa 481b59
      update_param(x, TRaster64P());
shun-iwasawa 481b59
      update_param(y, TRaster64P());
shun-iwasawa 481b59
    }
shun-iwasawa 481b59
  }
shun-iwasawa 481b59
shun-iwasawa 481b59
  std::vector<ushort> rgbaLut(TPixel64::maxChannelValue + 1);</ushort>
shun-iwasawa 481b59
  std::vector<ushort> rgbLut(TPixel64::maxChannelValue + 1);</ushort>
shun-iwasawa 481b59
  std::vector<ushort> rLut(TPixel64::maxChannelValue + 1);</ushort>
shun-iwasawa 481b59
  std::vector<ushort> gLut(TPixel64::maxChannelValue + 1);</ushort>
shun-iwasawa 481b59
  std::vector<ushort> bLut(TPixel64::maxChannelValue + 1);</ushort>
shun-iwasawa 481b59
  std::vector<ushort> aLut(TPixel64::maxChannelValue + 1);</ushort>
shun-iwasawa 481b59
shun-iwasawa 481b59
  fill_lut<tpixel64, ushort="">(pointsList[0], rgbaLut, isLinear);</tpixel64,>
shun-iwasawa 481b59
  fill_lut<tpixel64, ushort="">(pointsList[1], rgbLut, isLinear);</tpixel64,>
shun-iwasawa 481b59
  fill_lut<tpixel64, ushort="">(pointsList[2], rLut, isLinear);</tpixel64,>
shun-iwasawa 481b59
  fill_lut<tpixel64, ushort="">(pointsList[3], gLut, isLinear);</tpixel64,>
shun-iwasawa 481b59
  fill_lut<tpixel64, ushort="">(pointsList[4], bLut, isLinear);</tpixel64,>
shun-iwasawa 481b59
  fill_lut<tpixel64, ushort="">(pointsList[5], aLut, isLinear);</tpixel64,>
shun-iwasawa 481b59
shun-iwasawa 481b59
  int lx = ras->getLx();
shun-iwasawa 481b59
  int ly = ras->getLy();
shun-iwasawa 481b59
shun-iwasawa 481b59
  std::vector<float> rLutF(TPixel64::maxChannelValue + 1);</float>
shun-iwasawa 481b59
  std::vector<float> gLutF(TPixel64::maxChannelValue + 1);</float>
shun-iwasawa 481b59
  std::vector<float> bLutF(TPixel64::maxChannelValue + 1);</float>
shun-iwasawa 481b59
  std::vector<float> aLutF(TPixel64::maxChannelValue + 1);</float>
shun-iwasawa 481b59
shun-iwasawa 481b59
  auto normalizeLut = [&](std::vector<float> &dst,</float>
shun-iwasawa 481b59
                          std::vector<ushort> &chanLut) {</ushort>
shun-iwasawa 481b59
    for (int i = 0; i <= TPixel64::maxChannelValue; i++) {
shun-iwasawa 481b59
      int v  = rgbaLut[rgbLut[chanLut[i]]];
shun-iwasawa 481b59
      dst[i] = float(v) / float(TPixel64::maxChannelValue);
shun-iwasawa 481b59
    }
shun-iwasawa 481b59
  };
shun-iwasawa 481b59
  normalizeLut(rLutF, rLut);
shun-iwasawa 481b59
  normalizeLut(gLutF, gLut);
shun-iwasawa 481b59
  normalizeLut(bLutF, bLut);
shun-iwasawa 481b59
  for (int i = 0; i <= TPixel64::maxChannelValue; i++) {
shun-iwasawa 481b59
    int v    = rgbaLut[aLut[i]];
shun-iwasawa 481b59
    aLutF[i] = float(v) / float(TPixel64::maxChannelValue);
shun-iwasawa 481b59
  }
shun-iwasawa 481b59
shun-iwasawa 481b59
  auto getLutValue = [&](std::vector<float> &lut, float val) {</float>
shun-iwasawa 481b59
    if (val < 0.f)
shun-iwasawa 481b59
      return lut[0];
shun-iwasawa 481b59
    else if (val >= 1.f)
shun-iwasawa 481b59
      return lut[TPixel64::maxChannelValue];
shun-iwasawa 481b59
    float v     = val * float(TPixel64::maxChannelValue);
shun-iwasawa 481b59
    int id      = (int)tfloor(v);
shun-iwasawa 481b59
    float ratio = v - float(id);
shun-iwasawa 481b59
    return lut[id] * (1.f - ratio) + lut[id + 1] * ratio;
shun-iwasawa 481b59
  };
shun-iwasawa 481b59
shun-iwasawa 481b59
  int j;
shun-iwasawa 481b59
  ras->lock();
shun-iwasawa 481b59
  for (j = 0; j < ly; j++) {
shun-iwasawa 481b59
    TPixelF *pix    = ras->pixels(j);
shun-iwasawa 481b59
    TPixelF *endPix = pix + lx;
shun-iwasawa 481b59
    while (pix < endPix) {
shun-iwasawa 481b59
      if (pix->m > 0.f) *pix = depremultiply(*pix);
shun-iwasawa 481b59
      pix->r = getLutValue(rLutF, pix->r);
shun-iwasawa 481b59
      pix->g = getLutValue(gLutF, pix->g);
shun-iwasawa 481b59
      pix->b = getLutValue(bLutF, pix->b);
shun-iwasawa 481b59
      pix->m = getLutValue(aLutF, pix->m);
shun-iwasawa 481b59
      if (pix->m > 0.f) *pix = premultiply(*pix);
shun-iwasawa 481b59
      pix++;
shun-iwasawa 481b59
    }
shun-iwasawa 481b59
  }
shun-iwasawa 481b59
  ras->unlock();
shun-iwasawa 481b59
}
Toshihiro Shimizu 890ddd
//-------------------------------------------------------------------
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
void ToneCurveFx::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();
shun-iwasawa 481b59
  TRaster64P raster64 = tile.getRaster();
shun-iwasawa 481b59
  TRasterFP rasterF   = tile.getRaster();
Toshihiro Shimizu 890ddd
Shinya Kitaoka 120a6e
  if (raster32)
Shinya Kitaoka 120a6e
    doToneCurveFx<tpixel32, uchar="">(raster32, frame, m_toneCurve.getPointer());</tpixel32,>
shun-iwasawa 481b59
  else if (raster64)
shun-iwasawa 481b59
    doToneCurveFx<tpixel64, ushort="">(raster64, frame, m_toneCurve.getPointer());</tpixel64,>
shun-iwasawa 481b59
  else if (rasterF)
shun-iwasawa 481b59
    doToneCurveFx<tpixelf, float="">(rasterF, frame, m_toneCurve.getPointer());</tpixelf,>
shun-iwasawa 481b59
  else
shun-iwasawa 481b59
    throw TException("Brightness&Contrast: unsupported Pixel Type");
Toshihiro Shimizu 890ddd
}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
FX_PLUGIN_IDENTIFIER(ToneCurveFx, "toneCurveFx");