Qt 4.8
Classes | Functions | Variables
qpaintengine_vg.cpp File Reference
#include "qpaintengine_vg_p.h"
#include "qpixmapdata_vg_p.h"
#include "qpixmapfilter_vg_p.h"
#include "qvgcompositionhelper_p.h"
#include "qvgimagepool_p.h"
#include "qvgfontglyphcache_p.h"
#include <QtGui/private/qeglcontext_p.h>
#include "qwindowsurface_vgegl_p.h"
#include <QtCore/qvarlengtharray.h>
#include <QtGui/private/qdrawhelper_p.h>
#include <QtGui/private/qtextengine_p.h>
#include <QtGui/private/qfontengine_p.h>
#include <QtGui/private/qpainterpath_p.h>
#include <QtGui/private/qstatictext_p.h>
#include <QtGui/QApplication>
#include <QtGui/QDesktopWidget>
#include <QtCore/qmath.h>
#include <QDebug>
#include <QSet>
#include "qpaintengine_vg.moc"

Go to the source code of this file.

Classes

class  QVGFontEngineCleaner
 
class  QVGPaintEnginePrivate
 

Functions

static bool clipTransformIsSimple (const QTransform &transform)
 
static QImage colorizeBitmap (const QImage &image, const QColor &color)
 
static void drawImageTiled (QVGPaintEnginePrivate *d, const QRectF &r, const QImage &image, const QRectF &sr=QRectF())
 
static void drawVGImage (QVGPaintEnginePrivate *d, const QRectF &r, VGImage vgImg, const QSize &imageSize, const QRectF &sr)
 
static void drawVGImage (QVGPaintEnginePrivate *d, const QPointF &pos, VGImage vgImg)
 
static void fillBackgroundRect (const QRect &rect, QVGPaintEnginePrivate *d)
 
Q_GUI_EXPORT QImage qt_imageForBrush (int style, bool invert)
 
Q_GUI_EXPORT QPainterPath qt_painterPathFromVectorPath (const QVectorPath &path)
 
Q_GUI_EXPORT bool qt_scaleForTransform (const QTransform &transform, qreal *scale)
 
void qt_vg_drawVGImage (QPainter *painter, const QPointF &pos, VGImage vgImg)
 
void qt_vg_drawVGImageStencil (QPainter *painter, const QPointF &pos, VGImage vgImg, const QBrush &brush)
 
VGImageFormat qt_vg_image_to_vg_format (QImage::Format format)
 
static bool qt_vg_pathToRect (const QPainterPath &path, QRectF *rect)
 
static VGImage toVGImage (const QImage &image, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
static VGImage toVGImageSubRect (const QImage &image, const QRect &sr, Qt::ImageConversionFlags flags=Qt::AutoColor)
 
static VGImage toVGImageWithOpacity (const QImage &image, qreal opacity)
 
static VGImage toVGImageWithOpacitySubRect (const QImage &image, qreal opacity, const QRect &sr)
 

Variables

static const qreal aliasedCoordinateDelta = 0.5 - 0.015625
 

Function Documentation

◆ clipTransformIsSimple()

static bool clipTransformIsSimple ( const QTransform transform)
inlinestatic

Definition at line 1618 of file qpaintengine_vg.cpp.

Referenced by QVGPaintEngine::clip(), and QVGPaintEngine::fillRect().

1619 {
1621  if (type == QTransform::TxNone || type == QTransform::TxTranslate)
1622  return true;
1623  if (type == QTransform::TxRotate) {
1624  // Check for 0, 90, 180, and 270 degree rotations.
1625  // (0 might happen after 4 rotations of 90 degrees).
1626  qreal m11 = transform.m11();
1627  qreal m12 = transform.m12();
1628  qreal m21 = transform.m21();
1629  qreal m22 = transform.m22();
1630  if (m11 == 0.0f && m22 == 0.0f) {
1631  if (m12 == 1.0f && m21 == -1.0f)
1632  return true; // 90 degrees.
1633  else if (m12 == -1.0f && m21 == 1.0f)
1634  return true; // 270 degrees.
1635  } else if (m12 == 0.0f && m21 == 0.0f) {
1636  if (m11 == -1.0f && m22 == -1.0f)
1637  return true; // 180 degrees.
1638  else if (m11 == 1.0f && m22 == 1.0f)
1639  return true; // 0 degrees.
1640  }
1641  }
1642  return false;
1643 }
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
TransformationType type() const
Returns the transformation type of this matrix.
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
TransformationType
Definition: qtransform.h:68
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237

◆ colorizeBitmap()

static QImage colorizeBitmap ( const QImage image,
const QColor color 
)
static

Definition at line 1024 of file qpaintengine_vg.cpp.

Referenced by QVGPaintEnginePrivate::setBrush().

1025 {
1026  QImage sourceImage = image.convertToFormat(QImage::Format_MonoLSB);
1027  QImage dest = QImage(sourceImage.size(), QImage::Format_ARGB32_Premultiplied);
1028 
1029  QRgb fg = PREMUL(color.rgba());
1030  QRgb bg = 0;
1031 
1032  int height = sourceImage.height();
1033  int width = sourceImage.width();
1034  for (int y=0; y<height; ++y) {
1035  const uchar *source = sourceImage.constScanLine(y);
1036  QRgb *target = reinterpret_cast<QRgb *>(dest.scanLine(y));
1037  for (int x=0; x < width; ++x)
1038  target[x] = (source[x>>3] >> (x&7)) & 1 ? fg : bg;
1039  }
1040  return dest;
1041 }
unsigned int QRgb
Definition: qrgb.h:53
unsigned char uchar
Definition: qglobal.h:994
Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x)
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587
const uchar * constScanLine(int) const
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1926
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
QRgb rgba() const
Returns the RGB value of the color, including its alpha.
Definition: qcolor.cpp:1019
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ drawImageTiled()

static void drawImageTiled ( QVGPaintEnginePrivate d,
const QRectF r,
const QImage image,
const QRectF sr = QRectF() 
)
static

Definition at line 3181 of file qpaintengine_vg.cpp.

Referenced by QVGPaintEngine::drawImage().

3185 {
3186  const int minTileSize = 16;
3187  int tileWidth = 512;
3188  int tileHeight = tileWidth;
3189 
3190  VGImageFormat tileFormat = qt_vg_image_to_vg_format(image.format());
3191  VGImage tile = VG_INVALID_HANDLE;
3193  while (tile == VG_INVALID_HANDLE && tileWidth >= minTileSize) {
3194  tile = pool->createPermanentImage(tileFormat, tileWidth, tileHeight,
3195  VG_IMAGE_QUALITY_FASTER);
3196  if (tile == VG_INVALID_HANDLE) {
3197  tileWidth /= 2;
3198  tileHeight /= 2;
3199  }
3200  }
3201  if (tile == VG_INVALID_HANDLE) {
3202  qWarning("drawImageTiled: Failed to create %dx%d tile, giving up", tileWidth, tileHeight);
3203  return;
3204  }
3205 
3206  VGfloat opacityMatrix[20] = {
3207  1.0f, 0.0f, 0.0f, 0.0f,
3208  0.0f, 1.0f, 0.0f, 0.0f,
3209  0.0f, 0.0f, 1.0f, 0.0f,
3210  0.0f, 0.0f, 0.0f, d->opacity,
3211  0.0f, 0.0f, 0.0f, 0.0f
3212  };
3213  VGImage tileWithOpacity = VG_INVALID_HANDLE;
3214  if (d->opacity != 1) {
3215  tileWithOpacity = pool->createPermanentImage(VG_sARGB_8888_PRE,
3216  tileWidth, tileHeight, VG_IMAGE_QUALITY_NONANTIALIASED);
3217  if (tileWithOpacity == VG_INVALID_HANDLE)
3218  qWarning("drawImageTiled: Failed to create extra tile, ignoring opacity");
3219  }
3220 
3221  QRect sourceRect = sr.toRect();
3222  if (sourceRect.isNull())
3223  sourceRect = QRect(0, 0, image.width(), image.height());
3224 
3225  VGfloat scaleX = r.width() / sourceRect.width();
3226  VGfloat scaleY = r.height() / sourceRect.height();
3227 
3228  d->setImageOptions();
3229  VGImageQuality oldImageQuality = d->imageQuality;
3230  VGRenderingQuality oldRenderingQuality = d->renderingQuality;
3231  d->setImageQuality(VG_IMAGE_QUALITY_NONANTIALIASED);
3232  d->setRenderingQuality(VG_RENDERING_QUALITY_NONANTIALIASED);
3233 
3234  for (int y = sourceRect.y(); y < sourceRect.height(); y += tileHeight) {
3235  int h = qMin(tileHeight, sourceRect.height() - y);
3236  if (h < 1)
3237  break;
3238  for (int x = sourceRect.x(); x < sourceRect.width(); x += tileWidth) {
3239  int w = qMin(tileWidth, sourceRect.width() - x);
3240  if (w < 1)
3241  break;
3242 
3243  int bytesPerPixel = image.depth() / 8;
3244  const uchar *sptr = image.constBits() + x * bytesPerPixel + y * image.bytesPerLine();
3245  vgImageSubData(tile, sptr, image.bytesPerLine(), tileFormat, 0, 0, w, h);
3246 
3247  QTransform transform(d->imageTransform);
3248  transform.translate(r.x() + x, r.y() + y);
3249  transform.scale(scaleX, scaleY);
3250  d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, transform);
3251 
3252  VGImage actualTile = tile;
3253  if (tileWithOpacity != VG_INVALID_HANDLE) {
3254  vgColorMatrix(tileWithOpacity, actualTile, opacityMatrix);
3255  if (w < tileWidth || h < tileHeight)
3256  actualTile = vgChildImage(tileWithOpacity, 0, 0, w, h);
3257  else
3258  actualTile = tileWithOpacity;
3259  } else if (w < tileWidth || h < tileHeight) {
3260  actualTile = vgChildImage(tile, 0, 0, w, h);
3261  }
3262  vgDrawImage(actualTile);
3263 
3264  if (actualTile != tile && actualTile != tileWithOpacity)
3265  vgDestroyImage(actualTile);
3266  }
3267  }
3268 
3269  vgDestroyImage(tile);
3270  if (tileWithOpacity != VG_INVALID_HANDLE)
3271  vgDestroyImage(tileWithOpacity);
3272 
3273  d->setImageQuality(oldImageQuality);
3274  d->setRenderingQuality(oldRenderingQuality);
3275 }
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
VGImageFormat qt_vg_image_to_vg_format(QImage::Format format)
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:231
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
VGImageQuality imageQuality
virtual VGImage createPermanentImage(VGImageFormat format, VGint width, VGint height, VGbitfield allowedQuality)
static int bytesPerPixel(QImage::Format format)
int width() const
Returns the width of the rectangle.
Definition: qrect.h:303
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
void setTransform(VGMatrixMode mode, const QTransform &transform)
void setRenderingQuality(VGRenderingQuality mode)
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
void setImageQuality(VGImageQuality mode)
unsigned char uchar
Definition: qglobal.h:994
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
Q_CORE_EXPORT void qWarning(const char *,...)
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
const uchar * constBits() const
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1985
VGRenderingQuality renderingQuality
QRect toRect() const
Returns a QRect based on the values of this rectangle.
Definition: qrect.h:845
static QVGImagePool * instance()
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
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
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ drawVGImage() [1/2]

static void drawVGImage ( QVGPaintEnginePrivate d,
const QRectF r,
VGImage  vgImg,
const QSize imageSize,
const QRectF sr 
)
static

Definition at line 3134 of file qpaintengine_vg.cpp.

Referenced by QVGPaintEngine::drawImage(), QVGPaintEngine::drawPixmap(), and qt_vg_drawVGImage().

3137 {
3138  if (vgImg == VG_INVALID_HANDLE)
3139  return;
3140  VGImage child = VG_INVALID_HANDLE;
3141 
3142  if (sr.topLeft().isNull() && sr.size() == imageSize) {
3143  child = vgImg;
3144  } else {
3145  QRect src = sr.toRect();
3146 #if !defined(QT_SHIVAVG)
3147  child = vgChildImage(vgImg, src.x(), src.y(), src.width(), src.height());
3148 #else
3149  child = vgImg; // XXX: ShivaVG doesn't have vgChildImage().
3150 #endif
3151  }
3152 
3153  QTransform transform(d->imageTransform);
3154  VGfloat scaleX = sr.width() == 0.0f ? 0.0f : r.width() / sr.width();
3155  VGfloat scaleY = sr.height() == 0.0f ? 0.0f : r.height() / sr.height();
3156  transform.translate(r.x(), r.y());
3157  transform.scale(scaleX, scaleY);
3158  d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, transform);
3159 
3160  d->setImageOptions();
3161  vgDrawImage(child);
3162 
3163  if(child != vgImg)
3164  vgDestroyImage(child);
3165 }
qreal y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:667
QPointF topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:539
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
void setTransform(VGMatrixMode mode, const QTransform &transform)
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
QRect toRect() const
Returns a QRect based on the values of this rectangle.
Definition: qrect.h:845
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
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
bool isNull() const
Returns true if both the x and y coordinates are set to +0.
Definition: qpoint.h:277
QSizeF size() const
Returns the size of the rectangle.
Definition: qrect.h:713
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ drawVGImage() [2/2]

static void drawVGImage ( QVGPaintEnginePrivate d,
const QPointF pos,
VGImage  vgImg 
)
static

Definition at line 3167 of file qpaintengine_vg.cpp.

3169 {
3170  if (vgImg == VG_INVALID_HANDLE)
3171  return;
3172 
3173  QTransform transform(d->imageTransform);
3174  transform.translate(pos.x(), pos.y());
3175  d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, transform);
3176 
3177  d->setImageOptions();
3178  vgDrawImage(vgImg);
3179 }
void setTransform(VGMatrixMode mode, const QTransform &transform)
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
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ fillBackgroundRect()

static void fillBackgroundRect ( const QRect rect,
QVGPaintEnginePrivate d 
)
static

Definition at line 4069 of file qpaintengine_vg.cpp.

Referenced by QVGCompositionHelper::fillBackground().

4070 {
4071  VGfloat coords[8];
4072  coords[0] = rect.x();
4073  coords[1] = rect.y();
4074  coords[2] = rect.x() + rect.width();
4075  coords[3] = coords[1];
4076  coords[4] = coords[2];
4077  coords[5] = rect.y() + rect.height();
4078  coords[6] = coords[0];
4079  coords[7] = coords[5];
4080 #if !defined(QVG_NO_MODIFY_PATH)
4081  vgModifyPathCoords(d->rectPath, 0, 4, coords);
4082  vgDrawPath(d->rectPath, VG_FILL_PATH);
4083 #else
4084  Q_UNUSED(d);
4085  VGPath rectPath = vgCreatePath
4086  (VG_PATH_FORMAT_STANDARD,
4087  VG_PATH_DATATYPE_F,
4088  1.0f, // scale
4089  0.0f, // bias
4090  5, // segmentCapacityHint
4091  8, // coordCapacityHint
4092  VG_PATH_CAPABILITY_ALL);
4093  static VGubyte const segments[5] = {
4094  VG_MOVE_TO_ABS,
4095  VG_LINE_TO_ABS,
4096  VG_LINE_TO_ABS,
4097  VG_LINE_TO_ABS,
4098  VG_CLOSE_PATH
4099  };
4100  vgAppendPathData(rectPath, 5, segments, coords);
4101  vgDrawPath(rectPath, VG_FILL_PATH);
4102  vgDestroyPath(rectPath);
4103 #endif
4104 }
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
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
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ qt_imageForBrush()

Q_GUI_EXPORT QImage qt_imageForBrush ( int  style,
bool  invert 
)

Definition at line 167 of file qbrush.cpp.

Referenced by QVGPaintEnginePrivate::roundedRectPath(), and QVGPaintEnginePrivate::setBrush().

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

◆ qt_painterPathFromVectorPath()

Q_GUI_EXPORT QPainterPath qt_painterPathFromVectorPath ( const QVectorPath path)

Definition at line 1033 of file qpaintengineex.cpp.

Referenced by QVGPaintEngine::draw(), and QVGPaintEngine::fill().

1034 {
1035  const qreal *points = path.points();
1036  const QPainterPath::ElementType *types = path.elements();
1037 
1038  QPainterPath p;
1039  if (types) {
1040  int id = 0;
1041  for (int i=0; i<path.elementCount(); ++i) {
1042  switch(types[i]) {
1044  p.moveTo(QPointF(points[id], points[id+1]));
1045  id+=2;
1046  break;
1048  p.lineTo(QPointF(points[id], points[id+1]));
1049  id+=2;
1050  break;
1052  QPointF p1(points[id], points[id+1]);
1053  QPointF p2(points[id+2], points[id+3]);
1054  QPointF p3(points[id+4], points[id+5]);
1055  p.cubicTo(p1, p2, p3);
1056  id+=6;
1057  break;
1058  }
1060  ;
1061  break;
1062  }
1063  }
1064  } else {
1065  p.moveTo(QPointF(points[0], points[1]));
1066  int id = 2;
1067  for (int i=1; i<path.elementCount(); ++i) {
1068  p.lineTo(QPointF(points[id], points[id+1]));
1069  id+=2;
1070  }
1071  }
1072  if (path.hints() & QVectorPath::WindingFill)
1074 
1075  return p;
1076 }
ElementType
This enum describes the types of elements used to connect vertices in subpaths.
Definition: qpainterpath.h:70
double qreal
Definition: qglobal.h:1193
int elementCount() const
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
const QPainterPath::ElementType * elements() const
void moveTo(const QPointF &p)
Moves the current point to the given point, implicitly starting a new subpath and closing the previou...
void lineTo(const QPointF &p)
Adds a straight line from the current position to the given endPoint.
void setFillRule(Qt::FillRule fillRule)
Sets the fill rule of the painter path to the given fillRule.
uint hints() const
static const struct @32 types[]
const qreal * points() const
void cubicTo(const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt)
Adds a cubic Bezier curve between the current position and the given endPoint using the control point...

◆ qt_scaleForTransform()

Q_GUI_EXPORT bool qt_scaleForTransform ( const QTransform transform,
qreal scale 
)

Definition at line 2407 of file qtransform.cpp.

Referenced by cubicTo_clipped(), lineTo_clipped(), QVGPaintEnginePrivate::setTransform(), and QVGPaintEnginePrivate::updateTransform().

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_vg_drawVGImage()

void qt_vg_drawVGImage ( QPainter painter,
const QPointF pos,
VGImage  vgImg 
)

Definition at line 3278 of file qpaintengine_vg.cpp.

Referenced by QVGPixmapConvolutionFilter::draw(), QVGPixmapColorizeFilter::draw(), QVGPixmapBlurFilter::draw(), and QVGPixmapConvolutionFilter::~QVGPixmapConvolutionFilter().

3279 {
3280  QVGPaintEngine *engine =
3281  static_cast<QVGPaintEngine *>(painter->paintEngine());
3282  drawVGImage(engine->vgPrivate(), pos, vgImg);
3283 }
QVGPaintEnginePrivate * vgPrivate()
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
Definition: qpainter.cpp:1991
static void drawVGImage(QVGPaintEnginePrivate *d, const QRectF &r, VGImage vgImg, const QSize &imageSize, const QRectF &sr)

◆ qt_vg_drawVGImageStencil()

void qt_vg_drawVGImageStencil ( QPainter painter,
const QPointF pos,
VGImage  vgImg,
const QBrush brush 
)

Definition at line 3287 of file qpaintengine_vg.cpp.

Referenced by QVGPixmapDropShadowFilter::draw(), qt_vg_drawVGImage(), and QVGPixmapConvolutionFilter::~QVGPixmapConvolutionFilter().

3288 {
3289  QVGPaintEngine *engine =
3290  static_cast<QVGPaintEngine *>(painter->paintEngine());
3291 
3292  QVGPaintEnginePrivate *d = engine->vgPrivate();
3293 
3294  QTransform transform(d->imageTransform);
3295  transform.translate(pos.x(), pos.y());
3296  d->setTransform(VG_MATRIX_IMAGE_USER_TO_SURFACE, transform);
3297 
3298  d->ensureBrush(brush);
3299  d->setImageMode(VG_DRAW_IMAGE_STENCIL);
3300  vgDrawImage(vgImg);
3301 }
double d
Definition: qnumeric_p.h:62
void setTransform(VGMatrixMode mode, const QTransform &transform)
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
QVGPaintEnginePrivate * vgPrivate()
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
Definition: qpainter.cpp:1991
void setImageMode(VGImageMode mode)
void ensureBrush(const QBrush &brush)
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65

◆ qt_vg_image_to_vg_format()

VGImageFormat qt_vg_image_to_vg_format ( QImage::Format  format)

Definition at line 4239 of file qpaintengine_vg.cpp.

Referenced by QVGPaintEngine::canVgWritePixels(), QVGPaintEngine::drawImage(), drawImageTiled(), QVGPixmapData::ensureReadback(), qt_vg_config_to_vg_format(), and QVGPixmapData::toVGImage().

4240 {
4241  switch (format) {
4243  return VG_BW_1;
4245  return VG_sL_8;
4247  return VG_sARGB_8888_PRE;
4248  case QImage::Format_RGB32:
4249  return VG_sXRGB_8888;
4250  case QImage::Format_ARGB32:
4251  return VG_sARGB_8888;
4252  case QImage::Format_RGB16:
4253  return VG_sRGB_565;
4255  return VG_sARGB_4444;
4256  default:
4257  break;
4258  }
4259  return VG_sARGB_8888; // XXX
4260 }

◆ qt_vg_pathToRect()

static bool qt_vg_pathToRect ( const QPainterPath path,
QRectF rect 
)
static

Definition at line 2077 of file qpaintengine_vg.cpp.

Referenced by QVGPaintEngine::clip().

2078 {
2079  if (path.elementCount() != 5)
2080  return false;
2081 
2082  const bool mightBeRect = path.elementAt(0).isMoveTo()
2083  && path.elementAt(1).isLineTo()
2084  && path.elementAt(2).isLineTo()
2085  && path.elementAt(3).isLineTo()
2086  && path.elementAt(4).isLineTo();
2087 
2088  if (!mightBeRect)
2089  return false;
2090 
2091  const qreal x1 = path.elementAt(0).x;
2092  const qreal y1 = path.elementAt(0).y;
2093 
2094  const qreal x2 = path.elementAt(1).x;
2095  const qreal y2 = path.elementAt(2).y;
2096 
2097  if (path.elementAt(1).y != y1)
2098  return false;
2099 
2100  if (path.elementAt(2).x != x2)
2101  return false;
2102 
2103  if (path.elementAt(3).x != x1 || path.elementAt(3).y != y2)
2104  return false;
2105 
2106  if (path.elementAt(4).x != x1 || path.elementAt(4).y != y1)
2107  return false;
2108 
2109  if (rect)
2110  *rect = QRectF(QPointF(x1, y1), QPointF(x2, y2));
2111 
2112  return true;
2113 }
double qreal
Definition: qglobal.h:1193
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
bool isLineTo() const
Returns true if the element is a line, otherwise returns false.
Definition: qpainterpath.h:84
qreal y
the y coordinate of the element&#39;s position.
Definition: qpainterpath.h:80
const QPainterPath::Element & elementAt(int i) const
Returns the element at the given index in the painter path.
Definition: qpainterpath.h:402
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
bool isMoveTo() const
Returns true if the element is moving the current position, otherwise returns false.
Definition: qpainterpath.h:83
qreal x
the x coordinate of the element&#39;s position.
Definition: qpainterpath.h:79
int elementCount() const
Returns the number of path elements in the painter path.
Definition: qpainterpath.h:397

◆ toVGImage()

static VGImage toVGImage ( const QImage image,
Qt::ImageConversionFlags  flags = Qt::AutoColor 
)
static

Definition at line 1044 of file qpaintengine_vg.cpp.

Referenced by colorizeBitmap(), QVGPaintEngine::drawImage(), and QVGPaintEnginePrivate::setBrush().

1045 {
1046  QImage img(image);
1047 
1048  VGImageFormat format;
1049  switch (img.format()) {
1050  case QImage::Format_Mono:
1051  img = image.convertToFormat(QImage::Format_MonoLSB, flags);
1052  img.invertPixels();
1053  format = VG_BW_1;
1054  break;
1056  img.invertPixels();
1057  format = VG_BW_1;
1058  break;
1059  case QImage::Format_RGB32:
1060  format = VG_sXRGB_8888;
1061  break;
1062  case QImage::Format_ARGB32:
1063  format = VG_sARGB_8888;
1064  break;
1066  format = VG_sARGB_8888_PRE;
1067  break;
1068  case QImage::Format_RGB16:
1069  format = VG_sRGB_565;
1070  break;
1071  default:
1072  // Convert everything else into ARGB32_Premultiplied.
1074  format = VG_sARGB_8888_PRE;
1075  break;
1076  }
1077 
1078  const uchar *pixels = img.constBits();
1079 
1080  VGImage vgImg = QVGImagePool::instance()->createPermanentImage
1081  (format, img.width(), img.height(), VG_IMAGE_QUALITY_FASTER);
1082  vgImageSubData
1083  (vgImg, pixels, img.bytesPerLine(), format, 0, 0,
1084  img.width(), img.height());
1085 
1086  return vgImg;
1087 }
virtual VGImage createPermanentImage(VGImageFormat format, VGint width, VGint height, VGbitfield allowedQuality)
unsigned char uchar
Definition: qglobal.h:994
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
const uchar * constBits() const
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1985
static QVGImagePool * instance()
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
void invertPixels(InvertMode=InvertRgb)
Inverts all pixel values in the image.
Definition: qimage.cpp:2179

◆ toVGImageSubRect()

static VGImage toVGImageSubRect ( const QImage image,
const QRect sr,
Qt::ImageConversionFlags  flags = Qt::AutoColor 
)
static

Definition at line 1090 of file qpaintengine_vg.cpp.

Referenced by QVGPaintEngine::drawImage(), and toVGImage().

1092 {
1093  QImage img(image);
1094 
1095  VGImageFormat format;
1096  int bpp = 4;
1097 
1098  switch (img.format()) {
1099  case QImage::Format_Mono:
1101  return VG_INVALID_HANDLE;
1102  case QImage::Format_RGB32:
1103  format = VG_sXRGB_8888;
1104  break;
1105  case QImage::Format_ARGB32:
1106  format = VG_sARGB_8888;
1107  break;
1109  format = VG_sARGB_8888_PRE;
1110  break;
1111  case QImage::Format_RGB16:
1112  format = VG_sRGB_565;
1113  bpp = 2;
1114  break;
1115  default:
1116  // Convert everything else into ARGB32_Premultiplied.
1118  format = VG_sARGB_8888_PRE;
1119  break;
1120  }
1121 
1122  const uchar *pixels = img.constBits() + bpp * sr.x() +
1123  img.bytesPerLine() * sr.y();
1124 
1125  VGImage vgImg = QVGImagePool::instance()->createPermanentImage
1126  (format, sr.width(), sr.height(), VG_IMAGE_QUALITY_FASTER);
1127  vgImageSubData
1128  (vgImg, pixels, img.bytesPerLine(), format, 0, 0,
1129  sr.width(), sr.height());
1130 
1131  return vgImg;
1132 }
virtual VGImage createPermanentImage(VGImageFormat format, VGint width, VGint height, VGbitfield allowedQuality)
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
unsigned char uchar
Definition: qglobal.h:994
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
const uchar * constBits() const
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1985
static QVGImagePool * instance()
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
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

◆ toVGImageWithOpacity()

static VGImage toVGImageWithOpacity ( const QImage image,
qreal  opacity 
)
static

Definition at line 1134 of file qpaintengine_vg.cpp.

Referenced by QVGPaintEngine::drawImage(), and QVGPaintEnginePrivate::setBrush().

1135 {
1137  img.fill(0);
1138  QPainter painter;
1139  painter.begin(&img);
1140  painter.setOpacity(opacity);
1141  painter.drawImage(0, 0, image);
1142  painter.end();
1143 
1144  const uchar *pixels = img.constBits();
1145 
1146  VGImage vgImg = QVGImagePool::instance()->createPermanentImage
1147  (VG_sARGB_8888_PRE, img.width(), img.height(), VG_IMAGE_QUALITY_FASTER);
1148  vgImageSubData
1149  (vgImg, pixels, img.bytesPerLine(), VG_sARGB_8888_PRE, 0, 0,
1150  img.width(), img.height());
1151 
1152  return vgImg;
1153 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
void fill(uint pixel)
Fills the entire image with the given pixelValue.
Definition: qimage.cpp:2032
virtual VGImage createPermanentImage(VGImageFormat format, VGint width, VGint height, VGbitfield allowedQuality)
bool begin(QPaintDevice *)
Begins painting the paint device and returns true if successful; otherwise returns false...
Definition: qpainter.cpp:1723
unsigned char uchar
Definition: qglobal.h:994
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587
static QVGImagePool * instance()
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Definition: qpainter.cpp:5936
void setOpacity(qreal opacity)
Sets the opacity of the painter to opacity.
Definition: qpainter.cpp:2139
bool end()
Ends painting.
Definition: qpainter.cpp:1929

◆ toVGImageWithOpacitySubRect()

static VGImage toVGImageWithOpacitySubRect ( const QImage image,
qreal  opacity,
const QRect sr 
)
static

Definition at line 1156 of file qpaintengine_vg.cpp.

Referenced by QVGPaintEngine::drawImage(), and toVGImageWithOpacity().

1157 {
1159  img.fill(0);
1160  QPainter painter;
1161  painter.begin(&img);
1162  painter.setOpacity(opacity);
1163  painter.drawImage(QPoint(0, 0), image, sr);
1164  painter.end();
1165 
1166  const uchar *pixels = img.constBits();
1167 
1168  VGImage vgImg = QVGImagePool::instance()->createPermanentImage
1169  (VG_sARGB_8888_PRE, img.width(), img.height(), VG_IMAGE_QUALITY_FASTER);
1170  vgImageSubData
1171  (vgImg, pixels, img.bytesPerLine(), VG_sARGB_8888_PRE, 0, 0,
1172  img.width(), img.height());
1173 
1174  return vgImg;
1175 }
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
void fill(uint pixel)
Fills the entire image with the given pixelValue.
Definition: qimage.cpp:2032
virtual VGImage createPermanentImage(VGImageFormat format, VGint width, VGint height, VGbitfield allowedQuality)
bool begin(QPaintDevice *)
Begins painting the paint device and returns true if successful; otherwise returns false...
Definition: qpainter.cpp:1723
unsigned char uchar
Definition: qglobal.h:994
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
static QVGImagePool * instance()
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Definition: qpainter.cpp:5936
void setOpacity(qreal opacity)
Sets the opacity of the painter to opacity.
Definition: qpainter.cpp:2139
bool end()
Ends painting.
Definition: qpainter.cpp:1929

Variable Documentation

◆ aliasedCoordinateDelta

const qreal aliasedCoordinateDelta = 0.5 - 0.015625
static