Qt 4.8
Public Functions | Private Functions | Friends | List of all members
QPixmapConvolutionFilter Class Reference

The QPixmapConvolutionFilter class provides convolution filtering for pixmaps. More...

#include <qpixmapfilter_p.h>

Inheritance diagram for QPixmapConvolutionFilter:
QPixmapFilter QObject QGLPixmapFilter< QPixmapConvolutionFilter > QVGPixmapConvolutionFilter QGLPixmapConvolutionFilter

Public Functions

QRectF boundingRectFor (const QRectF &rect) const
 
void draw (QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect=QRectF()) const
 
 QPixmapConvolutionFilter (QObject *parent=0)
 Constructs a pixmap convolution filter. More...
 
void setConvolutionKernel (const qreal *matrix, int rows, int columns)
 Sets convolution kernel with the given number of rows and columns. More...
 
 ~QPixmapConvolutionFilter ()
 Destructor of pixmap convolution 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...
 

Private Functions

int columns () const
 Gets the number of columns in the convolution kernel. More...
 
const qrealconvolutionKernel () const
 Gets the convolution kernel data. More...
 
int rows () const
 Gets the number of rows in the convolution kernel. More...
 

Friends

class QGLPixmapConvolutionFilter
 
class QVGPixmapConvolutionFilter
 

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 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 Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

The QPixmapConvolutionFilter class provides convolution filtering for pixmaps.

Since
4.5

QPixmapConvolutionFilter implements a convolution pixmap filter, which is applied when QPixmapFilter::draw() is called. A convolution filter lets you distort an image by setting the values of a matrix of qreal values called its kernel. The matrix's values are usually between -1.0 and 1.0.

Warning
This function is not part of the public interface. In convolution filtering, the pixel value is calculated from the neighboring pixels based on the weighting convolution kernel. This needs explaining to be useful.

Example:

qreal kernel[] = {
0.0,-1.0, 0.0,
-1.0, 5.0,-1.0,
0.0,-1.0, 0.0
};
myFilter->setConvolutionKernel(kernel, 3, 3);
myFilter->draw(painter, QPoint(0, 0), originalPixmap);
See also
{Pixmap Filters Example}, QPixmapColorizeFilter, QPixmapDropShadowFilter
Warning
This function is not part of the public interface.

Definition at line 101 of file qpixmapfilter_p.h.

Constructors and Destructors

◆ QPixmapConvolutionFilter()

QPixmapConvolutionFilter::QPixmapConvolutionFilter ( QObject parent = 0)

Constructs a pixmap convolution filter.

By default there is no convolution kernel.

Warning
This function is not part of the public interface.

Definition at line 241 of file qpixmapfilter.cpp.

243 {
245  d->convoluteAlpha = true;
246 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
QPixmapFilter(QPixmapFilterPrivate &d, FilterType type, QObject *parent)
The QPixmapConvolutionFilter class provides convolution filtering for pixmaps.

◆ ~QPixmapConvolutionFilter()

QPixmapConvolutionFilter::~QPixmapConvolutionFilter ( )

Destructor of pixmap convolution filter.

Warning
This function is not part of the public interface.

Definition at line 253 of file qpixmapfilter.cpp.

254 {
255 }

Functions

◆ boundingRectFor()

QRectF QPixmapConvolutionFilter::boundingRectFor ( const QRectF rect) const
virtual
Warning
This function is not part of the public interface.

Reimplemented from QPixmapFilter.

Definition at line 315 of file qpixmapfilter.cpp.

Referenced by draw().

316 {
318  return rect.adjusted(-d->kernelWidth / 2, -d->kernelHeight / 2, (d->kernelWidth - 1) / 2, (d->kernelHeight - 1) / 2);
319 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
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
The QPixmapConvolutionFilter class provides convolution filtering for pixmaps.

◆ columns()

int QPixmapConvolutionFilter::columns ( ) const
private

Gets the number of columns in the convolution kernel.

Warning
This function is not part of the public interface.

Definition at line 305 of file qpixmapfilter.cpp.

Referenced by QVGPixmapConvolutionFilter::draw(), QGLPixmapConvolutionFilter::processGL(), and setConvolutionKernel().

306 {
308  return d->kernelWidth;
309 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPixmapConvolutionFilter class provides convolution filtering for pixmaps.

◆ convolutionKernel()

const qreal * QPixmapConvolutionFilter::convolutionKernel ( ) const
private

Gets the convolution kernel data.

Warning
This function is not part of the public interface.

Definition at line 283 of file qpixmapfilter.cpp.

Referenced by QVGPixmapConvolutionFilter::draw().

284 {
286  return d->convolutionKernel;
287 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPixmapConvolutionFilter class provides convolution filtering for pixmaps.

◆ draw()

void QPixmapConvolutionFilter::draw ( QPainter painter,
const QPointF p,
const QPixmap src,
const QRectF srcRect = QRectF() 
) const
virtual
Warning
This function is not part of the public interface.

Implements QPixmapFilter.

Reimplemented in QGLPixmapFilter< QPixmapConvolutionFilter >, and QVGPixmapConvolutionFilter.

Definition at line 425 of file qpixmapfilter.cpp.

Referenced by QVGPixmapConvolutionFilter::draw(), and draw().

426 {
428  if (!painter->isActive())
429  return;
430 
431  if(d->kernelWidth<=0 || d->kernelHeight <= 0)
432  return;
433 
434  if (src.isNull())
435  return;
436 
437  QPixmapFilter *filter = painter->paintEngine() && painter->paintEngine()->isExtended() ?
438  static_cast<QPaintEngineEx *>(painter->paintEngine())->pixmapFilter(type(), this) : 0;
439  QPixmapConvolutionFilter *convolutionFilter = static_cast<QPixmapConvolutionFilter*>(filter);
440  if (convolutionFilter) {
441  convolutionFilter->setConvolutionKernel(d->convolutionKernel, d->kernelWidth, d->kernelHeight);
442  convolutionFilter->d_func()->convoluteAlpha = d->convoluteAlpha;
443  convolutionFilter->draw(painter, p, src, srcRect);
444  return;
445  }
446 
447  // falling back to raster implementation
448 
449  QImage *target = 0;
450  if (painter->paintEngine()->paintDevice()->devType() == QInternal::Image) {
451  target = static_cast<QImage *>(painter->paintEngine()->paintDevice());
452 
453  QTransform mat = painter->combinedTransform();
454 
455  if (mat.type() > QTransform::TxTranslate) {
456  // Disabled because of transformation...
457  target = 0;
458  } else {
459  QRasterPaintEngine *pe = static_cast<QRasterPaintEngine *>(painter->paintEngine());
461  // disabled because of complex clipping...
462  target = 0;
463  else {
464  QRectF clip = pe->clipBoundingRect();
465  QRectF rect = boundingRectFor(srcRect.isEmpty() ? src.rect() : srcRect);
466  QTransform x = painter->deviceTransform();
467  if (!clip.contains(rect.translated(x.dx() + p.x(), x.dy() + p.y()))) {
468  target = 0;
469  }
470 
471  }
472  }
473  }
474 
475  if (target) {
476  QTransform x = painter->deviceTransform();
477  QPointF offset(x.dx(), x.dy());
478 
479  convolute(target, p+offset, src.toImage(), srcRect, QPainter::CompositionMode_SourceOver, d->convolutionKernel, d->kernelWidth, d->kernelHeight);
480  } else {
481  QRect srect = srcRect.isNull() ? src.rect() : srcRect.toRect();
482  QRect rect = boundingRectFor(srect).toRect();
484  QPoint offset = srect.topLeft() - rect.topLeft();
485  convolute(&result,
486  offset,
487  src.toImage(),
488  srect,
490  d->convolutionKernel,
491  d->kernelWidth,
492  d->kernelHeight);
493  painter->drawImage(p - offset, result);
494  }
495 }
double d
Definition: qnumeric_p.h:62
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
qreal dy() const
Returns the vertical translation factor.
Definition: qtransform.h:277
void setConvolutionKernel(const qreal *matrix, int rows, int columns)
Sets convolution kernel with the given number of rows and columns.
QPaintDevice * paintDevice() const
Returns the device that this engine is painting on, if painting is active; otherwise returns 0...
ClipType clipType() const
Returns the type of the clip currently set.
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
QRect clipBoundingRect() const
Returns the bounding rect of the currently set clip.
FilterType type() const
Returns the type of the filter.
bool isExtended() const
Returns true if the paint engine is a QPaintEngineEx derivative.
Definition: qpaintengine.h:234
TransformationType type() const
Returns the transformation type of this matrix.
#define Q_D(Class)
Definition: qglobal.h:2482
virtual int devType() const
Definition: qpaintdevice.h:167
qreal x() const
Returns the x-coordinate of this point.
Definition: qpoint.h:282
bool contains(const QPointF &p) const
Returns true if the given point is inside or on the edge of the rectangle; otherwise returns false...
Definition: qrect.cpp:2349
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
bool isActive() const
Returns true if begin() has been called and end() has not yet been called; otherwise returns false...
Definition: qpainter.cpp:1545
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
const QTransform & deviceTransform() const
Returns the matrix that transforms from logical coordinates to device coordinates of the platform dep...
Definition: qpainter.cpp:9579
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
Definition: qpainter.cpp:1991
QTransform combinedTransform() const
Returns the transformation matrix combining the current window/viewport and world transformation...
Definition: qpainter.cpp:9669
QRect toRect() const
Returns a QRect based on the values of this rectangle.
Definition: qrect.h:845
static void convolute(QImage *destImage, const QPointF &pos, const QImage &srcImage, const QRectF &srcRect, QPainter::CompositionMode mode, qreal *kernel, int kernelWidth, int kernelHeight)
QRectF boundingRectFor(const QRectF &rect) const
The QPixmapFilter class provides the basic functionality for pixmap filter classes.
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
qreal dx() const
Returns the horizontal translation factor.
Definition: qtransform.h:273
QRect rect() const
Returns the pixmap&#39;s enclosing rectangle.
Definition: qpixmap.cpp:676
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Definition: qpainter.cpp:5936
qreal y() const
Returns the y-coordinate of this point.
Definition: qpoint.h:287
The QPixmapConvolutionFilter class provides convolution filtering for pixmaps.
The QRasterPaintEngine class enables hardware acceleration of painting operations in Qt for Embedded ...
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
Definition: qpixmap.cpp:615
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
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
Definition: qrect.h:658
void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect=QRectF()) const
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655
The QTransform class specifies 2D transformations of a coordinate system.
Definition: qtransform.h:65
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288

◆ rows()

int QPixmapConvolutionFilter::rows ( ) const
private

Gets the number of rows in the convolution kernel.

Warning
This function is not part of the public interface.

Definition at line 294 of file qpixmapfilter.cpp.

Referenced by QVGPixmapConvolutionFilter::draw(), QGLPixmapConvolutionFilter::processGL(), and setConvolutionKernel().

295 {
297  return d->kernelHeight;
298 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QPixmapConvolutionFilter class provides convolution filtering for pixmaps.

◆ setConvolutionKernel()

void QPixmapConvolutionFilter::setConvolutionKernel ( const qreal kernel,
int  rows,
int  columns 
)

Sets convolution kernel with the given number of rows and columns.

Values from kernel are copied to internal data structure.

To preserve the intensity of the pixmap, the sum of all the values in the convolution kernel should add up to 1.0. A sum greater than 1.0 produces a lighter result and a sum less than 1.0 produces a darker and transparent result.

Warning
This function is not part of the public interface.

Definition at line 268 of file qpixmapfilter.cpp.

Referenced by draw().

269 {
271  delete [] d->convolutionKernel;
272  d->convolutionKernel = new qreal[rows * columns];
273  memcpy(d->convolutionKernel, kernel, sizeof(qreal) * rows * columns);
274  d->kernelWidth = columns;
275  d->kernelHeight = rows;
276 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
#define Q_D(Class)
Definition: qglobal.h:2482
int rows() const
Gets the number of rows in the convolution kernel.
int columns() const
Gets the number of columns in the convolution kernel.
The QPixmapConvolutionFilter class provides convolution filtering for pixmaps.

Friends and Related Functions

◆ QGLPixmapConvolutionFilter

Definition at line 116 of file qpixmapfilter_p.h.

◆ QVGPixmapConvolutionFilter

Definition at line 117 of file qpixmapfilter_p.h.


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