42 #include "private/qpixmapfilter_p.h" 43 #include "private/qpixmapdata_gl_p.h" 44 #include "private/qpaintengineex_opengl2_p.h" 45 #include "private/qglengineshadermanager_p.h" 46 #include "private/qpixmapdata_p.h" 47 #include "private/qimagepixmapcleanuphooks_p.h" 57 #include "private/qapplication_p.h" 58 #include "private/qdrawhelper_p.h" 59 #include "private/qmemrotate_p.h" 60 #include "private/qmath_p.h" 135 if (!
d->colorizeFilter)
137 return d->colorizeFilter.data();
142 return d->blurFilter.data();
146 if (!
d->dropShadowFilter)
148 return d->dropShadowFilter.data();
152 if (!
d->convolutionFilter)
154 return d->convolutionFilter.data();
162 "uniform lowp vec4 colorizeColor;" 163 "uniform lowp float colorizeStrength;" 164 "lowp vec4 customShader(lowp sampler2D src, highp vec2 srcCoords)" 166 " lowp vec4 srcPixel = texture2D(src, srcCoords);" 167 " lowp float gray = dot(srcPixel.rgb, vec3(0.212671, 0.715160, 0.072169));" 168 " lowp vec3 colorized = 1.0-((1.0-gray)*(1.0-colorizeColor.rgb));" 169 " return vec4(mix(srcPixel.rgb, colorized * srcPixel.a, colorizeStrength), srcPixel.a);" 196 const qreal *kernel = convolutionKernel();
197 int kernelWidth = columns();
198 int kernelHeight = rows();
199 int kernelSize = kernelWidth * kernelHeight;
204 for(
int i = 0; i < kernelSize; ++i)
205 matrix[i] = kernel[i];
207 for(
int y = 0; y < kernelHeight; ++y) {
208 for(
int x = 0; x < kernelWidth; ++x) {
209 offset[(y * kernelWidth + x) * 2] = x - (kernelWidth / 2);
210 offset[(y * kernelWidth + x) * 2 + 1] = (kernelHeight / 2) - y;
214 const qreal iw = 1.0 / m_srcSize.width();
215 const qreal ih = 1.0 / m_srcSize.height();
224 int kernelWidth = columns();
225 int kernelHeight = rows();
226 int kernelSize = kernelWidth * kernelHeight;
227 code.
append(
"uniform highp vec2 inv_texture_size;\n" 228 "uniform mediump float matrix[");
231 "uniform highp vec2 offset[");
234 code.
append(
"lowp vec4 customShader(lowp sampler2D src, highp vec2 srcCoords) {\n");
236 code.
append(
" int i = 0;\n" 237 " lowp vec4 sum = vec4(0.0);\n" 238 " for (i = 0; i < ");
241 " sum += matrix[i] * texture2D(src,srcCoords+inv_texture_size*offset[i]);\n" 249 : m_prevKernelSize(-1)
287 m_paddedImage << image;
292 glDeleteTextures(1, &m_texture);
295 QImage paddedImage(
int scaleLevel = 0)
const;
307 for (
int i = m_paddedImage.size() - 1; i <= scaleLevel; ++i)
310 return m_paddedImage.at(scaleLevel);
322 bool hasBlurTextureInfo(
quint64 cacheKey)
const;
324 void clearBlurTextureInfo(
quint64 cacheKey);
344 cache.setMaxCost(4 * 1024 * 1024);
345 blurTextureCaches.append(
this);
350 blurTextureCaches.removeAt(blurTextureCaches.indexOf(
this));
363 return qt_blur_texture_caches()->value(context);
368 return cache.take(pixmap.
cacheKey());
373 cache.remove(cacheKey);
378 return cache.contains(cacheKey);
383 static bool hookAdded =
false;
413 glGenTextures(1, &texture);
422 uint mod = x % multiplier;
425 return x + multiplier - mod;
438 qreal actualRadius = radius();
454 if (!info || info->
radius() < actualRadius) {
455 QSize paddedSize = targetRect.
size() / 2;
465 p.drawImage((padding - oldPadding) / 2, (padding - oldPadding) / 2, info->
paddedImage());
475 reinterpret_cast<quint32*
>(padded.scanLine(padding / 2)) + padding / 2,
476 padded.bytesPerLine());
482 textureSize = paddedSize;
487 actualRadius *=
qreal(0.5);
490 if (actualRadius <= 16)
492 actualRadius *=
qreal(0.5);
495 const int s = (1 << level);
498 padding =
qMin(prepadding,
qCeil(actualRadius) << level);
499 targetRect = src.
rect().
adjusted(-padding, -padding, padding, padding);
504 int paddingDelta = (prepadding - padding) >> level;
506 QRect subRect(paddingDelta, paddingDelta, targetRect.
width() >> level, targetRect.
height() >> level);
510 qt_rectcopy((
QRgb *)subImage.bits(), ((
QRgb *)sourceImage.scanLine(paddingDelta)) + paddingDelta,
511 0, 0, subRect.height(), subRect.width(), subImage.bytesPerLine(), sourceImage.bytesPerLine());
513 GLuint texture = info->
texture();
518 QRect textureSubRect = subImage.rect().
adjusted(0, 0, -1, -1);
530 engine->drawTexture(targetRectF.
translated(pos), texture, textureSize, textureSubRect);
538 "uniform lowp vec4 shadowColor;" 539 "lowp vec4 customShader(lowp sampler2D src, highp vec2 srcCoords)" 541 " return shadowColor * texture2D(src, srcCoords.yx).a;" 554 qreal r = blurRadius();
555 QRectF targetRectUnaligned =
QRectF(src.
rect()).translated(pos + offset()).adjusted(-r, -r, r, r);
566 if (!info || info->
radius() != r) {
569 qreal rx = r + targetRect.
left() - targetRectUnaligned.
left();
570 qreal ry = r + targetRect.
top() - targetRectUnaligned.
top();
584 glGenTextures(1, &texture);
592 GLuint texture = info->
texture();
void setUniforms(QGLShaderProgram *program)
int startTimer(int interval)
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer...
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.
QByteArray generateConvolutionShader() const
QRect toAlignedRect() const
Returns a QRect based on the values of this rectangle that is the smallest possible integer rectangle...
const T * constData() const
QImage toImage() const
Converts the pixmap to a QImage.
void clearBlurTextureInfo(quint64 cacheKey)
qreal alphaF() const
Returns the alpha color component of this color.
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 ...
void setHeight(int h)
Sets the height of the rectangle to the given height.
bool processGL(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &srcRect) const
static mach_timebase_info_data_t info
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
int width() const
Returns the width of the pixmap.
QSize size() const
Returns the size of the pixmap.
void addPixmapDataModificationHook(_qt_pixmap_cleanup_hook_pmd)
qreal greenF() const
Returns the green color component of this color.
void setColorTable(const QVector< QRgb > colors)
Sets the color table used to translate color indexes to QRgb values, to the specified colors...
QByteArray & append(char c)
Appends the character ch to this byte array.
QList< QImage > m_paddedImage
void fill(uint pixel)
Fills the entire image with the given pixelValue.
The QByteArray class provides an array of bytes.
The QPointF class defines a point in the plane using floating point precision.
qreal left() const
Returns the x-coordinate of the rectangle's left edge.
virtual void timerEvent(QTimerEvent *)
This event handler can be reimplemented in a subclass to receive timer events for the object...
int left() const
Returns the x-coordinate of the rectangle's left edge.
int width() const
Returns the width of the rectangle.
QGLPixmapConvolutionFilter()
int bytesPerLine() const
Returns the number of bytes per image scanline.
static void enableCleanupHooks(const QImage &image)
int height() const
Returns the height of the rectangle.
QRect rect() const
Returns the enclosing rectangle (0, 0, width(), height()) of the image.
Q_GUI_EXPORT QImage qt_halfScaled(const QImage &source)
The QObject class is the base class of all Qt objects.
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
GLuint bindTexture(const QImage &image, GLenum target, GLint format, BindOptions options)
Generates and binds a 2D GL texture to the current context, based on image.
bool hasBlurTextureInfo(quint64 cacheKey) const
static const QGLContext * currentContext()
Returns the current context, i.e.
void setSource(const QByteArray &)
const QGLContext * qt_gl_share_context()
void insertBlurTextureInfo(const QPixmap &pixmap, QGLBlurTextureInfo *info)
QPixmapFilter * pixmapFilter(int type, const QPixmapFilter *prototype)
void setUniformValueArray(int location, const GLfloat *values, int count, int tupleSize)
Sets the uniform variable array at location in the current context to the count elements of values...
QGLBlurTextureInfo(const QImage &image, GLuint tex, qreal r)
int width() const
Returns the width.
void setRenderHint(RenderHint hint, bool on=true)
Sets the given render hint on the painter if on is true; otherwise clears the render hint...
#define QT_BEGIN_NAMESPACE
This macro expands to.
QCache< quint64, QGLBlurTextureInfo > cache
The QRectF class defines a rectangle in the plane using floating point precision. ...
virtual QPixmapFilter * pixmapFilter(int, const QPixmapFilter *)
static uint nextMultiple(uint x, uint multiplier)
void drawImpl(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &srcRect=QRectF()) const
static const int qAnimatedBlurLevelIncrement
void addPixmapDataDestructionHook(_qt_pixmap_cleanup_hook_pmd)
void setUniforms(QGLShaderProgram *program)
The QGLContext class encapsulates an OpenGL rendering context.
bool processGL(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &srcRect) const
qreal height() const
Returns the height of the rectangle.
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
QSize size() const
Returns the size of the rectangle.
virtual bool processGL(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &srcRect) const =0
The QImage class provides a hardware-independent image representation that allows direct access to th...
QGLPixmapColorizeFilter()
qreal width() const
Returns the width of the rectangle.
QPaintEngine * paintEngine() const
Returns the paint engine that the painter is currently operating on if the painter is active; otherwi...
void bindTexture(const QPixmap &src) const
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 ...
static GLuint generateBlurTexture(const QSize &size, GLenum format=GL_RGBA)
void setUniforms(QGLShaderProgram *program)
QImage alphaChannel() const
Returns the alpha channel of the image as a new grayscale QImage in which each pixel's red...
QSize size() const
Returns the size of the image, i.
int rows() const
Gets the number of rows in the convolution kernel.
static QByteArray prototype(const QList< QByteArray > ¶meterTypes, const QList< QByteArray > ¶meterNames, bool *ok)
uchar * bits()
Returns a pointer to the first pixel data.
static const char * qt_gl_drop_shadow_filter
int top() const
Returns the y-coordinate of the rectangle's top edge.
int width() const
Returns the width of the image.
int columns() const
Gets the number of columns in the convolution kernel.
bool drawTexture(const QRectF &r, GLuint textureId, const QSize &size, const QRectF &sr)
void setUniformValue(int location, GLfloat value)
Sets the uniform variable at location in the current context to value.
The QTimerEvent class contains parameters that describe a timer event.
qreal x() const
Returns the x-coordinate of the rectangle's left edge.
The QPixmapFilter class provides the basic functionality for pixmap filter classes.
bool processGL(QPainter *painter, const QPointF &pos, const QPixmap &pixmap, const QRectF &srcRect) const
void qt_rectcopy(T *dest, const T *src, int x, int y, int width, int height, int dstStride, int srcStride)
qreal redF() const
Returns the red color component of this color.
static QGLBlurTextureCache * cacheForContext(const QGLContext *context)
void setWidth(int w)
Sets the width of the rectangle to the given width.
Q_GUI_EXPORT void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed=0)
~QGLPixmapConvolutionFilter()
int height() const
Returns the height.
qreal blueF() const
Returns the blue color component of this color.
The QRect class defines a rectangle in the plane using integer precision.
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
int height() const
Returns the height of the image.
qint64 cacheKey() const
Returns a number that identifies this QPixmap.
QRect rect() const
Returns the pixmap's enclosing rectangle.
The QPixmap class is an off-screen image representation that can be used as a paint device...
Q_GUI_EXPORT void qt_memrotate90_gl(const quint32 *src, int srcWidth, int srcHeight, int srcStride, quint32 *dest, int dstStride)
qreal top() const
Returns the y-coordinate of the rectangle's top edge.
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...
int height() const
Returns the height of the pixmap.
static void pixmapDestroyed(QPixmapData *pixmap)
void timerEvent(QTimerEvent *event)
This event handler can be reimplemented in a subclass to receive timer events for the object...
The QSize class defines the size of a two-dimensional object using integer point precision.
QGLBlurTextureInfo * takeBlurTextureInfo(const QPixmap &pixmap)
qreal bottom() const
Returns the y-coordinate of the rectangle's bottom edge.
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...
static QImagePixmapCleanupHooks * instance()
static const int qMaxBlurHalfScaleLevel
bool setOnPainter(QPainter *)
QImage paddedImage(int scaleLevel=0) const
bool processGL(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &srcRect) const
static const char * qt_gl_colorize_filter
The QGLShaderProgram class allows OpenGL shader programs to be linked and used.
static QByteArray number(int, int base=10)
Returns a byte array containing the string equivalent of the number n to base base (10 by default)...
QVector< QRgb > colorTable() const
Returns a list of the colors contained in the image's color table, or an empty list if the image does...
void removeFromPainter(QPainter *)
Q_DECL_CONSTEXPR int qRound(qreal d)
static QList< QGLBlurTextureCache * > blurTextureCaches
void killTimer(int id)
Kills the timer with timer identifier, id.
QGLPixmapDropShadowFilter()