51 #include "private/qapplication_p.h" 52 #include "private/qgraphicssystem_p.h" 53 #include "private/qpaintengineex_p.h" 54 #include "private/qpaintengine_raster_p.h" 56 #include "private/qmath_p.h" 57 #include "private/qmemrotate_p.h" 58 #include "private/qdrawhelper_p.h" 60 #ifndef QT_NO_GRAPHICSEFFECT 127 d_func()->type =
type;
138 d_func()->type =
type;
224 delete[] convolutionKernel;
245 d->convoluteAlpha =
true;
271 delete []
d->convolutionKernel;
273 memcpy(
d->convolutionKernel, kernel,
sizeof(
qreal) * rows * columns);
275 d->kernelHeight =
rows;
286 return d->convolutionKernel;
297 return d->kernelHeight;
308 return d->kernelWidth;
318 return rect.
adjusted(-
d->kernelWidth / 2, -
d->kernelHeight / 2, (
d->kernelWidth - 1) / 2, (
d->kernelHeight - 1) / 2);
335 int *fixedKernel =
new int[kernelWidth*kernelHeight];
336 for(
int i = 0; i < kernelWidth*kernelHeight; i++)
338 fixedKernel[i] = (int)(65536 * kernel[i]);
342 QRectF bounded = trect.
adjusted(-kernelWidth / 2, -kernelHeight / 2, (kernelWidth - 1) / 2, (kernelHeight - 1) / 2);
347 QRectF sbounded = srect.
adjusted(-kernelWidth / 2, -kernelHeight / 2, (kernelWidth - 1) / 2, (kernelHeight - 1) / 2);
353 int yk = srcStartPoint.
y();
354 for (
int y = targetRect.
top(); y <= targetRect.
bottom(); y++) {
356 int xk = srcStartPoint.
x();
357 for(
int x = targetRect.
left(); x <= targetRect.
right(); x++) {
364 int kernely = -kernelHeight/2;
366 int endy = kernelHeight;
367 if(yk+kernely+endy >= srcImage.
height())
368 endy = kernelHeight-((yk+kernely+endy)-srcImage.
height())-1;
370 starty = -(yk+kernely);
372 int kernelx = -kernelWidth/2;
374 int endx = kernelWidth;
375 if(xk+kernelx+endx >= srcImage.
width())
376 endx = kernelWidth-((xk+kernelx+endx)-srcImage.
width())-1;
378 startx = -(xk+kernelx);
380 for (
int ys = starty; ys < endy; ys ++) {
381 const uint *pix = sourceStart + (processImage.
bytesPerLine()/
sizeof(
uint))*(yk+kernely+ys) + ((xk+kernelx+startx));
382 const uint *endPix = pix+endx-startx;
383 int kernelPos = ys*kernelWidth+startx;
384 while (pix < endPix) {
385 int factor = fixedKernel[kernelPos++];
386 a += (((*pix) & 0xff000000)>>24) * factor;
387 r += (((*pix) & 0x00ff0000)>>16) * factor;
388 g += (((*pix) & 0x0000ff00)>>8 ) * factor;
389 b += (((*pix) & 0x000000ff) ) * factor;
394 r =
qBound((
int)0, r >> 16, (
int)255);
395 g =
qBound((
int)0, g >> 16, (
int)255);
396 b =
qBound((
int)0, b >> 16, (
int)255);
397 a =
qBound((
int)0, a >> 16, (
int)255);
400 uint color = (a<<24)+(r<<16)+(g<<8)+b;
403 uint current = *output;
404 uchar ca = (current&0xff000000)>>24;
405 uchar cr = (current&0x00ff0000)>>16;
406 uchar cg = (current&0x0000ff00)>>8;
407 uchar cb = (current&0x000000ff);
409 (((ca*(255-
a) >> 8)+
a) << 24)+
410 (((cr*(255-
a) >> 8)+r) << 16)+
411 (((cg*(255-
a) >> 8)+g) << 8)+
412 (((cb*(255-
a) >> 8)+b));
419 delete[] fixedKernel;
431 if(
d->kernelWidth<=0 ||
d->kernelHeight <= 0)
440 if (convolutionFilter) {
442 convolutionFilter->d_func()->convoluteAlpha =
d->convoluteAlpha;
443 convolutionFilter->
draw(painter, p, src, srcRect);
490 d->convolutionKernel,
530 QGraphicsBlurEffect::BlurHints
hints;
616 return rect.
adjusted(-delta, -delta, delta, delta);
630 template<
int aprec,
int zprec>
635 #define Z_MASK (0xff << zprec) 639 const int B_zprec = qt_static_shift<zprec>(*pixel) &
Z_MASK;
642 const int zR_zprec = zR >> aprec;
643 const int zG_zprec = zG >> aprec;
644 const int zB_zprec = zB >> aprec;
645 const int zA_zprec = zA >> aprec;
647 zR += alpha * (R_zprec - zR_zprec);
648 zG += alpha * (G_zprec - zG_zprec);
649 zB += alpha * (B_zprec - zB_zprec);
650 zA += alpha * (A_zprec - zA_zprec);
652 #define ZA_MASK (0xff << (zprec + aprec)) 655 | qt_static_shift<16 - zprec - aprec>(zR &
ZA_MASK)
657 | qt_static_shift<-zprec - aprec>(zB & ZA_MASK);
661 const int alphaIndex = (QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3);
663 template<
int aprec,
int zprec>
666 const int A_zprec = int(*(bptr)) << zprec;
667 const int z_zprec = z >> aprec;
668 z += alpha * (A_zprec - z_zprec);
669 *(bptr) = z >> (zprec + aprec);
672 template<
int aprec,
int zprec,
bool alphaOnly>
677 int zR = 0, zG = 0, zB = 0, zA = 0;
682 const int stride = im.
depth() >> 3;
683 const int im_width = im.
width();
686 qt_blurinner_alphaOnly<aprec, zprec>(bptr, zA, alpha);
688 qt_blurinner<aprec, zprec>(bptr, zR, zG, zB, zA, alpha);
697 qt_blurinner_alphaOnly<aprec, zprec>(bptr, zA, alpha);
699 qt_blurinner<aprec, zprec>(bptr, zR, zG, zB, zA, alpha);
720 template <
int aprec,
int zprec,
bool alphaOnly>
725 radius *=
qreal(0.5);
734 const qreal cutOffIntensity = 2;
735 int alpha = radius <=
qreal(1e-5)
737 :
qRound((1<<aprec)*(1 -
qPow(cutOffIntensity * (1 /
qreal(255)), 1 / radius)));
739 int img_height = img.
height();
740 for (
int row = 0; row < img_height; ++row) {
741 for (
int i = 0; i <= int(improvedQuality); ++i)
742 qt_blurrow<aprec, zprec, alphaOnly>(img, row, alpha);
746 if (transposed >= 0) {
747 if (img.
depth() == 8) {
750 reinterpret_cast<quint8*
>(temp.bits()),
751 temp.bytesPerLine());
755 reinterpret_cast<quint32*
>(temp.bits()),
756 temp.bytesPerLine());
759 if (img.
depth() == 8) {
762 reinterpret_cast<quint8*
>(temp.bits()),
763 temp.bytesPerLine());
767 reinterpret_cast<quint32*
>(temp.bits()),
768 temp.bytesPerLine());
772 img_height = temp.height();
773 for (
int row = 0; row < img_height; ++row) {
774 for (
int i = 0; i <= int(improvedQuality); ++i)
775 qt_blurrow<aprec, zprec, alphaOnly>(temp, row, alpha);
778 if (transposed == 0) {
779 if (img.
depth() == 8) {
781 temp.width(), temp.height(), temp.bytesPerLine(),
786 temp.width(), temp.height(), temp.bytesPerLine(),
794 #define AVG(a,b) ( ((((a)^(b)) & 0xfefefefeUL) >> 1) + ((a)&(b)) ) 795 #define AVG16(a,b) ( ((((a)^(b)) & 0xf7deUL) >> 1) + ((a)&(b)) ) 808 const uchar *src =
reinterpret_cast<const uchar*
>(
const_cast<const QImage &
>(srcImage).bits());
812 uchar *dst =
reinterpret_cast<uchar*
>(dest.bits());
813 int dx = dest.bytesPerLine();
814 int ww = dest.width();
815 int hh = dest.height();
817 for (
int y = hh; y; --y, dst += dx, src += sx2) {
818 const uchar *p1 = src;
819 const uchar *p2 = src + sx;
821 for (
int x = ww; x; --x, ++q, p1 += 2, p2 += 2)
822 *q = ((
int(p1[0]) +
int(p1[1]) +
int(p2[0]) +
int(p2[1])) + 2) >> 2;
829 const uchar *src =
reinterpret_cast<const uchar*
>(
const_cast<const QImage &
>(srcImage).bits());
833 uchar *dst =
reinterpret_cast<uchar*
>(dest.bits());
834 int dx = dest.bytesPerLine();
835 int ww = dest.width();
836 int hh = dest.height();
838 for (
int y = hh; y; --y, dst += dx, src += sx2) {
839 const uchar *p1 = src;
840 const uchar *p2 = src + sx;
842 for (
int x = ww; x; --x, q += 3, p1 += 6, p2 += 6) {
844 q[0] =
AVG(
AVG(p1[0], p1[3]),
AVG(p2[0], p2[3]));
846 const quint16 p16_1 = (p1[2] << 8) | p1[1];
847 const quint16 p16_2 = (p1[5] << 8) | p1[4];
848 const quint16 p16_3 = (p2[2] << 8) | p2[1];
849 const quint16 p16_4 = (p2[5] << 8) | p2[4];
851 q[1] = result & 0xff;
865 const quint32 *src =
reinterpret_cast<const quint32*
>(
const_cast<const QImage &
>(srcImage).bits());
870 int dx = dest.bytesPerLine() >> 2;
871 int ww = dest.width();
872 int hh = dest.height();
874 for (
int y = hh; y; --y, dst += dx, src += sx2) {
878 for (
int x = ww; x; --x, q++, p1 += 2, p2 += 2)
879 *q =
AVG(
AVG(p1[0], p1[1]),
AVG(p2[0], p2[1]));
894 if (radius >= 4 && blurImage.
width() >= 2 && blurImage.
height() >= 2) {
897 radius *=
qreal(0.5);
901 expblur<12, 10, true>(blurImage,
radius, quality, transposed);
903 expblur<12, 10, false>(blurImage,
radius, quality, transposed);
906 p->
scale(scale, scale);
908 p->
drawImage(
QRect(0, 0, blurImage.width(), blurImage.height()), blurImage);
915 expblur<12, 10, true>(blurImage, radius, quality, transposed);
917 expblur<12, 10, false>(blurImage,
radius, quality, transposed);
936 srcRect = src.
rect();
938 if (
d->radius <= 1) {
946 scaledRadius /= scale;
954 blurFilter->
draw(painter, p, src, srcRect);
961 if (srcRect == src.
rect()) {
979 QRect destRect = rect;
980 QRect srcRect = rect;
982 srcRect = dest.
rect();
983 destRect = dest.
rect();
985 if (&image != &dest) {
989 unsigned int *
data = (
unsigned int *)image.
bits();
990 unsigned int *outData = (
unsigned int *)dest.
bits();
992 if (dest.
size() == image.
size() && image.
rect() == srcRect) {
995 for (
int i = 0; i < pixels; ++i) {
996 int val =
qGray(data[i]);
997 outData[i] =
qRgba(val, val, val,
qAlpha(data[i]));
1000 int yd = destRect.
top();
1001 for (
int y = srcRect.
top(); y <= srcRect.
bottom() && y < image.
height(); y++) {
1002 data = (
unsigned int*)image.
scanLine(y);
1003 outData = (
unsigned int*)dest.
scanLine(yd++);
1004 int xd = destRect.
left();
1005 for (
int x = srcRect.
left(); x <= srcRect.
right() && x < image.
width(); x++) {
1006 int val =
qGray(data[x]);
1007 outData[xd++] =
qRgba(val, val, val,
qAlpha(data[x]));
1061 d->alphaBlend =
false;
1124 if (colorizeFilter) {
1127 colorizeFilter->
draw(painter, dest, src, srcRect);
1157 destPainter.fillRect(srcImage.
rect(),
d->color);
1160 if (
d->alphaBlend) {
1162 QImage buffer = srcImage;
1180 : offset(8, 8),
color(63, 63, 63, 180), radius(1) {}
1364 if (dropShadowFilter) {
1368 dropShadowFilter->
draw(p, pos, px, src);
1389 blackenPainter.
fillRect(blurred.rect(),
d->color);
1390 blackenPainter.
end();
1401 #endif //QT_NO_GRAPHICSEFFECT qreal radius() const
Gets the radius of the blur filter.
The QPainter class performs low-level painting on widgets and other paint devices.
The QColor class provides colors based on RGB, HSV or CMYK values.
QRect toAlignedRect() const
Returns a QRect based on the values of this rectangle that is the smallest possible integer rectangle...
void setColor(const QColor &color)
Sets the color of the drop shadow to the color specified.
QImage toImage() const
Converts the pixmap to a QImage.
void setConvolutionKernel(const qreal *matrix, int rows, int columns)
Sets convolution kernel with the given number of rows and columns.
static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qreal threshold)
void qt_blurinner_alphaOnly(uchar *bptr, int &z, int alpha)
qreal * convolutionKernel
const QTransform & transform() const
Returns the world transformation matrix.
#define QT_END_NAMESPACE
This macro expands to.
QPaintDevice * paintDevice() const
Returns the device that this engine is painting on, if painting is active; otherwise returns 0...
QPixmapBlurFilter(QObject *parent=0)
Constructs a pixmap blur filter.
QSize size() const
Returns the size of the pixmap.
CompositionMode
Defines the modes supported for digital image compositing.
Q_GUI_EXPORT void qt_blurImage(QPainter *p, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed=0)
int qt_static_shift(int value)
QPixmapDropShadowFilter(QObject *parent=0)
Constructs drop shadow filter.
Q_GUI_EXPORT_INLINE int qAlpha(QRgb rgb)
Q_GUI_EXPORT QImage qt_halfScaled(const QImage &source)
virtual ~QPixmapFilter()=0
Destroys the pixmap filter.
ClipType clipType() const
Returns the type of the clip currently set.
void qt_blurrow(QImage &im, int line, int alpha)
QPixmapBlurFilterPrivate()
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 ...
void fill(uint pixel)
Fills the entire image with the given pixelValue.
Q_GUI_EXPORT bool qt_scaleForTransform(const QTransform &transform, qreal *scale)
The QPointF class defines a point in the plane using floating point precision.
QRect clipBoundingRect() const
Returns the bounding rect of the currently set clip.
FilterType type() const
Returns the type of the filter.
int left() const
Returns the x-coordinate of the rectangle's left edge.
QPixmapColorizeFilter(QObject *parent=0)
Constructs an pixmap colorize filter.
bool hasAlphaChannel() const
Returns true if the image has a format that respects the alpha channel, otherwise returns false...
int bytesPerLine() const
Returns the number of bytes per image scanline.
long ASN1_INTEGER_get ASN1_INTEGER * a
QRect intersected(const QRect &other) const
Returns the intersection of this rectangle and the given rectangle.
bool isExtended() const
Returns true if the paint engine is a QPaintEngineEx derivative.
void moveTo(int x, int t)
Moves the rectangle, leaving the top-left corner at the given position (x, y).
void setOffset(const QPointF &offset)
Sets the shadow offset in pixels to the offset specified.
int bottom() const
Returns the y-coordinate of the rectangle's bottom edge.
QRect rect() const
Returns the enclosing rectangle (0, 0, width(), height()) of the image.
The QObject class is the base class of all Qt objects.
The QGraphicsBlurEffect class provides a blur effect.
static void grayscale(const QImage &image, QImage &dest, const QRect &rect=QRect())
void Q_GUI_EXPORT qt_memrotate90(const quint32 *, int, int, int, quint32 *, int)
QRectF boundingRectFor(const QRectF &rect) const
virtual int devType() const
Format format() const
Returns the format of the image.
void qt_blurinner(uchar *bptr, int &zR, int &zG, int &zB, int &zA, int alpha)
void setBlurHints(QGraphicsBlurEffect::BlurHints hints)
Setting the blur hints to PerformanceHint causes the implementation to trade off visual quality to bl...
qreal x() const
Returns the x-coordinate of this point.
void setBlurRadius(qreal radius)
Sets the radius in pixels of the blur on the drop shadow to the radius specified. ...
bool contains(const QPointF &p) const
Returns true if the given point is inside or on the edge of the rectangle; otherwise returns false...
QPixmapConvolutionFilterPrivate()
~QPixmapConvolutionFilter()
Destructor of pixmap convolution filter.
QGraphicsBlurEffect::BlurHints hints
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint...
FilterType
This enum describes the types of filter that can be applied to pixmaps.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Q_GUI_EXPORT_INLINE QRgb qRgba(int r, int g, int b, int a)
The QRectF class defines a rectangle in the plane using floating point precision. ...
QColor color() const
Gets the color of the colorize filter.
const qreal * convolutionKernel() const
Gets the convolution kernel data.
The QPixmapColorizeFilter class provides colorizing filtering for pixmaps.
void setStrength(qreal strength)
Sets the strength of the colorize filter to strength.
bool isActive() const
Returns true if begin() has been called and end() has not yet been called; otherwise returns false...
QSize size() const
Returns the size of the rectangle.
The QPixmapBlurFilter class provides blur filtering for pixmaps.
The QImage class provides a hardware-independent image representation that allows direct access to th...
static const char * data(const QByteArray &arr)
const QTransform & deviceTransform() const
Returns the matrix that transforms from logical coordinates to device coordinates of the platform dep...
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...
qreal blurRadius() const
Returns the radius in pixels of the blur on the drop shadow.
int depth() const
Returns the depth of the image.
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 ...
QPixmapConvolutionFilter(QObject *parent=0)
Constructs a pixmap convolution filter.
qreal qPow(qreal x, qreal y)
QRect toRect() const
Returns a QRect based on the values of this rectangle.
~QPixmapConvolutionFilterPrivate()
QImage alphaChannel() const
Returns the alpha channel of the image as a new grayscale QImage in which each pixel's red...
void setColor(const QColor &color)
Sets the color of the colorize filter to the color specified.
QPixmapFilter::FilterType type
QSize size() const
Returns the size of the image, i.
int rows() const
Gets the number of rows in the convolution kernel.
Q_GUI_EXPORT_INLINE int qGray(int r, int g, int b)
uchar * bits()
Returns a pointer to the first pixel data.
int top() const
Returns the y-coordinate of the rectangle's top edge.
int width() const
Returns the width of the image.
QGraphicsBlurEffect::BlurHints blurHints() const
Gets the blur hints of the blur filter.
int columns() const
Gets the number of columns in the convolution kernel.
#define Q_DECLARE_PUBLIC(Class)
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
int right() const
Returns the x-coordinate of the rectangle's right edge.
const QTransform & worldTransform() const
Returns the world transformation matrix.
static void convolute(QImage *destImage, const QPointF &pos, const QImage &srcImage, const QRectF &srcRect, QPainter::CompositionMode mode, qreal *kernel, int kernelWidth, int kernelHeight)
void setCompositionMode(CompositionMode mode)
Sets the composition mode to the given mode.
QRectF boundingRectFor(const QRectF &rect) const
void Q_GUI_QWS_EXPORT qt_memrotate270(const quint32 *, int, int, int, quint32 *, int)
QColor color() const
Returns the color of the drop shadow.
The QPixmapFilter class provides the basic functionality for pixmap filter classes.
~QPixmapDropShadowFilter()
Destroys drop shadow filter.
QObject * parent() const
Returns a pointer to the parent object.
The QPoint class defines a point in the plane using integer precision.
QRectF united(const QRectF &other) const
Returns the bounding rectangle of this rectangle and the given rectangle.
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
The QPixmapDropShadowFilter class is a convenience class for drawing pixmaps with drop shadows...
QRectF boundingRectFor(const QRectF &rect) const
The QRect class defines a rectangle in the plane using integer precision.
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
void setWorldTransform(const QTransform &matrix, bool combine=false)
Sets the world transformation matrix.
int height() const
Returns the height of the image.
void moveTo(qreal x, qreal t)
Moves the rectangle, leaving the top-left corner at the given position (x, y).
QRect rect() const
Returns the pixmap's enclosing rectangle.
int y() const
Returns the y coordinate of this point.
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
QPixmapFilter(QPixmapFilterPrivate &d, FilterType type, QObject *parent)
qreal y() const
Returns the y-coordinate of this point.
The QPixmap class is an off-screen image representation that can be used as a paint device...
The QPixmapConvolutionFilter class provides convolution filtering for pixmaps.
void scale(qreal sx, qreal sy)
Scales the coordinate system by ({sx}, {sy}).
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...
static Q_DECL_CONSTEXPR bool qFuzzyIsNull(double d)
void setRadius(qreal radius)
Sets the radius of the blur filter.
int x() const
Returns the x coordinate of this point.
The QRasterPaintEngine class enables hardware acceleration of painting operations in Qt for Embedded ...
void setOpacity(qreal opacity)
Sets the opacity of the painter to opacity.
void setAlphaChannel(const QImage &alphaChannel)
Sets the alpha channel of this image to the given alphaChannel.
QPixmapDropShadowFilterPrivate()
bool isNull() const
Returns true if this is a null pixmap; otherwise returns false.
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...
QPixmap copy(int x, int y, int width, int height) const
Returns a deep copy of the subset of the pixmap that is specified by the rectangle QRect( x...
bool isEmpty() const
Returns true if the rectangle is empty, otherwise returns false.
void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect=QRectF()) const
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 *p, const QPointF &pos, const QPixmap &px, const QRectF &src=QRectF()) const
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
QPointF offset() const
Returns the shadow offset in pixels.
void expblur(QImage &img, qreal radius, bool improvedQuality=false, int transposed=0)
Q_DECL_CONSTEXPR int qRound(qreal d)
void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect=QRectF()) const
void draw(QPainter *painter, const QPointF &dest, const QPixmap &src, const QRectF &srcRect=QRectF()) const
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
void fillRect(const QRectF &, const QBrush &)
Fills the given rectangle with the brush specified.
~QPixmapBlurFilter()
Destructor of pixmap blur filter.
QPoint topLeft() const
Returns the position of the rectangle's top-left corner.
void translate(const QPointF &offset)
Translates the coordinate system by the given offset; i.e.