22 #include <qtconcurrentrun.h> 24 #define DEBUG_RENDER 0 27 #include <qelapsedtimer.h> 38 if ( QSysInfo::ByteOrder == QSysInfo::BigEndian )
40 return ( ch[0] & 0x7f ) == 0x7f && ch[1] > 0xf0;
44 return ( ch[7] & 0x7f ) == 0x7f && ch[6] > 0xf0;
179 if ( colorMap == NULL )
226 numColors = qMax( numColors, 0 );
257 const QColor&
color, qreal width, Qt::PenStyle style )
482 const QRectF& area,
const QSize& imageSize )
const 484 if ( imageSize.isEmpty() ||
m_data->
data == NULL
491 if ( !intensityRange.
isValid() )
495 ? QImage::Format_ARGB32 : QImage::Format_Indexed8;
497 QImage image( imageSize, format );
509 #if !defined( QT_NO_QFUTURE ) 512 if ( numThreads <= 0 )
513 numThreads = QThread::idealThreadCount();
515 if ( numThreads <= 0 )
518 const int numRows = imageSize.height() / numThreads;
521 futures.reserve( numThreads - 1 );
523 for ( uint i = 0; i < numThreads; i++ )
525 QRect tile( 0, i * numRows, image.width(), numRows );
526 if ( i == numThreads - 1 )
528 tile.setHeight( image.height() - i * numRows );
533 futures += QtConcurrent::run(
534 #
if QT_VERSION >= 0x060000
537 this, &QwtPlotSpectrogram::renderTile,
539 xMap, yMap, tile, &image );
543 for (
int i = 0; i < futures.size(); i++ )
544 futures[i].waitForFinished();
547 const QRect tile( 0, 0, image.width(), image.height() );
552 const qint64 elapsed = time.elapsed();
553 qDebug() <<
"renderImage" << imageSize << elapsed;
574 const QRect& tile, QImage* image )
const 577 if ( range.
width() <= 0.0 )
588 for (
int y = tile.top();
y <= tile.bottom();
y++ )
592 QRgb* line =
reinterpret_cast< QRgb*
>( image->scanLine(
y ) );
595 for (
int x = tile.left();
x <= tile.right();
x++ )
605 else if ( numColors == 0 )
607 *line++ = colorMap->
rgb( range, value );
612 *line++ = rgbTable[
index];
619 for (
int y = tile.top();
y <= tile.bottom();
y++ )
623 unsigned char* line = image->scanLine(
y );
626 for (
int x = tile.left();
x <= tile.right();
x++ )
639 *line++ =
static_cast< unsigned char >(
index );
664 const QRectF& area,
const QRect& rect )
const 666 QSize raster = rect.size() / 2;
668 const QRectF pixelRect =
pixelHint( area );
669 if ( !pixelRect.isEmpty() )
671 const QSize res(
qwtCeil( rect.width() / pixelRect.width() ),
672 qwtCeil( rect.height() / pixelRect.height() ) );
673 raster = raster.boundedTo( res );
690 const QRectF& rect,
const QSize& raster )
const 717 for (
int l = 0; l < numLevels; l++ )
722 if ( pen.style() == Qt::NoPen )
725 if ( pen.style() == Qt::NoPen )
728 painter->setPen( pen );
730 const QPolygonF& lines = contourLines[level];
731 for (
int i = 0; i < lines.size(); i += 2 )
733 const QPointF p1( xMap.
transform( lines[i].x() ),
735 const QPointF p2( xMap.
transform( lines[i + 1].x() ),
756 const QRectF& canvasRect )
const 764 const int margin = 2;
765 QRectF rasterRect( canvasRect.x() - margin, canvasRect.y() - margin,
766 canvasRect.width() + 2 * margin, canvasRect.height() + 2 * margin );
774 if ( area.isEmpty() )
781 raster = raster.boundedTo( rasterRect.toRect().size() );
782 if ( raster.isValid() )
virtual void discardRaster()
Discard a raster.
double invTransform(double p) const
virtual void legendChanged()
virtual QVector< QRgb > colorTable(int numColors) const
The data is displayed using contour lines.
uint renderThreadCount() const
virtual ~QwtPlotSpectrogram()
Destructor.
const QwtText & title() const
static void drawLine(QPainter *, qreal x1, qreal y1, qreal x2, qreal y2)
Wrapper for QPainter::drawLine()
A class representing an interval.
virtual QVector< QRgb > colorTable256() const
bool testConrecFlag(QwtRasterData::ConrecFlag) const
A class, which displays raster data.
virtual QRectF pixelHint(const QRectF &) const QWT_OVERRIDE
Pixel hint.
void setDefaultContourPen(const QColor &, qreal width=0.0, Qt::PenStyle=Qt::SolidLine)
int colorTableSize() const
ConrecFlag
Flags to modify the contour algorithm.
virtual ContourLines contourLines(const QRectF &rect, const QSize &raster, const QList< double > &levels, ConrecFlags) const
const QwtRasterData * data() const
bool testDisplayMode(DisplayMode) const
virtual QRectF pixelHint(const QRectF &) const
Pixel hint.
virtual void drawContourLines(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QwtRasterData::ContourLines &) const
void setData(QwtRasterData *data)
virtual QPen contourPen(double level) const
Calculate the pen for a contour line.
virtual void initRaster(const QRectF &, const QSize &raster)
Initialize a raster.
virtual int rtti() const QWT_OVERRIDE
double transform(double s) const
QMap< double, QPolygonF > ContourLines
Contour lines.
virtual uint colorIndex(int numColors, const QwtInterval &interval, double value) const
Map a value of a given interval into a color index.
Ignore all vertices on the same level.
virtual QwtInterval interval(Qt::Axis) const QWT_OVERRIDE
virtual QwtRasterData::ContourLines renderContourLines(const QRectF &rect, const QSize &raster) const
void setDisplayMode(DisplayMode, bool on=true)
virtual QwtInterval interval(Qt::Axis) const =0
The item is represented on the legend.
QVector< QRgb > colorTable
virtual void draw(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect) const QWT_OVERRIDE
Draw the raster data.
The values are mapped to colors using a color map.
virtual QRectF boundingRect() const QWT_OVERRIDE
bool testAttribute(Attribute) const
QList< double > contourLevels
void setColorMap(QwtColorMap *)
virtual void draw(QPainter *, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect) const QWT_OVERRIDE
Draw the spectrogram.
Ignore all values, that are out of range.
void setColorTableSize(int numColors)
void setZ(double z)
Set the z value.
QwtColorMap is used to map values into colors.
static int sort(lua_State *L)
QwtRasterData::ConrecFlags conrecFlags
QwtPlotSpectrogram(const QString &title=QString())
virtual double value(double x, double y) const =0
QList< double > contourLevels() const
virtual QImage renderImage(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &area, const QSize &imageSize) const QWT_OVERRIDE
Render an image from data and color map.
QwtLinearColorMap builds a color map from color stops.
The map is intended to map into RGB values.
double width() const
Return the width of an interval.
virtual void itemChanged()
const QwtColorMap * colorMap() const
QwtRasterData defines an interface to any type of raster data.
virtual QRgb rgb(const QwtInterval &interval, double value) const =0
static bool qwtIsNaN(double d)
void setItemAttribute(ItemAttribute, bool on=true)
void setContourLevels(const QList< double > &)
QPen defaultContourPen() const
void setConrecFlag(QwtRasterData::ConrecFlag, bool on)
void renderTile(const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &tile, QImage *) const
Render a tile of an image.
std::basic_string< Char > format(const text_style &ts, const S &format_str, const Args &... args)
virtual QSize contourRasterSize(const QRectF &, const QRect &) const
Return the raster to be used by the CONREC contour algorithm.