shun_iwasawa c0bf38
#include "iwa_timecodefx.h"
shun_iwasawa c0bf38
shun_iwasawa c0bf38
#include "tparamuiconcept.h"
shun_iwasawa c0bf38
shun_iwasawa c0bf38
#include <qfont></qfont>
shun_iwasawa c0bf38
#include <qfontmetrics></qfontmetrics>
shun_iwasawa c0bf38
#include <qimage></qimage>
shun_iwasawa c0bf38
#include <qpainter></qpainter>
shun_iwasawa c0bf38
//------------------------------------------------------------------
shun_iwasawa c0bf38
shun_iwasawa c0bf38
Iwa_TimeCodeFx::Iwa_TimeCodeFx()
shun_iwasawa c0bf38
    : m_displayType(new TIntEnumParam(TYPE_HHMMSSFF, "HH;MM;SS;FF"))
shun_iwasawa c0bf38
    , m_frameRate(24)
shun_iwasawa c0bf38
    , m_startFrame(0)
shun_iwasawa c0bf38
    , m_position(TPointD(0.0, 0.0))
shun_iwasawa c0bf38
    , m_size(25)
shun_iwasawa c0bf38
    , m_textColor(TPixel32::White)
shun_iwasawa c0bf38
    , m_showBox(true)
shun_iwasawa c0bf38
    , m_boxColor(TPixel32::Black) {
manongjohn bf6c84
  m_displayType->addItem(TYPE_HHMMSSFF2, "HH:MM:SS:FF");
shun_iwasawa c0bf38
  m_displayType->addItem(TYPE_FRAME, "Frame Number");
shun_iwasawa c0bf38
  m_position->getX()->setMeasureName("fxLength");
shun_iwasawa c0bf38
  m_position->getY()->setMeasureName("fxLength");
shun_iwasawa c0bf38
  m_size->setMeasureName("fxLength");
shun_iwasawa c0bf38
  m_size->setValueRange(0.1, (std::numeric_limits<double>::max)());</double>
shun_iwasawa c0bf38
shun_iwasawa c0bf38
  bindParam(this, "displayType", m_displayType);
shun_iwasawa c0bf38
  bindParam(this, "frameRate", m_frameRate);
shun_iwasawa c0bf38
  bindParam(this, "startFrame", m_startFrame);
shun_iwasawa c0bf38
  bindParam(this, "position", m_position);
shun_iwasawa c0bf38
  bindParam(this, "size", m_size);
shun_iwasawa c0bf38
  bindParam(this, "textColor", m_textColor);
shun_iwasawa c0bf38
  bindParam(this, "showBox", m_showBox);
shun_iwasawa c0bf38
  bindParam(this, "boxColor", m_boxColor);
shun_iwasawa c0bf38
}
shun_iwasawa c0bf38
shun_iwasawa c0bf38
//------------------------------------------------------------------
shun_iwasawa c0bf38
shun_iwasawa c0bf38
bool Iwa_TimeCodeFx::doGetBBox(double frame, TRectD &bBox,
shun_iwasawa c0bf38
                               const TRenderSettings &ri) {
shun_iwasawa c0bf38
  bBox = TConsts::infiniteRectD;
shun_iwasawa c0bf38
  return true;
shun_iwasawa c0bf38
}
shun_iwasawa c0bf38
shun_iwasawa c0bf38
//------------------------------------------------------------------
shun_iwasawa c0bf38
shun_iwasawa c0bf38
void Iwa_TimeCodeFx::doCompute(TTile &tile, double frame,
shun_iwasawa c0bf38
                               const TRenderSettings &ri) {
shun_iwasawa c0bf38
  double fac   = sqrt(fabs(ri.m_affine.det()));
shun_iwasawa c0bf38
  int size     = (int)(fac * fabs(m_size->getValue(frame)));
shun_iwasawa c0bf38
  TPoint point = convert(
shun_iwasawa c0bf38
      fac * m_position->getValue(frame) -
shun_iwasawa c0bf38
      (tile.m_pos + tile.getRaster()->getCenterD()) +
shun_iwasawa c0bf38
      TPointD(ri.m_cameraBox.getLx() / 2.0, ri.m_cameraBox.getLy() / 2.0));
shun_iwasawa ddeca6
#ifdef _WIN32
shun_iwasawa c0bf38
  QFont font("Arial", size);
shun_iwasawa ddeca6
#else
shun_iwasawa ddeca6
  QFont font("Helvetica", size);
shun_iwasawa ddeca6
#endif
shun_iwasawa c0bf38
  font.setWeight(QFont::Normal);
shun_iwasawa c0bf38
  QFontMetrics fm(font);
shun_iwasawa c0bf38
  QString timeCodeStr = getTimeCodeStr(frame, ri);
shun-iwasawa 443318
  int width           = fm.horizontalAdvance(timeCodeStr);
shun_iwasawa c0bf38
  int height          = fm.height();
shun_iwasawa c0bf38
shun_iwasawa c0bf38
  QImage img(width, height, QImage::Format_ARGB32);
shun_iwasawa c0bf38
shun_iwasawa c0bf38
  if (m_showBox->getValue()) {
shun_iwasawa c0bf38
    TPixel32 boxColor = m_boxColor->getValue(frame);
shun_iwasawa c0bf38
    img.fill(QColor((int)boxColor.r, (int)boxColor.g, (int)boxColor.b,
shun_iwasawa c0bf38
                    (int)boxColor.m));
shun_iwasawa c0bf38
  } else
shun_iwasawa c0bf38
    img.fill(Qt::transparent);
shun_iwasawa c0bf38
shun_iwasawa c0bf38
  QPainter painter(&img);
shun_iwasawa c0bf38
  TPixel32 color = m_textColor->getValue(frame);
shun_iwasawa c0bf38
  painter.setPen(
shun_iwasawa c0bf38
      QColor((int)color.r, (int)color.g, (int)color.b, (int)color.m));
shun_iwasawa c0bf38
  painter.setFont(font);
shun_iwasawa c0bf38
  painter.drawText(QPoint(0, fm.ascent()), timeCodeStr);
shun_iwasawa c0bf38
shun_iwasawa c0bf38
  tile.getRaster()->clear();
shun_iwasawa c0bf38
  TRaster32P ras32 = (TRaster32P)tile.getRaster();
shun_iwasawa c0bf38
  TRaster64P ras64 = (TRaster64P)tile.getRaster();
shun_iwasawa c0bf38
  if (ras32)
shun_iwasawa c0bf38
    putTimeCodeImage<traster32p, tpixel32="">(ras32, point, img);</traster32p,>
shun_iwasawa c0bf38
  else if (ras64)
shun_iwasawa c0bf38
    putTimeCodeImage<traster64p, tpixel64="">(ras64, point, img);</traster64p,>
shun_iwasawa c0bf38
  else
shun_iwasawa c0bf38
    throw TException("Iwa_TimeCodeFx: unsupported Pixel Type");
shun_iwasawa c0bf38
}
shun_iwasawa c0bf38
shun_iwasawa c0bf38
//------------------------------------------------------------------
shun_iwasawa c0bf38
shun_iwasawa c0bf38
void Iwa_TimeCodeFx::getParamUIs(TParamUIConcept *&concepts, int &length) {
shun_iwasawa c0bf38
  concepts = new TParamUIConcept[length = 1];
shun_iwasawa c0bf38
shun_iwasawa c0bf38
  concepts[0].m_type  = TParamUIConcept::POINT;
shun_iwasawa c0bf38
  concepts[0].m_label = "Position";
shun_iwasawa c0bf38
  concepts[0].m_params.push_back(m_position);
shun_iwasawa c0bf38
}
shun_iwasawa c0bf38
shun_iwasawa c0bf38
//------------------------------------------------------------------
shun_iwasawa c0bf38
shun_iwasawa c0bf38
std::string Iwa_TimeCodeFx::getAlias(double frame,
shun_iwasawa c0bf38
                                     const TRenderSettings &info) const {
shun_iwasawa c0bf38
  std::string alias = getFxType();
shun_iwasawa c0bf38
  alias += "[";
shun_iwasawa c0bf38
shun_iwasawa c0bf38
  std::string paramalias("");
shun_iwasawa c0bf38
  for (int i = 0; i < getParams()->getParamCount(); ++i) {
shun_iwasawa c0bf38
    TParam *param = getParams()->getParam(i);
shun_iwasawa c0bf38
    paramalias += param->getName() + "=" + param->getValueAlias(frame, 3);
shun_iwasawa c0bf38
  }
shun_iwasawa c0bf38
shun_iwasawa c0bf38
  return alias + std::to_string(frame) + "," + std::to_string(getIdentifier()) +
shun_iwasawa c0bf38
         paramalias + "]";
shun_iwasawa c0bf38
}
shun_iwasawa c0bf38
shun_iwasawa c0bf38
//------------------------------------------------------------------
shun_iwasawa c0bf38
shun_iwasawa c0bf38
QString Iwa_TimeCodeFx::getTimeCodeStr(double frame,
shun_iwasawa c0bf38
                                       const TRenderSettings &ri) {
shun_iwasawa c0bf38
  int f = (int)frame + m_startFrame->getValue();
shun_iwasawa c0bf38
manongjohn bf6c84
  if (m_displayType->getValue() != TYPE_FRAME) {
manongjohn bf6c84
    QString separator =
manongjohn bf6c84
        (m_displayType->getValue() == TYPE_HHMMSSFF ? ";" : ":");
shun_iwasawa c0bf38
    bool neg = (f < 0);
shun_iwasawa c0bf38
    f        = abs(f);
shun_iwasawa c0bf38
    int fps  = m_frameRate->getValue();
shun_iwasawa c0bf38
    int hh   = f / (fps * 60 * 60);
shun_iwasawa c0bf38
    f -= hh * fps * 60 * 60;
shun_iwasawa c0bf38
    int mm = f / (fps * 60);
shun_iwasawa c0bf38
    f -= mm * fps * 60;
shun_iwasawa c0bf38
    int ss = f / fps;
shun_iwasawa c0bf38
    int ff = f % fps;
shun_iwasawa c0bf38
    return QString((neg) ? "-" : "") +
manongjohn bf6c84
           QString::number(hh).rightJustified(2, '0') + separator +
manongjohn bf6c84
           QString::number(mm).rightJustified(2, '0') + separator +
manongjohn bf6c84
           QString::number(ss).rightJustified(2, '0') + separator +
shun_iwasawa c0bf38
           QString::number(ff).rightJustified(2, '0');
shun_iwasawa c0bf38
  } else {   // TYPE_FRAMENUMBER
shun_iwasawa c0bf38
    f += 1;  // starting from "000001" with no frame offset.
shun_iwasawa c0bf38
    return QString((f < 0) ? "-" : "") +
shun_iwasawa c0bf38
           QString::number(abs(f)).rightJustified(6, '0');
shun_iwasawa c0bf38
  }
shun_iwasawa c0bf38
}
shun_iwasawa c0bf38
shun_iwasawa c0bf38
//------------------------------------------------------------------
shun_iwasawa c0bf38
shun_iwasawa c0bf38
template <typename pixel="" raster,="" typename=""></typename>
shun_iwasawa c0bf38
void Iwa_TimeCodeFx::putTimeCodeImage(const RASTER srcRas, TPoint &pos,
shun_iwasawa c0bf38
                                      QImage &img) {
shun_iwasawa c0bf38
  for (int j = 0; j < img.height(); j++) {
shun_iwasawa c0bf38
    int rasY = pos.y + j;
shun_iwasawa c0bf38
    if (rasY < 0) continue;
shun_iwasawa c0bf38
    if (srcRas->getLy() <= rasY) break;
shun_iwasawa c0bf38
shun_iwasawa c0bf38
    PIXEL *pix  = srcRas->pixels(rasY);
shun_iwasawa c0bf38
    QRgb *img_p = (QRgb *)img.scanLine(img.height() - j - 1);
shun_iwasawa c0bf38
    for (int i = 0; i < img.width(); i++, img_p++) {
shun_iwasawa c0bf38
      int rasX = pos.x + i;
shun_iwasawa c0bf38
      if (rasX < 0) continue;
shun_iwasawa c0bf38
      if (srcRas->getLx() <= rasX) break;
shun_iwasawa c0bf38
shun_iwasawa ddeca6
      pix[rasX].r = (typename PIXEL::Channel)(
shun_iwasawa c0bf38
          qRed(*img_p) * (int)PIXEL::maxChannelValue / (int)UCHAR_MAX);
shun_iwasawa ddeca6
      pix[rasX].g = (typename PIXEL::Channel)(
shun_iwasawa c0bf38
          qGreen(*img_p) * (int)PIXEL::maxChannelValue / (int)UCHAR_MAX);
shun_iwasawa ddeca6
      pix[rasX].b = (typename PIXEL::Channel)(
shun_iwasawa c0bf38
          qBlue(*img_p) * (int)PIXEL::maxChannelValue / (int)UCHAR_MAX);
shun_iwasawa ddeca6
      pix[rasX].m = (typename PIXEL::Channel)(
shun_iwasawa c0bf38
          qAlpha(*img_p) * (int)PIXEL::maxChannelValue / (int)UCHAR_MAX);
shun_iwasawa c0bf38
    }
shun_iwasawa c0bf38
  }
shun_iwasawa c0bf38
}
shun_iwasawa c0bf38
shun_iwasawa c0bf38
//==============================================================================
shun_iwasawa c0bf38
shun_iwasawa c0bf38
FX_PLUGIN_IDENTIFIER(Iwa_TimeCodeFx, "iwa_TimeCodeFx");