Qt 4.8
Classes | Macros | Enumerations | Functions | Variables
qpaintengine_raster.cpp File Reference
#include <QtCore/qglobal.h>
#include <QtCore/qmutex.h>
#include <private/qrasterdefs_p.h>
#include <private/qgrayraster_p.h>
#include <qpainterpath.h>
#include <qdebug.h>
#include <qhash.h>
#include <qlabel.h>
#include <qbitmap.h>
#include <qmath.h>
#include <private/qfontengine_ft_p.h>
#include <private/qmath_p.h>
#include <private/qtextengine_p.h>
#include <private/qfontengine_p.h>
#include <private/qpixmap_raster_p.h>
#include <private/qimage_p.h>
#include <private/qstatictext_p.h>
#include <private/qcosmeticstroker_p.h>
#include "qmemrotate_p.h"
#include "qpaintengine_raster_p.h"
#include "qoutlinemapper_p.h"
#include <qt_windows.h>
#include <qvarlengtharray.h>
#include "qguifunctions_wince.h"
#include <limits.h>

Go to the source code of this file.

Classes

struct  ClipData
 
class  QGradientCache
 
struct  QGradientCache::CacheInfo
 
struct  QRasterFloatPoint
 

Macros

#define int_dim(pos, dim)   (int(pos+dim) - int(pos))
 
#define qreal_to_fixed_26_6(f)   (int(f * 64))
 
#define QT_FAST_SPANS
 
#define QT_FT_BEGIN_HEADER
 
#define QT_FT_END_HEADER
 
#define qt_swap_int(x, y)   { int tmp = (x); (x) = (y); (y) = tmp; }
 
#define qt_swap_qreal(x, y)   { qreal tmp = (x); (x) = (y); (y) = tmp; }
 

Enumerations

enum  LineDrawMode { LineDrawClipped, LineDrawNormal, LineDrawIncludeLastPixel }
 
enum  RotationType
 

Functions

static ucharalignAddress (uchar *address, quintptr alignmentMask)
 
static void drawEllipse_midpoint_i (const QRect &rect, const QRect &clip, ProcessSpans pen_func, ProcessSpans brush_func, QSpanData *pen_data, QSpanData *brush_data)
 Draws an ellipse using the integer point midpoint algorithm. More...
 
static void drawEllipsePoints (int x, int y, int length, const QRect &rect, const QRect &clip, ProcessSpans pen_func, ProcessSpans brush_func, QSpanData *pen_data, QSpanData *brush_data)
 
static int fast_ceil_positive (const qreal &v)
 
static void fillRect_normalized (const QRect &r, QSpanData *data, QRasterPaintEnginePrivate *pe)
 
static bool isAbove (const QPointF *a, const QPointF *b)
 
template<typename T >
static bool isRect (const T *pts, int elementCount)
 
static bool monoVal (const uchar *s, int x)
 
int q_gray_rendered_spans (QT_FT_Raster raster)
 
static void qrasterpaintengine_dirty_clip (QRasterPaintEnginePrivate *d, QRasterPaintEngineState *s)
 
static void qrasterpaintengine_state_setNoClip (QRasterPaintEngineState *s)
 
static void qt_ft_outline_cubic_to (qfixed c1x, qfixed c1y, qfixed c2x, qfixed c2y, qfixed ex, qfixed ey, void *data)
 
static void qt_ft_outline_line_to (qfixed x, qfixed y, void *data)
 
static void qt_ft_outline_move_to (qfixed x, qfixed y, void *data)
 
const QVector< QRgb > * qt_image_colortable (const QImage &image)
 
Q_GUI_EXPORT QImage qt_imageForBrush (int brushStyle, bool invert)
 
static const QSpanqt_intersect_spans (const QClipData *clip, int *currentClip, const QSpan *spans, const QSpan *end, QSpan **outSpans, int available)
 
static int qt_intersect_spans (QT_FT_Span *spans, int numSpans, const QRect &clip)
 
QRectF qt_mapRect_non_normalizing (const QRectF &r, const QTransform &t)
 
static void qt_merge_clip (const QClipData *c1, const QClipData *c2, QClipData *result)
 
Q_GUI_EXPORT bool qt_scaleForTransform (const QTransform &transform, qreal *scale)
 
static void qt_span_clip (int count, const QSpan *spans, void *userData)
 
static void qt_span_fill_clipped (int count, const QSpan *spans, void *userData)
 
static void qt_span_fill_clipRect (int count, const QSpan *spans, void *userData)
 
static bool splitPolygon (const QPointF *points, int pointCount, QVector< QPointF > *upper, QVector< QPointF > *lower)
 
static const QRect toAlignedRect_positive (const QRectF &rect)
 
static QRect toNormalizedFillRect (const QRectF &rect)
 
static const QRect toRect_normalized (const QRectF &rect)
 

Variables

static const qreal aliasedCoordinateDelta = 0.5 - 0.015625
 
bool qt_applefontsmoothing_enabled
 
bool qt_cleartype_enabled
 

Macro Definition Documentation

◆ int_dim

#define int_dim (   pos,
  dim 
)    (int(pos+dim) - int(pos))

Definition at line 128 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::drawEllipse().

◆ qreal_to_fixed_26_6

#define qreal_to_fixed_26_6 (   f)    (int(f * 64))

Definition at line 113 of file qpaintengine_raster.cpp.

◆ QT_FAST_SPANS

#define QT_FAST_SPANS

Definition at line 122 of file qpaintengine_raster.cpp.

◆ QT_FT_BEGIN_HEADER

#define QT_FT_BEGIN_HEADER

Definition at line 45 of file qpaintengine_raster.cpp.

◆ QT_FT_END_HEADER

#define QT_FT_END_HEADER

Definition at line 46 of file qpaintengine_raster.cpp.

◆ qt_swap_int

#define qt_swap_int (   x,
 
)    { int tmp = (x); (x) = (y); (y) = tmp; }

Definition at line 114 of file qpaintengine_raster.cpp.

◆ qt_swap_qreal

#define qt_swap_qreal (   x,
 
)    { qreal tmp = (x); (x) = (y); (y) = tmp; }

Definition at line 115 of file qpaintengine_raster.cpp.

Enumeration Type Documentation

◆ LineDrawMode

Enumerator
LineDrawClipped 
LineDrawNormal 
LineDrawIncludeLastPixel 

Definition at line 157 of file qpaintengine_raster.cpp.

◆ RotationType

Definition at line 2216 of file qpaintengine_raster.cpp.

2216  {
2217  Rotation90,
2218  Rotation180,
2219  Rotation270,
2220  NoRotation
2221  };

Function Documentation

◆ alignAddress()

static uchar* alignAddress ( uchar address,
quintptr  alignmentMask 
)
inlinestatic

Definition at line 3775 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEnginePrivate::rasterize().

3776 {
3777  return (uchar *)(((quintptr)address + alignmentMask) & ~alignmentMask);
3778 }
QIntegerForSizeof< void * >::Unsigned quintptr
Definition: qglobal.h:986
unsigned char uchar
Definition: qglobal.h:994

◆ drawEllipse_midpoint_i()

static void drawEllipse_midpoint_i ( const QRect rect,
const QRect clip,
ProcessSpans  pen_func,
ProcessSpans  brush_func,
QSpanData pen_data,
QSpanData brush_data 
)
static

Draws an ellipse using the integer point midpoint algorithm.

Warning
This function is not part of the public interface.

Definition at line 5133 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::drawEllipse().

5136 {
5137  const qreal a = qreal(rect.width()) / 2;
5138  const qreal b = qreal(rect.height()) / 2;
5139  qreal d = b*b - (a*a*b) + qreal(0.25)*a*a;
5140 
5141  int x = 0;
5142  int y = (rect.height() + 1) / 2;
5143  int startx = x;
5144 
5145  // region 1
5146  while (a*a*(2*y - 1) > 2*b*b*(x + 1)) {
5147  if (d < 0) { // select E
5148  d += b*b*(2*x + 3);
5149  ++x;
5150  } else { // select SE
5151  d += b*b*(2*x + 3) + a*a*(-2*y + 2);
5152  drawEllipsePoints(startx, y, x - startx + 1, rect, clip,
5153  pen_func, brush_func, pen_data, brush_data);
5154  startx = ++x;
5155  --y;
5156  }
5157  }
5158  drawEllipsePoints(startx, y, x - startx + 1, rect, clip,
5159  pen_func, brush_func, pen_data, brush_data);
5160 
5161  // region 2
5162  d = b*b*(x + qreal(0.5))*(x + qreal(0.5)) + a*a*((y - 1)*(y - 1) - b*b);
5163  const int miny = rect.height() & 0x1;
5164  while (y > miny) {
5165  if (d < 0) { // select SE
5166  d += b*b*(2*x + 2) + a*a*(-2*y + 3);
5167  ++x;
5168  } else { // select S
5169  d += a*a*(-2*y + 3);
5170  }
5171  --y;
5172  drawEllipsePoints(x, y, 1, rect, clip,
5173  pen_func, brush_func, pen_data, brush_data);
5174  }
5175 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
static void drawEllipsePoints(int x, int y, int length, const QRect &rect, const QRect &clip, ProcessSpans pen_func, ProcessSpans brush_func, QSpanData *pen_data, QSpanData *brush_data)
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
long ASN1_INTEGER_get ASN1_INTEGER * a
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306

◆ drawEllipsePoints()

static void drawEllipsePoints ( int  x,
int  y,
int  length,
const QRect rect,
const QRect clip,
ProcessSpans  pen_func,
ProcessSpans  brush_func,
QSpanData pen_data,
QSpanData brush_data 
)
inlinestatic
Warning
This function is not part of the public interface. x and y is relative to the midpoint of rect.

Definition at line 5058 of file qpaintengine_raster.cpp.

Referenced by drawEllipse_midpoint_i().

5063 {
5064  if (length == 0)
5065  return;
5066 
5067  QT_FT_Span outline[4];
5068  const int midx = rect.x() + (rect.width() + 1) / 2;
5069  const int midy = rect.y() + (rect.height() + 1) / 2;
5070 
5071  x = x + midx;
5072  y = midy - y;
5073 
5074  // topleft
5075  outline[0].x = midx + (midx - x) - (length - 1) - (rect.width() & 0x1);
5076  outline[0].len = qMin(length, x - outline[0].x);
5077  outline[0].y = y;
5078  outline[0].coverage = 255;
5079 
5080  // topright
5081  outline[1].x = x;
5082  outline[1].len = length;
5083  outline[1].y = y;
5084  outline[1].coverage = 255;
5085 
5086  // bottomleft
5087  outline[2].x = outline[0].x;
5088  outline[2].len = outline[0].len;
5089  outline[2].y = midy + (midy - y) - (rect.height() & 0x1);
5090  outline[2].coverage = 255;
5091 
5092  // bottomright
5093  outline[3].x = x;
5094  outline[3].len = length;
5095  outline[3].y = outline[2].y;
5096  outline[3].coverage = 255;
5097 
5098  if (brush_func && outline[0].x + outline[0].len < outline[1].x) {
5099  QT_FT_Span fill[2];
5100 
5101  // top fill
5102  fill[0].x = outline[0].x + outline[0].len - 1;
5103  fill[0].len = qMax(0, outline[1].x - fill[0].x);
5104  fill[0].y = outline[1].y;
5105  fill[0].coverage = 255;
5106 
5107  // bottom fill
5108  fill[1].x = outline[2].x + outline[2].len - 1;
5109  fill[1].len = qMax(0, outline[3].x - fill[1].x);
5110  fill[1].y = outline[3].y;
5111  fill[1].coverage = 255;
5112 
5113  int n = (fill[0].y >= fill[1].y ? 1 : 2);
5114  n = qt_intersect_spans(fill, n, clip);
5115  if (n > 0)
5116  brush_func(n, fill, brush_data);
5117  }
5118  if (pen_func) {
5119  int n = (outline[1].y >= outline[2].y ? 2 : 4);
5120  n = qt_intersect_spans(outline, n, clip);
5121  if (n > 0)
5122  pen_func(n, outline, pen_data);
5123  }
5124 }
static const QSpan * qt_intersect_spans(const QClipData *clip, int *currentClip, const QSpan *spans, const QSpan *end, QSpan **outSpans, int available)
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
unsigned char coverage
unsigned short len
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252

◆ fast_ceil_positive()

static int fast_ceil_positive ( const qreal v)
inlinestatic

Definition at line 2143 of file qpaintengine_raster.cpp.

Referenced by toAlignedRect_positive().

2144 {
2145  const int iv = int(v);
2146  if (v - iv == 0)
2147  return iv;
2148  else
2149  return iv + 1;
2150 }

◆ fillRect_normalized()

static void fillRect_normalized ( const QRect r,
QSpanData data,
QRasterPaintEnginePrivate pe 
)
static

Definition at line 1435 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::drawImage(), QRasterPaintEngine::drawRects(), QRasterPaintEngine::drawTiledPixmap(), QRasterPaintEngine::fill(), and QRasterPaintEngine::fillRect().

1437 {
1438  int x1, x2, y1, y2;
1439 
1440  bool rectClipped = true;
1441 
1442  if (data->clip) {
1443  x1 = qMax(r.x(), data->clip->xmin);
1444  x2 = qMin(r.x() + r.width(), data->clip->xmax);
1445  y1 = qMax(r.y(), data->clip->ymin);
1446  y2 = qMin(r.y() + r.height(), data->clip->ymax);
1447  rectClipped = data->clip->hasRectClip;
1448 
1449  } else if (pe) {
1450  x1 = qMax(r.x(), pe->deviceRect.x());
1451  x2 = qMin(r.x() + r.width(), pe->deviceRect.x() + pe->deviceRect.width());
1452  y1 = qMax(r.y(), pe->deviceRect.y());
1453  y2 = qMin(r.y() + r.height(), pe->deviceRect.y() + pe->deviceRect.height());
1454  } else {
1455  x1 = qMax(r.x(), 0);
1456  x2 = qMin(r.x() + r.width(), data->rasterBuffer->width());
1457  y1 = qMax(r.y(), 0);
1458  y2 = qMin(r.y() + r.height(), data->rasterBuffer->height());
1459  }
1460 
1461  if (x2 <= x1 || y2 <= y1)
1462  return;
1463 
1464  const int width = x2 - x1;
1465  const int height = y2 - y1;
1466 
1467  bool isUnclipped = rectClipped
1468  || (pe && pe->isUnclipped_normalized(QRect(x1, y1, width, height)));
1469 
1470  if (pe && isUnclipped) {
1472 
1473  if (data->fillRect && (mode == QPainter::CompositionMode_Source
1475  && qAlpha(data->solid.color) == 255)))
1476  {
1477  data->fillRect(data->rasterBuffer, x1, y1, width, height,
1478  data->solid.color);
1479  return;
1480  }
1481  }
1482 
1483  ProcessSpans blend = isUnclipped ? data->unclipped_blend : data->blend;
1484 
1485  const int nspans = 256;
1486  QT_FT_Span spans[nspans];
1487 
1488  Q_ASSERT(data->blend);
1489  int y = y1;
1490  while (y < y2) {
1491  int n = qMin(nspans, y2 - y);
1492  int i = 0;
1493  while (i < n) {
1494  spans[i].x = x1;
1495  spans[i].len = width;
1496  spans[i].y = y + i;
1497  spans[i].coverage = 255;
1498  ++i;
1499  }
1500 
1501  blend(n, spans, data);
1502  y += n;
1503  }
1504 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
unsigned char coverage
CompositionMode
Defines the modes supported for digital image compositing.
Definition: qpainter.h:138
unsigned short len
QT_FT_SpanFunc ProcessSpans
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
QScopedPointer< QRasterBuffer > rasterBuffer
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QSolidData solid
bool isUnclipped_normalized(const QRect &rect) const
Returns true if the rectangle is completely within the current clip state of the paint engine...
QPainter::CompositionMode compositionMode
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
int qAlpha(QRgb rgba)
Returns the alpha component of the ARGB quadruplet rgba.
Definition: qrgb.h:66
ProcessSpans blend
RectFillFunc fillRect
const QClipData * clip
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
QRasterBuffer * rasterBuffer
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
ProcessSpans unclipped_blend

◆ isAbove()

static bool isAbove ( const QPointF a,
const QPointF b 
)
inlinestatic

Definition at line 1839 of file qpaintengine_raster.cpp.

Referenced by splitPolygon().

1840 {
1841  return a->y() < b->y();
1842 }
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287

◆ isRect()

template<typename T >
static bool isRect ( const T *  pts,
int  elementCount 
)
inlinestatic

Definition at line 194 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::clip(), QRasterPaintEngine::drawPolygon(), QClipData::fixup(), and qt_region_strictContains().

194  {
195  return (elementCount == 5 // 5-point polygon, check for closed rect
196  && pts[0] == pts[8] && pts[1] == pts[9] // last point == first point
197  && pts[0] == pts[6] && pts[2] == pts[4] // x values equal
198  && pts[1] == pts[3] && pts[5] == pts[7] // y values equal...
199  && pts[0] < pts[4] && pts[1] < pts[5]
200  ) ||
201  (elementCount == 4 // 4-point polygon, check for unclosed rect
202  && pts[0] == pts[6] && pts[2] == pts[4] // x values equal
203  && pts[1] == pts[3] && pts[5] == pts[7] // y values equal...
204  && pts[0] < pts[4] && pts[1] < pts[5]
205  );
206 }

◆ monoVal()

static bool monoVal ( const uchar s,
int  x 
)
inlinestatic

Definition at line 2549 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::alphaPenBlt().

2550 {
2551  return (s[x>>3] << (x&7)) & 0x80;
2552 }

◆ q_gray_rendered_spans()

int q_gray_rendered_spans ( QT_FT_Raster  raster)

◆ qrasterpaintengine_dirty_clip()

static void qrasterpaintengine_dirty_clip ( QRasterPaintEnginePrivate d,
QRasterPaintEngineState s 
)
static

Definition at line 1159 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::clip(), and QRasterPaintEngine::setClipRectInDeviceCoords().

1160 {
1164 
1165  d->solid_color_filler.clip = d->clip();
1167 
1168 #ifdef QT_DEBUG_DRAW
1169  dumpClip(d->rasterBuffer->width(), d->rasterBuffer->height(), &*d->clip());
1170 #endif
1171 
1172 }
QScopedPointer< QRasterBuffer > rasterBuffer
const QClipData * clip
const QClipData * clip() const

◆ qrasterpaintengine_state_setNoClip()

static void qrasterpaintengine_state_setNoClip ( QRasterPaintEngineState s)
static

Definition at line 1151 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::clip().

1152 {
1153  if (s->flags.has_clip_ownership)
1154  delete s->clip;
1155  s->clip = 0;
1156  s->flags.has_clip_ownership = false;
1157 }

◆ qt_ft_outline_cubic_to()

static void qt_ft_outline_cubic_to ( qfixed  c1x,
qfixed  c1y,
qfixed  c2x,
qfixed  c2y,
qfixed  ex,
qfixed  ey,
void *  data 
)
static

Definition at line 219 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::init().

223 {
224  ((QOutlineMapper *) data)->curveTo(QPointF(qt_fixed_to_real(c1x), qt_fixed_to_real(c1y)),
227 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
static const char * data(const QByteArray &arr)
#define qt_fixed_to_real(fixed)
Definition: qstroker_p.h:102

◆ qt_ft_outline_line_to()

static void qt_ft_outline_line_to ( qfixed  x,
qfixed  y,
void *  data 
)
static

Definition at line 214 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::init().

215 {
217 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
static const char * data(const QByteArray &arr)
#define qt_fixed_to_real(fixed)
Definition: qstroker_p.h:102

◆ qt_ft_outline_move_to()

static void qt_ft_outline_move_to ( qfixed  x,
qfixed  y,
void *  data 
)
static

Definition at line 209 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::init().

210 {
212 }
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
static const char * data(const QByteArray &arr)
#define qt_fixed_to_real(fixed)
Definition: qstroker_p.h:102

◆ qt_image_colortable()

const QVector<QRgb>* qt_image_colortable ( const QImage image)

Definition at line 122 of file qimage.cpp.

Referenced by QSpanData::setupMatrix().

123 {
124  return &image.d->colortable;
125 }
QImageData * d
Definition: qimage.h:336
QVector< QRgb > colortable
Definition: qimage_p.h:80

◆ qt_imageForBrush()

Q_GUI_EXPORT QImage qt_imageForBrush ( int  brushStyle,
bool  invert 
)

Definition at line 167 of file qbrush.cpp.

Referenced by QSpanData::setup().

168 {
169  return qt_brushPatternImageCache()->getImage(brushStyle, invert);
170 }

◆ qt_intersect_spans() [1/2]

static const QSpan* qt_intersect_spans ( const QClipData clip,
int *  currentClip,
const QSpan spans,
const QSpan end,
QSpan **  outSpans,
int  available 
)
static
Warning
This function is not part of the public interface. spans must be sorted on y

Definition at line 4325 of file qpaintengine_raster.cpp.

Referenced by drawEllipsePoints(), qt_span_clip(), qt_span_fill_clipped(), and qt_span_fill_clipRect().

4328 {
4329  const_cast<QClipData *>(clip)->initialize();
4330 
4331  QSpan *out = *outSpans;
4332 
4333  const QSpan *clipSpans = clip->m_spans + *currentClip;
4334  const QSpan *clipEnd = clip->m_spans + clip->count;
4335 
4336  while (available && spans < end ) {
4337  if (clipSpans >= clipEnd) {
4338  spans = end;
4339  break;
4340  }
4341  if (clipSpans->y > spans->y) {
4342  ++spans;
4343  continue;
4344  }
4345  if (spans->y != clipSpans->y) {
4346  if (spans->y < clip->count && clip->m_clipLines[spans->y].spans)
4347  clipSpans = clip->m_clipLines[spans->y].spans;
4348  else
4349  ++clipSpans;
4350  continue;
4351  }
4352  Q_ASSERT(spans->y == clipSpans->y);
4353 
4354  int sx1 = spans->x;
4355  int sx2 = sx1 + spans->len;
4356  int cx1 = clipSpans->x;
4357  int cx2 = cx1 + clipSpans->len;
4358 
4359  if (cx1 < sx1 && cx2 < sx1) {
4360  ++clipSpans;
4361  continue;
4362  } else if (sx1 < cx1 && sx2 < cx1) {
4363  ++spans;
4364  continue;
4365  }
4366  int x = qMax(sx1, cx1);
4367  int len = qMin(sx2, cx2) - x;
4368  if (len) {
4369  out->x = qMax(sx1, cx1);
4370  out->len = qMin(sx2, cx2) - out->x;
4371  out->y = spans->y;
4372  out->coverage = qt_div_255(spans->coverage * clipSpans->coverage);
4373  ++out;
4374  --available;
4375  }
4376  if (sx2 < cx2) {
4377  ++spans;
4378  } else {
4379  ++clipSpans;
4380  }
4381  }
4382 
4383  *outSpans = out;
4384  *currentClip = clipSpans - clip->m_spans;
4385  return spans;
4386 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
unsigned char coverage
unsigned short len
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
struct QClipData::ClipLine * m_clipLines
Q_STATIC_INLINE_FUNCTION int qt_div_255(int x)
static const KeyPair *const end

◆ qt_intersect_spans() [2/2]

static int qt_intersect_spans ( QT_FT_Span spans,
int  numSpans,
const QRect clip 
)
static

Definition at line 4415 of file qpaintengine_raster.cpp.

4417 {
4418  const short minx = clip.left();
4419  const short miny = clip.top();
4420  const short maxx = clip.right();
4421  const short maxy = clip.bottom();
4422 
4423  int n = 0;
4424  for (int i = 0; i < numSpans; ++i) {
4425  if (spans[i].y > maxy)
4426  break;
4427  if (spans[i].y < miny
4428  || spans[i].x > maxx
4429  || spans[i].x + spans[i].len <= minx) {
4430  continue;
4431  }
4432  if (spans[i].x < minx) {
4433  spans[n].len = qMin(spans[i].len - (minx - spans[i].x), maxx - minx + 1);
4434  spans[n].x = minx;
4435  } else {
4436  spans[n].x = spans[i].x;
4437  spans[n].len = qMin(spans[i].len, ushort(maxx - spans[n].x + 1));
4438  }
4439  if (spans[n].len == 0)
4440  continue;
4441  spans[n].y = spans[i].y;
4442  spans[n].coverage = spans[i].coverage;
4443  ++n;
4444  }
4445  return n;
4446 }
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
unsigned char coverage
unsigned short len
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
unsigned short ushort
Definition: qglobal.h:995

◆ qt_mapRect_non_normalizing()

QRectF qt_mapRect_non_normalizing ( const QRectF r,
const QTransform t 
)

Definition at line 2210 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::drawImage().

2211 {
2212  return QRectF(r.topLeft() * t, r.bottomRight() * t);
2213 }
QPointF bottomRight() const
Returns the position of the rectangle&#39;s bottom-right corner.
Definition: qrect.h:540
QPointF topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:539
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511

◆ qt_merge_clip()

static void qt_merge_clip ( const QClipData c1,
const QClipData c2,
QClipData result 
)
static

Definition at line 3652 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::clip().

3653 {
3654  Q_ASSERT(c1->clipSpanHeight == c2->clipSpanHeight && c1->clipSpanHeight == result->clipSpanHeight);
3655 
3657 
3658  QClipData::ClipLine *c1ClipLines = const_cast<QClipData *>(c1)->clipLines();
3659  QClipData::ClipLine *c2ClipLines = const_cast<QClipData *>(c2)->clipLines();
3660  result->initialize();
3661 
3662  for (int y = 0; y < c1->clipSpanHeight; ++y) {
3663  const QSpan *c1_spans = c1ClipLines[y].spans;
3664  int c1_count = c1ClipLines[y].count;
3665  const QSpan *c2_spans = c2ClipLines[y].spans;
3666  int c2_count = c2ClipLines[y].count;
3667 
3668  if (c1_count == 0 && c2_count == 0)
3669  continue;
3670  if (c1_count == 0) {
3671  result->appendSpans(c2_spans, c2_count);
3672  continue;
3673  } else if (c2_count == 0) {
3674  result->appendSpans(c1_spans, c1_count);
3675  continue;
3676  }
3677 
3678  // we need to merge the two
3679 
3680  // find required length
3681  int max = qMax(c1_spans[c1_count - 1].x + c1_spans[c1_count - 1].len,
3682  c2_spans[c2_count - 1].x + c2_spans[c2_count - 1].len);
3683  buffer.resize(max);
3684  memset(buffer.data(), 0, buffer.size() * sizeof(short));
3685 
3686  // Fill with old spans.
3687  for (int i = 0; i < c1_count; ++i) {
3688  const QSpan *cs = c1_spans + i;
3689  for (int j=cs->x; j<cs->x + cs->len; ++j)
3690  buffer[j] = cs->coverage;
3691  }
3692 
3693  // Fill with new spans
3694  for (int i = 0; i < c2_count; ++i) {
3695  const QSpan *cs = c2_spans + i;
3696  for (int j = cs->x; j < cs->x + cs->len; ++j) {
3697  buffer[j] += cs->coverage;
3698  if (buffer[j] > 255)
3699  buffer[j] = 255;
3700  }
3701  }
3702 
3703  int x = 0;
3704  while (x<max) {
3705 
3706  // Skip to next span
3707  while (x < max && buffer[x] == 0) ++x;
3708  if (x >= max) break;
3709 
3710  int sx = x;
3711  int coverage = buffer[x];
3712 
3713  // Find length of span
3714  while (x < max && buffer[x] == coverage)
3715  ++x;
3716 
3717  result->appendSpan(sx, x - sx, y, coverage);
3718  }
3719  }
3720 }
void resize(int size)
unsigned char coverage
unsigned short len
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
void appendSpan(int x, int length, int y, int coverage)
void appendSpans(const QSpan *s, int num)
int size() const

◆ qt_scaleForTransform()

Q_GUI_EXPORT bool qt_scaleForTransform ( const QTransform transform,
qreal scale 
)

Definition at line 2407 of file qtransform.cpp.

Referenced by QRasterPaintEngine::updateMatrix().

2408 {
2409  const QTransform::TransformationType type = transform.type();
2410  if (type <= QTransform::TxTranslate) {
2411  if (scale)
2412  *scale = 1;
2413  return true;
2414  } else if (type == QTransform::TxScale) {
2415  const qreal xScale = qAbs(transform.m11());
2416  const qreal yScale = qAbs(transform.m22());
2417  if (scale)
2418  *scale = qMax(xScale, yScale);
2419  return qFuzzyCompare(xScale, yScale);
2420  }
2421 
2422  const qreal xScale = transform.m11() * transform.m11()
2423  + transform.m21() * transform.m21();
2424  const qreal yScale = transform.m12() * transform.m12()
2425  + transform.m22() * transform.m22();
2426  if (scale)
2427  *scale = qSqrt(qMax(xScale, yScale));
2428  return type == QTransform::TxRotate && qFuzzyCompare(xScale, yScale);
2429 }
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
TransformationType type() const
Returns the transformation type of this matrix.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
TransformationType
Definition: qtransform.h:68
bool qFuzzyCompare(const QMatrix &m1, const QMatrix &m2)
The qFuzzyCompare function is for comparing two matrices using a fuzziness factor.
Definition: qmatrix.h:172
qreal qSqrt(qreal v)
Definition: qmath.h:205
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237

◆ qt_span_clip()

static void qt_span_clip ( int  count,
const QSpan spans,
void *  userData 
)
static

Definition at line 4465 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::clip().

4466 {
4467  ClipData *clipData = reinterpret_cast<ClipData *>(userData);
4468 
4469 // qDebug() << " qt_span_clip: " << count << clipData->operation;
4470 // for (int i = 0; i < qMin(count, 10); ++i) {
4471 // qDebug() << " " << spans[i].x << spans[i].y << spans[i].len << spans[i].coverage;
4472 // }
4473 
4474  switch (clipData->operation) {
4475 
4476  case Qt::IntersectClip:
4477  {
4478  QClipData *newClip = clipData->newClip;
4479  newClip->initialize();
4480 
4481  int currentClip = 0;
4482  const QSpan *end = spans + count;
4483  while (spans < end) {
4484  QSpan *newspans = newClip->m_spans + newClip->count;
4485  spans = qt_intersect_spans(clipData->oldClip, &currentClip, spans, end,
4486  &newspans, newClip->allocated - newClip->count);
4487  newClip->count = newspans - newClip->m_spans;
4488  if (spans < end) {
4489  newClip->m_spans = q_check_ptr((QSpan *)realloc(newClip->m_spans, newClip->allocated*2*sizeof(QSpan)));
4490  newClip->allocated *= 2;
4491  }
4492  }
4493  }
4494  break;
4495 
4496  case Qt::UniteClip:
4497  case Qt::ReplaceClip:
4498  clipData->newClip->appendSpans(spans, count);
4499  break;
4500  case Qt::NoClip:
4501  break;
4502  }
4503 }
QClipData * oldClip
T * q_check_ptr(T *p)
Definition: qglobal.h:1857
static const QSpan * qt_intersect_spans(const QClipData *clip, int *currentClip, const QSpan *spans, const QSpan *end, QSpan **outSpans, int available)
void appendSpans(const QSpan *s, int num)
QClipData * newClip
static const KeyPair *const end
Qt::ClipOperation operation

◆ qt_span_fill_clipped()

static void qt_span_fill_clipped ( int  count,
const QSpan spans,
void *  userData 
)
static

Definition at line 4388 of file qpaintengine_raster.cpp.

Referenced by QSpanData::adjustSpanMethods().

4389 {
4390 // qDebug() << "qt_span_fill_clipped" << spanCount;
4391  QSpanData *fillData = reinterpret_cast<QSpanData *>(userData);
4392 
4393  Q_ASSERT(fillData->blend && fillData->unclipped_blend);
4394 
4395  const int NSPANS = 256;
4396  QSpan cspans[NSPANS];
4397  int currentClip = 0;
4398  const QSpan *end = spans + spanCount;
4399  while (spans < end) {
4400  QSpan *clipped = cspans;
4401  spans = qt_intersect_spans(fillData->clip, &currentClip, spans, end, &clipped, NSPANS);
4402 // qDebug() << "processed " << spanCount - (end - spans) << "clipped" << clipped-cspans
4403 // << "span:" << cspans->x << cspans->y << cspans->len << spans->coverage;
4404 
4405  if (clipped - cspans)
4406  fillData->unclipped_blend(clipped - cspans, cspans, fillData);
4407  }
4408 }
static const QSpan * qt_intersect_spans(const QClipData *clip, int *currentClip, const QSpan *spans, const QSpan *end, QSpan **outSpans, int available)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
ProcessSpans blend
const QClipData * clip
ProcessSpans unclipped_blend
static const KeyPair *const end

◆ qt_span_fill_clipRect()

static void qt_span_fill_clipRect ( int  count,
const QSpan spans,
void *  userData 
)
static

Definition at line 4449 of file qpaintengine_raster.cpp.

Referenced by QSpanData::adjustSpanMethods().

4451 {
4452  QSpanData *fillData = reinterpret_cast<QSpanData *>(userData);
4453  Q_ASSERT(fillData->blend && fillData->unclipped_blend);
4454 
4455  Q_ASSERT(fillData->clip);
4456  Q_ASSERT(!fillData->clip->clipRect.isEmpty());
4457 
4458  // hw: check if this const_cast<> is safe!!!
4459  count = qt_intersect_spans(const_cast<QSpan*>(spans), count,
4460  fillData->clip->clipRect);
4461  if (count > 0)
4462  fillData->unclipped_blend(count, spans, fillData);
4463 }
static const QSpan * qt_intersect_spans(const QClipData *clip, int *currentClip, const QSpan *spans, const QSpan *end, QSpan **outSpans, int available)
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
ProcessSpans blend
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:234
const QClipData * clip
ProcessSpans unclipped_blend

◆ splitPolygon()

static bool splitPolygon ( const QPointF points,
int  pointCount,
QVector< QPointF > *  upper,
QVector< QPointF > *  lower 
)
static

Definition at line 1844 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::fillPolygon().

1845 {
1846  Q_ASSERT(upper);
1847  Q_ASSERT(lower);
1848 
1849  Q_ASSERT(pointCount >= 2);
1850 
1851  QVector<const QPointF *> sorted;
1852  sorted.reserve(pointCount);
1853 
1854  upper->reserve(pointCount * 3 / 4);
1855  lower->reserve(pointCount * 3 / 4);
1856 
1857  for (int i = 0; i < pointCount; ++i)
1858  sorted << points + i;
1859 
1860  qSort(sorted.begin(), sorted.end(), isAbove);
1861 
1862  qreal splitY = sorted.at(sorted.size() / 2)->y();
1863 
1864  const QPointF *end = points + pointCount;
1865  const QPointF *last = end - 1;
1866 
1867  QVector<QPointF> *bin[2] = { upper, lower };
1868 
1869  for (const QPointF *p = points; p < end; ++p) {
1870  int side = p->y() < splitY;
1871  int lastSide = last->y() < splitY;
1872 
1873  if (side != lastSide) {
1874  if (qFuzzyCompare(p->y(), splitY)) {
1875  bin[!side]->append(*p);
1876  } else if (qFuzzyCompare(last->y(), splitY)) {
1877  bin[side]->append(*last);
1878  } else {
1879  QPointF delta = *p - *last;
1880  QPointF intersection(p->x() + delta.x() * (splitY - p->y()) / delta.y(), splitY);
1881 
1882  bin[0]->append(intersection);
1883  bin[1]->append(intersection);
1884  }
1885  }
1886 
1887  bin[side]->append(*p);
1888 
1889  last = p;
1890  }
1891 
1892  // give up if we couldn't reduce the point count
1893  return upper->size() < pointCount && lower->size() < pointCount;
1894 }
double qreal
Definition: qglobal.h:1193
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
The QVector class is a template class that provides a dynamic array.
Definition: qdatastream.h:64
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the vector...
Definition: qvector.h:250
void append(const T &t)
Inserts value at the end of the vector.
Definition: qvector.h:573
static bool isAbove(const QPointF *a, const QPointF *b)
void qSort(RandomAccessIterator start, RandomAccessIterator end)
Definition: qalgorithms.h:177
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
iterator begin()
Returns an STL-style iterator pointing to the first item in the vector.
Definition: qvector.h:247
QTextStream & bin(QTextStream &stream)
Calls QTextStream::setIntegerBase(2) on stream and returns stream.
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
bool qFuzzyCompare(const QMatrix &m1, const QMatrix &m2)
The qFuzzyCompare function is for comparing two matrices using a fuzziness factor.
Definition: qmatrix.h:172
void reserve(int size)
Attempts to allocate memory for at least size elements.
Definition: qvector.h:339
static const KeyPair *const end
int size() const
Returns the number of items in the vector.
Definition: qvector.h:137

◆ toAlignedRect_positive()

static const QRect toAlignedRect_positive ( const QRectF rect)
inlinestatic

Definition at line 2152 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::drawImage().

2153 {
2154  const int xmin = int(rect.x());
2155  const int xmax = int(fast_ceil_positive(rect.right()));
2156  const int ymin = int(rect.y());
2157  const int ymax = int(fast_ceil_positive(rect.bottom()));
2158  return QRect(xmin, ymin, xmax - xmin, ymax - ymin);
2159 }
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
static int fast_ceil_positive(const qreal &v)
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528

◆ toNormalizedFillRect()

static QRect toNormalizedFillRect ( const QRectF rect)
inlinestatic

Definition at line 1681 of file qpaintengine_raster.cpp.

Referenced by QRasterPaintEngine::fill(), and QRasterPaintEngine::fillRect().

1682 {
1683  int x1 = qRound(rect.x() + aliasedCoordinateDelta);
1684  int y1 = qRound(rect.y() + aliasedCoordinateDelta);
1685  int x2 = qRound(rect.right() + aliasedCoordinateDelta);
1686  int y2 = qRound(rect.bottom() + aliasedCoordinateDelta);
1687 
1688  if (x2 < x1)
1689  qSwap(x1, x2);
1690  if (y2 < y1)
1691  qSwap(y1, y2);
1692 
1693  return QRect(x1, y1, x2 - x1, y2 - y1);
1694 }
static const qreal aliasedCoordinateDelta
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
qreal right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:527
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ toRect_normalized()

static const QRect toRect_normalized ( const QRectF rect)
inlinestatic

Definition at line 2133 of file qpaintengine_raster.cpp.

2134 {
2135  const int x = qRound(rect.x());
2136  const int y = qRound(rect.y());
2137  const int w = int(rect.width() + qreal(0.5));
2138  const int h = int(rect.height() + qreal(0.5));
2139 
2140  return QRect(x, y, w, h);
2141 }
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
double qreal
Definition: qglobal.h:1193
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

Variable Documentation

◆ aliasedCoordinateDelta

const qreal aliasedCoordinateDelta = 0.5 - 0.015625
static

◆ qt_applefontsmoothing_enabled

bool qt_applefontsmoothing_enabled

Definition at line 208 of file qapplication_mac.mm.

Referenced by QRasterPaintEngine::begin().

◆ qt_cleartype_enabled

bool qt_cleartype_enabled

Definition at line 241 of file qapplication_win.cpp.

Referenced by QRasterPaintEngine::begin().