Qt 4.8
qglpixmapfilter.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtOpenGL module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
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"
48 #include "qglpixmapfilter_p.h"
49 #include "qgraphicssystem_gl_p.h"
50 #include "qpaintengine_opengl_p.h"
51 #include "qcache.h"
52 
53 #include "qglframebufferobject.h"
54 #include "qglshaderprogram.h"
55 #include "qgl_p.h"
56 
57 #include "private/qapplication_p.h"
58 #include "private/qdrawhelper_p.h"
59 #include "private/qmemrotate_p.h"
60 #include "private/qmath_p.h"
61 #include "qmath.h"
62 
64 
65 // qpixmapfilter.cpp
66 Q_GUI_EXPORT void qt_blurImage(QImage &blurImage, qreal radius, bool quality, int transposed = 0);
68 
70 {
72 }
73 
74 void QGLPixmapFilterBase::drawImpl(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF& source) const
75 {
76  processGL(painter, pos, src, source);
77 }
78 
79 class QGLPixmapColorizeFilter: public QGLCustomShaderStage, public QGLPixmapFilter<QPixmapColorizeFilter>
80 {
81 public:
83 
84  void setUniforms(QGLShaderProgram *program);
85 
86 protected:
87  bool processGL(QPainter *painter, const QPointF &pos, const QPixmap &pixmap, const QRectF &srcRect) const;
88 };
89 
90 class QGLPixmapConvolutionFilter: public QGLCustomShaderStage, public QGLPixmapFilter<QPixmapConvolutionFilter>
91 {
92 public:
95 
96  void setUniforms(QGLShaderProgram *program);
97 
98 protected:
99  bool processGL(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &srcRect) const;
100 
101 private:
102  QByteArray generateConvolutionShader() const;
103 
104  mutable QSize m_srcSize;
105  mutable int m_prevKernelSize;
106 };
107 
108 class QGLPixmapBlurFilter : public QGLCustomShaderStage, public QGLPixmapFilter<QPixmapBlurFilter>
109 {
110 public:
112 
113 protected:
114  bool processGL(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &srcRect) const;
115 };
116 
117 class QGLPixmapDropShadowFilter : public QGLCustomShaderStage, public QGLPixmapFilter<QPixmapDropShadowFilter>
118 {
119 public:
121 
122  void setUniforms(QGLShaderProgram *program);
123 
124 protected:
125  bool processGL(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &srcRect) const;
126 };
127 
128 extern const QGLContext *qt_gl_share_context();
129 
131 {
133  switch (type) {
135  if (!d->colorizeFilter)
136  d->colorizeFilter.reset(new QGLPixmapColorizeFilter);
137  return d->colorizeFilter.data();
138 
140  if (!d->blurFilter)
141  d->blurFilter.reset(new QGLPixmapBlurFilter());
142  return d->blurFilter.data();
143  }
144 
146  if (!d->dropShadowFilter)
147  d->dropShadowFilter.reset(new QGLPixmapDropShadowFilter());
148  return d->dropShadowFilter.data();
149  }
150 
152  if (!d->convolutionFilter)
153  d->convolutionFilter.reset(new QGLPixmapConvolutionFilter);
154  return d->convolutionFilter.data();
155 
156  default: break;
157  }
158  return QPaintEngineEx::pixmapFilter(type, prototype);
159 }
160 
161 static const char *qt_gl_colorize_filter =
162  "uniform lowp vec4 colorizeColor;"
163  "uniform lowp float colorizeStrength;"
164  "lowp vec4 customShader(lowp sampler2D src, highp vec2 srcCoords)"
165  "{"
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);"
170  "}";
171 
173 {
174  setSource(qt_gl_colorize_filter);
175 }
176 
177 bool QGLPixmapColorizeFilter::processGL(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &) const
178 {
180 
181  filter->setOnPainter(painter);
182  painter->drawPixmap(pos, src);
183  filter->removeFromPainter(painter);
184 
185  return true;
186 }
187 
189 {
190  program->setUniformValue("colorizeColor", color());
191  program->setUniformValue("colorizeStrength", float(strength()));
192 }
193 
195 {
196  const qreal *kernel = convolutionKernel();
197  int kernelWidth = columns();
198  int kernelHeight = rows();
199  int kernelSize = kernelWidth * kernelHeight;
200 
201  QVarLengthArray<GLfloat> matrix(kernelSize);
202  QVarLengthArray<GLfloat> offset(kernelSize * 2);
203 
204  for(int i = 0; i < kernelSize; ++i)
205  matrix[i] = kernel[i];
206 
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;
211  }
212  }
213 
214  const qreal iw = 1.0 / m_srcSize.width();
215  const qreal ih = 1.0 / m_srcSize.height();
216  program->setUniformValue("inv_texture_size", iw, ih);
217  program->setUniformValueArray("matrix", matrix.constData(), kernelSize, 1);
218  program->setUniformValueArray("offset", offset.constData(), kernelSize, 2);
219 }
220 
221 // generates convolution filter code for arbitrary sized kernel
223  QByteArray code;
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[");
229  code.append(QByteArray::number(kernelSize));
230  code.append("];\n"
231  "uniform highp vec2 offset[");
232  code.append(QByteArray::number(kernelSize));
233  code.append("];\n");
234  code.append("lowp vec4 customShader(lowp sampler2D src, highp vec2 srcCoords) {\n");
235 
236  code.append(" int i = 0;\n"
237  " lowp vec4 sum = vec4(0.0);\n"
238  " for (i = 0; i < ");
239  code.append(QByteArray::number(kernelSize));
240  code.append("; i++) {\n"
241  " sum += matrix[i] * texture2D(src,srcCoords+inv_texture_size*offset[i]);\n"
242  " }\n"
243  " return sum;\n"
244  "}");
245  return code;
246 }
247 
249  : m_prevKernelSize(-1)
250 {
251 }
252 
254 {
255 }
256 
257 bool QGLPixmapConvolutionFilter::processGL(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &srcRect) const
258 {
260 
261  m_srcSize = src.size();
262 
263  int kernelSize = rows() * columns();
264  if (m_prevKernelSize == -1 || m_prevKernelSize != kernelSize) {
266  m_prevKernelSize = kernelSize;
267  }
268 
269  filter->setOnPainter(painter);
270  painter->drawPixmap(pos, src, srcRect);
271  filter->removeFromPainter(painter);
272 
273  return true;
274 }
275 
277 {
278 }
279 
281 {
282 public:
283  QGLBlurTextureInfo(const QImage &image, GLuint tex, qreal r)
284  : m_texture(tex)
285  , m_radius(r)
286  {
287  m_paddedImage << image;
288  }
289 
291  {
292  glDeleteTextures(1, &m_texture);
293  }
294 
295  QImage paddedImage(int scaleLevel = 0) const;
296  GLuint texture() const { return m_texture; }
297  qreal radius() const { return m_radius; }
298 
299 private:
301  GLuint m_texture;
303 };
304 
306 {
307  for (int i = m_paddedImage.size() - 1; i <= scaleLevel; ++i)
308  m_paddedImage << qt_halfScaled(m_paddedImage.at(i));
309 
310  return m_paddedImage.at(scaleLevel);
311 }
312 
314 {
315 public:
316  static QGLBlurTextureCache *cacheForContext(const QGLContext *context);
317 
320 
321  QGLBlurTextureInfo *takeBlurTextureInfo(const QPixmap &pixmap);
322  bool hasBlurTextureInfo(quint64 cacheKey) const;
323  void insertBlurTextureInfo(const QPixmap &pixmap, QGLBlurTextureInfo *info);
324  void clearBlurTextureInfo(quint64 cacheKey);
325 
327 
328 private:
329  static void pixmapDestroyed(QPixmapData *pixmap);
330 
332 
334 
335  int timerId;
336 };
337 
340 
342  : timerId(0)
343 {
344  cache.setMaxCost(4 * 1024 * 1024);
345  blurTextureCaches.append(this);
346 }
347 
349 {
350  blurTextureCaches.removeAt(blurTextureCaches.indexOf(this));
351 }
352 
354 {
355  killTimer(timerId);
356  timerId = 0;
357 
358  cache.clear();
359 }
360 
362 {
363  return qt_blur_texture_caches()->value(context);
364 }
365 
367 {
368  return cache.take(pixmap.cacheKey());
369 }
370 
372 {
373  cache.remove(cacheKey);
374 }
375 
377 {
378  return cache.contains(cacheKey);
379 }
380 
382 {
383  static bool hookAdded = false;
384  if (!hookAdded) {
387  hookAdded = true;
388  }
389 
391  cache.insert(pixmap.cacheKey(), info, pixmap.width() * pixmap.height());
392 
393  if (timerId)
394  killTimer(timerId);
395 
396  timerId = startTimer(8000);
397 }
398 
400 {
401  foreach (QGLBlurTextureCache *cache, blurTextureCaches) {
402  if (cache->hasBlurTextureInfo(pmd->cacheKey()))
403  cache->clearBlurTextureInfo(pmd->cacheKey());
404  }
405 }
406 
407 static const int qAnimatedBlurLevelIncrement = 16;
408 static const int qMaxBlurHalfScaleLevel = 1;
409 
410 static GLuint generateBlurTexture(const QSize &size, GLenum format = GL_RGBA)
411 {
412  GLuint texture;
413  glGenTextures(1, &texture);
414  glBindTexture(GL_TEXTURE_2D, texture);
415  glTexImage2D(GL_TEXTURE_2D, 0, format, size.width(), size.height(), 0, format,
416  GL_UNSIGNED_BYTE, 0);
417  return texture;
418 }
419 
420 static inline uint nextMultiple(uint x, uint multiplier)
421 {
422  uint mod = x % multiplier;
423  if (mod == 0)
424  return x;
425  return x + multiplier - mod;
426 }
427 
428 Q_GUI_EXPORT void qt_memrotate90_gl(const quint32 *src, int srcWidth, int srcHeight, int srcStride,
429  quint32 *dest, int dstStride);
430 
431 bool QGLPixmapBlurFilter::processGL(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &) const
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 }
536 
537 static const char *qt_gl_drop_shadow_filter =
538  "uniform lowp vec4 shadowColor;"
539  "lowp vec4 customShader(lowp sampler2D src, highp vec2 srcCoords)"
540  "{"
541  " return shadowColor * texture2D(src, srcCoords.yx).a;"
542  "}";
543 
544 
546 {
548 }
549 
550 bool QGLPixmapDropShadowFilter::processGL(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &srcRect) const
551 {
553 
554  qreal r = blurRadius();
555  QRectF targetRectUnaligned = QRectF(src.rect()).translated(pos + offset()).adjusted(-r, -r, r, r);
556  QRect targetRect = targetRectUnaligned.toAlignedRect();
557 
558  // ensure even dimensions (going to divide by two)
559  targetRect.setWidth((targetRect.width() + 1) & ~1);
560  targetRect.setHeight((targetRect.height() + 1) & ~1);
561 
564 
565  QGLBlurTextureInfo *info = blurTextureCache->takeBlurTextureInfo(src);
566  if (!info || info->radius() != r) {
567  QImage half = qt_halfScaled(src.toImage().alphaChannel());
568 
569  qreal rx = r + targetRect.left() - targetRectUnaligned.left();
570  qreal ry = r + targetRect.top() - targetRectUnaligned.top();
571 
572  QImage image = QImage(targetRect.size() / 2, QImage::Format_Indexed8);
573  image.setColorTable(half.colorTable());
574  image.fill(0);
575  int dx = qRound(rx * qreal(0.5));
576  int dy = qRound(ry * qreal(0.5));
577  qt_rectcopy(image.bits(), half.bits(), dx, dy,
578  half.width(), half.height(),
579  image.bytesPerLine(), half.bytesPerLine());
580 
581  qt_blurImage(image, r * qreal(0.5), false, 1);
582 
583  GLuint texture;
584  glGenTextures(1, &texture);
585  glBindTexture(GL_TEXTURE_2D, texture);
586  glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, image.width(), image.height(),
587  0, GL_ALPHA, GL_UNSIGNED_BYTE, image.bits());
588 
589  info = new QGLBlurTextureInfo(image, texture, r);
590  }
591 
592  GLuint texture = info->texture();
593 
594  filter->setOnPainter(painter);
595 
596  QGL2PaintEngineEx *engine = static_cast<QGL2PaintEngineEx *>(painter->paintEngine());
598 
599  engine->drawTexture(targetRect, texture, info->paddedImage().size(), info->paddedImage().rect());
600 
601  filter->removeFromPainter(painter);
602 
603  // Now draw the actual pixmap over the top.
604  painter->drawPixmap(pos, src, srcRect);
605 
606  blurTextureCache->insertBlurTextureInfo(src, info);
607 
608  return true;
609 }
610 
612 {
613  QColor col = color();
614  qreal alpha = col.alphaF();
615  program->setUniformValue("shadowColor", col.redF() * alpha,
616  col.greenF() * alpha,
617  col.blueF() * alpha,
618  alpha);
619 }
620 
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...
Definition: qobject.cpp:1623
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
double d
Definition: qnumeric_p.h:62
QByteArray generateConvolutionShader() const
QRect toAlignedRect() const
Returns a QRect based on the values of this rectangle that is the smallest possible integer rectangle...
Definition: qrect.cpp:2817
const T * constData() const
QImage toImage() const
Converts the pixmap to a QImage.
Definition: qpixmap.cpp:542
void clearBlurTextureInfo(quint64 cacheKey)
qreal alphaF() const
Returns the alpha color component of this color.
Definition: qcolor.cpp:1106
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
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
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)
Definition: qglobal.h:1215
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
int width() const
Returns the width of the pixmap.
Definition: qpixmap.cpp:630
QSize size() const
Returns the size of the pixmap.
Definition: qpixmap.cpp:661
void addPixmapDataModificationHook(_qt_pixmap_cleanup_hook_pmd)
int qCeil(qreal v)
Definition: qmath.h:63
qreal greenF() const
Returns the green color component of this color.
Definition: qcolor.cpp:1241
void setColorTable(const QVector< QRgb > colors)
Sets the color table used to translate color indexes to QRgb values, to the specified colors...
Definition: qimage.cpp:1744
QByteArray & append(char c)
Appends the character ch to this byte array.
QList< QImage > m_paddedImage
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
void fill(uint pixel)
Fills the entire image with the given pixelValue.
Definition: qimage.cpp:2032
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
GLuint texture() const
qreal left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:525
virtual void timerEvent(QTimerEvent *)
This event handler can be reimplemented in a subclass to receive timer events for the object...
Definition: qobject.cpp:1294
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
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
static void enableCleanupHooks(const QImage &image)
int height() const
Returns the height of the rectangle.
Definition: qrect.h:306
QRect rect() const
Returns the enclosing rectangle (0, 0, width(), height()) of the image.
Definition: qimage.cpp:1603
Q_GUI_EXPORT QImage qt_halfScaled(const QImage &source)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
#define Q_D(Class)
Definition: qglobal.h:2482
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.
Definition: qgl.cpp:2854
#define GL_TEXTURE_2D
bool hasBlurTextureInfo(quint64 cacheKey) const
static const QGLContext * currentContext()
Returns the current context, i.e.
Definition: qgl.cpp:3545
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.
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
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QCache< quint64, QGLBlurTextureInfo > cache
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
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
unsigned __int64 quint64
Definition: qglobal.h:943
#define GL_ALPHA
void addPixmapDataDestructionHook(_qt_pixmap_cleanup_hook_pmd)
void setUniforms(QGLShaderProgram *program)
The QGLContext class encapsulates an OpenGL rendering context.
Definition: qgl.h:310
bool processGL(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &srcRect) const
qreal height() const
Returns the height of the rectangle.
Definition: qrect.h:710
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
Definition: qglobal.h:1968
QSize size() const
Returns the size of the rectangle.
Definition: qrect.h:309
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...
Definition: qimage.h:87
unsigned int uint
Definition: qglobal.h:996
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
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 ...
Definition: qrect.h:781
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&#39;s red...
Definition: qimage.cpp:6430
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587
int rows() const
Gets the number of rows in the convolution kernel.
static QByteArray prototype(const QList< QByteArray > &parameterTypes, const QList< QByteArray > &parameterNames, bool *ok)
Definition: qaxserver.cpp:685
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
static const char * qt_gl_drop_shadow_filter
int top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:243
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
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.
unsigned int GLenum
Definition: main.cpp:50
The QTimerEvent class contains parameters that describe a timer event.
Definition: qcoreevent.h:341
qreal x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:664
#define GL_UNSIGNED_BYTE
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.
Definition: qcolor.cpp:1213
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
qreal blueF() const
Returns the blue color component of this color.
Definition: qcolor.cpp:1269
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
qint64 cacheKey() const
Returns a number that identifies this QPixmap.
Definition: qpixmap.cpp:1136
QRect rect() const
Returns the pixmap&#39;s enclosing rectangle.
Definition: qpixmap.cpp:676
The QPixmap class is an off-screen image representation that can be used as a paint device...
Definition: qpixmap.h:71
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
qreal top() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:526
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
int height() const
Returns the height of the pixmap.
Definition: qpixmap.cpp:645
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.
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
qint64 cacheKey() const
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&#39;s color table, or an empty list if the image does...
Definition: qimage.cpp:1770
void removeFromPainter(QPainter *)
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203
static QList< QGLBlurTextureCache * > blurTextureCaches
void killTimer(int id)
Kills the timer with timer identifier, id.
Definition: qobject.cpp:1650