Qt 4.8
Classes | Macros | Functions | Variables
qpixmapfilter.cpp File Reference
#include <qglobal.h>
#include <QDebug>
#include "qpainter.h"
#include "qpixmap.h"
#include "qpixmapfilter_p.h"
#include "qvarlengtharray.h"
#include "private/qapplication_p.h"
#include "private/qgraphicssystem_p.h"
#include "private/qpaintengineex_p.h"
#include "private/qpaintengine_raster_p.h"
#include "qmath.h"
#include "private/qmath_p.h"
#include "private/qmemrotate_p.h"
#include "private/qdrawhelper_p.h"

Go to the source code of this file.

Classes

class  QPixmapBlurFilterPrivate
 
class  QPixmapColorizeFilterPrivate
 
class  QPixmapConvolutionFilterPrivate
 
class  QPixmapDropShadowFilterPrivate
 
class  QPixmapFilterPrivate
 

Macros

#define AVG(a, b)   ( ((((a)^(b)) & 0xfefefefeUL) >> 1) + ((a)&(b)) )
 
#define AVG16(a, b)   ( ((((a)^(b)) & 0xf7deUL) >> 1) + ((a)&(b)) )
 
#define Z_MASK   (0xff << zprec)
 
#define ZA_MASK   (0xff << (zprec + aprec))
 

Functions

static void convolute (QImage *destImage, const QPointF &pos, const QImage &srcImage, const QRectF &srcRect, QPainter::CompositionMode mode, qreal *kernel, int kernelWidth, int kernelHeight)
 
template<int aprec, int zprec, bool alphaOnly>
void expblur (QImage &img, qreal radius, bool improvedQuality=false, int transposed=0)
 
static void grayscale (const QImage &image, QImage &dest, const QRect &rect=QRect())
 
Q_GUI_EXPORT void qt_blurImage (QPainter *p, QImage &blurImage, qreal radius, bool quality, bool alphaOnly, int transposed=0)
 
Q_GUI_EXPORT void qt_blurImage (QImage &blurImage, qreal radius, bool quality, int transposed=0)
 
template<int aprec, int zprec>
void qt_blurinner (uchar *bptr, int &zR, int &zG, int &zB, int &zA, int alpha)
 
template<int aprec, int zprec>
void qt_blurinner_alphaOnly (uchar *bptr, int &z, int alpha)
 
template<int aprec, int zprec, bool alphaOnly>
void qt_blurrow (QImage &im, int line, int alpha)
 
Q_GUI_EXPORT QImage qt_halfScaled (const QImage &source)
 
Q_GUI_EXPORT bool qt_scaleForTransform (const QTransform &transform, qreal *scale)
 
template<int shift>
int qt_static_shift (int value)
 

Variables

const int alphaIndex = (QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3)
 
const qreal radiusScale = qreal(2.5)
 

Macro Definition Documentation

◆ AVG

#define AVG (   a,
 
)    ( ((((a)^(b)) & 0xfefefefeUL) >> 1) + ((a)&(b)) )

Definition at line 794 of file qpixmapfilter.cpp.

Referenced by qt_halfScaled().

◆ AVG16

#define AVG16 (   a,
 
)    ( ((((a)^(b)) & 0xf7deUL) >> 1) + ((a)&(b)) )

Definition at line 795 of file qpixmapfilter.cpp.

Referenced by qt_halfScaled().

◆ Z_MASK

#define Z_MASK   (0xff << zprec)

Referenced by qt_blurinner().

◆ ZA_MASK

#define ZA_MASK   (0xff << (zprec + aprec))

Referenced by qt_blurinner().

Function Documentation

◆ convolute()

static void convolute ( QImage destImage,
const QPointF pos,
const QImage srcImage,
const QRectF srcRect,
QPainter::CompositionMode  mode,
qreal kernel,
int  kernelWidth,
int  kernelHeight 
)
static

Definition at line 322 of file qpixmapfilter.cpp.

Referenced by QPixmapConvolutionFilter::draw().

331 {
332  const QImage processImage = (srcImage.format() != QImage::Format_ARGB32_Premultiplied ) ? srcImage.convertToFormat(QImage::Format_ARGB32_Premultiplied) : srcImage;
333  // TODO: support also other formats directly without copying
334 
335  int *fixedKernel = new int[kernelWidth*kernelHeight];
336  for(int i = 0; i < kernelWidth*kernelHeight; i++)
337  {
338  fixedKernel[i] = (int)(65536 * kernel[i]);
339  }
340  QRectF trect = srcRect.isNull() ? processImage.rect() : srcRect;
341  trect.moveTo(pos);
342  QRectF bounded = trect.adjusted(-kernelWidth / 2, -kernelHeight / 2, (kernelWidth - 1) / 2, (kernelHeight - 1) / 2);
343  QRect rect = bounded.toAlignedRect();
344  QRect targetRect = rect.intersected(destImage->rect());
345 
346  QRectF srect = srcRect.isNull() ? processImage.rect() : srcRect;
347  QRectF sbounded = srect.adjusted(-kernelWidth / 2, -kernelHeight / 2, (kernelWidth - 1) / 2, (kernelHeight - 1) / 2);
348  QPoint srcStartPoint = sbounded.toAlignedRect().topLeft()+(targetRect.topLeft()-rect.topLeft());
349 
350  const uint *sourceStart = (uint*)processImage.scanLine(0);
351  uint *outputStart = (uint*)destImage->scanLine(0);
352 
353  int yk = srcStartPoint.y();
354  for (int y = targetRect.top(); y <= targetRect.bottom(); y++) {
355  uint* output = outputStart + (destImage->bytesPerLine()/sizeof(uint))*y+targetRect.left();
356  int xk = srcStartPoint.x();
357  for(int x = targetRect.left(); x <= targetRect.right(); x++) {
358  int r = 0;
359  int g = 0;
360  int b = 0;
361  int a = 0;
362 
363  // some out of bounds pre-checking to avoid inner-loop ifs
364  int kernely = -kernelHeight/2;
365  int starty = 0;
366  int endy = kernelHeight;
367  if(yk+kernely+endy >= srcImage.height())
368  endy = kernelHeight-((yk+kernely+endy)-srcImage.height())-1;
369  if(yk+kernely < 0)
370  starty = -(yk+kernely);
371 
372  int kernelx = -kernelWidth/2;
373  int startx = 0;
374  int endx = kernelWidth;
375  if(xk+kernelx+endx >= srcImage.width())
376  endx = kernelWidth-((xk+kernelx+endx)-srcImage.width())-1;
377  if(xk+kernelx < 0)
378  startx = -(xk+kernelx);
379 
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;
390  pix++;
391  }
392  }
393 
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);
398  // composition mode checking could be moved outside of loop
400  uint color = (a<<24)+(r<<16)+(g<<8)+b;
401  *output++ = color;
402  } else {
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);
408  uint color =
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));
413  *output++ = color;;
414  }
415  xk++;
416  }
417  yk++;
418  }
419  delete[] fixedKernel;
420 }
QRect toAlignedRect() const
Returns a QRect based on the values of this rectangle that is the smallest possible integer rectangle...
Definition: qrect.cpp:2817
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
long ASN1_INTEGER_get ASN1_INTEGER * a
QRect intersected(const QRect &other) const
Returns the intersection of this rectangle and the given rectangle.
Definition: qrect.h:481
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
QRect rect() const
Returns the enclosing rectangle (0, 0, width(), height()) of the image.
Definition: qimage.cpp:1603
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
unsigned char uchar
Definition: qglobal.h:994
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
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
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
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
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
int right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
Definition: qglobal.h:1219
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
void moveTo(qreal x, qreal t)
Moves the rectangle, leaving the top-left corner at the given position (x, y).
Definition: qrect.h:728
int y() const
Returns the y coordinate of this point.
Definition: qpoint.h:131
int x() const
Returns the x coordinate of this point.
Definition: qpoint.h:128
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:655
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288

◆ expblur()

template<int aprec, int zprec, bool alphaOnly>
void expblur ( QImage img,
qreal  radius,
bool  improvedQuality = false,
int  transposed = 0 
)

Definition at line 721 of file qpixmapfilter.cpp.

722 {
723  // halve the radius if we're using two passes
724  if (improvedQuality)
725  radius *= qreal(0.5);
726 
728  || img.format() == QImage::Format_RGB32
729  || img.format() == QImage::Format_Indexed8);
730 
731  // choose the alpha such that pixels at radius distance from a fully
732  // saturated pixel will have an alpha component of no greater than
733  // the cutOffIntensity
734  const qreal cutOffIntensity = 2;
735  int alpha = radius <= qreal(1e-5)
736  ? ((1 << aprec)-1)
737  : qRound((1<<aprec)*(1 - qPow(cutOffIntensity * (1 / qreal(255)), 1 / radius)));
738 
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);
743  }
744 
745  QImage temp(img.height(), img.width(), img.format());
746  if (transposed >= 0) {
747  if (img.depth() == 8) {
748  qt_memrotate270(reinterpret_cast<const quint8*>(img.bits()),
749  img.width(), img.height(), img.bytesPerLine(),
750  reinterpret_cast<quint8*>(temp.bits()),
751  temp.bytesPerLine());
752  } else {
753  qt_memrotate270(reinterpret_cast<const quint32*>(img.bits()),
754  img.width(), img.height(), img.bytesPerLine(),
755  reinterpret_cast<quint32*>(temp.bits()),
756  temp.bytesPerLine());
757  }
758  } else {
759  if (img.depth() == 8) {
760  qt_memrotate90(reinterpret_cast<const quint8*>(img.bits()),
761  img.width(), img.height(), img.bytesPerLine(),
762  reinterpret_cast<quint8*>(temp.bits()),
763  temp.bytesPerLine());
764  } else {
765  qt_memrotate90(reinterpret_cast<const quint32*>(img.bits()),
766  img.width(), img.height(), img.bytesPerLine(),
767  reinterpret_cast<quint32*>(temp.bits()),
768  temp.bytesPerLine());
769  }
770  }
771 
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);
776  }
777 
778  if (transposed == 0) {
779  if (img.depth() == 8) {
780  qt_memrotate90(reinterpret_cast<const quint8*>(temp.bits()),
781  temp.width(), temp.height(), temp.bytesPerLine(),
782  reinterpret_cast<quint8*>(img.bits()),
783  img.bytesPerLine());
784  } else {
785  qt_memrotate90(reinterpret_cast<const quint32*>(temp.bits()),
786  temp.width(), temp.height(), temp.bytesPerLine(),
787  reinterpret_cast<quint32*>(img.bits()),
788  img.bytesPerLine());
789  }
790  } else {
791  img = temp;
792  }
793 }
double qreal
Definition: qglobal.h:1193
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
unsigned char quint8
Definition: qglobal.h:934
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void Q_GUI_EXPORT qt_memrotate90(const quint32 *, int, int, int, quint32 *, int)
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
qreal qPow(qreal x, qreal y)
Definition: qmath.h:244
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
void Q_GUI_QWS_EXPORT qt_memrotate270(const quint32 *, int, int, int, quint32 *, int)
unsigned int quint32
Definition: qglobal.h:938
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
Q_DECL_CONSTEXPR int qRound(qreal d)
Definition: qglobal.h:1203

◆ grayscale()

static void grayscale ( const QImage image,
QImage dest,
const QRect rect = QRect() 
)
static

Definition at line 977 of file qpixmapfilter.cpp.

Referenced by QPixmapColorizeFilter::draw(), and QTiffHandler::read().

978 {
979  QRect destRect = rect;
980  QRect srcRect = rect;
981  if (rect.isNull()) {
982  srcRect = dest.rect();
983  destRect = dest.rect();
984  }
985  if (&image != &dest) {
986  destRect.moveTo(QPoint(0, 0));
987  }
988 
989  unsigned int *data = (unsigned int *)image.bits();
990  unsigned int *outData = (unsigned int *)dest.bits();
991 
992  if (dest.size() == image.size() && image.rect() == srcRect) {
993  // a bit faster loop for grayscaling everything
994  int pixels = dest.width() * dest.height();
995  for (int i = 0; i < pixels; ++i) {
996  int val = qGray(data[i]);
997  outData[i] = qRgba(val, val, val, qAlpha(data[i]));
998  }
999  } else {
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]));
1008  }
1009  }
1010  }
1011 }
bool isNull() const
Returns true if the rectangle is a null rectangle, otherwise returns false.
Definition: qrect.h:231
int left() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:240
void moveTo(int x, int t)
Moves the rectangle, leaving the top-left corner at the given position (x, y).
Definition: qrect.h:334
int bottom() const
Returns the y-coordinate of the rectangle&#39;s bottom edge.
Definition: qrect.h:249
QRect rect() const
Returns the enclosing rectangle (0, 0, width(), height()) of the image.
Definition: qimage.cpp:1603
int qAlpha(QRgb rgba)
Returns the alpha component of the ARGB quadruplet rgba.
Definition: qrgb.h:66
static const char * data(const QByteArray &arr)
int qGray(int r, int g, int b)
Definition: qrgb.h:75
QSize size() const
Returns the size of the image, i.
Definition: qimage.cpp:1587
uchar * bits()
Returns a pointer to the first pixel data.
Definition: qimage.cpp:1946
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 right() const
Returns the x-coordinate of the rectangle&#39;s right edge.
Definition: qrect.h:246
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
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
QRgb qRgba(int r, int g, int b, int a)
Returns the ARGB quadruplet ({a}, {r}, {g}, {b}).
Definition: qrgb.h:72
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ qt_blurImage() [1/2]

Q_GUI_EXPORT void qt_blurImage ( QPainter p,
QImage blurImage,
qreal  radius,
bool  quality,
bool  alphaOnly,
int  transposed = 0 
)

Definition at line 885 of file qpixmapfilter.cpp.

Referenced by QPixmapBlurFilter::draw(), and QPixmapDropShadowFilter::draw().

886 {
888  && blurImage.format() != QImage::Format_RGB32)
889  {
891  }
892 
893  qreal scale = 1;
894  if (radius >= 4 && blurImage.width() >= 2 && blurImage.height() >= 2) {
895  blurImage = qt_halfScaled(blurImage);
896  scale = 2;
897  radius *= qreal(0.5);
898  }
899 
900  if (alphaOnly)
901  expblur<12, 10, true>(blurImage, radius, quality, transposed);
902  else
903  expblur<12, 10, false>(blurImage, radius, quality, transposed);
904 
905  if (p) {
906  p->scale(scale, scale);
908  p->drawImage(QRect(0, 0, blurImage.width(), blurImage.height()), blurImage);
909  }
910 }
double qreal
Definition: qglobal.h:1193
Q_GUI_EXPORT QImage qt_halfScaled(const QImage &source)
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
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
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572
void drawImage(const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)
Definition: qpainter.cpp:5936
void scale(qreal sx, qreal sy)
Scales the coordinate system by ({sx}, {sy}).
Definition: qpainter.cpp:3234

◆ qt_blurImage() [2/2]

Q_GUI_EXPORT void qt_blurImage ( QImage blurImage,
qreal  radius,
bool  quality,
int  transposed = 0 
)

Definition at line 912 of file qpixmapfilter.cpp.

Referenced by QGLPixmapBlurFilter::processGL(), and QGLPixmapDropShadowFilter::processGL().

913 {
914  if (blurImage.format() == QImage::Format_Indexed8)
915  expblur<12, 10, true>(blurImage, radius, quality, transposed);
916  else
917  expblur<12, 10, false>(blurImage, radius, quality, transposed);
918 }
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305

◆ qt_blurinner()

template<int aprec, int zprec>
void qt_blurinner ( uchar bptr,
int &  zR,
int &  zG,
int &  zB,
int &  zA,
int  alpha 
)
inline

Definition at line 631 of file qpixmapfilter.cpp.

632 {
633  QRgb *pixel = (QRgb *)bptr;
634 
635 #define Z_MASK (0xff << zprec)
636  const int A_zprec = qt_static_shift<zprec - 24>(*pixel) & Z_MASK;
637  const int R_zprec = qt_static_shift<zprec - 16>(*pixel) & Z_MASK;
638  const int G_zprec = qt_static_shift<zprec - 8>(*pixel) & Z_MASK;
639  const int B_zprec = qt_static_shift<zprec>(*pixel) & Z_MASK;
640 #undef Z_MASK
641 
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;
646 
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);
651 
652 #define ZA_MASK (0xff << (zprec + aprec))
653  *pixel =
654  qt_static_shift<24 - zprec - aprec>(zA & ZA_MASK)
655  | qt_static_shift<16 - zprec - aprec>(zR & ZA_MASK)
656  | qt_static_shift<8 - zprec - aprec>(zG & ZA_MASK)
657  | qt_static_shift<-zprec - aprec>(zB & ZA_MASK);
658 #undef ZA_MASK
659 }
unsigned int QRgb
Definition: qrgb.h:53
int qt_static_shift(int value)
#define Z_MASK
#define ZA_MASK

◆ qt_blurinner_alphaOnly()

template<int aprec, int zprec>
void qt_blurinner_alphaOnly ( uchar bptr,
int &  z,
int  alpha 
)
inline

Definition at line 664 of file qpixmapfilter.cpp.

665 {
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);
670 }

◆ qt_blurrow()

template<int aprec, int zprec, bool alphaOnly>
void qt_blurrow ( QImage im,
int  line,
int  alpha 
)
inline

Definition at line 673 of file qpixmapfilter.cpp.

674 {
675  uchar *bptr = im.scanLine(line);
676 
677  int zR = 0, zG = 0, zB = 0, zA = 0;
678 
679  if (alphaOnly && im.format() != QImage::Format_Indexed8)
680  bptr += alphaIndex;
681 
682  const int stride = im.depth() >> 3;
683  const int im_width = im.width();
684  for (int index = 0; index < im_width; ++index) {
685  if (alphaOnly)
686  qt_blurinner_alphaOnly<aprec, zprec>(bptr, zA, alpha);
687  else
688  qt_blurinner<aprec, zprec>(bptr, zR, zG, zB, zA, alpha);
689  bptr += stride;
690  }
691 
692  bptr -= stride;
693 
694  for (int index = im_width - 2; index >= 0; --index) {
695  bptr -= stride;
696  if (alphaOnly)
697  qt_blurinner_alphaOnly<aprec, zprec>(bptr, zA, alpha);
698  else
699  qt_blurinner<aprec, zprec>(bptr, zR, zG, zB, zA, alpha);
700  }
701 }
const int alphaIndex
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
unsigned char uchar
Definition: qglobal.h:994
int depth() const
Returns the depth of the image.
Definition: qimage.cpp:1620
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
quint16 index
uchar * scanLine(int)
Returns a pointer to the pixel data at the scanline with index i.
Definition: qimage.cpp:1886

◆ qt_halfScaled()

Q_GUI_EXPORT QImage qt_halfScaled ( const QImage source)

Definition at line 797 of file qpixmapfilter.cpp.

Referenced by QGLBlurTextureInfo::paddedImage(), QGLPixmapBlurFilter::processGL(), QGLPixmapDropShadowFilter::processGL(), and qt_blurImage().

798 {
799  if (source.width() < 2 || source.height() < 2)
800  return QImage();
801 
802  QImage srcImage = source;
803 
804  if (source.format() == QImage::Format_Indexed8) {
805  // assumes grayscale
806  QImage dest(source.width() / 2, source.height() / 2, srcImage.format());
807 
808  const uchar *src = reinterpret_cast<const uchar*>(const_cast<const QImage &>(srcImage).bits());
809  int sx = srcImage.bytesPerLine();
810  int sx2 = sx << 1;
811 
812  uchar *dst = reinterpret_cast<uchar*>(dest.bits());
813  int dx = dest.bytesPerLine();
814  int ww = dest.width();
815  int hh = dest.height();
816 
817  for (int y = hh; y; --y, dst += dx, src += sx2) {
818  const uchar *p1 = src;
819  const uchar *p2 = src + sx;
820  uchar *q = dst;
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;
823  }
824 
825  return dest;
826  } else if (source.format() == QImage::Format_ARGB8565_Premultiplied) {
827  QImage dest(source.width() / 2, source.height() / 2, srcImage.format());
828 
829  const uchar *src = reinterpret_cast<const uchar*>(const_cast<const QImage &>(srcImage).bits());
830  int sx = srcImage.bytesPerLine();
831  int sx2 = sx << 1;
832 
833  uchar *dst = reinterpret_cast<uchar*>(dest.bits());
834  int dx = dest.bytesPerLine();
835  int ww = dest.width();
836  int hh = dest.height();
837 
838  for (int y = hh; y; --y, dst += dx, src += sx2) {
839  const uchar *p1 = src;
840  const uchar *p2 = src + sx;
841  uchar *q = dst;
842  for (int x = ww; x; --x, q += 3, p1 += 6, p2 += 6) {
843  // alpha
844  q[0] = AVG(AVG(p1[0], p1[3]), AVG(p2[0], p2[3]));
845  // rgb
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];
850  const quint16 result = AVG16(AVG16(p16_1, p16_2), AVG16(p16_3, p16_4));
851  q[1] = result & 0xff;
852  q[2] = result >> 8;
853  }
854  }
855 
856  return dest;
857  } else if (source.format() != QImage::Format_ARGB32_Premultiplied
858  && source.format() != QImage::Format_RGB32)
859  {
861  }
862 
863  QImage dest(source.width() / 2, source.height() / 2, srcImage.format());
864 
865  const quint32 *src = reinterpret_cast<const quint32*>(const_cast<const QImage &>(srcImage).bits());
866  int sx = srcImage.bytesPerLine() >> 2;
867  int sx2 = sx << 1;
868 
869  quint32 *dst = reinterpret_cast<quint32*>(dest.bits());
870  int dx = dest.bytesPerLine() >> 2;
871  int ww = dest.width();
872  int hh = dest.height();
873 
874  for (int y = hh; y; --y, dst += dx, src += sx2) {
875  const quint32 *p1 = src;
876  const quint32 *p2 = src + sx;
877  quint32 *q = dst;
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]));
880  }
881 
882  return dest;
883 }
int bytesPerLine() const
Returns the number of bytes per image scanline.
Definition: qimage.cpp:1812
Format format() const
Returns the format of the image.
Definition: qimage.cpp:2305
unsigned char uchar
Definition: qglobal.h:994
unsigned short quint16
Definition: qglobal.h:936
The QImage class provides a hardware-independent image representation that allows direct access to th...
Definition: qimage.h:87
#define AVG16(a, b)
int width() const
Returns the width of the image.
Definition: qimage.cpp:1557
QImage convertToFormat(Format f, Qt::ImageConversionFlags flags=Qt::AutoColor) const Q_REQUIRED_RESULT
Returns a copy of the image in the given format.
Definition: qimage.cpp:3966
#define AVG(a, b)
unsigned int quint32
Definition: qglobal.h:938
int height() const
Returns the height of the image.
Definition: qimage.cpp:1572

◆ qt_scaleForTransform()

Q_GUI_EXPORT bool qt_scaleForTransform ( const QTransform transform,
qreal scale 
)

Definition at line 2407 of file qtransform.cpp.

Referenced by QPixmapBlurFilter::draw(), qt_blurImage(), and QX11PaintEngine::updateMatrix().

2408 {
2409  const QTransform::TransformationType type = transform.type();
2410  if (type <= QTransform::TxTranslate) {
2411  if (scale)
2412  *scale = 1;
2413  return true;
2414  } else if (type == QTransform::TxScale) {
2415  const qreal xScale = qAbs(transform.m11());
2416  const qreal yScale = qAbs(transform.m22());
2417  if (scale)
2418  *scale = qMax(xScale, yScale);
2419  return qFuzzyCompare(xScale, yScale);
2420  }
2421 
2422  const qreal xScale = transform.m11() * transform.m11()
2423  + transform.m21() * transform.m21();
2424  const qreal yScale = transform.m12() * transform.m12()
2425  + transform.m22() * transform.m22();
2426  if (scale)
2427  *scale = qSqrt(qMax(xScale, yScale));
2428  return type == QTransform::TxRotate && qFuzzyCompare(xScale, yScale);
2429 }
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
qreal m21() const
Returns the horizontal shearing factor.
Definition: qtransform.h:249
qreal m22() const
Returns the vertical scaling factor.
Definition: qtransform.h:253
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
TransformationType type() const
Returns the transformation type of this matrix.
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
qreal m12() const
Returns the vertical shearing factor.
Definition: qtransform.h:241
TransformationType
Definition: qtransform.h:68
bool qFuzzyCompare(const QMatrix &m1, const QMatrix &m2)
The qFuzzyCompare function is for comparing two matrices using a fuzziness factor.
Definition: qmatrix.h:172
qreal qSqrt(qreal v)
Definition: qmath.h:205
qreal m11() const
Returns the horizontal scaling factor.
Definition: qtransform.h:237

◆ qt_static_shift()

template<int shift>
int qt_static_shift ( int  value)
inline

Definition at line 620 of file qpixmapfilter.cpp.

Referenced by qt_blurinner().

621 {
622  if (shift == 0)
623  return value;
624  else if (shift > 0)
625  return value << (uint(shift) & 0x1f);
626  else
627  return value >> (uint(-shift) & 0x1f);
628 }
static ShiftResult shift(const QBezier *orig, QBezier *shifted, qreal offset, qreal threshold)
Definition: qbezier.cpp:289
unsigned int uint
Definition: qglobal.h:996

Variable Documentation

◆ alphaIndex

const int alphaIndex = (QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 3)

Definition at line 661 of file qpixmapfilter.cpp.

Referenced by qt_blurrow().

◆ radiusScale

const qreal radiusScale = qreal(2.5)