Qt 4.8
Classes | Macros | Typedefs | Functions
qrasterizer.cpp File Reference
#include "qrasterizer_p.h"
#include <QPoint>
#include <QRect>
#include <private/qmath_p.h>
#include <private/qdatabuffer_p.h>
#include <private/qdrawhelper_p.h>

Go to the source code of this file.

Classes

struct  QBoolToType< B >
 
class  QRasterizerPrivate
 
class  QScanConverter
 
struct  QScanConverter::Intersection
 
struct  QScanConverter::Line
 
class  QSpanBuffer
 

Macros

#define CHUNK_SIZE   64
 
#define COORD_OFFSET   32
 
#define COORD_ROUNDING   1
 
#define DO_SEGMENT(next, li, ri, ls, rs)
 
#define FloatToQ16Dot16(i)   (int)((i) * qreal(65536.))
 
#define IntToQ16Dot16(i)   ((i) << 16)
 
#define Q16Dot16Factor   65536
 
#define Q16Dot16FastMultiply(x, y)   (((x) * (y)) >> 16)
 
#define Q16Dot16Multiply(x, y)   (int)((qlonglong(x) * qlonglong(y)) >> 16)
 
#define Q16Dot16ToFloat(i)   ((i)/qreal(65536.))
 
#define Q16Dot16ToInt(i)   ((i) >> 16)
 
#define SPAN_BUFFER_SIZE   256
 

Typedefs

typedef int Q16Dot16
 

Functions

static Q16Dot16 intersectPixelFP (int x, Q16Dot16 top, Q16Dot16 bottom, Q16Dot16 leftIntersectX, Q16Dot16 rightIntersectX, Q16Dot16 slope, Q16Dot16 invSlope)
 
static QT_FT_Vector PointToVector (const QPointF &p)
 
static bool q26Dot6Compare (qreal p1, qreal p2)
 
static qreal qFloorF (qreal v)
 
static qreal qSafeDivide (qreal x, qreal y)
 
static int qSafeFloatToQ16Dot16 (qreal x)
 
template<typename T >
void qScanConvert (QScanConverter &d, T allVertical)
 
static QPointF snapTo26Dot6Grid (const QPointF &p)
 
static void split (QT_FT_Vector *b)
 
static bool topOrder (const QScanConverter::Line &a, const QScanConverter::Line &b)
 
static bool xOrder (const QScanConverter::Line *a, const QScanConverter::Line *b)
 

Macro Definition Documentation

◆ CHUNK_SIZE

#define CHUNK_SIZE   64

◆ COORD_OFFSET

#define COORD_OFFSET   32

◆ COORD_ROUNDING

#define COORD_ROUNDING   1

◆ DO_SEGMENT

#define DO_SEGMENT (   next,
  li,
  ri,
  ls,
  rs 
)
Value:
ny = qMin(next + 1, d->clipRect.top()); \
if (y < ny) { \
li += ls * (ny - y); \
ri += rs * (ny - y); \
y = ny; \
} \
if (next > d->clipRect.bottom()) \
next = d->clipRect.bottom(); \
for (; y <= next; ++y) { \
const int x1 = qMax(Q16Dot16ToInt(li), d->clipRect.left()); \
const int x2 = qMin(Q16Dot16ToInt(ri), d->clipRect.right()); \
if (x2 >= x1) \
buffer.addSpan(x1, x2 - x1 + 1, y, 255); \
li += ls; \
ri += rs; \
}
double d
Definition: qnumeric_p.h:62
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
#define Q16Dot16ToInt(i)
Definition: qrasterizer.cpp:57

Referenced by QRasterizer::rasterizeLine().

◆ FloatToQ16Dot16

#define FloatToQ16Dot16 (   i)    (int)((i) * qreal(65536.))

Definition at line 55 of file qrasterizer.cpp.

Referenced by QScanConverter::mergeLine(), and QRasterizer::rasterizeLine().

◆ IntToQ16Dot16

#define IntToQ16Dot16 (   i)    ((i) << 16)

◆ Q16Dot16Factor

#define Q16Dot16Factor   65536

◆ Q16Dot16FastMultiply

#define Q16Dot16FastMultiply (   x,
 
)    (((x) * (y)) >> 16)

Definition at line 61 of file qrasterizer.cpp.

Referenced by intersectPixelFP().

◆ Q16Dot16Multiply

#define Q16Dot16Multiply (   x,
 
)    (int)((qlonglong(x) * qlonglong(y)) >> 16)

◆ Q16Dot16ToFloat

#define Q16Dot16ToFloat (   i)    ((i)/qreal(65536.))

Definition at line 54 of file qrasterizer.cpp.

Referenced by QScanConverter::clip().

◆ Q16Dot16ToInt

#define Q16Dot16ToInt (   i)    ((i) >> 16)

◆ SPAN_BUFFER_SIZE

#define SPAN_BUFFER_SIZE   256

Definition at line 63 of file qrasterizer.cpp.

Referenced by QSpanBuffer::addSpan().

Typedef Documentation

◆ Q16Dot16

typedef int Q16Dot16

Definition at line 53 of file qrasterizer.cpp.

Function Documentation

◆ intersectPixelFP()

static Q16Dot16 intersectPixelFP ( int  x,
Q16Dot16  top,
Q16Dot16  bottom,
Q16Dot16  leftIntersectX,
Q16Dot16  rightIntersectX,
Q16Dot16  slope,
Q16Dot16  invSlope 
)
static

Definition at line 661 of file qrasterizer.cpp.

Referenced by QRasterizer::rasterizeLine().

662 {
663  Q16Dot16 leftX = IntToQ16Dot16(x);
664  Q16Dot16 rightX = IntToQ16Dot16(x) + Q16Dot16Factor;
665 
666  Q16Dot16 leftIntersectY, rightIntersectY;
667  if (slope > 0) {
668  leftIntersectY = top + Q16Dot16Multiply(leftX - leftIntersectX, invSlope);
669  rightIntersectY = leftIntersectY + invSlope;
670  } else {
671  leftIntersectY = top + Q16Dot16Multiply(leftX - rightIntersectX, invSlope);
672  rightIntersectY = leftIntersectY + invSlope;
673  }
674 
675  if (leftIntersectX >= leftX && rightIntersectX <= rightX) {
676  return Q16Dot16Multiply(bottom - top, leftIntersectX - leftX + ((rightIntersectX - leftIntersectX) >> 1));
677  } else if (leftIntersectX >= rightX) {
678  return bottom - top;
679  } else if (leftIntersectX >= leftX) {
680  if (slope > 0) {
681  return (bottom - top) - Q16Dot16FastMultiply((rightX - leftIntersectX) >> 1, rightIntersectY - top);
682  } else {
683  return (bottom - top) - Q16Dot16FastMultiply((rightX - leftIntersectX) >> 1, bottom - rightIntersectY);
684  }
685  } else if (rightIntersectX <= leftX) {
686  return 0;
687  } else if (rightIntersectX <= rightX) {
688  if (slope > 0) {
689  return Q16Dot16FastMultiply((rightIntersectX - leftX) >> 1, bottom - leftIntersectY);
690  } else {
691  return Q16Dot16FastMultiply((rightIntersectX - leftX) >> 1, leftIntersectY - top);
692  }
693  } else {
694  if (slope > 0) {
695  return (bottom - rightIntersectY) + ((rightIntersectY - leftIntersectY) >> 1);
696  } else {
697  return (rightIntersectY - top) + ((leftIntersectY - rightIntersectY) >> 1);
698  }
699  }
700 }
#define Q16Dot16Factor
Definition: qrasterizer.cpp:58
#define Q16Dot16Multiply(x, y)
Definition: qrasterizer.cpp:60
#define Q16Dot16FastMultiply(x, y)
Definition: qrasterizer.cpp:61
#define IntToQ16Dot16(i)
Definition: qrasterizer.cpp:56
int Q16Dot16
Definition: qrasterizer.cpp:53

◆ PointToVector()

static QT_FT_Vector PointToVector ( const QPointF p)
inlinestatic

Definition at line 68 of file qrasterizer.cpp.

Referenced by QRasterizer::rasterize().

69 {
70  QT_FT_Vector result = { QT_FT_Pos(p.x() * 64), QT_FT_Pos(p.y() * 64) };
71  return result;
72 }
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
QT_FT_BEGIN_HEADER typedef signed int QT_FT_Pos

◆ q26Dot6Compare()

static bool q26Dot6Compare ( qreal  p1,
qreal  p2 
)
inlinestatic

Definition at line 702 of file qrasterizer.cpp.

Referenced by QRasterizer::rasterizeLine().

703 {
704  return int((p2 - p1) * qreal(64.)) == 0;
705 }
double qreal
Definition: qglobal.h:1193

◆ qFloorF()

static qreal qFloorF ( qreal  v)
inlinestatic

Definition at line 707 of file qrasterizer.cpp.

Referenced by snapTo26Dot6Grid().

708 {
709 #ifdef QT_USE_MATH_H_FLOATS
710  if (sizeof(qreal) == sizeof(float))
711  return floorf(v);
712  else
713 #endif
714  return floor(v);
715 }
double qreal
Definition: qglobal.h:1193
T floor(const T &a)

◆ qSafeDivide()

static qreal qSafeDivide ( qreal  x,
qreal  y 
)
inlinestatic

Definition at line 731 of file qrasterizer.cpp.

Referenced by QRasterizer::rasterizeLine().

732 {
733  if (y == 0)
734  return x > 0 ? 1e20 : -1e20;
735  return x / y;
736 }

◆ qSafeFloatToQ16Dot16()

static int qSafeFloatToQ16Dot16 ( qreal  x)
inlinestatic

Definition at line 742 of file qrasterizer.cpp.

Referenced by QRasterizer::rasterizeLine().

743 {
744  qreal tmp = x * 65536.;
745  if (tmp > qreal(INT_MAX))
746  return INT_MAX;
747  else if (tmp < qreal(INT_MIN))
748  return -INT_MAX;
749  return int(tmp);
750 }
double qreal
Definition: qglobal.h:1193
#define INT_MAX

◆ qScanConvert()

template<typename T >
void qScanConvert ( QScanConverter d,
allVertical 
)

Definition at line 319 of file qrasterizer.cpp.

320 {
321  if (!d.m_lines.size()) {
322  d.m_active.reset();
323  return;
324  }
325  qSort(d.m_lines.data(), d.m_lines.data() + d.m_lines.size(), QT_PREPEND_NAMESPACE(topOrder));
326  int line = 0;
327  for (int y = d.m_lines.first().top; y <= d.m_bottom; ++y) {
328  for (; line < d.m_lines.size() && d.m_lines.at(line).top == y; ++line) {
329  // add node to active list
330  if (allVertical()) {
331  QScanConverter::Line *l = &d.m_lines.at(line);
332  d.m_active.resize(d.m_active.size() + 1);
333  int j;
334  for (j = d.m_active.size() - 2; j >= 0 && QT_PREPEND_NAMESPACE(xOrder)(l, d.m_active.at(j)); --j)
335  d.m_active.at(j+1) = d.m_active.at(j);
336  d.m_active.at(j+1) = l;
337  } else {
338  d.m_active << &d.m_lines.at(line);
339  }
340  }
341 
342  int numActive = d.m_active.size();
343  if (!allVertical()) {
344  // use insertion sort instead of qSort, as the active edge list is quite small
345  // and in the average case already sorted
346  for (int i = 1; i < numActive; ++i) {
347  QScanConverter::Line *l = d.m_active.at(i);
348  int j;
349  for (j = i-1; j >= 0 && QT_PREPEND_NAMESPACE(xOrder)(l, d.m_active.at(j)); --j)
350  d.m_active.at(j+1) = d.m_active.at(j);
351  d.m_active.at(j+1) = l;
352  }
353  }
354 
355  int x = 0;
356  int winding = 0;
357  for (int i = 0; i < numActive; ++i) {
358  QScanConverter::Line *node = d.m_active.at(i);
359 
360  const int current = Q16Dot16ToInt(node->x);
361  if (winding & d.m_fillRuleMask)
362  d.m_spanBuffer->addSpan(x, current - x, y, 0xff);
363 
364  x = current;
365  winding += node->winding;
366 
367  if (node->bottom == y) {
368  // remove node from active list
369  for (int j = i; j < numActive - 1; ++j)
370  d.m_active.at(j) = d.m_active.at(j+1);
371 
372  d.m_active.resize(--numActive);
373  --i;
374  } else if (!allVertical())
375  node->x += node->delta;
376  }
377  }
378  d.m_active.reset();
379 }
QSpanBuffer * m_spanBuffer
QDataBuffer< Line > m_lines
void addSpan(int x, unsigned int len, int y, unsigned char coverage)
Definition: qrasterizer.cpp:89
QDataBuffer< Line * > m_active
static bool topOrder(const QScanConverter::Line &a, const QScanConverter::Line &b)
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
static bool xOrder(const QScanConverter::Line *a, const QScanConverter::Line *b)
#define Q16Dot16ToInt(i)
Definition: qrasterizer.cpp:57
QFactoryLoader * l

◆ snapTo26Dot6Grid()

static QPointF snapTo26Dot6Grid ( const QPointF p)
inlinestatic

Definition at line 717 of file qrasterizer.cpp.

Referenced by QRasterizer::rasterizeLine().

718 {
719  return QPointF(qFloorF(p.x() * 64) * (1 / qreal(64)),
720  qFloorF(p.y() * 64) * (1 / qreal(64)));
721 }
double qreal
Definition: qglobal.h:1193
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
static qreal qFloorF(qreal v)
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ split()

static void split ( QT_FT_Vector b)
static

Definition at line 274 of file qrasterizer.cpp.

Referenced by QItemSelectionModelPrivate::_q_columnsAboutToBeInserted(), QItemSelectionModelPrivate::_q_rowsAboutToBeInserted(), QCoreApplication::applicationFilePath(), QDBusAbstractInterface::callWithArgumentList(), QDeclarativeCompiler::deferredProperties(), QNativeWifiEngine::disconnectFromId(), QIntersectionFinder::hasIntersections(), QByteArray::isSharedWith(), QStringList::lastIndexOf(), QItemSelection::merge(), QScanConverter::mergeCurve(), QXlibMime::mimeConvertToFormat(), QStringList::operator<<(), QBezier::pt4(), QItemSelection::QItemSelection(), QTextDocumentPrivate::setDefaultFont(), QTriangulator< T >::ComplexToSimple::splitEdge(), QTriangulator< T >::ComplexToSimple::splitEdgeListRange(), and QX11Data::xdndMimeConvertToFormat().

275 {
276  b[6] = b[3];
277 
278  {
279  const QT_FT_Pos temp = (b[1].x + b[2].x)/2;
280 
281  b[1].x = (b[0].x + b[1].x)/2;
282  b[5].x = (b[2].x + b[3].x)/2;
283  b[2].x = (b[1].x + temp)/2;
284  b[4].x = (b[5].x + temp)/2;
285  b[3].x = (b[2].x + b[4].x)/2;
286  }
287  {
288  const QT_FT_Pos temp = (b[1].y + b[2].y)/2;
289 
290  b[1].y = (b[0].y + b[1].y)/2;
291  b[5].y = (b[2].y + b[3].y)/2;
292  b[2].y = (b[1].y + temp)/2;
293  b[4].y = (b[5].y + temp)/2;
294  b[3].y = (b[2].y + b[4].y)/2;
295  }
296 }
QT_FT_BEGIN_HEADER typedef signed int QT_FT_Pos

◆ topOrder()

static bool topOrder ( const QScanConverter::Line a,
const QScanConverter::Line b 
)
inlinestatic

Definition at line 298 of file qrasterizer.cpp.

Referenced by qScanConvert().

299 {
300  return a.top < b.top;
301 }

◆ xOrder()

static bool xOrder ( const QScanConverter::Line a,
const QScanConverter::Line b 
)
inlinestatic

Definition at line 303 of file qrasterizer.cpp.

Referenced by qScanConvert().

304 {
305  return a->x < b->x;
306 }