13 #include <qapplication.h> 14 #include <qdesktopwidget.h> 16 #include <qpaintengine.h> 20 #include <qtconcurrentrun.h> 50 r.setLeft( qRound( rect.left() ) );
51 r.setRight( qRound( rect.right() ) );
52 r.setTop( qRound( rect.top() ) );
53 r.setBottom( qRound( rect.bottom() ) );
65 if ( area.left() <= xInterval.
minValue() )
68 r.adjust(0, 0, -1, 0);
76 if ( area.right() >= xInterval.
maxValue() )
81 r.adjust(0, 0, -1, 0);
87 if ( area.top() <= yInterval.
minValue() )
90 r.adjust(0, 0, 0, -1);
98 if ( area.bottom() >= yInterval.
maxValue() )
101 r.adjust(0, 1, 0, 0);
103 r.adjust(0, 0, 0, -1);
112 const QRectF &
area,
const QRectF &area2,
const QRectF &
paintRect,
115 const QRectF strippedRect =
qwtStripRect(paintRect, area2,
116 xMap, yMap, xInterval, yInterval);
117 const QSize sz = strippedRect.toRect().size();
119 const int w = image.width();
120 const int h = image.height();
123 const double pw = ( r.width() - 1) / w;
124 const double ph = ( r.height() - 1) / h;
131 px0 = px0 - xMap.
transform( area.left() );
141 px0 += strippedRect.left() - paintRect.left();
157 py0 += strippedRect.top() - paintRect.top();
159 QImage expanded(sz, image.format());
161 switch( image.depth() )
165 for (
int y1 = 0; y1 < h; y1++ )
174 yy1 = qRound( y1 * ph - py0 );
186 yy2 = qRound( ( y1 + 1 ) * ph - py0 );
187 if ( yy2 > sz.height() )
191 const quint32 *line1 =
192 reinterpret_cast<const quint32 *
>( image.scanLine( y1 ) );
194 for (
int x1 = 0; x1 < w; x1++ )
203 xx1 = qRound( x1 * pw - px0 );
215 xx2 = qRound( ( x1 + 1 ) * pw - px0 );
216 if ( xx2 > sz.width() )
220 const quint32 rgb( line1[x1] );
221 for (
int y2 = yy1; y2 < yy2; y2++ )
223 quint32 *line2 =
reinterpret_cast<quint32 *
>(
224 expanded.scanLine( y2 ) );
226 for (
int x2 = xx1; x2 < xx2; x2++ )
235 for (
int y1 = 0; y1 < h; y1++ )
244 yy1 = qRound( y1 * ph - py0 );
256 yy2 = qRound( ( y1 + 1 ) * ph - py0 );
257 if ( yy2 > sz.height() )
261 const uchar *line1 = image.scanLine( y1 );
263 for (
int x1 = 0; x1 < w; x1++ )
272 xx1 = qRound( x1 * pw - px0 );
284 xx2 = qRound( ( x1 + 1 ) * pw - px0 );
285 if ( xx2 > sz.width() )
289 for (
int y2 = yy1; y2 < yy2; y2++ )
291 uchar *line2 = expanded.scanLine( y2 );
292 memset( line2 + xx1, line1[x1], xx2 - xx1 );
307 const double pw = pixelRect.width();
308 const double ph = pixelRect.height();
310 const double dx1 = pixelRect.left() - rect.left();
311 const double dx2 = pixelRect.right() - rect.right();
312 const double dy1 = pixelRect.top() - rect.top();
313 const double dy2 = pixelRect.bottom() - rect.bottom();
316 r.setLeft( pixelRect.left() - qCeil( dx1 / pw ) * pw );
317 r.setTop( pixelRect.top() - qCeil( dy1 / ph ) * ph );
318 r.setRight( pixelRect.right() - qFloor( dx2 / pw ) * pw );
319 r.setBottom( pixelRect.bottom() - qFloor( dy2 / ph ) * ph );
328 const QPointF p1 = tr.map( QPointF( xMap.
p1(), yMap.
p1() ) );
329 const QPointF p2 = tr.map( QPointF( xMap.
p2(), yMap.
p2() ) );
341 double sx1 = area.left();
342 double sx2 = area.right();
346 double sy1 = area.top();
347 double sy2 = area.bottom();
360 const QPainter *painter )
362 bool doCache =
false;
369 switch ( painter->paintEngine()->type() )
371 case QPaintEngine::SVG:
372 case QPaintEngine::Pdf:
373 case QPaintEngine::PostScript:
374 case QPaintEngine::MacPrinter:
375 case QPaintEngine::Picture:
386 const QRect& tile,
int alpha )
388 const QRgb mask1 = qRgba( 0, 0, 0, alpha );
389 const QRgb mask2 = qRgba( 255, 255, 255, 0 );
390 const QRgb mask3 = qRgba( 0, 0, 0, 255 );
392 const int y0 = tile.top();
393 const int y1 = tile.bottom();
394 const int x0 = tile.left();
395 const int x1 = tile.right();
397 if ( from->depth() == 8 )
399 for (
int y = y0;
y <= y1;
y++ )
401 QRgb *alphaLine =
reinterpret_cast<QRgb *
>( to->scanLine(
y ) );
402 const unsigned char *line = from->scanLine(
y );
404 for (
int x = x0;
x <= x1;
x++ )
405 *alphaLine++ = ( from->color( *line++ ) & mask2 ) | mask1;
408 else if ( from->depth() == 32 )
410 for (
int y = y0;
y <= y1;
y++ )
412 QRgb *alphaLine =
reinterpret_cast<QRgb *
>( to->scanLine(
y ) );
413 const QRgb *line =
reinterpret_cast<const QRgb *
>( from->scanLine(
y ) );
415 for (
int x = x0;
x <= x1;
x++ )
417 const QRgb rgb = *line++;
419 *alphaLine++ = ( rgb & mask2 ) | mask1;
610 const QRectF &canvasRect )
const 629 QRectF
paintRect = painter->transform().mapRect( canvasRect );
633 if ( br.isValid() && !br.contains( area ) )
636 if ( !area.isValid() )
646 if ( !pixelRect.isEmpty() )
649 const double dx = qAbs( xxMap.invTransform( 1 ) - xxMap.invTransform( 0 ) );
652 if ( dx > pixelRect.width() && dy > pixelRect.height() )
659 pixelRect = QRectF();
668 if ( dx > pixelRect.width() )
669 pixelRect.setWidth( dx );
671 if ( dy > pixelRect.height() )
672 pixelRect.setHeight( dy );
676 if ( pixelRect.isEmpty() )
691 area, paintRect, paintRect.size().toSize(), doCache);
692 if ( image.isNull() )
699 xxMap, yyMap, xInterval, yInterval);
701 if ( imageRect != paintRect )
704 qRound( imageRect.x() - paintRect.x()),
705 qRound( imageRect.y() - paintRect.y() ),
706 qRound( imageRect.width() ),
707 qRound( imageRect.height() ) );
709 image = image.copy(r);
720 if ( imageArea.right() == xInterval.
maxValue() &&
723 imageArea.adjust(0, 0, pixelRect.width(), 0);
725 if ( imageArea.bottom() == yInterval.
maxValue() &&
728 imageArea.adjust(0, 0, 0, pixelRect.height() );
732 imageSize.setWidth( qRound( imageArea.width() / pixelRect.width() ) );
733 imageSize.setHeight( qRound( imageArea.height() / pixelRect.height() ) );
736 imageArea, paintRect, imageSize, doCache );
738 if ( image.isNull() )
742 xxMap, yyMap, xInterval, yInterval);
744 if ( ( image.width() > 1 || image.height() > 1 ) &&
752 imageArea, area, paintRect, xInterval, yInterval );
757 painter->setWorldTransform( QTransform() );
799 r.setLeft(-0.5 * FLT_MAX);
806 r.setBottom( intervalY.
maxValue() );
810 r.setTop(-0.5 * FLT_MAX);
811 r.setHeight(FLT_MAX);
814 return r.normalized();
819 const QRectF &imageArea,
const QRectF &
paintRect,
820 const QSize &imageSize,
bool doCache)
const 823 if ( imageArea.isEmpty() || paintRect.isEmpty() || imageSize.isEmpty() )
836 if ( image.isNull() )
839 if ( paintRect.toRect().width() > imageSize.width() )
840 dx = imageArea.width() / imageSize.width();
843 imageMap(Qt::Horizontal, xMap, imageArea, imageSize, dx);
846 if ( paintRect.toRect().height() > imageSize.height() )
847 dy = imageArea.height() / imageSize.height();
850 imageMap(Qt::Vertical, yMap, imageArea, imageSize, dy);
852 image =
renderImage( xxMap, yyMap, imageArea, imageSize );
864 QImage alphaImage( image.size(), QImage::Format_ARGB32 );
866 #if !defined(QT_NO_QFUTURE) 869 if ( numThreads <= 0 )
870 numThreads = QThread::idealThreadCount();
872 if ( numThreads <= 0 )
875 const int numRows = image.height() / numThreads;
877 QVector< QFuture<void> > futures;
878 futures.reserve( numThreads - 1 );
880 for ( uint
i = 0;
i < numThreads;
i++ )
882 QRect tile( 0,
i * numRows, image.width(), numRows );
883 if (
i == numThreads - 1 )
885 tile.setHeight( image.height() -
i * numRows );
890 futures += QtConcurrent::run(
894 for (
int i = 0;
i < futures.size();
i++ )
895 futures[
i].waitForFinished();
897 const QRect tile( 0, 0, image.width(), image.height() );
918 Qt::Orientation orientation,
920 const QSize &imageSize,
double pixelSize)
const 922 double p1, p2, s1, s2;
924 if ( orientation == Qt::Horizontal )
927 p2 = imageSize.width();
934 p2 = imageSize.height();
939 if ( pixelSize > 0.0 )
941 double off = 0.5 * pixelSize;
bool testPaintAttribute(PaintAttribute) const
virtual QImage renderImage(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &area, const QSize &imageSize) const =0
Render an image.
virtual QRectF boundingRect() const
static void drawImage(QPainter *, const QRectF &, const QImage &)
Wrapper for QPainter::drawImage()
A class representing an interval.
A class, which displays raster data.
Max value is not included in the interval.
void setPaintAttribute(PaintAttribute, bool on=true)
virtual void draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &rect) const
Draw the raster data.
void setScaleInterval(double s1, double s2)
Specify the borders of the scale interval.
TFSIMD_FORCE_INLINE const tfScalar & y() const
static QRectF qwtStripRect(const QRectF &rect, const QRectF &area, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtInterval &xInterval, const QwtInterval &yInterval)
QFlags< PaintAttribute > PaintAttributes
Paint attributes.
The item is represented on the legend.
static QRectF qwtAlignRect(const QRectF &rect)
virtual QwtInterval interval(Qt::Axis) const
void setCachePolicy(CachePolicy)
virtual QwtScaleMap imageMap(Qt::Orientation, const QwtScaleMap &map, const QRectF &area, const QSize &imageSize, double pixelSize) const
Calculate a scale map for painting to an image.
QImage compose(const QwtScaleMap &, const QwtScaleMap &, const QRectF &imageArea, const QRectF &paintRect, const QSize &imageSize, bool doCache) const
struct QwtPlotRasterItem::PrivateData::ImageCache cache
void setPaintInterval(double p1, double p2)
Specify the borders of the paint device interval.
A class representing a text.
void setZ(double z)
Set the z value.
virtual QRectF pixelHint(const QRectF &) const
Pixel hint.
CachePolicy
Cache policy The default policy is NoCache.
Min value is not included in the interval.
TFSIMD_FORCE_INLINE const tfScalar & x() const
QRectF paintRect(const QwtScaleMap &, const QwtScaleMap &) const
Calculate the bounding paint rectangle of 2 maps.
double invTransform(double p) const
BorderFlags borderFlags() const
void setAlpha(int alpha)
Set an alpha value for the raster data.
virtual void itemChanged()
static QImage qwtExpandImage(const QImage &image, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &area, const QRectF &area2, const QRectF &paintRect, const QwtInterval &xInterval, const QwtInterval &yInterval)
uint renderThreadCount() const
TFSIMD_FORCE_INLINE const tfScalar & w() const
QwtPlotRasterItem(const QString &title=QString())
Constructor.
QwtPlotRasterItem::CachePolicy policy
virtual ~QwtPlotRasterItem()
Destructor.
Base class for items on the plot canvas.
void setItemAttribute(ItemAttribute, bool on=true)
double transform(double s) const
CachePolicy cachePolicy() const
static void qwtAdjustMaps(QwtScaleMap &xMap, QwtScaleMap &yMap, const QRectF &area, const QRectF &paintRect)
static QRectF qwtExpandToPixels(const QRectF &rect, const QRectF &pixelRect)
QwtPlotRasterItem::PaintAttributes paintAttributes
static bool roundingAlignment()
const QwtText & title() const
static void qwtTransformMaps(const QTransform &tr, const QwtScaleMap &xMap, const QwtScaleMap &yMap, QwtScaleMap &xxMap, QwtScaleMap &yyMap)
static bool qwtUseCache(QwtPlotRasterItem::CachePolicy policy, const QPainter *painter)
static void qwtToRgba(const QImage *from, QImage *to, const QRect &tile, int alpha)