13#include "private/qguiapplication_p.h"
14#include "private/qpaintengineex_p.h"
15#include "private/qpaintengine_raster_p.h"
17#include "private/qmath_p.h"
18#include "private/qdrawhelper_p.h"
82 d_func()->type =
type;
93 d_func()->type =
type;
197 d->convoluteAlpha =
true;
223 delete []
d->convolutionKernel;
224 d->convolutionKernel =
new qreal[rows * columns];
225 memcpy(
d->convolutionKernel,
kernel,
sizeof(
qreal) * rows * columns);
226 d->kernelWidth = columns;
227 d->kernelHeight = rows;
235const qreal *QPixmapConvolutionFilter::convolutionKernel()
const
238 return d->convolutionKernel;
246int QPixmapConvolutionFilter::rows()
const
249 return d->kernelHeight;
257int QPixmapConvolutionFilter::columns()
const
260 return d->kernelWidth;
270 return rect.adjusted(-
d->kernelWidth / 2, -
d->kernelHeight / 2, (
d->kernelWidth - 1) / 2, (
d->kernelHeight - 1) / 2);
287 std::unique_ptr<int[]> fixedKernel(
new int[kernelWidth * kernelHeight]);
288 for(
int i = 0;
i < kernelWidth*kernelHeight;
i++)
290 fixedKernel[
i] = (int)(65536 *
kernel[
i]);
292 QRectF trect = srcRect.
isNull() ? processImage.rect() : srcRect;
294 QRectF bounded = trect.
adjusted(-kernelWidth / 2, -kernelHeight / 2, (kernelWidth - 1) / 2, (kernelHeight - 1) / 2);
298 QRectF srect = srcRect.
isNull() ? processImage.rect() : srcRect;
299 QRectF sbounded = srect.
adjusted(-kernelWidth / 2, -kernelHeight / 2, (kernelWidth - 1) / 2, (kernelHeight - 1) / 2);
300 QPoint srcStartPoint = sbounded.toAlignedRect().topLeft()+(targetRect.topLeft()-
rect.topLeft());
302 const uint *sourceStart = (
const uint*)processImage.scanLine(0);
303 uint *outputStart = (
uint*)destImage->scanLine(0);
305 int yk = srcStartPoint.
y();
306 for (
int y = targetRect.top();
y <= targetRect.bottom();
y++) {
307 uint*
output = outputStart + (destImage->bytesPerLine()/
sizeof(
uint))*
y+targetRect.left();
308 int xk = srcStartPoint.x();
309 for(
int x = targetRect.left();
x <= targetRect.right();
x++) {
316 int kernely = -kernelHeight/2;
318 int endy = kernelHeight;
319 if (yk+kernely+endy >= srcImage.height())
320 endy = kernelHeight-((yk+kernely+endy)-srcImage.height())-1;
322 starty = -(yk+kernely);
324 int kernelx = -kernelWidth/2;
326 int endx = kernelWidth;
327 if (xk+kernelx+endx >= srcImage.width())
328 endx = kernelWidth-((xk+kernelx+endx)-srcImage.width())-1;
330 startx = -(xk+kernelx);
332 for (
int ys = starty; ys < endy; ys ++) {
333 const uint *
pix = sourceStart + (processImage.bytesPerLine()/
sizeof(
uint))*(yk+kernely+ys) + ((xk+kernelx+startx));
334 const uint *endPix =
pix+endx-startx;
335 int kernelPos = ys*kernelWidth+startx;
336 while (
pix < endPix) {
337 int factor = fixedKernel[kernelPos++];
338 a += (((*pix) & 0xff000000)>>24) * factor;
339 r += (((*pix) & 0x00ff0000)>>16) * factor;
340 g += (((*pix) & 0x0000ff00)>>8 ) * factor;
341 b += (((*pix) & 0x000000ff) ) * factor;
346 r =
qBound((
int)0,
r >> 16, (
int)255);
347 g =
qBound((
int)0,
g >> 16, (
int)255);
348 b =
qBound((
int)0,
b >> 16, (
int)255);
349 a =
qBound((
int)0,
a >> 16, (
int)255);
356 uchar ca = (current&0xff000000)>>24;
357 uchar cr = (current&0x00ff0000)>>16;
358 uchar cg = (current&0x0000ff00)>>8;
359 uchar cb = (current&0x000000ff);
361 (((ca*(255-
a) >> 8)+
a) << 24)+
362 (((cr*(255-
a) >> 8)+
r) << 16)+
363 (((cg*(255-
a) >> 8)+
g) << 8)+
364 (((
cb*(255-
a) >> 8)+
b));
382 if (
d->kernelWidth<=0 ||
d->kernelHeight <= 0)
405 QRectF clip = pe->clipBoundingRect();
431 d->convolutionKernel,
468 QGraphicsBlurEffect::BlurHints
hints;
554 return rect.adjusted(-delta, -delta, delta, delta);
574 if (srcRect.isNull())
575 srcRect =
src.rect();
577 if (
d->radius <= 1) {
585 scaledRadius /=
scale;
589 if (srcRect ==
src.rect()) {
590 srcImage =
src.toImage();
593 srcImage =
src.copy(
rect).toImage();
610 srcRect = dest.
rect();
611 destRect = dest.
rect();
613 if (&
image != &dest) {
617 const unsigned int *
data = (
const unsigned int *)
image.bits();
618 unsigned int *outData = (
unsigned int *)dest.
bits();
628 int yd = destRect.top();
629 for (
int y = srcRect.top();
y <= srcRect.bottom() &&
y <
image.height();
y++) {
630 data = (
const unsigned int*)
image.scanLine(
y);
631 outData = (
unsigned int*)dest.
scanLine(yd++);
632 int xd = destRect.left();
633 for (
int x = srcRect.left();
x <= srcRect.right() &&
x <
image.width();
x++) {
686 d->alphaBlend =
false;
763 if (srcRect.isNull()) {
764 srcImage =
src.toImage();
766 srcImage = std::move(srcImage).convertToFormat(
format);
767 destImage =
QImage(srcImage.size(), srcImage.format());
771 srcImage =
src.copy(
rect).toImage();
773 srcImage = std::move(srcImage).convertToFormat(
format);
774 destImage =
QImage(
rect.size(), srcImage.format());
776 destImage.setDevicePixelRatio(
src.devicePixelRatio());
780 grayscale(srcImage, destImage, srcImage.rect());
782 destPainter.fillRect(srcImage.rect(),
d->color);
789 bufPainter.setOpacity(
d->strength);
790 bufPainter.drawImage(0, 0, destImage);
792 destImage = std::move(
buffer);
795 if (srcImage.hasAlphaChannel()) {
799 maskPainter.drawImage(0, 0, srcImage);
968 return rect.united(
rect.translated(
d->offset).adjusted(-
d->radius, -
d->radius,
d->radius,
d->radius));
989 tmpPainter.drawPixmap(
d->offset, px);
994 blurred.setDevicePixelRatio(px.devicePixelRatio());
1000 tmp = std::move(blurred);
1003 tmpPainter.begin(&tmp);
1005 tmpPainter.fillRect(tmp.
rect(),
d->color);
1009 p->drawImage(
pos, tmp);
1017#include "moc_qpixmapfilter_p.cpp"
The QColor class provides colors based on RGB, HSV or CMYK values.
The QGraphicsBlurEffect class provides a blur effect.
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false.
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
QSize size() const
Returns the size of the image, i.e.
int width() const
Returns the width of the image.
uchar * bits()
Returns a pointer to the first pixel data.
int height() const
Returns the height of the image.
@ Format_ARGB32_Premultiplied
void fill(uint pixel)
Fills the entire image with the given pixelValue.
QRect rect() const
Returns the enclosing rectangle (0, 0, width(), height()) of the image.
void setDevicePixelRatio(qreal scaleFactor)
Sets the device pixel ratio for the image.
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const &
virtual int devType() const
QPaintDevice * paintDevice() const
Returns the device that this engine is painting on, if painting is active; otherwise returns \nullptr...
The QPainter class performs low-level painting on widgets and other paint devices.
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
QTransform combinedTransform() const
Returns the transformation matrix combining the current window/viewport and world transformation.
const QTransform & worldTransform() const
Returns the world transformation matrix.
void setWorldTransform(const QTransform &matrix, bool combine=false)
Sets the world transformation matrix.
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Draws the rectangular portion source of the given image into the target rectangle in the paint device...
const QTransform & deviceTransform() const
Returns the matrix that transforms from logical coordinates to device coordinates of the platform dep...
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.
const QTransform & transform() const
Alias for worldTransform().
CompositionMode
Defines the modes supported for digital image compositing.
@ CompositionMode_SourceOver
@ CompositionMode_DestinationIn
@ CompositionMode_SourceIn
bool isActive() const
Returns true if begin() has been called and end() has not yet been called; otherwise returns false.
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.
QPixmapBlurFilterPrivate()
QGraphicsBlurEffect::BlurHints hints
The QPixmapBlurFilter class provides blur filtering for pixmaps.
void setBlurHints(QGraphicsBlurEffect::BlurHints hints)
Setting the blur hints to PerformanceHint causes the implementation to trade off visual quality to bl...
QPixmapBlurFilter(QObject *parent=nullptr)
Constructs a pixmap blur filter.
void setRadius(qreal radius)
Sets the radius of the blur filter.
QGraphicsBlurEffect::BlurHints blurHints() const
Gets the blur hints of the blur filter.
QRectF boundingRectFor(const QRectF &rect) const override
qreal radius() const
Gets the radius of the blur filter.
~QPixmapBlurFilter()
Destructor of pixmap blur filter.
void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect=QRectF()) const override
The QPixmapColorizeFilter class provides colorizing filtering for pixmaps.
QColor color() const
Gets the color of the colorize filter.
qreal strength() const
Gets the strength of the colorize filter, 1.0 means full colorized while 0.0 equals to no filtering a...
void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect=QRectF()) const override
QPixmapColorizeFilter(QObject *parent=nullptr)
Constructs an pixmap colorize filter.
void setStrength(qreal strength)
Sets the strength of the colorize filter to strength.
void setColor(const QColor &color)
Sets the color of the colorize filter to the color specified.
QPixmapConvolutionFilterPrivate()
~QPixmapConvolutionFilterPrivate()
qreal * convolutionKernel
The QPixmapConvolutionFilter class provides convolution filtering for pixmaps.
void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect=QRectF()) const override
QPixmapConvolutionFilter(QObject *parent=nullptr)
Constructs a pixmap convolution filter.
void setConvolutionKernel(const qreal *matrix, int rows, int columns)
Sets convolution kernel with the given number of rows and columns.
~QPixmapConvolutionFilter()
Destructor of pixmap convolution filter.
QRectF boundingRectFor(const QRectF &rect) const override
QPixmapDropShadowFilterPrivate()
The QPixmapDropShadowFilter class is a convenience class for drawing pixmaps with drop shadows.
void setOffset(const QPointF &offset)
Sets the shadow offset in pixels to the offset specified.
qreal blurRadius() const
Returns the radius in pixels of the blur on the drop shadow.
QPixmapDropShadowFilter(QObject *parent=nullptr)
Constructs drop shadow filter.
QColor color() const
Returns the color of the drop shadow.
QRectF boundingRectFor(const QRectF &rect) const override
void draw(QPainter *p, const QPointF &pos, const QPixmap &px, const QRectF &src=QRectF()) const override
void setColor(const QColor &color)
Sets the color of the drop shadow to the color specified.
QPointF offset() const
Returns the shadow offset in pixels.
~QPixmapDropShadowFilter()
Destroys drop shadow filter.
void setBlurRadius(qreal radius)
Sets the radius in pixels of the blur on the drop shadow to the radius specified.
QPixmapFilter::FilterType type
The QPixmapFilter class provides the basic functionality for pixmap filter classes....
virtual QRectF boundingRectFor(const QRectF &rect) const
Returns the bounding rectangle that is affected by the pixmap filter if the filter is applied to the ...
virtual ~QPixmapFilter()=0
Destroys the pixmap filter.
FilterType type() const
Returns the type of the filter.
QPixmapFilter(QPixmapFilterPrivate &d, FilterType type, QObject *parent)
Returns a copy of the pixmap that is transformed using the given transformation transform and transfo...
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
constexpr int y() const noexcept
Returns the y coordinate of this point.
The QRasterPaintEngine class enables hardware acceleration of painting operations in Qt for Embedded ...
\inmodule QtCore\reentrant
QRect toAlignedRect() const noexcept
bool contains(const QRectF &r) const noexcept
This is an overloaded member function, provided for convenience. It differs from the above function o...
constexpr QRectF adjusted(qreal x1, qreal y1, qreal x2, qreal y2) const noexcept
Returns a new rectangle with dx1, dy1, dx2 and dy2 added respectively to the existing coordinates of ...
constexpr bool isNull() const noexcept
Returns true if the rectangle is a null rectangle, otherwise returns false.
constexpr QRect toRect() const noexcept
Returns a QRect based on the values of this rectangle.
\inmodule QtCore\reentrant
constexpr bool isNull() const noexcept
Returns true if the rectangle is a null rectangle, otherwise returns false.
QRect intersected(const QRect &other) const noexcept
constexpr void moveTo(int x, int t) noexcept
Moves the rectangle, leaving the top-left corner at the given position (x, y).
Combined button and popup list for selecting options.
bool qFuzzyIsNull(qfloat16 f) noexcept
Q_GUI_EXPORT void qt_blurImage(QPainter *p, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed=0)
constexpr const T & qBound(const T &min, const T &val, const T &max)
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum GLenum const void * pixels
GLint GLsizei GLsizei GLenum format
GLuint GLenum GLenum transform
GLenum GLenum GLenum GLenum GLenum scale
Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale)
Q_GUI_EXPORT void qt_blurImage(QPainter *p, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed=0)
Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale)
static void grayscale(const QImage &image, QImage &dest, const QRect &rect=QRect())
static void convolute(QImage *destImage, const QPointF &pos, const QImage &srcImage, const QRectF &srcRect, QPainter::CompositionMode mode, qreal *kernel, int kernelWidth, int kernelHeight)
constexpr int qGray(int r, int g, int b)
constexpr QRgb qRgba(int r, int g, int b, int a)
constexpr int qAlpha(QRgb rgb)
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
QT_BEGIN_NAMESPACE typedef uchar * output