Qt 4.8
Public Functions | Protected Functions | List of all members
QGLPixmapBlurFilter Class Reference
Inheritance diagram for QGLPixmapBlurFilter:
QGLCustomShaderStage QGLPixmapFilter< QPixmapBlurFilter > QPixmapBlurFilter QGLPixmapFilterBase QPixmapFilter QObject

Public Functions

 QGLPixmapBlurFilter ()
 
- Public Functions inherited from QGLCustomShaderStage
 QGLCustomShaderStage ()
 
void removeFromPainter (QPainter *)
 
void setInactive ()
 
bool setOnPainter (QPainter *)
 
virtual void setUniforms (QGLShaderProgram *)
 
void setUniformsDirty ()
 
QByteArray source () const
 
virtual ~QGLCustomShaderStage ()
 
- Public Functions inherited from QGLPixmapFilter< QPixmapBlurFilter >
void draw (QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &srcRect=QRectF()) const
 
- Public Functions inherited from QPixmapBlurFilter
QGraphicsBlurEffect::BlurHints blurHints () const
 Gets the blur hints of the blur filter. More...
 
QRectF boundingRectFor (const QRectF &rect) const
 
 QPixmapBlurFilter (QObject *parent=0)
 Constructs a pixmap blur filter. More...
 
qreal radius () const
 Gets the radius of the blur filter. More...
 
void setBlurHints (QGraphicsBlurEffect::BlurHints hints)
 Setting the blur hints to PerformanceHint causes the implementation to trade off visual quality to blur the image faster. More...
 
void setRadius (qreal radius)
 Sets the radius of the blur filter. More...
 
 ~QPixmapBlurFilter ()
 Destructor of pixmap blur filter. More...
 
- Public Functions inherited from QPixmapFilter
FilterType type () const
 Returns the type of the filter. More...
 
virtual ~QPixmapFilter ()=0
 Destroys the pixmap filter. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 
- Public Functions inherited from QGLPixmapFilterBase
virtual ~QGLPixmapFilterBase ()
 

Protected Functions

bool processGL (QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &srcRect) const
 
- Protected Functions inherited from QGLCustomShaderStage
void setSource (const QByteArray &)
 
- Protected Functions inherited from QPixmapFilter
 QPixmapFilter (QPixmapFilterPrivate &d, FilterType type, QObject *parent)
 
 QPixmapFilter (FilterType type, QObject *parent)
 Constructs a default QPixmapFilter with the given type. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Functions inherited from QGLPixmapFilterBase
void bindTexture (const QPixmap &src) const
 
void drawImpl (QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &srcRect=QRectF()) const
 

Additional Inherited Members

- Public Types inherited from QPixmapFilter
enum  FilterType {
  ConvolutionFilter, ColorizeFilter, DropShadowFilter, BlurFilter,
  UserFilter = 1024
}
 This enum describes the types of filter that can be applied to pixmaps. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 108 of file qglpixmapfilter.cpp.

Constructors and Destructors

◆ QGLPixmapBlurFilter()

QGLPixmapBlurFilter::QGLPixmapBlurFilter ( )

Definition at line 276 of file qglpixmapfilter.cpp.

277 {
278 }

Functions

◆ processGL()

bool QGLPixmapBlurFilter::processGL ( QPainter painter,
const QPointF pos,
const QPixmap src,
const QRectF srcRect 
) const
protectedvirtual

Implements QGLPixmapFilterBase.

Definition at line 431 of file qglpixmapfilter.cpp.

432 {
433  if (radius() < 1) {
434  painter->drawPixmap(pos, src);
435  return true;
436  }
437 
438  qreal actualRadius = radius();
439 
441 
444  int padding = nextMultiple(qCeil(actualRadius), qAnimatedBlurLevelIncrement);
445  QRect targetRect = src.rect().adjusted(-padding, -padding, padding, padding);
446 
447  // pad so that we'll be able to half-scale qMaxBlurHalfScaleLevel times
448  targetRect.setWidth((targetRect.width() + (qMaxBlurHalfScaleLevel-1)) & ~(qMaxBlurHalfScaleLevel-1));
449  targetRect.setHeight((targetRect.height() + (qMaxBlurHalfScaleLevel-1)) & ~(qMaxBlurHalfScaleLevel-1));
450 
451  QSize textureSize;
452 
453  info = blurTextureCache->takeBlurTextureInfo(src);
454  if (!info || info->radius() < actualRadius) {
455  QSize paddedSize = targetRect.size() / 2;
456 
457  QImage padded(paddedSize.height(), paddedSize.width(), QImage::Format_ARGB32_Premultiplied);
458  padded.fill(0);
459 
460  if (info) {
461  int oldPadding = qRound(info->radius());
462 
463  QPainter p(&padded);
464  p.setCompositionMode(QPainter::CompositionMode_Source);
465  p.drawImage((padding - oldPadding) / 2, (padding - oldPadding) / 2, info->paddedImage());
466  p.end();
467  } else {
468  // TODO: combine byteswapping and memrotating into one by declaring
469  // custom GL_RGBA pixel type and qt_colorConvert template for it
470  QImage prepadded = qt_halfScaled(src.toImage()).convertToFormat(QImage::Format_ARGB32_Premultiplied);
471 
472  // byte-swap and memrotates in one go
473  qt_memrotate90_gl(reinterpret_cast<const quint32*>(prepadded.bits()),
474  prepadded.width(), prepadded.height(), prepadded.bytesPerLine(),
475  reinterpret_cast<quint32*>(padded.scanLine(padding / 2)) + padding / 2,
476  padded.bytesPerLine());
477  }
478 
479  delete info;
480  info = new QGLBlurTextureInfo(padded, generateBlurTexture(paddedSize), padding);
481 
482  textureSize = paddedSize;
483  } else {
484  textureSize = QSize(info->paddedImage().height(), info->paddedImage().width());
485  }
486 
487  actualRadius *= qreal(0.5);
488  int level = 1;
489  for (; level < qMaxBlurHalfScaleLevel; ++level) {
490  if (actualRadius <= 16)
491  break;
492  actualRadius *= qreal(0.5);
493  }
494 
495  const int s = (1 << level);
496 
497  int prepadding = qRound(info->radius());
498  padding = qMin(prepadding, qCeil(actualRadius) << level);
499  targetRect = src.rect().adjusted(-padding, -padding, padding, padding);
500 
501  targetRect.setWidth(targetRect.width() & ~(s-1));
502  targetRect.setHeight(targetRect.height() & ~(s-1));
503 
504  int paddingDelta = (prepadding - padding) >> level;
505 
506  QRect subRect(paddingDelta, paddingDelta, targetRect.width() >> level, targetRect.height() >> level);
507  QImage sourceImage = info->paddedImage(level-1);
508 
509  QImage subImage(subRect.height(), subRect.width(), QImage::Format_ARGB32_Premultiplied);
510  qt_rectcopy((QRgb *)subImage.bits(), ((QRgb *)sourceImage.scanLine(paddingDelta)) + paddingDelta,
511  0, 0, subRect.height(), subRect.width(), subImage.bytesPerLine(), sourceImage.bytesPerLine());
512 
513  GLuint texture = info->texture();
514 
515  qt_blurImage(subImage, actualRadius, blurHints() & QGraphicsBlurEffect::QualityHint, 1);
516 
517  // subtract one pixel off the end to prevent the bilinear sampling from sampling uninitialized data
518  QRect textureSubRect = subImage.rect().adjusted(0, 0, -1, -1);
519  QRectF targetRectF = QRectF(targetRect).adjusted(0, 0, -targetRect.width() / qreal(textureSize.width()), -targetRect.height() / qreal(textureSize.height()));
520 
521  glBindTexture(GL_TEXTURE_2D, texture);
522  glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, subImage.width(), subImage.height(), GL_RGBA,
523  GL_UNSIGNED_BYTE, const_cast<const QImage &>(subImage).bits());
524 
525  QGL2PaintEngineEx *engine = static_cast<QGL2PaintEngineEx *>(painter->paintEngine());
527 
528  // texture is flipped on the y-axis
529  targetRectF = QRectF(targetRectF.x(), targetRectF.bottom(), targetRectF.width(), -targetRectF.height());
530  engine->drawTexture(targetRectF.translated(pos), texture, textureSize, textureSubRect);
531 
532  blurTextureCache->insertBlurTextureInfo(src, info);
533 
534  return true;
535 }
qreal radius() const
Gets the radius of the blur filter.
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
unsigned int QRgb
Definition: qrgb.h:53
QRect adjusted(int x1, int y1, int x2, int y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:431
void setHeight(int h)
Sets the height of the rectangle to the given height.
Definition: qrect.h:445
double qreal
Definition: qglobal.h:1193
static mach_timebase_info_data_t info
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
int qCeil(qreal v)
Definition: qmath.h:63
void fill(uint pixel)
Fills the entire image with the given pixelValue.
Definition: qimage.cpp:2032
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
Q_GUI_EXPORT QImage qt_halfScaled(const QImage &source)
#define GL_TEXTURE_2D
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
void insertBlurTextureInfo(const QPixmap &pixmap, QGLBlurTextureInfo *info)
int width() const
Returns the width.
Definition: qsize.h:126
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint...
Definition: qpainter.cpp:7620
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
static uint nextMultiple(uint x, uint multiplier)
static const int qAnimatedBlurLevelIncrement
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
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
qreal width() const
Returns the width of the rectangle.
Definition: qrect.h:707
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
Definition: qpainter.cpp:1991
QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
Definition: qrect.h:781
static GLuint generateBlurTexture(const QSize &size, GLenum format=GL_RGBA)
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QGraphicsBlurEffect::BlurHints blurHints() const
Gets the blur hints of the blur filter.
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
#define GL_UNSIGNED_BYTE
void qt_rectcopy(T *dest, const T *src, int x, int y, int width, int height, int dstStride, int srcStride)
static QGLBlurTextureCache * cacheForContext(const QGLContext *context)
#define ctx
Definition: qgl.cpp:6094
unsigned int quint32
Definition: qglobal.h:938
void setWidth(int w)
Sets the width of the rectangle to the given width.
Definition: qrect.h:442
Q_GUI_EXPORT void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed=0)
int height() const
Returns the height.
Definition: qsize.h:129
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
QRect rect() const
Returns the pixmap&#39;s enclosing rectangle.
Definition: qpixmap.cpp:676
Q_GUI_EXPORT void qt_memrotate90_gl(const quint32 *src, int srcWidth, int srcHeight, int srcStride, quint32 *dest, int dstStride)
Definition: qmemrotate.cpp:591
#define GL_RGBA
void drawPixmap(const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)
Draws the rectangular portion source of the given pixmap into the given target in the paint device...
Definition: qpainter.cpp:5619
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QGLBlurTextureInfo * takeBlurTextureInfo(const QPixmap &pixmap)
qreal bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:528
QRectF translated(qreal dx, qreal dy) const
Returns a copy of the rectangle that is translated dx along the x axis and dy along the y axis...
Definition: qrect.h:740
static const int qMaxBlurHalfScaleLevel
QImage paddedImage(int scaleLevel=0) const
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

The documentation for this class was generated from the following file: