Beispiel #1
0
void YUV_Init(void) {
   float y, u, v;
   int y_, cb, cr;

   if (initialised++) return;

   for (y_ = 0; y_ <= 255; y_++)
   {
      y = ((float) 255 / 219) * (y_ - 16);
      yuv_xy[y_] = ValidRange((int) (y));
   }

   for (cb = 0; cb <= 255; cb++)
   {
      u = ((float) 255 / 224) * (cb - 128);
      yuv_gu[cb] = - ValidRange((int) (0.344 * u));
      yuv_bu[cb] =   ValidRange((int) (1.772 * u));
   }

   for (cr = 0; cr <= 255; cr++)
   {
      v = ((float) 255 / 224) * (cr - 128);
      yuv_rv[cr] =   ValidRange((int) (1.402 * v));
      yuv_gv[cr] = - ValidRange((int) (0.714 * v));
   }
   TRACE("Filled hash table\n");
}
Beispiel #2
0
void RangeHistogram::mouseMoveEvent(QMouseEvent *e)
{
  QPoint pos = e->pos();
  if(ValidRange() && (e->buttons() & Qt::LeftButton) && pos != m_MousePrev)
  {
    if(m_DragMode == DraggingMode::White)
    {
      float newWhite = (float)(pos.x() - totalSpace()) / (float)regionWidth();

      setWhiteDelta(qBound(blackDelta() + m_MinRangeSize, newWhite, 1.0f));
    }
    else if(m_DragMode == DraggingMode::Black)
    {
      float newBlack = (float)(pos.x() - totalSpace()) / (float)regionWidth();

      setBlackDelta(qBound(0.0f, newBlack, whiteDelta() - m_MinRangeSize));
    }

    emit rangeUpdated();

    if(m_DragMode != DraggingMode::None)
      update();

    m_MousePrev = pos;
  }
}
Beispiel #3
0
float RangeHistogram::whiteDelta()
{
  if(!ValidRange())
    return 0.0f;

  return delta(m_WhitePoint);
}
Beispiel #4
0
float RangeHistogram::blackDelta()
{
  if(!ValidRange())
    return 0.0f;

  return delta(m_BlackPoint);
}
Beispiel #5
0
byte Motor::inStopRegion( )
{
	if ( ValidRange() )	return 0;
	if ( Value < Stop1_Value )	return 1;
	if ( Value > Stop2_Value )	return 2;
	return 0;
}
Beispiel #6
0
void RangeHistogram::mousePressEvent(QMouseEvent *e)
{
  if(e->button() != Qt::LeftButton || !ValidRange())
    return;

  QRect r = rect();

  r.marginsRemoved(QMargins(totalSpace(), totalSpace(), totalSpace(), totalSpace()));

  int whiteX = (int)(whiteDelta() * r.width());
  int blackX = (int)(blackDelta() * r.width());

  QPointF whiteVec(whiteX - e->pos().x(), rect().height() - e->pos().y());
  QPointF blackVec(blackX - e->pos().x(), e->pos().y());

  float whitedist = (float)sqrt(whiteVec.x() * whiteVec.x() + whiteVec.y() * whiteVec.y());
  float blackdist = (float)sqrt(blackVec.x() * blackVec.x() + blackVec.y() * blackVec.y());

  if(whitedist < blackdist && whitedist < 18.0f)
    m_DragMode = DraggingMode::White;
  else if(blackdist < whitedist && blackdist < 18.0f)
    m_DragMode = DraggingMode::Black;
  else if(e->pos().x() > whiteX)
    m_DragMode = DraggingMode::White;
  else if(e->pos().x() < blackX)
    m_DragMode = DraggingMode::Black;

  if(m_DragMode == DraggingMode::White)
  {
    float newWhite = (float)(e->pos().x() - totalSpace()) / (float)regionWidth();

    setWhiteDelta(qBound(blackDelta() + m_MinRangeSize, newWhite, 1.0f));
  }
  else if(m_DragMode == DraggingMode::Black)
  {
    float newBlack = (float)(e->pos().x() - totalSpace()) / (float)regionWidth();

    setBlackDelta(qBound(0.0f, newBlack, whiteDelta() - m_MinRangeSize));
  }

  emit rangeUpdated();

  if(m_DragMode != DraggingMode::None)
    update();

  m_MousePrev = e->pos();
}
Beispiel #7
0
void RangeHistogram::paintEvent(QPaintEvent *e)
{
  QPainter p(this);

  p.setRenderHint(QPainter::Antialiasing);

  const QBrush blackBrush(QColor(0, 0, 0));
  const QBrush redBrush(QColor(60, 0, 0));
  const QBrush greenBrush(QColor(0, 128, 0));
  const QBrush whiteBrush(QColor(255, 255, 255));

  QRectF r = rect();

  p.eraseRect(r);

  r = r.marginsRemoved(QMarginsF(m_Margin, m_Margin, m_Margin, m_Margin));

  p.fillRect(r, palette().brush(QPalette::Shadow));

  QMarginsF border(m_Border, m_Border, m_Border, m_Border);
  border /= devicePixelRatioF();

  r = r.marginsRemoved(border);

  p.fillRect(r, ValidRange() ? palette().brush(QPalette::Inactive, QPalette::Highlight) : redBrush);

  int whiteX = (int)(whiteDelta() * r.width());
  int blackX = (int)(blackDelta() * r.width() + 0.5);

  QRectF blackPoint(r.topLeft(), QSize(blackX, r.height()));
  QRectF whitePoint(r.left() + whiteX, r.top(), r.width() - whiteX, r.height());

  if(ValidRange())
  {
    p.setPen(QPen(palette().color(QPalette::Dark)));
    p.drawLine(blackPoint.topRight(), blackPoint.bottomRight());
    p.drawLine(whitePoint.topLeft(), whitePoint.bottomLeft());
  }

  p.fillRect(whitePoint, whiteBrush);
  p.fillRect(blackPoint, blackBrush);

  if(!ValidRange())
    return;

  if(!m_HistogramData.isEmpty())
  {
    float minx = delta(m_HistogramMin);
    float maxx = delta(m_HistogramMax);

    uint32_t maxval = 0;
    for(int i = 0; i < m_HistogramData.count(); i++)
    {
      float x = (float)i / (float)m_HistogramData.count();

      float xdelta = minx + x * (maxx - minx);

      if(xdelta >= 0.0f && xdelta <= 1.0f)
      {
        maxval = qMax(maxval, m_HistogramData[i]);
      }
    }

    if(maxval == 0)
      maxval = 1;

    for(int i = 0; i < m_HistogramData.count(); i++)
    {
      float x = (float)i / (float)m_HistogramData.count();
      float y = (float)m_HistogramData[i] / (float)maxval;

      float xdelta = minx + x * (maxx - minx);

      if(xdelta >= 0.0f && xdelta <= 1.0f)
      {
        float segwidth = qMax(r.width() * (maxx - minx) / (float)m_HistogramData.count(), 1.0);

        QRectF barRect(QPointF(r.left() + r.width() * (minx + x * (maxx - minx)),
                               r.bottom() - r.height() * y + 1),
                       QSizeF(segwidth, r.height() * y));

        p.fillRect(barRect, greenBrush);
      }
    }
  }

  QVector<QPointF> blackTriangle = {QPoint(blackPoint.right(), m_MarkerSize * 2),
                                    QPoint(blackPoint.right() + m_MarkerSize, 0),
                                    QPoint(blackPoint.right() - m_MarkerSize, 0)};

  QPainterPath blackPath;
  blackPath.addPolygon(QPolygonF(blackTriangle));
  p.fillPath(blackPath, palette().brush(QPalette::Dark));

  QVector<QPointF> whiteTriangle = {
      QPoint(whitePoint.left(), whitePoint.bottom() - m_MarkerSize * 2 + m_Margin),
      QPoint(whitePoint.left() + m_MarkerSize, whitePoint.bottom() + m_Margin),
      QPoint(whitePoint.left() - m_MarkerSize, whitePoint.bottom() + m_Margin)};

  QPainterPath whitePath;
  whitePath.addPolygon(QPolygonF(whiteTriangle));
  p.fillPath(whitePath, palette().brush(QPalette::Dark));

  blackTriangle[0] -= QPointF(0.0, 2.0) / devicePixelRatioF();
  blackTriangle[1] += QPointF(-2.0, 1.0) / devicePixelRatioF();
  blackTriangle[2] += QPointF(2.0, 1.0) / devicePixelRatioF();

  blackPath = QPainterPath();
  blackPath.addPolygon(QPolygonF(blackTriangle));

  whiteTriangle[0] += QPointF(0.0, 2.0) / devicePixelRatioF();
  whiteTriangle[1] -= QPointF(2.0, 1.0) / devicePixelRatioF();
  whiteTriangle[2] += QPointF(2.0, -1.0) / devicePixelRatioF();

  whitePath = QPainterPath();
  whitePath.addPolygon(QPolygonF(whiteTriangle));

  p.fillPath(blackPath, blackBrush);
  p.fillPath(whitePath, whiteBrush);
}
Beispiel #8
0
static inline void YUV2RGB(const unsigned char y_, const unsigned char cb, const unsigned char cr, RGB* retval) {
   retval->r = ValidRange(yuv_xy[y_] + yuv_rv[cr]);
   retval->g = ValidRange(yuv_xy[y_] + yuv_gu[cb] + yuv_gv[cr]);
   retval->b = ValidRange(yuv_xy[y_] + yuv_bu[cb]);
}